2010-05-28 01:31:03 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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"
|
2006-08-22 04:24:44 +02:00
|
|
|
#include "CinemaTrack.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"
|
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"
|
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"
|
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"
|
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,
|
2010-04-30 01:22:18 +02:00
|
|
|
CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema,
|
|
|
|
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
|
|
|
|
|
|
|
// write it out
|
2009-11-03 22:46:35 +01:00
|
|
|
packer.Write(pathname);
|
2005-01-12 15:31:47 +01:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath pathnameXML = fs::change_extension(pathname, L".xml");
|
2010-08-01 22:56:34 +02:00
|
|
|
WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, 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
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// EnumTerrainTextures: build lists of textures used by map, and tile descriptions for
|
|
|
|
// 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;
|
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);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// pack heightmap
|
2004-07-31 17:57:18 +02: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;
|
|
|
|
|
|
|
|
// build lists by scanning through the terrain
|
2004-07-31 17:57:18 +02:00
|
|
|
EnumTerrainTextures(pTerrain, terrainTextures, tiles);
|
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]);
|
|
|
|
|
|
|
|
// pack tile data
|
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
|
|
|
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,
|
2010-04-30 01:22:18 +02:00
|
|
|
CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema,
|
|
|
|
CSimulation2* pSimulation2)
|
2005-01-12 15:31:47 +01:00
|
|
|
{
|
2006-12-03 18:13:22 +01:00
|
|
|
XML_Start();
|
2005-01-12 15:31:47 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Scenario");
|
2010-05-20 20:09:23 +02:00
|
|
|
XML_Attribute("version", (int)FILE_VERSION);
|
2005-05-11 05:07:08 +02:00
|
|
|
|
2010-04-30 01:22:18 +02:00
|
|
|
if (pSimulation2 && !pSimulation2->GetStartupScript().empty())
|
|
|
|
{
|
|
|
|
XML_Element("Script");
|
|
|
|
XML_CDATA(pSimulation2->GetStartupScript().c_str());
|
|
|
|
}
|
|
|
|
|
2005-05-11 05:07:08 +02:00
|
|
|
{
|
|
|
|
XML_Element("Environment");
|
|
|
|
|
2006-06-22 00:37:31 +02:00
|
|
|
XML_Setting("SkySet", pSkyMan->GetSkySet());
|
2005-05-11 05:07:08 +02:00
|
|
|
{
|
|
|
|
XML_Element("SunColour");
|
|
|
|
XML_Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z...
|
|
|
|
XML_Attribute("g", pLightEnv->m_SunColor.Y);
|
|
|
|
XML_Attribute("b", pLightEnv->m_SunColor.Z);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("SunElevation");
|
|
|
|
XML_Attribute("angle", pLightEnv->m_Elevation);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("SunRotation");
|
|
|
|
XML_Attribute("angle", pLightEnv->m_Rotation);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("TerrainAmbientColour");
|
|
|
|
XML_Attribute("r", pLightEnv->m_TerrainAmbientColor.X);
|
|
|
|
XML_Attribute("g", pLightEnv->m_TerrainAmbientColor.Y);
|
|
|
|
XML_Attribute("b", pLightEnv->m_TerrainAmbientColor.Z);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("UnitsAmbientColour");
|
|
|
|
XML_Attribute("r", pLightEnv->m_UnitsAmbientColor.X);
|
|
|
|
XML_Attribute("g", pLightEnv->m_UnitsAmbientColor.Y);
|
|
|
|
XML_Attribute("b", pLightEnv->m_UnitsAmbientColor.Z);
|
|
|
|
}
|
2006-06-11 09:03:59 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Water");
|
|
|
|
{
|
|
|
|
XML_Element("WaterBody");
|
|
|
|
XML_Setting("Type", "default");
|
|
|
|
{
|
|
|
|
XML_Element("Colour");
|
|
|
|
XML_Attribute("r", pWaterMan->m_WaterColor.r);
|
|
|
|
XML_Attribute("g", pWaterMan->m_WaterColor.g);
|
|
|
|
XML_Attribute("b", pWaterMan->m_WaterColor.b);
|
|
|
|
}
|
2010-05-28 01:23:53 +02:00
|
|
|
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
|
|
|
debug_assert(!cmpWaterMan.null());
|
|
|
|
XML_Setting("Height", cmpWaterMan->GetExactWaterLevel(0, 0));
|
2006-06-11 09:03:59 +02:00
|
|
|
XML_Setting("Shininess", pWaterMan->m_Shininess);
|
|
|
|
XML_Setting("Waviness", pWaterMan->m_Waviness);
|
2006-09-18 20:09:07 +02:00
|
|
|
XML_Setting("Murkiness", pWaterMan->m_Murkiness);
|
|
|
|
{
|
|
|
|
XML_Element("Tint");
|
|
|
|
XML_Attribute("r", pWaterMan->m_WaterTint.r);
|
|
|
|
XML_Attribute("g", pWaterMan->m_WaterTint.g);
|
|
|
|
XML_Attribute("b", pWaterMan->m_WaterTint.b);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("ReflectionTint");
|
|
|
|
XML_Attribute("r", pWaterMan->m_ReflectionTint.r);
|
|
|
|
XML_Attribute("g", pWaterMan->m_ReflectionTint.g);
|
|
|
|
XML_Attribute("b", pWaterMan->m_ReflectionTint.b);
|
|
|
|
}
|
|
|
|
XML_Setting("ReflectionTintStrength", pWaterMan->m_ReflectionTintStrength);
|
2006-06-11 09:03:59 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-11 05:07:08 +02:00
|
|
|
}
|
|
|
|
|
2006-03-21 21:55:45 +01:00
|
|
|
{
|
|
|
|
XML_Element("Camera");
|
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Position");
|
|
|
|
CVector3D pos = pCamera->m_Orientation.GetTranslation();
|
|
|
|
XML_Attribute("x", pos.X);
|
|
|
|
XML_Attribute("y", pos.Y);
|
|
|
|
XML_Attribute("z", pos.Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
CVector3D in = pCamera->m_Orientation.GetIn();
|
|
|
|
// Convert to spherical coordinates
|
|
|
|
float rotation = atan2(in.X, in.Z);
|
2010-03-26 20:04:40 +01:00
|
|
|
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - (float)M_PI/2;
|
2006-03-21 21:55:45 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Rotation");
|
|
|
|
XML_Attribute("angle", rotation);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("Declination");
|
|
|
|
XML_Attribute("angle", declination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 23:15:41 +02:00
|
|
|
if (pSimulation2)
|
|
|
|
{
|
|
|
|
std::string settings = pSimulation2->GetMapSettings();
|
|
|
|
if (!settings.empty())
|
|
|
|
{
|
|
|
|
XML_Element("ScriptSettings");
|
|
|
|
XML_CDATA(("\n" + settings + "\n").c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
XML_Element("Entities");
|
|
|
|
|
2010-08-01 22:56:34 +02:00
|
|
|
CSimulation2& sim = *pSimulation2;
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
|
|
|
debug_assert(!cmpTemplateManager.null());
|
|
|
|
|
|
|
|
// This will probably need to be changed in the future, but for now we'll
|
|
|
|
// just save all entities that have a position
|
|
|
|
const CSimulation2::InterfaceList& ents = sim.GetEntitiesWithInterface(IID_Position);
|
|
|
|
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;
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
XML_Element("Entity");
|
|
|
|
XML_Attribute("uid", ent);
|
|
|
|
|
|
|
|
XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent));
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
|
|
|
|
if (!cmpOwner.null())
|
|
|
|
XML_Setting("Player", (int)cmpOwner->GetOwner());
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
|
|
|
|
if (!cmpPosition.null())
|
|
|
|
{
|
|
|
|
CFixedVector3D pos = cmpPosition->GetPosition();
|
|
|
|
CFixedVector3D rot = cmpPosition->GetRotation();
|
|
|
|
{
|
|
|
|
XML_Element("Position");
|
2010-08-04 23:15:41 +02:00
|
|
|
XML_Attribute("x", pos.X);
|
|
|
|
XML_Attribute("z", pos.Z);
|
2010-01-09 20:20:14 +01:00
|
|
|
// TODO: height offset etc
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XML_Element("Orientation");
|
2010-08-04 23:15:41 +02:00
|
|
|
XML_Attribute("y", rot.Y);
|
2010-01-09 20:20:14 +01:00
|
|
|
// TODO: X, Z maybe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
const std::map<CStrW, CCinemaPath>& paths = pCinema->GetAllPaths();
|
|
|
|
std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin();
|
2006-08-22 04:24:44 +02:00
|
|
|
|
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
XML_Element("Paths");
|
2006-08-22 04:24:44 +02:00
|
|
|
|
2007-02-27 03:14:18 +01:00
|
|
|
for ( ; it != paths.end(); it++ )
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
|
|
|
CStrW name = it->first;
|
|
|
|
float timescale = it->second.GetTimescale();
|
2007-02-27 03:14:18 +01:00
|
|
|
|
|
|
|
XML_Element("Path");
|
2006-12-03 18:13:22 +01:00
|
|
|
XML_Attribute("name", name);
|
|
|
|
XML_Attribute("timescale", timescale);
|
2007-02-27 03:14:18 +01:00
|
|
|
|
|
|
|
const std::vector<SplineData>& nodes = it->second.GetAllNodes();
|
|
|
|
const CCinemaData* data = it->second.GetData();
|
2006-12-03 18:13:22 +01:00
|
|
|
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
XML_Element("Distortion");
|
|
|
|
XML_Attribute("mode", data->m_Mode);
|
|
|
|
XML_Attribute("style", data->m_Style);
|
|
|
|
XML_Attribute("growth", data->m_Growth);
|
|
|
|
XML_Attribute("switch", data->m_Switch);
|
2006-12-03 18:13:22 +01:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:33:56 +02:00
|
|
|
for ( ssize_t j=nodes.size()-1; j >= 0; --j )
|
2007-02-27 03:14:18 +01:00
|
|
|
{
|
|
|
|
XML_Element("Node");
|
|
|
|
|
2006-08-22 04:24:44 +02:00
|
|
|
{
|
2007-02-27 03:14:18 +01:00
|
|
|
XML_Element("Position");
|
2006-12-03 18:13:22 +01:00
|
|
|
XML_Attribute("x", nodes[j].Position.X);
|
|
|
|
XML_Attribute("y", nodes[j].Position.Y);
|
|
|
|
XML_Attribute("z", nodes[j].Position.Z);
|
|
|
|
}
|
2007-02-27 03:14:18 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Rotation");
|
|
|
|
XML_Attribute("x", nodes[j].Rotation.X);
|
|
|
|
XML_Attribute("y", nodes[j].Rotation.Y);
|
|
|
|
XML_Attribute("z", nodes[j].Rotation.Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
XML_Setting("Time", nodes[j].Distance);
|
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
|
|
|
}
|
2010-07-04 12:15:53 +02:00
|
|
|
if (! XML_StoreVFS(g_VFS, filename))
|
2007-12-20 21:21:45 +01:00
|
|
|
debug_assert(0); // failed to write map XML file
|
2005-01-17 05:52:02 +01:00
|
|
|
}
|
2005-03-29 22:50:04 +02:00
|
|
|
|
2010-05-20 20:09:23 +02:00
|
|
|
/*
|
2006-11-24 20:45:04 +01:00
|
|
|
void CMapWriter::WriteTriggerGroup(XMLWriter_File& xml_file_, const MapTriggerGroup& group, const std::list<MapTriggerGroup>& groupList)
|
|
|
|
{
|
|
|
|
XML_Element("Group");
|
|
|
|
XML_Attribute("name", group.name);
|
|
|
|
|
|
|
|
for ( std::list<CStrW>::const_iterator it = group.childGroups.begin();
|
|
|
|
it != group.childGroups.end(); ++it )
|
|
|
|
{
|
|
|
|
//Not very efficient...
|
|
|
|
std::list<MapTriggerGroup>::const_iterator it2 = std::find(groupList.begin(), groupList.end(), *it);
|
|
|
|
if ( it2 != groupList.end() )
|
|
|
|
WriteTriggerGroup(xml_file_, *it2, groupList);
|
|
|
|
else
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_warn(L"Invalid trigger group ID while writing map");
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( std::list<MapTrigger>::const_iterator it = group.triggers.begin(); it != group.triggers.end(); ++it )
|
|
|
|
{
|
|
|
|
WriteTrigger(xml_file_, *it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapWriter::WriteTrigger(XMLWriter_File& xml_file_, const MapTrigger& trigger)
|
|
|
|
{
|
|
|
|
XML_Element("Trigger");
|
|
|
|
XML_Attribute("name", trigger.name);
|
|
|
|
|
|
|
|
{
|
|
|
|
if ( trigger.active )
|
|
|
|
XML_Setting("Active", "true");
|
|
|
|
else
|
|
|
|
XML_Setting("Active", "false");
|
|
|
|
XML_Setting("MaxRunCount", trigger.maxRunCount);
|
|
|
|
XML_Setting("Delay", trigger.timeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Conditions");
|
|
|
|
for ( std::list<MapTriggerCondition>::const_iterator it2 = trigger.conditions.begin();
|
|
|
|
it2 != trigger.conditions.end(); ++it2 )
|
|
|
|
{
|
|
|
|
size_t distance = std::distance( trigger.conditions.begin(), it2 );
|
|
|
|
std::set<MapTriggerLogicBlock>::const_iterator logicIter;
|
|
|
|
|
|
|
|
if ( ( logicIter = trigger.logicBlocks.find(MapTriggerLogicBlock(distance)) )
|
|
|
|
!= trigger.logicBlocks.end() )
|
|
|
|
{
|
|
|
|
XML_Element("LogicBlock");
|
2006-11-30 00:37:10 +01:00
|
|
|
if ( logicIter->negated )
|
2006-11-24 20:45:04 +01:00
|
|
|
XML_Attribute("not", "true");
|
|
|
|
else
|
|
|
|
XML_Attribute("not", "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Condition");
|
|
|
|
XML_Attribute("name", it2->name);
|
2007-01-17 00:22:25 +01:00
|
|
|
|
2006-11-24 20:45:04 +01:00
|
|
|
XML_Attribute("function", it2->functionName);
|
|
|
|
XML_Attribute("display", it2->displayName);
|
|
|
|
|
2006-11-30 00:37:10 +01:00
|
|
|
if ( it2->negated )
|
2006-11-24 20:45:04 +01:00
|
|
|
XML_Attribute("not", "true");
|
|
|
|
else
|
|
|
|
XML_Attribute("not", "false");
|
|
|
|
|
|
|
|
for ( std::list<CStrW>::const_iterator paramIter = it2->parameters.begin();
|
|
|
|
paramIter != it2->parameters.end(); ++paramIter )
|
|
|
|
{
|
2007-04-27 05:05:26 +02:00
|
|
|
CStrW paramString(*paramIter);
|
2009-11-03 22:46:35 +01:00
|
|
|
//paramString.Replace(L"<", L"<");
|
|
|
|
//paramString.Replace(L">", L">");
|
2007-04-27 05:05:26 +02:00
|
|
|
XML_Setting("Parameter", paramString);
|
|
|
|
}
|
|
|
|
if ( it2->linkLogic == 1 )
|
|
|
|
XML_Setting("LinkLogic", "AND");
|
|
|
|
else if ( it2->linkLogic == 2 )
|
|
|
|
XML_Setting("LinkLogic", "OR");
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2007-04-27 05:05:26 +02:00
|
|
|
if ( trigger.logicBlockEnds.find(distance) != trigger.logicBlockEnds.end() )
|
|
|
|
{
|
2007-01-17 00:22:25 +01:00
|
|
|
XML_Element("LogicBlockEnd");
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} //Read all conditions
|
|
|
|
} //Conditions' scope
|
|
|
|
|
|
|
|
{
|
|
|
|
XML_Element("Effects");
|
|
|
|
for ( std::list<MapTriggerEffect>::const_iterator it2 = trigger.effects.begin();
|
|
|
|
it2 != trigger.effects.end(); ++it2 )
|
|
|
|
{
|
|
|
|
XML_Element("Effect");
|
|
|
|
XML_Attribute("name", it2->name);
|
2007-01-17 00:22:25 +01:00
|
|
|
{
|
|
|
|
XML_Setting("function", it2->functionName);
|
|
|
|
XML_Setting("display", it2->displayName);
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2007-01-17 00:22:25 +01:00
|
|
|
for ( std::list<CStrW>::const_iterator paramIter = it2->parameters.begin();
|
2006-11-24 20:45:04 +01:00
|
|
|
paramIter != it2->parameters.end(); ++paramIter )
|
2007-01-17 00:22:25 +01:00
|
|
|
{
|
|
|
|
XML_Setting("Parameter", *paramIter);
|
|
|
|
}
|
2006-11-24 20:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} //Effects' scope
|
|
|
|
}
|
2010-05-20 20:09:23 +02:00
|
|
|
*/
|