[Gameplay] Reduce loom cost
[0ad.git] / source / graphics / MapReader.h
blobab5618ff77c634f42d53f3d9ebf2d3487a5fd6fd
1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_MAPREADER
19 #define INCLUDED_MAPREADER
21 #include "MapIO.h"
23 #include "graphics/LightEnv.h"
24 #include "ps/CStr.h"
25 #include "ps/FileIo.h"
26 #include "scriptinterface/ScriptTypes.h"
27 #include "simulation2/system/Entity.h"
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;
38 class CTerrainTextureEntry;
39 class CGameView;
40 class CXMLReader;
41 class CMapGenerator;
42 class ScriptContext;
43 class ScriptInterface;
45 class CMapReader : public CMapIO
47 friend class CXMLReader;
49 public:
50 // constructor
51 CMapReader();
52 ~CMapReader();
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);
59 void LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
61 private:
62 // Load script settings for use by scripts
63 int LoadScriptSettings();
65 // load player settings only
66 int LoadPlayerSettings();
68 // load map settings only
69 int LoadMapSettings();
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();
76 // ApplyData: take all the input data, and rebuild the scene from it
77 int ApplyData();
78 int ApplyTerrainData();
80 // read some misc data from the XML file
81 int ReadXML();
83 // read entity data from the XML file
84 int ReadXMLEntities();
86 // Copy random map settings over to sim
87 int LoadRMSettings();
89 // Generate random map
90 int GenerateMap(const CStrW& scriptFile);
92 // Parse script data into terrain
93 int ParseTerrain();
95 // Parse script data into entities
96 int ParseEntities();
98 // Parse script data into environment
99 int ParseEnvironment();
101 // Parse script data into camera
102 int ParseCamera();
105 // size of map
106 ssize_t m_PatchesPerSide;
107 // heightmap for map
108 std::vector<u16> m_Heightmap;
109 // list of terrain textures used by map
110 std::vector<CTerrainTextureEntry*> m_TerrainTextures;
111 // tile descriptions for each tile
112 std::vector<STileDesc> m_Tiles;
113 // lightenv stored in file
114 CLightEnv m_LightEnv;
115 // startup script
116 CStrW m_Script;
118 // random map data
119 JS::PersistentRootedValue m_ScriptSettings;
120 JS::PersistentRootedValue m_MapData;
122 CMapGenerator* m_MapGen;
124 CFileUnpacker unpacker;
125 CTerrain* pTerrain;
126 WaterManager* pWaterMan;
127 SkyManager* pSkyMan;
128 CPostprocManager* pPostproc;
129 CLightEnv* pLightEnv;
130 CGameView* pGameView;
131 CCinemaManager* pCinema;
132 CTriggerManager* pTrigMan;
133 CSimulation2* pSimulation2;
134 const CSimContext* pSimContext;
135 int m_PlayerID;
136 bool m_SkipEntities;
137 VfsPath filename_xml;
138 bool only_xml;
139 u32 file_format_version;
140 entity_id_t m_StartingCameraTarget;
141 CVector3D m_StartingCamera;
143 // UnpackTerrain generator state
144 size_t cur_terrain_tex;
145 size_t num_terrain_tex;
147 CXMLReader* xml_reader;
151 * A restricted map reader that returns various summary information
152 * for use by scripts (particularly the GUI).
154 class CMapSummaryReader
156 public:
158 * Try to load a map file.
159 * @param pathname Path to .pmp or .xml file
161 PSRETURN LoadMap(const VfsPath& pathname);
164 * Returns a value of the form:
165 * @code
167 * "settings": { ... contents of the map's <ScriptSettings> ... }
169 * @endcode
171 void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue);
173 private:
174 CStr m_ScriptSettings;
177 #endif