Line data Source code
1 : /* Copyright (C) 2026 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/Errors.h" 28 : 29 : #include <js/TypeDecls.h> 30 : #include <memory> 31 : 32 : class CGame; 33 : class CMapReader; 34 : class CStrW; 35 : class CTerrain; 36 : class CUnitManager; 37 : namespace Script { class Context; } 38 : 39 : #ifndef ERROR_GROUP_GAME_DEFINED 40 : #define ERROR_GROUP_GAME_DEFINED 41 : ERROR_GROUP(Game); 42 : #endif 43 : ERROR_SUBGROUP(Game, World); 44 : ERROR_TYPE(Game_World, MapLoadFailed); 45 : 46 : /** 47 : * CWorld is a general data class containing whatever is needed to accurately represent the world. 48 : * This includes the map, entities, influence maps, tiles, heightmap, etc. 49 : **/ 50 : class CWorld 51 : { 52 : public: 53 : CWorld(CGame& game); 54 : ~CWorld(); 55 : 56 : /* 57 : Initialize the World - load the map and all objects 58 : */ 59 : void RegisterInit(const CStrW& mapFile, const Script::Context& cx, JS::HandleValue settings, int playerID); 60 : 61 : /* 62 : Initialize the World - generate and load the random map 63 : */ 64 : void RegisterInitRMS(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, int playerID); 65 : 66 : /** 67 : * Explicitly delete m_MapReader once the map has finished loading. 68 : **/ 69 : int DeleteMapReader(); 70 : 71 : /** 72 : * Get a reference to the terrain object. 73 : * 74 : * @return CTerrain& dereferenced m_Terrain. 75 : **/ 76 3 : CTerrain& GetTerrain() 77 : { 78 3 : return *m_Terrain; 79 : } 80 : 81 : /** 82 : * Get a reference to the unit manager object. 83 : * 84 : * @return CUnitManager& dereferenced m_UnitManager. 85 : **/ 86 3 : CUnitManager& GetUnitManager() 87 : { 88 3 : return *m_UnitManager; 89 : } 90 : 91 : private: 92 : /** 93 : * Reference to the CGame object representing the game. 94 : */ 95 : CGame& m_Game; 96 : 97 : /** 98 : * The CTerrain object represents the height map. 99 : */ 100 : const std::unique_ptr<CTerrain> m_Terrain; 101 : 102 : /** 103 : * The CUnitManager that holds all the units in the world. 104 : */ 105 : const std::unique_ptr<CUnitManager> m_UnitManager; 106 : 107 : /** 108 : * The map reader gets deleted just after the map is read. 109 : */ 110 : std::unique_ptr<CMapReader> m_MapReader; 111 : }; 112 : 113 : // rationale: see definition. 114 : class CLightEnv; 115 : extern CLightEnv g_LightEnv; 116 : 117 : #endif