1
0
Fork 0
forked from fte/fteqw

Fixes saved games.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3563 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2010-07-25 15:06:38 +00:00
parent d745c39e8a
commit 0f5a25025d
3 changed files with 32 additions and 19 deletions

View file

@ -502,7 +502,7 @@ void LoadModelsAndSounds(vfsfile_t *f)
*sv.strings.sound_precache[i] = 0; *sv.strings.sound_precache[i] = 0;
} }
qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers) qboolean SV_LoadLevelCache(char *savename, char *level, char *startspot, qboolean ignoreplayers)
{ {
eval_t *eval, *e2; eval_t *eval, *e2;
@ -542,7 +542,10 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
gametype = cache->gametype; gametype = cache->gametype;
sprintf (name, "saves/%s", level); if (savename)
sprintf (name, "saves/%s/%s", savename, level);
else
sprintf (name, "saves/%s", level);
COM_DefaultExtension (name, ".lvc", sizeof(name)); COM_DefaultExtension (name, ".lvc", sizeof(name));
// Con_TPrintf (STL_LOADGAMEFROM, name); // Con_TPrintf (STL_LOADGAMEFROM, name);
@ -743,7 +746,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
return true; //yay return true; //yay
} }
void SV_SaveLevelCache(qboolean dontharmgame) void SV_SaveLevelCache(char *savedir, qboolean dontharmgame)
{ {
int len; int len;
char *s; char *s;
@ -779,7 +782,10 @@ void SV_SaveLevelCache(qboolean dontharmgame)
} }
sprintf (name, "saves/%s", cache->mapname); if (savedir)
sprintf (name, "saves/%s/%s", savedir, cache->mapname);
else
sprintf (name, "saves/%s", cache->mapname);
COM_DefaultExtension (name, ".lvc", sizeof(name)); COM_DefaultExtension (name, ".lvc", sizeof(name));
FS_CreatePath(name, FS_GAMEONLY); FS_CreatePath(name, FS_GAMEONLY);
@ -795,6 +801,7 @@ void SV_SaveLevelCache(qboolean dontharmgame)
if (!FS_NativePath(name, FS_GAMEONLY, syspath, sizeof(syspath))) if (!FS_NativePath(name, FS_GAMEONLY, syspath, sizeof(syspath)))
return; return;
ge->WriteLevel(syspath); ge->WriteLevel(syspath);
FS_FlushFSHash();
return; return;
} }
#endif #endif
@ -875,10 +882,13 @@ void SV_SaveLevelCache(qboolean dontharmgame)
VFS_PRINTF (f,"\n"); VFS_PRINTF (f,"\n");
s = PR_SaveEnts(svprogfuncs, NULL, &len, 1); s = PR_SaveEnts(svprogfuncs, NULL, &len, 1);
VFS_PRINTF(f, "%s\n", s); VFS_PUTS(f, s);
VFS_PUTS(f, "\n");
svprogfuncs->parms->memfree(s); svprogfuncs->parms->memfree(s);
VFS_CLOSE (f); VFS_CLOSE (f);
FS_FlushFSHash();
} }
#ifdef NEWSAVEFORMAT #ifdef NEWSAVEFORMAT
@ -927,7 +937,7 @@ void SV_Savegame_f (void)
savefilename = va("saves/%s/info.fsv", savename); savefilename = va("saves/%s/info.fsv", savename);
FS_CreatePath(savefilename, FS_GAMEONLY); FS_CreatePath(savefilename, FS_GAMEONLY);
f = FS_OpenVFS(savefilename, "wt", FS_GAMEONLY); f = FS_OpenVFS(savefilename, "wb", FS_GAMEONLY);
if (!f) if (!f)
{ {
Con_Printf("Couldn't open file saves/%s/info.fsv\n", savename); Con_Printf("Couldn't open file saves/%s/info.fsv\n", savename);
@ -955,7 +965,7 @@ void SV_Savegame_f (void)
Q_strncpyz(str, svs.info, sizeof(str)); Q_strncpyz(str, svs.info, sizeof(str));
Info_RemovePrefixedKeys(str, '*'); Info_RemovePrefixedKeys(str, '*');
VFS_PRINTF (f, "%s\"\n", str); VFS_PRINTF (f, "%s\n", str);
Q_strncpyz(str, localinfo, sizeof(str)); Q_strncpyz(str, localinfo, sizeof(str));
Info_RemovePrefixedKeys(str, '*'); Info_RemovePrefixedKeys(str, '*');
@ -985,23 +995,26 @@ void SV_Savegame_f (void)
VFS_PRINTF (f, "set nextserver \"%s\"\n", Cvar_Get("nextserver", "", 0, "")->string); VFS_PRINTF (f, "set nextserver \"%s\"\n", Cvar_Get("nextserver", "", 0, "")->string);
VFS_PRINTF (f, "}\n"); VFS_PRINTF (f, "}\n");
SV_SaveLevelCache(true); //add the current level. Note that this can cause reentry problems.
cache = svs.levcache; //state from previous levels - just copy it all accross. cache = svs.levcache; //state from previous levels - just copy it all accross.
VFS_PRINTF(f, "{\n"); VFS_PRINTF(f, "{\n");
while(cache) while(cache)
{ {
VFS_PRINTF(f, "%s\n", cache->mapname); VFS_PRINTF(f, "%s\n", cache->mapname);
if (strcmp(cache->mapname, sv.name))
FS_Copy(va("saves/%s.lvc", cache->mapname), va("saves/%s/%s.lvc", savename, cache->mapname), FS_GAME, FS_GAME); {
FS_Copy(va("saves/%s.lvc", cache->mapname), va("saves/%s/%s.lvc", savename, cache->mapname), FS_GAME, FS_GAME);
}
cache = cache->next; cache = cache->next;
} }
VFS_PRINTF(f, "}\n"); VFS_PRINTF(f, "}\n");
SV_SaveLevelCache(savename, true); //add the current level.
VFS_PRINTF (f, "%s\n", sv.name); VFS_PRINTF (f, "%s\n", sv.name);
VFS_CLOSE(f); VFS_CLOSE(f);
FS_FlushFSHash();
} }
void SV_Loadgame_f (void) void SV_Loadgame_f (void)
@ -1025,7 +1038,7 @@ void SV_Loadgame_f (void)
strcpy(savename, "quicksav"); strcpy(savename, "quicksav");
sprintf (filename, "saves/%s/info.fsv", savename); sprintf (filename, "saves/%s/info.fsv", savename);
f = FS_OpenVFS (filename, "rt", FS_GAME); f = FS_OpenVFS (filename, "rb", FS_GAME);
if (!f) if (!f)
{ {
Con_TPrintf (STL_ERRORCOULDNTOPEN); Con_TPrintf (STL_ERRORCOULDNTOPEN);
@ -1189,7 +1202,7 @@ void SV_Loadgame_f (void)
VFS_CLOSE(f); VFS_CLOSE(f);
SV_LoadLevelCache(str, "", true); SV_LoadLevelCache(savename, str, "", true);
sv.allocated_client_slots = slots; sv.allocated_client_slots = slots;
} }
#endif #endif

