LCOV - code coverage report
Current view: top level - source/graphics - MapReader.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 1 100.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 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 "lib/file/vfs/vfs_path.h"
      25             : #include "lib/posix/posix_types.h"
      26             : #include "maths/Vector3D.h"
      27             : #include "ps/CStr.h"
      28             : #include "ps/Errors.h"
      29             : #include "ps/FileIo.h"
      30             : #include "ps/Loader.h"
      31             : #include "simulation2/system/Entity.h"
      32             : 
      33             : #include <cstddef>
      34             : #include <js/RootingAPI.h>
      35             : #include <js/TypeDecls.h>
      36             : #include <js/Value.h>
      37             : #include <memory>
      38             : #include <vector>
      39             : 
      40             : class CCinemaManager;
      41             : class CGameView;
      42             : class CPostprocManager;
      43             : class CSimContext;
      44             : class CSimulation2;
      45             : class CTerrain;
      46             : class CTerrainTextureEntry;
      47             : class CTriggerManager;
      48             : class CXMLReader;
      49             : class SkyManager;
      50             : class WaterManager;
      51             : namespace Script { class Context; }
      52             : namespace Script { class Interface; }
      53             : 
      54             : class CMapReader : public CMapIO
      55             : {
      56             :     friend class CXMLReader;
      57             : 
      58             : public:
      59             :     // constructor
      60             :     CMapReader();
      61             :     CMapReader(const CMapReader&) = delete;
      62             :     CMapReader& operator =(const CMapReader&) = delete;
      63             :     CMapReader(CMapReader&&) = delete;
      64             :     CMapReader& operator =(CMapReader&&) = delete;
      65             :     ~CMapReader();
      66             : 
      67             :     // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
      68             :     void LoadMap(const VfsPath& pathname, const Script::Context& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
      69             :         CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
      70             :             int playerID, bool skipEntities);
      71             : 
      72             :     void LoadRandomMap(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
      73             : 
      74             : private:
      75             :     // Load script settings for use by scripts
      76             :     int LoadScriptSettings();
      77             : 
      78             :     // load player settings only
      79             :     int LoadPlayerSettings();
      80             : 
      81             :     // load map settings only
      82             :     int LoadMapSettings();
      83             : 
      84             :     // UnpackTerrain: unpack the terrain from the input stream
      85             :     PS::Loader::Task UnpackTerrain();
      86             :     // UnpackCinema: unpack the cinematic tracks from the input stream
      87             :     int UnpackCinema();
      88             : 
      89             :     // ApplyData: take all the input data, and rebuild the scene from it
      90             :     int ApplyData();
      91             :     int ApplyTerrainData();
      92             : 
      93             :     // read some misc data from the XML file
      94             :     int ReadXML();
      95             : 
      96             :     // read entity data from the XML file
      97             :     PS::Loader::Task ReadXMLEntities();
      98             : 
      99             :     // Copy random map settings over to sim
     100             :     int LoadRMSettings();
     101             : 
     102             :     // Generate random map
     103             :     PS::Loader::Task RunMapGeneration(const CStrW& scriptFile);
     104             : 
     105             :     // Parse script data into terrain
     106             :     int ParseTerrain();
     107             : 
     108             :     // Parse script data into entities
     109             :     PS::Loader::Task ParseEntities();
     110             : 
     111             :     // Parse script data into environment
     112             :     int ParseEnvironment();
     113             : 
     114             :     // Parse script data into camera
     115             :     int ParseCamera();
     116             : 
     117             : 
     118             :     // size of map
     119             :     ssize_t m_PatchesPerSide{0};
     120             :     // heightmap for map
     121             :     std::vector<std::uint16_t> m_Heightmap;
     122             :     // list of terrain textures used by map
     123             :     std::vector<CTerrainTextureEntry*> m_TerrainTextures;
     124             :     // tile descriptions for each tile
     125             :     std::vector<STileDesc> m_Tiles;
     126             :     // lightenv stored in file
     127             :     CLightEnv m_LightEnv;
     128             :     // startup script
     129             :     CStrW m_Script;
     130             : 
     131             :     // random map data
     132             :     JS::PersistentRootedValue m_ScriptSettings;
     133             :     JS::PersistentRootedValue m_MapData;
     134             : 
     135             :     CFileUnpacker unpacker;
     136             :     CTerrain* pTerrain;
     137             :     WaterManager* pWaterMan;
     138             :     SkyManager* pSkyMan;
     139             :     CPostprocManager* pPostproc;
     140             :     CLightEnv* pLightEnv;
     141             :     CGameView* pGameView;
     142             :     CCinemaManager* pCinema;
     143             :     CTriggerManager* pTrigMan;
     144             :     CSimulation2* pSimulation2;
     145             :     const CSimContext* pSimContext;
     146             :     int m_PlayerID;
     147             :     bool m_SkipEntities;
     148             :     VfsPath m_FilenameXml;
     149             :     bool only_xml;
     150             :     std::uint32_t file_format_version;
     151             :     entity_id_t m_StartingCameraTarget;
     152             :     CVector3D m_StartingCamera;
     153             : 
     154             :     std::unique_ptr<CXMLReader> m_XmlReader;
     155             : };
     156             : 
     157             : /**
     158             :  * A restricted map reader that returns various summary information
     159             :  * for use by scripts (particularly the GUI).
     160             :  */
     161           9 : class CMapSummaryReader
     162             : {
     163             : public:
     164             :     /**
     165             :      * Try to load a map file.
     166             :      * @param pathname Path to .pmp or .xml file
     167             :      */
     168             :     PSRETURN LoadMap(const VfsPath& pathname);
     169             : 
     170             :     /**
     171             :      * Returns a value of the form:
     172             :      * @code
     173             :      * {
     174             :      *   "settings": { ... contents of the map's <ScriptSettings> ... }
     175             :      * }
     176             :      * @endcode
     177             :      */
     178             :     void GetMapSettings(const Script::Interface& scriptInterface, JS::MutableHandleValue);
     179             : 
     180             : private:
     181             :     CStr m_ScriptSettings;
     182             : };
     183             : 
     184             : #endif

Generated by: LCOV version 1.16