Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapReader.cpp
Show All 22 Lines | |||||
#include "graphics/CinemaManager.h" | #include "graphics/CinemaManager.h" | ||||
#include "graphics/Entity.h" | #include "graphics/Entity.h" | ||||
#include "graphics/GameView.h" | #include "graphics/GameView.h" | ||||
#include "graphics/MapGenerator.h" | #include "graphics/MapGenerator.h" | ||||
#include "graphics/Patch.h" | #include "graphics/Patch.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/TerrainTextureEntry.h" | #include "graphics/TerrainTextureEntry.h" | ||||
#include "graphics/TerrainTextureManager.h" | #include "graphics/TerrainTextureManager.h" | ||||
#include "graphics/WaterManager.h" | |||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#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 "scriptinterface/ScriptContext.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" | ||||
Show All 12 Lines | |||||
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, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, 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 = pGameView_ ? &pGameView_->GetMutableWaterManager() : nullptr; | ||||
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; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, SkyManager* pSkyMan_, | ||||
// 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, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, | void CMapReader::LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_, 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_ScriptSettings.init(cx.GetGeneralJSContext(), settings); | ||||
pTerrain = pTerrain_; | pTerrain = pTerrain_; | ||||
pLightEnv = pLightEnv_; | pLightEnv = pLightEnv_; | ||||
pGameView = pGameView_; | pGameView = pGameView_; | ||||
pWaterMan = pWaterMan_; | pWaterMan = pGameView_ ? &pGameView_->GetMutableWaterManager() : nullptr; | ||||
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; | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
int CMapReader::ApplyData() | int CMapReader::ApplyData() | ||||
{ | { | ||||
// copy over the lighting parameters | // copy over the lighting parameters | ||||
if (pLightEnv) | if (pLightEnv) | ||||
*pLightEnv = m_LightEnv; | *pLightEnv = m_LightEnv; | ||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(*pSimContext, SYSTEM_ENTITY); | CmpPtr<ICmpPlayerManager> cmpPlayerManager(*pSimContext, SYSTEM_ENTITY); | ||||
if (pGameView) | |||||
pWaterMan->RecomputeWaterDataIfNeeded(); | |||||
if (pGameView && cmpPlayerManager) | if (pGameView && cmpPlayerManager) | ||||
{ | { | ||||
// Default to global camera (with constraints) | // Default to global camera (with constraints) | ||||
pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus()); | pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus()); | ||||
// TODO: Starting rotation? | // TODO: Starting rotation? | ||||
CmpPtr<ICmpPlayer> cmpPlayer(*pSimContext, cmpPlayerManager->GetPlayerByID(m_PlayerID)); | CmpPtr<ICmpPlayer> cmpPlayer(*pSimContext, cmpPlayerManager->GetPlayerByID(m_PlayerID)); | ||||
if (cmpPlayer && cmpPlayer->HasStartingCamera()) | if (cmpPlayer && cmpPlayer->HasStartingCamera()) | ||||
▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | else if (element_name == el_water) | ||||
XERO_ITER_EL(element, waterbody) | XERO_ITER_EL(element, waterbody) | ||||
{ | { | ||||
ENSURE(waterbody.GetNodeName() == el_waterbody); | ENSURE(waterbody.GetNodeName() == el_waterbody); | ||||
XERO_ITER_EL(waterbody, waterelement) | XERO_ITER_EL(waterbody, waterelement) | ||||
{ | { | ||||
int water_element_name = waterelement.GetNodeName(); | int water_element_name = waterelement.GetNodeName(); | ||||
if (water_element_name == el_height) | if (water_element_name == el_height) | ||||
{ | { | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*m_MapReader.pSimContext, SYSTEM_ENTITY); | CmpPtr<ICmpWaterManager> cmpWaterManager(*m_MapReader.pSimContext, SYSTEM_ENTITY); | ||||
ENSURE(cmpWaterManager); | ENSURE(cmpWaterManager); | ||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText())); | cmpWaterManager->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText())); | ||||
continue; | continue; | ||||
} | } | ||||
vladislavbelov: Looks like a duplication, are there guarantees that the heights will always match? | |||||
// The rest are purely graphical effects, and should be ignored if | // The rest are purely graphical effects, and should be ignored if | ||||
// graphics are disabled | // graphics are disabled | ||||
if (!m_MapReader.pWaterMan) | if (!m_MapReader.pWaterMan) | ||||
continue; | continue; | ||||
if (water_element_name == el_type) | if (water_element_name == el_type) | ||||
{ | { | ||||
if (waterelement.GetText() == "default") | if (waterelement.GetText() == "default") | ||||
m_MapReader.pWaterMan->m_WaterType = L"ocean"; | m_MapReader.pWaterMan->SetWaterType(L"ocean"); | ||||
else | else | ||||
m_MapReader.pWaterMan->m_WaterType = waterelement.GetText().FromUTF8(); | m_MapReader.pWaterMan->SetWaterType(waterelement.GetText().FromUTF8()); | ||||
} | } | ||||
#define READ_COLOR(el, out) \ | #define READ_COLOR(el, out) \ | ||||
else if (water_element_name == el) \ | else if (water_element_name == el) \ | ||||
{ \ | { \ | ||||
XMBAttributeList colorAttrs = waterelement.GetAttributes(); \ | XMBAttributeList colorAttrs = waterelement.GetAttributes(); \ | ||||
out = CColor( \ | out = CColor( \ | ||||
colorAttrs.GetNamedItem(at_r).ToFloat(), \ | colorAttrs.GetNamedItem(at_r).ToFloat(), \ | ||||
colorAttrs.GetNamedItem(at_g).ToFloat(), \ | colorAttrs.GetNamedItem(at_g).ToFloat(), \ | ||||
▲ Show 20 Lines • Show All 772 Lines • ▼ Show 20 Lines | #define GET_ENVIRONMENT_PROPERTY(val, prop, out)\ | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*pSimulation2, SYSTEM_ENTITY); | CmpPtr<ICmpWaterManager> cmpWaterManager(*pSimulation2, SYSTEM_ENTITY); | ||||
ENSURE(cmpWaterManager); | ENSURE(cmpWaterManager); | ||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(waterHeight)); | cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(waterHeight)); | ||||
// If we have graphics, get rest of settings | // If we have graphics, get rest of settings | ||||
if (pWaterMan) | if (pWaterMan) | ||||
{ | { | ||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, Type, pWaterMan->m_WaterType) | std::wstring type; | ||||
if (pWaterMan->m_WaterType == L"default") | GET_ENVIRONMENT_PROPERTY(waterBodyObj, Type, type) | ||||
pWaterMan->m_WaterType = L"ocean"; | if (type == L"default") | ||||
pWaterMan->SetWaterType(L"ocean"); | |||||
else | |||||
pWaterMan->SetWaterType(type); | |||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, Color, pWaterMan->m_WaterColor) | GET_ENVIRONMENT_PROPERTY(waterBodyObj, Color, pWaterMan->m_WaterColor) | ||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, Tint, pWaterMan->m_WaterTint) | GET_ENVIRONMENT_PROPERTY(waterBodyObj, Tint, pWaterMan->m_WaterTint) | ||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, Waviness, pWaterMan->m_Waviness) | GET_ENVIRONMENT_PROPERTY(waterBodyObj, Waviness, pWaterMan->m_Waviness) | ||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, Murkiness, pWaterMan->m_Murkiness) | GET_ENVIRONMENT_PROPERTY(waterBodyObj, Murkiness, pWaterMan->m_Murkiness) | ||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj, WindAngle, pWaterMan->m_WindAngle) | GET_ENVIRONMENT_PROPERTY(waterBodyObj, WindAngle, pWaterMan->m_WindAngle) | ||||
} | } | ||||
JS::RootedValue fogObject(rq.cx); | JS::RootedValue fogObject(rq.cx); | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Looks like a duplication, are there guarantees that the heights will always match?