From 4720a00f98b19f792a4e377dde44acfebfaccfac Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Wed, 12 Jan 2005 14:31:47 +0000 Subject: [PATCH] Made ScEd output entities into an XML file. Added CStrW::utf8() (used by XMLWriter). This was SVN commit r1716. --- binaries/data/mods/official/maps/scenario.dtd | 19 +++ source/graphics/MapIO.h | 2 +- source/graphics/MapReader.cpp | 152 +++++++++++++++--- source/graphics/MapReader.h | 3 + source/graphics/MapWriter.cpp | 103 +++++++++++- source/graphics/MapWriter.h | 3 + source/graphics/ObjectEntry.cpp | 18 ++- source/graphics/ObjectManager.cpp | 2 +- source/main.cpp | 2 + source/ps/CStr.cpp | 42 ++++- source/ps/CStr.h | 12 +- source/ps/FileUnpacker.h | 2 +- source/ps/XMLWriter.cpp | 10 +- source/ps/XMLWriter.h | 2 + source/simulation/Entity.cpp | 5 + source/simulation/EntityManager.cpp | 1 - source/tests/Tests.cpp | 60 +++++++ source/tools/sced/EditorData.cpp | 38 +---- source/tools/sced/PaintObjectCommand.cpp | 2 +- source/tools/sced/PaintObjectTool.cpp | 1 + source/tools/sced/ui/MainFrm.cpp | 4 + 21 files changed, 407 insertions(+), 76 deletions(-) create mode 100644 binaries/data/mods/official/maps/scenario.dtd diff --git a/binaries/data/mods/official/maps/scenario.dtd b/binaries/data/mods/official/maps/scenario.dtd new file mode 100644 index 0000000000..8c826f9696 --- /dev/null +++ b/binaries/data/mods/official/maps/scenario.dtd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/source/graphics/MapIO.h b/source/graphics/MapIO.h index 57d6e2e6cc..bd6305623f 100755 --- a/source/graphics/MapIO.h +++ b/source/graphics/MapIO.h @@ -5,7 +5,7 @@ class CMapIO { public: // current file version given to saved maps - enum { FILE_VERSION = 2 }; + enum { FILE_VERSION = 3 }; // supported file read version - file with version less than this will be reject enum { FILE_READ_VERSION = 1 }; diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index d73a1363d0..f80c447b28 100755 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -32,8 +32,15 @@ void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain, CUnitManager // unpack the data UnpackMap(unpacker); - // finally, apply data to the world + // apply data to the world ApplyData(unpacker, pTerrain, pUnitMan, pLightEnv); + + if (unpacker.GetVersion()>=3) { + // read the corresponding XML file + CStr filename_xml (filename); + filename_xml = filename_xml.Left(filename_xml.Length()-4) + ".xml"; + ReadXML(filename_xml); + } } // UnpackMap: unpack the given data from the raw data stream into local variables @@ -148,29 +155,33 @@ void CMapReader::ApplyData(CFileUnpacker& unpacker, CTerrain *pTerrain, CUnitMan for (u32 i=0;im_Model) { - // Hijack the standard actor instantiation for actors that correspond to entities. - // Not an ideal solution; we'll have to figure out a map format that can define entities separately or somesuch. - CBaseEntity* templateObject = g_EntityTemplateCollection.getTemplateByActor( objentry ); - - if( templateObject ) - { - CVector3D orient = ((CMatrix3D*)m_Objects[i].m_Transform)->GetIn(); - CVector3D position = ((CMatrix3D*)m_Objects[i].m_Transform)->GetTranslation(); - - g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) ); - } - else - { - CUnit* unit=new CUnit(objentry,objentry->m_Model->Clone()); - - CMatrix3D transform; - memcpy(&transform._11,m_Objects[i].m_Transform,sizeof(float)*16); - unit->GetModel()->SetTransform(transform); + if (unpacker.GetVersion() < 3) { - // add this unit to list of units stored in unit manager - pUnitMan->AddUnit(unit); + // Hijack the standard actor instantiation for actors that correspond to entities. + // Not an ideal solution; we'll have to figure out a map format that can define entities separately or somesuch. + + CBaseEntity* templateObject = g_EntityTemplateCollection.getTemplateByActor(objentry); + + if (templateObject) + { + CVector3D orient = ((CMatrix3D*)m_Objects[i].m_Transform)->GetIn(); + CVector3D position = ((CMatrix3D*)m_Objects[i].m_Transform)->GetTranslation(); + + g_EntityManager.create(templateObject, position, atan2(-orient.X, -orient.Z)); + + continue; + } } + + CUnit* unit=new CUnit(objentry,objentry->m_Model->Clone()); + + CMatrix3D transform; + memcpy(&transform._11,m_Objects[i].m_Transform,sizeof(float)*16); + unit->GetModel()->SetTransform(transform); + + // add this unit to list of units stored in unit manager + pUnitMan->AddUnit(unit); } } @@ -179,3 +190,102 @@ void CMapReader::ApplyData(CFileUnpacker& unpacker, CTerrain *pTerrain, CUnitMan *pLightEnv=m_LightEnv; } } + + +void CMapReader::ReadXML(const char* filename) +{ +#ifdef SCED + // HACK: ScEd uses absolute filenames, not VFS paths. I can't be bothered + // to make Xeromyces work with non-VFS, so just cheat: + CStr filename_vfs (filename); + filename_vfs = filename_vfs.substr(filename_vfs.ReverseFind("\\mods\\official\\") + 15); + filename_vfs.Replace("\\", "/"); + filename = filename_vfs; +#endif + + CXeromyces XeroFile; + if (XeroFile.Load(filename) != PSRETURN_OK) + throw CFileUnpacker::CFileReadError(); + + // Define all the elements and attributes used in the XML file +#define EL(x) int el_##x = XeroFile.getElementID(#x) +#define AT(x) int at_##x = XeroFile.getAttributeID(#x) + EL(scenario); + EL(entities); + EL(entity); + EL(template); + EL(position); + EL(orientation); + AT(x); + AT(y); + AT(z); + AT(angle); +#undef AT +#undef EL + + XMBElement root = XeroFile.getRoot(); + assert(root.getNodeName() == el_scenario); + + // + + XMBElementList children = root.getChildNodes(); + for (int i = 0; i < children.Count; ++i) + { + XMBElement child = children.item(i); + if (child.getNodeName() == el_entities) + { + // + + XMBElementList children = child.getChildNodes(); + for (int i = 0; i < children.Count; ++i) + { + XMBElement child = children.item(i); + assert(child.getNodeName() == el_entity); + + // + + CStrW TemplateName; + CVector3D Position; + float Orientation; + + XMBElementList children = child.getChildNodes(); + for (int i = 0; i < children.Count; ++i) + { + XMBElement child = children.item(i); + int element_name = child.getNodeName(); + + if (element_name == el_template) + { + //