forked from 0ad/0ad
Set each player's default camera location to their civ center.
This was SVN commit r7672.
This commit is contained in:
parent
c59e2c572b
commit
c57575df3e
@ -46,6 +46,8 @@
|
||||
#include "simulation2/components/ICmpPosition.h"
|
||||
#include "simulation2/components/ICmpWaterManager.h"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#define LOG_CATEGORY L"graphics"
|
||||
|
||||
CMapReader::CMapReader()
|
||||
@ -57,13 +59,12 @@ CMapReader::CMapReader()
|
||||
|
||||
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
|
||||
void CMapReader::LoadMap(const VfsPath& pathname, CTerrain *pTerrain_,
|
||||
CUnitManager *pUnitMan_, WaterManager* pWaterMan_, SkyManager* pSkyMan_,
|
||||
WaterManager* pWaterMan_, SkyManager* pSkyMan_,
|
||||
CLightEnv *pLightEnv_, CCamera *pCamera_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_,
|
||||
CSimulation2 *pSimulation2_, CEntityManager *pEntityMan_)
|
||||
CSimulation2 *pSimulation2_, int playerID_)
|
||||
{
|
||||
// latch parameters (held until DelayedLoadFinished)
|
||||
pTerrain = pTerrain_;
|
||||
pUnitMan = pUnitMan_;
|
||||
pLightEnv = pLightEnv_;
|
||||
pCamera = pCamera_;
|
||||
pWaterMan = pWaterMan_;
|
||||
@ -71,7 +72,9 @@ void CMapReader::LoadMap(const VfsPath& pathname, CTerrain *pTerrain_,
|
||||
pCinema = pCinema_;
|
||||
pTrigMan = pTrigMan_;
|
||||
pSimulation2 = pSimulation2_;
|
||||
pEntityMan = pEntityMan_;
|
||||
m_PlayerID = playerID_;
|
||||
|
||||
m_CameraStartupTarget = INVALID_ENTITY;
|
||||
|
||||
filename_xml = fs::change_extension(pathname, L".xml");
|
||||
|
||||
@ -101,10 +104,6 @@ void CMapReader::LoadMap(const VfsPath& pathname, CTerrain *pTerrain_,
|
||||
if (pSimulation2)
|
||||
pSimulation2->ResetState();
|
||||
|
||||
// delete all remaining non-entity units
|
||||
if (pUnitMan)
|
||||
pUnitMan->DeleteAll();
|
||||
|
||||
// unpack the data
|
||||
if (!only_xml)
|
||||
RegMemFun(this, &CMapReader::UnpackMap, L"CMapReader::UnpackMap", 1200);
|
||||
@ -224,6 +223,26 @@ int CMapReader::ApplyData()
|
||||
if (pLightEnv)
|
||||
*pLightEnv = m_LightEnv;
|
||||
}
|
||||
|
||||
if (m_CameraStartupTarget != INVALID_ENTITY && pCamera)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, m_CameraStartupTarget);
|
||||
if (!cmpPosition.null())
|
||||
{
|
||||
pCamera->m_Orientation.SetIdentity();
|
||||
|
||||
pCamera->m_Orientation.Translate(CVector3D(0.f, 0.f, -200.f)); // move backwards from the target entity
|
||||
|
||||
pCamera->m_Orientation.RotateX(DEGTORAD(30));
|
||||
pCamera->m_Orientation.RotateY(DEGTORAD(0));
|
||||
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
pCamera->m_Orientation.Translate(CVector3D(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat()));
|
||||
|
||||
pCamera->UpdateFrustum();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1002,6 +1021,17 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(PlayerID);
|
||||
|
||||
if (m_MapReader.m_CameraStartupTarget == INVALID_ENTITY && !cmpPosition.null())
|
||||
{
|
||||
// HACK: we special-case civil centre files to initialise the camera.
|
||||
// This ought to be based on a more generic mechanism for indicating
|
||||
// per-player camera start locations.
|
||||
if (PlayerID == m_MapReader.m_PlayerID && boost::algorithm::ends_with(TemplateName, L"civil_centre"))
|
||||
{
|
||||
m_MapReader.m_CameraStartupTarget = ent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
completed_jobs++;
|
||||
|
@ -23,10 +23,10 @@
|
||||
#include "ps/CStr.h"
|
||||
#include "LightEnv.h"
|
||||
#include "ps/FileIo.h"
|
||||
#include "simulation2/system/Entity.h"
|
||||
|
||||
class CObjectEntry;
|
||||
class CTerrain;
|
||||
class CUnitManager;
|
||||
class WaterManager;
|
||||
class SkyManager;
|
||||
class CLightEnv;
|
||||
@ -34,7 +34,6 @@ class CCamera;
|
||||
class CCinemaManager;
|
||||
class CTriggerManager;
|
||||
class CSimulation2;
|
||||
class CEntityManager;
|
||||
class CTextureEntry;
|
||||
|
||||
class CXMLReader;
|
||||
@ -47,9 +46,9 @@ public:
|
||||
// constructor
|
||||
CMapReader();
|
||||
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
|
||||
void LoadMap(const VfsPath& pathname, CTerrain*, CUnitManager*,
|
||||
void LoadMap(const VfsPath& pathname, CTerrain*,
|
||||
WaterManager*, SkyManager*, CLightEnv*, CCamera*,
|
||||
CCinemaManager*, CTriggerManager*, CSimulation2*, CEntityManager*);
|
||||
CCinemaManager*, CTriggerManager*, CSimulation2*, int playerID);
|
||||
|
||||
private:
|
||||
// UnpackTerrain: unpack the terrain from the input stream
|
||||
@ -85,7 +84,6 @@ private:
|
||||
// state latched by LoadMap and held until DelayedLoadFinished
|
||||
CFileUnpacker unpacker;
|
||||
CTerrain* pTerrain;
|
||||
CUnitManager* pUnitMan;
|
||||
WaterManager* pWaterMan;
|
||||
SkyManager* pSkyMan;
|
||||
CLightEnv* pLightEnv;
|
||||
@ -93,10 +91,11 @@ private:
|
||||
CCinemaManager* pCinema;
|
||||
CTriggerManager* pTrigMan;
|
||||
CSimulation2* pSimulation2;
|
||||
CEntityManager* pEntityMan;
|
||||
int m_PlayerID;
|
||||
VfsPath filename_xml;
|
||||
bool only_xml;
|
||||
u32 file_format_version;
|
||||
entity_id_t m_CameraStartupTarget;
|
||||
|
||||
// UnpackTerrain generator state
|
||||
size_t cur_terrain_tex;
|
||||
|
@ -506,7 +506,7 @@ void CMapWriter::RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan,
|
||||
{
|
||||
CMapReader* reader = new CMapReader;
|
||||
LDR_BeginRegistering();
|
||||
reader->LoadMap(pathnames[i], pTerrain, pUnitMan, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, pTrigMan, pSimulation2, pEntityMan);
|
||||
reader->LoadMap(pathnames[i], pTerrain, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, pTrigMan, pSimulation2, -1);
|
||||
LDR_EndRegistering();
|
||||
LDR_NonprogressiveLoad();
|
||||
|
||||
|
@ -128,7 +128,7 @@ void CGame::RegisterInit(const CScriptValRooted& attribs)
|
||||
// some point to be stored in the world object?
|
||||
if (m_GameView)
|
||||
m_GameView->RegisterInit();
|
||||
m_World->RegisterInit(mapFile);
|
||||
m_World->RegisterInit(mapFile, m_PlayerID);
|
||||
LDR_EndRegistering();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -41,8 +41,6 @@
|
||||
#include "renderer/Renderer.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
|
||||
#define LOG_CATEGORY L"world"
|
||||
|
||||
/**
|
||||
* Global light settings.
|
||||
* It is not a member of CWorld because it is passed
|
||||
@ -66,9 +64,9 @@ CWorld::CWorld(CGame *pGame):
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the game world and loads required world resources.
|
||||
* Initializes the game world with the attributes provided.
|
||||
**/
|
||||
void CWorld::Initialize(const CStrW& mapFile)
|
||||
void CWorld::RegisterInit(const CStrW& mapFile, int playerID)
|
||||
{
|
||||
// Load the map, if one was specified
|
||||
if (mapFile.length())
|
||||
@ -80,34 +78,25 @@ void CWorld::Initialize(const CStrW& mapFile)
|
||||
{
|
||||
reader = new CMapReader;
|
||||
CTriggerManager* pTriggerManager = NULL;
|
||||
reader->LoadMap(mapfilename, m_Terrain, m_UnitManager,
|
||||
reader->LoadMap(mapfilename, m_Terrain,
|
||||
CRenderer::IsInitialised() ? g_Renderer.GetWaterManager() : NULL,
|
||||
CRenderer::IsInitialised() ? g_Renderer.GetSkyManager() : NULL,
|
||||
&g_LightEnv,
|
||||
m_pGame->GetView() ? m_pGame->GetView()->GetCamera() : NULL,
|
||||
m_pGame->GetView() ? m_pGame->GetView()->GetCinema() : NULL,
|
||||
pTriggerManager, m_pGame->GetSimulation2(), NULL);
|
||||
pTriggerManager, m_pGame->GetSimulation2(), playerID);
|
||||
// fails immediately, or registers for delay loading
|
||||
}
|
||||
catch (PSERROR_File& err)
|
||||
{
|
||||
delete reader;
|
||||
LOG(CLogger::Error, LOG_CATEGORY, L"Failed to load map %ls: %hs", mapfilename.string().c_str(), err.what());
|
||||
LOGERROR(L"Failed to load map %ls: %hs", mapfilename.string().c_str(), err.what());
|
||||
throw PSERROR_Game_World_MapLoadFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the game world with the attributes provided.
|
||||
**/
|
||||
void CWorld::RegisterInit(const CStrW& mapFile)
|
||||
{
|
||||
Initialize(mapFile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
@ -115,7 +104,7 @@ void CWorld::RegisterInit(const CStrW& mapFile)
|
||||
CWorld::~CWorld()
|
||||
{
|
||||
delete m_Terrain;
|
||||
delete m_UnitManager; // must come after deleting EntityManager
|
||||
delete m_UnitManager;
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,11 +76,10 @@ public:
|
||||
CWorld(CGame *pGame);
|
||||
~CWorld();
|
||||
|
||||
void RegisterInit(const CStrW& mapFile);
|
||||
/*
|
||||
Initialize the World - load the map and all objects
|
||||
*/
|
||||
void Initialize(const CStrW& mapFile);
|
||||
void RegisterInit(const CStrW& mapFile, int playerID);
|
||||
|
||||
// provided for JS _rewritemaps function
|
||||
void RewriteMap();
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
CMapReader* mapReader = new CMapReader(); // it'll call "delete this" itself
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/scenarios/Latium.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, NULL);
|
||||
mapReader->LoadMap(L"maps/scenarios/Latium.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, -1);
|
||||
LDR_EndRegistering();
|
||||
TS_ASSERT_OK(LDR_NonprogressiveLoad());
|
||||
|
||||
|
@ -466,7 +466,7 @@ public:
|
||||
CMapReader* mapReader = new CMapReader(); // it'll call "delete this" itself
|
||||
|
||||
LDR_BeginRegistering();
|
||||
mapReader->LoadMap(L"maps/scenarios/Latium.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, NULL);
|
||||
mapReader->LoadMap(L"maps/scenarios/Latium.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, &sim2, -1);
|
||||
LDR_EndRegistering();
|
||||
TS_ASSERT_OK(LDR_NonprogressiveLoad());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user