mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
First iteration of autosave
This commit is contained in:
parent
7fbb90771d
commit
26c9f12dca
2 changed files with 83 additions and 0 deletions
69
Quake/host.c
69
Quake/host.c
|
@ -644,6 +644,75 @@ void Host_ServerFrame (void)
|
|||
|
||||
// send all messages to the clients
|
||||
SV_SendClientMessages ();
|
||||
|
||||
// Autosave stuff
|
||||
|
||||
static double oldhealth = 0;
|
||||
static double lastautosave = 0;
|
||||
static int autosaveindex = 0;
|
||||
static char *autosavemap[2];
|
||||
static double autosavetime[2];
|
||||
static const float AUTOSAVE_DURATION = 30;
|
||||
static const float AUTOSAVE_SAFETY_MARGIN = 10;
|
||||
static const float AUTOSAVE_SAFE_HEALTH = 65;
|
||||
|
||||
if (!deathmatch.value && !coop.value && !sv.paused &&
|
||||
sv.active && !cl.intermission && svs.maxclients == 1)
|
||||
{
|
||||
// Reset the last autosave time if it is out of bounds (i.e. we changed
|
||||
// maps)
|
||||
if (lastautosave > sv.time)
|
||||
{
|
||||
lastautosave = 0;
|
||||
}
|
||||
|
||||
if (oldhealth > 0 && sv_player->v.health <= 0 &&
|
||||
(sv.time - lastautosave) <= AUTOSAVE_SAFETY_MARGIN)
|
||||
{
|
||||
// Player just died within a few seconds of an autosave, so
|
||||
// replace that autosave with the backup (if one exists)
|
||||
fprintf(stderr, "Invalidate last autosave");
|
||||
}
|
||||
|
||||
if ((sv.time - lastautosave) > AUTOSAVE_DURATION)
|
||||
{
|
||||
// Eligible for autosave
|
||||
if (sv_player->v.health >= AUTOSAVE_SAFE_HEALTH)
|
||||
{
|
||||
// If we have plenty of health, save right now
|
||||
fprintf(stderr, "Healthy autosave");
|
||||
|
||||
Cmd_ExecuteString ("save quick", src_command);
|
||||
lastautosave = sv.time;
|
||||
}
|
||||
else if (sv_player->v.health > oldhealth)
|
||||
{
|
||||
fprintf(stderr, "Unhealthy, just got health autosave");
|
||||
// If we have less than AUTOSAVE_SAFE_HEALTH, only save if we just
|
||||
// picked up a healthpack
|
||||
Cmd_ExecuteString ("save quick", src_command);
|
||||
lastautosave = sv.time;
|
||||
// FIXME: picking up 15 health when we have 1 might not warrant
|
||||
// an autosave
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldhealth = sv_player->v.health;
|
||||
|
||||
/*
|
||||
if (ericw % 100 == 0)
|
||||
{
|
||||
fprintf(stderr, "1000 frames. server time: %lf\n", sv.time);
|
||||
if (ericw % 300 == 0)
|
||||
{
|
||||
if (!sv.paused)
|
||||
{
|
||||
fprintf(stderr, "autosaving...\n");
|
||||
Cmd_ExecuteString ("save quick", src_command);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -885,6 +885,7 @@ void Host_Changelevel_f (void)
|
|||
key_dest = key_game; // remove console or menu
|
||||
SV_SaveSpawnparms ();
|
||||
strcpy (level, Cmd_Argv(1));
|
||||
fprintf(stderr, "Host_Changelevel_f '%s'\n", level);
|
||||
SV_SpawnServer (level);
|
||||
}
|
||||
|
||||
|
@ -906,6 +907,19 @@ void Host_Restart_f (void)
|
|||
return;
|
||||
strcpy (mapname, sv.name); // must copy out, because it gets cleared
|
||||
// in sv_spawnserver
|
||||
|
||||
fprintf(stderr, "Host_Restart_f '%s' health %lf\n", mapname, sv_player->v.health);
|
||||
|
||||
// Autosave stuff
|
||||
|
||||
if (!deathmatch.value && !coop.value && !sv.paused &&
|
||||
sv.active && !cl.intermission && svs.maxclients == 1)
|
||||
{
|
||||
//if (0 == strcmp(mapname, autosavemap[autosaveindex]))
|
||||
Cmd_ExecuteString ("load quick", src_command);
|
||||
return;
|
||||
}
|
||||
|
||||
SV_SpawnServer (mapname);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue