Skip to content

Commit

Permalink
- fixed the 'frozen level' handling and did some cleanup on the sessi…
Browse files Browse the repository at this point in the history
…on data in savegames.

The handling for the two frozen flags was totally inconsistent.
Furthermore, these need to be session data, not level data.
The old exported variables for this still exist and shadow the real state, but are deprecated now.
Frozen state should only be checked with "currentSession.isFrozen()" now.

The session data in the savegame was grouped and separated from the global state, which onl consists of server CVARs and RNG state now.
  • Loading branch information
coelckers committed Jan 12, 2019
1 parent 9f1aedd commit 9099dc6
Show file tree
Hide file tree
Showing 34 changed files with 378 additions and 352 deletions.
1 change: 1 addition & 0 deletions src/actor.h
Expand Up @@ -1487,6 +1487,7 @@ class AActor : public DThinker
void DeleteAttachedLights();
static void DeleteAllAttachedLights();
static void RecreateAllAttachedLights();
bool isFrozen();

bool hasmodel;
};
Expand Down
22 changes: 22 additions & 0 deletions src/actorinlines.h
Expand Up @@ -96,6 +96,28 @@ inline double AActor::AttackOffset(double offset)

}

inline bool AActor::isFrozen()
{
if (!(flags5 & MF5_NOTIMEFREEZE))
{
auto state = currentSession->isFrozen();
if (state)
{
if (player == nullptr || player->Bot != nullptr) return true;

// This is the only place in the entire game where the two freeze flags need different treatment.
// The time freezer flag also freezes other players, the global setting does not.

if ((state & 1) && player->timefreezer == 0)
{
return true;
}
}
}
return false;
}


class FActorIterator
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/b_bot.cpp
Expand Up @@ -139,7 +139,7 @@ void DBot::Tick ()
{
Super::Tick ();

if (player->mo == nullptr || Level->freeze)
if (player->mo == nullptr || currentSession->isFrozen())
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/b_game.cpp
Expand Up @@ -138,7 +138,7 @@ void FCajunMaster::Main(FLevelLocals *Level)
return;

//Add new bots?
if (wanted_botnum > botnum && !Level->freeze)
if (wanted_botnum > botnum && !currentSession->isFrozen())
{
if (t_join == ((wanted_botnum - botnum) * SPAWN_DELAY))
{
Expand Down
8 changes: 4 additions & 4 deletions src/decallib.cpp
Expand Up @@ -1178,7 +1178,7 @@ void DDecalFader::Tick ()
}
else
{
if (Level->maptime < TimeToStartDecay || Level->freeze)
if (Level->maptime < TimeToStartDecay || currentSession->isFrozen())
{
return;
}
Expand Down Expand Up @@ -1265,7 +1265,7 @@ void DDecalStretcher::Tick ()
Destroy ();
return;
}
if (Level->maptime < TimeToStart || Level->freeze)
if (Level->maptime < TimeToStart || currentSession->isFrozen())
{
return;
}
Expand Down Expand Up @@ -1333,7 +1333,7 @@ void DDecalSlider::Tick ()
Destroy ();
return;
}
if (Level->maptime < TimeToStart || Level->freeze)
if (Level->maptime < TimeToStart || currentSession->isFrozen())
{
return;
}
Expand Down Expand Up @@ -1401,7 +1401,7 @@ void DDecalColorer::Tick ()
}
else
{
if (Level->maptime < TimeToStartDecay || Level->freeze)
if (Level->maptime < TimeToStartDecay || currentSession->isFrozen())
{
return;
}
Expand Down
4 changes: 0 additions & 4 deletions src/doomstat.cpp
Expand Up @@ -67,10 +67,6 @@ CUSTOM_CVAR (String, language, "auto", CVAR_ARCHIVE)
// [RH] Network arbitrator
int Net_Arbitrator = 0;

int NextSkill = -1;

int SinglePlayerClass[MAXPLAYERS];

bool ToggleFullscreen;

FString LumpFilterIWAD;
5 changes: 0 additions & 5 deletions src/doomstat.h
Expand Up @@ -68,7 +68,6 @@ extern FString StoredWarp; // [RH] +warp at the command line

// Selected by user.
EXTERN_CVAR (Int, gameskill);
extern int NextSkill; // [RH] Skill to use at next level load

// Netgame? Only true if >1 player.
extern bool netgame;
Expand All @@ -91,10 +90,6 @@ EXTERN_CVAR (Bool, teamplay)
// [RH] Friendly fire amount
EXTERN_CVAR (Float, teamdamage)

// [RH] The class the player will spawn as in single player,
// in case using a random class with Hexen.
extern int SinglePlayerClass[/*MAXPLAYERS*/];

// -------------------------
// Internal parameters for sound rendering.

Expand Down
59 changes: 19 additions & 40 deletions src/g_game.cpp
Expand Up @@ -73,7 +73,6 @@
#include "dobjgc.h"
#include "gi.h"

#include "g_hub.h"
#include "g_levellocals.h"
#include "events.h"

Expand All @@ -95,7 +94,6 @@ void G_DoWorldDone (void);
void G_DoSaveGame (bool okForQuicksave, FString filename, const char *description);
void G_DoAutoSave ();

void STAT_Serialize(FSerializer &file);
bool WriteZip(const char *filename, TArray<FString> &filenames, TArray<FCompressedBuffer> &content);

FIntCVar gameskill ("skill", 2, CVAR_SERVERINFO|CVAR_LATCH);
Expand Down Expand Up @@ -1886,30 +1884,23 @@ void G_DoLoadGame ()
return;
}


