]> icculus.org git repositories - btb/d2x.git/blob - main/editor/ktmap.c
imported missing editor files from d1x
[btb/d2x.git] / main / editor / ktmap.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 /*
14  * $Source: /cvs/cvsroot/d2x/main/editor/ktmap.c,v $
15  * $Revision: 1.1 $
16  * $Author: btb $
17  * $Date: 2004-12-19 13:54:27 $
18  * 
19  * Texture map key bindings.
20  * 
21  * $Log: not supported by cvs2svn $
22  * Revision 1.1.1.1  1999/06/14 22:03:34  donut
23  * Import of d1x 1.37 source.
24  *
25  * Revision 2.0  1995/02/27  11:35:37  john
26  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
27  * for bitmaps.tbl.
28  * 
29  * Revision 1.26  1994/08/25  21:57:12  mike
30  * IS_CHILD stuff.
31  * 
32  * Revision 1.25  1994/08/03  10:32:41  mike
33  * Texture map stretching.
34  * 
35  * Revision 1.24  1994/05/14  17:17:35  matt
36  * Got rid of externs in source (non-header) files
37  * 
38  * Revision 1.23  1994/04/28  10:48:38  yuan
39  * Fixed undo message for Clear Texture.
40  * 
41  * Revision 1.22  1994/04/22  17:45:42  john
42  * MAde top 2 bits of paste-ons pick the 
43  * orientation of the bitmap.
44  * 
45  * Revision 1.21  1994/04/01  14:36:08  yuan
46  * Fixed propogate function so you can propogate and move.
47  * 
48  * Revision 1.20  1994/03/19  17:22:08  yuan
49  * Wall system implemented until specific features need to be added...
50  * (Needs to be hammered on though.)
51  * 
52  * Revision 1.19  1994/02/14  12:06:12  mike
53  * change segment data structure.
54  * 
55  * Revision 1.18  1994/01/25  17:58:47  yuan
56  * Added ambient lighting, and also added fixing bogus segments
57  * functions to the editor... (they don't work fully... need to
58  * check out seguvs.c
59  * 
60  * Revision 1.17  1994/01/24  11:54:52  yuan
61  * Checking everything in
62  * 
63  * Revision 1.16  1994/01/18  16:05:57  yuan
64  * Added clear texture 2 function (shift 0)
65  * 
66  * Revision 1.15  1994/01/18  10:15:01  yuan
67  * added texture stuff
68  * 
69  * Revision 1.14  1993/12/06  19:33:57  yuan
70  * Fixed autosave stuff so that undo restores Cursegp and
71  * Markedsegp
72  * 
73  * Revision 1.13  1993/12/02  12:39:39  matt
74  * Removed extra includes
75  * 
76  * Revision 1.12  1993/11/28  17:31:34  mike
77  * Use new segment data structure.
78  * 
79  * Revision 1.11  1993/11/12  16:38:37  mike
80  * Change call to med_propagate_tmaps_to_segments to include new uv_only_flag parameter.
81  * 
82  * Revision 1.10  1993/11/11  15:53:30  yuan
83  * Fixed undo display message
84  * 
85  * Revision 1.9  1993/11/08  19:13:46  yuan
86  * Added Undo command (not working yet)
87  * 
88  * Revision 1.8  1993/11/05  17:32:48  john
89  * added funcs
90  * .,
91  * 
92  * Revision 1.7  1993/11/02  10:31:08  mike
93  * Add PropagateTexturesSelected.
94  * 
95  * Revision 1.6  1993/10/29  11:43:15  mike
96  * Write PropagateTextures
97  * 
98  * Revision 1.5  1993/10/25  13:26:39  mike
99  * Force redraw whenever a texture map is assigned.
100  * 
101  * Revision 1.4  1993/10/15  17:42:53  mike
102  * Make AssignTexture also assign texture maps to New_segment.
103  * 
104  * Revision 1.3  1993/10/15  13:10:24  mike
105  * Adapt AssignTexture to new segment structure.
106  * 
107  * Revision 1.2  1993/10/14  18:09:17  mike
108  * Debug code for AssignTexture and comment out code.
109  * 
110  * Revision 1.1  1993/10/14  14:01:49  mike
111  * Initial revision
112  * 
113  * 
114  */
115
116
117 #ifdef RCS
118 static char rcsid[] = "$Id: ktmap.c,v 1.1 2004-12-19 13:54:27 btb Exp $";
119 #endif
120
121 #include <string.h>
122
123 #include "inferno.h"
124 #include "editor.h"
125 #include "mono.h"
126 #include "kdefs.h"
127
128 //      Assign CurrentTexture to Curside in *Cursegp
129 int AssignTexture(void)
130 {
131    autosave_mine( mine_filename );
132    strcpy(undo_status[Autosave_count], "Assign Texture UNDONE.");
133
134         Cursegp->sides[Curside].tmap_num = CurrentTexture;
135
136         New_segment.sides[Curside].tmap_num = CurrentTexture;
137
138 //      propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0); 
139                                                                                                                                                                          
140         Update_flags |= UF_WORLD_CHANGED;
141
142         return 1;
143 }
144
145 //      Assign CurrentTexture to Curside in *Cursegp
146 int AssignTexture2(void)
147 {
148         int texnum, orient, ctexnum, newtexnum;
149
150    autosave_mine( mine_filename );
151    strcpy(undo_status[Autosave_count], "Assign Texture 2 UNDONE.");
152
153         texnum = Cursegp->sides[Curside].tmap_num2 & 0x3FFF;
154         orient = ((Cursegp->sides[Curside].tmap_num2 & 0xC000) >> 14) & 3;
155         ctexnum = CurrentTexture;
156         
157         if ( ctexnum == texnum )        {
158                 orient = (orient+1) & 3;
159                 newtexnum = (orient<<14) | texnum;
160         } else {
161                 newtexnum = ctexnum;
162         }
163
164         Cursegp->sides[Curside].tmap_num2 = newtexnum;
165         New_segment.sides[Curside].tmap_num2 = newtexnum;
166
167         Update_flags |= UF_WORLD_CHANGED;
168
169         return 1;
170 }
171
172 int ClearTexture2(void)
173 {
174    autosave_mine( mine_filename );
175    strcpy(undo_status[Autosave_count], "Clear Texture 2 UNDONE.");
176
177         Cursegp->sides[Curside].tmap_num2 = 0;
178
179         New_segment.sides[Curside].tmap_num2 = 0;
180
181         Update_flags |= UF_WORLD_CHANGED;
182
183         return 1;
184 }
185
186
187 //      --------------------------------------------------------------------------------------------------
188 //      Propagate textures from Cursegp through Curside.
189 //      If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well)
190 //      If move_flag !0, then move forward to new segment after propagation, else don't
191 int propagate_textures_common(int uv_flag, int move_flag)
192 {
193    autosave_mine( mine_filename );
194    strcpy(undo_status[Autosave_count], "Propogate Textures UNDONE.");
195         
196         if (IS_CHILD(Cursegp->children[Curside]))
197                 med_propagate_tmaps_to_segments(Cursegp, &Segments[Cursegp->children[Curside]], uv_flag);
198
199         if (move_flag)
200                 SelectCurrentSegForward();
201
202         Update_flags |= UF_WORLD_CHANGED;
203
204         return 1;
205 }
206
207 //      Propagate texture maps from current segment, through current side
208 int PropagateTextures(void)
209 {
210         return propagate_textures_common(0, 0);
211 }
212
213 //      Propagate texture maps from current segment, through current side
214 int PropagateTexturesUVs(void)
215 {
216         return propagate_textures_common(-1, 0);
217 }
218
219 //      Propagate texture maps from current segment, through current side
220 // And move to that segment.
221 int PropagateTexturesMove(void)
222 {
223         return propagate_textures_common(0, 1);
224 }
225
226 //      Propagate uv coordinate from current segment, through current side
227 // And move to that segment.
228 int PropagateTexturesMoveUVs(void)
229 {
230         return propagate_textures_common(-1, 1);
231 }
232
233
234 //      -------------------------------------------------------------------------------------
235 int is_selected_segment(int segnum)
236 {
237         int     i;
238
239         for (i=0; i<N_selected_segs; i++)
240                 if (Selected_segs[i] == segnum)
241                         return 1;
242
243         return 0;
244
245 }
246
247 //      -------------------------------------------------------------------------------------
248 //      Auxiliary function for PropagateTexturesSelected.
249 //      Recursive parse.
250 void pts_aux(segment *sp)
251 {
252         int             side;
253
254         Been_visited[sp-Segments] = 1;
255
256         for (side=0; side<MAX_SIDES_PER_SEGMENT; side++) {
257                 if (IS_CHILD(sp->children[side])) {
258                         while ((!Been_visited[sp->children[side]]) && is_selected_segment(sp->children[side])) {
259                                 med_propagate_tmaps_to_segments(sp,&Segments[sp->children[side]],0);
260                                 pts_aux(&Segments[sp->children[side]]);
261                         }
262                 }
263         }
264 }
265
266 //      -------------------------------------------------------------------------------------
267 //      Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list
268 //      until a segment not in Selected_list is reached.
269 int PropagateTexturesSelected(void)
270 {
271         int             i;
272
273    autosave_mine( mine_filename );
274    strcpy(undo_status[Autosave_count], "Propogate Textures Selected UNDONE.");
275
276         for (i=0; i<MAX_SEGMENTS; i++) Been_visited[i] = 0;     //clear visited list
277         Been_visited[Cursegp-Segments] = 1;
278
279         pts_aux(Cursegp);
280
281         Update_flags |= UF_WORLD_CHANGED;
282
283         return 1;
284 }
285