Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/MapReader.cpp
Show All 33 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/LoaderThunks.h" | #include "ps/LoaderThunks.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "renderer/PostprocManager.h" | #include "renderer/PostprocManager.h" | ||||
#include "renderer/SkyManager.h" | #include "renderer/SkyManager.h" | ||||
#include "renderer/WaterManager.h" | #include "renderer/WaterManager.h" | ||||
#include "scriptinterface/ScriptContext.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpCinemaManager.h" | #include "simulation2/components/ICmpCinemaManager.h" | ||||
#include "simulation2/components/ICmpGarrisonHolder.h" | #include "simulation2/components/ICmpGarrisonHolder.h" | ||||
#include "simulation2/components/ICmpObstruction.h" | #include "simulation2/components/ICmpObstruction.h" | ||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "simulation2/components/ICmpPlayer.h" | #include "simulation2/components/ICmpPlayer.h" | ||||
#include "simulation2/components/ICmpPlayerManager.h" | #include "simulation2/components/ICmpPlayerManager.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/components/ICmpTurretHolder.h" | #include "simulation2/components/ICmpTurretHolder.h" | ||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include <boost/algorithm/string/predicate.hpp> | #include <boost/algorithm/string/predicate.hpp> | ||||
CMapReader::CMapReader() | CMapReader::CMapReader() | ||||
: xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) | : xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) | ||||
{ | { | ||||
cur_terrain_tex = 0; // important - resets generator state | cur_terrain_tex = 0; // important - resets generator state | ||||
} | } | ||||
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful | // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful | ||||
void CMapReader::LoadMap(const VfsPath& pathname, JSRuntime* rt, JS::HandleValue settings, CTerrain *pTerrain_, | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | ||||
WaterManager* pWaterMan_, SkyManager* pSkyMan_, | WaterManager* pWaterMan_, SkyManager* pSkyMan_, | ||||
CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_, | CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_, | ||||
CSimulation2 *pSimulation2_, const CSimContext* pSimContext_, int playerID_, bool skipEntities) | CSimulation2 *pSimulation2_, const CSimContext* pSimContext_, int playerID_, bool skipEntities) | ||||
{ | { | ||||
pTerrain = pTerrain_; | pTerrain = pTerrain_; | ||||
pLightEnv = pLightEnv_; | pLightEnv = pLightEnv_; | ||||
pGameView = pGameView_; | pGameView = pGameView_; | ||||
pWaterMan = pWaterMan_; | pWaterMan = pWaterMan_; | ||||
pSkyMan = pSkyMan_; | pSkyMan = pSkyMan_; | ||||
pCinema = pCinema_; | pCinema = pCinema_; | ||||
pTrigMan = pTrigMan_; | pTrigMan = pTrigMan_; | ||||
pPostproc = pPostproc_; | pPostproc = pPostproc_; | ||||
pSimulation2 = pSimulation2_; | pSimulation2 = pSimulation2_; | ||||
pSimContext = pSimContext_; | pSimContext = pSimContext_; | ||||
m_PlayerID = playerID_; | m_PlayerID = playerID_; | ||||
m_SkipEntities = skipEntities; | m_SkipEntities = skipEntities; | ||||
m_StartingCameraTarget = INVALID_ENTITY; | m_StartingCameraTarget = INVALID_ENTITY; | ||||
m_ScriptSettings.init(rt, settings); | m_ScriptSettings.init(cx.GetGeneralJSContext(), settings); | ||||
filename_xml = pathname.ChangeExtension(L".xml"); | filename_xml = pathname.ChangeExtension(L".xml"); | ||||
// In some cases (particularly tests) we don't want to bother storing a large | // In some cases (particularly tests) we don't want to bother storing a large | ||||
// mostly-empty .pmp file, so we let the XML file specify basic terrain instead. | // mostly-empty .pmp file, so we let the XML file specify basic terrain instead. | ||||
// If there's an .xml file and no .pmp, then we're probably in this XML-only mode | // If there's an .xml file and no .pmp, then we're probably in this XML-only mode | ||||
only_xml = false; | only_xml = false; | ||||
if (!VfsFileExists(pathname) && VfsFileExists(filename_xml)) | if (!VfsFileExists(pathname) && VfsFileExists(filename_xml)) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | ||||
// apply misc data to the world | // apply misc data to the world | ||||
RegMemFun(this, &CMapReader::ApplyData, L"CMapReader::ApplyData", 5); | RegMemFun(this, &CMapReader::ApplyData, L"CMapReader::ApplyData", 5); | ||||
// load map settings script (must be done after reading map) | // load map settings script (must be done after reading map) | ||||
RegMemFun(this, &CMapReader::LoadMapSettings, L"CMapReader::LoadMapSettings", 5); | RegMemFun(this, &CMapReader::LoadMapSettings, L"CMapReader::LoadMapSettings", 5); | ||||
} | } | ||||
// LoadRandomMap: try to load the map data; reinitialise the scene to new data if successful | // LoadRandomMap: try to load the map data; reinitialise the scene to new data if successful | ||||
void CMapReader::LoadRandomMap(const CStrW& scriptFile, JSRuntime* rt, JS::HandleValue settings, CTerrain *pTerrain_, | void CMapReader::LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | ||||
WaterManager* pWaterMan_, SkyManager* pSkyMan_, | WaterManager* pWaterMan_, SkyManager* pSkyMan_, | ||||
CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_, | CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_, | ||||
CSimulation2 *pSimulation2_, int playerID_) | CSimulation2 *pSimulation2_, int playerID_) | ||||
{ | { | ||||
m_ScriptFile = scriptFile; | m_ScriptFile = scriptFile; | ||||
pSimulation2 = pSimulation2_; | pSimulation2 = pSimulation2_; | ||||
pSimContext = pSimulation2 ? &pSimulation2->GetSimContext() : NULL; | pSimContext = pSimulation2 ? &pSimulation2->GetSimContext() : NULL; | ||||
m_ScriptSettings.init(rt, settings); | m_ScriptSettings.init(cx.GetGeneralJSContext(), settings); | ||||
pTerrain = pTerrain_; | pTerrain = pTerrain_; | ||||
pLightEnv = pLightEnv_; | pLightEnv = pLightEnv_; | ||||
pGameView = pGameView_; | pGameView = pGameView_; | ||||
pWaterMan = pWaterMan_; | pWaterMan = pWaterMan_; | ||||
pSkyMan = pSkyMan_; | pSkyMan = pSkyMan_; | ||||
pCinema = pCinema_; | pCinema = pCinema_; | ||||
pTrigMan = pTrigMan_; | pTrigMan = pTrigMan_; | ||||
pPostproc = pPostproc_; | pPostproc = pPostproc_; | ||||
▲ Show 20 Lines • Show All 1,126 Lines • ▼ Show 20 Lines | int CMapReader::GenerateMap() | ||||
if (progress < 0) | if (progress < 0) | ||||
{ | { | ||||
// RMS failed - return to main menu | // RMS failed - return to main menu | ||||
throw PSERROR_Game_World_MapLoadFailed("Error generating random map.\nCheck application log for details."); | throw PSERROR_Game_World_MapLoadFailed("Error generating random map.\nCheck application log for details."); | ||||
} | } | ||||
else if (progress == 0) | else if (progress == 0) | ||||
{ | { | ||||
// Finished, get results as StructuredClone object, which must be read to obtain the JS::Value | // Finished, get results as StructuredClone object, which must be read to obtain the JS::Value | ||||
shared_ptr<ScriptInterface::StructuredClone> results = m_MapGen->GetResults(); | ScriptInterface::StructuredClone results = m_MapGen->GetResults(); | ||||
// Parse data into simulation context | // Parse data into simulation context | ||||
JS::RootedValue data(rq.cx); | JS::RootedValue data(rq.cx); | ||||
pSimulation2->GetScriptInterface().ReadStructuredClone(results, &data); | pSimulation2->GetScriptInterface().ReadStructuredClone(results, &data); | ||||
if (data.isUndefined()) | if (data.isUndefined()) | ||||
{ | { | ||||
// RMS failed - return to main menu | // RMS failed - return to main menu | ||||
▲ Show 20 Lines • Show All 304 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator