Don't use std::shared_ptr<ScriptContext> in the CSimulation2
Since 1bccfef6fb
the `CSimulation2` uses the `std::shared_ptr` only in
the constructor and stores a `ScriptContext&` (inside it's members).
That's a bit dangerous: A caller might think `CSimulation2` takes
ownership of the `ScriptContext`.
With this commit the caller has to pass an `ScriptContext&` to the
constructor.
Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5223
This was SVN commit r28046.
This commit is contained in:
parent
1b3e8a0218
commit
6b31999b64
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -28,7 +28,7 @@ class TestLOSTexture : public CxxTest::TestSuite
|
||||
public:
|
||||
void test_basic()
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, NULL);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, nullptr};
|
||||
CLOSTexture tex(sim);
|
||||
|
||||
const ssize_t size = 8;
|
||||
@ -67,7 +67,7 @@ public:
|
||||
|
||||
void test_perf_DISABLED()
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, NULL);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, nullptr};
|
||||
CLOSTexture tex(sim);
|
||||
|
||||
const ssize_t size = 257;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -181,7 +181,7 @@ public:
|
||||
TestLogger logger;
|
||||
|
||||
CMaterial material{};
|
||||
CSimulation2 simulation{nullptr, g_ScriptContext, nullptr};
|
||||
CSimulation2 simulation{nullptr, *g_ScriptContext, nullptr};
|
||||
|
||||
CTerrain terrain;
|
||||
terrain.Initialize(4, nullptr);
|
||||
@ -246,7 +246,7 @@ public:
|
||||
CSkeletonAnimManager skeletonAnimationManager{colladaManager};
|
||||
|
||||
CUnitManager unitManager;
|
||||
CSimulation2 simulation{&unitManager, g_ScriptContext, nullptr};
|
||||
CSimulation2 simulation{&unitManager, *g_ScriptContext, nullptr};
|
||||
CObjectManager objectManager{
|
||||
meshManager, skeletonAnimationManager, simulation};
|
||||
unitManager.SetObjectManager(objectManager);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -69,7 +69,7 @@ const CStr CGame::EventNameSimulationUpdate = "SimulationUpdate";
|
||||
**/
|
||||
CGame::CGame(bool replayLog):
|
||||
m_World(new CWorld(*this)),
|
||||
m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptContext, &m_World->GetTerrain())),
|
||||
m_Simulation2{new CSimulation2{&m_World->GetUnitManager(), *g_ScriptContext, &m_World->GetTerrain()}},
|
||||
// TODO: we need to remove that global dependency. Maybe the game view
|
||||
// should be created outside only if needed.
|
||||
m_GameView(CRenderer::IsInitialised() ? new CGameView(g_VideoMode.GetBackendDevice(), this) : nullptr),
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -578,7 +578,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
// on anything else.)
|
||||
if (args.Has("dumpSchema"))
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, NULL);
|
||||
CSimulation2 sim{NULL, *g_ScriptContext, NULL};
|
||||
sim.LoadDefaultScripts();
|
||||
std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
|
||||
f << sim.GenerateSchema();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -53,10 +53,10 @@
|
||||
class CSimulation2Impl
|
||||
{
|
||||
public:
|
||||
CSimulation2Impl(CUnitManager* unitManager, std::shared_ptr<ScriptContext> cx, CTerrain* terrain) :
|
||||
m_SimContext(), m_ComponentManager(m_SimContext, *cx),
|
||||
m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false),
|
||||
m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext())
|
||||
CSimulation2Impl(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain) :
|
||||
m_ComponentManager{m_SimContext, cx},
|
||||
m_MapSettings{cx.GetGeneralJSContext()},
|
||||
m_InitAttributes{cx.GetGeneralJSContext()}
|
||||
{
|
||||
m_SimContext.m_UnitManager = unitManager;
|
||||
m_SimContext.m_Terrain = terrain;
|
||||
@ -131,14 +131,14 @@ public:
|
||||
|
||||
uint32_t m_TurnNumber;
|
||||
|
||||
bool m_EnableOOSLog;
|
||||
bool m_EnableOOSLog{false};
|
||||
OsPath m_OOSLogPath;
|
||||
|
||||
// Functions and data for the serialization test mode: (see Update() for relevant comments)
|
||||
|
||||
bool m_EnableSerializationTest;
|
||||
int m_RejoinTestTurn;
|
||||
bool m_TestingRejoin;
|
||||
bool m_EnableSerializationTest{false};
|
||||
int m_RejoinTestTurn{-1};
|
||||
bool m_TestingRejoin{false};
|
||||
|
||||
// Secondary simulation (NB: order matters for destruction).
|
||||
std::unique_ptr<CComponentManager> m_SecondaryComponentManager;
|
||||
@ -634,7 +634,7 @@ void CSimulation2Impl::DumpState()
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
CSimulation2::CSimulation2(CUnitManager* unitManager, std::shared_ptr<ScriptContext> cx, CTerrain* terrain) :
|
||||
CSimulation2::CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain) :
|
||||
m(new CSimulation2Impl(unitManager, cx, terrain))
|
||||
{
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -50,7 +50,7 @@ class CSimulation2
|
||||
public:
|
||||
// TODO: CUnitManager should probably be handled automatically by this
|
||||
// module, but for now we'll have it passed in externally instead
|
||||
CSimulation2(CUnitManager* unitManager, std::shared_ptr<ScriptContext> cx, CTerrain* terrain);
|
||||
CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain);
|
||||
~CSimulation2();
|
||||
|
||||
void EnableSerializationTest();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -137,7 +137,7 @@ public:
|
||||
{
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
|
||||
CSimulation2 sim2{nullptr, *g_ScriptContext, &terrain};
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
@ -196,7 +196,7 @@ public:
|
||||
CTerrain terrain;
|
||||
terrain.Initialize(5, NULL);
|
||||
|
||||
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
|
||||
CSimulation2 sim2{nullptr, *g_ScriptContext, &terrain};
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
@ -251,7 +251,7 @@ public:
|
||||
{
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
|
||||
CSimulation2 sim2{nullptr, *g_ScriptContext, &terrain};
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
@ -308,7 +308,7 @@ public:
|
||||
{
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
|
||||
CSimulation2 sim2{nullptr, *g_ScriptContext, &terrain};
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -240,7 +240,7 @@ public:
|
||||
void test_load_all_DISABLED() // disabled since it's a bit slow and noisy
|
||||
{
|
||||
CTerrain dummy;
|
||||
CSimulation2 sim(NULL, g_ScriptContext, &dummy);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, &dummy};
|
||||
sim.LoadDefaultScripts();
|
||||
sim.ResetState();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -887,7 +887,7 @@ public:
|
||||
|
||||
CTerrain terrain;
|
||||
|
||||
CSimulation2 sim2(NULL, g_ScriptContext, &terrain);
|
||||
CSimulation2 sim2{nullptr, *g_ScriptContext, &terrain};
|
||||
sim2.LoadDefaultScripts();
|
||||
sim2.ResetState();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -57,7 +57,7 @@ public:
|
||||
|
||||
void test_AddEntity()
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, &m_Terrain};
|
||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/"));
|
||||
|
||||
sim.ResetState(true, true);
|
||||
@ -77,7 +77,7 @@ public:
|
||||
|
||||
void test_DestroyEntity()
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, &m_Terrain};
|
||||
TS_ASSERT(sim.LoadScripts(L"simulation/components/addentity/"));
|
||||
|
||||
sim.ResetState(true, true);
|
||||
@ -133,7 +133,7 @@ public:
|
||||
|
||||
void test_hotload_scripts()
|
||||
{
|
||||
CSimulation2 sim(NULL, g_ScriptContext, &m_Terrain);
|
||||
CSimulation2 sim{nullptr, *g_ScriptContext, &m_Terrain};
|
||||
|
||||
TS_ASSERT_OK(CreateDirectories(DataDir()/"mods"/"_test.sim"/"simulation"/"components"/"hotload"/"", 0700));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -77,7 +77,7 @@ public:
|
||||
MeshManager(ColladaManager),
|
||||
SkeletonAnimManager(ColladaManager),
|
||||
UnitManager(),
|
||||
Simulation2(&UnitManager, g_ScriptContext, &Terrain),
|
||||
Simulation2{&UnitManager, *g_ScriptContext, &Terrain},
|
||||
ObjectManager(MeshManager, SkeletonAnimManager, Simulation2),
|
||||
LOSTexture(Simulation2),
|
||||
TerritoryTexture(Simulation2),
|
||||
|
Loading…
Reference in New Issue
Block a user