added live cart reloading #374

This commit is contained in:
BADIM-PC\Vadim 2017-11-21 19:47:36 +03:00
parent f4808d40d4
commit 31929e5550
3 changed files with 49 additions and 1 deletions

View File

@ -731,6 +731,25 @@ static bool loadProject(Console* console, const char* data, s32 size, tic_cartri
return done; return done;
} }
static void updateProject(Console* console)
{
tic_mem* tic = console->tic;
if(strlen(console->romName))
{
s32 size = 0;
void* data = fsLoadFile(console->fs, console->romName, &size);
if(data)
{
loadProject(console, data, size, &tic->cart);
SDL_free(data);
studioRomLoaded();
}
}
}
static bool hasExt(const char* name, const char* ext) static bool hasExt(const char* name, const char* ext)
{ {
return strcmp(name + strlen(name) - strlen(ext), ext) == 0; return strcmp(name + strlen(name) - strlen(ext), ext) == 0;
@ -2721,10 +2740,11 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
#if defined(TIC80_PRO) #if defined(TIC80_PRO)
.loadProject = loadProject, .loadProject = loadProject,
.updateProject = updateProject,
#else #else
.loadProject = NULL, .loadProject = NULL,
.updateProject = NULL,
#endif #endif
.error = error, .error = error,
.trace = trace, .trace = trace,
.tick = tick, .tick = tick,

View File

@ -92,6 +92,7 @@ struct Console
void(*load)(Console*, const char* name); void(*load)(Console*, const char* name);
bool(*loadProject)(Console*, const char* data, s32 size, tic_cartridge* dst); bool(*loadProject)(Console*, const char* data, s32 size, tic_cartridge* dst);
void(*updateProject)(Console*);
void(*error)(Console*, const char*); void(*error)(Console*, const char*);
void(*trace)(Console*, const char*, u8 color); void(*trace)(Console*, const char*, u8 color);
void(*tick)(Console*); void(*tick)(Console*);

View File

@ -760,6 +760,8 @@ void exitFromGameMenu()
{ {
setStudioMode(TIC_CONSOLE_MODE); setStudioMode(TIC_CONSOLE_MODE);
} }
studio.console.showGameMenu = false;
} }
void setStudioMode(EditorMode mode) void setStudioMode(EditorMode mode)
@ -1680,6 +1682,12 @@ static void processMouseInput()
studio.tic->ram.vram.input.gamepad.pressed = studio.mouse.state->down ? 1 : 0; studio.tic->ram.vram.input.gamepad.pressed = studio.mouse.state->down ? 1 : 0;
} }
static void reloadConfirm(bool yes, void* data)
{
if(yes)
studio.console.updateProject(&studio.console);
}
SDL_Event* pollEvent() SDL_Event* pollEvent()
{ {
static SDL_Event event; static SDL_Event event;
@ -1721,6 +1729,25 @@ SDL_Event* pollEvent()
{ {
case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break; case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
#if defined(TIC80_PRO)
if(studio.mode != TIC_START_MODE && studioCartChanged())
{
static const char* Rows[] =
{
"",
"CART HAS CHANGED!",
"",
"DO YOU WANT",
"TO RELOAD IT?"
};
showDialog(Rows, COUNT_OF(Rows), reloadConfirm, NULL);
}
else studio.console.updateProject(&studio.console);
#endif
{ {
studio.console.codeLiveReload.reload(&studio.console,studio.code.data); studio.console.codeLiveReload.reload(&studio.console,studio.code.data);
if(studio.code.update) if(studio.code.update)