Merge pull request #340 from matheuslessarodrigues/tic_0.47.0
Tic 0.47.0
This commit is contained in:
commit
335d8cb65e
|
@ -2277,30 +2277,61 @@ static void cmdLoadCart(Console* console, const char* name)
|
|||
}
|
||||
}
|
||||
|
||||
static void cmdInjectCode(Console* console, const char* param, const char* name)
|
||||
{
|
||||
if(strcmp(param, "-code") == 0)
|
||||
static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileName)
|
||||
{
|
||||
s32 size = 0;
|
||||
void* code = fsReadFile(name, &size);
|
||||
void* contents = fsReadFile(fileName, &size);
|
||||
|
||||
memset(embed.file.code.data, 0, sizeof(tic_code));
|
||||
|
||||
if(code)
|
||||
if(contents)
|
||||
{
|
||||
memset(buffer, 0, TIC_CODE_SIZE);
|
||||
|
||||
if(size > TIC_CODE_SIZE)
|
||||
{
|
||||
char buffer[256];
|
||||
sprintf(buffer, "\n code is larger than %i symbols\n", TIC_CODE_SIZE);
|
||||
char messageBuffer[256];
|
||||
sprintf(messageBuffer, "\n code is larger than %i symbols\n", TIC_CODE_SIZE);
|
||||
|
||||
printError(console, buffer);
|
||||
printError(console, messageBuffer);
|
||||
}
|
||||
|
||||
memcpy(embed.file.code.data, code, SDL_min(size, TIC_CODE_SIZE-1));
|
||||
SDL_free(code);
|
||||
memcpy(buffer, contents, SDL_min(size, TIC_CODE_SIZE-1));
|
||||
SDL_free(contents);
|
||||
|
||||
embed.yes = true;
|
||||
embed.fast = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void tryReloadCode(Console* console, char* codeBuffer)
|
||||
{
|
||||
if(console->codeLiveReload.active)
|
||||
{
|
||||
const char* fileName = console->codeLiveReload.fileName;
|
||||
loadFileIntoBuffer(console, codeBuffer, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
static void cmdInjectCode(Console* console, const char* param, const char* name)
|
||||
{
|
||||
bool watch = strcmp(param, "-code-watch") == 0;
|
||||
if(strcmp(param, "-code") == 0 || watch)
|
||||
{
|
||||
bool loaded = loadFileIntoBuffer(console, &embed.file.code.data, name);
|
||||
|
||||
if(loaded)
|
||||
{
|
||||
embed.yes = true;
|
||||
embed.fast = true;
|
||||
|
||||
if(watch)
|
||||
{
|
||||
console->codeLiveReload.active = true;
|
||||
strcpy(console->codeLiveReload.fileName, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2393,6 +2424,11 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
|
|||
.start = 0,
|
||||
.active = false,
|
||||
},
|
||||
.codeLiveReload =
|
||||
{
|
||||
.active = false,
|
||||
.reload = tryReloadCode,
|
||||
},
|
||||
.inputPosition = 0,
|
||||
.history = NULL,
|
||||
.historyHead = NULL,
|
||||
|
@ -2407,6 +2443,8 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
|
|||
memset(console->buffer, 0, CONSOLE_BUFFER_SIZE);
|
||||
memset(console->colorBuffer, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE);
|
||||
|
||||
memset(console->codeLiveReload.fileName, 0, FILENAME_MAX);
|
||||
|
||||
if(argc)
|
||||
{
|
||||
strcpy(console->appPath, argv[0]);
|
||||
|
|
|
@ -61,6 +61,14 @@ struct Console
|
|||
bool active;
|
||||
} scroll;
|
||||
|
||||
struct
|
||||
{
|
||||
char fileName[FILENAME_MAX];
|
||||
bool active;
|
||||
|
||||
void(*reload)(Console*, char*);
|
||||
} codeLiveReload;
|
||||
|
||||
char* buffer;
|
||||
u8* colorBuffer;
|
||||
|
||||
|
|
|
@ -1739,6 +1739,13 @@ SDL_Event* pollEvent()
|
|||
switch(event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
{
|
||||
studio.console.codeLiveReload.reload(&studio.console,studio.code.data);
|
||||
if(studio.code.update)
|
||||
studio.code.update(&studio.code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERUP:
|
||||
|
|
Loading…
Reference in New Issue