LCOV - code coverage report
Current view: top level - source/ps - World.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 42 4.8 %
Date: 2023-01-19 00:18:29 Functions: 2 7 28.6 %

          Line data    Source code
       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             : #include "precompiled.h"
      19             : 
      20             : #include "graphics/GameView.h"
      21             : #include "graphics/LightEnv.h"
      22             : #include "graphics/MapReader.h"
      23             : #include "graphics/MapWriter.h"
      24             : #include "graphics/Terrain.h"
      25             : #include "graphics/Terrain.h"
      26             : #include "graphics/UnitManager.h"
      27             : #include "lib/timer.h"
      28             : #include "ps/CLogger.h"
      29             : #include "ps/CStr.h"
      30             : #include "ps/Errors.h"
      31             : #include "ps/Game.h"
      32             : #include "ps/Loader.h"
      33             : #include "ps/LoaderThunks.h"
      34             : #include "ps/World.h"
      35             : #include "renderer/Renderer.h"
      36             : #include "renderer/SceneRenderer.h"
      37             : #include "simulation2/Simulation2.h"
      38             : 
      39             : /**
      40             :  * Global light settings.
      41             :  * It is not a member of CWorld because it is passed
      42             :  * to the renderer before CWorld exists.
      43             :  **/
      44           1 : CLightEnv g_LightEnv;
      45             : 
      46             : 
      47             : /**
      48             :  * Constructor.
      49             :  *
      50             :  * @param pGame CGame * pGame pointer to the container game object.
      51             :  **/
      52           0 : CWorld::CWorld(CGame *pGame):
      53             :     m_pGame(pGame),
      54           0 :     m_Terrain(new CTerrain()),
      55           0 :     m_UnitManager(new CUnitManager()),
      56           0 :     m_MapReader(new CMapReader)
      57             : {
      58           0 : }
      59             : 
      60             : /**
      61             :  * Initializes the game world with the attributes provided.
      62             :  **/
      63           0 : void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
      64             : {
      65             :     // Load the map, if one was specified
      66           0 :     if (mapFile.length())
      67             :     {
      68           0 :         VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp");
      69             : 
      70             :         try
      71             :         {
      72           0 :             CTriggerManager* pTriggerManager = NULL;
      73           0 :             m_MapReader->LoadMap(mapfilename, cx, settings, m_Terrain,
      74           0 :                 CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetWaterManager() : NULL,
      75           0 :                 CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetSkyManager() : NULL,
      76           0 :                 &g_LightEnv, m_pGame->GetView(),
      77           0 :                 m_pGame->GetView() ? m_pGame->GetView()->GetCinema() : NULL,
      78           0 :                 pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : NULL,
      79           0 :                 m_pGame->GetSimulation2(), &m_pGame->GetSimulation2()->GetSimContext(), playerID, false);
      80             :                 // fails immediately, or registers for delay loading
      81           0 :             RegMemFun(this, &CWorld::DeleteMapReader, L"CWorld::DeleteMapReader", 5);
      82             :         }
      83           0 :         catch (PSERROR_File& err)
      84             :         {
      85           0 :             SAFE_DELETE(m_MapReader);
      86           0 :             LOGERROR("Failed to load map %s: %s", mapfilename.string8(), err.what());
      87           0 :             throw PSERROR_Game_World_MapLoadFailed("Failed to load map.\nCheck application log for details.");
      88             :         }
      89             :     }
      90           0 : }
      91             : 
      92           0 : void CWorld::RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
      93             : {
      94             :     // If scriptFile is empty, a blank map will be generated using settings (no RMS run)
      95           0 :     CTriggerManager* pTriggerManager = NULL;
      96           0 :     m_MapReader->LoadRandomMap(scriptFile, cx, settings, m_Terrain,
      97           0 :         CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetWaterManager() : NULL,
      98           0 :         CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetSkyManager() : NULL,
      99           0 :         &g_LightEnv, m_pGame->GetView(),
     100           0 :         m_pGame->GetView() ? m_pGame->GetView()->GetCinema() : NULL,
     101           0 :         pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : NULL,
     102           0 :         m_pGame->GetSimulation2(), playerID);
     103             :         // registers for delay loading
     104           0 :     RegMemFun(this, &CWorld::DeleteMapReader, L"CWorld::DeleteMapReader", 5);
     105           0 : }
     106             : 
     107           0 : int CWorld::DeleteMapReader()
     108             : {
     109           0 :     SAFE_DELETE(m_MapReader);
     110           0 :     return 0;
     111             : }
     112             : 
     113             : /**
     114             :  * Destructor.
     115             :  *
     116             :  **/
     117           0 : CWorld::~CWorld()
     118             : {
     119           0 :     delete m_Terrain;
     120           0 :     delete m_UnitManager;
     121           0 :     delete m_MapReader;
     122           3 : }

Generated by: LCOV version 1.13