mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
Deferred loading of save files
This commit is contained in:
@@ -162,6 +162,8 @@ typedef unsigned int pixel;
|
||||
typedef unsigned char uint8;
|
||||
|
||||
extern int saveURIOpen;
|
||||
extern char * saveDataOpen;
|
||||
extern int saveDataOpenSize;
|
||||
|
||||
extern int amd;
|
||||
|
||||
|
@@ -233,6 +233,7 @@ static void CustomApplicationMain (int argc, char **argv)
|
||||
|
||||
#endif
|
||||
|
||||
void *file_load(char *fn, int *size);
|
||||
|
||||
/*
|
||||
* Catch document open requests...this lets us notice files when the app
|
||||
@@ -251,15 +252,15 @@ static void CustomApplicationMain (int argc, char **argv)
|
||||
*/
|
||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||
{
|
||||
const char *temparg;
|
||||
/*const char *temparg;
|
||||
size_t arglen;
|
||||
char *arg;
|
||||
char **newargv;
|
||||
|
||||
if (!gFinderLaunch) /* MacOS is passing command line args. */
|
||||
if (!gFinderLaunch)
|
||||
return FALSE;
|
||||
|
||||
if (gCalledAppMainline) /* app has started, ignore this document. */
|
||||
if (gCalledAppMainline)
|
||||
return FALSE;
|
||||
|
||||
temparg = [filename UTF8String];
|
||||
@@ -280,7 +281,24 @@ static void CustomApplicationMain (int argc, char **argv)
|
||||
gArgv[gArgc++] = "open";
|
||||
gArgv[gArgc++] = arg;
|
||||
gArgv[gArgc] = NULL;
|
||||
return TRUE;
|
||||
return TRUE;*/
|
||||
const char * tempArg;
|
||||
char * arg;
|
||||
size_t argLen;
|
||||
tempArg = [filename UTF8String];
|
||||
argLen = SDL_strlen(tempArg)+1;
|
||||
arg = (char *) SDL_malloc(argLen);
|
||||
if (arg == NULL)
|
||||
return FALSE;
|
||||
SDL_strlcpy(arg, tempArg, argLen);
|
||||
|
||||
saveDataOpen = file_load(arg, &saveDataOpenSize);
|
||||
if(saveDataOpen)
|
||||
return TRUE;
|
||||
|
||||
saveDataOpen = NULL;
|
||||
saveDataOpenSize = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
||||
|
@@ -820,7 +820,7 @@ void draw_svf_ui(pixel *vid_buf, int alternate)// all the buttons at the bottom
|
||||
}
|
||||
|
||||
// the reload button
|
||||
c = (svf_open || svf_fileopen) ? 255 : 128;
|
||||
c = (svf_last) ? 255 : 128;
|
||||
drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255);
|
||||
drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255);
|
||||
|
||||
|
61
src/main.c
61
src/main.c
@@ -203,6 +203,8 @@ char new_message_msg[255];
|
||||
float mheat = 0.0f;
|
||||
|
||||
int saveURIOpen = 0;
|
||||
char * saveDataOpen = NULL;
|
||||
int saveDataOpenSize = 0;
|
||||
|
||||
int do_open = 0;
|
||||
int sys_pause = 0;
|
||||
@@ -830,6 +832,11 @@ int main(int argc, char *argv[])
|
||||
argc = i+2;
|
||||
break;
|
||||
}
|
||||
else if (!strncmp(argv[i], "open", 5) && i+1<argc)
|
||||
{
|
||||
saveDataOpen = file_load(argv[i+1], &saveDataOpenSize);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
load_presets();
|
||||
@@ -875,26 +882,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (!strncmp(argv[i], "open", 5) && i+1<argc)
|
||||
{
|
||||
int size;
|
||||
void *file_data;
|
||||
file_data = file_load(argv[i+1], &size);
|
||||
if (file_data)
|
||||
{
|
||||
svf_last = file_data;
|
||||
svf_lsize = size;
|
||||
if(!parse_save(file_data, size, 1, 0, 0, bmap, fvx, fvy, vx, vy, pv, signs, parts, pmap))
|
||||
{
|
||||
it=0;
|
||||
svf_filename[0] = 0;
|
||||
svf_fileopen = 1;
|
||||
} else {
|
||||
saveOpenError = 1;
|
||||
svf_last = NULL;
|
||||
svf_lsize = 0;
|
||||
free(file_data);
|
||||
file_data = NULL;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
|
||||
@@ -979,6 +966,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if(saveOpenError)
|
||||
{
|
||||
saveOpenError = 0;
|
||||
error_ui(vid_buf, 0, "Unable to open save file.");
|
||||
}
|
||||
|
||||
@@ -1129,6 +1117,37 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
do_check = (do_check+1) & 15;
|
||||
}
|
||||
if (saveDataOpen)
|
||||
{
|
||||
//Clear all settings and simulation data
|
||||
clear_sim();
|
||||
it=0;
|
||||
legacy_enable = 0;
|
||||
svf_filename[0] = 0;
|
||||
svf_fileopen = 0;
|
||||
svf_myvote = 0;
|
||||
svf_open = 0;
|
||||
svf_publish = 0;
|
||||
svf_own = 0;
|
||||
svf_id[0] = 0;
|
||||
svf_name[0] = 0;
|
||||
svf_tags[0] = 0;
|
||||
svf_description[0] = 0;
|
||||
gravityMode = 0;
|
||||
airMode = 0;
|
||||
|
||||
svf_last = saveDataOpen;
|
||||
svf_lsize = saveDataOpenSize;
|
||||
if(parse_save(saveDataOpen, saveDataOpenSize, 1, 0, 0, bmap, fvx, fvy, vx, vy, pv, signs, parts, pmap))
|
||||
{
|
||||
saveOpenError = 1;
|
||||
svf_last = NULL;
|
||||
svf_lsize = 0;
|
||||
free(saveDataOpen);
|
||||
}
|
||||
saveDataOpenSize = 0;
|
||||
saveDataOpen = NULL;
|
||||
}
|
||||
if (http_session_check)
|
||||
{
|
||||
if (!do_s_check && http_async_req_status(http_session_check))
|
||||
@@ -2280,7 +2299,7 @@ int main(int argc, char *argv[])
|
||||
memset(fire_b, 0, sizeof(fire_b));
|
||||
}
|
||||
}
|
||||
if (x>=19 && x<=35 && svf_last && (svf_open || svf_fileopen) && !bq) {
|
||||
if (x>=19 && x<=35 && svf_last && !bq) {
|
||||
//int tpval = sys_pause;
|
||||
parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
|
||||
//sys_pause = tpval;
|
||||
|
Reference in New Issue
Block a user