Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
Show All 39 Lines | |||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "ps/World.h" | |||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include <fstream> | #include <fstream> | ||||
#include <iomanip> | #include <iomanip> | ||||
#include <memory> | #include <memory> | ||||
class CSimulation2Impl | class CSimulation2Impl | ||||
{ | { | ||||
public: | public: | ||||
CSimulation2Impl(CUnitManager* unitManager, std::shared_ptr<ScriptContext> cx, CTerrain* terrain) : | CSimulation2Impl(std::shared_ptr<ScriptContext> cx, CWorld* world) : | ||||
m_SimContext(), m_ComponentManager(m_SimContext, cx), | m_SimContext(), m_ComponentManager(m_SimContext, cx), | ||||
m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | ||||
m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext()) | m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext()) | ||||
{ | { | ||||
m_SimContext.m_UnitManager = unitManager; | m_SimContext.m_UnitManager = &world->GetUnitManager(); | ||||
m_SimContext.m_Terrain = terrain; | m_SimContext.m_Terrain = world->GetTerrain(); | ||||
m_SimContext.m_World = world; | |||||
m_ComponentManager.LoadComponentTypes(); | m_ComponentManager.LoadComponentTypes(); | ||||
RegisterFileReloadFunc(ReloadChangedFileCB, this); | RegisterFileReloadFunc(ReloadChangedFileCB, this); | ||||
// Tests won't have config initialised | // Tests won't have config initialised | ||||
if (CConfigDB::IsInitialised()) | if (CConfigDB::IsInitialised()) | ||||
{ | { | ||||
CFG_GET_VAL("ooslog", m_EnableOOSLog); | CFG_GET_VAL("ooslog", m_EnableOOSLog); | ||||
▲ Show 20 Lines • Show All 558 Lines • ▼ Show 20 Lines | void CSimulation2Impl::DumpState() | ||||
m_ComponentManager.DumpDebugState(file, true); | m_ComponentManager.DumpDebugState(file, true); | ||||
std::ofstream binfile (OsString(path.ChangeExtension(L".dat")).c_str(), std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); | std::ofstream binfile (OsString(path.ChangeExtension(L".dat")).c_str(), std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); | ||||
m_ComponentManager.SerializeState(binfile); | m_ComponentManager.SerializeState(binfile); | ||||
} | } | ||||
//////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////// | ||||
CSimulation2::CSimulation2(CUnitManager* unitManager, std::shared_ptr<ScriptContext> cx, CTerrain* terrain) : | CSimulation2::CSimulation2(std::shared_ptr<ScriptContext> cx, CWorld* world) : | ||||
phosit: Should be passed by reference. nullptr would lead to UB. | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsMh, conceptually I'd rather not, because the simulation should be able to exist without the world. What UB are you referring to ? wraitii: Mh, conceptually I'd rather not, because the simulation should be able to exist without the… | |||||
phositUnsubmitted Done Inline ActionsThe constructor of CSimulation2Impl calls -> on it. phosit: The constructor of CSimulation2Impl calls -> on it. | |||||
wraitiiAuthorUnsubmitted Done Inline Actionsfixed that wraitii: fixed that | |||||
m(new CSimulation2Impl(unitManager, cx, terrain)) | m(new CSimulation2Impl(cx, world)) | ||||
{ | { | ||||
} | } | ||||
CSimulation2::~CSimulation2() | CSimulation2::~CSimulation2() | ||||
{ | { | ||||
delete m; | delete m; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Should be passed by reference. nullptr would lead to UB.