Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapReader.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | ||||
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(cx.GetGeneralJSContext(), settings); | m_MapSettings.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 All 17 Lines | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | ||||
// delete all existing entities | // delete all existing entities | ||||
if (pSimulation2) | if (pSimulation2) | ||||
pSimulation2->ResetState(); | pSimulation2->ResetState(); | ||||
// reset post effects | // reset post effects | ||||
if (pPostproc) | if (pPostproc) | ||||
pPostproc->SetPostEffect(L"default"); | pPostproc->SetPostEffect(L"default"); | ||||
// load map or script settings script | // If no map settings were passed, load the default map settings in its place | ||||
if (settings.isUndefined()) | // (this is sort of a workaround, ideally the callers would load these settings themselves, | ||||
// in case they need to be modified, but it works well enough for now). | |||||
if (m_MapSettings.isUndefined()) | |||||
RegMemFun(this, &CMapReader::LoadScriptSettings, L"CMapReader::LoadScriptSettings", 50); | RegMemFun(this, &CMapReader::LoadScriptSettings, L"CMapReader::LoadScriptSettings", 50); | ||||
else | |||||
RegMemFun(this, &CMapReader::LoadRMSettings, L"CMapReader::LoadRMSettings", 50); | |||||
// load player settings script (must be done before reading map) | // parse player settings script (must be done before reading map) | ||||
RegMemFun(this, &CMapReader::LoadPlayerSettings, L"CMapReader::LoadPlayerSettings", 50); | RegMemFun(this, &CMapReader::ParsePlayerSettings, L"CMapReader::ParsePlayerSettings", 50); | ||||
// unpack the data | // unpack the data | ||||
if (!only_xml) | if (!only_xml) | ||||
RegMemFun(this, &CMapReader::UnpackMap, L"CMapReader::UnpackMap", 1200); | RegMemFun(this, &CMapReader::UnpackMap, L"CMapReader::UnpackMap", 1200); | ||||
// read the corresponding XML file | // read the corresponding XML file | ||||
RegMemFun(this, &CMapReader::ReadXML, L"CMapReader::ReadXML", 50); | RegMemFun(this, &CMapReader::ReadXML, L"CMapReader::ReadXML", 50); | ||||
// apply terrain data to the world | // apply terrain data to the world | ||||
RegMemFun(this, &CMapReader::ApplyTerrainData, L"CMapReader::ApplyTerrainData", 5); | RegMemFun(this, &CMapReader::ApplyTerrainData, L"CMapReader::ApplyTerrainData", 5); | ||||
// read entities | // read entities | ||||
RegMemFun(this, &CMapReader::ReadXMLEntities, L"CMapReader::ReadXMLEntities", 5800); | RegMemFun(this, &CMapReader::ReadXMLEntities, L"CMapReader::ReadXMLEntities", 5800); | ||||
// 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) | // parse map settings script (must be done after reading map) | ||||
RegMemFun(this, &CMapReader::LoadMapSettings, L"CMapReader::LoadMapSettings", 5); | RegMemFun(this, &CMapReader::ParseMapSettings, L"CMapReader::ParseMapSettings", 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, const ScriptContext& cx, 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(cx.GetGeneralJSContext(), settings); | m_MapSettings.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_; | ||||
m_PlayerID = playerID_; | m_PlayerID = playerID_; | ||||
m_SkipEntities = false; | m_SkipEntities = false; | ||||
m_StartingCameraTarget = INVALID_ENTITY; | m_StartingCameraTarget = INVALID_ENTITY; | ||||
// delete all existing entities | // delete all existing entities | ||||
if (pSimulation2) | if (pSimulation2) | ||||
pSimulation2->ResetState(); | pSimulation2->ResetState(); | ||||
only_xml = false; | only_xml = false; | ||||
// copy random map settings (before entity creation) | // parse player settings script (must be done before reading map) | ||||
RegMemFun(this, &CMapReader::LoadRMSettings, L"CMapReader::LoadRMSettings", 50); | RegMemFun(this, &CMapReader::ParsePlayerSettings, L"CMapReader::ParsePlayerSettings", 50); | ||||
// load player settings script (must be done before reading map) | |||||
RegMemFun(this, &CMapReader::LoadPlayerSettings, L"CMapReader::LoadPlayerSettings", 50); | |||||
// load map generator with random map script | // load map generator with random map script | ||||
RegMemFun(this, &CMapReader::GenerateMap, L"CMapReader::GenerateMap", 20000); | RegMemFun(this, &CMapReader::GenerateMap, L"CMapReader::GenerateMap", 20000); | ||||
// parse RMS results into terrain structure | // parse RMS results into terrain structure | ||||
RegMemFun(this, &CMapReader::ParseTerrain, L"CMapReader::ParseTerrain", 500); | RegMemFun(this, &CMapReader::ParseTerrain, L"CMapReader::ParseTerrain", 500); | ||||
// parse RMS results into environment settings | // parse RMS results into environment settings | ||||
RegMemFun(this, &CMapReader::ParseEnvironment, L"CMapReader::ParseEnvironment", 5); | RegMemFun(this, &CMapReader::ParseEnvironment, L"CMapReader::ParseEnvironment", 5); | ||||
// parse RMS results into camera settings | // parse RMS results into camera settings | ||||
RegMemFun(this, &CMapReader::ParseCamera, L"CMapReader::ParseCamera", 5); | RegMemFun(this, &CMapReader::ParseCamera, L"CMapReader::ParseCamera", 5); | ||||
// apply terrain data to the world | // apply terrain data to the world | ||||
RegMemFun(this, &CMapReader::ApplyTerrainData, L"CMapReader::ApplyTerrainData", 5); | RegMemFun(this, &CMapReader::ApplyTerrainData, L"CMapReader::ApplyTerrainData", 5); | ||||
// parse RMS results into entities | // parse RMS results into entities | ||||
RegMemFun(this, &CMapReader::ParseEntities, L"CMapReader::ParseEntities", 1000); | RegMemFun(this, &CMapReader::ParseEntities, L"CMapReader::ParseEntities", 1000); | ||||
// 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) | // parse map settings script (must be done after reading map) | ||||
RegMemFun(this, &CMapReader::LoadMapSettings, L"CMapReader::LoadMapSettings", 5); | RegMemFun(this, &CMapReader::ParseMapSettings, L"CMapReader::ParseMapSettings", 5); | ||||
} | } | ||||
// UnpackMap: unpack the given data from the raw data stream into local variables | // UnpackMap: unpack the given data from the raw data stream into local variables | ||||
int CMapReader::UnpackMap() | int CMapReader::UnpackMap() | ||||
{ | { | ||||
return UnpackTerrain(); | return UnpackTerrain(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 979 Lines • ▼ Show 20 Lines | |||||
// load script settings from map | // load script settings from map | ||||
int CMapReader::LoadScriptSettings() | int CMapReader::LoadScriptSettings() | ||||
{ | { | ||||
if (!xml_reader) | if (!xml_reader) | ||||
xml_reader = new CXMLReader(filename_xml, *this); | xml_reader = new CXMLReader(filename_xml, *this); | ||||
// parse the script settings | // parse the script settings | ||||
if (pSimulation2) | if (pSimulation2) | ||||
pSimulation2->SetMapSettings(xml_reader->ReadScriptSettings()); | pSimulation2->SetInitAttributesFromSettings(xml_reader->ReadScriptSettings()); | ||||
return 0; | return 0; | ||||
} | } | ||||
// load player settings script | int CMapReader::ParsePlayerSettings() | ||||
int CMapReader::LoadPlayerSettings() | |||||
{ | { | ||||
if (pSimulation2) | if (pSimulation2) | ||||
pSimulation2->LoadPlayerSettings(true); | pSimulation2->ParsePlayerSettings(true); | ||||
return 0; | return 0; | ||||
} | } | ||||
// load map settings script | int CMapReader::ParseMapSettings() | ||||
int CMapReader::LoadMapSettings() | |||||
{ | { | ||||
if (pSimulation2) | if (pSimulation2) | ||||
pSimulation2->LoadMapSettings(); | pSimulation2->ParseMapSettings(); | ||||
return 0; | return 0; | ||||
} | } | ||||
int CMapReader::ReadXML() | int CMapReader::ReadXML() | ||||
{ | { | ||||
if (!xml_reader) | if (!xml_reader) | ||||
xml_reader = new CXMLReader(filename_xml, *this); | xml_reader = new CXMLReader(filename_xml, *this); | ||||
Show All 17 Lines | int CMapReader::ReadXMLEntities() | ||||
return ret; | return ret; | ||||
} | } | ||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
int CMapReader::LoadRMSettings() | |||||
{ | |||||
// copy random map settings over to sim | |||||
ENSURE(pSimulation2); | |||||
pSimulation2->SetMapSettings(m_ScriptSettings); | |||||
return 0; | |||||
} | |||||
int CMapReader::GenerateMap() | int CMapReader::GenerateMap() | ||||
{ | { | ||||
ScriptRequest rq(pSimulation2->GetScriptInterface()); | ScriptRequest rq(pSimulation2->GetScriptInterface()); | ||||
if (!m_MapGen) | if (!m_MapGen) | ||||
{ | { | ||||
// Initialize map generator | // Initialize map generator | ||||
m_MapGen = new CMapGenerator(); | m_MapGen = new CMapGenerator(); | ||||
VfsPath scriptPath; | VfsPath scriptPath; | ||||
if (m_ScriptFile.length()) | if (m_ScriptFile.length()) | ||||
scriptPath = L"maps/random/"+m_ScriptFile; | scriptPath = L"maps/random/"+m_ScriptFile; | ||||
// Stringify settings to pass across threads | // Stringify settings to pass across threads | ||||
std::string scriptSettings = pSimulation2->GetScriptInterface().StringifyJSON(&m_ScriptSettings); | std::string scriptSettings = pSimulation2->GetScriptInterface().StringifyJSON(&m_MapSettings); | ||||
// Try to generate map | // Try to generate map | ||||
m_MapGen->GenerateMap(scriptPath, scriptSettings); | m_MapGen->GenerateMap(scriptPath, scriptSettings); | ||||
} | } | ||||
// Check status | // Check status | ||||
int progress = m_MapGen->GetProgress(); | int progress = m_MapGen->GetProgress(); | ||||
if (progress < 0) | if (progress < 0) | ||||
▲ Show 20 Lines • Show All 316 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator