Merge pull request #340 from matheuslessarodrigues/tic_0.47.0

Tic 0.47.0
This commit is contained in:
Vadim Grigoruk 2017-10-17 08:58:11 +03:00 committed by GitHub
commit 335d8cb65e
3 changed files with 211 additions and 158 deletions

View File

@ -2277,30 +2277,61 @@ static void cmdLoadCart(Console* console, const char* name)
} }
} }
static void cmdInjectCode(Console* console, const char* param, const char* name) static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileName)
{
if(strcmp(param, "-code") == 0)
{ {
s32 size = 0; s32 size = 0;
void* code = fsReadFile(name, &size); void* contents = fsReadFile(fileName, &size);
memset(embed.file.code.data, 0, sizeof(tic_code)); if(contents)
if(code)
{ {
memset(buffer, 0, TIC_CODE_SIZE);
if(size > TIC_CODE_SIZE) if(size > TIC_CODE_SIZE)
{ {
char buffer[256]; char messageBuffer[256];
sprintf(buffer, "\n code is larger than %i symbols\n", TIC_CODE_SIZE); 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)); memcpy(buffer, contents, SDL_min(size, TIC_CODE_SIZE-1));
SDL_free(code); SDL_free(contents);
embed.yes = true; embed.yes = true;
embed.fast = 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, .start = 0,
.active = false, .active = false,
}, },
.codeLiveReload =
{
.active = false,
.reload = tryReloadCode,
},
.inputPosition = 0, .inputPosition = 0,
.history = NULL, .history = NULL,
.historyHead = 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->buffer, 0, CONSOLE_BUFFER_SIZE);
memset(console->colorBuffer, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE); memset(console->colorBuffer, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE);
memset(console->codeLiveReload.fileName, 0, FILENAME_MAX);
if(argc) if(argc)
{ {
strcpy(console->appPath, argv[0]); strcpy(console->appPath, argv[0]);

View File

@ -61,6 +61,14 @@ struct Console
bool active; bool active;
} scroll; } scroll;
struct
{
char fileName[FILENAME_MAX];
bool active;
void(*reload)(Console*, char*);
} codeLiveReload;
char* buffer; char* buffer;
u8* colorBuffer; u8* colorBuffer;

View File

@ -1739,6 +1739,13 @@ SDL_Event* pollEvent()
switch(event.window.event) switch(event.window.event)
{ {
case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break; 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; break;
case SDL_FINGERUP: case SDL_FINGERUP: