Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
World.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /**
19  * File : World.cpp
20  * Project : engine
21  * Description : Contains the CWorld Class implementation.
22  *
23  **/
24 #include "precompiled.h"
25 
26 #include "graphics/GameView.h"
27 #include "graphics/LightEnv.h"
28 #include "graphics/MapReader.h"
29 #include "graphics/MapWriter.h"
30 #include "graphics/Terrain.h"
31 #include "graphics/Terrain.h"
32 #include "graphics/UnitManager.h"
33 #include "lib/timer.h"
34 #include "ps/CLogger.h"
35 #include "ps/CStr.h"
36 #include "ps/Errors.h"
37 #include "ps/Game.h"
38 #include "ps/Loader.h"
39 #include "ps/LoaderThunks.h"
40 #include "ps/World.h"
41 #include "renderer/Renderer.h"
43 
44 /**
45  * Global light settings.
46  * It is not a member of CWorld because it is passed
47  * to the renderer before CWorld exists.
48  **/
50 
51 
52 /**
53  * Constructor.
54  *
55  * @param pGame CGame * pGame pointer to the container game object.
56  **/
58  m_pGame(pGame),
59  m_Terrain(new CTerrain()),
60  m_UnitManager(new CUnitManager()),
61  m_TerritoryManager(NULL)
62 {
63 }
64 
65 /**
66  * Initializes the game world with the attributes provided.
67  **/
68 void CWorld::RegisterInit(const CStrW& mapFile, const CScriptValRooted& settings, int playerID)
69 {
70  // Load the map, if one was specified
71  if (mapFile.length())
72  {
73  VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp");
74  CMapReader* reader = 0;
75 
76  try
77  {
78  reader = new CMapReader;
79  CTriggerManager* pTriggerManager = NULL;
80  reader->LoadMap(mapfilename, settings, m_Terrain,
81  CRenderer::IsInitialised() ? g_Renderer.GetWaterManager() : NULL,
82  CRenderer::IsInitialised() ? g_Renderer.GetSkyManager() : NULL,
84  m_pGame->GetView() ? m_pGame->GetView()->GetCinema() : NULL,
85  pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : NULL,
86  m_pGame->GetSimulation2(), &m_pGame->GetSimulation2()->GetSimContext(), playerID, false);
87  // fails immediately, or registers for delay loading
88  }
89  catch (PSERROR_File& err)
90  {
91  delete reader;
92  LOGERROR(L"Failed to load map %ls: %hs", mapfilename.string().c_str(), err.what());
93  throw PSERROR_Game_World_MapLoadFailed("Failed to load map.\nCheck application log for details.");
94  }
95  }
96 }
97 
98 void CWorld::RegisterInitRMS(const CStrW& scriptFile, const CScriptValRooted& settings, int playerID)
99 {
100  // If scriptFile is empty, a blank map will be generated using settings (no RMS run)
101  CMapReader* reader = 0;
102 
103  reader = new CMapReader;
104  CTriggerManager* pTriggerManager = NULL;
105  reader->LoadRandomMap(scriptFile, settings, m_Terrain,
106  CRenderer::IsInitialised() ? g_Renderer.GetWaterManager() : NULL,
107  CRenderer::IsInitialised() ? g_Renderer.GetSkyManager() : NULL,
109  m_pGame->GetView() ? m_pGame->GetView()->GetCinema() : NULL,
110  pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : NULL,
111  m_pGame->GetSimulation2(), playerID);
112  // registers for delay loading
113 }
114 
115 
116 /**
117  * Destructor.
118  *
119  **/
121 {
122  delete m_Terrain;
123  delete m_UnitManager;
124 }
The container that holds the rules, resources and attributes of the game.
Definition: Game.h:39
const CSimContext & GetSimContext() const
CCinemaManager * GetCinema()
Definition: GameView.cpp:395
Path VfsPath
VFS path of the form &quot;(dir/)*file?&quot;.
Definition: vfs_path.h:40
#define LOGERROR
Definition: CLogger.h:35
CLightEnv g_LightEnv
File : World.cpp Project : engine Description : Contains the CWorld Class implementation.
Definition: World.cpp:49
void RegisterInitRMS(const CStrW &scriptFile, const CScriptValRooted &settings, int playerID)
Definition: World.cpp:98
void RegisterInit(const CStrW &mapFile, const CScriptValRooted &settings, int playerID)
Initializes the game world with the attributes provided.
Definition: World.cpp:68
#define g_Renderer
Definition: Renderer.h:61
~CWorld()
Destructor.
Definition: World.cpp:120
Definition: path.h:75
const String & string() const
Definition: path.h:123
virtual const char * what() const
Definition: Errors.cpp:453
void LoadMap(const VfsPath &pathname, const CScriptValRooted &settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc, CSimulation2 *, const CSimContext *, int playerID, bool skipEntities)
Definition: MapReader.cpp:67
static bool IsInitialised()
Definition: Singleton.h:63
CSimulation2 * GetSimulation2()
Get the pointer to the simulation2 object.
Definition: Game.h:136
void LoadRandomMap(const CStrW &scriptFile, const CScriptValRooted &settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc_, CSimulation2 *, int playerID)
Definition: MapReader.cpp:146
CGameView * GetView()
Get the pointer to the game view object.
Definition: Game.h:128
Path ChangeExtension(Path extension) const
Definition: path.h:185
CWorld(CGame *pGame)
Constructor.
Definition: World.cpp:57
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:36
CTerrain * m_Terrain
pointer to the CTerrain object representing the height map.
Definition: World.h:58
CUnitManager * m_UnitManager
pointer to the CUnitManager that holds all the units in the world.
Definition: World.h:63
CGame * m_pGame
pointer to the CGame object representing the game.
Definition: World.h:53