Skip to content

Commit 334e14b

Browse files
committed
add file headers for quicker load list generation
1 parent d0f7816 commit 334e14b

18 files changed

+92
-123
lines changed

src/audio.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uint8_t audio_init_done;
1111

1212
void audio_fini(void)
1313
{
14-
LOG("FIN: Audio fini");
14+
LOG("Audio fini");
1515
TRACE_AND_INDENT();
1616
Mix_CloseAudio();
1717
audio_init_done = false;

src/game.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void Config::fini(void)
239239

240240
void Config::reset(void)
241241
{
242-
LOG("INF: Game reset");
242+
LOG("Game reset");
243243
TRACE_AND_INDENT();
244244

245245
config_pix_height = {};
@@ -289,7 +289,7 @@ void game_config_reset(Gamep g) { g->config.reset(); }
289289

290290
Game::Game(std::string vappdata)
291291
{
292-
LOG("INF: Game load %s", vappdata.c_str());
292+
LOG("Game load %s", vappdata.c_str());
293293
TRACE_AND_INDENT();
294294

295295
auto g = this;
@@ -311,7 +311,7 @@ Game::Game(std::string vappdata)
311311

312312
void Game::init(void)
313313
{
314-
LOG("INF: Game init");
314+
LOG("Game init");
315315
TRACE_AND_INDENT();
316316

317317
set_seed();
@@ -320,7 +320,7 @@ void game_init(Gamep g) { g->init(); }
320320

321321
void Game::fini(void)
322322
{
323-
LOG("FIN: Game fini");
323+
LOG("Game fini");
324324
TRACE_AND_INDENT();
325325

326326
state_change(STATE_QUITTING, "quitting");
@@ -498,7 +498,7 @@ void Game::state_change(uint8_t new_state, const std::string &why)
498498
//
499499
// Why oh why change state
500500
//
501-
LOG("INF: Game state change: %s -> %s, reason: %s", gama_state_to_string(old_state).c_str(),
501+
LOG("Game state change: %s -> %s, reason: %s", gama_state_to_string(old_state).c_str(),
502502
gama_state_to_string(new_state).c_str(), why.c_str());
503503
TRACE_AND_INDENT();
504504

src/game_load.hpp

+13-29
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ bool Game::load(std::string file_to_load, class Game &target)
322322
int r = lzo1x_decompress((lzo_bytep) compressed, compressed_len, (lzo_bytep) uncompressed, &new_len, nullptr);
323323
if (r == LZO_E_OK && new_len == uncompressed_len) {
324324
if (! game_headers_only) {
325-
CON("INF: Loading %s, decompress %luMb -> %luMb", file_to_load.c_str(),
325+
LOG("Loading: %s, decompress %luMb -> %luMb", file_to_load.c_str(),
326326
(unsigned long) compressed_len / (1024 * 1024), (unsigned long) uncompressed_len / (1024 * 1024));
327327
}
328328
} else {
@@ -390,7 +390,7 @@ void Game::load(int slot)
390390
}
391391

392392
if (! slot_valid[ slot ]) {
393-
CON("No game at that slot.");
393+
LOG("No game at that slot.");
394394
return;
395395
}
396396

@@ -403,19 +403,11 @@ void Game::load(int slot)
403403
this_save_file = saved_dir + "saved-snapshot";
404404
}
405405

406-
LOG("-");
407-
CON("INF: Loading %s", this_save_file.c_str());
408-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
409-
LOG("v v v v v v v v v v v v v v v v v v v v v v v v v v v");
410-
406+
LOG("Loading: %s", this_save_file.c_str());
411407
g_loading = true;
412408
load(this_save_file, *this);
413409
g_loading = false;
414-
415-
LOG("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^");
416-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
417-
CON("INF: Loaded %s, seed %d", this_save_file.c_str(), seed);
418-
LOG("-");
410+
LOG("Loaded %s, seed %u", this_save_file.c_str(), seed);
419411

420412
CON("Loaded the game from %s.", this_save_file.c_str());
421413

@@ -431,19 +423,11 @@ void Game::load_snapshot(void)
431423

432424
auto this_save_file = saved_dir + "saved-snapshot";
433425

434-
LOG("-");
435-
CON("INF: Loading %s", this_save_file.c_str());
436-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
437-
LOG("v v v v v v v v v v v v v v v v v v v v v v v v v v v");
438-
426+
LOG("Loading: %s", this_save_file.c_str());
439427
g_loading = true;
440428
load(this_save_file, *this);
441429
g_loading = false;
442-
443-
LOG("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^");
444-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
445-
CON("INF: Loaded %s, seed %d", this_save_file.c_str(), seed);
446-
LOG("-");
430+
LOG("Loaded %s, seed %u", this_save_file.c_str(), seed);
447431

448432
CON("Loaded the game from %s.", this_save_file.c_str());
449433

@@ -494,7 +478,7 @@ static bool wid_load_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
494478
{
495479
int slot = c - '0';
496480
if (! slot_valid[ slot ]) {
497-
CON("No game at that slot.");
481+
LOG("No game at that slot.");
498482
} else {
499483
game->load(slot);
500484
wid_load_destroy(game);
@@ -506,7 +490,7 @@ static bool wid_load_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
506490
case SDLK_ESCAPE :
507491
{
508492
TRACE_NO_INDENT();
509-
CON("INF: Load game cancelled");
493+
LOG("Load game cancelled");
510494
wid_load_destroy(game);
511495
return true;
512496
}
@@ -531,7 +515,7 @@ static bool wid_load_key_down(Gamep g, Widp w, const struct SDL_Keysym *key)
531515

532516
static bool wid_load_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
533517
{
534-
CON("INF: Load selected slot");
518+
LOG("Load selected slot");
535519
TRACE_AND_INDENT();
536520

537521
auto slot = wid_get_int_context(w);
@@ -542,7 +526,7 @@ static bool wid_load_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
542526

543527
static bool wid_load_saved_snapshot(Gamep g, Widp w, int x, int y, uint32_t button)
544528
{
545-
CON("INF: Load snapshot");
529+
LOG("Load snapshot");
546530
TRACE_AND_INDENT();
547531

548532
game->load_snapshot();
@@ -552,7 +536,7 @@ static bool wid_load_saved_snapshot(Gamep g, Widp w, int x, int y, uint32_t butt
552536

553537
static bool wid_load_cancel(Gamep g, Widp w, int x, int y, uint32_t button)
554538
{
555-
CON("INF: Load cancel");
539+
LOG("Load cancel");
556540
TRACE_AND_INDENT();
557541

558542
wid_load_destroy(game);
@@ -561,7 +545,7 @@ static bool wid_load_cancel(Gamep g, Widp w, int x, int y, uint32_t button)
561545

562546
void Game::load_select(void)
563547
{
564-
CON("INF: Load menu");
548+
LOG("Load menu");
565549
TRACE_AND_INDENT();
566550

567551
if (wid_load) {
@@ -604,7 +588,7 @@ void Game::load_select(void)
604588
auto tmp_file = saved_dir + "saved-slot-info-" + std::to_string(slot);
605589

606590
if (slot == UI_WID_SAVE_SLOTS - 1) {
607-
tmp_file = saved_dir + "saved-snapshot";
591+
tmp_file = saved_dir + "saved-snapshot-info";
608592
}
609593

610594
auto p = wid_load->wid_text_area->wid_text_area;

src/game_save.hpp

+25-40
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ std::ostream &operator<<(std::ostream &out, Bits< const class Game & > const my)
113113

114114
bool Game::save(std::string file_to_save)
115115
{
116-
TRACE_NO_INDENT();
116+
LOG("Save: %s", file_to_save.c_str());
117+
TRACE_AND_INDENT();
118+
117119
std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
118120

119121
const class Game &c = *this;
@@ -148,7 +150,7 @@ bool Game::save(std::string file_to_save)
148150
int r
149151
= lzo1x_1_compress((lzo_bytep) uncompressed, uncompressed_len, (lzo_bytep) compressed, &compressed_len, wrkmem);
150152
if (r == LZO_E_OK) {
151-
LOG("INF: Saved as %s, compress %luMb -> %luMb", file_to_save.c_str(),
153+
LOG("Saved as %s, compress %luMb -> %luMb", file_to_save.c_str(),
152154
(unsigned long) uncompressed_len / (1024 * 1024), (unsigned long) compressed_len / (1024 * 1024));
153155
} else {
154156
ERR("LZO internal error - compression failed: %d", r);
@@ -198,7 +200,7 @@ bool Game::save(std::string file_to_save)
198200
ERR("Failed to open %s for writing: %s", file_to_save.c_str(), strerror(errno));
199201
return false;
200202
}
201-
LOG("INF: Opened [%s] for writing", file_to_save.c_str());
203+
LOG("Opened [%s] for writing", file_to_save.c_str());
202204

203205
fwrite((char *) &uncompressed_len, sizeof(uncompressed_len), 1, ofile);
204206
fwrite((char *) &cs, sizeof(cs), 1, ofile);
@@ -214,7 +216,9 @@ bool Game::save(std::string file_to_save)
214216

215217
void Game::save(int slot)
216218
{
217-
TRACE_NO_INDENT();
219+
LOG("Save slot: %d", slot);
220+
TRACE_AND_INDENT();
221+
218222
if (slot < 0) {
219223
return;
220224
}
@@ -225,56 +229,37 @@ void Game::save(int slot)
225229

226230
auto this_save_file = saved_dir + "saved-slot-info-" + std::to_string(slot);
227231

228-
LOG("-");
229-
CON("INF: Saving info only to: %s", this_save_file.c_str());
230-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
231-
LOG("v v v v v v v v v v v v v v v v v v v v v v v v v v v");
232-
232+
LOG("Saving: %s", this_save_file.c_str());
233233
game_headers_only = true;
234234
save(this_save_file);
235235
game_headers_only = false;
236236

237-
LOG("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^");
238-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
239-
CON("INF: Saved %s, seed %u", this_save_file.c_str(), seed);
240-
LOG("-");
241-
242237
this_save_file = saved_dir + "saved-slot-" + std::to_string(slot);
243238

244-
LOG("-");
245-
CON("INF: Saving levels to: %s", this_save_file.c_str());
246-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
247-
LOG("v v v v v v v v v v v v v v v v v v v v v v v v v v v");
248-
239+
LOG("Saving: %s", this_save_file.c_str());
249240
save(this_save_file);
250-
251-
LOG("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^");
252-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
253-
CON("INF: Saved %s, seed %u", this_save_file.c_str(), seed);
254-
LOG("-");
241+
LOG("Saved %s, seed %u", this_save_file.c_str(), seed);
255242

256243
CON("Saved the game to %s.", this_save_file.c_str());
257244
}
258245

259246
void Game::save_snapshot(void)
260247
{
261-
CON("Autosaving...");
248+
LOG("Save snapshot");
249+
TRACE_AND_INDENT();
262250

263-
TRACE_NO_INDENT();
251+
auto this_save_file = saved_dir + "saved-snapshot-info";
264252

265-
auto this_save_file = saved_dir + "saved-snapshot";
253+
LOG("Saving: %s", this_save_file.c_str());
254+
game_headers_only = true;
255+
save(this_save_file);
256+
game_headers_only = true;
266257

267-
LOG("-");
268-
CON("INF: Saving %s", this_save_file.c_str());
269-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
270-
LOG("v v v v v v v v v v v v v v v v v v v v v v v v v v v");
258+
this_save_file = saved_dir + "saved-snapshot";
271259

260+
LOG("Saving: %s", this_save_file.c_str());
272261
save(this_save_file);
273-
274-
LOG("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^");
275-
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
276-
CON("INF: Saved %s, seed %u", this_save_file.c_str(), seed);
277-
LOG("-");
262+
LOG("Saved %s, seed %u", this_save_file.c_str(), seed);
278263

279264
CON("%%fg=green$Autosaved.%%fg=reset$");
280265
}
@@ -288,7 +273,7 @@ void Game::save_config(void)
288273
ERR("Failed to open %s for writing: %s", filename.c_str(), strerror(errno));
289274
return;
290275
}
291-
LOG("INF: Opened [%s] for writing", filename.c_str());
276+
LOG("Opened [%s] for writing", filename.c_str());
292277
const Config &c = game->config;
293278
out << bits(c);
294279
}
@@ -347,7 +332,7 @@ static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
347332
case SDLK_ESCAPE :
348333
{
349334
TRACE_NO_INDENT();
350-
CON("INF: Save game cancelled");
335+
LOG("Save game cancelled");
351336
wid_save_destroy(game);
352337
return true;
353338
}
@@ -388,7 +373,7 @@ static bool wid_save_cancel(Gamep g, Widp w, int x, int y, uint32_t button)
388373

389374
void Game::save_select(void)
390375
{
391-
CON("INF: Save menu");
376+
LOG("Save menu");
392377
TRACE_AND_INDENT();
393378

394379
if (wid_save) {
@@ -399,7 +384,7 @@ void Game::save_select(void)
399384
int menu_width = UI_WID_POPUP_WIDTH_WIDE;
400385
point outer_tl(TERM_WIDTH / 2 - (menu_width / 2), TERM_HEIGHT / 2 - (menu_height / 2));
401386
point outer_br(TERM_WIDTH / 2 + (menu_width / 2), TERM_HEIGHT / 2 + (menu_height / 2));
402-
wid_save = new WidPopup(game, "Game load", outer_tl, outer_br, nullptr, "", false, false);
387+
wid_save = new WidPopup(game, "Game save", outer_tl, outer_br, nullptr, "", false, false);
403388

404389
wid_set_on_key_up(game, wid_save->wid_popup_container, wid_save_key_up);
405390
wid_set_on_key_down(game, wid_save->wid_popup_container, wid_save_key_down);

src/log.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ static void sdl_msgerr_(const char *fmt, va_list args)
390390
vsnprintf(buf, MAXLONGSTR, fmt, args);
391391

392392
#if SDL_MAJOR_VERSION >= 2
393-
CON("INF: Show SDL message box");
393+
CON("Show SDL message box");
394394
//
395395
// The window is needed else the box appears behind the main window.
396396
//
397397
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "gorget", buf, sdl.window);
398-
CON("INF: Launched SDL message box");
398+
CON("Launched SDL message box");
399399
#endif
400400
}
401401

src/main.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ static bool seed_manually_set {};
4040

4141
void quit(Gamep *g_in)
4242
{
43-
LOG("FIN: Quitting, start cleanup");
43+
LOG("Quitting, start cleanup");
4444
TRACE_AND_INDENT();
4545

4646
Gamep g = *g_in;
4747
*g_in = nullptr;
4848

4949
if (g_quitting) {
50-
LOG("FIN: Quitting, nested");
50+
LOG("Quitting, nested");
5151
return;
5252
}
5353

@@ -125,7 +125,7 @@ void quit(Gamep *g_in)
125125
}
126126
#endif
127127

128-
LOG("FIN: Cleanup done");
128+
LOG("Cleanup done");
129129
}
130130

131131
void restart(Gamep g)
@@ -151,7 +151,7 @@ void restart(Gamep g)
151151
executable = (char *) "gorget.exe";
152152
#endif
153153

154-
CON("FIN: Run \"%s\"", executable);
154+
CON("Run \"%s\"", executable);
155155
if (g_opt_debug1) {
156156
sdl_flush_display(g, true);
157157
}
@@ -861,17 +861,17 @@ int main(int argc, char *argv[])
861861

862862
TRACE_NO_INDENT();
863863
sdl_loop(g);
864-
LOG("FIN: SDL loop finished");
864+
LOG("SDL loop finished");
865865
flush_the_console(g);
866866

867867
if (g_need_restart) {
868868
g_need_restart = false;
869869
restart(g);
870870
}
871871

872-
CON("FIN: Quit");
872+
CON("Quit");
873873
quit(&g);
874874

875-
CON("FIN: Goodbye my friend and take care until next time!");
875+
CON("Goodbye my friend and take care until next time!");
876876
return 0;
877877
}

0 commit comments

Comments
 (0)