Skip to content

lindi0v/cpp-cute-framework-hot-reload-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cute Framework Hot Reload PoC

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:

  1. The host app starts once and keeps the window/app loop alive.
  2. Game logic is compiled as a dynamic library (mygame_game).
  3. The host detects changes to the dynamic library and reloads it at runtime.
  4. 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:

  1. Keep src/hot_reload_api.h as the shared ABI between host and module.
  2. Add src/hot_reload_runtime.h/.cpp to your host executable target.
  3. Put gameplay code into src/game_module.cpp callbacks (on_load, on_update, on_unload).
  4. Keep engine/app lifecycle in src/main.cpp and call HotReloadRuntime::tick from the main loop.
  5. Rename the CMake project name as usual; the dynamic library target follows <project>_game.

Minimal usage example

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}"
)

About

Cute Framework hot reload PoC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors