Revision: 6481
http://delta3d.svn.sourceforge.net/delta3d/?rev=6481&view=rev
Author: jhoude
Date: 2009-11-24 07:23:04 +0000 (Tue, 24 Nov 2009)
Log Message:
-----------
Extracted base functionality of the xml parsing from the map loading system so they can be used elsewhere.
Created an ActorPropertySerializer class that handles xml reading/writing of actor properties.
Modified Paths:
--------------
branches/dtDirector/inc/dtDAL/exceptionenum.h
branches/dtDirector/inc/dtDAL/mapcontenthandler.h
branches/dtDirector/inc/dtDAL/mapxml.h
branches/dtDirector/src/dtDAL/exceptionenum.cpp
branches/dtDirector/src/dtDAL/mapcontenthandler.cpp
branches/dtDirector/src/dtDAL/mapxml.cpp
branches/dtDirector/src/dtDAL/project.cpp
Added Paths:
-----------
branches/dtDirector/inc/dtDAL/actorpropertyserializer.h
branches/dtDirector/inc/dtDAL/basexml.h
branches/dtDirector/inc/dtDAL/basexmlhandler.h
branches/dtDirector/src/dtDAL/actorpropertyserializer.cpp
branches/dtDirector/src/dtDAL/basexml.cpp
branches/dtDirector/src/dtDAL/basexmlhandler.cpp
Added: branches/dtDirector/inc/dtDAL/actorpropertyserializer.h
===================================================================
--- branches/dtDirector/inc/dtDAL/actorpropertyserializer.h (rev 0)
+++ branches/dtDirector/inc/dtDAL/actorpropertyserializer.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -0,0 +1,220 @@
+/* -*-c++-*-
+ * Delta3D Open Source Game and Simulation Engine
+ * Copyright (C) 2005, BMH Associates, Inc.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * David Guthrie
+ * Extracted actor property functionality from mapxml by Jeff P. Houde
+ */
+
+#ifndef DELTA_ACTOR_PROPERTY_SERIALIZER
+#define DELTA_ACTOR_PROPERTY_SERIALIZER
+
+#include <dtDAL/export.h>
+#include <dtDAL/basexml.h>
+#include <dtDAL/basexmlhandler.h>
+#include <dtDAL/namedparameter.h>
+
+namespace dtDAL
+{
+ class Map;
+ class ActorProxy;
+ class AbstractParameter;
+ class ActorProperty;
+ class DataType;
+ class MapContentHandler;
+ class ArrayActorPropertyBase;
+ class ContainerActorProperty;
+ class PropertyContainer;
+
+ /**
+ * @class ActorPropertySerializer
+ * @brief Writes a map out to an XML file
+ */
+ class DT_DAL_EXPORT ActorPropertySerializer
+ {
+ public:
+
+ /**
+ * Constructor.
+ */
+ ActorPropertySerializer(BaseXMLWriter* writer);
+ ActorPropertySerializer(BaseXMLHandler* parser);
+
+ /**
+ * Destructor.
+ */
+ virtual ~ActorPropertySerializer();
+
+ /**
+ * Sets the map.
+ */
+ void SetMap(Map* map);
+
+ /**
+ * Resets the serializer.
+ */
+ void Reset();
+ void ClearParameterValues();
+
+ /**
+ * Writes a property.
+ */
+ void WriteProperty(const ActorProperty& property);
+
+ /**
+ * Handler when an element is started.
+ *
+ * @param[in] localname The local name of the element.
+ *
+ * @return True if the element belongs to a property.
+ */
+ bool ElementStarted(const XMLCh* const localname);
+
+ /**
+ * Handler when an element is ended.
+ *
+ * @param[in] localname The local name of the element.
+ *
+ * @return True if the element belongs to a property.
+ */
+ bool ElementEnded(const XMLCh* const localname, PropertyContainer* propContainer);
+
+ /**
+ * Handler to parse the data of an element.
+ *
+ * @param[in] chars The characters of the element data.
+ *
+ * @return True if the characters belong to a property.
+ */
+ bool Characters(BaseXMLHandler::xmlCharString& topEl, const XMLCh* const chars, PropertyContainer* propContainer);
+
+ //processes the mGroupProperties multimap to set GroupActorProperties.
+ void AssignGroupProperties();
+
+ //processes the mActorLinking multimap to set ActorActorProperties.
+ void LinkActors();
+
+ /**
+ * Returns whether or not the map had a temporary property in it.
+ */
+ bool HasDeprecatedProperty() const { return mHasDeprecatedProperty; }
+
+ private:
+
+ /**
+ * Writes a Vector actor property.
+ */
+ template <typename VecType>
+ void WriteVec(const VecType& vec, char* numberConversionBuffer, const size_t bufferMax);
+
+ /**
+ * Writes a color actor property.
+ */
+ template <typename Type>
+ void WriteColorRGBA(const Type& holder, char* numberConversionBuffer, size_t bufferMax);
+
+ /**
+ * Writes an array actor property.
+ */
+ void WriteArray(const ArrayActorPropertyBase& arrayProp, char* numberConversionBuffer, size_t bufferMax);
+
+ /**
+ * Writes a container actor property.
+ */
+ void WriteContainer(const ContainerActorProperty& arrayProp, char* numberConversionBuffer, size_t bufferMax);
+
+ /**
+ * Writes a simple actor property.
+ */
+ void WriteSimple(const AbstractParameter& holder);
+
+ /**
+ * Writes a parameter for a group actor property.
+ */
+ void WriteParameter(const NamedParameter& param);
+
+ /**
+ * Ends an actor property group element.
+ */
+ void EndActorPropertyGroupElement(PropertyContainer* propContainer);
+
+ //Called from characters when the state says we are inside a parameter of a group actor property.
+ void ParameterCharacters(BaseXMLHandler::xmlCharString& topEl, const XMLCh* const chars, dtDAL::PropertyContainer* propContainer);
+
+ //Creates a named parameter based on the name and type last parsed and pushes it to the top of the stack.
+ void CreateAndPushParameter();
+
+ //parses the text data from the xml and stores it in the property.
+ void ParsePropertyData(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, dtDAL::DataType** dataType, dtDAL::ActorProperty* actorProperty, dtDAL::PropertyContainer* propContainer);
+
+ //parses the text data from the xml and stores it in the property.
+ void ParseParameterData(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, dtDAL::PropertyContainer* propContainer);
+
+ //parses one item out of the xml and stores it in the proper element of the osg Vec#.
+ template <typename VecType>
+ void ParseVec(BaseXMLHandler::xmlCharString& topEl, const std::string& dataValue, VecType& vec, size_t vecSize);
+
+ //parses the data for an array property.
+ void ParseArray(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, ArrayActorPropertyBase* arrayProp, PropertyContainer* propContainer);
+
+ //parses the data for a container property.
+ void ParseContainer(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, ContainerActorProperty* arrayProp, PropertyContainer* propContainer);
+
+ //decides on a property's datatype base on the name of the element.
+ DataType* ParsePropertyType(const XMLCh* const localname, bool errorIfNotFound = true);
+
+ // Workaround for properties where empty data would result in the property not being set.
+ void NonEmptyDefaultWorkaround();
+
+ void EndActorPropertyParameterElement();
+
+ void EndActorPropertyElement();
+
+ //returns true if a property in the actor is the same as the XML expects and adjusts the value.
+ bool IsPropertyCorrectType(dtDAL::DataType** dataType, dtDAL::ActorProperty* actorProperty);
+
+ dtCore::RefPtr<Map> mMap;
+
+ BaseXMLWriter* mWriter;
+ BaseXMLHandler* mParser;
+
+ dtCore::RefPtr<ActorProperty> mActorProperty;
+ DataType* mActorPropertyType;
+ DataType* mParameterTypeToCreate;
+
+ std::string mParameterNameToCreate;
+ std::string mDescriptorDisplayName;
+
+ bool mHasDeprecatedProperty;
+ bool mInActorProperty;
+ bool mInGroupProperty;
+ int mInArrayProperty; // Since arrays can be nested, we need to keep track of how deep we are.
+ int mInContainerProperty; // Since containers can be nested, we need to keep track of how deep we are.
+
+ //The data for group parameters is like linked actors, it needs to be set only after the map is done loading
+ //so things are not in a bad state.
+ std::multimap<dtDAL::PropertyContainer*, std::pair<std::string, dtCore::RefPtr<dtDAL::NamedGroupParameter> > > mGroupParameters;
+
+ //data for actor linking is not completely available until all actors have been created, so it
+ //is stored until the end.
+ std::multimap<dtDAL::PropertyContainer*, std::pair<std::string, dtCore::UniqueId> > mActorLinking;
+
+ std::stack<dtCore::RefPtr<NamedParameter> > mParameterStack;
+ };
+}
+
+#endif
Added: branches/dtDirector/inc/dtDAL/basexml.h
===================================================================
--- branches/dtDirector/inc/dtDAL/basexml.h (rev 0)
+++ branches/dtDirector/inc/dtDAL/basexml.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -0,0 +1,174 @@
+/* -*-c++-*-
+ * Delta3D Open Source Game and Simulation Engine
+ * Copyright (C) 2005, BMH Associates, Inc.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * David Guthrie
+ * Extracted base functionality from mapxml by Jeff P. Houde
+ */
+
+#ifndef DELTA_BASEXML
+#define DELTA_BASEXML
+
+#include <string>
+#include <stack>
+#include <map>
+#include <set>
+#include <vector>
+
+#include <osg/Referenced>
+
+#include <dtCore/refptr.h>
+#include <dtDAL/export.h>
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/framework/XMLFormatter.hpp>
+#include <xercesc/sax2/SAX2XMLReader.hpp>
+
+namespace dtUtil
+{
+ class Log;
+}
+
+namespace dtDAL
+{
+ class BaseXMLHandler;
+
+ /**
+ * @class BaseXMLParser
+ * @brief front end class for parsing an XML file.
+ */
+ class DT_DAL_EXPORT BaseXMLParser: public osg::Referenced
+ {
+ public:
+
+ /**
+ * Constructor.
+ */
+ BaseXMLParser();
+
+ /**
+ * Parses the given XML file.
+ *
+ * @param[in] path The path to the xml file to parse.
+ */
+ virtual bool Parse(const std::string& path);
+
+ ///@return true if the map is currently being parsed.
+ bool IsParsing() const { return mParsing; }
+
+ protected:
+
+ virtual ~BaseXMLParser();
+
+ public:
+
+ /**
+ * this is called automatically on startup.
+ */
+ static void StaticInit();
+
+ /**
+ * this is called automatically on shutdown.
+ */
+ static void StaticShutdown();
+
+ dtUtil::Log* mLogger;
+
+ private:
+ BaseXMLParser(const BaseXMLParser& copyParser);
+ BaseXMLParser& operator=(const BaseXMLParser& assignParser);
+
+ protected:
+ dtCore::RefPtr<BaseXMLHandler> mHandler;
+ xercesc::SAX2XMLReader* mXercesParser;
+ bool mParsing;
+ };
+
+
+ /**
+ * @class BaseXMLWriter
+ * @brief Writes a map out to an XML file
+ */
+ class DT_DAL_EXPORT BaseXMLWriter: public osg::Referenced
+ {
+ public:
+
+ /**
+ * Constructor.
+ */
+ BaseXMLWriter();
+
+ /**
+ * @Note Create your own Save functions in your inherited classes.
+ */
+
+ dtUtil::Log* mLogger;
+
+ protected:
+ virtual ~BaseXMLWriter(); ///Protected destructor so that this could be subclassed.
+
+ class FormatTarget: public xercesc::XMLFormatTarget
+ {
+ public:
+ FormatTarget();
+ virtual ~FormatTarget();
+
+ void SetOutputFile(FILE* newFile);
+ const FILE* GetOutputFile(FILE* newFile) const { return mOutFile; }
+
+ virtual void writeChars(
+ const XMLByte* const toWrite,
+ const unsigned int count,
+ xercesc::XMLFormatter* const formatter);
+
+ virtual void flush();
+
+ private:
+ FILE* mOutFile;
+ dtUtil::Log* mLogger;
+ };
+
+ typedef std::basic_string<XMLCh> xmlCharString;
+ static const int indentSize = 4;
+
+ bool mLastCharWasLF;
+ std::stack<xmlCharString> mElements;
+
+ FormatTarget mFormatTarget;
+ xercesc::XMLFormatter mFormatter;
+
+ public:
+
+ //writes out the open tags for a new element including indentation.
+ virtual void BeginElement(const XMLCh* const name, const XMLCh* const attributes = NULL);
+ //writes out the end element tag including indentation if necessary.
+ virtual void EndElement();
+
+ virtual void AddCharacters(const xmlCharString& string);
+ virtual void AddCharacters(const std::string& string);
+
+ void AddIndent();
+
+ //disable copy constructor
+ BaseXMLWriter(const BaseXMLWriter& toCopy): mFormatter("UTF-8", NULL, &mFormatTarget, xercesc::XMLFormatter::NoEscapes, xercesc::XMLFormatter::DefaultUnRep) {}
+ //disable operator =
+ BaseXMLWriter& operator=(const BaseXMLWriter& assignTo) { return *this;}
+ };
+
+}
+
+#endif
Added: branches/dtDirector/inc/dtDAL/basexmlhandler.h
===================================================================
--- branches/dtDirector/inc/dtDAL/basexmlhandler.h (rev 0)
+++ branches/dtDirector/inc/dtDAL/basexmlhandler.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -0,0 +1,192 @@
+/* -*-c++-*-
+ * Delta3D Open Source Game and Simulation Engine
+ * Copyright (C) 2006, Alion Science and Technology, BMH Operation.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * David Guthrie
+ * Extracted base functionality from mapcontenthandler by Jeff P. Houde
+ */
+
+#ifndef DELTA_BASE_XML_HANDLER
+#define DELTA_BASE_XML_HANDLER
+
+#include <vector>
+#include <string>
+#include <stack>
+#include <map>
+#include <set>
+
+#include <dtDAL/export.h>
+#include <dtCore/refptr.h>
+#include <osg/Referenced>
+
+#include <xercesc/sax2/ContentHandler.hpp>
+#include <xercesc/sax/ErrorHandler.hpp>
+#include <xercesc/sax/EntityResolver.hpp>
+
+namespace dtUtil
+{
+ class Log;
+}
+
+namespace dtDAL
+{
+ /**
+ * @class BaseXMLHandler
+ * @brief The SAX2 content handler for handling xml.
+ */
+ class DT_DAL_EXPORT BaseXMLHandler: public xercesc::ContentHandler, public xercesc::ErrorHandler,
+ public xercesc::EntityResolver, public osg::Referenced
+ {
+ public:
+
+ //A string using the xerces multibyte character. This allows
+ //for easier coding.
+ typedef std::basic_string<XMLCh> xmlCharString;
+
+ ///Constructor
+ BaseXMLHandler();
+
+ /**
+ * @see DocumentHandler#startDocument
+ */
+ virtual void startDocument();
+
+ /**
+ * @see DocumentHandler#endDocument
+ */
+ virtual void endDocument();
+
+ /**
+ * Any previously held onto map created during parsing will be deleted.
+ * @see DocumentHandler#resetDocument
+ */
+ virtual void resetDocument();
+
+ /**
+ * @see DocumentHandler#startElement
+ */
+ virtual void startElement( const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname,
+ const xercesc::Attributes& attrs );
+ virtual void ElementStarted( const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname,
+ const xercesc::Attributes& attrs);
+
+ /**
+ * @see DocumentHandler#endElement
+ */
+ virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
+ virtual void ElementEnded(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
+
+ /**
+ * @see DocumentHandler#characters
+ */
+ virtual void characters(const XMLCh* const chars, const unsigned int length);
+
+ /**
+ * @see DocumentHandler#ignorableWhitespace
+ */
+ virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
+
+ /**
+ * @see DocumentHandler#processingInstruction
+ */
+ virtual void processingInstruction(const XMLCh* const target, const XMLCh* const data);
+
+ /**
+ * @see Locator
+ */
+ virtual void setDocumentLocator(const xercesc::Locator* const locator);
+
+ /**
+ * @see DocumentHandler#startPrefixMapping
+ */
+ virtual void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
+
+ /**
+ * @see DocumentHandler#endPrefixMapping
+ */
+ virtual void endPrefixMapping(const XMLCh* const prefix);
+
+ /**
+ * @see DocumentHandler#skippedEntity
+ */
+ virtual void skippedEntity(const XMLCh* const name);
+
+ //@}
+
+ /** @name Default implementation of the EntityResolver interface. */
+
+ //@{
+ /**
+ * @see EntityResolver#resolveEntity
+ */
+ virtual xercesc::InputSource* resolveEntity(
+ const XMLCh* const publicId,
+ const XMLCh* const systemId);
+
+ //@}
+
+ /** @name Default implementation of the ErrorHandler interface */
+ //@{
+ /**
+ * @see xercesc::ErrorHandler#warning
+ * @see xercesc::SAXParseException#SAXParseException
+ */
+ virtual void error(const xercesc::SAXParseException& exc);
+
+ /**
+ * @see xercesc::ErrorHandler#fatalError
+ * @see xercesc::SAXParseException#SAXParseException
+ */
+ virtual void fatalError(const xercesc::SAXParseException& exc);
+
+ /**
+ * @see xercesc::ErrorHandler#warning
+ * @see xercesc::SAXParseException#SAXParseException
+ */
+ virtual void warning(const xercesc::SAXParseException& exc);
+
+ /**
+ * @see xercesc::ErrorHandler#resetErrors
+ */
+ virtual void resetErrors();
+
+ virtual void Reset();
+
+ dtUtil::Log* mLogger;
+
+ protected: // This class is referenced counted, but this causes an error...
+
+ virtual ~BaseXMLHandler();
+
+ // -----------------------------------------------------------------------
+ // Unimplemented constructors and operators
+ // -----------------------------------------------------------------------
+ BaseXMLHandler(const BaseXMLHandler&);
+ BaseXMLHandler& operator=(const BaseXMLHandler&);
+
+ std::stack<xmlCharString> mElements;
+
+ int mErrorCount;
+ int mFatalErrorCount;
+ int mWarningCount;
+ };
+}
+#endif
Modified: branches/dtDirector/inc/dtDAL/exceptionenum.h
===================================================================
--- branches/dtDirector/inc/dtDAL/exceptionenum.h 2009-11-23 17:40:54 UTC (rev 6480)
+++ branches/dtDirector/inc/dtDAL/exceptionenum.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -45,6 +45,10 @@
static ExceptionEnum MapSaveError;
static ExceptionEnum MapException;
+ static ExceptionEnum XMLLoadParsingError;
+ static ExceptionEnum XMLSaveError;
+ static ExceptionEnum XMLException;
+
static ExceptionEnum ObjectFactoryUnknownType;
static ExceptionEnum InvalidActorException;
Modified: branches/dtDirector/inc/dtDAL/mapcontenthandler.h
===================================================================
--- branches/dtDirector/inc/dtDAL/mapcontenthandler.h 2009-11-23 17:40:54 UTC (rev 6480)
+++ branches/dtDirector/inc/dtDAL/mapcontenthandler.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -22,27 +22,12 @@
#ifndef DELTA_MAP_CONTENT_HANDLER
#define DELTA_MAP_CONTENT_HANDLER
-#include <vector>
-#include <string>
-#include <stack>
-#include <map>
-#include <set>
-
+#include <dtDAL/basexmlhandler.h>
#include <dtDAL/map.h>
-#include <dtDAL/export.h>
+#include <dtDAL/actorpropertyserializer.h>
+
#include <dtCore/uniqueid.h>
-#include <dtCore/refptr.h>
-#include <osg/Referenced>
-#include <xercesc/sax2/ContentHandler.hpp>
-#include <xercesc/sax/ErrorHandler.hpp>
-#include <xercesc/sax/EntityResolver.hpp>
-
-namespace dtUtil
-{
- class Log;
-}
-
namespace dtDAL
{
class ActorProxy;
@@ -61,8 +46,7 @@
* @class MapContentHandler
* @brief The SAX2 content handler for loading maps.
*/
- class DT_DAL_EXPORT MapContentHandler: public xercesc::ContentHandler, public xercesc::ErrorHandler,
- public xercesc::EntityResolver, public osg::Referenced
+ class DT_DAL_EXPORT MapContentHandler: public BaseXMLHandler
{
public:
@@ -74,13 +58,11 @@
///Constructor
MapContentHandler();
- virtual const std::vector<std::string>& GetMissingLibraries() { return mMissingLibraries; }
- virtual const std::set<std::string>& GetMissingActorTypes() { return mMissingActorTypes; }
-
/**
- * @see DocumentHandler#characters
+ * Any map held onto by a previous parsing will be deleted here and new map created.
+ * @see DocumentHandler#startDocument
*/
- virtual void characters(const XMLCh* const chars, const unsigned int length);
+ virtual void startDocument();
/**
* @see DocumentHandler#endDocument
@@ -88,111 +70,39 @@
virtual void endDocument();
/**
- * @see DocumentHandler#endElement
- */
- virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
-
- /**
- * @see DocumentHandler#ignorableWhitespace
- */
- virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
-
- /**
- * @see DocumentHandler#processingInstruction
- */
- virtual void processingInstruction(const XMLCh* const target, const XMLCh* const data);
-
- /**
- * Any previously held onto map created during parsing will be deleted.
- * @see DocumentHandler#resetDocument
- */
- virtual void resetDocument();
-
- /**
- * @see Locator
- */
- virtual void setDocumentLocator(const xercesc::Locator* const locator);
-
- /**
- * Any map held onto by a previous parsing will be deleted here and new map created.
- * @see DocumentHandler#startDocument
- */
- virtual void startDocument();
-
- /**
* @see DocumentHandler#startElement
*/
- virtual void startElement( const XMLCh* const uri,
+ virtual void ElementStarted( const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname,
const xercesc::Attributes& attrs );
/**
- * @see DocumentHandler#startPrefixMapping
+ * @see DocumentHandler#endElement
*/
- virtual void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
+ virtual void ElementEnded(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
/**
- * @see DocumentHandler#endPrefixMapping
+ * @see DocumentHandler#characters
*/
- virtual void endPrefixMapping(const XMLCh* const prefix);
+ virtual void characters(const XMLCh* const chars, const unsigned int length);
/**
- * @see DocumentHandler#skippedEntity
+ * Retrieves a list of missing libraries.
*/
- virtual void skippedEntity(const XMLCh* const name);
+ virtual const std::vector<std::string>& GetMissingLibraries() { return mMissingLibraries; }
- //@}
-
- /** @name Default implementation of the EntityResolver interface. */
-
- //@{
/**
- * @see EntityResolver#resolveEntity
+ * Retrieves a list of missing actor types.
*/
- virtual xercesc::InputSource* resolveEntity(
- const XMLCh* const publicId,
- const XMLCh* const systemId);
+ virtual const std::set<std::string>& GetMissingActorTypes() { return mMissingActorTypes; }
- //@}
-
- /** @name Default implementation of the ErrorHandler interface */
- //@{
/**
- * @see xercesc::ErrorHandler#warning
- * @see xercesc::SAXParseException#SAXParseException
- */
- virtual void error(const xercesc::SAXParseException& exc);
-
- /**
- * @see xercesc::ErrorHandler#fatalError
- * @see xercesc::SAXParseException#SAXParseException
- */
- virtual void fatalError(const xercesc::SAXParseException& exc);
-
- /**
- * @see xercesc::ErrorHandler#warning
- * @see xercesc::SAXParseException#SAXParseException
- */
- virtual void warning(const xercesc::SAXParseException& exc);
-
- /**
- * @see xercesc::ErrorHandler#resetErrors
- */
- virtual void resetErrors();
-
-
- /**
* @return true if the map parsing has come across the map name yet.
*/
bool HasFoundMapName() const { return mFoundMapName; };
/**
- * Returns whether or not the map had a temporary property in it.
- */
- bool HasDeprecatedProperty() const { return mHasDeprecatedProperty; }
-
- /**
* Initializes the content handler to load a map.
*/
void SetMapMode() {mLoadingPrefab = false; mPrefabReadMode = PREFAB_READ_ALL;}
@@ -217,6 +127,11 @@
const Map* GetMap() const;
/**
+ * Returns whether or not the map had a temporary property in it.
+ */
+ bool HasDeprecatedProperty() const { return mPropSerializer->HasDeprecatedProperty(); }
+
+ /**
* This causes the parser to release its reference to the map.
*/
void ClearMap();
@@ -226,9 +141,6 @@
virtual ~MapContentHandler();
private:
- //A string using the xerces multibyte character. This allows
- //for easier coding.
- typedef std::basic_string<XMLCh> xmlCharString;
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
@@ -247,51 +159,21 @@
bool mInGroup;
bool mInPresetCameras;
bool mIgnoreCurrentActor;
- bool mInActorProperty;
- bool mPreparingProp;
- bool mInGroupProperty;
- bool mHasDeprecatedProperty;
- int mInArrayProperty; // Since arrays can be nested, we need to keep track of how deep we are.
- int mInContainerProperty; // Since containers can be nested, we need to keep track of how deep we are.
std::string mLibName;
std::string mLibVersion;
dtCore::UniqueId mEnvActorId;
- std::stack<xmlCharString> mElements;
-
std::vector<std::string> mMissingLibraries;
std::set<std::string> mMissingActorTypes;
- //data for actor linking is not completely available until all actors have been created, so it
- //is stored until the end.
- std::multimap<dtCore::UniqueId, std::pair<std::string, dtCore::UniqueId> > mActorLinking;
- //The data for group parameters is like linked actors, it needs to be set only after the map is done loading
- //so things are not in a bad state.
- std::multimap<dtCore::UniqueId, std::pair<std::string, dtCore::RefPtr<dtDAL::NamedGroupParameter> > > mGroupParameters;
+ ActorPropertySerializer* mPropSerializer;
- std::string mCurrentPropName;
- bool mCurrentPropIsVector;
-
- std::string mDescriptorDisplayName;
-
dtCore::RefPtr<GameEvent> mGameEvent;
dtCore::RefPtr<ActorProxy> mActorProxy;
- DataType* mActorPropertyType;
- dtCore::RefPtr<ActorProperty> mActorProperty;
- std::stack<dtCore::RefPtr<NamedParameter> > mParameterStack;
- std::string mParameterNameToCreate;
- DataType* mParameterTypeToCreate;
-
- dtUtil::Log* mLogger;
-
- int mErrorCount;
- int mFatalErrorCount;
- int mWarningCount;
-
int mGroupIndex;
bool mFoundMapName;
@@ -311,46 +193,16 @@
void ClearLibraryValues();
//reset/clear all of the actor data/state variables
void ClearActorValues();
- //reset/clear all of the parameter data/state variables
- void ClearParameterValues();
- //returns true if a property in the actor is the same as the XML expects and adjusts the value.
- bool IsPropertyCorrectType(dtDAL::DataType** dataType, dtDAL::ActorProperty* actorProperty);
//Called from characters when the state says we are inside an actor element.
void ActorCharacters(const XMLCh* const chars);
//Called from characters when the state says we are inside a preset camera element.
void PresetCameraCharacters(const XMLCh* const chars);
- //Called from characters when the state says we are inside a parameter of a group actor property.
- void ParameterCharacters(const XMLCh* const chars);
- //parses the text data from the xml and stores it in the property.
- void ParsePropertyData(std::string& dataValue, dtDAL::DataType** dataType, dtDAL::ActorProperty* actorProperty);
- //parses the text data from the xml and stores it in the property.
- void ParseParameterData(std::string& dataValue);
- //parses one item out of the xml and stores it in the proper element of the osg Vec#.
- template <typename VecType>
- void ParseVec(const std::string& dataValue, VecType& vec, size_t vecSize);
- //parses the data for an array property.
- void ParseArray(std::string& dataValue, ArrayActorPropertyBase* arrayProp);
- //parses the data for a container property.
- void ParseContainer(std::string& dataValue, ContainerActorProperty* arrayProp);
- //processes the mActorLinking multimap to set ActorActorProperties.
- void LinkActors();
- //processes the mGroupProperties multimap to set GroupActorProperties.
- void AssignGroupProperties();
- //decides on a property's datatype base on the name of the element.
- DataType* ParsePropertyType(const XMLCh* const localname, bool errorIfNotFound = true);
- //Creates a named parameter based on the name and type last parsed and pushes it to the top of the stack.
- void CreateAndPushParameter();
- // Workaround for properties where empty data would result in the property not being set.
- void NonEmptyDefaultWorkaround();
void EndHeaderElement(const XMLCh* const localname);
void EndActorSection(const XMLCh* const localname);
void EndActorsElement();
void EndActorElement();
void EndActorPropertySection(const XMLCh* const localname);
- void EndActorPropertyGroupElement();
- void EndActorPropertyParameterElement();
- void EndActorPropertyElement();
void EndGroupSection(const XMLCh* const localname);
void EndGroupElement();
void EndPresetCameraSection(const XMLCh* const localname);
Modified: branches/dtDirector/inc/dtDAL/mapxml.h
===================================================================
--- branches/dtDirector/inc/dtDAL/mapxml.h 2009-11-23 17:40:54 UTC (rev 6480)
+++ branches/dtDirector/inc/dtDAL/mapxml.h 2009-11-24 07:23:04 UTC (rev 6481)
@@ -22,47 +22,30 @@
#ifndef DELTA_MAPXML
#define DELTA_MAPXML
-#include <string>
-#include <stack>
-#include <map>
-#include <set>
-#include <vector>
-
-#include <osg/Referenced>
-
-#include <dtCore/refptr.h>
#include <dtDAL/export.h>
+#include <dtDAL/basexml.h>
-#include <xercesc/util/XercesDefs.hpp>
-#include <xercesc/framework/XMLFormatter.hpp>
-#include <xercesc/sax2/SAX2XMLReader.hpp>
-
-namespace dtUtil
-{
- class Log;
-}
-
namespace dtDAL
{
class Map;
- class ActorProxy;
- class AbstractParameter;
- class ActorProperty;
- class DataType;
- class NamedParameter;
class MapContentHandler;
- class ArrayActorPropertyBase;
- class ContainerActorProperty;
+ class ActorProxy;
+ class ActorPropertySerializer;
/**
* @class MapParser
* @brief front end class for converting an XML map into a map instance.
*/
- class DT_DAL_EXPORT MapParser: public osg::Referenced
+ class DT_DAL_EXPORT MapParser: public BaseXMLParser
{
public:
/**
+ * Constructor.
+ */
+ MapParser();
+
+ /**
* Completely parses a map file. Be sure store an dtCore::RefPtr to the map immediately, otherwise
* if the parser is deleted or another map file is parse, the map will get deleted.
* @param path The file path to the map.
@@ -70,7 +53,7 @@
* @return A pointer to the loaded map.
* @throws MapLoadParseError if a fatal error occurs in the parsing.
*/
- Map* Parse(const std::string& path);
+ bool Parse(const std::string& path, Map** map);
/**
* Parses a prefab resource and places it in the given map
@@ -96,9 +79,6 @@
*/
const std::string ParseMapName(const std::string& path);
- ///@return true if the map is currently being parsed.
- bool IsParsing() const { return mParsing; }
-
/**
* This method exists to allow actors being parsed to access their map. It's to help
* with certain features of the loading process. Using the meth
@@ -114,31 +94,15 @@
bool HasDeprecatedProperty() const;
- MapParser();
-
protected:
virtual ~MapParser();
- public:
+ private:
+ MapParser(const MapParser& copyParser);
+ MapParser& operator=(const MapParser& assignParser);
- /**
- * this is called automatically on startup.
- */
- static void StaticInit();
-
- /**
- * this is called automatically on shutdown.
- */
- static void StaticShutdown();
-
- private:
- MapParser(const MapParser& copyParser);
- MapParser& operator=(const MapParser& assignParser);
- dtCore::RefPtr<MapContentHandler> mHandler;
- xercesc::SAX2XMLReader* mXercesParser;
- dtUtil::Log* mLogger;
- bool mParsing;
+ dtCore::RefPtr<MapContentHandler> mMapHandler;
};
@@ -146,91 +110,44 @@
* @class MapWriter
* @brief Writes a map out to an XML file
*/
- class DT_DAL_EXPORT MapWriter: public osg::Referenced
+ class DT_DAL_EXPORT MapWriter: public BaseXMLWriter
{
- public:
- MapWriter();
- /**
- * Saves the map to an XML file.
- * The create time will be set on the map if this is the first time it has been saved.
- * @param map the map to save.
- * @param filePath the path to the file to save. The map has a file name property,
- * but it does not include any directories needed or the extension.
- * @throws ExceptionEnum::MapSaveError if any errors occur saving the file.
- */
- void Save(Map& map, const std::string& filePath);
+ public:
- /**
- * Saves a number of given actor proxies into a prefab resource.
- */
- void SavePrefab(std::vector<dtCore::RefPtr<ActorProxy> > proxyList,
- const std::string& filePath, const std::string& description,
- const std::string& iconFile = "");
-
- protected:
- virtual ~MapWriter(); ///Protected destructor so that this could be subclassed.
- private:
+ /**
+ * Constructor.
+ */
+ MapWriter();
- class MapFormatTarget: public xercesc::XMLFormatTarget
- {
- public:
- MapFormatTarget();
- virtual ~MapFormatTarget();
+ /**
+ * Saves the map to an XML file.
+ * The create time will be set on the map if this is the first time it has been saved.
+ * @param map the map to save.
+ * @param filePath the path to the file to save. The map has a file name property,
+ * but it does not include any directories needed or the extension.
+ * @throws ExceptionEnum::MapSaveError if any errors occur saving the file.
+ */
+ void Save(Map& map, const std::string& filePath);
- void SetOutputFile(FILE* newFile);
- const FILE* GetOutputFile(FILE* newFile) const { return mOutFile; }
-
- virtual void writeChars(
- const XMLByte* const toWrite,
- const unsigned int count,
- xercesc::XMLFormatter* const formatter);
-
- virtual void flush();
-
- private:
- FILE* mOutFile;
- dtUtil::Log* mLogger;
- };
+ /**
+ * Saves a number of given actor proxies into a prefab resource.
+ */
+ void SavePrefab(std::vector<dtCore::RefPtr<ActorProxy> > proxyList,
+ const std::string& filePath, const std::string& description,
+ const std::string& iconFile = "");
- typedef std::basic_string<XMLCh> xmlCharString;
- static const int indentSize = 4;
- dtUtil::Log* mLogger;
+ protected:
+ virtual ~MapWriter(); ///Protected destructor so that this could be subclassed.
- bool mLastCharWasLF;
- std::stack<xmlCharString> mElements;
-
- MapFormatTarget mFormatTarget;
- xercesc::XMLFormatter mFormatter;
-
- //writes out the open tags for a new element including indentation.
- void BeginElement(const XMLCh* const name, const XMLCh* const attributes = NULL);
- //writes out the end element tag including indentation if necessary.
- void EndElement();
-
- void AddCharacters(const xmlCharString& string);
- void AddCharacters(const std::string& string);
-
- void AddIndent();
-
- template <typename VecType>
- void WriteVec(const VecType& vec, char* numberConversionBuffer, const size_t bufferMax);
-
- template <typename Type>
- void WriteColorRGBA(const Type& holder, char* numberConversionBuffer, size_t bufferMax);
- void WriteArray(const ArrayActorPropertyBase& arrayProp, char* numberConversionBuffer, size_t bufferMax);
- void WriteContainer(const ContainerActorProperty& arrayProp, char* numberConversionBuffer, size_t bufferMax);
+ private:
- void WriteSimple(const AbstractParameter& holder);
+ //disable copy constructor
+ MapWriter(const MapWriter& toCopy): BaseXMLWriter(toCopy) {}
+ //disable operator =
+ MapWriter& operator=(const MapWriter& assignTo) { return *this;}
- void WriteProperty(const ActorProperty& property);
- void WriteParameter(const NamedParameter& param);
-
- //disable copy constructor
- MapWriter(const MapWriter& toCopy): mFormatter("UTF-8", NULL, &mFormatTarget, xercesc::XMLFormatter::NoEscapes, xercesc::XMLFormatter::DefaultUnRep) {}
- //disable operator =
- MapWriter& operator=(const MapWriter& assignTo) { return *this;}
+ ActorPropertySerializer* mPropSerializer;
};
-
}
#endif
Added: branches/dtDirector/src/dtDAL/actorpropertyserializer.cpp
===================================================================
--- branches/dtDirector/src/dtDAL/actorpropertyserializer.cpp (rev 0)
+++ branches/dtDirector/src/dtDAL/actorpropertyserializer.cpp 2009-11-24 07:23:04 UTC (rev 6481)
@@ -0,0 +1,1650 @@
+/*
+ * Delta3D Open Source Game and Simulation Engine
+ * Copyright (C) 2005, BMH Associates, Inc.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * David Guthrie
+ * Extracted actor property functionality from mapxml by Jeff P. Houde
+ */
+
+#include <prefix/dtdalprefix-src.h>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <cmath>
+
+#include <osgDB/FileNameUtils>
+
+#include <dtCore/transformable.h>
+#include <dtCore/transform.h>
+
+#include <dtDAL/actorpropertyserializer.h>
+#include <dtDAL/exceptionenum.h>
+#include <dtDAL/enginepropertytypes.h>
+#include <dtDAL/groupactorproperty.h>
+#include <dtDAL/arrayactorpropertybase.h>
+#include <dtDAL/containeractorproperty.h>
+#include <dtDAL/actorproperty.h>
+#include <dtDAL/actorproxy.h>
+#include <dtDAL/actortype.h>
+#include <dtDAL/datatype.h>
+#include <dtDAL/gameevent.h>
+#include <dtDAL/gameeventmanager.h>
+#include <dtDAL/mapxmlconstants.h>
+#include <dtDAL/mapcontenthandler.h>
+#include <dtDAL/transformableactorproxy.h>
+#include <dtDAL/propertycontainer.h>
+
+#include <dtUtil/xercesutils.h>
+
+#include <iostream>
+
+XERCES_CPP_NAMESPACE_USE
+
+namespace dtDAL
+{
+ static const std::string logName("actorpropertyserializer.cpp");
+
+ //////////////////////////////////////////////////////////////////////////
+ ActorPropertySerializer::ActorPropertySerializer(BaseXMLWriter* writer)
+ : mWriter(writer)
+ , mHasDeprecatedProperty(false)
+ , mActorProperty(NULL)
+ , mActorPropertyType(NULL)
+ , mInActorProperty(false)
+ , mInGroupProperty(false)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ ActorPropertySerializer::ActorPropertySerializer(BaseXMLHandler* parser)
+ : mParser(parser)
+ , mHasDeprecatedProperty(false)
+ , mActorProperty(NULL)
+ , mActorPropertyType(NULL)
+ , mInActorProperty(false)
+ , mInGroupProperty(false)
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ ActorPropertySerializer::~ActorPropertySerializer()
+ {
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::SetMap(Map* map)
+ {
+ mMap = map;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::Reset()
+ {
+ mGroupParameters.clear();
+
+ mInActorProperty = false;
+
+ ClearParameterValues();
+
+ //This should NOT be done in the Actor Value because this should
+ //be cleared at the start and finish of a document, not between each actor.
+ mActorLinking.clear();
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ClearParameterValues()
+ {
+ mActorProperty = NULL;
+ mActorPropertyType = NULL;
+
+ mInGroupProperty = false;
+ mInArrayProperty = 0;
+ mInContainerProperty = 0;
+ while (!mParameterStack.empty())
+ {
+ mParameterStack.pop();
+ }
+
+ mParameterNameToCreate.clear();
+ mParameterTypeToCreate = NULL;
+ mDescriptorDisplayName.clear();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::WriteProperty(const ActorProperty& property)
+ {
+ if (!mWriter) return;
+
+ const size_t bufferMax = 512;
+ char numberConversionBuffer[bufferMax];
+ const DataType& propertyType = property.GetDataType();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_ELEMENT);
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT);
+ mWriter->AddCharacters(property.GetName());
+ if (mWriter->mLogger->IsLevelEnabled(dtUtil::Log::LOG_DEBUG))
+ {
+ mWriter->mLogger->LogMessage(dtUtil::Log::LOG_DEBUG, __FUNCTION__, __LINE__,
+ "Found Property Named: %s", property.GetName().c_str());
+ }
+ mWriter->EndElement();
+
+ switch (propertyType.GetTypeId())
+ {
+ case DataType::FLOAT_ID:
+ case DataType::DOUBLE_ID:
+ case DataType::INT_ID:
+ case DataType::LONGINT_ID:
+ case DataType::STRING_ID:
+ case DataType::BOOLEAN_ID:
+ case DataType::ACTOR_ID:
+ case DataType::GAMEEVENT_ID:
+ case DataType::ENUMERATION_ID:
+ WriteSimple(property);
+ break;
+ case DataType::VEC2_ID:
+ WriteVec(static_cast<const Vec2ActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC2F_ID:
+ WriteVec(static_cast<const Vec2fActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC2D_ID:
+ WriteVec(static_cast<const Vec2dActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3_ID:
+ WriteVec(static_cast<const Vec3ActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3F_ID:
+ WriteVec(static_cast<const Vec3fActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3D_ID:
+ WriteVec(static_cast<const Vec3dActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4_ID:
+ WriteVec(static_cast<const Vec4ActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4F_ID:
+ WriteVec(static_cast<const Vec4fActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4D_ID:
+ WriteVec(static_cast<const Vec4dActorProperty&>(property).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::RGBACOLOR_ID:
+ WriteColorRGBA(static_cast<const ColorRgbaActorProperty&>(property), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::GROUP_ID:
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_GROUP_ELEMENT);
+ dtCore::RefPtr<NamedGroupParameter> gp = static_cast<const GroupActorProperty&>(property).GetValue();
+ if (gp.valid())
+ {
+ std::vector<const NamedParameter*> parameters;
+ gp->GetParameters(parameters);
+ for (size_t i = 0; i < parameters.size(); ++i)
+ {
+ WriteParameter(*parameters[i]);
+ }
+ }
+ mWriter->EndElement();
+ break;
+ }
+ case DataType::ARRAY_ID:
+ {
+ WriteArray(static_cast<const ArrayActorPropertyBase&>(property), numberConversionBuffer, bufferMax);
+ break;
+ }
+ case DataType::CONTAINER_ID:
+ {
+ WriteContainer(static_cast<const ContainerActorProperty&>(property), numberConversionBuffer, bufferMax);
+ break;
+ }
+ default:
+ {
+ if (propertyType.IsResource())
+ {
+ const ResourceActorProperty& p =
+ static_cast<const ResourceActorProperty&>(property);
+
+ ResourceDescriptor* rd = p.GetValue();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT);
+ mWriter->AddCharacters(property.GetDataType().GetName());
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_DISPLAY_ELEMENT);
+ if (rd != NULL)
+ mWriter->AddCharacters(rd->GetDisplayName());
+ mWriter->EndElement();
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_IDENTIFIER_ELEMENT);
+ if (rd != NULL)
+ mWriter->AddCharacters(rd->GetResourceIdentifier());
+ mWriter->EndElement();
+ }
+ else
+ {
+ mWriter->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Unhandled datatype in ActorPropertySerializer: %s.",
+ propertyType.GetName().c_str());
+ }
+ }
+ }
+
+ //end property element
+ mWriter->EndElement();
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ bool ActorPropertySerializer::ElementStarted(const XMLCh* const localname)
+ {
+ if (!mParser) return false;
+
+ if (mInActorProperty)
+ {
+ if (mActorProperty != NULL)
+ {
+ if (mActorPropertyType == NULL)
+ {
+ mActorPropertyType = ParsePropertyType(localname);
+ }
+
+ if (mInGroupProperty)
+ {
+ if (!mParameterNameToCreate.empty())
+ {
+ mParameterTypeToCreate = ParsePropertyType(localname);
+ //It will be null if it's a resource property. The value will be parsed later.
+ if (mParameterTypeToCreate != NULL)
+ CreateAndPushParameter();
+ }
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_GROUP_ELEMENT) == 0)
+ {
+ mInGroupProperty = true;
+ ClearParameterValues();
+ mParameterStack.push(new NamedGroupParameter(mActorProperty->GetName()));
+
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT) == 0)
+ {
+ mInArrayProperty++;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT) == 0)
+ {
+ mInContainerProperty++;
+ }
+ }
+
+ return true;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_ELEMENT) == 0)
+ {
+ mInActorProperty = true;
+ return true;
+ }
+
+ return false;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ bool ActorPropertySerializer::ElementEnded(const XMLCh* const localname, PropertyContainer* propContainer)
+ {
+ if (mInArrayProperty == 0 && mInContainerProperty == 0 && XMLString::compareString(localname, MapXMLConstants::ACTOR_PROPERTY_ELEMENT) == 0)
+ {
+ EndActorPropertyElement();
+ return true;
+ }
+ else if (XMLString::compareString(localname, MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT) == 0)
+ {
+ mInArrayProperty--;
+ if (mInArrayProperty < 0) mInArrayProperty = 0;
+ return true;
+ }
+ else if (XMLString::compareString(localname, MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT) == 0)
+ {
+ mInContainerProperty--;
+ if (mInContainerProperty < 0) mInContainerProperty = 0;
+ return true;
+ }
+ else if (mInGroupProperty)
+ {
+ if (XMLString::compareString(localname, MapXMLConstants::ACTOR_PROPERTY_PARAMETER_ELEMENT) == 0)
+ {
+ EndActorPropertyParameterElement();
+ return true;
+ }
+ else if (XMLString::compareString(localname, MapXMLConstants::ACTOR_PROPERTY_GROUP_ELEMENT) == 0)
+ {
+ EndActorPropertyGroupElement(propContainer);
+ return true;
+ }
+ else if (!mParameterStack.empty())
+ {
+ // parse the end element into a data type to see if it's an end param element.
+ dtDAL::DataType* d = ParsePropertyType(localname, false);
+ // The parameter has ended, so pop.
+ if (d != NULL)
+ {
+ mParameterStack.pop();
+ }
+ return true;
+ }
+ }
+ else if (mInActorProperty)
+ {
+ if (mActorProperty != NULL)
+ {
+ if (mActorPropertyType != NULL && mInArrayProperty == 0 && mInContainerProperty == 0)
+ {
+ // parse the end element into a data type to see if it's an end property element.
+ dtDAL::DataType* d = ParsePropertyType(localname, false);
+ // The property has ended, so in case the property type has not
+ // been unset, it is now.
+ if (d != NULL)
+ {
+ //This works here because the actor types referenced here all set
+ // their property type to NULL when the value is set.
+ NonEmptyDefaultWorkaround();
+ mActorPropertyType = NULL;
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ bool ActorPropertySerializer::Characters(BaseXMLHandler::xmlCharString& topEl, const XMLCh* const chars, PropertyContainer* propContainer)
+ {
+ if (mInActorProperty)
+ {
+ if (mInGroupProperty)
+ {
+ ParameterCharacters(topEl, chars, propContainer);
+ }
+ else
+ {
+ // Make sure we don't try and change the current property if we are loading properties from an array.
+ if (mInArrayProperty == 0 && mInContainerProperty == 0 && topEl == MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT)
+ {
+ std::string propName = dtUtil::XMLStringConverter(chars).ToString();
+ mActorProperty = propContainer->GetProperty(propName);
+
+ // If the property was not found, attempt to get a temporary one instead.
+ if (!mActorProperty.valid())
+ {
+ mActorProperty = propContainer->GetDeprecatedProperty(propName);
+ if (mActorProperty.valid())
+ {
+ mHasDeprecatedProperty = true;
+ }
+ }
+ }
+ else if (mActorProperty != NULL)
+ {
+ // Make sure we don't try and change the current property if we are loading properties from an array.
+ if (mInArrayProperty == 0 && mInContainerProperty == 0 && topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT)
+ {
+ std::string resourceTypeString = dtUtil::XMLStringConverter(chars).ToString();
+ mActorPropertyType = static_cast<DataType*>(DataType::GetValueForName(resourceTypeString));
+
+ if (mActorPropertyType == NULL)
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "No resource type found for type specified in xml \"%s.\"",
+ resourceTypeString.c_str());
+ }
+ }
+ else if (mActorPropertyType != NULL)
+ {
+ std::string dataValue = dtUtil::XMLStringConverter(chars).ToString();
+
+ if (mParser->mLogger->IsLevelEnabled(dtUtil::Log::LOG_DEBUG))
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_DEBUG, __FUNCTION__, __LINE__,
+ "Setting value of property %s, property type %s, datatype %s, value %s, element name %s.",
+ mActorProperty->GetName().c_str(),
+ mActorProperty->GetDataType().GetName().c_str(),
+ mActorPropertyType->GetName().c_str(),
+ dataValue.c_str(), dtUtil::XMLStringConverter(topEl.c_str()).c_str());
+ }
+
+ //we now have the property, the type, and the data.
+ ParsePropertyData(topEl, dataValue, &mActorPropertyType, mActorProperty.get(), propContainer);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ template <typename VecType>
+ void ActorPropertySerializer::WriteVec(const VecType& vec, char* numberConversionBuffer, const size_t bufferMax)
+ {
+ switch (VecType::num_components) {
+ case 2:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_VEC2_ELEMENT);
+ break;
+ case 3:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_VEC3_ELEMENT);
+ break;
+ case 4:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_VEC4_ELEMENT);
+ break;
+ default:
+ //LOG error
+ return;
+ }
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_VEC_1_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", vec[0]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_VEC_2_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", vec[1]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ if (VecType::num_components > 2)
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_VEC_3_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", vec[2]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+ }
+
+ if (VecType::num_components > 3)
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_VEC_4_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", vec[3]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+ }
+
+ mWriter->EndElement();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::WriteParameter(const NamedParameter& parameter)
+ {
+ const size_t bufferMax = 512;
+ char numberConversionBuffer[bufferMax];
+ const DataType& dataType = parameter.GetDataType();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_PARAMETER_ELEMENT);
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT);
+ mWriter->AddCharacters(parameter.GetName());
+ if (mWriter->mLogger->IsLevelEnabled(dtUtil::Log::LOG_DEBUG))
+ {
+ mWriter->mLogger->LogMessage(dtUtil::Log::LOG_DEBUG, __FUNCTION__, __LINE__,
+ "Found Parameter of GroupActorProperty Named: %s", parameter.GetName().c_str());
+ }
+ mWriter->EndElement();
+
+ switch (dataType.GetTypeId())
+ {
+ case DataType::FLOAT_ID:
+ case DataType::DOUBLE_ID:
+ case DataType::INT_ID:
+ case DataType::LONGINT_ID:
+ case DataType::STRING_ID:
+ case DataType::BOOLEAN_ID:
+ case DataType::ACTOR_ID:
+ case DataType::GAMEEVENT_ID:
+ case DataType::ENUMERATION_ID:
+ WriteSimple(parameter);
+ break;
+ case DataType::VEC2_ID:
+ WriteVec(static_cast<const NamedVec2Parameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC2F_ID:
+ WriteVec(static_cast<const NamedVec2fParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC2D_ID:
+ WriteVec(static_cast<const NamedVec2dParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3_ID:
+ WriteVec(static_cast<const NamedVec3Parameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3F_ID:
+ WriteVec(static_cast<const NamedVec3fParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC3D_ID:
+ WriteVec(static_cast<const NamedVec3dParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4_ID:
+ WriteVec(static_cast<const NamedVec4Parameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4F_ID:
+ WriteVec(static_cast<const NamedVec4fParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::VEC4D_ID:
+ WriteVec(static_cast<const NamedVec4dParameter&>(parameter).GetValue(), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::RGBACOLOR_ID:
+ WriteColorRGBA(static_cast<const NamedRGBAColorParameter&>(parameter), numberConversionBuffer, bufferMax);
+ break;
+ case DataType::GROUP_ID:
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_GROUP_ELEMENT);
+ std::vector<const NamedParameter*> parameters;
+ static_cast<const NamedGroupParameter&>(parameter).GetParameters(parameters);
+ for (size_t i = 0; i < parameters.size(); ++i)
+ {
+ WriteParameter(*parameters[i]);
+ }
+ mWriter->EndElement();
+ break;
+ }
+ case DataType::ARRAY_ID:
+ {
+ // mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT);
+ // TODO ARRAY: Save an array that was part of a group.
+ break;
+ }
+ case DataType::CONTAINER_ID:
+ {
+ //mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT);
+ // TODO CONTAINER: Save a container that was part of a group.
+ break;
+ }
+ default:
+ {
+ if (dataType.IsResource())
+ {
+ const NamedResourceParameter& p =
+ static_cast<const NamedResourceParameter&>(parameter);
+
+ const ResourceDescriptor* rd = p.GetValue();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT);
+ mWriter->AddCharacters(parameter.GetDataType().GetName());
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_DISPLAY_ELEMENT);
+ if (rd != NULL)
+ mWriter->AddCharacters(rd->GetDisplayName());
+ mWriter->EndElement();
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_RESOURCE_IDENTIFIER_ELEMENT);
+ if (rd != NULL)
+ mWriter->AddCharacters(rd->GetResourceIdentifier());
+ mWriter->EndElement();
+ }
+ else
+ {
+ mWriter->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Unhandled datatype in ActorPropertySerializer: %s.",
+ dataType.GetName().c_str());
+ }
+ }
+ }
+ //End the parameter element.
+ mWriter->EndElement();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ template <typename Type>
+ void ActorPropertySerializer::WriteColorRGBA(const Type& holder, char* numberConversionBuffer, size_t bufferMax)
+ {
+ osg::Vec4f val = holder.GetValue();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_COLOR_RGBA_ELEMENT);
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_COLOR_R_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", val[0]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_COLOR_G_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", val[1]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_COLOR_B_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", val[2]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_COLOR_A_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%f", val[3]);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ mWriter->EndElement();
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::WriteArray(const ArrayActorPropertyBase& arrayProp, char* numberConversionBuffer, size_t bufferMax)
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT);
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_ARRAY_SIZE_ELEMENT);
+ int arraySize = arrayProp.GetArraySize();
+ snprintf(numberConversionBuffer, bufferMax, "%d", arraySize);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ // Save out the data for each index.
+ for (int index = 0; index < arraySize; index++)
+ {
+ // Save out the index number.
+ mWriter->BeginElement(MapXMLConstants::ACTOR_ARRAY_ELEMENT);
+
+ mWriter->BeginElement(MapXMLConstants::ACTOR_ARRAY_INDEX_ELEMENT);
+ snprintf(numberConversionBuffer, bufferMax, "%d", index);
+ mWriter->AddCharacters(numberConversionBuffer);
+ mWriter->EndElement();
+
+ // Write the data for the current property.
+ arrayProp.SetIndex(index);
+ WriteProperty(*arrayProp.GetArrayProperty());
+
+ mWriter->EndElement();
+ }
+
+ mWriter->EndElement();
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::WriteContainer(const ContainerActorProperty& arrayProp, char* numberConversionBuffer, size_t bufferMax)
+ {
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT);
+
+ // Save out the data for each index.
+ for (int index = 0; index < arrayProp.GetPropertyCount(); index++)
+ {
+ // Write the data for the current property.
+ WriteProperty(*arrayProp.GetProperty(index));
+ }
+
+ mWriter->EndElement();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::WriteSimple(const AbstractParameter& holder)
+ {
+ switch (holder.GetDataType().GetTypeId())
+ {
+ case DataType::FLOAT_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_FLOAT_ELEMENT);
+ break;
+ case DataType::DOUBLE_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_DOUBLE_ELEMENT);
+ break;
+ case DataType::INT_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_INTEGER_ELEMENT);
+ break;
+ case DataType::LONGINT_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_LONG_ELEMENT);
+ break;
+ case DataType::STRING_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_STRING_ELEMENT);
+ break;
+ case DataType::BOOLEAN_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_BOOLEAN_ELEMENT);
+ break;
+ case DataType::ACTOR_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_ACTOR_ID_ELEMENT);
+ break;
+ case DataType::GAMEEVENT_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_GAMEEVENT_ELEMENT);
+ break;
+ case DataType::ENUMERATION_ID:
+ mWriter->BeginElement(MapXMLConstants::ACTOR_PROPERTY_ENUM_ELEMENT);
+ break;
+ default:
+ //LOG ERROR
+ return;
+ }
+ mWriter->AddCharacters(holder.ToString());
+ mWriter->EndElement();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::AssignGroupProperties()
+ {
+ if (!mMap.valid()) return;
+
+ for (std::multimap<PropertyContainer*, std::pair<std::string, dtCore::RefPtr<dtDAL::NamedGroupParameter> > >::iterator i
+ = mGroupParameters.begin();
+ i != mGroupParameters.end(); ++i)
+ {
+ PropertyContainer* propContainer = i->first;
+ if (propContainer == NULL)
+ {
+ continue;
+ }
+ std::pair<std::string, dtCore::RefPtr<dtDAL::NamedGroupParameter> >& data = i->second;
+ std::string& propertyName = data.first;
+ dtCore::RefPtr<dtDAL::NamedGroupParameter>& propValue = data.second;
+
+ dtCore::RefPtr<ActorProperty> property = propContainer->GetProperty(propertyName);
+ if (!property.valid())
+ {
+ property = propContainer->GetDeprecatedProperty(propertyName);
+ }
+
+ if (!property.valid())
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_INFO, __FUNCTION__, __LINE__,
+ "Group property %s set with actor %s does not exist on the property container.",
+ propertyName.c_str(), propValue->ToString().c_str());
+ continue;
+ }
+
+ GroupActorProperty* gap = dynamic_cast<GroupActorProperty*>(property.get());
+ if (gap == NULL)
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_INFO, __FUNCTION__, __LINE__,
+ "Actor property %s set with actor %s is not a GroupActorProperty.",
+ propertyName.c_str(), propValue->ToString().c_str());
+ continue;
+ }
+ gap->SetValue(*propValue);
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::EndActorPropertyGroupElement(PropertyContainer* propContainer)
+ {
+ dtCore::RefPtr<NamedGroupParameter> topParam = static_cast<NamedGroupParameter*>(mParameterStack.top().get());
+ mParameterStack.pop();
+ //The only way we know we have completed a group actor property is that the
+ //stack of parameters has been emptied since they can nest infinitely.
+ if (mParameterStack.empty())
+ {
+ mInGroupProperty = false;
+ mGroupParameters.insert(std::make_pair(propContainer,
+ std::make_pair(mActorProperty->GetName(), topParam)));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ParameterCharacters(BaseXMLHandler::xmlCharString& topEl, const XMLCh* const chars, PropertyContainer* propContainer)
+ {
+ if (topEl == MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT)
+ {
+ mParameterNameToCreate = dtUtil::XMLStringConverter(chars).ToString();
+ if (mParameterNameToCreate.empty())
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "In named parameter section, found a named parameter with an empty name.");
+
+ }
+ //Resource datatypes are held in a string value inside the resource element.
+ //This means creating the parameter has to be here, when the type element is found.
+ else if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT)
+ {
+ std::string resourceTypeString = dtUtil::XMLStringConverter(chars).ToString();
+ mParameterTypeToCreate = static_cast<DataType*>(DataType::GetValueForName(resourceTypeString));
+
+ if (mParameterTypeToCreate == NULL)
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "No resource type found for type specified in xml \"%s.\"",
+ resourceTypeString.c_str());
+ }
+ else
+ {
+ //if this fails, the parameter just won't be added.
+ CreateAndPushParameter();
+ }
+ }
+ //The make sure we are parsing a parameter type other than group. If not, then no character data
+ //makes any sense to handle.
+ else if (!mParameterStack.empty() && mParameterStack.top()->GetDataType() != DataType::GROUP)
+ {
+ std::string dataValue = dtUtil::XMLStringConverter(chars).ToString();
+
+ if (mParser->mLogger->IsLevelEnabled(dtUtil::Log::LOG_DEBUG))
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_DEBUG, __FUNCTION__, __LINE__,
+ "Setting value of parameter %s, parameter datatype %s, value %s, element name %s.",
+ mParameterStack.top()->GetName().c_str(),
+ mParameterStack.top()->GetDataType().GetName().c_str(),
+ dataValue.c_str(), dtUtil::XMLStringConverter(topEl.c_str()).c_str());
+
+ //we now have the property, the type, and the data.
+ ParseParameterData(topEl, dataValue, propContainer);
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::CreateAndPushParameter()
+ {
+ try
+ {
+ NamedGroupParameter& gp = dynamic_cast<NamedGroupParameter&>(*mParameterStack.top());
+ mParameterStack.push(gp.AddParameter(mParameterNameToCreate, *mParameterTypeToCreate));
+ mParameterTypeToCreate = NULL;
+ mParameterNameToCreate.clear();
+ }
+ catch (const std::bad_cast&)
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Tried to add a new parameter \"%s\" with type \"%s\", but failed",
+ mParameterNameToCreate.c_str(), mParameterTypeToCreate->GetName().c_str());
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ParsePropertyData(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, dtDAL::DataType** dataType, dtDAL::ActorProperty* actorProperty, PropertyContainer* propContainer)
+ {
+ if (!IsPropertyCorrectType(dataType, actorProperty))
+ return;
+
+ switch ((*dataType)->GetTypeId())
+ {
+ case DataType::FLOAT_ID:
+ case DataType::DOUBLE_ID:
+ case DataType::INT_ID:
+ case DataType::LONGINT_ID:
+ case DataType::STRING_ID:
+ case DataType::BOOLEAN_ID:
+ case DataType::ENUMERATION_ID:
+ {
+ if (!actorProperty->FromString(dataValue))
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "Failed Setting value %s for property type %s named %s",
+ dataValue.c_str(), (*dataType)->GetName().c_str(),
+ actorProperty->GetName().c_str());
+ }
+ (*dataType) = NULL;
+ break;
+ }
+ case DataType::GAMEEVENT_ID:
+ {
+ GameEventActorProperty& geProp = static_cast<GameEventActorProperty&>(*actorProperty);
+ if (mMap.valid() && !dtUtil::Trim(dataValue).empty())
+ {
+ GameEvent *e = mMap->GetEventManager().FindEvent(dtCore::UniqueId(dataValue));
+ if (e != NULL)
+ {
+ geProp.SetValue(e);
+ }
+ else
+ {
+ geProp.SetValue(NULL);
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Game Event referenced in actor property %s was not found.",
+ actorProperty->GetName().c_str());
+ }
+ }
+ else
+ {
+ geProp.SetValue(NULL);
+ }
+ (*dataType) = NULL;
+ break;
+ }
+ case DataType::VEC2_ID:
+ {
+ Vec2ActorProperty& p = static_cast<Vec2ActorProperty&>(*actorProperty);
+ osg::Vec2 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC2F_ID:
+ {
+ Vec2fActorProperty& p = static_cast<Vec2fActorProperty&>(*actorProperty);
+ osg::Vec2f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC2D_ID:
+ {
+ Vec2dActorProperty& p = static_cast<Vec2dActorProperty&>(*actorProperty);
+ osg::Vec2d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3_ID:
+ {
+ Vec3ActorProperty& p = static_cast<Vec3ActorProperty&>(*actorProperty);
+ osg::Vec3 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3F_ID:
+ {
+ Vec3fActorProperty& p = static_cast<Vec3fActorProperty&>(*actorProperty);
+ osg::Vec3f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3D_ID:
+ {
+ Vec3dActorProperty& p = static_cast<Vec3dActorProperty&>(*actorProperty);
+ osg::Vec3d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4_ID:
+ {
+ Vec4ActorProperty& p = static_cast<Vec4ActorProperty&>(*actorProperty);
+ osg::Vec4 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4F_ID:
+ {
+ Vec4fActorProperty& p = static_cast<Vec4fActorProperty&>(*actorProperty);
+ osg::Vec4f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4D_ID:
+ {
+ Vec4dActorProperty& p = static_cast<Vec4dActorProperty&>(*actorProperty);
+ osg::Vec4d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::RGBACOLOR_ID:
+ {
+ ColorRgbaActorProperty& p = static_cast<ColorRgbaActorProperty&>(*actorProperty);
+ osg::Vec4 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::ACTOR_ID:
+ {
+ //insert the data into this map to make it accessible to assign once the parsing is done.
+ dtUtil::Trim(dataValue);
+ if (!dataValue.empty() && dataValue != "NULL")
+ {
+ ActorIDActorProperty* p = dynamic_cast<ActorIDActorProperty*>(actorProperty);
+ if (p)
+ {
+ if (!p->FromString(dataValue))
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "Failed Setting value %s for property type %s named %s",
+ dataValue.c_str(), (*dataType)->GetName().c_str(),
+ actorProperty->GetName().c_str());
+ }
+ }
+ else
+ {
+ mActorLinking.insert(std::make_pair(propContainer, std::make_pair(actorProperty->GetName(), dtCore::UniqueId(dataValue))));
+ }
+ }
+ (*dataType) = NULL;
+ break;
+ }
+ case DataType::GROUP_ID:
+ {
+ ///Nothing Useful happens here.
+ break;
+ }
+ case DataType::ARRAY_ID:
+ {
+ ArrayActorPropertyBase& arrayProp = static_cast<ArrayActorPropertyBase&>(*actorProperty);
+ ParseArray(topEl, dataValue, &arrayProp, propContainer);
+ break;
+ }
+ case DataType::CONTAINER_ID:
+ {
+ ContainerActorProperty& arrayProp = static_cast<ContainerActorProperty&>(*actorProperty);
+ ParseContainer(topEl, dataValue, &arrayProp, propContainer);
+ break;
+ }
+ default:
+ {
+ if ((*dataType)->IsResource())
+ {
+ ResourceActorProperty& p = static_cast<ResourceActorProperty&>(*actorProperty);
+ if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT)
+ {
+ if (dataValue != p.GetDataType().GetName())
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "Save file expected resource property %s to have type %s, but it is %s.",
+ actorProperty->GetName().c_str(),
+ dataValue.c_str(), p.GetDataType().GetName().c_str());
+ p.SetValue(NULL);
+ (*dataType) = NULL;
+ }
+ }
+ else if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_DISPLAY_ELEMENT)
+ {
+ mDescriptorDisplayName = dataValue;
+ }
+ else if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_IDENTIFIER_ELEMENT)
+ {
+ //if the value is null, then both strings will be empty.
+ if (dataValue != "" && mDescriptorDisplayName != "")
+ {
+ ResourceDescriptor rd(mDescriptorDisplayName, dataValue);
+ p.SetValue(&rd);
+ }
+ else
+ {
+ p.SetValue(NULL);
+ }
+ }
+ }
+ else
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "DataType \"%s\" is not supported in the map loading code. The data has been ignored.",
+ (*dataType)->GetName().c_str());
+ }
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ParseParameterData(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, PropertyContainer* propContainer)
+ {
+ if (mParameterStack.empty())
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "Unable to set the value \"%s\" without a valid parameter for group actor property \"%s\"",
+ dataValue.c_str(), mActorProperty->GetName().c_str());
+ return;
+ }
+
+ ///Optimization
+ if (topEl == MapXMLConstants::ACTOR_PROPERTY_PARAMETER_ELEMENT)
+ return;
+
+ NamedParameter& np = *mParameterStack.top();
+
+ switch (np.GetDataType().GetTypeId())
+ {
+ case DataType::FLOAT_ID:
+ case DataType::DOUBLE_ID:
+ case DataType::INT_ID:
+ case DataType::LONGINT_ID:
+ case DataType::STRING_ID:
+ case DataType::BOOLEAN_ID:
+ case DataType::ENUMERATION_ID:
+ {
+ if (!np.FromString(dataValue))
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "Failed Setting value \"%s\" for parameter type \"%s\" named \"%s\" in property \"%s\".",
+ dataValue.c_str(), mActorPropertyType->GetName().c_str(),
+ mActorProperty->GetName().c_str());
+ }
+ break;
+ }
+ case DataType::GAMEEVENT_ID:
+ {
+ NamedGameEventParameter& geParam = static_cast<NamedGameEventParameter&>(np);
+ if (mMap.valid() && !dtUtil::Trim(dataValue).empty())
+ {
+ GameEvent *e = mMap->GetEventManager().FindEvent(dtCore::UniqueId(dataValue));
+ if (e != NULL)
+ {
+ geParam.SetValue(dtCore::UniqueId(dataValue));
+ }
+ else
+ {
+ geParam.SetValue(dtCore::UniqueId(""));
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Game Event referenced in named parameter \"%s\" in property \"%s\" "
+ "was not found.",
+ np.GetName().c_str(), mActorProperty->GetName().c_str());
+ }
+ }
+ else
+ {
+ geParam.SetValue(dtCore::UniqueId(""));
+ }
+ break;
+ }
+ case DataType::VEC2_ID:
+ {
+ NamedVec2Parameter& p = static_cast<NamedVec2Parameter&>(np);
+ osg::Vec2 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC2F_ID:
+ {
+ NamedVec2fParameter& p = static_cast<NamedVec2fParameter&>(np);
+ osg::Vec2f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC2D_ID:
+ {
+ NamedVec2dParameter& p = static_cast<NamedVec2dParameter&>(np);
+ osg::Vec2d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 2);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3_ID:
+ {
+ NamedVec3Parameter& p = static_cast<NamedVec3Parameter&>(np);
+ osg::Vec3 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3F_ID:
+ {
+ NamedVec3fParameter& p = static_cast<NamedVec3fParameter&>(np);
+ osg::Vec3f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC3D_ID:
+ {
+ NamedVec3dParameter& p = static_cast<NamedVec3dParameter&>(np);
+ osg::Vec3d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 3);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4_ID:
+ {
+ NamedVec4Parameter& p = static_cast<NamedVec4Parameter&>(np);
+ osg::Vec4 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4F_ID:
+ {
+ NamedVec4fParameter& p = static_cast<NamedVec4fParameter&>(np);
+ osg::Vec4f vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::VEC4D_ID:
+ {
+ NamedVec4dParameter& p = static_cast<NamedVec4dParameter&>(np);
+ osg::Vec4d vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::RGBACOLOR_ID:
+ {
+ NamedRGBAColorParameter& p = static_cast<NamedRGBAColorParameter&>(np);
+ osg::Vec4 vec = p.GetValue();
+ ParseVec(topEl, dataValue, vec, 4);
+ p.SetValue(vec);
+ break;
+ }
+ case DataType::ACTOR_ID:
+ {
+ //insert the data into this map to make it accessible to assign once the parsing is done.
+ dtUtil::Trim(dataValue);
+ if (!dataValue.empty() && dataValue != "NULL")
+ {
+ static_cast<NamedActorParameter&>(np).SetValue(dtCore::UniqueId(dataValue));
+ }
+ break;
+ }
+ case DataType::GROUP_ID:
+ {
+ break;
+ }
+ default:
+ {
+ if (np.GetDataType().IsResource())
+ {
+ NamedResourceParameter& p = static_cast<NamedResourceParameter&>(np);
+
+ if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_DISPLAY_ELEMENT)
+ {
+ mDescriptorDisplayName = dataValue;
+ }
+ else if (topEl == MapXMLConstants::ACTOR_PROPERTY_RESOURCE_IDENTIFIER_ELEMENT)
+ {
+ //if the value is null, then both strings will be empty.
+ if (dataValue != "" && mDescriptorDisplayName != "")
+ {
+ ResourceDescriptor rd(mDescriptorDisplayName, dataValue);
+ p.SetValue(&rd);
+ }
+ else
+ {
+ p.SetValue(NULL);
+ }
+ }
+ }
+ else
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_WARNING, __FUNCTION__, __LINE__,
+ "DataType \"%s\" is not supported in the map loading code. Ignoring parameter \"%s\".",
+ np.GetDataType().GetName().c_str(), np.GetName().c_str());
+
+ }
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ template <typename VecType>
+ void ActorPropertySerializer::ParseVec(BaseXMLHandler::xmlCharString& topEl, const std::string& dataValue, VecType& vec, size_t vecSize)
+ {
+ char* endMarker;
+ double value = strtod(dataValue.c_str(), &endMarker);
+
+ if (topEl == MapXMLConstants::ACTOR_VEC_1_ELEMENT || topEl == MapXMLConstants::ACTOR_COLOR_R_ELEMENT)
+ {
+ vec[0] = value;
+ }
+ else if (topEl == MapXMLConstants::ACTOR_VEC_2_ELEMENT || topEl == MapXMLConstants::ACTOR_COLOR_G_ELEMENT)
+ {
+ vec[1] = value;
+ }
+ else if (vecSize >= 3 && (topEl == MapXMLConstants::ACTOR_VEC_3_ELEMENT || topEl == MapXMLConstants::ACTOR_COLOR_B_ELEMENT))
+ {
+ vec[2] = value;
+ }
+ else if (vecSize == 4 && (topEl == MapXMLConstants::ACTOR_VEC_4_ELEMENT || topEl == MapXMLConstants::ACTOR_COLOR_A_ELEMENT))
+ {
+ vec[3] = value;
+ }
+ else
+ {
+ if (topEl == MapXMLConstants::ACTOR_PROPERTY_VEC2_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_VEC3_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_VEC4_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_COLOR_RGBA_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_COLOR_RGBA_ELEMENT)
+ return;
+
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Got an invalid element for a Vec%u: %s", unsigned(vecSize), dtUtil::XMLStringConverter(topEl.c_str()).c_str());
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ParseArray(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, ArrayActorPropertyBase* arrayProp, PropertyContainer* propContainer)
+ {
+ // Find the property we want to edit based on how deep the array is nested.
+ for (int nestIndex = 1; nestIndex < mInArrayProperty; nestIndex++)
+ {
+ arrayProp = static_cast<ArrayActorPropertyBase*>(arrayProp->GetArrayProperty());
+ }
+
+ if (!arrayProp)
+ {
+ return;
+ }
+
+ // Array Size
+ if (topEl == MapXMLConstants::ACTOR_ARRAY_SIZE_ELEMENT)
+ {
+ int arraySize;
+ std::istringstream stream;
+ stream.str(dataValue);
+ stream >> arraySize;
+
+ // Add more elements.
+ arrayProp->SetIndex(0);
+ while (arraySize > arrayProp->GetArraySize())
+ {
+ arrayProp->Insert(0);
+ }
+
+ // Remove extra elements.
+ while (arraySize < arrayProp->GetArraySize())
+ {
+ arrayProp->Remove(0);
+ }
+ }
+ // Set current Array Index
+ else if (topEl == MapXMLConstants::ACTOR_ARRAY_INDEX_ELEMENT)
+ {
+ int index;
+ std::istringstream stream;
+ stream.str(dataValue);
+ stream >> index;
+ arrayProp->SetIndex(index);
+ }
+ // Skipped elements.
+ else if (topEl == MapXMLConstants::ACTOR_ARRAY_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_ELEMENT)
+ {
+ }
+ // Unrecognized elements are checked with the array's property type
+ else
+ {
+ ActorProperty* prop = arrayProp->GetArrayProperty();
+ if (prop)
+ {
+ DataType* propType = &prop->GetDataType();
+
+ // If the element is the name of the property, we only care
+ // about it if we are parsing container elements.
+ if (topEl != MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT ||
+ (propType == &DataType::ARRAY || propType == &DataType::CONTAINER))
+ {
+ ParsePropertyData(topEl, dataValue, &propType, prop, propContainer);
+ }
+ }
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::ParseContainer(BaseXMLHandler::xmlCharString& topEl, std::string& dataValue, ContainerActorProperty* arrayProp, PropertyContainer* propContainer)
+ {
+ // Find the property we want to edit based on how deep the container is nested.
+ for (int nestIndex = 1; nestIndex < mInContainerProperty; nestIndex++)
+ {
+ int index = arrayProp->GetCurrentPropertyIndex();
+ arrayProp = static_cast<ContainerActorProperty*>(arrayProp->GetProperty(index));
+ }
+
+ if (!arrayProp)
+ {
+ return;
+ }
+
+ // Skipped elements.
+ if (topEl == MapXMLConstants::ACTOR_ARRAY_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT ||
+ topEl == MapXMLConstants::ACTOR_PROPERTY_ELEMENT)
+ {
+ }
+ else if (topEl == MapXMLConstants::ACTOR_PROPERTY_NAME_ELEMENT)
+ {
+ arrayProp->SetCurrentPropertyIndex(-1);
+ // Find the property in the container with the given name.
+ for (int index = 0; index < arrayProp->GetPropertyCount(); index++)
+ {
+ ActorProperty* prop = arrayProp->GetProperty(index);
+ if (prop)
+ {
+ if (prop->GetName() == dataValue)
+ {
+ arrayProp->SetCurrentPropertyIndex(index);
+ break;
+ }
+ }
+ }
+ }
+ // Unrecognized elements are checked with the array's property type
+ else
+ {
+ int index = arrayProp->GetCurrentPropertyIndex();
+ ActorProperty* prop = arrayProp->GetProperty(index);
+ if (prop)
+ {
+ DataType* propType = &prop->GetDataType();
+ ParsePropertyData(topEl, dataValue, &propType, prop, propContainer);
+ }
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////
+ DataType* ActorPropertySerializer::ParsePropertyType(const XMLCh* const localname, bool errorIfNotFound)
+ {
+ if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_BOOLEAN_ELEMENT) == 0)
+ {
+ return &DataType::BOOLEAN;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_FLOAT_ELEMENT) == 0)
+ {
+ return &DataType::FLOAT;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_DOUBLE_ELEMENT) == 0)
+ {
+ return &DataType::DOUBLE;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_INTEGER_ELEMENT) == 0)
+ {
+ return &DataType::INT;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_LONG_ELEMENT) == 0)
+ {
+ return &DataType::LONGINT;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_VEC2_ELEMENT) == 0)
+ {
+ return &DataType::VEC2;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_VEC3_ELEMENT) == 0)
+ {
+ return &DataType::VEC3;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_VEC4_ELEMENT) == 0)
+ {
+ return &DataType::VEC4;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_STRING_ELEMENT) == 0)
+ {
+ return &DataType::STRING;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_COLOR_RGBA_ELEMENT) == 0)
+ {
+ return &DataType::RGBACOLOR;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_COLOR_RGB_ELEMENT) == 0)
+ {
+ return &DataType::RGBCOLOR;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_ENUM_ELEMENT) == 0)
+ {
+ return &DataType::ENUMERATION;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_ACTOR_ID_ELEMENT) == 0)
+ {
+ return &DataType::ACTOR;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_GAMEEVENT_ELEMENT) == 0)
+ {
+ return &DataType::GAME_EVENT;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_GROUP_ELEMENT) == 0)
+ {
+ return &DataType::GROUP;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_ARRAY_ELEMENT) == 0)
+ {
+ return &DataType::ARRAY;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_CONTAINER_ELEMENT) == 0)
+ {
+ return &DataType::CONTAINER;
+ }
+ else if (XMLString::compareString(localname,
+ MapXMLConstants::ACTOR_PROPERTY_RESOURCE_TYPE_ELEMENT) == 0)
+ {
+ //Need the character contents to know the type, so this will be
+ //handled later.
+ }
+ else if (errorIfNotFound)
+ {
+ mParser->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,
+ "Found property data element with name %s, but this does not map to a known type.\n",
+ dtUtil::XMLStringConverter(localname).c_str());
+ }
+ return NULL;
+ }
+
+
+ /////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::NonEmptyDefaultWorkaround()
+ {
+ // We don't have control over what the string or actor
+ // property default value is, but if the data in the
+ // xml is empty string, no event is generated. Thus,
+ // this preemptively set this string to "" so that
+ // empty data will work.
+ if (mActorPropertyType != NULL && !mActorProperty->IsReadOnly())
+ {
+ if (*mActorPropertyType == DataType::STRING
+ || *mActorPropertyType == DataType::ACTOR)
+ {
+ mActorProperty->FromString("");
+ }
+ else if (*mActorPropertyType == DataType::GAME_EVENT)
+ {
+ static_cast<GameEventActorProperty*>(mActorProperty.get())->SetValue(NULL);
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::EndActorPropertyParameterElement()
+ {
+ ///We pop if the element was never filled in. This happens if the value is empty for
+ ///parameter data. We don't pop for a group because that is handled separately below.
+ if (!mParameterStack.empty() && mParameterStack.top()->GetDataType() != DataType::GROUP)
+ {
+ mParameterStack.pop();
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ void ActorPropertySerializer::EndActorPropertyElement()
+ {
+ mInActorProperty = false;
+ mActorProperty = NULL;
+ mActorPropertyType = NULL;
+ }
+
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|