summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-01 19:34:17 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-01 19:34:17 (GMT)
commit939265a77de93fd6e9b5136ad948fc16ce077918 (patch)
tree431f525f5f62482c282fd7d3155f883905b6eb04 /src
parent8dcccbc4fce604664fd353101bbc2b669b1f83cb (diff)
downloadpowder-939265a77de93fd6e9b5136ad948fc16ce077918.zip
powder-939265a77de93fd6e9b5136ad948fc16ce077918.tar.gz
Deferred loading of save files
Diffstat (limited to 'src')
-rw-r--r--src/SDLMain.m26
-rw-r--r--src/interface.c2
-rw-r--r--src/main.c61
3 files changed, 63 insertions, 26 deletions
diff --git a/src/SDLMain.m b/src/SDLMain.m
index 3298fc2..bca2253 100644
--- a/src/SDLMain.m
+++ b/src/SDLMain.m
@@ -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
diff --git a/src/interface.c b/src/interface.c
index 6ee5974..689ef13 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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);
diff --git a/src/main.c b/src/main.c
index a21f11a..a7da674 100644
--- a/src/main.c
+++ b/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;