From: <cn...@us...> - 2009-10-27 03:18:34
|
Revision: 589 http://hgengine.svn.sourceforge.net/hgengine/?rev=589&view=rev Author: cnlohr Date: 2009-10-27 03:18:28 +0000 (Tue, 27 Oct 2009) Log Message: ----------- first incarnation of XML Saving Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MessageHandler.h Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/Mercury2.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -42,7 +42,9 @@ { char buffer[2048]; LOG.Write(ssprintf( "Fatal error encountered in Mercury 2: %s", cn_get_crash_description( signal ) )); - cnget_backtrace( 1, buffer, 2047 ); + cnget_backtrace( 1, buffer, 2047 ); + + //XXX: Sometimes we produce a crash, we get the crash report, and the next line doesn't work... This should be examined. LOG.Write( buffer ); return 0; //Continue regular crash. @@ -173,7 +175,11 @@ #endif m_count = 0; fpsTimer = timer; - } + } + + MString st; + root->SaveToXML( st ); + StringToFile( "test.xml", st ); } while ( w->PumpMessages() ); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryAsset.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -77,6 +77,22 @@ } } +void MercuryAsset::SaveToXML( MString & sXMLStream, int depth ) +{ + sXMLStream += ssprintf( "%*c<node type=\"%s\" ", depth*3, 32, GetType() ); + if( m_path.length() ) + sXMLStream += ssprintf( "file=\"%s\" ", m_path.c_str() ); + + SaveToXMLTag( sXMLStream ); + sXMLStream += "/>\n"; +} + +void MercuryAsset::SaveToXMLTag( MString & sXMLStream ) +{ + //Assets, generally do not actually have anything else to save... +} + + void MercuryAsset::DrawAxes() { GLCALL( glBegin(GL_LINES) ); Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryAsset.h 2009-10-27 03:18:28 UTC (rev 589) @@ -45,7 +45,15 @@ ///Loads an asset from an XMLAsset representing itself virtual void LoadFromXML(const XMLNode& node); - + + ///Saves the main body of an XML node. + /** This behaves very similarly to MercuryNode::SaveToXML + The most notable difference is it doesn't handle children.*/ + virtual void SaveToXML( MString & sXMLStream, int depth = 0 ); + + ///Saves individual portions into the tag. + virtual void SaveToXMLTag( MString & sXMLStream ); + virtual void LoadedCallback(); //thread safe inline void IsInstanced(bool b) { m_isInstanced = b; } @@ -66,6 +74,8 @@ virtual MercuryAssetInstance* GenerateInstanceData(MercuryNode* parentNode); LoadState GetLoadState(); //thread safe + + GENRTTI( MercuryAsset ); protected: void SetLoadState(LoadState ls); //thread safe Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryNode.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -306,9 +306,48 @@ for( unsigned i = 0; i < out.size(); i++ ) m_iForcePasses = m_iForcePasses | (1<<StrToInt( out[i] ) ); } +} +void MercuryNode::SaveToXML( MString & sXMLStream, int depth ) +{ + sXMLStream += ssprintf( "%*c<node type=\"%s\" ", depth*3, 32, GetType() ); + if( GetName().length() ) + sXMLStream += ssprintf( "name=\"%s\" ", GetName().c_str() ); + + SaveToXMLTag( sXMLStream ); + + bool bNoChildren = true; + if( !m_assets.empty() ) + { + //No children yet (but we have them, so terminate (>) ) + if( bNoChildren ) + sXMLStream += ">\n"; + bNoChildren = false; + + for( std::list< MercuryAssetInstance * >::iterator i = m_assets.begin(); i != m_assets.end(); i++ ) + (*i)->Asset().SaveToXML( sXMLStream, depth + 1 ); + } + + if( ! m_children.empty() ) + { + //No children yet (but we have them, so terminate (>) ) + if( bNoChildren ) + sXMLStream += ">\n"; + bNoChildren = false; + for( std::list< MercuryNode * >::iterator i = m_children.begin(); i != m_children.end(); i++ ) + (*i)->SaveToXML( sXMLStream, depth + 1 ); + } + + if( bNoChildren ) + sXMLStream += "/>\n"; + else + sXMLStream += ssprintf( "%*c</node>\n", depth * 3, 32 ); } +void MercuryNode::SaveToXMLTag( MString & sXMLStream ) +{ + //MercuryNodes do not have anything else to save. +} void MercuryNode::PreRender(const MercuryMatrix& matrix) { Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryNode.h 2009-10-27 03:18:28 UTC (rev 589) @@ -17,12 +17,6 @@ Each node exists as a single entity in the scene graph. **/ -#define GENRTTI(x) static const x* Cast(const MercuryNode* n) \ -{ if (n==NULL) return NULL; return dynamic_cast<const x*>(n); } \ -static x* Cast(MercuryNode* n) \ -{ if (n==NULL) return NULL; return dynamic_cast<x*>(n); } \ -virtual const char * GetType() { return #x; } - /* #define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \ { const MercuryNode* tn = n; \ @@ -87,7 +81,22 @@ ///Loads a node from an XMLNode representing itself virtual void LoadFromXML(const XMLNode& node); - + + ///Saves the main body of an XML node. + /** This, in the base class sets up the stream (i.e. <node and invokes the + SaveToXML tag then outputs the termination (i.e. /> or > ) it then outputs + all of the various Assets and Nodes that are attached as children. It handles + closing the argument as well. Unless you intend to modify the behavior, do not + override this. In addition, it is generally best to completely re-write it if + you intend to modify the behavior. */ + virtual void SaveToXML( MString & sXMLStream, int depth = 0 ); + + ///Saves just the tag portion of an XML node. + /** The update process here is tricky. This is invoked by the base + MercuryNode class. It does not handle setting it up, i.e. type=... name=... + The various abstracted classes must append on arguments they require. */ + virtual void SaveToXMLTag( MString & sXMLStream ); + ///Run on a child when added to a parent virtual void OnAdded() {}; Modified: Mercury2/src/MessageHandler.h =================================================================== --- Mercury2/src/MessageHandler.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MessageHandler.h 2009-10-27 03:18:28 UTC (rev 589) @@ -3,9 +3,14 @@ #include <MercuryString.h> #include <global.h> - #include <MercuryVertex.h> +#define GENRTTI(x) static const x* Cast(const MessageHandler* n) \ +{ if (!n) return 0; return dynamic_cast<const x*>(n); } \ +static x* Cast(MessageHandler* n) \ +{ if (!n) return 0; return dynamic_cast<x*>(n); } \ +virtual const char * GetType() { return #x; } + class MessageData { public: @@ -23,9 +28,10 @@ class MessageHandler { - public: - virtual ~MessageHandler() {}; - virtual void HandleMessage(const MString& message, const MessageData& data) {}; +public: + virtual ~MessageHandler() {}; + virtual void HandleMessage(const MString& message, const MessageData& data) {}; + GENRTTI( MessageHandler ); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |