Skip to content

Commit acc5739

Browse files
committed
Add debug console command: bm_used
Reports how many bmpman slots are used, with subtotals for each image type and EFFs broken down by sub-type
1 parent e47884e commit acc5739

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

code/bmpman/bmpman.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <ctype.h>
4040
#include <limits.h>
41+
#include <iomanip>
4142

4243
// --------------------------------------------------------------------------------------------------------------------
4344
// Private macros.
@@ -292,6 +293,104 @@ DCF(bm_frag, "Shows BmpMan fragmentation") {
292293
key_getch();
293294
}
294295

296+
DCF(bm_used, "Shows BmpMan Slot Usage") {
297+
if (dc_optional_string_either("help", "--help")) {
298+
dc_printf("Displays used bmpman slots usage with a breakdown per filetype\n\n");
299+
return;
300+
}
301+
302+
int none = 0, pcx = 0, user = 0, tga = 0, png = 0; int jpg = 0, dds = 0, ani = 0;
303+
int eff = 0, eff_dds = 0, eff_tga = 0, eff_png = 0, eff_jpg = 0, eff_pcx = 0;
304+
int render_target_dynamic = 0, render_target_static = 0;
305+
306+
for (int i = 0; i<MAX_BITMAPS; i++) {
307+
switch (bm_bitmaps[i].type) {
308+
case BM_TYPE_NONE:
309+
none++;
310+
break;
311+
case BM_TYPE_PCX:
312+
pcx++;
313+
break;
314+
case BM_TYPE_USER:
315+
user++;
316+
break;
317+
case BM_TYPE_TGA:
318+
tga++;
319+
break;
320+
case BM_TYPE_PNG:
321+
// TODO distinguish png(static) from apng
322+
png++;
323+
break;
324+
case BM_TYPE_JPG:
325+
jpg++;
326+
break;
327+
case BM_TYPE_DDS:
328+
dds++;
329+
break;
330+
case BM_TYPE_ANI:
331+
ani++;
332+
break;
333+
case BM_TYPE_EFF:
334+
eff++;
335+
switch (bm_bitmaps[i].info.ani.eff.type) {
336+
case BM_TYPE_DDS:
337+
eff_dds++;
338+
break;
339+
case BM_TYPE_TGA:
340+
eff_tga++;
341+
break;
342+
case BM_TYPE_PNG:
343+
eff_png++;
344+
break;
345+
case BM_TYPE_JPG:
346+
eff_jpg++;
347+
break;
348+
case BM_TYPE_PCX:
349+
eff_pcx++;
350+
break;
351+
default:
352+
Warning(LOCATION, "Unhandled EFF image type (%i), get a coder!", bm_bitmaps[i].info.ani.eff.type);
353+
break;
354+
}
355+
break;
356+
case BM_TYPE_RENDER_TARGET_STATIC:
357+
render_target_static++;
358+
break;
359+
case BM_TYPE_RENDER_TARGET_DYNAMIC:
360+
render_target_dynamic++;
361+
break;
362+
default:
363+
Warning(LOCATION, "Unhandled image type (%i), get a coder!", bm_bitmaps[i].type);
364+
break;
365+
}
366+
}
367+
368+
SCP_stringstream text;
369+
text << "BmpMan Used Slots\n";
370+
text << " " << std::dec << std::setw(4) << std::setfill('0') << pcx << ", PCX\n";
371+
text << " " << std::dec << std::setw(4) << std::setfill('0') << user << ", User\n";
372+
text << " " << std::dec << std::setw(4) << std::setfill('0') << tga << ", TGA\n";
373+
text << " " << std::dec << std::setw(4) << std::setfill('0') << png << ", PNG\n";
374+
text << " " << std::dec << std::setw(4) << std::setfill('0') << jpg << ", JPG\n";
375+
text << " " << std::dec << std::setw(4) << std::setfill('0') << dds << ", DDS\n";
376+
text << " " << std::dec << std::setw(4) << std::setfill('0') << ani << ", ANI\n";
377+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff << ", EFF\n";
378+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff_dds << ", EFF/DDS\n";
379+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff_tga << ", EFF/TGA\n";
380+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff_png << ", EFF/PNG\n";
381+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff_jpg << ", EFF/JPG\n";
382+
text << " " << std::dec << std::setw(4) << std::setfill('0') << eff_pcx << ", EFF/PCX\n";
383+
text << " " << std::dec << std::setw(4) << std::setfill('0') << render_target_static << ", Render/Static\n";
384+
text << " " << std::dec << std::setw(4) << std::setfill('0') << render_target_dynamic << ", Render/Dynamic\n";
385+
text << " " << std::dec << std::setw(4) << std::setfill('0') << MAX_BITMAPS-none << "/" << MAX_BITMAPS << ", Total\n";
386+
text << "\n";
387+
388+
// TODO consider converting 1's to monospace to make debug console output prettier
389+
mprintf(("%s", text.str().c_str())); // log for ease for copying data
390+
dc_printf("%s", text.str().c_str()); // instant gratification
391+
}
392+
393+
295394
DCF(bmpman, "Shows/changes bitmap caching parameters and usage") {
296395
if (dc_optional_string_either("help", "--help")) {
297396
dc_printf("Usage: BmpMan [arg]\nWhere arg can be any of the following:\n");

code/globalincs/version.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "globalincs/pstypes.h"
1111
#include "globalincs/version.h"
1212

13-
#include <sstream>
14-
1513
namespace version
1614
{
1715
bool check_at_least(int major, int minor, int build, int revision)

code/globalincs/vmallocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <list>
88
#include <map>
99
#include <string>
10+
#include <sstream>
1011
#include <queue>
1112
#include <deque>
1213
#include <unordered_map>

0 commit comments

Comments
 (0)