]> icculus.org git repositories - btb/d2x.git/blob - main/editor/info.c
more header cleanup
[btb/d2x.git] / main / editor / info.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 /*
15  *
16  * Print debugging info in ui.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "conf.h"
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #ifdef DO_MEMINFO
29 #include <i86.h>
30 #include <malloc.h>
31 #endif
32
33 #include "inferno.h"
34 #include "gr.h"
35 #include "ui.h"
36 #include "editor.h"
37 #include "mono.h"
38 #include "error.h"
39
40
41 int init_info;
42
43 #ifdef DO_MEMINFO
44 struct meminfo {
45     int LargestBlockAvail;
46     int MaxUnlockedPage;
47     int LargestLockablePage;
48     int LinAddrSpace;
49     int NumFreePagesAvail;
50     int NumPhysicalPagesFree;
51     int TotalPhysicalPages;
52     int FreeLinAddrSpace;
53     int SizeOfPageFile;
54     int Reserved[3];
55 } MemInfo;
56
57 #define DPMI_INT        0x31
58
59 void read_mem_info()
60 {
61     union REGS regs;
62     struct SREGS sregs;
63
64     regs.x.eax = 0x00000500;
65     memset( &sregs, 0, sizeof(sregs) );
66     sregs.es = FP_SEG( &MemInfo );
67     regs.x.edi = FP_OFF( &MemInfo );
68
69     int386x( DPMI_INT, &regs, &regs, &sregs );
70 }
71 #endif
72
73 char * get_object_type(int num, char *name)
74 {
75         switch (num) {
76                 case OBJ_NONE:                  strcpy(name, "OBJ_NONE    ");   break;
77                 case OBJ_WALL:          strcpy(name, "OBJ_WALL    ");   break;
78                 case OBJ_FIREBALL:      strcpy(name, "OBJ_FIREBALL");   break;
79                 case OBJ_ROBOT:                 strcpy(name, "OBJ_ROBOT   ");   break;
80                 case OBJ_HOSTAGE:       strcpy(name, "OBJ_HOSTAGE ");   break;
81                 case OBJ_PLAYER:                strcpy(name, "OBJ_PLAYER  ");   break;
82                 case OBJ_WEAPON:                strcpy(name, "OBJ_WEAPON  ");   break;
83                 case OBJ_CAMERA:                strcpy(name, "OBJ_CAMERA  ");   break;
84                 case OBJ_POWERUP:       strcpy(name, "OBJ_POWERUP ");   break;
85                 default:                                        strcpy(name, " (unknown)  ");   break;
86         }
87
88         return name;
89 }
90
91 char * get_control_type(int num, char *name)
92 {
93         switch (num) {
94                 case CT_NONE:                                   strcpy(name, "CT_NONE       "); break;
95                 case CT_AI:                                             strcpy(name, "CT_AI         "); break;
96                 case CT_EXPLOSION:                      strcpy(name, "CT_EXPLOSION  "); break;
97                 //case CT_MULTIPLAYER:                  strcpy(name, "CT_MULTIPLAYER"); break;
98                 case CT_FLYING:                         strcpy(name, "CT_FLYING     "); break;
99                 case CT_SLEW:                                   strcpy(name, "CT_SLEW       "); break;
100                 case CT_FLYTHROUGH:                     strcpy(name, "CT_FLYTHROUGH "); break;
101                 //case CT_DEMO:                                 strcpy(name, "CT_DEMO       "); break;
102                 //case CT_ROBOT_FLYTHROUGH:     strcpy(name, "CT_FLYTHROUGH "); break;
103                 case CT_WEAPON:                         strcpy(name, "CT_WEAPON     "); break;
104                 default:                                                        strcpy(name, " (unknown)    "); break;
105         }
106         return name;
107 }
108
109 char * get_movement_type(int num, char *name)
110 {
111         switch (num) {
112                 case MT_NONE:                   strcpy(name, "MT_NONE       "); break;
113                 case MT_PHYSICS:                strcpy(name, "MT_PHYSICS    "); break;
114                 //case MT_MULTIPLAYER:  strcpy(name, "MT_MULTIPLAYER"); break;
115                 default:                                        strcpy(name, " (unknown)    "); break;
116         }
117         return name;
118 }
119
120 char * get_ai_behavior(int num, char *name)
121 {
122 #define AIB_STILL                                               0x80
123 #define AIB_NORMAL                                              0x81
124 #define AIB_HIDE                                                        0x82
125 #define AIB_RUN_FROM                                    0x83
126 #define AIB_FOLLOW_PATH                         0x84
127
128         switch (num) {
129                 case AIB_STILL:                         strcpy(name, "STILL       ");   break;
130                 case AIB_NORMAL:                                strcpy(name, "NORMAL      ");   break;
131                 case AIB_HIDE:                                  strcpy(name, "HIDE        ");   break;
132                 case AIB_RUN_FROM:                      strcpy(name, "RUN_FROM    ");   break;
133                 case AIB_FOLLOW_PATH:           strcpy(name, "FOLLOW_PATH ");   break;
134                 default:                                                        strcpy(name, " (unknown)  ");   break;
135         }
136         return name;
137 }
138
139 //      ---------------------------------------------------------------------------------------------------
140 void info_display_object_placement(int show_all)
141 {
142         static  int     old_Cur_object_index;
143         static  int     old_type;
144         static  int     old_movement_type;
145         static  int     old_control_type;
146         static  int     old_mode;
147
148         char            name[30];
149
150         if (init_info | show_all) {
151                 old_Cur_object_index = -2;
152                 old_type = -2;
153                 old_movement_type = -2;
154                 old_control_type = -2;
155                 old_mode = -2;
156         }
157
158         if ( ( Cur_object_index != old_Cur_object_index) || 
159                         ( Objects[Cur_object_index].type != old_type) || 
160                         ( Objects[Cur_object_index].movement_type != old_movement_type) || 
161                         ( Objects[Cur_object_index].control_type != old_control_type) || 
162                         ( Objects[Cur_object_index].ctype.ai_info.behavior != old_mode) ) {
163
164                 gr_uprintf( 0, 0, "Object id: %4d\n", Cur_object_index);
165                 gr_uprintf( 0, 16, "Type: %s\n", get_object_type(Objects[Cur_object_index].type , name));
166                 gr_uprintf( 0, 32, "Movmnt: %s\n", get_movement_type(Objects[Cur_object_index].movement_type, name));
167                 gr_uprintf( 0, 48, "Cntrl: %s\n", get_control_type(Objects[Cur_object_index].control_type, name));
168                 gr_uprintf( 0, 64, "Mode: %s\n", get_ai_behavior(Objects[Cur_object_index].ctype.ai_info.behavior, name));
169
170                 old_Cur_object_index = Cur_object_index;
171                 old_type = Objects[Cur_object_index].type;
172                 old_movement_type = Objects[Cur_object_index].movement_type;
173                 old_mode = Objects[Cur_object_index].control_type;
174                 old_mode = Objects[Cur_object_index].ctype.ai_info.behavior;
175         }
176
177 }
178
179 //      ---------------------------------------------------------------------------------------------------
180 void info_display_segsize(int show_all)
181 {
182         static  int     old_SegSizeMode;
183
184         char            name[30];
185
186         if (init_info | show_all) {
187                 old_SegSizeMode = -2;
188         }
189
190         if (old_SegSizeMode != SegSizeMode  ) {
191                 switch (SegSizeMode) {
192                         case SEGSIZEMODE_FREE:          strcpy(name, "free   ");        break;
193                         case SEGSIZEMODE_ALL:           strcpy(name, "all    ");        break;
194                         case SEGSIZEMODE_CURSIDE:       strcpy(name, "curside");        break;
195                         case SEGSIZEMODE_EDGE:          strcpy(name, "edge   ");        break;
196                         case SEGSIZEMODE_VERTEX:        strcpy(name, "vertex ");        break;
197                         default:
198                                 Error("Illegal value for SegSizeMode in info.c/info_display_segsize\n");
199                 }
200
201                 gr_uprintf( 0, 0, "Mode: %s\n", name);
202
203                 old_SegSizeMode = SegSizeMode;
204         }
205
206 }
207
208 extern int num_objects;
209
210 //      ---------------------------------------------------------------------------------------------------
211 void info_display_default(int show_all)
212 {
213         static int old_Num_segments = -1;
214         static int old_Num_vertices = -1;
215         static int old_Num_objects = -1;
216         static int old_Cursegp_num = -1;
217         static int old_Curside = -1;
218         static int old_Cursegp_num_for_verts = -1;
219         static int old_CurrentTexture = -1;
220         static int old_Num_walls = -1;
221         static int old_Num_triggers = -1;
222
223         if (init_info | show_all) {
224                 init_info = 0;
225                 old_Num_segments = -1;
226                 old_Num_vertices = -1;
227                 old_Num_objects = -1;
228                 old_Cursegp_num = -1;
229                 old_Cursegp_num_for_verts = -1;
230                 old_Curside = -1;
231                 old_CurrentTexture = -1;
232                 old_Num_walls = -1;
233                 old_Num_triggers = -1;
234         }
235
236         gr_set_fontcolor(CBLACK,CWHITE);
237
238         //--------------- Number of segments ----------------
239
240         if ( old_Num_segments != Num_segments ) {
241                 gr_uprintf( 0, 0, "Segments: %4d/%4d", Num_segments, MAX_SEGMENTS );
242                 old_Num_segments = Num_segments;
243         }
244
245         //---------------- Number of vertics -----------------
246         
247         if ( old_Num_vertices != Num_vertices ) {
248                 gr_uprintf( 0, 16, "Vertices: %4d/%4d", Num_vertices, MAX_VERTICES );
249                 old_Num_vertices = Num_vertices;
250         }
251
252         //---------------- Number of objects -----------------
253         
254         if ( old_Num_objects != num_objects )   {
255                 gr_uprintf( 0, 32, "Objs: %3d/%3d", num_objects, MAX_OBJECTS );
256                 old_Num_objects = num_objects;
257         }
258
259         //--------------- Current_segment_number -------------
260         //--------------- Current_side_number -------------
261
262         if ( (old_Cursegp_num != SEGMENT_NUMBER(Cursegp)) || (old_Curside != Curside) ) {
263                 gr_uprintf( 0, 48, "Cursegp/side: %3d/%1d", SEGMENT_NUMBER(Cursegp), Curside );
264                 gr_uprintf( 0, 128, " tmap1,2,o: %3d/%3dx%1d", Cursegp->sides[Curside].tmap_num, Cursegp->sides[Curside].tmap_num2 & 0x3FFF, (Cursegp->sides[Curside].tmap_num2 >> 14) & 3);
265                 old_Cursegp_num = SEGMENT_NUMBER(Cursegp);
266                 old_Curside = Curside;
267         }
268
269         //--------------- Current_vertex_numbers -------------
270
271         if ( old_Cursegp_num_for_verts != SEGMENT_NUMBER(Cursegp) ) {
272
273                 gr_uprintf( 0, 64, "{%3d,%3d,%3d,%3d,", Cursegp->verts[0],Cursegp->verts[1],
274                                                                                                                                                                                          Cursegp->verts[2],Cursegp->verts[3] );
275                 gr_uprintf( 0, 80," %3d,%3d,%3d,%3d}", Cursegp->verts[4],Cursegp->verts[5],
276                                                                                                                                                                                          Cursegp->verts[6],Cursegp->verts[7] );
277                 old_Cursegp_num_for_verts = SEGMENT_NUMBER(Cursegp);
278         }
279
280         //--------------- Num walls/links/triggers -------------------------
281
282         if ( old_Num_walls != Num_walls ) {
283 //              gr_uprintf( 0, 96, "Walls/Links %d/%d", Num_walls, Num_links );
284                 gr_uprintf( 0, 96, "Walls %3d", Num_walls );
285                 old_Num_walls = Num_walls;
286         }
287
288         //--------------- Num triggers ----------------------
289
290         if ( old_Num_triggers != Num_triggers ) {
291                 gr_uprintf( 0, 112, "Num_triggers %2d", Num_triggers );
292                 old_Num_triggers = Num_triggers;
293         }
294
295         //--------------- Current texture number -------------
296
297         if ( old_CurrentTexture != CurrentTexture )     {
298                 gr_uprintf( 0, 144, "Tex/Light: %3d %5.2f", CurrentTexture, f2fl(TmapInfo[CurrentTexture].lighting));
299                 old_CurrentTexture = CurrentTexture;
300         }
301
302 }
303
304 //      ------------------------------------------------------------------------------------
305 void clear_pad_display(void)
306 {
307         gr_clear_canvas(CWHITE);
308    gr_set_fontcolor( CBLACK, CWHITE );
309 }
310
311 //      ------------------------------------------------------------------------------------
312 void info_display_all( UI_WINDOW * wnd )
313 {
314         static int old_padnum = -1;
315         int        padnum,show_all = 0;
316         grs_canvas *save_canvas = grd_curcanv;
317
318         wnd++;          //kill warning
319
320         grd_curcanv = Pad_text_canvas;
321
322         padnum = ui_pad_get_current();
323         Assert(padnum <= MAX_PAD_ID);
324
325         if (padnum != old_padnum) {
326                 clear_pad_display();
327                 old_padnum = padnum;
328                 show_all = 1;
329         }
330
331         switch (padnum) {
332                 case OBJECT_PAD_ID:                     // Object placement
333                         info_display_object_placement(show_all);
334                         break;
335                 case SEGSIZE_PAD_ID:                    // Segment sizing
336                         info_display_segsize(show_all);
337                         break;
338                 default:
339                         info_display_default(show_all);
340                         break;
341         }
342         grd_curcanv = save_canvas;
343 }
344