View file

@ -933,8 +933,8 @@ void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg);
void SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, unsigned int protext); void SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, unsigned int protext);
void SV_SaveSpawnparms (qboolean); void SV_SaveSpawnparms (qboolean);
void SV_SaveLevelCache(qboolean dontharmgame); void SV_SaveLevelCache(char *savename, qboolean dontharmgame);
qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers); qboolean SV_LoadLevelCache(char *savename, char *level, char *startspot, qboolean ignoreplayers);
void SV_Physics_Client (edict_t *ent, int num); void SV_Physics_Client (edict_t *ent, int num);

View file

@ -560,7 +560,7 @@ void SV_Map_f (void)
savedinuse[i] = svs.clients[i].q2edict->inuse; savedinuse[i] = svs.clients[i].q2edict->inuse;
svs.clients[i].q2edict->inuse = false; svs.clients[i].q2edict->inuse = false;
} }
SV_SaveLevelCache(false); SV_SaveLevelCache(NULL, false);
for (i=0 ; i<sv.allocated_client_slots; i++) for (i=0 ; i<sv.allocated_client_slots; i++)
{ {
svs.clients[i].q2edict->inuse = savedinuse[i]; svs.clients[i].q2edict->inuse = savedinuse[i];
@ -568,7 +568,7 @@ void SV_Map_f (void)
} }
else else
#endif #endif
SV_SaveLevelCache(false); SV_SaveLevelCache(NULL, false);
} }
#ifdef Q3SERVER #ifdef Q3SERVER
@ -603,7 +603,7 @@ void SV_Map_f (void)
SV_BroadcastCommand ("changing \"%s\"\n", level); SV_BroadcastCommand ("changing \"%s\"\n", level);
SV_SendMessagesToAll (); SV_SendMessagesToAll ();
if (newunit || !startspot || !SV_LoadLevelCache(level, startspot, false)) if (newunit || !startspot || !SV_LoadLevelCache(NULL, level, startspot, false))
{ {
if (waschangelevel && !startspot) if (waschangelevel && !startspot)
startspot = ""; startspot = "";