Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapReader.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 #include "lib/res/handle.h"
23 #include "ps/CStr.h"
24 #include "LightEnv.h"
25 #include "ps/FileIo.h"
28 
29 class CObjectEntry;
30 class CTerrain;
31 class WaterManager;
32 class SkyManager;
33 class CLightEnv;
34 class CCinemaManager;
35 class CPostprocManager;
36 class CTriggerManager;
37 class CSimulation2;
38 class CSimContext;
40 class CScriptValRooted;
41 class ScriptInterface;
42 class CGameView;
43 class CXMLReader;
44 class CMapGenerator;
45 
46 class CMapReader : public CMapIO
47 {
48  friend class CXMLReader;
49 
50 public:
51  // constructor
52  CMapReader();
53  ~CMapReader();
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 CScriptValRooted& settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
57  CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
58  int playerID, bool skipEntities);
59 
60  void LoadRandomMap(const CStrW& scriptFile, const CScriptValRooted& settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
61 
62 private:
63  // Load script settings for use by scripts
64  int LoadScriptSettings();
65 
66  // load player settings only
67  int LoadPlayerSettings();
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
75  int UnpackCinema();
76 
77  // UnpackMap: unpack the given data from the raw data stream into local variables
78  int UnpackMap();
79 
80  // ApplyData: take all the input data, and rebuild the scene from it
81  int ApplyData();
82 
83  // ReadXML: read some other data (entities, etc) in XML format
84  int ReadXML();
85 
86  // clean up everything used during delayed load
87  int DelayLoadFinished();
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
125 
127 
128  // state latched by LoadMap and held until DelayedLoadFinished
137  CTriggerManager* pTrigMan;
143  bool only_xml;
147 
148  // UnpackTerrain generator state
151 
153 };
154 
155 /**
156  * A restricted map reader that returns various summary information
157  * for use by scripts (particularly the GUI).
158  */
160 {
161 public:
162  /**
163  * Try to load a map file.
164  * @param pathname Path to .pmp or .xml file
165  */
166  PSRETURN LoadMap(const VfsPath& pathname);
167 
168  /**
169  * Returns a value of the form:
170  * @code
171  * {
172  * "settings": { ... contents of the map's <ScriptSettings> ... }
173  * }
174  * @endcode
175  */
177 
178 private:
180 };
181 
182 #endif
CScriptValRooted GetMapSettings(ScriptInterface &scriptInterface)
Returns a value of the form:
Definition: MapReader.cpp:373
CPostprocManager * pPostproc
Definition: MapReader.h:133
std::vector< CTerrainTextureEntry * > m_TerrainTextures
Definition: MapReader.h:113
int ParseEntities()
Definition: MapReader.cpp:1339
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:1402
int ReadXML()
Definition: MapReader.cpp:1171
CFileUnpacker unpacker
Definition: MapReader.h:129
CScriptValRooted m_MapData
Definition: MapReader.h:124
SkyManager * pSkyMan
Definition: MapReader.h:132
helper class for reading binary files
Definition: FileIo.h:100
CCinemaManager * pCinema
Definition: MapReader.h:136
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
Random map generator interface.
Definition: MapGenerator.h:37
Public API for simulation system.
Definition: Simulation2.h:46
int ParseTerrain()
Definition: MapReader.cpp:1265
int UnpackCinema()
int ParseCamera()
Definition: MapReader.cpp:1479
CVector3D m_StartingCamera
Definition: MapReader.h:146
size_t num_terrain_tex
Definition: MapReader.h:150
u32 PSRETURN
Definition: Errors.h:75
Definition: path.h:75
WaterManager * pWaterMan
Definition: MapReader.h:131
int LoadScriptSettings()
Definition: MapReader.cpp:1142
bool m_SkipEntities
Definition: MapReader.h:141
u32 file_format_version
Definition: MapReader.h:144
CScriptValRooted m_ScriptSettings
Definition: MapReader.h:123
void LoadMap(const VfsPath &pathname, const CScriptValRooted &settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc, CSimulation2 *, const CSimContext *, int playerID, bool skipEntities)
Definition: MapReader.cpp:67
ssize_t m_PatchesPerSide
Definition: MapReader.h:109
int UnpackTerrain()
Definition: MapReader.cpp:219
int m_PlayerID
Definition: MapReader.h:140
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:1199
void LoadRandomMap(const CStrW &scriptFile, const CScriptValRooted &settings, CTerrain *, WaterManager *, SkyManager *, CLightEnv *, CGameView *, CCinemaManager *, CTriggerManager *, CPostprocManager *pPostproc_, CSimulation2 *, int playerID)
Definition: MapReader.cpp:146
size_t cur_terrain_tex
Definition: MapReader.h:149
PSRETURN LoadMap(const VfsPath &pathname)
Try to load a map file.
Definition: MapReader.cpp:342
int GenerateMap()
Definition: MapReader.cpp:1208
#define u32
Definition: types.h:41
int LoadPlayerSettings()
Definition: MapReader.cpp:1155
int UnpackMap()
Definition: MapReader.cpp:205
CLightEnv * pLightEnv
Definition: MapReader.h:134
CTriggerManager * pTrigMan
Definition: MapReader.h:137
CStrW m_Script
Definition: MapReader.h:119
entity_id_t m_StartingCameraTarget
Definition: MapReader.h:145
const CSimContext * pSimContext
Definition: MapReader.h:139
Abstraction around a SpiderMonkey JSContext.
CSimulation2 * pSimulation2
Definition: MapReader.h:138
int ApplyData()
Definition: MapReader.cpp:268
int DelayLoadFinished()
Definition: MapReader.cpp:1186
Definition: MapIO.h:21
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:36
int LoadMapSettings()
Definition: MapReader.cpp:1163
CGameView * pGameView
Definition: MapReader.h:135
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
bool only_xml
Definition: MapReader.h:143
A restricted map reader that returns various summary information for use by scripts (particularly the...
Definition: MapReader.h:159
CTerrain * pTerrain
Definition: MapReader.h:130
CXMLReader * xml_reader
Definition: MapReader.h:152
VfsPath filename_xml
Definition: MapReader.h:142
Class WaterManager: Maintain water settings and textures.
Definition: WaterManager.h:49
Class SkyManager: Maintain sky settings and textures, and render the sky.
Definition: SkyManager.h:30