Skip to content

Commit

Permalink
Implement "resume reload" command. (#2609)
Browse files Browse the repository at this point in the history
* Implement "resume reload" command.

When resuming, you can pass "reload" as the argument, which causes the
cart's code to be reloaded before resuming the game.

This allows for a much smoother iterative development style where you
can pause the game, make changes, and see the effect of those changes
without restarting the game. It does require some special handling in
the cart to support saving state to a global and avoiding that state
being reinitialized if it's already set; for instance:

    state = state or {x=25, y=100, shots={}}

This implements it in a way that will be supported by any script that
already supports eval.

* Don't try to eval in fennel if the VM hasn't been initialized.
  • Loading branch information
technomancy authored Jun 2, 2024
1 parent 43a0317 commit 921d5e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/fennel.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ static void evalFennel(tic_mem* tic, const char* code) {
tic_core* core = (tic_core*)tic;
lua_State* fennel = core->currentVM;

/* if we proceed with an uninitialized VM it will segfault; however */
/* it could be better just to initialize here when needed instead! */
if (!fennel) return;

lua_settop(fennel, 0);

if (luaL_loadbuffer(fennel, execute_fennel_src, strlen(execute_fennel_src), "execute_fennel") != LUA_OK)
Expand Down
17 changes: 17 additions & 0 deletions src/studio/screens/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,23 @@ static void onRunCommand(Console* console)

static void onResumeCommand(Console* console)
{
if(console->desc->count)
{
const char* param = console->desc->params->key;

if(strcmp(param, "reload") == 0)
{
const tic_script* script_config = tic_get_script(console->tic);
if (script_config->eval)
{
script_config->eval(console->tic, console->tic->cart.code.data);
}
else
{
printError(console, "eval not implemented for the script");
}
}
}
commandDone(console);

resumeGame(console->studio);
Expand Down

0 comments on commit 921d5e6

Please sign in to comment.