Well hot-loading is sort of not an entry level thing, per se, but it’s not difficult, just probably not what I’d start with - go make a few fun silly small games first
Hot-reloading that I’ve used personally is resources/data only, not c/c++ recompiling on the fly (though that is also possible). So either the game code watches for file change notifications, or polls files for changes, or has UI to force reload of object(s).
The data is reloaded from file (“entity_typename.data”) into the entity type’s “template” of sorts (for those created in future) and applied across all current entity instances in the scene of that type. Various resources are referenced in this template: sounds, animation frames, textures, etc.
So at a high-level the texture is swapped, base property values are updated (each instance can apply modifier values to these), some other properties are updated in whole (overwritten), new animation frame sets are swapped with old, etc.
I’ve added videos from handmade hero and j.blow’s Jai development for some current examples.
(sorry the rest is quite long, I should probably move this onto my blog and link)
If I started a new game (medium to larger, year+ long project) I’d want to start with some of these things right up front.
- Hot reloading of data (maps, entity, localization, etc)
- Heavily data-driven (again while scripting makes things easier initially, just making all data/properties modifiable without re-compiling gets you 80-90% of what scripting provides in most cases I’ve worked with where Lua/JS was used)
- In-Game UI to modify data/properties/scene as well that allows save/load (and versioning)
- Quake-style console either hooked up to CCConsole commands, or written from scratch (or open source code)
Handmade Hero Hot-Recompile in C99 (but c++ compiler for a few extra features)
For a look at how one can in fact do hot-reload of actual code while debugging (or technically in released build on platforms where executing data is allowed) you can check out handmade hero’s videos:
I think if you look at week 5 on this link those videos may also have some notes.
Note: I really don’t recommend this for anyone using cocos2d-x. If you really wanted this with c++ go use Unreal instead.
However, in general I do believe people think scripting languages are some golden ticket when in fact they really just wanted data files and an in-game editor with hot-reloading of these assets. An external editor can be used, but if you use an in-game editor with save/load then you don’t need the actual live reloading, for the most part.
Coincidentally Jonathan Blow just did some streams on this exact very subject (see below). He doesn’t go into the platform layer file notification, but you can use libfswatch (https://github.com/emcrisostomo/fswatch) to hook up the capability. He also develops the console using immediate mode GUI ideas. You could use imGUI to use similar code, but otherwise you’d have to figure out how to best apply the state onto the cocos::ui::Widgets if you use them for the quake console.
One key aspect I’ve found makes this easier with cocos2d-x is that we have game entity state separated from the Node* derived rendering instances. We update the Node* (et al) properties (position, sprite frame, etc) from the state. This means we only use Actions for menus and effects (particles, etc), but we do use the internal tween:: functions.
Cocos2d-x has a highly coupled data design, especially if you use Actions and such for manipulating state. We manually update spriteFrames for our animations by keeping frame index and anything else we need to set current sprite frame, for example. This allows us to hot-reload the prefix/frame-index-list and have a character on screen change to use the new animation texture/frames associated with the current running state (e.g. “walking”).
Cocos2d-x does have a limited console-like experience that can be used by telnetting into the game remotely. You can see the implementation in CCConsole.cpp
Archived Twitch Stream Videos
- These are long and unedited archives of him live streaming on Twitch
- I wouldn’t watch straight through unless you were very interested in his new language
- He’s mostly streaming to show his progress on his new programming language JAI
- He does a little C++ here and there when he’s debugging his JAI compiler
Hot-Reload Global State - variables, in his terms, you can extrapolate this out to loading data into a game entity
Initial Quake Console UI (6 parts - mostly again I’d expect it to be uninteresting for you)
Adding simple Commands
Playlist where these exist (some others)