Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
World.h
Go to the documentation of this file.
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
32class CGame;
33class CMapReader;
34class CStrW;
35class CTerrain;
36class CUnitManager;
37namespace Script { class Context; }
38
39#ifndef ERROR_GROUP_GAME_DEFINED
40#define ERROR_GROUP_GAME_DEFINED
42#endif
43ERROR_SUBGROUP(Game, World);
44ERROR_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 **/
50class CWorld
51{
52public:
53 CWorld(CGame& game);
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 **/
77 {
78 return *m_Terrain;
79 }
80
81 /**
82 * Get a reference to the unit manager object.
83 *
84 * @return CUnitManager& dereferenced m_UnitManager.
85 **/
87 {
88 return *m_UnitManager;
89 }
90
91private:
92 /**
93 * Reference to the CGame object representing the game.
94 */
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.
114class CLightEnv;
115extern CLightEnv g_LightEnv;
116
117#endif
ERROR_TYPE(Game_World, MapLoadFailed)
ERROR_SUBGROUP(Game, World)
ERROR_GROUP(Game)
CLightEnv g_LightEnv
Global light settings.
Definition: World.cpp:48
The container that holds the rules, resources and attributes of the game.
Definition: Game.h:49
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:36
Definition: MapReader.h:55
Definition: Terrain.h:52
Definition: UnitManager.h:39
CWorld is a general data class containing whatever is needed to accurately represent the world.
Definition: World.h:51
std::unique_ptr< CMapReader > m_MapReader
The map reader gets deleted just after the map is read.
Definition: World.h:110
CTerrain & GetTerrain()
Get a reference to the terrain object.
Definition: World.h:76
CGame & m_Game
Reference to the CGame object representing the game.
Definition: World.h:95
const std::unique_ptr< CTerrain > m_Terrain
The CTerrain object represents the height map.
Definition: World.h:100
void RegisterInitRMS(const CStrW &scriptFile, const Script::Context &cx, JS::HandleValue settings, int playerID)
Definition: World.cpp:103
CWorld(CGame &game)
Constructor.
Definition: World.cpp:56
int DeleteMapReader()
Explicitly delete m_MapReader once the map has finished loading.
Definition: World.cpp:120
const std::unique_ptr< CUnitManager > m_UnitManager
The CUnitManager that holds all the units in the world.
Definition: World.h:105
void RegisterInit(const CStrW &mapFile, const Script::Context &cx, JS::HandleValue settings, int playerID)
Initializes the game world with the attributes provided.
Definition: World.cpp:69
CUnitManager & GetUnitManager()
Get a reference to the unit manager object.
Definition: World.h:86
Definition: Context.h:51
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32