2025-07-23 10:19:42 -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
|
|
|
*/
|
|
|
|
|
|
2004-07-27 14:00:53 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2025-07-23 10:19:42 -07:00
|
|
|
#include "World.h"
|
|
|
|
|
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "graphics/GameView.h"
|
2025-07-23 10:19:42 -07:00
|
|
|
#include "graphics/HeightMipmap.h"
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "graphics/LightEnv.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "graphics/MapReader.h"
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "graphics/Terrain.h"
|
|
|
|
|
#include "graphics/UnitManager.h"
|
2025-07-23 10:19:42 -07:00
|
|
|
#include "lib/path.h"
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
|
#include "ps/CStr.h"
|
2025-07-23 10:19:42 -07:00
|
|
|
#include "ps/FileIo.h"
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "ps/Game.h"
|
|
|
|
|
#include "ps/Loader.h"
|
|
|
|
|
#include "renderer/Renderer.h"
|
2022-01-04 05:29:01 -08:00
|
|
|
#include "renderer/SceneRenderer.h"
|
2010-05-01 09:20:58 -07:00
|
|
|
#include "simulation2/Simulation2.h"
|
2004-07-27 14:00:53 -07:00
|
|
|
|
2025-07-23 10:19:42 -07:00
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
class CTriggerManager;
|
|
|
|
|
|
2007-01-31 17:34:17 -08:00
|
|
|
/**
|
|
|
|
|
* Global light settings.
|
|
|
|
|
* It is not a member of CWorld because it is passed
|
|
|
|
|
* to the renderer before CWorld exists.
|
|
|
|
|
**/
|
2004-10-23 07:39:28 -07:00
|
|
|
CLightEnv g_LightEnv;
|
2004-07-27 14:00:53 -07:00
|
|
|
|
2005-09-29 17:59:42 -07:00
|
|
|
|
2007-01-31 17:34:17 -08:00
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*
|
2023-10-02 12:47:31 -07:00
|
|
|
* @param game CGame& game reference to the container game object.
|
2007-01-31 17:34:17 -08:00
|
|
|
**/
|
2023-10-02 12:47:31 -07:00
|
|
|
CWorld::CWorld(CGame& game):
|
|
|
|
|
m_Game{game},
|
|
|
|
|
m_Terrain{std::make_unique<CTerrain>()},
|
|
|
|
|
m_UnitManager{std::make_unique<CUnitManager>()},
|
|
|
|
|
m_MapReader{std::make_unique<CMapReader>()}
|
2007-01-07 17:56:46 -08:00
|
|
|
{
|
|
|
|
|
}
|
2005-09-29 17:59:42 -07:00
|
|
|
|
2023-10-02 12:47:31 -07:00
|
|
|
CWorld::~CWorld() = default;
|
|
|
|
|
|
2007-01-31 17:34:17 -08:00
|
|
|
/**
|
2010-07-03 06:15:57 -07:00
|
|
|
* Initializes the game world with the attributes provided.
|
2007-01-31 17:34:17 -08:00
|
|
|
**/
|
2020-11-18 06:39:04 -08:00
|
|
|
void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
|
2004-07-27 14:00:53 -07:00
|
|
|
{
|
2005-02-11 04:57:19 -08:00
|
|
|
// Load the map, if one was specified
|
2010-06-30 14:41:04 -07:00
|
|
|
if (mapFile.length())
|
2005-02-11 04:57:19 -08:00
|
|
|
{
|
Implements skirmish maps, based on patch by sanderd17, fixes #1198. Skirmish maps are like scenarios, except the player can choose their civ during match setup. To create a skirmish map: place some skirmish entities for each player in Atlas (see templates/skirmish/* for examples), uncheck the player's civ in Atlas' player panel if desired, and save in the maps/skirmishes directory. The map will appear in match setup under the "Skirmish" match type.
Implements custom, VFS-based map load/save dialogs for Atlas (replaces
broken native file dialogs), fixes #631, #889.
Fixes map loading/saving to handle arbitrary subdirectories for better
organization.
Adds default settings to Atlas player panel, fixes #1872. Each setting
now has a checkbox to choose whether it should be saved with the map
(avoids writing lots of useless default data for each map).
Adds map preview setting to Atlas, refs #1745.
Cleans up and simplifies some duplicate code.
Fixes optional serialization performance test.
This was SVN commit r13938.
2013-10-03 19:29:16 -07:00
|
|
|
VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp");
|
2005-03-30 08:14:19 -08:00
|
|
|
|
2010-06-30 14:41:04 -07:00
|
|
|
try
|
|
|
|
|
{
|
2023-10-02 12:47:31 -07:00
|
|
|
CTriggerManager* pTriggerManager = nullptr;
|
|
|
|
|
m_MapReader->LoadMap(mapfilename, cx, settings, m_Terrain.get(),
|
|
|
|
|
CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetWaterManager() :
|
|
|
|
|
nullptr,
|
|
|
|
|
CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetSkyManager() :
|
|
|
|
|
nullptr, &g_LightEnv, m_Game.GetView(),
|
|
|
|
|
m_Game.GetView() ? m_Game.GetView()->GetCinema() : nullptr, pTriggerManager,
|
|
|
|
|
CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : nullptr,
|
|
|
|
|
m_Game.GetSimulation2(), &m_Game.GetSimulation2()->GetSimContext(), playerID,
|
|
|
|
|
false);
|
2005-03-22 13:00:56 -08:00
|
|
|
// fails immediately, or registers for delay loading
|
2023-06-26 11:35:34 -07:00
|
|
|
LDR_Register([this](const double)
|
|
|
|
|
{
|
|
|
|
|
return DeleteMapReader();
|
|
|
|
|
}, L"CWorld::DeleteMapReader", 5);
|
2010-06-30 14:41:04 -07:00
|
|
|
}
|
|
|
|
|
catch (PSERROR_File& err)
|
|
|
|
|
{
|
2023-10-02 12:47:31 -07:00
|
|
|
m_MapReader.reset();
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGERROR("Failed to load map %s: %s", mapfilename.string8(), err.what());
|
Implements skirmish maps, based on patch by sanderd17, fixes #1198. Skirmish maps are like scenarios, except the player can choose their civ during match setup. To create a skirmish map: place some skirmish entities for each player in Atlas (see templates/skirmish/* for examples), uncheck the player's civ in Atlas' player panel if desired, and save in the maps/skirmishes directory. The map will appear in match setup under the "Skirmish" match type.
Implements custom, VFS-based map load/save dialogs for Atlas (replaces
broken native file dialogs), fixes #631, #889.
Fixes map loading/saving to handle arbitrary subdirectories for better
organization.
Adds default settings to Atlas player panel, fixes #1872. Each setting
now has a checkbox to choose whether it should be saved with the map
(avoids writing lots of useless default data for each map).
Adds map preview setting to Atlas, refs #1745.
Cleans up and simplifies some duplicate code.
Fixes optional serialization performance test.
This was SVN commit r13938.
2013-10-03 19:29:16 -07:00
|
|
|
throw PSERROR_Game_World_MapLoadFailed("Failed to load map.\nCheck application log for details.");
|
2005-02-11 04:57:19 -08:00
|
|
|
}
|
2004-07-27 14:00:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2004-08-05 06:07:51 -07:00
|
|
|
|
2020-11-18 06:39:04 -08:00
|
|
|
void CWorld::RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
|
2011-03-21 18:34:45 -07:00
|
|
|
{
|
|
|
|
|
// If scriptFile is empty, a blank map will be generated using settings (no RMS run)
|
2023-10-02 12:47:31 -07:00
|
|
|
CTriggerManager* pTriggerManager = nullptr;
|
|
|
|
|
m_MapReader->LoadRandomMap(scriptFile, cx, settings, m_Terrain.get(),
|
|
|
|
|
CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetWaterManager() : nullptr,
|
|
|
|
|
CRenderer::IsInitialised() ? &g_Renderer.GetSceneRenderer().GetSkyManager() : nullptr,
|
|
|
|
|
&g_LightEnv, m_Game.GetView(), m_Game.GetView() ? m_Game.GetView()->GetCinema() : nullptr,
|
|
|
|
|
pTriggerManager, CRenderer::IsInitialised() ? &g_Renderer.GetPostprocManager() : nullptr,
|
|
|
|
|
m_Game.GetSimulation2(), playerID);
|
2011-04-06 19:32:16 -07:00
|
|
|
// registers for delay loading
|
2023-06-26 11:35:34 -07:00
|
|
|
LDR_Register([this](const double)
|
|
|
|
|
{
|
|
|
|
|
return DeleteMapReader();
|
|
|
|
|
}, L"CWorld::DeleteMapReader", 5);
|
2011-03-21 18:34:45 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 17:37:48 -07:00
|
|
|
int CWorld::DeleteMapReader()
|
|
|
|
|
{
|
2023-10-02 12:47:31 -07:00
|
|
|
m_MapReader.reset();
|
2017-08-24 17:37:48 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|