1
0
forked from mirrors/0ad

Introduce a namespace in Loader

All functions had a `LDR_` prefix. The prefix is removed.
Functions and globals which are only used in Loader.cpp are now
contained in an anonymous namespace.
This commit is contained in:
phosit
2025-10-20 21:35:40 +02:00
parent f257ce8f9c
commit 1917d034fd
15 changed files with 94 additions and 81 deletions
+3 -3
View File
@@ -206,17 +206,17 @@ CMiniMapTexture& CGameView::GetMiniMapTexture()
void CGameView::RegisterInit() void CGameView::RegisterInit()
{ {
// CGameView init // CGameView init
LDR_Register([this] PS::Loader::Register([this]
{ {
m->CameraController->LoadConfig(); m->CameraController->LoadConfig();
return 0; return 0;
}, L"CGameView init", 1); }, L"CGameView init", 1);
LDR_Register([] PS::Loader::Register([]
{ {
return g_TexMan.StartTerrainTextures(); return g_TexMan.StartTerrainTextures();
}, L"StartTerrainTextures", 1); }, L"StartTerrainTextures", 1);
LDR_Register([] PS::Loader::Register([]
{ {
return g_TexMan.PollTerrainTextures(); return g_TexMan.PollTerrainTextures();
}, L"PollTerrainTextures", 60); }, L"PollTerrainTextures", 60);
+21 -21
View File
@@ -150,55 +150,55 @@ void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::
// load map or script settings script // load map or script settings script
if (settings.isUndefined()) if (settings.isUndefined())
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadScriptSettings(); return LoadScriptSettings();
}, L"CMapReader::LoadScriptSettings", 50); }, L"CMapReader::LoadScriptSettings", 50);
else else
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadRMSettings(); return LoadRMSettings();
}, L"CMapReader::LoadRMSettings", 50); }, L"CMapReader::LoadRMSettings", 50);
// load player settings script (must be done before reading map) // load player settings script (must be done before reading map)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadPlayerSettings(); return LoadPlayerSettings();
}, L"CMapReader::LoadPlayerSettings", 50); }, L"CMapReader::LoadPlayerSettings", 50);
// unpack the data // unpack the data
if (!only_xml) if (!only_xml)
LDR_Register([this] PS::Loader::Register([this]
{ {
return UnpackTerrain(); return UnpackTerrain();
}, L"CMapReader::UnpackMap", 1200); }, L"CMapReader::UnpackMap", 1200);
// read the corresponding XML file // read the corresponding XML file
LDR_Register([this] PS::Loader::Register([this]
{ {
return ReadXML(); return ReadXML();
}, L"CMapReader::ReadXML", 50); }, L"CMapReader::ReadXML", 50);
// apply terrain data to the world // apply terrain data to the world
LDR_Register([this] PS::Loader::Register([this]
{ {
return ApplyTerrainData(); return ApplyTerrainData();
}, L"CMapReader::ApplyTerrainData", 5); }, L"CMapReader::ApplyTerrainData", 5);
// read entities // read entities
LDR_Register([this] PS::Loader::Register([this]
{ {
return ReadXMLEntities(); return ReadXMLEntities();
}, L"CMapReader::ReadXMLEntities", 5800); }, L"CMapReader::ReadXMLEntities", 5800);
// apply misc data to the world // apply misc data to the world
LDR_Register([this] PS::Loader::Register([this]
{ {
return ApplyData(); return ApplyData();
}, L"CMapReader::ApplyData", 5); }, L"CMapReader::ApplyData", 5);
// load map settings script (must be done after reading map) // load map settings script (must be done after reading map)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadMapSettings(); return LoadMapSettings();
}, L"CMapReader::LoadMapSettings", 5); }, L"CMapReader::LoadMapSettings", 5);
@@ -232,70 +232,70 @@ void CMapReader::LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx,
only_xml = false; only_xml = false;
// copy random map settings (before entity creation) // copy random map settings (before entity creation)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadRMSettings(); return LoadRMSettings();
}, L"CMapReader::LoadRMSettings", 50); }, L"CMapReader::LoadRMSettings", 50);
// load player settings script (must be done before reading map) // load player settings script (must be done before reading map)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadPlayerSettings(); return LoadPlayerSettings();
}, L"CMapReader::LoadPlayerSettings", 50); }, L"CMapReader::LoadPlayerSettings", 50);
// load map generator with random map script // load map generator with random map script
LDR_Register([this, scriptFile] PS::Loader::Register([this, scriptFile]
{ {
return StartMapGeneration(scriptFile); return StartMapGeneration(scriptFile);
}, L"CMapReader::StartMapGeneration", 1); }, L"CMapReader::StartMapGeneration", 1);
LDR_Register([this] PS::Loader::Register([this]
{ {
return PollMapGeneration(); return PollMapGeneration();
}, L"CMapReader::PollMapGeneration", 19999); }, L"CMapReader::PollMapGeneration", 19999);
// parse RMS results into terrain structure // parse RMS results into terrain structure
LDR_Register([this] PS::Loader::Register([this]
{ {
return ParseTerrain(); return ParseTerrain();
}, L"CMapReader::ParseTerrain", 500); }, L"CMapReader::ParseTerrain", 500);
// parse RMS results into environment settings // parse RMS results into environment settings
LDR_Register([this] PS::Loader::Register([this]
{ {
return ParseEnvironment(); return ParseEnvironment();
}, L"CMapReader::ParseEnvironment", 5); }, L"CMapReader::ParseEnvironment", 5);
// parse RMS results into camera settings // parse RMS results into camera settings
LDR_Register([this] PS::Loader::Register([this]
{ {
return ParseCamera(); return ParseCamera();
}, L"CMapReader::ParseCamera", 5); }, L"CMapReader::ParseCamera", 5);
// apply terrain data to the world // apply terrain data to the world
LDR_Register([this] PS::Loader::Register([this]
{ {
return ApplyTerrainData(); return ApplyTerrainData();
}, L"CMapReader::ApplyTerrainData", 5); }, L"CMapReader::ApplyTerrainData", 5);
// parse RMS results into entities // parse RMS results into entities
LDR_Register([this] PS::Loader::Register([this]
{ {
return StartParseEntities(); return StartParseEntities();
}, L"CMapReader::StartParseEntities", 10); }, L"CMapReader::StartParseEntities", 10);
LDR_Register([this] PS::Loader::Register([this]
{ {
return PollParseEntities(); return PollParseEntities();
}, L"CMapReader::PollParseEntities", 1000); }, L"CMapReader::PollParseEntities", 1000);
// apply misc data to the world // apply misc data to the world
LDR_Register([this] PS::Loader::Register([this]
{ {
return ApplyData(); return ApplyData();
}, L"CMapReader::ApplyData", 5); }, L"CMapReader::ApplyData", 5);
// load map settings script (must be done after reading map) // load map settings script (must be done after reading map)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadMapSettings(); return LoadMapSettings();
}, L"CMapReader::LoadMapSettings", 5); }, L"CMapReader::LoadMapSettings", 5);
+1 -1
View File
@@ -329,7 +329,7 @@ static int ProgressiveLoad()
int progressPercent{0}; int progressPercent{0};
try try
{ {
const LDR_ProgressiveLoadResult result{LDR_ProgressiveLoad(10e-3)}; const PS::Loader::ProgressiveLoadResult result{PS::Loader::ProgressiveLoad(10e-3)};
description = result.nextDescription; description = result.nextDescription;
progressPercent = result.progressPercent; progressPercent = result.progressPercent;
switch(result.status) switch(result.status)
+3 -3
View File
@@ -189,7 +189,7 @@ public:
for (size_t j = 0; j < clients.size(); ++j) for (size_t j = 0; j < clients.size(); ++j)
{ {
clients[j]->Poll(); clients[j]->Poll();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
clients[j]->LoadFinished(); clients[j]->LoadFinished();
} }
@@ -272,7 +272,7 @@ public:
for (size_t j = 0; j < clients.size(); ++j) for (size_t j = 0; j < clients.size(); ++j)
{ {
clients[j]->Poll(); clients[j]->Poll();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
clients[j]->LoadFinished(); clients[j]->LoadFinished();
} }
@@ -367,7 +367,7 @@ public:
clients[2]->Poll(); clients[2]->Poll();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
clients[2]->LoadFinished(); clients[2]->LoadFinished();
wait(clients, 100); wait(clients, 100);
+6 -6
View File
@@ -251,9 +251,9 @@ void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& saved
LOGERROR("GameSpeed could not be parsed."); LOGERROR("GameSpeed could not be parsed.");
} }
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
LDR_Register([this] PS::Loader::Register([this]
{ {
return m_Simulation2->ProgressiveLoad(); return m_Simulation2->ProgressiveLoad();
}, L"Simulation init", 1000); }, L"Simulation init", 1000);
@@ -282,24 +282,24 @@ void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& saved
m_World->RegisterInit(mapFile, scriptInterface.GetContext(), settings, m_PlayerID); m_World->RegisterInit(mapFile, scriptInterface.GetContext(), settings, m_PlayerID);
} }
if (m_GameView) if (m_GameView)
LDR_Register([&waterManager = g_Renderer.GetSceneRenderer().GetWaterManager()] PS::Loader::Register([&waterManager = g_Renderer.GetSceneRenderer().GetWaterManager()]
{ {
return waterManager.LoadWaterTextures(); return waterManager.LoadWaterTextures();
}, L"LoadWaterTextures", 80); }, L"LoadWaterTextures", 80);
if (m_IsSavedGame) if (m_IsSavedGame)
LDR_Register([this, savedState] PS::Loader::Register([this, savedState]
{ {
return LoadInitialState(savedState); return LoadInitialState(savedState);
}, L"Loading game", 1000); }, L"Loading game", 1000);
if (m_IsVisualReplay) if (m_IsVisualReplay)
LDR_Register([this] PS::Loader::Register([this]
{ {
return LoadVisualReplayData(); return LoadVisualReplayData();
}, L"Loading visual replay data", 1000); }, L"Loading visual replay data", 1000);
LDR_EndRegistering(); PS::Loader::EndRegistering();
} }
int CGame::LoadInitialState(const std::string& savedState) int CGame::LoadInitialState(const std::string& savedState)
+2 -2
View File
@@ -868,7 +868,7 @@ bool Autostart(const CmdLineArgs& args)
if (args.Has("autostart-nonvisual")) if (args.Has("autostart-nonvisual"))
{ {
LDR_NonprogressiveLoad(); PS::Loader::NonprogressiveLoad();
g_Game->ReallyStartGame(); g_Game->ReallyStartGame();
} }
@@ -914,7 +914,7 @@ void CancelLoad(const CStrW& message)
JS::RootedValue global(rq.cx, rq.globalValue()); JS::RootedValue global(rq.cx, rq.globalValue());
LDR_Cancel(); PS::Loader::Cancel();
if (g_GUI && if (g_GUI &&
g_GUI->GetPageCount() && g_GUI->GetPageCount() &&
+26 -17
View File
@@ -32,24 +32,28 @@
#include <string> #include <string>
#include <utility> #include <utility>
namespace PS::Loader
{
namespace
{
// set by LDR_EndRegistering; may be 0 during development when // set by LDR_EndRegistering; may be 0 during development when
// estimated task durations haven't yet been set. // estimated task durations haven't yet been set.
static double total_estimated_duration; double total_estimated_duration;
// total time spent loading so far, set by LDR_ProgressiveLoad. // total time spent loading so far, set by LDR_ProgressiveLoad.
// we need a persistent counter so it can be reset after each load. // we need a persistent counter so it can be reset after each load.
// this also accumulates less errors than: // this also accumulates less errors than:
// progress += task_estimated / total_estimated. // progress += task_estimated / total_estimated.
static double estimated_duration_tally; double estimated_duration_tally;
// needed for report of how long each individual task took. // needed for report of how long each individual task took.
static double task_elapsed_time; double task_elapsed_time;
// main purpose is to indicate whether a load is in progress, so that // main purpose is to indicate whether a load is in progress, so that
// LDR_ProgressiveLoad can return 0 iff loading just completed. // LDR_ProgressiveLoad can return 0 iff loading just completed.
// the REGISTERING state allows us to detect 2 simultaneous loads (bogus); // the REGISTERING state allows us to detect 2 simultaneous loads (bogus);
// FIRST_LOAD is used to skip the first timeslice (see LDR_ProgressiveLoad). // FIRST_LOAD is used to skip the first timeslice (see LDR_ProgressiveLoad).
static enum enum
{ {
IDLE, IDLE,
REGISTERING, REGISTERING,
@@ -78,21 +82,22 @@ struct LoadRequest
} }
}; };
typedef std::deque<LoadRequest> LoadRequests; using LoadRequests = std::deque<LoadRequest>;
static LoadRequests load_requests; LoadRequests load_requests;
// Returns true if the return code indicates that the `LoadRequest` didn't // Returns true if the return code indicates that the `LoadRequest` didn't
// finish and should be reinvoked in the next frame. // finish and should be reinvoked in the next frame.
static bool ldr_was_interrupted(const int ret) bool WasInterrupted(const int ret)
{ {
return 0 < ret && ret <= 100; return 0 < ret && ret <= 100;
} }
} // anonymous namespace
// call before starting to register load requests. // call before starting to register load requests.
// this routine is provided so we can prevent 2 simultaneous load operations, // this routine is provided so we can prevent 2 simultaneous load operations,
// which is bogus. that can happen by clicking the load button quickly, // which is bogus. that can happen by clicking the load button quickly,
// or issuing via console while already loading. // or issuing via console while already loading.
void LDR_BeginRegistering() void BeginRegistering()
{ {
ENSURE(state == IDLE); ENSURE(state == IDLE);
@@ -109,7 +114,7 @@ void LDR_BeginRegistering()
// <estimated_duration_ms>: used to calculate progress, and when checking // <estimated_duration_ms>: used to calculate progress, and when checking
// whether there is enough of the time budget left to process this task // whether there is enough of the time budget left to process this task
// (reduces timeslice overruns, making the main loop more responsive). // (reduces timeslice overruns, making the main loop more responsive).
void LDR_Register(LoadFunc func, std::wstring description, int estimatedDurationMs) void Register(LoadFunc func, std::wstring description, int estimatedDurationMs)
{ {
ENSURE(state == REGISTERING); // must be called between LDR_(Begin|End)Register ENSURE(state == REGISTERING); // must be called between LDR_(Begin|End)Register
@@ -119,7 +124,7 @@ void LDR_Register(LoadFunc func, std::wstring description, int estimatedDuration
// call when finished registering tasks; subsequent calls to // call when finished registering tasks; subsequent calls to
// LDR_ProgressiveLoad will then work off the queued entries. // LDR_ProgressiveLoad will then work off the queued entries.
void LDR_EndRegistering() void EndRegistering()
{ {
ENSURE(state == REGISTERING); ENSURE(state == REGISTERING);
ENSURE(!load_requests.empty()); ENSURE(!load_requests.empty());
@@ -135,7 +140,7 @@ void LDR_EndRegistering()
// immediately cancel this load; no further tasks will be processed. // immediately cancel this load; no further tasks will be processed.
// used to abort loading upon user request or failure. // used to abort loading upon user request or failure.
// note: no special notification will be returned by LDR_ProgressiveLoad. // note: no special notification will be returned by LDR_ProgressiveLoad.
void LDR_Cancel() void Cancel()
{ {
// the queue doesn't need to be emptied now; that'll happen during the // the queue doesn't need to be emptied now; that'll happen during the
// next LDR_StartRegistering. for now, it is sufficient to set the // next LDR_StartRegistering. for now, it is sufficient to set the
@@ -143,9 +148,11 @@ void LDR_Cancel()
state = IDLE; state = IDLE;
} }
namespace
{
// helper routine for LDR_ProgressiveLoad. // helper routine for LDR_ProgressiveLoad.
// tries to prevent starting a long task when at the end of a timeslice. // tries to prevent starting a long task when at the end of a timeslice.
static bool HaveTimeForNextTask(double time_left, double time_budget, int estimated_duration_ms) bool HaveTimeForNextTask(double time_left, double time_budget, int estimated_duration_ms)
{ {
// have already exceeded our time budget // have already exceeded our time budget
if(time_left <= 0.0) if(time_left <= 0.0)
@@ -164,10 +171,11 @@ static bool HaveTimeForNextTask(double time_left, double time_budget, int estima
return true; return true;
} }
}
LDR_ProgressiveLoadResult LDR_ProgressiveLoad(double time_budget) ProgressiveLoadResult ProgressiveLoad(double time_budget)
{ {
LDR_ProgressiveLoadResult ret; ProgressiveLoadResult ret;
double progress = 0.0; // used to set progress_percent double progress = 0.0; // used to set progress_percent
double time_left = time_budget; double time_left = time_budget;
@@ -201,7 +209,7 @@ LDR_ProgressiveLoadResult LDR_ProgressiveLoad(double time_budget)
// call this task's function and bill elapsed time. // call this task's function and bill elapsed time.
const double t0 = timer_Time(); const double t0 = timer_Time();
const int status = lr.func(); const int status = lr.func();
const bool timed_out = ldr_was_interrupted(status); const bool timed_out = WasInterrupted(status);
const double elapsed_time = timer_Time() - t0; const double elapsed_time = timer_Time() - t0;
time_left -= elapsed_time; time_left -= elapsed_time;
task_elapsed_time += elapsed_time; task_elapsed_time += elapsed_time;
@@ -278,7 +286,7 @@ done:
// immediately process all queued load requests. // immediately process all queued load requests.
// returns 0 on success or a negative error code. // returns 0 on success or a negative error code.
Status LDR_NonprogressiveLoad() Status NonprogressiveLoad()
{ {
const double time_budget = 100.0; const double time_budget = 100.0;
// large enough so that individual functions won't time out // large enough so that individual functions won't time out
@@ -286,7 +294,7 @@ Status LDR_NonprogressiveLoad()
for(;;) for(;;)
{ {
const auto [ret, description, progress_percent] = LDR_ProgressiveLoad(time_budget); const auto [ret, description, progress_percent] = ProgressiveLoad(time_budget);
switch(ret) switch(ret)
{ {
case INFO::OK: case INFO::OK:
@@ -301,3 +309,4 @@ Status LDR_NonprogressiveLoad()
} }
} }
} }
} // namespace PS::Loader
+11 -7
View File
@@ -27,6 +27,8 @@
#include <functional> #include <functional>
#include <string> #include <string>
namespace PS::Loader
{
/* /*
[KEEP IN SYNC WITH WIKI!] [KEEP IN SYNC WITH WIKI!]
@@ -102,7 +104,7 @@ Then in the main loop, call LDR_ProgressiveLoad().
// this routine is provided so we can prevent 2 simultaneous load operations, // this routine is provided so we can prevent 2 simultaneous load operations,
// which is bogus. that can happen by clicking the load button quickly, // which is bogus. that can happen by clicking the load button quickly,
// or issuing via console while already loading. // or issuing via console while already loading.
extern void LDR_BeginRegistering(); void BeginRegistering();
// callback function of a task; performs the actual work. // callback function of a task; performs the actual work.
@@ -125,20 +127,20 @@ using LoadFunc = std::function<int()>;
// <estimated_duration_ms>: used to calculate progress, and when checking // <estimated_duration_ms>: used to calculate progress, and when checking
// whether there is enough of the time budget left to process this task // whether there is enough of the time budget left to process this task
// (reduces timeslice overruns, making the main loop more responsive). // (reduces timeslice overruns, making the main loop more responsive).
void LDR_Register(LoadFunc func, std::wstring description, int estimated_duration_ms); void Register(LoadFunc func, std::wstring description, int estimated_duration_ms);
// call when finished registering tasks; subsequent calls to // call when finished registering tasks; subsequent calls to
// LDR_ProgressiveLoad will then work off the queued entries. // LDR_ProgressiveLoad will then work off the queued entries.
extern void LDR_EndRegistering(); void EndRegistering();
// immediately cancel this load; no further tasks will be processed. // immediately cancel this load; no further tasks will be processed.
// used to abort loading upon user request or failure. // used to abort loading upon user request or failure.
// note: no special notification will be returned by LDR_ProgressiveLoad. // note: no special notification will be returned by LDR_ProgressiveLoad.
extern void LDR_Cancel(); void Cancel();
struct LDR_ProgressiveLoadResult struct ProgressiveLoadResult
{ {
/** /**
* @c INFO::All_COMPLETE if the final load task just completed. * @c INFO::All_COMPLETE if the final load task just completed.
@@ -163,11 +165,11 @@ struct LDR_ProgressiveLoadResult
* Process as many of the queued tasks as possible within @c timeBudget [s]. * Process as many of the queued tasks as possible within @c timeBudget [s].
* if a task is lengthy, the budget may be exceeded. call from the main loop. * if a task is lengthy, the budget may be exceeded. call from the main loop.
*/ */
LDR_ProgressiveLoadResult LDR_ProgressiveLoad(double time_budget); ProgressiveLoadResult ProgressiveLoad(double time_budget);
// immediately process all queued load requests. // immediately process all queued load requests.
// returns 0 on success or a negative error code. // returns 0 on success or a negative error code.
extern Status LDR_NonprogressiveLoad(); Status NonprogressiveLoad();
// boilerplate check-if-timed-out and return-progress-percent code. // boilerplate check-if-timed-out and return-progress-percent code.
@@ -185,4 +187,6 @@ extern Status LDR_NonprogressiveLoad();
return (int)progress_percent;\ return (int)progress_percent;\
} }
} // namespace PS::Loader
#endif // #ifndef INCLUDED_LOADER #endif // #ifndef INCLUDED_LOADER
+1 -1
View File
@@ -268,7 +268,7 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur
g_Game->StartGame(&attribs, ""); g_Game->StartGame(&attribs, "");
// TODO: Non progressive load can fail - need a decent way to handle this // TODO: Non progressive load can fail - need a decent way to handle this
LDR_NonprogressiveLoad(); PS::Loader::NonprogressiveLoad();
PSRETURN ret = g_Game->ReallyStartGame(); PSRETURN ret = g_Game->ReallyStartGame();
ENSURE(ret == PSRETURN_OK); ENSURE(ret == PSRETURN_OK);
+2 -2
View File
@@ -86,7 +86,7 @@ void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::Han
m_Game.GetSimulation2(), &m_Game.GetSimulation2()->GetSimContext(), playerID, m_Game.GetSimulation2(), &m_Game.GetSimulation2()->GetSimContext(), playerID,
false); false);
// fails immediately, or registers for delay loading // fails immediately, or registers for delay loading
LDR_Register([this] PS::Loader::Register([this]
{ {
return DeleteMapReader(); return DeleteMapReader();
}, L"CWorld::DeleteMapReader", 5); }, L"CWorld::DeleteMapReader", 5);
@@ -111,7 +111,7 @@ void CWorld::RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, J
pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : nullptr, pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : nullptr,
m_Game.GetSimulation2(), playerID); m_Game.GetSimulation2(), playerID);
// registers for delay loading // registers for delay loading
LDR_Register([this] PS::Loader::Register([this]
{ {
return DeleteMapReader(); return DeleteMapReader();
}, L"CWorld::DeleteMapReader", 5); }, L"CWorld::DeleteMapReader", 5);
+1 -1
View File
@@ -363,7 +363,7 @@ void Interface::ApplyMessage(const GameMessage& msg)
if (nonVisual) if (nonVisual)
{ {
LDR_NonprogressiveLoad(); PS::Loader::NonprogressiveLoad();
ENSURE(g_Game->ReallyStartGame() == PSRETURN_OK); ENSURE(g_Game->ReallyStartGame() == PSRETURN_OK);
m_ReturnValue = GetGameState(); m_ReturnValue = GetGameState();
m_MsgApplied.notify_one(); m_MsgApplied.notify_one();
+3 -3
View File
@@ -449,7 +449,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
// Load the map into the secondary simulation // Load the map into the secondary simulation
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
std::string mapType; std::string mapType;
@@ -470,8 +470,8 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
NULL, NULL, m_SecondaryContext.get(), INVALID_PLAYER, true); // throws exception on failure NULL, NULL, m_SecondaryContext.get(), INVALID_PLAYER, true); // throws exception on failure
} }
LDR_EndRegistering(); PS::Loader::EndRegistering();
ENSURE(LDR_NonprogressiveLoad() == INFO::OK); ENSURE(PS::Loader::NonprogressiveLoad() == INFO::OK);
ENSURE(m_SecondaryComponentManager->DeserializeState(primaryStateBefore.state)); ENSURE(m_SecondaryComponentManager->DeserializeState(primaryStateBefore.state));
} }
@@ -164,13 +164,13 @@ public:
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
mapReader->LoadMap(L"maps/skirmishes/Median Oasis (2).pmp", mapReader->LoadMap(L"maps/skirmishes/Median Oasis (2).pmp",
sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue,
&terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&sim2, &sim2.GetSimContext(), -1, false); &sim2, &sim2.GetSimContext(), -1, false);
LDR_EndRegistering(); PS::Loader::EndRegistering();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
sim2.PreInitGame(); sim2.PreInitGame();
sim2.InitGame(); sim2.InitGame();
@@ -278,13 +278,13 @@ public:
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp", mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp",
sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue,
&terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&sim2, &sim2.GetSimContext(), -1, false); &sim2, &sim2.GetSimContext(), -1, false);
LDR_EndRegistering(); PS::Loader::EndRegistering();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
sim2.PreInitGame(); sim2.PreInitGame();
sim2.InitGame(); sim2.InitGame();
@@ -335,13 +335,13 @@ public:
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp", mapReader->LoadMap(L"maps/scenarios/Peloponnese.pmp",
sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue,
&terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&sim2, &sim2.GetSimContext(), -1, false); &sim2, &sim2.GetSimContext(), -1, false);
LDR_EndRegistering(); PS::Loader::EndRegistering();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
sim2.PreInitGame(); sim2.PreInitGame();
sim2.InitGame(); sim2.InitGame();
+3 -3
View File
@@ -907,13 +907,13 @@ public:
std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>(); std::unique_ptr<CMapReader> mapReader = std::make_unique<CMapReader>();
LDR_BeginRegistering(); PS::Loader::BeginRegistering();
mapReader->LoadMap(L"maps/skirmishes/Greek Acropolis (2).pmp", mapReader->LoadMap(L"maps/skirmishes/Greek Acropolis (2).pmp",
sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue, sim2.GetScriptInterface().GetContext(), JS::UndefinedHandleValue,
&terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&sim2, &sim2.GetSimContext(), -1, false); &sim2, &sim2.GetSimContext(), -1, false);
LDR_EndRegistering(); PS::Loader::EndRegistering();
TS_ASSERT_OK(LDR_NonprogressiveLoad()); TS_ASSERT_OK(PS::Loader::NonprogressiveLoad());
sim2.Update(0); sim2.Update(0);
@@ -109,7 +109,7 @@ namespace
g_Game->StartGame(attrs, ""); g_Game->StartGame(attrs, "");
// TODO: Non progressive load can fail - need a decent way to handle this // TODO: Non progressive load can fail - need a decent way to handle this
LDR_NonprogressiveLoad(); PS::Loader::NonprogressiveLoad();
// Disable fog-of-war - this must be done before starting the game, // Disable fog-of-war - this must be done before starting the game,
// as visual actors cache their visibility state on first render. // as visual actors cache their visibility state on first render.
@@ -153,7 +153,7 @@ QUERYHANDLER(GenerateMap)
catch (std::exception&) catch (std::exception&)
{ {
// Cancel loading // Cancel loading
LDR_Cancel(); PS::Loader::Cancel();
// Since map generation failed and we don't know why, use the blank map as a fallback // Since map generation failed and we don't know why, use the blank map as a fallback