2025-07-28 11:13:46 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_MAPREADER
|
|
|
|
|
#define INCLUDED_MAPREADER
|
2004-05-29 13:56:24 -07:00
|
|
|
|
|
|
|
|
#include "MapIO.h"
|
2020-11-21 03:20:29 -08:00
|
|
|
|
|
|
|
|
#include "graphics/LightEnv.h"
|
2025-07-28 11:13:46 -07:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
|
|
|
#include "lib/posix/posix_types.h"
|
|
|
|
|
#include "lib/types.h"
|
|
|
|
|
#include "maths/Vector3D.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "ps/CStr.h"
|
2025-07-28 11:13:46 -07:00
|
|
|
#include "ps/Errors.h"
|
2008-02-04 03:40:42 -08:00
|
|
|
#include "ps/FileIo.h"
|
2025-10-20 12:55:24 -07:00
|
|
|
#include "ps/Loader.h"
|
2010-07-03 06:15:57 -07:00
|
|
|
#include "simulation2/system/Entity.h"
|
2004-05-29 13:56:24 -07:00
|
|
|
|
2025-07-28 11:13:46 -07:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
2023-11-19 11:19:32 -08:00
|
|
|
#include <memory>
|
2025-07-28 11:13:46 -07:00
|
|
|
#include <vector>
|
2023-11-19 11:19:32 -08:00
|
|
|
|
2006-08-21 19:24:44 -07:00
|
|
|
class CCinemaManager;
|
2025-07-28 11:13:46 -07:00
|
|
|
class CGameView;
|
2012-10-15 03:34:23 -07:00
|
|
|
class CPostprocManager;
|
2011-10-24 07:31:05 -07:00
|
|
|
class CSimContext;
|
2025-07-28 11:13:46 -07:00
|
|
|
class CSimulation2;
|
|
|
|
|
class CTerrain;
|
2010-09-04 14:26:52 -07:00
|
|
|
class CTerrainTextureEntry;
|
2025-07-28 11:13:46 -07:00
|
|
|
class CTriggerManager;
|
2005-05-03 14:42:09 -07:00
|
|
|
class CXMLReader;
|
2021-05-03 09:07:26 -07:00
|
|
|
class ScriptContext;
|
|
|
|
|
class ScriptInterface;
|
2025-07-28 11:13:46 -07:00
|
|
|
class SkyManager;
|
|
|
|
|
class WaterManager;
|
2005-05-03 14:42:09 -07:00
|
|
|
|
2004-05-29 13:56:24 -07:00
|
|
|
class CMapReader : public CMapIO
|
|
|
|
|
{
|
2005-05-10 20:07:08 -07:00
|
|
|
friend class CXMLReader;
|
|
|
|
|
|
2004-05-29 13:56:24 -07:00
|
|
|
public:
|
|
|
|
|
// constructor
|
|
|
|
|
CMapReader();
|
2025-11-03 10:22:06 -08:00
|
|
|
CMapReader(const CMapReader&) = delete;
|
|
|
|
|
CMapReader& operator =(const CMapReader&) = delete;
|
|
|
|
|
CMapReader(CMapReader&&) = delete;
|
|
|
|
|
CMapReader& operator =(CMapReader&&) = delete;
|
2011-04-09 22:31:18 -07:00
|
|
|
~CMapReader();
|
|
|
|
|
|
2004-05-29 13:56:24 -07:00
|
|
|
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
|
2020-11-18 06:39:04 -08:00
|
|
|
void LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
|
2016-11-23 03:18:37 -08:00
|
|
|
CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
|
2012-10-15 03:34:23 -07:00
|
|
|
int playerID, bool skipEntities);
|
2010-10-29 21:02:42 -07:00
|
|
|
|
2020-11-18 06:39:04 -08:00
|
|
|
void LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
|
2004-05-29 13:56:24 -07:00
|
|
|
|
|
|
|
|
private:
|
2010-10-29 21:02:42 -07:00
|
|
|
// Load script settings for use by scripts
|
|
|
|
|
int LoadScriptSettings();
|
|
|
|
|
|
|
|
|
|
// load player settings only
|
|
|
|
|
int LoadPlayerSettings();
|
|
|
|
|
|
|
|
|
|
// load map settings only
|
|
|
|
|
int LoadMapSettings();
|
|
|
|
|
|
2004-05-29 13:56:24 -07:00
|
|
|
// UnpackTerrain: unpack the terrain from the input stream
|
2025-10-20 12:55:24 -07:00
|
|
|
PS::Loader::Task UnpackTerrain();
|
2015-12-31 05:40:56 -08:00
|
|
|
// UnpackCinema: unpack the cinematic tracks from the input stream
|
2006-08-21 19:24:44 -07:00
|
|
|
int UnpackCinema();
|
2004-05-29 13:56:24 -07:00
|
|
|
|
|
|
|
|
// ApplyData: take all the input data, and rebuild the scene from it
|
2005-05-03 14:42:09 -07:00
|
|
|
int ApplyData();
|
2014-06-01 11:08:11 -07:00
|
|
|
int ApplyTerrainData();
|
2004-05-29 13:56:24 -07:00
|
|
|
|
2014-06-01 11:08:11 -07:00
|
|
|
// read some misc data from the XML file
|
2005-05-03 14:42:09 -07:00
|
|
|
int ReadXML();
|
2005-03-22 13:00:56 -08:00
|
|
|
|
2014-06-01 11:08:11 -07:00
|
|
|
// read entity data from the XML file
|
2025-10-20 12:55:24 -07:00
|
|
|
PS::Loader::Task ReadXMLEntities();
|
2014-06-01 11:08:11 -07:00
|
|
|
|
2011-03-21 18:34:45 -07:00
|
|
|
// Copy random map settings over to sim
|
|
|
|
|
int LoadRMSettings();
|
|
|
|
|
|
|
|
|
|
// Generate random map
|
2025-10-20 12:55:24 -07:00
|
|
|
PS::Loader::Task RunMapGeneration(const CStrW& scriptFile);
|
2011-03-21 18:34:45 -07:00
|
|
|
|
|
|
|
|
// Parse script data into terrain
|
|
|
|
|
int ParseTerrain();
|
|
|
|
|
|
|
|
|
|
// Parse script data into entities
|
2025-10-20 12:55:24 -07:00
|
|
|
PS::Loader::Task ParseEntities();
|
2011-03-21 18:34:45 -07:00
|
|
|
|
|
|
|
|
// Parse script data into environment
|
|
|
|
|
int ParseEnvironment();
|
|
|
|
|
|
|
|
|
|
// Parse script data into camera
|
|
|
|
|
int ParseCamera();
|
|
|
|
|
|
2005-01-12 06:31:47 -08:00
|
|
|
|
2016-11-23 03:18:37 -08:00
|
|
|
// size of map
|
2023-11-19 11:19:32 -08:00
|
|
|
ssize_t m_PatchesPerSide{0};
|
2004-05-29 13:56:24 -07:00
|
|
|
// heightmap for map
|
|
|
|
|
std::vector<u16> m_Heightmap;
|
|
|
|
|
// list of terrain textures used by map
|
2010-09-04 14:26:52 -07:00
|
|
|
std::vector<CTerrainTextureEntry*> m_TerrainTextures;
|
2004-05-29 13:56:24 -07:00
|
|
|
// tile descriptions for each tile
|
|
|
|
|
std::vector<STileDesc> m_Tiles;
|
|
|
|
|
// lightenv stored in file
|
|
|
|
|
CLightEnv m_LightEnv;
|
2010-04-29 16:22:18 -07:00
|
|
|
// startup script
|
|
|
|
|
CStrW m_Script;
|
2005-03-22 13:00:56 -08:00
|
|
|
|
2011-03-21 18:34:45 -07:00
|
|
|
// random map data
|
2016-09-02 09:53:22 -07:00
|
|
|
JS::PersistentRootedValue m_ScriptSettings;
|
|
|
|
|
JS::PersistentRootedValue m_MapData;
|
2011-03-21 18:34:45 -07:00
|
|
|
|
2005-03-22 13:00:56 -08:00
|
|
|
CFileUnpacker unpacker;
|
2005-05-03 14:42:09 -07:00
|
|
|
CTerrain* pTerrain;
|
2006-06-11 00:03:59 -07:00
|
|
|
WaterManager* pWaterMan;
|
2006-06-21 15:37:31 -07:00
|
|
|
SkyManager* pSkyMan;
|
2012-10-15 03:34:23 -07:00
|
|
|
CPostprocManager* pPostproc;
|
2005-05-03 14:42:09 -07:00
|
|
|
CLightEnv* pLightEnv;
|
2010-08-13 06:26:29 -07:00
|
|
|
CGameView* pGameView;
|
2006-08-21 19:24:44 -07:00
|
|
|
CCinemaManager* pCinema;
|
2006-11-24 11:45:04 -08:00
|
|
|
CTriggerManager* pTrigMan;
|
2010-02-08 14:05:05 -08:00
|
|
|
CSimulation2* pSimulation2;
|
2011-10-24 07:31:05 -07:00
|
|
|
const CSimContext* pSimContext;
|
2010-07-03 06:15:57 -07:00
|
|
|
int m_PlayerID;
|
2011-10-24 07:31:05 -07:00
|
|
|
bool m_SkipEntities;
|
2025-11-03 01:25:48 -08:00
|
|
|
VfsPath m_FilenameXml;
|
2010-05-03 12:13:58 -07:00
|
|
|
bool only_xml;
|
|
|
|
|
u32 file_format_version;
|
2011-06-13 16:32:41 -07:00
|
|
|
entity_id_t m_StartingCameraTarget;
|
|
|
|
|
CVector3D m_StartingCamera;
|
2005-05-03 14:42:09 -07:00
|
|
|
|
2025-11-03 01:25:48 -08:00
|
|
|
std::unique_ptr<CXMLReader> m_XmlReader;
|
2004-05-29 13:56:24 -07:00
|
|
|
};
|
|
|
|
|
|
2010-08-04 14:15:41 -07:00
|
|
|
/**
|
|
|
|
|
* A restricted map reader that returns various summary information
|
|
|
|
|
* for use by scripts (particularly the GUI).
|
|
|
|
|
*/
|
|
|
|
|
class CMapSummaryReader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Try to load a map file.
|
|
|
|
|
* @param pathname Path to .pmp or .xml file
|
|
|
|
|
*/
|
|
|
|
|
PSRETURN LoadMap(const VfsPath& pathname);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a value of the form:
|
|
|
|
|
* @code
|
|
|
|
|
* {
|
|
|
|
|
* "settings": { ... contents of the map's <ScriptSettings> ... }
|
|
|
|
|
* }
|
|
|
|
|
* @endcode
|
|
|
|
|
*/
|
2017-08-23 17:32:42 -07:00
|
|
|
void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue);
|
2010-08-04 14:15:41 -07:00
|
|
|
|
|
|
|
|
private:
|
2011-02-17 12:08:20 -08:00
|
|
|
CStr m_ScriptSettings;
|
2010-08-04 14:15:41 -07:00
|
|
|
};
|
|
|
|
|
|
2004-06-02 08:03:17 -07:00
|
|
|
#endif
|