A library for doing live-reloading game development.
This is inspired by the article "Interactive Programming in C" by Chris Wellons, and the video "Loading Game Code Dynamically" from Handmade Hero by Casey Muratori.
The general idea is that your main host program is a wrapper around a dynamic library that does all the interesting work of your game. This means that you can simply reload the library while the game is still running, and have your game update live. As a consequence however, you can't have any global state in your library, everything must be owned by the host in order to avoid getting unloaded with the library.
Currently, this library doesn't provide a good solution for calling back into the wrapper code, which you want to do for things like allocating memory. That will hopefully come in a new version of the crate very soon.
See the Host Example and Library Example sections for instructions on how to build a reloadable application.
Host Example
A program that hosts a reloadable library will need to load the library, and
then periodically reload it. The Reloadable automatically installs a
filesystem watcher for you so that it knows when the library file has been
updated or replaced, and the reload method will only actually perform
a reload if the file has changed. The core of your main loop will therefore
usually look something like this:
use thread;
Library Example
A live-reloadable library needs to register its entry-points so that the
host program can find them. The [live_reload!][] macro lets you do this
conveniently.
The lifecycle of your reloadable library will happen in a few stages:
initgets called at the very beginning of the program, when the host starts for the first time.reloadgets called on each library load, including the first time. This should be usually empty, but when you're in development, you might want to reset things here, or migrate data, or things like that. The pointer you're passed will refer to the same struct that you had when the previous library was unloaded, so it might not be properly initialized. You should try to make your struct be#[repr(C)], and only add members at the end to minimize the problems of reloading.updategets called at the host program's discretion. You'll probably end up calling this once per frame. In addition to doing whatever work you were interested in,updatealso returns a value indicating whether the host program should quit.unloadgets called before a library unloads. This will probably be empty even more often thanreload, but you might need it for some debugging or data migration purpose.deinitgets called when the host program is actually shutting down--it's called on the drop of theReloadable.
Here's an example of a live-reloadable library that handles a counter.
extern crate live_reload;
#
use ShouldQuit;
live_reload!