Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
| 3 | * described in COPYING.txt. |
||
| 4 | * Portions of this file are copyright Parallax Software and licensed |
||
| 5 | * according to the Parallax license below. |
||
| 6 | * See COPYING.txt for license details. |
||
| 7 | |||
| 8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
| 9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
| 10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
| 11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
| 12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
| 13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
| 14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
| 15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
| 16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
| 17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
| 18 | */ |
||
| 19 | |||
| 20 | /* |
||
| 21 | * |
||
| 22 | * Print debugging info in ui. |
||
| 23 | * |
||
| 24 | */ |
||
| 25 | |||
| 26 | #include <cinttypes> |
||
| 27 | #include <stdio.h> |
||
| 28 | #include <stdlib.h> |
||
| 29 | #include <string.h> |
||
| 30 | |||
| 31 | #include "inferno.h" |
||
| 32 | #include "window.h" |
||
| 33 | #include "segment.h" |
||
| 34 | #include "event.h" |
||
| 35 | #include "gr.h" |
||
| 36 | #include "ui.h" |
||
| 37 | #include "editor.h" |
||
| 38 | #include "editor/esegment.h" |
||
| 39 | #include "dxxerror.h" |
||
| 40 | #include "textures.h" |
||
| 41 | #include "object.h" |
||
| 42 | #include "ai.h" |
||
| 43 | #include "texpage.h" // Textue selection paging stuff |
||
| 44 | #include "objpage.h" // Object selection paging stuff |
||
| 45 | #include "wall.h" |
||
| 46 | #include "switch.h" |
||
| 47 | #include "info.h" |
||
| 48 | |||
| 49 | int init_info; |
||
| 50 | |||
| 51 | typedef const char object_type_name[13]; |
||
| 52 | typedef const char control_type_name[15]; |
||
| 53 | typedef const char movement_type_name[15]; |
||
| 54 | typedef const char ai_type_name[13]; |
||
| 55 | |||
| 56 | static object_type_name &get_object_type(int num) |
||
| 57 | { |
||
| 58 | switch (num) { |
||
| 59 | case OBJ_NONE: |
||
| 60 | return "OBJ_NONE "; |
||
| 61 | case OBJ_WALL: |
||
| 62 | return "OBJ_WALL "; |
||
| 63 | case OBJ_FIREBALL: |
||
| 64 | return "OBJ_FIREBALL"; |
||
| 65 | case OBJ_ROBOT: |
||
| 66 | return "OBJ_ROBOT "; |
||
| 67 | case OBJ_HOSTAGE: |
||
| 68 | return "OBJ_HOSTAGE "; |
||
| 69 | case OBJ_PLAYER: |
||
| 70 | return "OBJ_PLAYER "; |
||
| 71 | case OBJ_WEAPON: |
||
| 72 | return "OBJ_WEAPON "; |
||
| 73 | case OBJ_CAMERA: |
||
| 74 | return "OBJ_CAMERA "; |
||
| 75 | case OBJ_POWERUP: |
||
| 76 | return "OBJ_POWERUP "; |
||
| 77 | default: |
||
| 78 | return " (unknown) "; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | static control_type_name &get_control_type(int num) |
||
| 83 | { |
||
| 84 | switch (num) { |
||
| 85 | case CT_NONE: |
||
| 86 | return "CT_NONE "; |
||
| 87 | case CT_AI: |
||
| 88 | return "CT_AI "; |
||
| 89 | case CT_EXPLOSION: |
||
| 90 | return "CT_EXPLOSION "; |
||
| 91 | case CT_FLYING: |
||
| 92 | return "CT_FLYING "; |
||
| 93 | case CT_SLEW: |
||
| 94 | return "CT_SLEW "; |
||
| 95 | case CT_FLYTHROUGH: |
||
| 96 | return "CT_FLYTHROUGH "; |
||
| 97 | case CT_WEAPON: |
||
| 98 | return "CT_WEAPON "; |
||
| 99 | default: |
||
| 100 | return " (unknown) "; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | static movement_type_name &get_movement_type(int num) |
||
| 105 | { |
||
| 106 | switch (num) { |
||
| 107 | case MT_NONE: |
||
| 108 | return "MT_NONE "; |
||
| 109 | case MT_PHYSICS: |
||
| 110 | return "MT_PHYSICS "; |
||
| 111 | default: |
||
| 112 | return " (unknown) "; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | static ai_type_name &get_ai_behavior(ai_behavior num) |
||
| 117 | { |
||
| 118 | switch (num) { |
||
| 119 | case ai_behavior::AIB_STILL: |
||
| 120 | return "STILL "; |
||
| 121 | case ai_behavior::AIB_NORMAL: |
||
| 122 | return "NORMAL "; |
||
| 123 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 124 | case ai_behavior::AIB_HIDE: |
||
| 125 | return "HIDE "; |
||
| 126 | case ai_behavior::AIB_FOLLOW_PATH: |
||
| 127 | return "FOLLOW_PATH "; |
||
| 128 | #elif defined(DXX_BUILD_DESCENT_II) |
||
| 129 | case ai_behavior::AIB_BEHIND: |
||
| 130 | return "BEHIND "; |
||
| 131 | case ai_behavior::AIB_SNIPE: |
||
| 132 | return "SNIPE "; |
||
| 133 | case ai_behavior::AIB_FOLLOW: |
||
| 134 | return "FOLLOW "; |
||
| 135 | #endif |
||
| 136 | case ai_behavior::AIB_RUN_FROM: |
||
| 137 | return "RUN_FROM "; |
||
| 138 | default: |
||
| 139 | return " (unknown) "; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | // --------------------------------------------------------------------------------------------------- |
||
| 144 | static void info_display_object_placement(grs_canvas &canvas, int show_all) |
||
| 145 | { |
||
| 146 | auto &Objects = LevelUniqueObjectState.Objects; |
||
| 147 | static int old_Cur_object_index; |
||
| 148 | static int old_type; |
||
| 149 | static int old_movement_type; |
||
| 150 | static int old_control_type; |
||
| 151 | static ai_behavior old_mode; |
||
| 152 | if (init_info || show_all || |
||
| 153 | ( Cur_object_index != old_Cur_object_index) || |
||
| 154 | ( Objects[Cur_object_index].type != old_type) || |
||
| 155 | ( Objects[Cur_object_index].movement_type != old_movement_type) || |
||
| 156 | ( Objects[Cur_object_index].control_type != old_control_type) || |
||
| 157 | ( Objects[Cur_object_index].ctype.ai_info.behavior != old_mode) ) { |
||
| 158 | |||
| 159 | gr_uprintf(canvas, *canvas.cv_font, 0, 0, "Object id: %4d\n", Cur_object_index); |
||
| 160 | gr_uprintf(canvas, *canvas.cv_font, 0, 16, "Type: %s\n", get_object_type(Objects[Cur_object_index].type)); |
||
| 161 | gr_uprintf(canvas, *canvas.cv_font, 0, 32, "Movmnt: %s\n", get_movement_type(Objects[Cur_object_index].movement_type)); |
||
| 162 | gr_uprintf(canvas, *canvas.cv_font, 0, 48, "Cntrl: %s\n", get_control_type(Objects[Cur_object_index].control_type)); |
||
| 163 | gr_uprintf(canvas, *canvas.cv_font, 0, 64, "Mode: %s\n", get_ai_behavior(Objects[Cur_object_index].ctype.ai_info.behavior)); |
||
| 164 | |||
| 165 | old_Cur_object_index = Cur_object_index; |
||
| 166 | old_type = Objects[Cur_object_index].type; |
||
| 167 | old_movement_type = Objects[Cur_object_index].movement_type; |
||
| 168 | old_control_type = Objects[Cur_object_index].control_type; |
||
| 169 | old_mode = Objects[Cur_object_index].ctype.ai_info.behavior; |
||
| 170 | } |
||
| 171 | |||
| 172 | } |
||
| 173 | |||
| 174 | // --------------------------------------------------------------------------------------------------- |
||
| 175 | static void info_display_segsize(grs_canvas &canvas, int show_all) |
||
| 176 | { |
||
| 177 | static int old_SegSizeMode; |
||
| 178 | if (init_info | show_all) { |
||
| 179 | old_SegSizeMode = -2; |
||
| 180 | } |
||
| 181 | |||
| 182 | if (old_SegSizeMode != SegSizeMode ) { |
||
| 183 | const char *name; |
||
| 184 | switch (SegSizeMode) { |
||
| 185 | case SEGSIZEMODE_FREE: name = "free "; break; |
||
| 186 | case SEGSIZEMODE_ALL: name = "all "; break; |
||
| 187 | case SEGSIZEMODE_CURSIDE: name = "curside"; break; |
||
| 188 | case SEGSIZEMODE_EDGE: name = "edge "; break; |
||
| 189 | case SEGSIZEMODE_VERTEX: name = "vertex "; break; |
||
| 190 | default: |
||
| 191 | Error("Illegal value for SegSizeMode in info.c/info_display_segsize\n"); |
||
| 192 | } |
||
| 193 | old_SegSizeMode = SegSizeMode; |
||
| 194 | gr_uprintf(canvas, *canvas.cv_font, 0, 0, "Mode: %s\n", name); |
||
| 195 | } |
||
| 196 | |||
| 197 | } |
||
| 198 | |||
| 199 | // --------------------------------------------------------------------------------------------------- |
||
| 200 | static void info_display_default(grs_canvas &canvas, int show_all) |
||
| 201 | { |
||
| 202 | auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
||
| 203 | auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
||
| 204 | static int old_Num_segments = -1; |
||
| 205 | static int old_Num_vertices = -1; |
||
| 206 | static int old_Num_objects = -1; |
||
| 207 | static int old_Cursegp_num = -1; |
||
| 208 | static int old_Curside = -1; |
||
| 209 | static int old_Cursegp_num_for_verts = -1; |
||
| 210 | static int old_CurrentTexture = -1; |
||
| 211 | static int old_Num_walls = -1; |
||
| 212 | static int old_Num_triggers = -1; |
||
| 213 | |||
| 214 | if (init_info | show_all) { |
||
| 215 | init_info = 0; |
||
| 216 | old_Num_segments = -1; |
||
| 217 | old_Num_vertices = -1; |
||
| 218 | old_Num_objects = -1; |
||
| 219 | old_Cursegp_num = -1; |
||
| 220 | old_Cursegp_num_for_verts = -1; |
||
| 221 | old_Curside = -1; |
||
| 222 | old_CurrentTexture = -1; |
||
| 223 | old_Num_walls = -1; |
||
| 224 | old_Num_triggers = -1; |
||
| 225 | } |
||
| 226 | |||
| 227 | gr_set_fontcolor(canvas, CBLACK, CWHITE); |
||
| 228 | |||
| 229 | //--------------- Number of segments ---------------- |
||
| 230 | |||
| 231 | if (old_Num_segments != LevelSharedSegmentState.Num_segments) |
||
| 232 | { |
||
| 233 | old_Num_segments = LevelSharedSegmentState.Num_segments; |
||
| 234 | gr_uprintf(canvas, *canvas.cv_font, 0, 0, "Segments: %4d/%4" PRIuFAST32, LevelSharedSegmentState.Num_segments, static_cast<uint_fast32_t>(MAX_SEGMENTS)); |
||
| 235 | } |
||
| 236 | |||
| 237 | //---------------- Number of vertics ----------------- |
||
| 238 | |||
| 239 | if (old_Num_vertices != LevelSharedVertexState.Num_vertices) |
||
| 240 | { |
||
| 241 | old_Num_vertices = LevelSharedVertexState.Num_vertices; |
||
| 242 | gr_uprintf(canvas, *canvas.cv_font, 0, 16, "Vertices: %4d/%4" PRIuFAST32, LevelSharedVertexState.Num_vertices, static_cast<uint_fast32_t>(MAX_VERTICES)); |
||
| 243 | } |
||
| 244 | |||
| 245 | //---------------- Number of objects ----------------- |
||
| 246 | |||
| 247 | if (old_Num_objects != LevelUniqueObjectState.num_objects) |
||
| 248 | { |
||
| 249 | const auto num_objects = LevelUniqueObjectState.num_objects; |
||
| 250 | old_Num_objects = num_objects; |
||
| 251 | gr_uprintf(canvas, *canvas.cv_font, 0, 32, "Objs: %3d/%3" DXX_PRI_size_type, num_objects, MAX_OBJECTS.value); |
||
| 252 | } |
||
| 253 | |||
| 254 | //--------------- Current_segment_number ------------- |
||
| 255 | //--------------- Current_side_number ------------- |
||
| 256 | |||
| 257 | if (old_Cursegp_num != Cursegp || old_Curside != Curside) |
||
| 258 | { |
||
| 259 | old_Cursegp_num = Cursegp; |
||
| 260 | old_Curside = Curside; |
||
| 261 | gr_uprintf(canvas, *canvas.cv_font, 0, 48, "Cursegp/side: %3hu/%1d", static_cast<segnum_t>(Cursegp), Curside); |
||
| 262 | unique_segment &useg = *Cursegp; |
||
| 263 | auto &uside = useg.sides[Curside]; |
||
| 264 | gr_uprintf(canvas, *canvas.cv_font, 0, 128, " tmap1,2,o: %3d/%3dx%1d", uside.tmap_num, uside.tmap_num2 & 0x3FFF, (uside.tmap_num2 >> 14) & 3); |
||
| 265 | } |
||
| 266 | |||
| 267 | //--------------- Current_vertex_numbers ------------- |
||
| 268 | |||
| 269 | if (old_Cursegp_num_for_verts != Cursegp) |
||
| 270 | { |
||
| 271 | old_Cursegp_num_for_verts = Cursegp; |
||
| 272 | gr_uprintf(canvas, *canvas.cv_font, 0, 64, "{%3d,%3d,%3d,%3d,", Cursegp->verts[0],Cursegp->verts[1], |
||
| 273 | Cursegp->verts[2],Cursegp->verts[3] ); |
||
| 274 | gr_uprintf(canvas, *canvas.cv_font, 0, 80," %3d,%3d,%3d,%3d}", Cursegp->verts[4],Cursegp->verts[5], |
||
| 275 | Cursegp->verts[6],Cursegp->verts[7] ); |
||
| 276 | } |
||
| 277 | |||
| 278 | //--------------- Num walls/links/triggers ------------------------- |
||
| 279 | |||
| 280 | auto &Walls = LevelUniqueWallSubsystemState.Walls; |
||
| 281 | if ( old_Num_walls != Walls.get_count() ) { |
||
| 282 | old_Num_walls = Walls.get_count(); |
||
| 283 | gr_uprintf(canvas, *canvas.cv_font, 0, 96, "Walls %3d", Walls.get_count()); |
||
| 284 | } |
||
| 285 | |||
| 286 | //--------------- Num triggers ---------------------- |
||
| 287 | |||
| 288 | { |
||
| 289 | auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
||
| 290 | if ( old_Num_triggers != Triggers.get_count() ) { |
||
| 291 | old_Num_triggers = Triggers.get_count(); |
||
| 292 | gr_uprintf(canvas, *canvas.cv_font, 0, 112, "Num_triggers %2d", Triggers.get_count()); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | //--------------- Current texture number ------------- |
||
| 297 | |||
| 298 | if ( old_CurrentTexture != CurrentTexture ) { |
||
| 299 | old_CurrentTexture = CurrentTexture; |
||
| 300 | gr_uprintf(canvas, *canvas.cv_font, 0, 144, "Tex/Light: %3d %5.2f", CurrentTexture, f2fl(TmapInfo[CurrentTexture].lighting)); |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | // ------------------------------------------------------------------------------------ |
||
| 305 | static void clear_pad_display(grs_canvas &canvas) |
||
| 306 | { |
||
| 307 | gr_clear_canvas(canvas, CWHITE); |
||
| 308 | gr_set_fontcolor(canvas, CBLACK, CWHITE); |
||
| 309 | } |
||
| 310 | |||
| 311 | // ------------------------------------------------------------------------------------ |
||
| 312 | static window_event_result info_display_all(window *wind,const d_event &event, const unused_window_userdata_t *) |
||
| 313 | { |
||
| 314 | static int old_padnum = -1; |
||
| 315 | int padnum,show_all = 1; // always redraw |
||
| 316 | grs_canvas *save_canvas = grd_curcanv; |
||
| 317 | |||
| 318 | switch (event.type) |
||
| 319 | { |
||
| 320 | case EVENT_WINDOW_DRAW: |
||
| 321 | { |
||
| 322 | gr_set_current_canvas(window_get_canvas(*wind)); |
||
| 323 | auto &canvas = *grd_curcanv; |
||
| 324 | |||
| 325 | padnum = ui_pad_get_current(); |
||
| 326 | Assert(padnum <= MAX_PAD_ID); |
||
| 327 | |||
| 328 | if (padnum != old_padnum) { |
||
| 329 | old_padnum = padnum; |
||
| 330 | clear_pad_display(canvas); |
||
| 331 | //show_all = 1; |
||
| 332 | } |
||
| 333 | |||
| 334 | switch (padnum) { |
||
| 335 | case OBJECT_PAD_ID: // Object placement |
||
| 336 | info_display_object_placement(canvas, show_all); |
||
| 337 | break; |
||
| 338 | case SEGSIZE_PAD_ID: // Segment sizing |
||
| 339 | info_display_segsize(canvas, show_all); |
||
| 340 | break; |
||
| 341 | default: |
||
| 342 | info_display_default(canvas, show_all); |
||
| 343 | break; |
||
| 344 | } |
||
| 345 | grd_curcanv = save_canvas; |
||
| 346 | return window_event_result::handled; |
||
| 347 | } |
||
| 348 | case EVENT_WINDOW_CLOSE: |
||
| 349 | Pad_info = NULL; |
||
| 350 | break; |
||
| 351 | |||
| 352 | default: |
||
| 353 | break; |
||
| 354 | } |
||
| 355 | return window_event_result::ignored; |
||
| 356 | } |
||
| 357 | |||
| 358 | // ------------------------------------------------------------------------------------ |
||
| 359 | window *info_window_create(void) |
||
| 360 | { |
||
| 361 | const auto wind = window_create(*Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160, info_display_all, unused_window_userdata); |
||
| 362 | if (wind) |
||
| 363 | window_set_modal(wind, 0); |
||
| 364 | |||
| 365 | return wind; |
||
| 366 | } |
||
| 367 | |||
| 368 |