Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
World.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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.h
20 * Project : engine
21 * Description : Contains the CWorld Class which contains all the entities and represents them at a specific moment in time.
22 *
23 **/
24#ifndef INCLUDED_WORLD
25#define INCLUDED_WORLD
26
27#include "ps/CStrForward.h"
28#include "ps/Errors.h"
29
30#include <memory>
31
32#ifndef ERROR_GROUP_GAME_DEFINED
33#define ERROR_GROUP_GAME_DEFINED
35#endif
36ERROR_SUBGROUP(Game, World);
37ERROR_TYPE(Game_World, MapLoadFailed);
38
39class CGame;
40class CUnitManager;
41class CTerrain;
42class CMapReader;
43class ScriptContext;
44
45/**
46 * CWorld is a general data class containing whatever is needed to accurately represent the world.
47 * This includes the map, entities, influence maps, tiles, heightmap, etc.
48 **/
49class CWorld
50{
51public:
52 CWorld(CGame& game);
54
55 /*
56 Initialize the World - load the map and all objects
57 */
58 void RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
59
60 /*
61 Initialize the World - generate and load the random map
62 */
63 void RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
64
65 /**
66 * Explicitly delete m_MapReader once the map has finished loading.
67 **/
68 int DeleteMapReader();
69
70 /**
71 * Get a reference to the terrain object.
72 *
73 * @return CTerrain& dereferenced m_Terrain.
74 **/
76 {
77 return *m_Terrain;
78 }
79
80 /**
81 * Get a reference to the unit manager object.
82 *
83 * @return CUnitManager& dereferenced m_UnitManager.
84 **/
86 {
87 return *m_UnitManager;
88 }
89
90private:
91 /**
92 * Reference to the CGame object representing the game.
93 */
95
96 /**
97 * The CTerrain object represents the height map.
98 */
99 const std::unique_ptr<CTerrain> m_Terrain;
100
101 /**
102 * The CUnitManager that holds all the units in the world.
103 */
104 const std::unique_ptr<CUnitManager> m_UnitManager;
105
106 /**
107 * The map reader gets deleted just after the map is read.
108 */
109 std::unique_ptr<CMapReader> m_MapReader;
110};
111
112// rationale: see definition.
113class CLightEnv;
114extern CLightEnv g_LightEnv;
115
116#endif
ERROR_TYPE(Game_World, MapLoadFailed)
ERROR_SUBGROUP(Game, World)
ERROR_GROUP(Game)
CLightEnv g_LightEnv
Global light settings.
Definition: World.cpp:43
The container that holds the rules, resources and attributes of the game.
Definition: Game.h:43
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:37
Definition: MapReader.h:47
Definition: Terrain.h:52
Definition: UnitManager.h:38
CWorld is a general data class containing whatever is needed to accurately represent the world.
Definition: World.h:50
std::unique_ptr< CMapReader > m_MapReader
The map reader gets deleted just after the map is read.
Definition: World.h:109
CTerrain & GetTerrain()
Get a reference to the terrain object.
Definition: World.h:75
void RegisterInitRMS(const CStrW &scriptFile, const ScriptContext &cx, JS::HandleValue settings, int playerID)
Definition: World.cpp:98
CGame & m_Game
Reference to the CGame object representing the game.
Definition: World.h:94
const std::unique_ptr< CTerrain > m_Terrain
The CTerrain object represents the height map.
Definition: World.h:99
CWorld(CGame &game)
Constructor.
Definition: World.cpp:51
int DeleteMapReader()
Explicitly delete m_MapReader once the map has finished loading.
Definition: World.cpp:115
const std::unique_ptr< CUnitManager > m_UnitManager
The CUnitManager that holds all the units in the world.
Definition: World.h:104
void RegisterInit(const CStrW &mapFile, const ScriptContext &cx, JS::HandleValue settings, int playerID)
Initializes the game world with the attributes provided.
Definition: World.cpp:64
CUnitManager & GetUnitManager()
Get a reference to the unit manager object.
Definition: World.h:85
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:46