2021-01-11 12:26:31 +01:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2023-12-03 01:30:12 +01:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2023-12-03 01:30:12 +01:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 19:00:33 +02: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-03 01:30:12 +01:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 19:00:33 +02: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-03 01:30:12 +01:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2004-06-01 19:34:12 +02:00
|
|
|
#include "precompiled.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-06-22 00:37:31 +02:00
|
|
|
#include "Camera.h"
|
2015-12-30 22:16:35 +01:00
|
|
|
#include "CinemaManager.h"
|
2010-08-13 15:26:29 +02:00
|
|
|
#include "GameView.h"
|
2006-06-22 00:37:31 +02:00
|
|
|
#include "LightEnv.h"
|
2005-03-29 22:50:04 +02:00
|
|
|
#include "MapReader.h"
|
2006-06-22 00:37:31 +02:00
|
|
|
#include "MapWriter.h"
|
|
|
|
#include "Patch.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
#include "Terrain.h"
|
2010-09-04 23:26:52 +02:00
|
|
|
#include "TerrainTextureEntry.h"
|
|
|
|
#include "TerrainTextureManager.h"
|
2006-06-22 00:37:31 +02:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/MathUtil.h"
|
2006-08-22 04:24:44 +02:00
|
|
|
#include "maths/NUSpline.h"
|
2013-09-10 01:31:22 +02:00
|
|
|
#include "ps/CLogger.h"
|
2006-06-22 00:37:31 +02:00
|
|
|
#include "ps/Loader.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/Filesystem.h"
|
2005-08-15 01:50:37 +02:00
|
|
|
#include "ps/XML/XMLWriter.h"
|
2012-10-15 12:34:23 +02:00
|
|
|
#include "renderer/PostprocManager.h"
|
2006-06-22 00:37:31 +02:00
|
|
|
#include "renderer/SkyManager.h"
|
|
|
|
#include "renderer/WaterManager.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "simulation2/Simulation2.h"
|
2017-04-05 05:59:20 +02:00
|
|
|
#include "simulation2/components/ICmpCinemaManager.h"
|
2020-03-15 14:54:50 +01:00
|
|
|
#include "simulation2/components/ICmpGarrisonHolder.h"
|
2012-08-01 23:38:13 +02:00
|
|
|
#include "simulation2/components/ICmpObstruction.h"
|
2010-01-22 21:03:14 +01:00
|
|
|
#include "simulation2/components/ICmpOwnership.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "simulation2/components/ICmpPosition.h"
|
|
|
|
#include "simulation2/components/ICmpTemplateManager.h"
|
2020-11-11 20:40:44 +01:00
|
|
|
#include "simulation2/components/ICmpTurretHolder.h"
|
2013-02-03 03:16:52 +01:00
|
|
|
#include "simulation2/components/ICmpVisual.h"
|
2010-05-28 01:23:53 +02:00
|
|
|
#include "simulation2/components/ICmpWaterManager.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CMapWriter constructor: nothing to do at the minute
|
|
|
|
CMapWriter::CMapWriter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SaveMap: try to save the current map to the given file
|
2009-11-03 22:46:35 +01:00
|
|
|
void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain,
|
2010-08-01 22:56:34 +02:00
|
|
|
WaterManager* pWaterMan, SkyManager* pSkyMan,
|
2017-04-05 05:59:20 +02:00
|
|
|
CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* UNUSED(pCinema),
|
2012-10-15 12:34:23 +02:00
|
|
|
CPostprocManager* pPostproc,
|
2010-04-30 01:22:18 +02:00
|
|
|
CSimulation2* pSimulation2)
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
2010-05-20 20:09:23 +02:00
|
|
|
CFilePacker packer(FILE_VERSION, "PSMP");
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// build necessary data
|
2006-06-22 00:37:31 +02:00
|
|
|
PackMap(packer, pTerrain);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2013-09-10 01:31:22 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// write it out
|
|
|
|
packer.Write(pathname);
|
|
|
|
}
|
|
|
|
catch (PSERROR_File_WriteFailed&)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Failed to write map '%s'", pathname.string8());
|
2013-09-10 01:31:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2005-01-12 15:31:47 +01:00
|
|
|
|
2011-03-23 14:36:20 +01:00
|
|
|
VfsPath pathnameXML = pathname.ChangeExtension(L".xml");
|
2017-04-05 05:59:20 +02:00
|
|
|
WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pPostproc, pSimulation2);
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2007-01-01 22:25:47 +01:00
|
|
|
// GetHandleIndex: return the index of the given handle in the given list; or 0xFFFF if
|
2004-05-29 22:56:24 +02:00
|
|
|
// handle isn't in list
|
2010-09-04 23:26:52 +02:00
|
|
|
static u16 GetEntryIndex(const CTerrainTextureEntry* entry, const std::vector<CTerrainTextureEntry*>& entries)
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
2010-05-28 01:31:03 +02:00
|
|
|
const size_t limit = std::min(entries.size(), size_t(0xFFFEu)); // paranoia
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for (size_t i=0;i<limit;i++) {
|
2010-05-28 01:31:03 +02:00
|
|
|
if (entries[i]==entry) {
|
2005-08-09 17:55:44 +02:00
|
|
|
return (u16)i;
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-01 22:25:47 +01:00
|
|
|
return 0xFFFF;
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-01-14 01:04:32 +01:00
|
|
|
// EnumTerrainTextures: build lists of textures used by map, and tile descriptions for
|
2004-05-29 22:56:24 +02:00
|
|
|
// each tile on the terrain
|
2004-07-31 17:57:18 +02:00
|
|
|
void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain,
|
|
|
|
std::vector<CStr>& textures,
|
2004-05-29 22:56:24 +02:00
|
|
|
std::vector<STileDesc>& tiles)
|
|
|
|
{
|
|
|
|
// the list of all handles in use
|
2010-09-04 23:26:52 +02:00
|
|
|
std::vector<CTerrainTextureEntry*> entries;
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// resize tile array to required size
|
2004-07-31 17:57:18 +02:00
|
|
|
tiles.resize(SQR(pTerrain->GetVerticesPerSide()-1));
|
2004-05-29 22:56:24 +02:00
|
|
|
STileDesc* tileptr=&tiles[0];
|
|
|
|
|
|
|
|
// now iterate through all the tiles
|
2009-11-08 17:49:52 +01:00
|
|
|
const ssize_t patchesPerSide=pTerrain->GetPatchesPerSide();
|
|
|
|
for (ssize_t j=0;j<patchesPerSide;j++) {
|
|
|
|
for (ssize_t i=0;i<patchesPerSide;i++) {
|
2008-07-12 12:45:11 +02:00
|
|
|
for (ssize_t m=0;m<PATCH_SIZE;m++) {
|
|
|
|
for (ssize_t k=0;k<PATCH_SIZE;k++) {
|
2009-11-08 17:49:52 +01:00
|
|
|
CMiniPatch& mp=pTerrain->GetPatch(i,j)->m_MiniPatches[m][k]; // can't fail
|
2010-05-28 01:31:03 +02:00
|
|
|
u16 index=u16(GetEntryIndex(mp.GetTextureEntry(),entries));
|
2007-01-01 22:25:47 +01:00
|
|
|
if (index==0xFFFF) {
|
2010-05-28 01:31:03 +02:00
|
|
|
index=(u16)entries.size();
|
|
|
|
entries.push_back(mp.GetTextureEntry());
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tileptr->m_Tex1Index=index;
|
2007-01-01 22:25:47 +01:00
|
|
|
tileptr->m_Tex2Index=0xFFFF;
|
2010-05-28 01:31:03 +02:00
|
|
|
tileptr->m_Priority=mp.GetPriority();
|
2004-05-29 22:56:24 +02:00
|
|
|
tileptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now find the texture names for each handle
|
2010-05-28 01:31:03 +02:00
|
|
|
for (size_t i=0;i<entries.size();i++) {
|
2004-05-29 22:56:24 +02:00
|
|
|
CStr texturename;
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry* texentry=entries[i];
|
2004-05-29 22:56:24 +02:00
|
|
|
if (!texentry) {
|
|
|
|
// uh-oh, this shouldn't happen; set texturename to empty string
|
|
|
|
texturename="";
|
|
|
|
} else {
|
2005-06-20 17:14:36 +02:00
|
|
|
texturename=texentry->GetTag();
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
textures.push_back(texturename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PackMap: pack the current world into a raw data stream
|
2006-06-22 00:37:31 +02:00
|
|
|
void CMapWriter::PackMap(CFilePacker& packer, CTerrain* pTerrain)
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
|
|
|
// now pack everything up
|
2004-07-31 17:57:18 +02:00
|
|
|
PackTerrain(packer, pTerrain);
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PackTerrain: pack the terrain onto the end of the output data stream
|
|
|
|
// - data: map size, heightmap, list of textures used by map, texture tile assignments
|
2006-06-11 09:03:59 +02:00
|
|
|
void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain)
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
|
|
|
// pack map size
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
const ssize_t mapsize = pTerrain->GetPatchesPerSide();
|
|
|
|
packer.PackSize(mapsize);
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// pack heightmap
|
2016-01-14 01:04:32 +01:00
|
|
|
packer.PackRaw(pTerrain->GetHeightMap(),sizeof(u16)*SQR(pTerrain->GetVerticesPerSide()));
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// the list of textures used by map
|
|
|
|
std::vector<CStr> terrainTextures;
|
|
|
|
// descriptions of each tile
|
|
|
|
std::vector<STileDesc> tiles;
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// build lists by scanning through the terrain
|
2004-07-31 17:57:18 +02:00
|
|
|
EnumTerrainTextures(pTerrain, terrainTextures, tiles);
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// pack texture names
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
const size_t numTextures = terrainTextures.size();
|
|
|
|
packer.PackSize(numTextures);
|
|
|
|
for (size_t i=0;i<numTextures;i++)
|
2004-05-29 22:56:24 +02:00
|
|
|
packer.PackString(terrainTextures[i]);
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// pack tile data
|
2013-09-10 01:31:22 +02:00
|
|
|
packer.PackRaw(&tiles[0],sizeof(STileDesc)*tiles.size());
|
2004-05-29 22:56:24 +02:00
|
|
|
}
|
2010-08-04 23:15:41 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
void CMapWriter::WriteXML(const VfsPath& filename,
|
2010-08-01 22:56:34 +02:00
|
|
|
WaterManager* pWaterMan, SkyManager* pSkyMan,
|
2017-04-05 05:59:20 +02:00
|
|
|
CLightEnv* pLightEnv, CCamera* pCamera,
|
2012-10-15 12:34:23 +02:00
|
|
|
CPostprocManager* pPostproc,
|
2010-04-30 01:22:18 +02:00
|
|
|
CSimulation2* pSimulation2)
|
2005-01-12 15:31:47 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_File xmlMapFile;
|
2005-01-12 15:31:47 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element scenarioTag(xmlMapFile, "Scenario");
|
|
|
|
scenarioTag.Attribute("version", static_cast<int>(FILE_VERSION));
|
2005-05-11 05:07:08 +02:00
|
|
|
|
2014-07-01 21:00:41 +02:00
|
|
|
ENSURE(pSimulation2);
|
|
|
|
CSimulation2& sim = *pSimulation2;
|
|
|
|
|
|
|
|
if (!sim.GetStartupScript().empty())
|
2010-04-30 01:22:18 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element scriptTag(xmlMapFile, "Script");
|
|
|
|
scriptTag.Text(sim.GetStartupScript().c_str(), true);
|
2010-04-30 01:22:18 +02:00
|
|
|
}
|
|
|
|
|
2005-05-11 05:07:08 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element environmentTag(xmlMapFile, "Environment");
|
|
|
|
environmentTag.Setting("SkySet", pSkyMan->GetSkySet());
|
2005-05-11 05:07:08 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element sunColorTag(xmlMapFile, "SunColor");
|
|
|
|
sunColorTag.Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z...
|
|
|
|
sunColorTag.Attribute("g", pLightEnv->m_SunColor.Y);
|
|
|
|
sunColorTag.Attribute("b", pLightEnv->m_SunColor.Z);
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element SunElevationTag(xmlMapFile, "SunElevation");
|
|
|
|
SunElevationTag.Attribute("angle", pLightEnv->m_Elevation);
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element sunRotationTag(xmlMapFile, "SunRotation");
|
|
|
|
sunRotationTag.Attribute("angle", pLightEnv->m_Rotation);
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
|
|
|
{
|
2021-01-17 14:10:00 +01:00
|
|
|
XMLWriter_Element ambientColorTag(xmlMapFile, "AmbientColor");
|
|
|
|
ambientColorTag.Attribute("r", pLightEnv->m_AmbientColor.X);
|
|
|
|
ambientColorTag.Attribute("g", pLightEnv->m_AmbientColor.Y);
|
|
|
|
ambientColorTag.Attribute("b", pLightEnv->m_AmbientColor.Z);
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
2012-10-15 12:34:23 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element fogTag(xmlMapFile, "Fog");
|
|
|
|
fogTag.Setting("FogFactor", pLightEnv->m_FogFactor);
|
|
|
|
fogTag.Setting("FogThickness", pLightEnv->m_FogMax);
|
2012-10-15 12:34:23 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element fogColorTag(xmlMapFile, "FogColor");
|
|
|
|
fogColorTag.Attribute("r", pLightEnv->m_FogColor.X);
|
|
|
|
fogColorTag.Attribute("g", pLightEnv->m_FogColor.Y);
|
|
|
|
fogColorTag.Attribute("b", pLightEnv->m_FogColor.Z);
|
2012-10-15 12:34:23 +02:00
|
|
|
}
|
|
|
|
}
|
2006-06-11 09:03:59 +02:00
|
|
|
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element waterTag(xmlMapFile, "Water");
|
2006-06-11 09:03:59 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element waterBodyTag(xmlMapFile, "WaterBody");
|
2014-07-04 11:03:21 +02:00
|
|
|
CmpPtr<ICmpWaterManager> cmpWaterManager(sim, SYSTEM_ENTITY);
|
2014-07-03 22:07:15 +02:00
|
|
|
ENSURE(cmpWaterManager);
|
2019-01-12 17:23:47 +01:00
|
|
|
waterBodyTag.Setting("Type", pWaterMan->m_WaterType);
|
2006-06-11 09:03:59 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element colorTag(xmlMapFile, "Color");
|
|
|
|
colorTag.Attribute("r", pWaterMan->m_WaterColor.r);
|
|
|
|
colorTag.Attribute("g", pWaterMan->m_WaterColor.g);
|
|
|
|
colorTag.Attribute("b", pWaterMan->m_WaterColor.b);
|
2006-06-11 09:03:59 +02:00
|
|
|
}
|
2006-09-18 20:09:07 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element tintTag(xmlMapFile, "Tint");
|
|
|
|
tintTag.Attribute("r", pWaterMan->m_WaterTint.r);
|
|
|
|
tintTag.Attribute("g", pWaterMan->m_WaterTint.g);
|
|
|
|
tintTag.Attribute("b", pWaterMan->m_WaterTint.b);
|
2006-09-18 20:09:07 +02:00
|
|
|
}
|
2019-01-12 17:23:47 +01:00
|
|
|
waterBodyTag.Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0));
|
|
|
|
waterBodyTag.Setting("Waviness", pWaterMan->m_Waviness);
|
|
|
|
waterBodyTag.Setting("Murkiness", pWaterMan->m_Murkiness);
|
|
|
|
waterBodyTag.Setting("WindAngle", pWaterMan->m_WindAngle);
|
2006-06-11 09:03:59 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2012-10-15 12:34:23 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element postProcTag(xmlMapFile, "Postproc");
|
2012-10-15 12:34:23 +02:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
postProcTag.Setting("Brightness", pLightEnv->m_Brightness);
|
|
|
|
postProcTag.Setting("Contrast", pLightEnv->m_Contrast);
|
|
|
|
postProcTag.Setting("Saturation", pLightEnv->m_Saturation);
|
|
|
|
postProcTag.Setting("Bloom", pLightEnv->m_Bloom);
|
|
|
|
postProcTag.Setting("PostEffect", pPostproc->GetPostEffect());
|
2012-10-15 12:34:23 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
|
|
|
|
2006-03-21 21:55:45 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element cameraTag(xmlMapFile, "Camera");
|
2006-03-21 21:55:45 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element positionTag(xmlMapFile, "Position");
|
2019-12-14 13:56:47 +01:00
|
|
|
CVector3D pos = pCamera->GetOrientation().GetTranslation();
|
2019-01-12 17:23:47 +01:00
|
|
|
positionTag.Attribute("x", pos.X);
|
|
|
|
positionTag.Attribute("y", pos.Y);
|
|
|
|
positionTag.Attribute("z", pos.Z);
|
2006-03-21 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-14 13:56:47 +01:00
|
|
|
CVector3D in = pCamera->GetOrientation().GetIn();
|
2006-03-21 21:55:45 +01:00
|
|
|
// Convert to spherical coordinates
|
|
|
|
float rotation = atan2(in.X, in.Z);
|
2019-01-12 17:23:47 +01:00
|
|
|
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - static_cast<float>(M_PI / 2);
|
2006-03-21 21:55:45 +01:00
|
|
|
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element rotationTag(xmlMapFile, "Rotation");
|
|
|
|
rotationTag.Attribute("angle", rotation);
|
2006-03-21 21:55:45 +01:00
|
|
|
}
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element declinationTag(xmlMapFile, "Declination");
|
|
|
|
declinationTag.Attribute("angle", declination);
|
2006-03-21 21:55:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 23:15:41 +02:00
|
|
|
{
|
2014-07-01 21:00:41 +02:00
|
|
|
std::string settings = sim.GetMapSettingsString();
|
2010-08-04 23:15:41 +02:00
|
|
|
if (!settings.empty())
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element scriptSettingsTag(xmlMapFile, "ScriptSettings");
|
|
|
|
scriptSettingsTag.Text(("\n" + settings + "\n").c_str(), true);
|
2010-08-04 23:15:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element entitiesTag(xmlMapFile, "Entities");
|
2010-01-09 20:20:14 +01:00
|
|
|
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
2012-02-08 03:46:15 +01:00
|
|
|
ENSURE(cmpTemplateManager);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// This will probably need to be changed in the future, but for now we'll
|
|
|
|
// just save all entities that have a position
|
2011-03-03 01:16:14 +01:00
|
|
|
CSimulation2::InterfaceList ents = sim.GetEntitiesWithInterface(IID_Position);
|
2010-01-09 20:20:14 +01:00
|
|
|
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
|
|
|
{
|
|
|
|
entity_id_t ent = it->first;
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
// Don't save local entities (placement previews etc)
|
|
|
|
if (ENTITY_IS_LOCAL(ent))
|
|
|
|
continue;
|
|
|
|
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element entityTag(xmlMapFile, "Entity");
|
|
|
|
entityTag.Attribute("uid", ent);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2019-01-12 17:23:47 +01:00
|
|
|
entityTag.Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2012-02-08 03:46:15 +01:00
|
|
|
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent);
|
|
|
|
if (cmpOwnership)
|
2019-01-12 17:23:47 +01:00
|
|
|
entityTag.Setting("Player", static_cast<int>(cmpOwnership->GetOwner()));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2020-03-15 14:54:50 +01:00
|
|
|
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent);
|
|
|
|
if (cmpGarrisonHolder)
|
|
|
|
{
|
|
|
|
std::vector<entity_id_t> garrison = cmpGarrisonHolder->GetEntities();
|
2020-05-07 18:57:45 +02:00
|
|
|
if (!garrison.empty())
|
2020-03-15 14:54:50 +01:00
|
|
|
{
|
2020-05-07 18:57:45 +02:00
|
|
|
XMLWriter_Element garrisonTag(xmlMapFile, "Garrison");
|
|
|
|
for (const entity_id_t garr_ent_id : garrison)
|
|
|
|
{
|
|
|
|
XMLWriter_Element garrisonedEntityTag(xmlMapFile, "GarrisonedEntity");
|
|
|
|
garrisonedEntityTag.Attribute("uid", static_cast<int>(garr_ent_id));
|
2020-11-11 20:40:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CmpPtr<ICmpTurretHolder> cmpTurretHolder(sim, ent);
|
|
|
|
if (cmpTurretHolder)
|
|
|
|
{
|
2021-01-17 14:10:00 +01:00
|
|
|
std::vector<std::pair<std::string, entity_id_t> > turrets = cmpTurretHolder->GetTurrets();
|
2020-11-11 20:40:44 +01:00
|
|
|
if (!turrets.empty())
|
|
|
|
{
|
|
|
|
XMLWriter_Element turretTag(xmlMapFile, "Turrets");
|
|
|
|
for (const std::pair<std::string, entity_id_t>& turret : turrets)
|
|
|
|
{
|
|
|
|
XMLWriter_Element turretedEntityTag(xmlMapFile, "Turret");
|
|
|
|
turretedEntityTag.Attribute("turret", turret.first);
|
|
|
|
turretedEntityTag.Attribute("uid", static_cast<int>(turret.second));
|
2020-05-07 18:57:45 +02:00
|
|
|
}
|
2020-03-15 14:54:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
|
2012-02-08 03:46:15 +01:00
|
|
|
if (cmpPosition)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2015-06-15 00:17:39 +02:00
|
|
|
CFixedVector3D pos;
|
|
|
|
if (cmpPosition->IsInWorld())
|
|
|
|
pos = cmpPosition->GetPosition();
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
CFixedVector3D rot = cmpPosition->GetRotation();
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element positionTag(xmlMapFile, "Position");
|
|
|
|
positionTag.Attribute("x", pos.X);
|
|
|
|
positionTag.Attribute("z", pos.Z);
|
2010-01-09 20:20:14 +01:00
|
|
|
// TODO: height offset etc
|
|
|
|
}
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element orientationTag(xmlMapFile, "Orientation");
|
|
|
|
orientationTag.Attribute("y", rot.Y);
|
2010-01-09 20:20:14 +01:00
|
|
|
// TODO: X, Z maybe
|
|
|
|
}
|
|
|
|
}
|
2012-08-01 23:38:13 +02:00
|
|
|
|
|
|
|
CmpPtr<ICmpObstruction> cmpObstruction(sim, ent);
|
|
|
|
if (cmpObstruction)
|
|
|
|
{
|
|
|
|
// TODO: Currently only necessary because Atlas
|
|
|
|
// does not set up control groups for its walls.
|
|
|
|
cmpObstruction->ResolveFoundationCollisions();
|
|
|
|
|
|
|
|
entity_id_t group = cmpObstruction->GetControlGroup();
|
|
|
|
entity_id_t group2 = cmpObstruction->GetControlGroup2();
|
|
|
|
|
|
|
|
// Don't waste space writing the default control groups.
|
2013-02-03 03:16:52 +01:00
|
|
|
if (group != ent || group2 != INVALID_ENTITY)
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element obstructionTag(xmlMapFile, "Obstruction");
|
2013-02-03 03:16:52 +01:00
|
|
|
if (group != ent)
|
2019-01-12 17:23:47 +01:00
|
|
|
obstructionTag.Attribute("group", group);
|
2013-02-03 03:16:52 +01:00
|
|
|
if (group2 != INVALID_ENTITY)
|
2019-01-12 17:23:47 +01:00
|
|
|
obstructionTag.Attribute("group2", group2);
|
2013-02-03 03:16:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CmpPtr<ICmpVisual> cmpVisual(sim, ent);
|
|
|
|
if (cmpVisual)
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
entity_id_t seed = static_cast<entity_id_t>(cmpVisual->GetActorSeed());
|
|
|
|
if (seed != ent)
|
2013-02-03 03:16:52 +01:00
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element actorTag(xmlMapFile, "Actor");
|
|
|
|
actorTag.Attribute("seed",seed);
|
2013-02-03 03:16:52 +01:00
|
|
|
}
|
|
|
|
// TODO: variation/selection strings
|
2012-08-01 23:38:13 +02:00
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 01:04:32 +01:00
|
|
|
|
2017-04-05 05:59:20 +02:00
|
|
|
CmpPtr<ICmpCinemaManager> cmpCinemaManager(sim, SYSTEM_ENTITY);
|
|
|
|
if (cmpCinemaManager)
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
2017-04-05 05:59:20 +02:00
|
|
|
const std::map<CStrW, CCinemaPath>& paths = cmpCinemaManager->GetPaths();
|
|
|
|
std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin();
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element pathsTag(xmlMapFile, "Paths");
|
2006-08-22 04:24:44 +02:00
|
|
|
|
2011-12-29 02:17:03 +01:00
|
|
|
for ( ; it != paths.end(); ++it )
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
2016-01-03 13:41:04 +01:00
|
|
|
fixed timescale = it->second.GetTimescale();
|
2017-03-20 16:26:34 +01:00
|
|
|
const std::vector<SplineData>& position_nodes = it->second.GetAllNodes();
|
2016-04-17 17:43:29 +02:00
|
|
|
const std::vector<SplineData>& target_nodes = it->second.GetTargetSpline().GetAllNodes();
|
2007-02-27 03:14:18 +01:00
|
|
|
const CCinemaData* data = it->second.GetData();
|
2016-11-23 15:09:58 +01:00
|
|
|
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element pathTag(xmlMapFile, "Path");
|
|
|
|
pathTag.Attribute("name", data->m_Name);
|
|
|
|
pathTag.Attribute("timescale", timescale);
|
|
|
|
pathTag.Attribute("orientation", data->m_Orientation);
|
|
|
|
pathTag.Attribute("mode", data->m_Mode);
|
|
|
|
pathTag.Attribute("style", data->m_Style);
|
2006-12-03 18:13:22 +01:00
|
|
|
|
2017-03-20 16:26:34 +01:00
|
|
|
struct SEvent
|
2007-02-27 03:14:18 +01:00
|
|
|
{
|
2017-03-20 16:26:34 +01:00
|
|
|
fixed time;
|
|
|
|
const char* type;
|
|
|
|
CFixedVector3D value;
|
|
|
|
SEvent(fixed time, const char* type, CFixedVector3D value)
|
|
|
|
: time(time), type(type), value(value)
|
|
|
|
{}
|
2017-03-24 23:49:06 +01:00
|
|
|
bool operator<(const SEvent& another) const
|
2007-02-27 03:14:18 +01:00
|
|
|
{
|
2017-03-20 16:26:34 +01:00
|
|
|
return time < another.time;
|
2007-02-27 03:14:18 +01:00
|
|
|
}
|
2017-03-20 16:26:34 +01:00
|
|
|
};
|
2016-02-15 18:18:59 +01:00
|
|
|
|
2017-03-20 16:26:34 +01:00
|
|
|
// All events of a manipulating of camera (position/rotation/target)
|
|
|
|
std::vector<SEvent> events;
|
2017-03-24 23:49:06 +01:00
|
|
|
events.reserve(position_nodes.size() + target_nodes.size());
|
2016-02-15 18:18:59 +01:00
|
|
|
|
2017-03-20 16:26:34 +01:00
|
|
|
fixed last_position = fixed::Zero();
|
|
|
|
for (size_t i = 0; i < position_nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
fixed distance = i > 0 ? position_nodes[i - 1].Distance : fixed::Zero();
|
|
|
|
last_position += distance;
|
|
|
|
events.emplace_back(last_position, "Position", position_nodes[i].Position);
|
|
|
|
}
|
2016-02-15 18:18:59 +01:00
|
|
|
|
2017-03-20 16:26:34 +01:00
|
|
|
fixed last_target = fixed::Zero();
|
|
|
|
for (size_t i = 0; i < target_nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
fixed distance = i > 0 ? target_nodes[i - 1].Distance : fixed::Zero();
|
|
|
|
last_target += distance;
|
|
|
|
events.emplace_back(last_target, "Target", target_nodes[i].Position);
|
|
|
|
}
|
2016-02-15 18:18:59 +01:00
|
|
|
|
2017-03-20 16:26:34 +01:00
|
|
|
std::sort(events.begin(), events.end());
|
|
|
|
for (size_t i = 0; i < events.size();)
|
|
|
|
{
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element nodeTag(xmlMapFile, "Node");
|
2017-03-20 16:26:34 +01:00
|
|
|
fixed deltatime = i > 0 ? (events[i].time - events[i - 1].time) : fixed::Zero();
|
2019-01-12 17:23:47 +01:00
|
|
|
nodeTag.Attribute("deltatime", deltatime);
|
2017-03-20 16:26:34 +01:00
|
|
|
size_t j = i;
|
|
|
|
for (; j < events.size() && events[j].time == events[i].time; ++j)
|
2016-02-15 18:18:59 +01:00
|
|
|
{
|
2017-03-20 16:26:34 +01:00
|
|
|
// Types: Position/Rotation/Target
|
2019-01-12 17:23:47 +01:00
|
|
|
XMLWriter_Element eventTypeTag(xmlMapFile, events[j].type);
|
|
|
|
eventTypeTag.Attribute("x", events[j].value.X);
|
|
|
|
eventTypeTag.Attribute("y", events[j].value.Y);
|
|
|
|
eventTypeTag.Attribute("z", events[j].value.Z);
|
2016-02-15 18:18:59 +01:00
|
|
|
}
|
2017-03-20 16:26:34 +01:00
|
|
|
i = j;
|
2006-12-03 18:13:22 +01:00
|
|
|
}
|
2006-08-22 04:24:44 +02:00
|
|
|
}
|
2006-12-03 18:13:22 +01:00
|
|
|
}
|
2005-01-12 15:31:47 +01:00
|
|
|
}
|
2019-01-12 17:23:47 +01:00
|
|
|
if (!xmlMapFile.StoreVFS(g_VFS, filename))
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Failed to write map '%s'", filename.string8());
|
2005-01-17 05:52:02 +01:00
|
|
|
}
|