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