From 828eb7f82a4321485f8f0d7ef7bb8c53603cd341 Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Fri, 3 Oct 2014 23:12:43 +0200 Subject: [PATCH] Don't save ControlTick and SyncRate in network savegames (#1058). --- src/control/C4GameSave.cpp | 2 +- src/game/C4Game.cpp | 19 +++++++++++-------- src/game/C4Game.h | 9 +++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/control/C4GameSave.cpp b/src/control/C4GameSave.cpp index f2034db13..e89e0d490 100644 --- a/src/control/C4GameSave.cpp +++ b/src/control/C4GameSave.cpp @@ -191,7 +191,7 @@ bool C4GameSave::SaveRuntimeData() { // Game.txt data (general runtime data and objects) C4ValueNumbers numbers; - if (!Game.SaveData(*pSaveGroup, false, IsExact(), &numbers)) + if (!Game.SaveData(*pSaveGroup, false, IsExact(), IsSynced(), &numbers)) { Log(LoadResStr("IDS_ERR_SAVE_RUNTIMEDATA")); return false; } // scenario sections (exact only) if (IsExact()) if (!SaveScenarioSections()) diff --git a/src/game/C4Game.cpp b/src/game/C4Game.cpp index a727868ed..3fdc4159e 100644 --- a/src/game/C4Game.cpp +++ b/src/game/C4Game.cpp @@ -1584,8 +1584,11 @@ void C4Game::CompileFunc(StdCompiler *pComp, CompileSettings comp, C4ValueNumber pComp->Name("Game"); pComp->Value(mkNamingAdapt(Time, "Time", 0)); pComp->Value(mkNamingAdapt(FrameCounter, "Frame", 0)); - pComp->Value(mkNamingAdapt(Control.ControlTick, "ControlTick", 0)); - pComp->Value(mkNamingAdapt(Control.SyncRate, "SyncRate", C4SyncCheckRate)); + if (comp.fSync) + { + pComp->Value(mkNamingAdapt(Control.ControlTick, "ControlTick", 0)); + pComp->Value(mkNamingAdapt(Control.SyncRate, "SyncRate", C4SyncCheckRate)); + } pComp->Value(mkNamingAdapt(iTick2, "Tick2", 0)); pComp->Value(mkNamingAdapt(iTick3, "Tick3", 0)); pComp->Value(mkNamingAdapt(iTick5, "Tick5", 0)); @@ -1672,11 +1675,11 @@ void C4Game::CompileFunc(StdCompiler *pComp, CompileSettings comp, C4ValueNumber pComp->NameEnd(); } -bool C4Game::CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, C4ValueNumbers * numbers) +bool C4Game::CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, bool sync, C4ValueNumbers * numbers) { ::Objects.Clear(!fLoadSection); GameText.Load(hGroup,C4CFN_Game); - CompileSettings Settings(fLoadSection, false, exact); + CompileSettings Settings(fLoadSection, false, exact, sync); // C4Game is not defaulted on compilation. // Loading of runtime data overrides only certain values. // Doesn't compile players; those will be done later @@ -1696,13 +1699,13 @@ bool C4Game::CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, return true; } -bool C4Game::SaveData(C4Group &hGroup, bool fSaveSection, bool fSaveExact, C4ValueNumbers * numbers) +bool C4Game::SaveData(C4Group &hGroup, bool fSaveSection, bool fSaveExact, bool fSaveSync, C4ValueNumbers * numbers) { if (fSaveExact) { StdStrBuf Buf; // Decompile (without players for scenario sections) - DecompileToBuf_Log(mkParAdapt(*this, CompileSettings(fSaveSection, !fSaveSection && fSaveExact, fSaveExact), numbers), &Buf, "Game"); + DecompileToBuf_Log(mkParAdapt(*this, CompileSettings(fSaveSection, !fSaveSection && fSaveExact, fSaveExact, fSaveSync), numbers), &Buf, "Game"); // Clear alternate saving method hGroup.Delete(C4CFN_ScenarioObjectsScript); @@ -2153,7 +2156,7 @@ bool C4Game::InitGame(C4Group &hGroup, bool fLoadSection, bool fLoadSky, C4Value if (!fLoadSection) InitValueOverloads(); // runtime data - if (!CompileRuntimeData(hGroup, fLoadSection, C4S.Head.SaveGame, numbers)) + if (!CompileRuntimeData(hGroup, fLoadSection, C4S.Head.SaveGame, C4S.Head.NetworkGame, numbers)) { LogFatal(LoadResStr("IDS_PRC_FAIL")); return false; } SetInitProgress(93); @@ -3322,7 +3325,7 @@ bool C4Game::LoadScenarioSection(const char *szSection, DWORD dwFlags) { C4ValueNumbers numbers; // objects: do not save info objects or inactive objects - if (!SaveData(*pGrp,true,false, &numbers)) + if (!SaveData(*pGrp,true,false, false, &numbers)) { DebugLog("LoadScenarioSection: Error saving objects"); return false; diff --git a/src/game/C4Game.h b/src/game/C4Game.h index 37768b81a..60dfa9ae0 100644 --- a/src/game/C4Game.h +++ b/src/game/C4Game.h @@ -35,9 +35,10 @@ private: bool fScenarioSection; bool fPlayers; bool fExact; + bool fSync; - CompileSettings(bool fScenarioSection, bool fPlayers, bool fExact) - : fScenarioSection(fScenarioSection), fPlayers(fPlayers), fExact(fExact) { } + CompileSettings(bool fScenarioSection, bool fPlayers, bool fExact, bool fSync) + : fScenarioSection(fScenarioSection), fPlayers(fPlayers), fExact(fExact), fSync(fSync) { } }; // struct of keyboard set and indexed control key @@ -264,9 +265,9 @@ protected: bool PlaceInEarth(C4ID id); public: void CompileFunc(StdCompiler *pComp, CompileSettings comp, C4ValueNumbers *); - bool SaveData(C4Group &hGroup, bool fSaveSection, bool fSaveExact, C4ValueNumbers *); + bool SaveData(C4Group &hGroup, bool fSaveSection, bool fSaveExact, bool fSaveSync, C4ValueNumbers *); protected: - bool CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, C4ValueNumbers *); + bool CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, bool sync, C4ValueNumbers *); bool StoreParticipantPlayers(); bool RecreatePlayerFiles();