]> icculus.org git repositories - btb/d2x.git/blob - main/editor/ktmap.c
Move old logs to ChangeLog-old
[btb/d2x.git] / main / editor / ktmap.c
1 /* $Id: ktmap.c,v 1.2 2004-12-19 14:52:48 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Texture map key bindings.
18  *
19  */
20
21
22 #ifdef RCS
23 static char rcsid[] = "$Id: ktmap.c,v 1.2 2004-12-19 14:52:48 btb Exp $";
24 #endif
25
26 #include <string.h>
27
28 #include "inferno.h"
29 #include "editor.h"
30 #include "mono.h"
31 #include "kdefs.h"
32
33 //      Assign CurrentTexture to Curside in *Cursegp
34 int AssignTexture(void)
35 {
36    autosave_mine( mine_filename );
37    strcpy(undo_status[Autosave_count], "Assign Texture UNDONE.");
38
39         Cursegp->sides[Curside].tmap_num = CurrentTexture;
40
41         New_segment.sides[Curside].tmap_num = CurrentTexture;
42
43 //      propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0); 
44                                                                                                                                                                          
45         Update_flags |= UF_WORLD_CHANGED;
46
47         return 1;
48 }
49
50 //      Assign CurrentTexture to Curside in *Cursegp
51 int AssignTexture2(void)
52 {
53         int texnum, orient, ctexnum, newtexnum;
54
55    autosave_mine( mine_filename );
56    strcpy(undo_status[Autosave_count], "Assign Texture 2 UNDONE.");
57
58         texnum = Cursegp->sides[Curside].tmap_num2 & 0x3FFF;
59         orient = ((Cursegp->sides[Curside].tmap_num2 & 0xC000) >> 14) & 3;
60         ctexnum = CurrentTexture;
61         
62         if ( ctexnum == texnum )        {
63                 orient = (orient+1) & 3;
64                 newtexnum = (orient<<14) | texnum;
65         } else {
66                 newtexnum = ctexnum;
67         }
68
69         Cursegp->sides[Curside].tmap_num2 = newtexnum;
70         New_segment.sides[Curside].tmap_num2 = newtexnum;
71
72         Update_flags |= UF_WORLD_CHANGED;
73
74         return 1;
75 }
76
77 int ClearTexture2(void)
78 {
79    autosave_mine( mine_filename );
80    strcpy(undo_status[Autosave_count], "Clear Texture 2 UNDONE.");
81
82         Cursegp->sides[Curside].tmap_num2 = 0;
83
84         New_segment.sides[Curside].tmap_num2 = 0;
85
86         Update_flags |= UF_WORLD_CHANGED;
87
88         return 1;
89 }
90
91
92 //      --------------------------------------------------------------------------------------------------
93 //      Propagate textures from Cursegp through Curside.
94 //      If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well)
95 //      If move_flag !0, then move forward to new segment after propagation, else don't
96 int propagate_textures_common(int uv_flag, int move_flag)
97 {
98    autosave_mine( mine_filename );
99    strcpy(undo_status[Autosave_count], "Propogate Textures UNDONE.");
100         
101         if (IS_CHILD(Cursegp->children[Curside]))
102                 med_propagate_tmaps_to_segments(Cursegp, &Segments[Cursegp->children[Curside]], uv_flag);
103
104         if (move_flag)
105                 SelectCurrentSegForward();
106
107         Update_flags |= UF_WORLD_CHANGED;
108
109         return 1;
110 }
111
112 //      Propagate texture maps from current segment, through current side
113 int PropagateTextures(void)
114 {
115         return propagate_textures_common(0, 0);
116 }
117
118 //      Propagate texture maps from current segment, through current side
119 int PropagateTexturesUVs(void)
120 {
121         return propagate_textures_common(-1, 0);
122 }
123
124 //      Propagate texture maps from current segment, through current side
125 // And move to that segment.
126 int PropagateTexturesMove(void)
127 {
128         return propagate_textures_common(0, 1);
129 }
130
131 //      Propagate uv coordinate from current segment, through current side
132 // And move to that segment.
133 int PropagateTexturesMoveUVs(void)
134 {
135         return propagate_textures_common(-1, 1);
136 }
137
138
139 //      -------------------------------------------------------------------------------------
140 int is_selected_segment(int segnum)
141 {
142         int     i;
143
144         for (i=0; i<N_selected_segs; i++)
145                 if (Selected_segs[i] == segnum)
146                         return 1;
147
148         return 0;
149
150 }
151
152 //      -------------------------------------------------------------------------------------
153 //      Auxiliary function for PropagateTexturesSelected.
154 //      Recursive parse.
155 void pts_aux(segment *sp)
156 {
157         int             side;
158
159         Been_visited[sp-Segments] = 1;
160
161         for (side=0; side<MAX_SIDES_PER_SEGMENT; side++) {
162                 if (IS_CHILD(sp->children[side])) {
163                         while ((!Been_visited[sp->children[side]]) && is_selected_segment(sp->children[side])) {
164                                 med_propagate_tmaps_to_segments(sp,&Segments[sp->children[side]],0);
165                                 pts_aux(&Segments[sp->children[side]]);
166                         }
167                 }
168         }
169 }
170
171 //      -------------------------------------------------------------------------------------
172 //      Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list
173 //      until a segment not in Selected_list is reached.
174 int PropagateTexturesSelected(void)
175 {
176         int             i;
177
178    autosave_mine( mine_filename );
179    strcpy(undo_status[Autosave_count], "Propogate Textures Selected UNDONE.");
180
181         for (i=0; i<MAX_SEGMENTS; i++) Been_visited[i] = 0;     //clear visited list
182         Been_visited[Cursegp-Segments] = 1;
183
184         pts_aux(Cursegp);
185
186         Update_flags |= UF_WORLD_CHANGED;
187
188         return 1;
189 }
190