3 ms·
>Recompiling and reloading parts of your game at run-time is quite easy in C. This is cool to hear. I've never done anything like this, but it almost sounds li
by hellofunk 11y ago
>Recompiling and reloading parts of your game at run-time is quite easy in C.
This is cool to hear. I've never done anything like this, but it almost sounds like REPL-driven development is a possibility in C?
- adrusi 11y agoCheck out the first few episodes of Casey Muratori's Handmade Hero series where he implements an extremely simple hot code reloading system in C (actually C++, but he doesn't use almost any C++ features, certainly not vtables).
- chii 11y agoif you don't want to watch the video, here is a basic overview tldw; of the technique: on every run of the game loop(usually every frame), reload a dynamically linked module (dll for windows, .so for linux), which contains the actual code you want to run every frame. The function you then invoke from the module must be passed the entire block of memory allocated for the game state. You then just recompile the dll/so module when you make a change, and the game would execute the new code on the next frame. Adding new data structures is OK as long as you don't mangle an existing data structure...but because a game can expect to work with a constant block of pre-allocated memory, this actually works fine most of the time...
- hellofunk 11y agoI assume you'd be using techniques discussed here? http://stackoverflow.com/questions/384121/creating-a-module-system-dynamic-loading-in-c http://stackoverflow.com/questions/384121/creating-a-module-...
- chii 11y agoyes - but different OS have different ways to load dynamically linked modules, and the casey video only showed the windows method. But it's basically the same, just library calls differently named.
- je42 11y agoReally great feature. But it doesn't tell anything about the quality of the code. Through out his complete series haven't seen any unittests for example. So I my book. No unittests => crappy code. His use of vtables is completely unrelated to the feature.
- crafn 11y agoIt's quite restricted still. For example changing datatypes during recompilation is problematic, at least if you don't destroy the instances before reloading, and re-instantiate afterwards. I don't bother to do that, because I see most of the value in things like tweaking game object logic repeatedly, which fits the restrictions nicely.