Pyrogenesis  trunk
MapReader.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 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 class CTerrain;
30 class WaterManager;
31 class SkyManager;
32 class CLightEnv;
33 class CCinemaManager;
34 class CPostprocManager;
35 class CTriggerManager;
36 class CSimulation2;
37 class CSimContext;
39 class CGameView;
40 class CXMLReader;
41 class CMapGenerator;
42 class ScriptContext;
43 class ScriptInterface;
44 
45 class CMapReader : public CMapIO
46 {
47  friend class CXMLReader;
48 
49 public:
50  // constructor
51  CMapReader();
52  ~CMapReader();
53 
54  // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
55  void LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
56  CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
57  int playerID, bool skipEntities);
58 
59  void LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
60 
61 private:
62  // Load script settings for use by scripts
63  int LoadScriptSettings();
64 
65  // load player settings only
66  int LoadPlayerSettings();
67 
68  // load map settings only
69  int LoadMapSettings();
70 
71  // UnpackTerrain: unpack the terrain from the input stream
72  int UnpackTerrain();
73  // UnpackCinema: unpack the cinematic tracks from the input stream
74  int UnpackCinema();
75 
76  // UnpackMap: unpack the given data from the raw data stream into local variables
77  int UnpackMap();
78 
79  // ApplyData: take all the input data, and rebuild the scene from it
80  int ApplyData();
81  int ApplyTerrainData();
82 
83  // read some misc data from the XML file
84  int ReadXML();
85 
86  // read entity data from the XML file
87  int ReadXMLEntities();
88 
89  // Copy random map settings over to sim
90  int LoadRMSettings();
91 
92  // Generate random map
93  int GenerateMap();
94 
95  // Parse script data into terrain
96  int ParseTerrain();
97 
98  // Parse script data into entities
99  int ParseEntities();
100 
101  // Parse script data into environment
102  int ParseEnvironment();
103 
104  // Parse script data into camera
105  int ParseCamera();
106 
107 
108  // size of map
110  // heightmap for map
111  std::vector<u16> m_Heightmap;
112  // list of terrain textures used by map
113  std::vector<CTerrainTextureEntry*> m_TerrainTextures;
114  // tile descriptions for each tile
115  std::vector<STileDesc> m_Tiles;
116  // lightenv stored in file
118  // startup script
119  CStrW m_Script;
120 
121  // random map data
123  JS::PersistentRootedValue m_ScriptSettings;
124  JS::PersistentRootedValue m_MapData;
125 
127 
136  CTriggerManager* pTrigMan;
142  bool only_xml;
146 
147  // UnpackTerrain 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 {
160 public:
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 
177 private:
179 };
180 
181 #endif
JS::PersistentRootedValue m_ScriptSettings
Definition: MapReader.h:123
CPostprocManager * pPostproc
Definition: MapReader.h:132
std::vector< CTerrainTextureEntry * > m_TerrainTextures
Definition: MapReader.h:113
int ReadXMLEntities()
Definition: MapReader.cpp:1246
int ParseEntities()
Definition: MapReader.cpp:1413
CMapGenerator * m_MapGen
Definition: MapReader.h:126
CLightEnv m_LightEnv
Definition: MapReader.h:117
std::vector< u16 > m_Heightmap
Definition: MapReader.h:111
int ParseEnvironment()
Definition: MapReader.cpp:1477
int ReadXML()
Definition: MapReader.cpp:1235
CFileUnpacker unpacker
Definition: MapReader.h:128
Definition: Vector3D.h:30
Definition: Terrain.h:51
SkyManager * pSkyMan
Definition: MapReader.h:131
helper class for reading binary files
Definition: FileIo.h:100
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:40
CMapReader()
Definition: MapReader.cpp:66
Definition: TerrainTextureEntry.h:32
CCinemaManager * pCinema
Definition: MapReader.h:135
Contains pointers to various &#39;global&#39; objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition: SimContext.h:32
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
Random map generator interface.
Definition: MapGenerator.h:39
int ApplyTerrainData()
Definition: MapReader.cpp:271
JS::PersistentRootedValue m_MapData
Definition: MapReader.h:124
Definition: MapReader.cpp:406
Public API for simulation system.
Definition: Simulation2.h:46
int ParseTerrain()
Definition: MapReader.cpp:1336
~CMapReader()
Definition: MapReader.cpp:1611
int UnpackCinema()
Definition: MapReader.h:45
int ParseCamera()
Definition: MapReader.cpp:1573
uint32_t u32
Definition: types.h:39
CVector3D m_StartingCamera
Definition: MapReader.h:145
size_t num_terrain_tex
Definition: MapReader.h:149
u32 PSRETURN
Definition: Errors.h:75
Definition: path.h:79
WaterManager * pWaterMan
Definition: MapReader.h:130
int LoadScriptSettings()
Definition: MapReader.cpp:1207
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:155
bool m_SkipEntities
Definition: MapReader.h:140
u32 file_format_version
Definition: MapReader.h:143
CStr m_ScriptSettings
Definition: MapReader.h:178
Definition: GameView.h:36
ssize_t m_PatchesPerSide
Definition: MapReader.h:109
int UnpackTerrain()
Definition: MapReader.cpp:221
int m_PlayerID
Definition: MapReader.h:139
CStrW m_ScriptFile
Definition: MapReader.h:122
std::vector< STileDesc > m_Tiles
Definition: MapReader.h:115
intptr_t ssize_t
Definition: wposix_types.h:82
int LoadRMSettings()
Definition: MapReader.cpp:1266
size_t cur_terrain_tex
Definition: MapReader.h:148
int GenerateMap()
Definition: MapReader.cpp:1275
int LoadPlayerSettings()
Definition: MapReader.cpp:1220
int UnpackMap()
Definition: MapReader.cpp:214
Class for in game playing of cinematics.
Definition: CinemaManager.h:28
CLightEnv * pLightEnv
Definition: MapReader.h:133
CTriggerManager * pTrigMan
Definition: MapReader.h:136
Definition: PostprocManager.h:31
CStrW m_Script
Definition: MapReader.h:119
entity_id_t m_StartingCameraTarget
Definition: MapReader.h:144
const CSimContext * pSimContext
Definition: MapReader.h:138
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
CSimulation2 * pSimulation2
Definition: MapReader.h:137
int ApplyData()
Definition: MapReader.cpp:313
Definition: MapIO.h:29
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:36
int LoadMapSettings()
Definition: MapReader.cpp:1228
CGameView * pGameView
Definition: MapReader.h:134
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
bool only_xml
Definition: MapReader.h:142
A restricted map reader that returns various summary information for use by scripts (particularly the...
Definition: MapReader.h:158
CTerrain * pTerrain
Definition: MapReader.h:129
CXMLReader * xml_reader
Definition: MapReader.h:151
VfsPath filename_xml
Definition: MapReader.h:141
Class WaterManager: Maintain rendering-related water settings and textures Anything that affects game...
Definition: WaterManager.h:47
Class SkyManager: Maintain sky settings and textures, and render the sky.
Definition: SkyManager.h:37