Merge 'remotes/trunk'
[0ad.git] / source / ps / World.h
blobda967825542271245cb84c8ce0904726bc00d291
1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
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.
23 **/
24 #ifndef INCLUDED_WORLD
25 #define INCLUDED_WORLD
27 #include "ps/CStrForward.h"
28 #include "ps/Errors.h"
30 #include <memory>
32 #ifndef ERROR_GROUP_GAME_DEFINED
33 #define ERROR_GROUP_GAME_DEFINED
34 ERROR_GROUP(Game);
35 #endif
36 ERROR_SUBGROUP(Game, World);
37 ERROR_TYPE(Game_World, MapLoadFailed);
39 class CGame;
40 class CUnitManager;
41 class CTerrain;
42 class CMapReader;
43 class ScriptContext;
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 **/
49 class CWorld
51 public:
52 CWorld(CGame& game);
53 ~CWorld();
56 Initialize the World - load the map and all objects
58 void RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
61 Initialize the World - generate and load the random map
63 void RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
65 /**
66 * Explicitly delete m_MapReader once the map has finished loading.
67 **/
68 int DeleteMapReader();
70 /**
71 * Get a reference to the terrain object.
73 * @return CTerrain& dereferenced m_Terrain.
74 **/
75 CTerrain& GetTerrain()
77 return *m_Terrain;
80 /**
81 * Get a reference to the unit manager object.
83 * @return CUnitManager& dereferenced m_UnitManager.
84 **/
85 CUnitManager& GetUnitManager()
87 return *m_UnitManager;
90 private:
91 /**
92 * Reference to the CGame object representing the game.
94 CGame& m_Game;
96 /**
97 * The CTerrain object represents the height map.
99 const std::unique_ptr<CTerrain> m_Terrain;
102 * The CUnitManager that holds all the units in the world.
104 const std::unique_ptr<CUnitManager> m_UnitManager;
107 * The map reader gets deleted just after the map is read.
109 std::unique_ptr<CMapReader> m_MapReader;
112 // rationale: see definition.
113 class CLightEnv;
114 extern CLightEnv g_LightEnv;
116 #endif