Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MapReader.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#ifndef INCLUDED_MAPREADER
19#define INCLUDED_MAPREADER
20
21#include "MapIO.h"
22
23#include "graphics/LightEnv.h"
24#include "ps/CStr.h"
25#include "ps/FileIo.h"
28
29#include <memory>
30
31class CTerrain;
32class WaterManager;
33class SkyManager;
34class CLightEnv;
35class CCinemaManager;
37class CTriggerManager;
38class CSimulation2;
39class CSimContext;
41class CGameView;
42class CXMLReader;
43class ScriptContext;
44class ScriptInterface;
45
46class CMapReader : public CMapIO
47{
48 friend class CXMLReader;
49
50public:
51 // constructor
54
55 // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
56 void LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
58 int playerID, bool skipEntities);
59
60 void LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
61
62private:
63 // Load script settings for use by scripts
65
66 // load player settings only
68
69 // load map settings only
70 int LoadMapSettings();
71
72 // UnpackTerrain: unpack the terrain from the input stream
73 int UnpackTerrain();
74 // UnpackCinema: unpack the cinematic tracks from the input stream
76
77 // ApplyData: take all the input data, and rebuild the scene from it
78 int ApplyData();
79 int ApplyTerrainData();
80
81 // read some misc data from the XML file
82 int ReadXML();
83
84 // read entity data from the XML file
85 int ReadXMLEntities();
86
87 // Copy random map settings over to sim
88 int LoadRMSettings();
89
90 // Generate random map
91 int StartMapGeneration(const CStrW& scriptFile);
93
94 // Parse script data into terrain
95 int ParseTerrain();
96
97 // Parse script data into entities
98 int ParseEntities();
99
100 // Parse script data into environment
101 int ParseEnvironment();
102
103 // Parse script data into camera
104 int ParseCamera();
105
106
107 // size of map
109 // heightmap for map
110 std::vector<u16> m_Heightmap;
111 // list of terrain textures used by map
112 std::vector<CTerrainTextureEntry*> m_TerrainTextures;
113 // tile descriptions for each tile
114 std::vector<STileDesc> m_Tiles;
115 // lightenv stored in file
117 // startup script
118 CStrW m_Script;
119
120 // random map data
121 JS::PersistentRootedValue m_ScriptSettings;
122 JS::PersistentRootedValue m_MapData;
123
124 struct GeneratorState;
125 std::unique_ptr<GeneratorState> m_GeneratorState;
126
135 CTriggerManager* pTrigMan;
145
146 // UnpackTerrain generator state
147 // It's important to initialize it to 0 - resets generator state
150
152};
153
154/**
155 * A restricted map reader that returns various summary information
156 * for use by scripts (particularly the GUI).
157 */
159{
160public:
161 /**
162 * Try to load a map file.
163 * @param pathname Path to .pmp or .xml file
164 */
165 PSRETURN LoadMap(const VfsPath& pathname);
166
167 /**
168 * Returns a value of the form:
169 * @code
170 * {
171 * "settings": { ... contents of the map's <ScriptSettings> ... }
172 * }
173 * @endcode
174 */
175 void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue);
176
177private:
179};
180
181#endif
u32 PSRETURN
Definition: Errors.h:75
Class for in game playing of cinematics.
Definition: CinemaManager.h:29
helper class for reading binary files
Definition: FileIo.h:101
Definition: GameView.h:37
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:37
Definition: MapIO.h:30
Definition: MapReader.h:47
int ParseEnvironment()
Definition: MapReader.cpp:1533
int ApplyData()
Definition: MapReader.cpp:368
CVector3D m_StartingCamera
Definition: MapReader.h:144
CStrW m_Script
Definition: MapReader.h:118
bool m_SkipEntities
Definition: MapReader.h:139
int LoadRMSettings()
Definition: MapReader.cpp:1321
int m_PlayerID
Definition: MapReader.h:138
CGameView * pGameView
Definition: MapReader.h:133
CXMLReader * xml_reader
Definition: MapReader.h:151
size_t cur_terrain_tex
Definition: MapReader.h:148
int LoadScriptSettings()
Definition: MapReader.cpp:1262
size_t num_terrain_tex
Definition: MapReader.h:149
CFileUnpacker unpacker
Definition: MapReader.h:127
CCinemaManager * pCinema
Definition: MapReader.h:134
int ApplyTerrainData()
Definition: MapReader.cpp:326
int PollMapGeneration()
Definition: MapReader.cpp:1367
CLightEnv m_LightEnv
Definition: MapReader.h:116
int ParseCamera()
Definition: MapReader.cpp:1629
int UnpackTerrain()
Definition: MapReader.cpp:276
CPostprocManager * pPostproc
Definition: MapReader.h:131
bool only_xml
Definition: MapReader.h:141
const CSimContext * pSimContext
Definition: MapReader.h:137
u32 file_format_version
Definition: MapReader.h:142
std::vector< STileDesc > m_Tiles
Definition: MapReader.h:114
~CMapReader()
Definition: MapReader.cpp:1667
SkyManager * pSkyMan
Definition: MapReader.h:130
int ReadXML()
Definition: MapReader.cpp:1290
int ReadXMLEntities()
Definition: MapReader.cpp:1301
CSimulation2 * pSimulation2
Definition: MapReader.h:136
int StartMapGeneration(const CStrW &scriptFile)
Definition: MapReader.cpp:1336
int UnpackCinema()
CLightEnv * pLightEnv
Definition: MapReader.h:132
void LoadMap(const VfsPath &pathname, const ScriptContext &cx, JS::HandleValue settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc, CSimulation2 *, const CSimContext *, int playerID, bool skipEntities)
Definition: MapReader.cpp:73
int ParseEntities()
Definition: MapReader.cpp:1469
int ParseTerrain()
Definition: MapReader.cpp:1392
int LoadMapSettings()
Definition: MapReader.cpp:1283
VfsPath filename_xml
Definition: MapReader.h:140
void LoadRandomMap(const CStrW &scriptFile, const ScriptContext &cx, JS::HandleValue settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc_, CSimulation2 *, int playerID)
Definition: MapReader.cpp:182
WaterManager * pWaterMan
Definition: MapReader.h:129
CTerrain * pTerrain
Definition: MapReader.h:128
std::unique_ptr< GeneratorState > m_GeneratorState
Definition: MapReader.h:125
JS::PersistentRootedValue m_ScriptSettings
Definition: MapReader.h:121
ssize_t m_PatchesPerSide
Definition: MapReader.h:108
JS::PersistentRootedValue m_MapData
Definition: MapReader.h:122
CTriggerManager * pTrigMan
Definition: MapReader.h:135
int LoadPlayerSettings()
Definition: MapReader.cpp:1275
entity_id_t m_StartingCameraTarget
Definition: MapReader.h:143
std::vector< u16 > m_Heightmap
Definition: MapReader.h:110
std::vector< CTerrainTextureEntry * > m_TerrainTextures
Definition: MapReader.h:112
A restricted map reader that returns various summary information for use by scripts (particularly the...
Definition: MapReader.h:159
void GetMapSettings(const ScriptInterface &scriptInterface, JS::MutableHandleValue)
Returns a value of the form:
Definition: MapReader.cpp:440
PSRETURN LoadMap(const VfsPath &pathname)
Try to load a map file.
Definition: MapReader.cpp:409
CStr m_ScriptSettings
Definition: MapReader.h:178
Definition: PostprocManager.h:32
Contains pointers to various 'global' objects that are needed by the simulation code,...
Definition: SimContext.h:33
Public API for simulation system.
Definition: Simulation2.h:47
Definition: TerrainTextureEntry.h:33
Definition: Terrain.h:52
Definition: Vector3D.h:31
Definition: MapReader.cpp:462
Definition: path.h:80
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:46
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
Class SkyManager: Maintain sky settings and textures, and render the sky.
Definition: SkyManager.h:38
Class WaterManager: Maintain rendering-related water settings and textures Anything that affects game...
Definition: WaterManager.h:48
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
Definition: MapReader.cpp:1331
uint32_t u32
Definition: types.h:39
intptr_t ssize_t
Definition: wposix_types.h:82