Implemented only for linux/macos
C++ hot reload setup.
- Reusable runtime module:
src/hot_reload_runtime.h,src/hot_reload_runtime.cpp - Host entrypoint using runtime:
src/main.cpp - Reloadable game module:
src/game_module.cpp - Shared API contract:
src/hot_reload_api.h
How it works:
- The host app starts once and keeps the window/app loop alive.
- Game logic is compiled as a dynamic library (
mygame_game). - The host detects changes to the dynamic library and reloads it at runtime.
- Existing game state memory is preserved when possible.
Default controls:
F5= force a reload check.- Automatic file timestamp polling is also enabled.
- Source edits in
src/now trigger automatic background rebuild of<project>_game, then runtime reload.
To adapt this template for another project:
- Keep
src/hot_reload_api.has the shared ABI between host and module. - Add
src/hot_reload_runtime.h/.cppto your host executable target. - Put gameplay code into
src/game_module.cppcallbacks (on_load,on_update,on_unload). - Keep engine/app lifecycle in
src/main.cppand callHotReloadRuntime::tickfrom the main loop. - Rename the CMake project name as usual; the dynamic library target follows
<project>_game.
src/main.cpp:
#include <cute.h>
#include "hot_reload_runtime.h"
using namespace Cute;
int main(int argc, char* argv[])
{
CF_Result result = make_app("Hot Reload", 0, 0, 0, 640, 480,
CF_APP_OPTIONS_WINDOW_POS_CENTERED_BIT | CF_APP_OPTIONS_RESIZABLE_BIT,
argv[0]);
if (is_error(result)) return -1;
HotReloadRuntimeConfig cfg{};
cfg.argv0 = argv[0] ? argv[0] : "";
cfg.module_filename = HOT_RELOAD_MODULE_FILENAME;
cfg.module_basename = HOT_RELOAD_MODULE_BASENAME;
cfg.source_dir = HOT_RELOAD_SOURCE_DIR;
cfg.build_dir = HOT_RELOAD_BUILD_DIR;
HotReloadRuntime runtime(cfg);
if (!runtime.is_loaded()) return -2;
while (app_is_running()) {
app_update();
CF_GameHostContext host{ CF_DELTA_TIME };
runtime.tick(host, key_just_pressed(CF_KEY_F5));
app_draw_onto_screen(true);
}
destroy_app();
return 0;
}CMakeLists.txt (host target):
add_executable(${PROJECT_NAME}
src/main.cpp
src/hot_reload_runtime.cpp
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
HOT_RELOAD_MODULE_FILENAME="${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}_game${CMAKE_SHARED_LIBRARY_SUFFIX}"
HOT_RELOAD_MODULE_BASENAME="${PROJECT_NAME}_game"
HOT_RELOAD_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
HOT_RELOAD_BUILD_DIR="${CMAKE_BINARY_DIR}"
)