first version working with no option to disable live reloading
This commit is contained in:
		@@ -2277,30 +2277,57 @@ static void cmdLoadCart(Console* console, const char* name)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileName)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						s32 size = 0;
 | 
				
			||||||
 | 
						void* contents = fsReadFile(fileName, &size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(buffer, 0, TIC_CODE_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(contents)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if(size > TIC_CODE_SIZE)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								char messageBuffer[256];
 | 
				
			||||||
 | 
								sprintf(messageBuffer, "\n code is larger than %i symbols\n", TIC_CODE_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								printError(console, messageBuffer);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							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)
 | 
					static void cmdInjectCode(Console* console, const char* param, const char* name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(strcmp(param, "-code") == 0)
 | 
						if(strcmp(param, "-code") == 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		s32 size = 0;
 | 
							bool loaded = loadFileIntoBuffer(console, &embed.file.code.data, name);
 | 
				
			||||||
		void* code = fsReadFile(name, &size);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		memset(embed.file.code.data, 0, sizeof(tic_code));
 | 
							if(loaded)
 | 
				
			||||||
 | 
					 | 
				
			||||||
		if(code)
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if(size > TIC_CODE_SIZE)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				char buffer[256];
 | 
					 | 
				
			||||||
				sprintf(buffer, "\n code is larger than %i symbols\n", TIC_CODE_SIZE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				printError(console, buffer);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			memcpy(embed.file.code.data, code, SDL_min(size, TIC_CODE_SIZE-1));
 | 
					 | 
				
			||||||
			SDL_free(code);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			embed.yes = true;
 | 
								embed.yes = true;
 | 
				
			||||||
			embed.fast = true;
 | 
								embed.fast = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								console->codeLiveReload.active = true;
 | 
				
			||||||
 | 
								strcpy(console->codeLiveReload.fileName, name);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -2393,6 +2420,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 +2439,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]);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user