Files
dusk/src/dusk/engine/engine.c
T
YourWishesandClaude Sonnet 5 93554b39ba Add DUSK_TRACK_MEMORY allocation tracker and memoryCheckUnfreed report
memoryAllocate() becomes a macro capturing __FILE__/__LINE__ into a
fixed-size tracking table when DUSK_TRACK_MEMORY is enabled (Linux only
for now), so a leak surviving to shutdown can be traced back to its call
site. Replaces engineDispose's hard assertTrue with memoryCheckUnfreed(),
which reports unfreed allocations (with call sites when tracking is on,
just a count otherwise) instead of aborting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-13 09:19:24 -05:00

115 lines
2.4 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "engine.h"
#include "util/memory.h"
#include "perf/perf.h"
#include "time/time.h"
#include "input/input.h"
#include "locale/localemanager.h"
#include "rpg/rpg.h"
#include "display/display.h"
#include "scene/scene.h"
#include "asset/asset.h"
#include "ui/ui.h"
#include "assert/assert.h"
#ifdef DUSK_NETWORK
#include "network/network.h"
#endif
#include "system/system.h"
#include "console/console.h"
#include "save/save.h"
#include "audio/audio.h"
#include "audio/mixer/audiomixer.h"
engine_t ENGINE;
errorret_t engineInit(const int32_t argc, const char_t **argv) {
assertInit();
memoryZero(&ENGINE, sizeof(engine_t));
ENGINE.running = true;
ENGINE.argc = argc;
ENGINE.argv = argv;
ENGINE.version = DUSK_VERSION;
// Init systems. Order is important.
perfInit();
timeInit();
consoleInit();
errorChain(systemInit());
errorChain(inputInit());
errorChain(assetInit());
errorChain(saveInit());
errorChain(localeManagerInit());
errorChain(displayInit());
errorChain(audioInit());
errorChain(uiInit());
errorChain(rpgInit());
#ifdef DUSK_NETWORK
errorChain(networkInit());
#endif
errorChain(sceneInit());
consolePrint("Engine initialized");
#ifdef DUSK_ASSERTIONS_FAKED
consolePrint("Assertions faked");
#else
consolePrint("Assertions real");
#endif
sceneSet(SCENE_TYPE_INITIAL);
errorOk();
}
errorret_t engineUpdate(void) {
// Order here is important.
#ifdef DUSK_NETWORK
errorChain(networkUpdate());
#endif
errorChain(saveUpdate());
timeUpdate();
inputUpdate();
consoleUpdate();
errorChain(audioUpdateEarly());
errorChain(rpgUpdate());
errorChain(sceneUpdate());
errorChain(assetUpdate());
errorChain(uiUpdate());
// Render
errorChain(displayUpdate());
errorChain(audioUpdateLate());
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
errorOk();
}
void engineExit(void) {
ENGINE.running = false;
}
errorret_t engineDispose(void) {
errorChain(sceneDispose());
#ifdef DUSK_NETWORK
errorChain(networkDispose());
#endif
errorChain(rpgDispose());
localeManagerDispose();
errorChain(uiDispose());
errorChain(audioDispose());
consoleDispose();
errorChain(displayDispose());
errorChain(saveDispose());
errorChain(assetDispose());
perfDispose();
memoryCheckUnfreed();
errorOk();
}