// Read intermission data for hubs
G_SerializeHub(arc);

bglobal.RemoveAllBots(true);

// read the global state
FString cvar;
arc("importantcvars", cvar);
if (!cvar.IsEmpty())
{
uint8_t *vars_p = (uint8_t *)cvar.GetChars();
C_ReadCVars(&vars_p);
}
FRandom::StaticReadRNGState(arc);

uint32_t time[2] = { 1,0 };

arc("ticrate", time[0])
("leveltime", time[1]);
// dearchive all the modifications
currentSession->time = Scale(time[1], TICRATE, time[0]);
// Read the session data
currentSession->SerializeSession(arc);

G_ReadSnapshots(resfile.get());
resfile.reset(nullptr); // we no longer need the resource file below this point
G_ReadVisited(arc);

// load a base level
savegamerestore = true; // Use the player actors in the savegame
Expand All @@ -1918,13 +1909,6 @@ void G_DoLoadGame ()
demoplayback = demoplaybacksave;
savegamerestore = false;

STAT_Serialize(arc);
FRandom::StaticReadRNGState(arc);
P_ReadACSDefereds(arc);
P_ReadACSVars(arc);

NextSkill = -1;
arc("nextskill", NextSkill);

// Delete all snapshots that were created for the currently active levels.
ForAllLevels([](FLevelLocals *Level)
Expand Down Expand Up @@ -2113,7 +2097,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio

char buf[100];

bool checkok = gamestate != GS_LEVEL;
bool checkok = gamestate == GS_LEVEL;

ForAllLevels([&](FLevelLocals *Level) {

Expand All @@ -2124,6 +2108,12 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio
}
});

if (!checkok)
{
Printf("Cannot save outside a level\n");
return;
}

if (demoplayback)
{
filename = G_BuildSaveName ("demosave." SAVEGAME_EXT, -1);
Expand Down Expand Up @@ -2194,32 +2184,14 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio
PutSaveWads (savegameinfo);
PutSaveComment (savegameinfo);

// Intermission stats for hubs
G_SerializeHub(savegameglobals);

{
FString vars = C_GetMassCVarString(CVAR_SERVERINFO);
savegameglobals.AddString("importantcvars", vars.GetChars());
}

if (currentSession->time != 0)
{
int tic = TICRATE;
savegameglobals("ticrate", tic);
savegameglobals("leveltime", currentSession->time);
}

STAT_Serialize(savegameglobals);
FRandom::StaticWriteRNGState(savegameglobals);
P_WriteACSDefereds(savegameglobals);
P_WriteACSVars(savegameglobals);
G_WriteVisited(savegameglobals);

currentSession->SerializeSession(savegameglobals);

if (NextSkill != -1)
{
savegameglobals("nextskill", NextSkill);
}

auto picdata = savepic.GetBuffer();
FCompressedBuffer bufpng = { picdata->Size(), picdata->Size(), METHOD_STORED, 0, static_cast<unsigned int>(crc32(0, &(*picdata)[0], picdata->Size())), (char*)&(*picdata)[0] };
Expand All @@ -2238,6 +2210,13 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio

savegameManager.NotifyNewSave (filename, description, okForQuicksave);


// delete the JSON buffers we created just above. Everything else will
// either still be needed or taken care of automatically.
savegame_content[1].Clean();
savegame_content[2].Clean();


// Check whether the file is ok by trying to open it.
FResourceFile *test = FResourceFile::OpenResourceFile(filename, true);
if (test != nullptr)
Expand Down
45 changes: 1 addition & 44 deletions src/g_hub.cpp
Expand Up @@ -34,7 +34,6 @@
*/

#include "doomstat.h"
#include "g_hub.h"
#include "g_level.h"
#include "g_game.h"
#include "m_png.h"
Expand All @@ -44,39 +43,7 @@
#include "g_levellocals.h"


//==========================================================================
//
// Player is leaving the current level
//
//==========================================================================

struct FHubInfo
{
int levelnum;

int maxkills;
int maxitems;
int maxsecret;
int maxfrags;

wbplayerstruct_t plyr[MAXPLAYERS];

FHubInfo &operator=(const wbstartstruct_t &wbs)
{
levelnum = wbs.finished_ep;
maxkills = wbs.maxkills;
maxsecret= wbs.maxsecret;
maxitems = wbs.maxitems;
maxfrags = wbs.maxfrags;
memcpy(plyr, wbs.plyr, sizeof(plyr));
return *this;
}
};


static TArray<FHubInfo> hubdata;

void G_LeavingHub(int mode, cluster_info_t * cluster, wbstartstruct_t * wbs, FLevelLocals *Level)
void FGameSession::LeavingHub(int mode, cluster_info_t * cluster, wbstartstruct_t * wbs, FLevelLocals *Level)
{
unsigned int i, j;

Expand Down Expand Up @@ -176,13 +143,3 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FHubInfo &h, FHubInfo
}
return arc;
}

void G_SerializeHub(FSerializer &arc)
{
arc("hubinfo", hubdata);
}

void G_ClearHubInfo()
{
hubdata.Clear();
}
13 changes: 0 additions & 13 deletions src/g_hub.h

This file was deleted.

0 comments on commit 9099dc6

Please sign in to comment.