You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(38) |
Jun
(25) |
Jul
(16) |
Aug
(52) |
Sep
(1) |
Oct
(3) |
Nov
(18) |
Dec
(7) |
---|
From: <zcc...@us...> - 2009-12-22 21:02:44
|
Revision: 169 http://sirrf.svn.sourceforge.net/sirrf/?rev=169&view=rev Author: zccdark203 Date: 2009-12-22 21:02:34 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Added the createComponent class, which is a basic component factory, to simplify component deserialization through the Entity class. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/components.h trunk/src/core/Entity.cpp Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-12-22 20:26:16 UTC (rev 168) +++ trunk/src/components/components.cpp 2009-12-22 21:02:34 UTC (rev 169) @@ -16,47 +16,29 @@ // Include files #include "components.h" - -// Parses the given XML file for components. -void parseComponentsXML(IXMLReader *file, Entity *entity) +// Creates a component of the given type. +EntityComponent* createComponent(const std::string &type, Entity *parent) { - // Did we get a valid pointer? - if(!file) - return; + // scene + if(type == "AnimatedMeshComponent") return new AnimatedMeshComponent(parent); + else if(type == "BillboardComponent") return new BillboardComponent(parent); + else if(type == "CameraComponent") return new CameraComponent(parent); + else if(type == "ImageComponent") return new ImageComponent(parent); + else if(type == "LightComponent") return new LightComponent(parent); + else if(type == "MeshComponent") return new MeshComponent(parent); + else if(type == "OctTreeComponent") return new OctTreeComponent(parent); + else if(type == "ParticleSysComponent") return new ParticleSysComponent(parent); + else if(type == "SkyBoxComponent") return new SkyBoxComponent(parent); + else if(type == "SkyDomeComponent") return new SkyDomeComponent(parent); + else if(type == "TerrainComponent") return new TerrainComponent(parent); + else if(type == "TextBillboardComponent") return new TextBillboardComponent(parent); - // Create a list of available parse functions. - std::vector<bool (*)(IXMLReader*, Entity*)> parsers; + // sound + else if(type == "SoundListenerComponent") return new SoundListenerComponent(parent); + else if(type == "SoundSourceComponent") return new SoundSourceComponent(parent); - parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(ParticleSysComponent::parseXML); - - // Read from the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT_END: - - // </components> - if(stringw("components") == file->getNodeName()) - return; - - break; - - default: - - // Parse for components. - std::vector<bool (*)(IXMLReader*, Entity*)>::iterator it; - - for(it = parsers.begin(); it != parsers.end(); it++) - { - if( (*it)(file, entity) ) - break; - } - - break; - } - } + // We couldn't find the requested component. + return NULL; } // End of File Modified: trunk/src/components/components.h =================================================================== --- trunk/src/components/components.h 2009-12-22 20:26:16 UTC (rev 168) +++ trunk/src/components/components.h 2009-12-22 21:02:34 UTC (rev 169) @@ -38,8 +38,8 @@ // Functions -//! Parses the given XML file for components. -extern void parseComponentsXML(IXMLReader *file, Entity *entity); +//! Creates a component with of the given type. +extern EntityComponent* createComponent(const std::string &type, Entity *parent); #endif Modified: trunk/src/core/Entity.cpp =================================================================== --- trunk/src/core/Entity.cpp 2009-12-22 20:26:16 UTC (rev 168) +++ trunk/src/core/Entity.cpp 2009-12-22 21:02:34 UTC (rev 169) @@ -575,12 +575,12 @@ // Process all attributes in the components collection. for(SerializedAttribute *innerAttribute = components->pullAttribute(); innerAttribute != NULL; innerAttribute = components->pullAttribute()) { - // Top attribute. - if(innerAttribute->getName() == "BillboardComponent") + // Try to create a component of the given type. + EntityComponent *component = createComponent(innerAttribute->getName(), this); + + // Did we succesfully create a component? + if(component != NULL) { - // Create the component. - BillboardComponent *component = new BillboardComponent(this); - // Rewrap attribute so that it can be deserialized properly. SerializedAttributes *wrappedComponent = new SerializedAttributes(); wrappedComponent->pushAttribute(innerAttribute); @@ -590,8 +590,10 @@ // Clean up. wrappedComponent->drop(); - component->drop(); } + + // Clean up. + component->drop(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-22 20:26:25
|
Revision: 168 http://sirrf.svn.sourceforge.net/sirrf/?rev=168&view=rev Author: zccdark203 Date: 2009-12-22 20:26:16 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Adjusted the AngelScript bindings of the Entity and EntityComponent classes so that they now also make use of our serialization system. Modified Paths: -------------- trunk/src/scripting/ScriptManager.cpp trunk/src/scripting/core/asEntity.cpp trunk/src/scripting/core/asEntityComponent.h Modified: trunk/src/scripting/ScriptManager.cpp =================================================================== --- trunk/src/scripting/ScriptManager.cpp 2009-12-22 20:05:36 UTC (rev 167) +++ trunk/src/scripting/ScriptManager.cpp 2009-12-22 20:26:16 UTC (rev 168) @@ -96,6 +96,10 @@ bindDataStack(pEngine); bindDataStore(pEngine); + bindSerializable(pEngine); + bindSerializedAttribute(pEngine); + bindSerializedAttributes(pEngine); + bindEntity(pEngine); bindEntityComponent(pEngine); bindEntityManager(pEngine); @@ -112,10 +116,6 @@ bindAssetProcessors(pEngine); bindComponents(pEngine); - bindSerializable(pEngine); - bindSerializedAttribute(pEngine); - bindSerializedAttributes(pEngine); - bindGameState(pEngine); bindGameManager(pEngine); Modified: trunk/src/scripting/core/asEntity.cpp =================================================================== --- trunk/src/scripting/core/asEntity.cpp 2009-12-22 20:05:36 UTC (rev 167) +++ trunk/src/scripting/core/asEntity.cpp 2009-12-22 20:26:16 UTC (rev 168) @@ -20,6 +20,7 @@ #include "asHasEvents.h" #include "asEntityComponent.h" +#include "asSerializable.h" #include "../ScriptHelper.h" #include "../../core/Entity.h" @@ -56,14 +57,11 @@ // Bind inherited functions. bindHasEventsBase<Entity>(engine, "Entity"); + bindSerializableBase<Entity>(engine, "Entity"); // Set Entity behaviour. r = engine->RegisterObjectBehaviour("Entity", asBEHAVE_FACTORY, "Entity@ f(const string &in)", asFUNCTION(createEntity), asCALL_CDECL); assert(r >= 0); - r = engine->RegisterObjectBehaviour("Entity", asBEHAVE_ADDREF, "void f()", - asMETHOD(Entity, grab), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectBehaviour("Entity", asBEHAVE_RELEASE, "void f()", - asMETHOD(Entity, drop), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("Entity", "Entity& opAssign(const Entity &in)", asFUNCTION(assignT<Entity>), asCALL_CDECL_OBJLAST); assert(r >= 0); @@ -108,10 +106,6 @@ r = engine->RegisterObjectMethod("Entity", "const vector3df& getRotation()", asMETHOD(Entity, getRotation), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectMethod("Entity", "bool loadXML(const string &in)", - asMETHODPR(Entity, loadXML, (const std::string&), bool), asCALL_THISCALL); - assert(r >= 0); - r = engine->RegisterObjectMethod("Entity", "void removeChildren()", asMETHOD(Entity, removeChildren), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("Entity", "void removeComponents()", Modified: trunk/src/scripting/core/asEntityComponent.h =================================================================== --- trunk/src/scripting/core/asEntityComponent.h 2009-12-22 20:05:36 UTC (rev 167) +++ trunk/src/scripting/core/asEntityComponent.h 2009-12-22 20:26:16 UTC (rev 168) @@ -21,6 +21,8 @@ #ifdef __COMPILE_WITH_ANGELSCRIPT__ +#include "asSerializable.h" + #include "../../core/EntityComponent.h" #include "../ScriptHelper.h" @@ -57,12 +59,10 @@ int r; std::string sType = type; + // Bind inherited functions. + bindSerializableBase<T>(engine, type); + // Set common behaviour. - r = engine->RegisterObjectBehaviour(type, asBEHAVE_ADDREF, "void f()", - asMETHOD(T, grab), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectBehaviour(type, asBEHAVE_RELEASE, "void f()", - asMETHOD(T, drop), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectBehaviour("EntityComponent", asBEHAVE_REF_CAST, std::string(sType + "@ f()").c_str(), asFUNCTION((asRefCast<EntityComponent,T>)), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectBehaviour(type, asBEHAVE_IMPLICIT_REF_CAST, std::string("EntityComponent@ f()").c_str(), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-22 20:05:46
|
Revision: 167 http://sirrf.svn.sourceforge.net/sirrf/?rev=167&view=rev Author: zccdark203 Date: 2009-12-22 20:05:36 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Sirrf's serialization system is now fully functional in AngelScript. Modified Paths: -------------- trunk/build/CMake/CMakeLists.txt trunk/build/CodeBlocks/sirrf.cbp trunk/src/scripting/ScriptManager.cpp trunk/src/scripting/core/asSerializedAttributes.cpp Added Paths: ----------- trunk/src/scripting/core/asSerializedAttribute.cpp trunk/src/scripting/core/asSerializedAttribute.h Modified: trunk/build/CMake/CMakeLists.txt =================================================================== --- trunk/build/CMake/CMakeLists.txt 2009-12-22 18:54:29 UTC (rev 166) +++ trunk/build/CMake/CMakeLists.txt 2009-12-22 20:05:36 UTC (rev 167) @@ -103,6 +103,7 @@ ${SOURCE_DIR}scripting/core/asGameState.cpp ${SOURCE_DIR}scripting/core/asHasEvents.cpp ${SOURCE_DIR}scripting/core/asSerializable.cpp + ${SOURCE_DIR}scripting/core/asSerializedAttribute.cpp ${SOURCE_DIR}scripting/core/asSerializedAttributes.cpp ${SOURCE_DIR}scripting/core/ScriptedEvent.cpp # /src/scripting/scripting Modified: trunk/build/CodeBlocks/sirrf.cbp =================================================================== --- trunk/build/CodeBlocks/sirrf.cbp 2009-12-22 18:54:29 UTC (rev 166) +++ trunk/build/CodeBlocks/sirrf.cbp 2009-12-22 20:05:36 UTC (rev 167) @@ -214,6 +214,8 @@ <Unit filename="../../src/scripting/core/asHasEvents.h" /> <Unit filename="../../src/scripting/core/asSerializable.cpp" /> <Unit filename="../../src/scripting/core/asSerializable.h" /> + <Unit filename="../../src/scripting/core/asSerializedAttribute.cpp" /> + <Unit filename="../../src/scripting/core/asSerializedAttribute.h" /> <Unit filename="../../src/scripting/core/asSerializedAttributes.cpp" /> <Unit filename="../../src/scripting/core/asSerializedAttributes.h" /> <Unit filename="../../src/scripting/scripting/asScript.cpp" /> Modified: trunk/src/scripting/ScriptManager.cpp =================================================================== --- trunk/src/scripting/ScriptManager.cpp 2009-12-22 18:54:29 UTC (rev 166) +++ trunk/src/scripting/ScriptManager.cpp 2009-12-22 20:05:36 UTC (rev 167) @@ -42,6 +42,7 @@ #include "core/asGameManager.h" #include "core/asGameState.h" #include "core/asSerializable.h" +#include "core/asSerializedAttribute.h" #include "core/asSerializedAttributes.h" #include "scripting/asScript.h" @@ -112,6 +113,7 @@ bindComponents(pEngine); bindSerializable(pEngine); + bindSerializedAttribute(pEngine); bindSerializedAttributes(pEngine); bindGameState(pEngine); Added: trunk/src/scripting/core/asSerializedAttribute.cpp =================================================================== --- trunk/src/scripting/core/asSerializedAttribute.cpp (rev 0) +++ trunk/src/scripting/core/asSerializedAttribute.cpp 2009-12-22 20:05:36 UTC (rev 167) @@ -0,0 +1,145 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializedAttribute.cpp +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the SerializedAttribute class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +// Include files +#include "asSerializedAttribute.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + +#include "asSerializable.h" +#include "../ScriptHelper.h" + +#include "../../core/SerializedAttribute.h" + + +//! Wrapper function to allow classes "derived" from the Serializable class to be +//! used by the SerializedAttribute::setObject. +void setObject(asIScriptObject *object, SerializedAttribute *pAttribute) +{ + ScriptedSerializable *serializable = new ScriptedSerializable(object); + pAttribute->setObject(serializable); + serializable->drop(); +} + + +//! Binds the SerializedAttribute class to AngelScript. +void bindSerializedAttribute(asIScriptEngine *engine) +{ + // Forward declarations. + int r; + + // Bind SerializedAttribute class. + r = engine->RegisterObjectType("SerializedAttribute", sizeof(SerializedAttribute), asOBJ_REF); + + // Set SerializedAttribute behaviour. + r = engine->RegisterObjectBehaviour("SerializedAttribute", asBEHAVE_ADDREF, "void f()", + asMETHOD(SerializedAttribute, grab), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectBehaviour("SerializedAttribute", asBEHAVE_RELEASE, "void f()", + asMETHOD(SerializedAttribute, drop), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttribute", "SerializedAttribute& opAssign(const SerializedAttribute &in)", + asFUNCTION(assignT<SerializedAttribute>), asCALL_CDECL_OBJLAST); assert(r >= 0); + + // Bind SerializedAttribute class functions. + r = engine->RegisterObjectMethod("SerializedAttribute", "const string& getName()", + asMETHOD(SerializedAttribute, getName), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "const string& getType()", + asMETHOD(SerializedAttribute, getType), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttribute", "aabbox3df getAabbox3df()", + asMETHOD(SerializedAttribute, getAabbox3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "aabbox3di getAabbox3di()", + asMETHOD(SerializedAttribute, getAabbox3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "bool getBool()", + asMETHOD(SerializedAttribute, getBool), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "SColor getColor()", + asMETHOD(SerializedAttribute, getColor), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "dimension2df getDimension2df()", + asMETHOD(SerializedAttribute, getDimension2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "dimension2di getDimension2di()", + asMETHOD(SerializedAttribute, getDimension2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "f32 getFloat()", + asMETHOD(SerializedAttribute, getFloat), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "s32 getInt()", + asMETHOD(SerializedAttribute, getInt), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "line2df getLine2df()", + asMETHOD(SerializedAttribute, getLine2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "line2di getLine2di()", + asMETHOD(SerializedAttribute, getLine2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "line3df getLine3df()", + asMETHOD(SerializedAttribute, getLine3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "line3di getLine3di()", + asMETHOD(SerializedAttribute, getLine3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "Serializable@ getObject()", + asMETHOD(SerializedAttribute, getObject), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "recti getRect()", + asMETHOD(SerializedAttribute, getRect), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "string getString()", + asMETHOD(SerializedAttribute, getString), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "vector2df getVector2df()", + asMETHOD(SerializedAttribute, getVector2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "vector2di getVector2di()", + asMETHOD(SerializedAttribute, getVector2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "vector3df getVector3df()", + asMETHOD(SerializedAttribute, getVector3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "vector3di getVector3di()", + asMETHOD(SerializedAttribute, getVector3di), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttribute", "void setAabbox3df(const aabbox3df &in)", + asMETHOD(SerializedAttribute, setAabbox3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setAabbox3di(const aabbox3di &in)", + asMETHOD(SerializedAttribute, setAabbox3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setBool(bool)", + asMETHOD(SerializedAttribute, setBool), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setColor(const SColor &in)", + asMETHOD(SerializedAttribute, setColor), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setDimension2df(const dimension2df &in)", + asMETHOD(SerializedAttribute, setDimension2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setDimension2di(const dimension2di &in)", + asMETHOD(SerializedAttribute, setDimension2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setFloat(f32)", + asMETHOD(SerializedAttribute, setFloat), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setInt(s32)", + asMETHOD(SerializedAttribute, setInt), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setLine2df(const line2df &in)", + asMETHOD(SerializedAttribute, setLine2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setLine2di(const line2di &in)", + asMETHOD(SerializedAttribute, setLine2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setLine3df(const line3df &in)", + asMETHOD(SerializedAttribute, setLine3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setLine3di(const line3di &in)", + asMETHOD(SerializedAttribute, setLine3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setObject(Serializable@+) ", + asMETHOD(SerializedAttribute, setObject), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void setObject(ISerializable@+)", + asFUNCTION(setObject), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setRect(const recti &in)", + asMETHOD(SerializedAttribute, setRect), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setString(const string &in)", + asMETHOD(SerializedAttribute, setString), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setVector2df(const vector2df &in)", + asMETHOD(SerializedAttribute, setVector2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setVector2di(const vector2di &in)", + asMETHOD(SerializedAttribute, setVector2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setVector3df(const vector3df &in)", + asMETHOD(SerializedAttribute, setVector3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttribute", "void setVector3di(const vector3di &in)", + asMETHOD(SerializedAttribute, setVector3di), asCALL_THISCALL); assert(r >= 0); +} + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +// End of File + Added: trunk/src/scripting/core/asSerializedAttribute.h =================================================================== --- trunk/src/scripting/core/asSerializedAttribute.h (rev 0) +++ trunk/src/scripting/core/asSerializedAttribute.h 2009-12-22 20:05:36 UTC (rev 167) @@ -0,0 +1,32 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializedAttribute.h +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the SerializedAttribute class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +#ifndef __ASSERIALIZEDATTRIBUTE_H__ +#define __ASSERIALIZEDATTRIBUTE_H__ + +// Include files +#include "../../dependencies.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + + +//! Binds the SerializedAttribute class to AngelScript. +extern void bindSerializedAttribute(asIScriptEngine *engine); + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +#endif + + Modified: trunk/src/scripting/core/asSerializedAttributes.cpp =================================================================== --- trunk/src/scripting/core/asSerializedAttributes.cpp 2009-12-22 18:54:29 UTC (rev 166) +++ trunk/src/scripting/core/asSerializedAttributes.cpp 2009-12-22 20:05:36 UTC (rev 167) @@ -48,8 +48,6 @@ // Bind SerializedAttributes class (and dependencies). r = engine->RegisterObjectType("SerializedAttributes", sizeof(SerializedAttributes), asOBJ_REF); - r = engine->RegisterObjectType("Serializable", sizeof(Serializable), asOBJ_REF); - r = engine->RegisterInterface("ISerializable"); // Bind inherited functions. bindSerializableBase<SerializedAttributes>(engine, "SerializedAttributes"); @@ -65,6 +63,9 @@ r = engine->RegisterObjectMethod("SerializedAttributes", "bool isEmpty()", asMETHOD(SerializedAttributes, isEmpty), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "SerializedAttribute@ pullAttribute()", + asMETHOD(SerializedAttributes, pushAttribute), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "aabbox3df pullAabbox3df()", asMETHOD(SerializedAttributes, pullAabbox3df), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("SerializedAttributes", "aabbox3di pullAabbox3di()", @@ -130,7 +131,7 @@ asMETHOD(SerializedAttributes, pushLine3di), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("SerializedAttributes", "void pushObject(const string &in, Serializable@+)", asMETHOD(SerializedAttributes, pushObject), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectMethod("SerializedAttributes", "void pushObject(ISerializable@+)", + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushObject(const string &in, ISerializable@+)", asFUNCTION(pushObject), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("SerializedAttributes", "void pushRect(const string &in, const recti &in)", asMETHOD(SerializedAttributes, pushRect), asCALL_THISCALL); assert(r >= 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-22 18:54:40
|
Revision: 166 http://sirrf.svn.sourceforge.net/sirrf/?rev=166&view=rev Author: zccdark203 Date: 2009-12-22 18:54:29 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Started with exposing Sirrf's serialization system to AngelScript. The Serializable and SerializedAttributes class are ready for usage in AngelScript. Modified Paths: -------------- trunk/build/CMake/CMakeLists.txt trunk/build/CodeBlocks/sirrf.cbp trunk/src/scripting/ScriptManager.cpp Added Paths: ----------- trunk/src/scripting/core/asSerializable.cpp trunk/src/scripting/core/asSerializable.h trunk/src/scripting/core/asSerializedAttributes.cpp trunk/src/scripting/core/asSerializedAttributes.h Modified: trunk/build/CMake/CMakeLists.txt =================================================================== --- trunk/build/CMake/CMakeLists.txt 2009-12-19 18:37:36 UTC (rev 165) +++ trunk/build/CMake/CMakeLists.txt 2009-12-22 18:54:29 UTC (rev 166) @@ -102,6 +102,8 @@ ${SOURCE_DIR}scripting/core/asGameManager.cpp ${SOURCE_DIR}scripting/core/asGameState.cpp ${SOURCE_DIR}scripting/core/asHasEvents.cpp + ${SOURCE_DIR}scripting/core/asSerializable.cpp + ${SOURCE_DIR}scripting/core/asSerializedAttributes.cpp ${SOURCE_DIR}scripting/core/ScriptedEvent.cpp # /src/scripting/scripting ${SOURCE_DIR}scripting/scripting/asScript.cpp Modified: trunk/build/CodeBlocks/sirrf.cbp =================================================================== --- trunk/build/CodeBlocks/sirrf.cbp 2009-12-19 18:37:36 UTC (rev 165) +++ trunk/build/CodeBlocks/sirrf.cbp 2009-12-22 18:54:29 UTC (rev 166) @@ -212,6 +212,10 @@ <Unit filename="../../src/scripting/core/asGameState.h" /> <Unit filename="../../src/scripting/core/asHasEvents.cpp" /> <Unit filename="../../src/scripting/core/asHasEvents.h" /> + <Unit filename="../../src/scripting/core/asSerializable.cpp" /> + <Unit filename="../../src/scripting/core/asSerializable.h" /> + <Unit filename="../../src/scripting/core/asSerializedAttributes.cpp" /> + <Unit filename="../../src/scripting/core/asSerializedAttributes.h" /> <Unit filename="../../src/scripting/scripting/asScript.cpp" /> <Unit filename="../../src/scripting/scripting/asScript.h" /> <Unit filename="../../src/scripting/scripting/asScriptManager.cpp" /> Modified: trunk/src/scripting/ScriptManager.cpp =================================================================== --- trunk/src/scripting/ScriptManager.cpp 2009-12-19 18:37:36 UTC (rev 165) +++ trunk/src/scripting/ScriptManager.cpp 2009-12-22 18:54:29 UTC (rev 166) @@ -41,6 +41,8 @@ #include "core/asEventManager.h" #include "core/asGameManager.h" #include "core/asGameState.h" +#include "core/asSerializable.h" +#include "core/asSerializedAttributes.h" #include "scripting/asScript.h" #include "scripting/asScriptManager.h" @@ -109,6 +111,9 @@ bindAssetProcessors(pEngine); bindComponents(pEngine); + bindSerializable(pEngine); + bindSerializedAttributes(pEngine); + bindGameState(pEngine); bindGameManager(pEngine); Added: trunk/src/scripting/core/asSerializable.cpp =================================================================== --- trunk/src/scripting/core/asSerializable.cpp (rev 0) +++ trunk/src/scripting/core/asSerializable.cpp 2009-12-22 18:54:29 UTC (rev 166) @@ -0,0 +1,114 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializable.cpp +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the Serializable class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +// Include files +#include "asSerializable.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + +#include "../../core/GameManager.h" + +// ScriptedSerializable class +// ScriptedSerializable constructor +ScriptedSerializable::ScriptedSerializable(asIScriptObject *object) +: mObject(object) +{ + // Set up pointers which will be used. + mObject->AddRef(); + mContext = GameManager::Instance()->getScriptManager()->getEngine()->CreateContext(); +} + +// ScriptedSerializable deconstructor +ScriptedSerializable::~ScriptedSerializable() +{ + mContext->Release(); + mObject->Release(); +} + +// Serializes this object. +bool ScriptedSerializable::onSerialization(SerializedAttributes *attributes) +{ + int id = mObject->GetObjectType()->GetMethodIdByDecl("bool onSerialization(SerializedAttributes @attributes)"); + + mContext->Prepare(id); + mContext->SetObject(mObject); + mContext->SetArgObject(0, (void*)attributes); + mContext->Execute(); + + return mContext->GetReturnByte(); +} + +// Deserializes this object. +bool ScriptedSerializable::onDeserialization(SerializedAttributes *attributes) +{ + int id = mObject->GetObjectType()->GetMethodIdByDecl("bool onDeserialization(SerializedAttributes @attributes)"); + + mContext->Prepare(id); + mContext->SetObject(mObject); + mContext->SetArgObject(0, (void*)attributes); + mContext->Execute(); + + return mContext->GetReturnByte(); +} + +//! Loads data in the given instance of the Serializable class from an XML file. +bool serializableLoadXML(asIScriptObject *object, const std::string &fileName) +{ + ScriptedSerializable *serializable = new ScriptedSerializable(object); + bool succeeded = serializable->loadXML(fileName); + serializable->drop(); + + return succeeded; +} + +//! Saves data from the given instance of the Serializable class to an XML file. +bool serializableSaveXML(asIScriptObject *object, const std::string &fileName) +{ + ScriptedSerializable *serializable = new ScriptedSerializable(object); + bool succeeded = serializable->saveXML(fileName); + serializable->drop(); + + return succeeded; +} + + +//! Binds the Serializable class to AngelScript. +void bindSerializable(asIScriptEngine *engine) +{ + // Forward declarations. + int r; + + // Bind Serializable class (and dependencies). + r = engine->RegisterObjectType("Serializable", sizeof(Serializable), asOBJ_REF); + r = engine->RegisterObjectType("SerializedAttributes", sizeof(SerializedAttributes), asOBJ_REF); + + + // Get Serializable base functions. + bindSerializableBase<EntityComponent>(engine, "Serializable"); + + // Define the interface for inheritance. + r = engine->RegisterInterface("ISerializable"); + + r = engine->RegisterInterfaceMethod("ISerializable", "bool onSerialization(SerializedAttributes @attributes)"); assert(r >= 0); + r = engine->RegisterInterfaceMethod("ISerializable", "bool onDeserialization(SerializedAttributes @attributes)"); assert(r >= 0); + + // Functions for interacting with the ISerializable interface. + r = engine->RegisterGlobalFunction("bool loadXML(ISerializable@+, const string &in)", asFUNCTION(serializableLoadXML), asCALL_CDECL); assert(r >= 0); + r = engine->RegisterGlobalFunction("bool saveXML(ISerializable@+, const string &in)", asFUNCTION(serializableSaveXML), asCALL_CDECL); assert(r >= 0); +} + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +// End of File Added: trunk/src/scripting/core/asSerializable.h =================================================================== --- trunk/src/scripting/core/asSerializable.h (rev 0) +++ trunk/src/scripting/core/asSerializable.h 2009-12-22 18:54:29 UTC (rev 166) @@ -0,0 +1,91 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializable.h +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the Serializable class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +#ifndef __ASSERIALIZABLE_H__ +#define __ASSERIALIZABLE_H__ + +// Include files +#include "../../dependencies.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + +#include "../../core/Serializable.h" +#include "../ScriptHelper.h" + + +// ScriptedSerializable class +//! A class derived from Serializable, which makes it possible to interact with classes derived from +//! Serializable within AngelScript. +//! @note For internal use only! +class ScriptedSerializable : public Serializable +{ +public: + + // Initialisation, deinitialisation and control... + ScriptedSerializable(asIScriptObject *object); + virtual ~ScriptedSerializable(); + + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); + +private: + + // Private members + asIScriptObject *mObject; + asIScriptContext *mContext; + +}; + +//! Binds the Serializable class to AngelScript. +extern void bindSerializable(asIScriptEngine *engine); + +//! Binds the base behaviours and methods of the Serializable class to the given class in +//! AngelScript. +template<typename T> +void bindSerializableBase(asIScriptEngine *engine, const char *type) +{ + // Forward declaration. + int r; + std::string sType = type; + + // Set common behaviour. + r = engine->RegisterObjectBehaviour(type, asBEHAVE_ADDREF, "void f()", + asMETHOD(T, grab), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectBehaviour(type, asBEHAVE_RELEASE, "void f()", + asMETHOD(T, drop), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectBehaviour("Serializable", asBEHAVE_REF_CAST, std::string(sType + "@ f()").c_str(), + asFUNCTION((asRefCast<Serializable,T>)), asCALL_CDECL_OBJLAST); assert( r >= 0 ); + r = engine->RegisterObjectBehaviour(type, asBEHAVE_IMPLICIT_REF_CAST, std::string("Serializable@ f()").c_str(), + asFUNCTION((asRefCast<T,Serializable>)), asCALL_CDECL_OBJLAST); assert( r >= 0 ); + + // Bind common class functions. + r = engine->RegisterObjectMethod(type, "bool loadXML(const string &in)", + asMETHODPR(T, loadXML, (const std::string&), bool), asCALL_THISCALL); + assert(r >= 0); + r = engine->RegisterObjectMethod(type, "bool saveXML(const string &in)", + asMETHODPR(T, saveXML, (const std::string&), bool), asCALL_THISCALL); + assert(r >= 0); +} + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +#endif + Added: trunk/src/scripting/core/asSerializedAttributes.cpp =================================================================== --- trunk/src/scripting/core/asSerializedAttributes.cpp (rev 0) +++ trunk/src/scripting/core/asSerializedAttributes.cpp 2009-12-22 18:54:29 UTC (rev 166) @@ -0,0 +1,151 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializedAttribute.cpp +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the SerializedAttributes class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +// Include files +#include "asEntity.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + +#include "asSerializable.h" +#include "../ScriptHelper.h" + +#include "../../core/SerializedAttributes.h" + + +//! Reference factory for the SerializedAttributes class. +SerializedAttributes* createSerializedAttributes() +{ + return new SerializedAttributes(); +} + +//! Wrapper function to allow classes "derived" from the Serializable class to be +//! used by the SerializedAttributes::pushObject. +void pushObject(const std::string &name, asIScriptObject *object, SerializedAttributes *pAttributes) +{ + ScriptedSerializable *serializable = new ScriptedSerializable(object); + pAttributes->pushObject(name, serializable); + serializable->drop(); +} + + +//! Binds the SerializedAttributes class to AngelScript. +void bindSerializedAttributes(asIScriptEngine *engine) +{ + // Forward declarations. + int r; + + // Bind SerializedAttributes class (and dependencies). + r = engine->RegisterObjectType("SerializedAttributes", sizeof(SerializedAttributes), asOBJ_REF); + r = engine->RegisterObjectType("Serializable", sizeof(Serializable), asOBJ_REF); + r = engine->RegisterInterface("ISerializable"); + + // Bind inherited functions. + bindSerializableBase<SerializedAttributes>(engine, "SerializedAttributes"); + + // Set SerializedAttributes behaviour. + r = engine->RegisterObjectBehaviour("SerializedAttributes", asBEHAVE_FACTORY, "SerializedAttributes@ f()", + asFUNCTION(createSerializedAttributes), asCALL_CDECL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttributes", "SerializedAttributes& opAssign(const SerializedAttributes &in)", + asFUNCTION(assignT<SerializedAttributes>), asCALL_CDECL_OBJLAST); assert(r >= 0); + + // Bind SerializedAttributes class functions. + r = engine->RegisterObjectMethod("SerializedAttributes", "bool isEmpty()", + asMETHOD(SerializedAttributes, isEmpty), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttributes", "aabbox3df pullAabbox3df()", + asMETHOD(SerializedAttributes, pullAabbox3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "aabbox3di pullAabbox3di()", + asMETHOD(SerializedAttributes, pullAabbox3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "bool pullBool()", + asMETHOD(SerializedAttributes, pullBool), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "SColor pullColor()", + asMETHOD(SerializedAttributes, pullColor), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "dimension2df pullDimension2df()", + asMETHOD(SerializedAttributes, pullDimension2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "dimension2di pullDimension2di()", + asMETHOD(SerializedAttributes, pullDimension2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "f32 pullFloat()", + asMETHOD(SerializedAttributes, pullFloat), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "s32 pullInt()", + asMETHOD(SerializedAttributes, pullInt), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "line2df pullLine2df()", + asMETHOD(SerializedAttributes, pullLine2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "line2di pullLine2di()", + asMETHOD(SerializedAttributes, pullLine2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "line3df pullLine3df()", + asMETHOD(SerializedAttributes, pullLine3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "line3di pullLine3di()", + asMETHOD(SerializedAttributes, pullLine3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "Serializable@ pullObject()", + asMETHOD(SerializedAttributes, pullObject), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "recti pullRect()", + asMETHOD(SerializedAttributes, pullRect), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "string pullString()", + asMETHOD(SerializedAttributes, pullString), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "vector2df pullVector2df()", + asMETHOD(SerializedAttributes, pullVector2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "vector2di pullVector2di()", + asMETHOD(SerializedAttributes, pullVector2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "vector3df pullVector3df()", + asMETHOD(SerializedAttributes, pullVector3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "vector3di pullVector3di()", + asMETHOD(SerializedAttributes, pullVector3di), asCALL_THISCALL); assert(r >= 0); + + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushAabbox3df(const string &in, const aabbox3df &in)", + asMETHOD(SerializedAttributes, pushAabbox3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushAabbox3di(const string &in, const aabbox3di &in)", + asMETHOD(SerializedAttributes, pushAabbox3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushBool(const string &in, bool)", + asMETHOD(SerializedAttributes, pushBool), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushColor(const string &in, const SColor &in)", + asMETHOD(SerializedAttributes, pushColor), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushDimension2df(const string &in, const dimension2df &in)", + asMETHOD(SerializedAttributes, pushDimension2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushDimension2di(const string &in, const dimension2di &in)", + asMETHOD(SerializedAttributes, pushDimension2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushFloat(const string &in, f32)", + asMETHOD(SerializedAttributes, pushFloat), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushInt(const string &in, s32)", + asMETHOD(SerializedAttributes, pushInt), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushLine2df(const string &in, const line2df &in)", + asMETHOD(SerializedAttributes, pushLine2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushLine2di(const string &in, const line2di &in)", + asMETHOD(SerializedAttributes, pushLine2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushLine3df(const string &in, const line3df &in)", + asMETHOD(SerializedAttributes, pushLine3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushLine3di(const string &in, const line3di &in)", + asMETHOD(SerializedAttributes, pushLine3di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushObject(const string &in, Serializable@+)", + asMETHOD(SerializedAttributes, pushObject), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushObject(ISerializable@+)", + asFUNCTION(pushObject), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushRect(const string &in, const recti &in)", + asMETHOD(SerializedAttributes, pushRect), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushString(const string &in, const string &in)", + asMETHOD(SerializedAttributes, pushString), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushVector2df(const string &in, const vector2df &in)", + asMETHOD(SerializedAttributes, pushVector2df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushVector2di(const string &in, const vector2di &in)", + asMETHOD(SerializedAttributes, pushVector2di), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushVector3df(const string &in, const vector3df &in)", + asMETHOD(SerializedAttributes, pushVector3df), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("SerializedAttributes", "void pushVector3di(const string &in, const vector3di &in)", + asMETHOD(SerializedAttributes, pushVector3di), asCALL_THISCALL); assert(r >= 0); +} + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +// End of File Added: trunk/src/scripting/core/asSerializedAttributes.h =================================================================== --- trunk/src/scripting/core/asSerializedAttributes.h (rev 0) +++ trunk/src/scripting/core/asSerializedAttributes.h 2009-12-22 18:54:29 UTC (rev 166) @@ -0,0 +1,32 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: asSerializedAttributes.h +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Binds the SerializedAttributes class to AngelScript +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +#ifndef __ASSERIALIZEDATTRIBUTES_H__ +#define __ASSERIALIZEDATTRIBUTES_H__ + +// Include files +#include "../../dependencies.h" + +#ifdef __COMPILE_WITH_ANGELSCRIPT__ + + +//! Binds the SerializedAttributes class to AngelScript. +extern void bindSerializedAttributes(asIScriptEngine *engine); + +#endif // __COMPILE_WITH_ANGELSCRIPT__ + +#endif + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-19 18:37:44
|
Revision: 165 http://sirrf.svn.sourceforge.net/sirrf/?rev=165&view=rev Author: zccdark203 Date: 2009-12-19 18:37:36 +0000 (Sat, 19 Dec 2009) Log Message: ----------- Adjusted the EntityManager's createEntityFromXML methods so that they make use of the fact that the Entity class is now serializable. Modified Paths: -------------- trunk/src/core/EntityManager.cpp Modified: trunk/src/core/EntityManager.cpp =================================================================== --- trunk/src/core/EntityManager.cpp 2009-12-04 11:59:55 UTC (rev 164) +++ trunk/src/core/EntityManager.cpp 2009-12-19 18:37:36 UTC (rev 165) @@ -114,132 +114,32 @@ // Creates an Entity from a XML file through a IXMLReader object. Entity* EntityManager::createEntityFromXML(IXMLReader *file, Entity *parent, AssetGroup *assets, bool grab) { - // Did we get a valid pointer? - if(!file) - return NULL; + // Create the entity. + Entity *entity = new Entity("", parent, assets); - // Read from the file. - Entity *entity = NULL; - bool doneParsing = false; - - while(file->read() && !doneParsing) + // Deserialize the entity from the given XML file. + if(entity->loadXML(file)) { - switch(file->getNodeType()) + if(grab) { - case io::EXN_ELEMENT: + // Check if we don't already have an entity with the same name. + if(getEntity(entity->getName()) != NULL) + { + entity->drop(); + return NULL; + } - // <Entity> - if(stringw("Entity") == file->getNodeName()) - { - // Initialisation - stringc name = file->getAttributeValue(L"name"); + // Add the entity. + mEntities.push_back(entity); + entity->grab(); + } - if(grab && getEntity(name.c_str()) != NULL) - return NULL; - - entity = new Entity(name.c_str(), parent, assets); - - // If we don't have a parent, we try to load the one specified in the file. - if(parent == NULL) - { - // Get the filename of the parent. - stringc parentFile = file->getAttributeValue(L"parent"); - - // Check the value we retrieved. - if(parentFile != "") - { - // Try to get a pointer to the parent. - Entity *retrievedParent = NULL; - - if(assets != NULL) - { - EntityProcessor *processor = static_cast<EntityProcessor*> - (assets->getAssetProcessor("entities")); - - retrievedParent = processor->getEntity(parentFile.c_str()); - } - - else - retrievedParent = GameManager::Instance()->getEntityManager() - ->getEntity(parentFile.c_str()); - - if(retrievedParent == NULL && assets == NULL) - { - parent = GameManager::Instance()->getEntityManager()-> - createEntityFromXML(parentFile.c_str(), NULL, NULL, grab); - } - - // Set parent, if available. - if(retrievedParent != NULL) - entity->setParent(retrievedParent); - } - } - } - - // Do we already have an entity? - if(entity != NULL) - { - // <absolutePosition> - if(stringw("absolutePosition") == file->getNodeName()) - { - entity->setAbsolutePosition(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <position> - else if(stringw("position") == file->getNodeName()) - { - entity->setPosition(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <absoluteRotation> - else if(stringw("absoluteRotation") == file->getNodeName()) - { - entity->setAbsoluteRotation(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <rotation> - else if(stringw("rotation") == file->getNodeName()) - { - entity->setRotation(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <components> - else if(stringw("components") == file->getNodeName()) - parseComponentsXML(file, entity); - } - - break; - - case io::EXN_ELEMENT_END: - - // </Entityr> - if(stringw("Entity") == file->getNodeName()) - doneParsing = true; - - break; - - default: - break; - } + return entity; } - // Add the entity. - if(grab && entity != NULL) - { - mEntities.push_back(entity); - entity->grab(); - } - - // We return the entity. - return entity; + // In case deserialization has failed, we will drop the entity and return a NULL pointer. + entity->drop(); + return NULL; } // Gets the entity with the given ID. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-04 12:00:03
|
Revision: 164 http://sirrf.svn.sourceforge.net/sirrf/?rev=164&view=rev Author: zccdark203 Date: 2009-12-04 11:59:55 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Serialized SoundSourceComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/sound/SoundSourceComponent.cpp trunk/src/components/sound/SoundSourceComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-12-04 11:35:43 UTC (rev 163) +++ trunk/src/components/components.cpp 2009-12-04 11:59:55 UTC (rev 164) @@ -30,10 +30,6 @@ parsers.push_back(AnimatedMeshComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); -#ifdef __COMPILE_WITH_SFML_AUDIO__ - parsers.push_back(SoundSourceComponent::parseXML); -#endif // __COMPILE_WITH_SFML_AUDIO__ - // Read from the file. while(file->read()) { Modified: trunk/src/components/sound/SoundSourceComponent.cpp =================================================================== --- trunk/src/components/sound/SoundSourceComponent.cpp 2009-12-04 11:35:43 UTC (rev 163) +++ trunk/src/components/sound/SoundSourceComponent.cpp 2009-12-04 11:59:55 UTC (rev 164) @@ -457,87 +457,64 @@ } } -// Parses for a SoundSourceComponent. -bool SoundSourceComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool SoundSourceComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - SoundSourceComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a SoundSourceComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("SoundSourceComponent") == file->getNodeName()) - { - // Initialise the component. - component = new SoundSourceComponent(entity); - } - } + // Serialize attributes. + if(mMusic != NULL) + root->pushString("music", mSoundFileName); - if(component == NULL) - return false; + root->pushFloat("attenuation", getAttenuation()); + root->pushBool("loop", getLoop()); + root->pushFloat("minDistance", getMinDistance()); + root->pushFloat("pitch", getPitch()); + root->pushFloat("volume", getVolume()); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Add root to the given collection of attributes. + attributes->pushObject("SoundSourceComponent", root); + root->drop(); - // <attenuation> - if(stringw("attenuation") == file->getNodeName()) - component->setAttenuation(file->getAttributeValueAsFloat(L"value")); + // Return + return true; +} - // <loop> - else if(stringw("loop") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setLoop( (value == "true") ? true : false ); - } +// Deserializes this object. +bool SoundSourceComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - // <minDistance> - else if(stringw("minDistance") == file->getNodeName()) - component->setMinDistance(file->getAttributeValueAsFloat(L"value")); + if(rootAttribute == NULL || rootAttribute->getName() != "SoundSourceComponent") + return false; - // <music> - else if(stringw("music") == file->getNodeName()) - { - stringc fileName = file->getAttributeValue(L"fileName"); - component->loadMusic(fileName.c_str()); - } + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // <pitch> - else if(stringw("pitch") == file->getNodeName()) - component->setPitch(file->getAttributeValueAsFloat(L"value")); + rootAttribute->drop(); // We no longer need this attribute. - else if(stringw("soundBuffer") == file->getNodeName()) - { - stringc bufferName = file->getAttributeValue(L"bufferName"); - component->loadSoundBuffer(bufferName.c_str()); - } + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "music") loadMusic(attribute->getString()); + else if(attribute->getName() == "attenuation") setAttenuation(attribute->getFloat()); + else if(attribute->getName() == "loop") setLoop(attribute->getBool()); + else if(attribute->getName() == "minDistance") setMinDistance(attribute->getFloat()); + else if(attribute->getName() == "pitch") setPitch(attribute->getFloat()); + else if(attribute->getName() == "volume") setVolume(attribute->getFloat()); - // <volume> - else if(stringw("volume") == file->getNodeName()) - component->setVolume(file->getAttributeValueAsFloat(L"value")); + // We no longer need a reference to the attribute. + attribute->drop(); + } - break; + // We no longer need a reference to the root. + root->drop(); - case io::EXN_ELEMENT_END: - - // </SoundSourceComponent> - if(stringw("SoundSourceComponent") == file->getNodeName()) - return true; - - break; - - default: - - break; - } - - } - - // The code should never get here. - return false; + // We're done. + return true; } #endif // __COMPILE_WITH_SFML_AUDIO__ Modified: trunk/src/components/sound/SoundSourceComponent.h =================================================================== --- trunk/src/components/sound/SoundSourceComponent.h 2009-12-04 11:35:43 UTC (rev 163) +++ trunk/src/components/sound/SoundSourceComponent.h 2009-12-04 11:59:55 UTC (rev 164) @@ -54,7 +54,7 @@ //! //! <b>XML:</b> //! \code - //! <music fileName="" /> + //! <music type="string" value="" /> //! \endcode //! //! @param fileName Filename of the music object to load. @@ -64,12 +64,6 @@ //! @param length Length of the buffer. bool loadMusicFromMemory(c8 *buffer, long length); //! Loads the sound data from a sound buffer. - //! - //! <b>XML:</b> - //! \code - //! <soundBuffer bufferName="" /> - //! \endcode - //! //! @param bufferName Name of the buffer to load. //! @see SoundManager bool loadSoundBuffer(const std::string &bufferName); @@ -110,7 +104,7 @@ //! //! <b>XML:</b> //! \code - //! <attenuation value="" /> + //! <attenuation type="number" value="" /> //! \endcode //! //! @param attenuation New attenuation factor. @@ -119,7 +113,7 @@ //! //! <b>XML:</b> //! \code - //! <loop value="" /> + //! <loop type="bool" value="" /> //! \endcode //! //! @param value If true, the sound loops. Else the sound doesn't loop. @@ -129,7 +123,7 @@ //! //! <b>XML:</b> //! \code - //! <minDistance value="" /> + //! <minDistance type="number" value="" /> //! \endcode void setMinDistance(f32 minDistance); //! Sets the current playing position of the sound. @@ -139,7 +133,7 @@ //! //! <b>XML:</b> //! \code - //! <pitch value="" /> + //! <pitch type="number" value="" /> //! \endcode //! void setPitch(f32 pitch); @@ -147,7 +141,7 @@ //! //! <b>XML:</b> //! \code - //! <volume value="" /> + //! <volume type="number" value="" /> //! \endcode //! void setVolume(f32 volume); @@ -166,10 +160,13 @@ //! @note For internal use only! void onSound(void *p); - // XML - //! Parses for a SoundSourceComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-12-04 11:35:55
|
Revision: 163 http://sirrf.svn.sourceforge.net/sirrf/?rev=163&view=rev Author: zccdark203 Date: 2009-12-04 11:35:43 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Serialized SoundListenerComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/sound/SoundListenerComponent.cpp trunk/src/components/sound/SoundListenerComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-24 10:39:19 UTC (rev 162) +++ trunk/src/components/components.cpp 2009-12-04 11:35:43 UTC (rev 163) @@ -31,7 +31,6 @@ parsers.push_back(ParticleSysComponent::parseXML); #ifdef __COMPILE_WITH_SFML_AUDIO__ - parsers.push_back(SoundListenerComponent::parseXML); parsers.push_back(SoundSourceComponent::parseXML); #endif // __COMPILE_WITH_SFML_AUDIO__ Modified: trunk/src/components/sound/SoundListenerComponent.cpp =================================================================== --- trunk/src/components/sound/SoundListenerComponent.cpp 2009-11-24 10:39:19 UTC (rev 162) +++ trunk/src/components/sound/SoundListenerComponent.cpp 2009-12-04 11:35:43 UTC (rev 163) @@ -115,59 +115,52 @@ setIsMainListener(true); } -// Parses for a SoundListenerComponent. -bool SoundListenerComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool SoundListenerComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - SoundListenerComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a SoundListenerComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("SoundListenerComponent") == file->getNodeName()) - { - // Initialise the component. - component = new SoundListenerComponent(entity, false); - } - } + // Serialize attributes. + root->pushBool("isMainListener", getIsMainListener()); - if(component == NULL) - return false; + // Add root to the given collection of attributes. + attributes->pushObject("SoundListenerComponent", root); + root->drop(); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Return + return true; +} - // <isMainListener> - if(stringw("isMainListener") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setIsMainListener( (value == "true") ? true : false ); - } +// Deserializes this object. +bool SoundListenerComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); + if(rootAttribute == NULL || rootAttribute->getName() != "SoundListenerComponent") + return false; - break; + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - case io::EXN_ELEMENT_END: + rootAttribute->drop(); // We no longer need this attribute. - // </SoundListenerComponent> - if(stringw("SoundListenerComponent") == file->getNodeName()) - return true; + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "isMainListener") setIsMainListener(attribute->getBool()); - break; + // We no longer need a reference to the attribute. + attribute->drop(); + } - default: + // We no longer need a reference to the root. + root->drop(); - break; - } - - } - - // The code should never get here. - return false; + // We're done. + return true; } #endif // __COMPILE_WITH_SFML_AUDIO__ Modified: trunk/src/components/sound/SoundListenerComponent.h =================================================================== --- trunk/src/components/sound/SoundListenerComponent.h 2009-11-24 10:39:19 UTC (rev 162) +++ trunk/src/components/sound/SoundListenerComponent.h 2009-12-04 11:35:43 UTC (rev 163) @@ -51,7 +51,7 @@ //! //! <b>XML:</b> //! \code - //! <isMainListener value="" /> + //! <isMainListener type="bool" value="" /> //! \endcode //! //! @param value Value to enable or disable this option. @@ -71,10 +71,13 @@ //! @note For internal use only! void onUnPause(void *p); - // XML - //! Parses for a SoundListenerComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-24 10:39:26
|
Revision: 162 http://sirrf.svn.sourceforge.net/sirrf/?rev=162&view=rev Author: zccdark203 Date: 2009-11-24 10:39:19 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Serialized TextBillboardComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/scene/TextBillboardComponent.cpp trunk/src/components/scene/TextBillboardComponent.h Modified: trunk/src/components/scene/TextBillboardComponent.cpp =================================================================== --- trunk/src/components/scene/TextBillboardComponent.cpp 2009-11-24 10:20:41 UTC (rev 161) +++ trunk/src/components/scene/TextBillboardComponent.cpp 2009-11-24 10:39:19 UTC (rev 162) @@ -86,6 +86,9 @@ // Set-up internal mechanism for collision detection. mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardTextSN); mMetaSelector = pSceneMgr->createMetaTriangleSelector(); + + // Misc + mText = text; } // Returns a direct pointer to the IBillboardTextSceneNode. @@ -105,12 +108,80 @@ void TextBillboardComponent::setText(const wchar_t *text) { mBillboardTextSN->setText(text); + mText = text; } // Sets the color of the text. void TextBillboardComponent::setTextColor(const SColor &color) { mBillboardTextSN->setTextColor(color); + mTextColor = color; } +// Serializes this object. +bool TextBillboardComponent::onSerialization(SerializedAttributes *attributes) +{ + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); + + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); + + // Serialize attributes. + root->pushStringW("text" , mText); + root->pushColor("textColor", mTextColor); + + // Add root to the given collection of attributes. + attributes->pushObject("TextBillboardComponent", root); + root->drop(); + + // Return + return true; +} + +// Deserializes this object. +bool TextBillboardComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); + + if(rootAttribute == NULL || rootAttribute->getName() != "TextBillboardComponent") + return false; + + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); + + rootAttribute->drop(); // We no longer need this attribute. + + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "BillboardComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); + + // Deserialize the component. + BillboardComponent::onDeserialization(wrappedAttribute); + + // Clean up. + wrappedAttribute->drop(); + } + + else if(attribute->getName() == "text") setText((attribute->getStringW()).c_str()); + else if(attribute->getName() == "textColor") setTextColor(attribute->getColor()); + + // We no longer need a reference to the attribute. + attribute->drop(); + } + + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; +} + // End of File Modified: trunk/src/components/scene/TextBillboardComponent.h =================================================================== --- trunk/src/components/scene/TextBillboardComponent.h 2009-11-24 10:20:41 UTC (rev 161) +++ trunk/src/components/scene/TextBillboardComponent.h 2009-11-24 10:39:19 UTC (rev 162) @@ -72,7 +72,7 @@ //! //! <b>XML:</b> //! \code - //! <text value="" /> + //! <text type="string" value="" /> //! \endcode //! //! @param text Text to set. @@ -85,12 +85,20 @@ //! //! <b>XML:</b> //! \code - //! <textColor a="" r="" g="" b="" /> + //! <textColor type="color" value="" /> //! \endcode //! //! @param color New color of the text. void setTextColor(const SColor &color); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); + private: // Private methods @@ -99,6 +107,9 @@ // Members IBillboardTextSceneNode *mBillboardTextSN; + + stringw mText; + SColor mTextColor; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-24 10:20:51
|
Revision: 161 http://sirrf.svn.sourceforge.net/sirrf/?rev=161&view=rev Author: zccdark203 Date: 2009-11-24 10:20:41 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Serialized TerrainComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/TerrainComponent.cpp trunk/src/components/scene/TerrainComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-24 10:00:35 UTC (rev 160) +++ trunk/src/components/components.cpp 2009-11-24 10:20:41 UTC (rev 161) @@ -29,7 +29,6 @@ parsers.push_back(AnimatedMeshComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); - parsers.push_back(TerrainComponent::parseXML); #ifdef __COMPILE_WITH_SFML_AUDIO__ parsers.push_back(SoundListenerComponent::parseXML); Modified: trunk/src/components/scene/TerrainComponent.cpp =================================================================== --- trunk/src/components/scene/TerrainComponent.cpp 2009-11-24 10:00:35 UTC (rev 160) +++ trunk/src/components/scene/TerrainComponent.cpp 2009-11-24 10:20:41 UTC (rev 161) @@ -165,65 +165,68 @@ heightMap->drop(); } -// Parses for a TerrainComponent. -bool TerrainComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool TerrainComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - TerrainComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a MeshComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("TerrainComponent") == file->getNodeName()) - { - // Initialise the component. - component = new TerrainComponent(entity); - } - } + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); - if(component == NULL) - return false; + // Serialize attributes. + root->pushString("heightMap", mHeightMapFileName); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Add root to the given collection of attributes. + attributes->pushObject("TerrainComponent", root); + root->drop(); - // <heightMap> - if(stringw("heightMap") == file->getNodeName()) - { - stringc fileName = file->getAttributeValue(L"fileName"); - component->loadHeightMap(fileName.c_str()); - } + // Return + return true; +} - // <textureScale> - else if(stringw("textureScale") == file->getNodeName()) - { - component->scaleTexture(file->getAttributeValueAsFloat(L"scale"), - file->getAttributeValueAsFloat(L"scale2")); - } +// Deserializes this object. +bool TerrainComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - break; + if(rootAttribute == NULL || rootAttribute->getName() != "TerrainComponent") + return false; - case io::EXN_ELEMENT_END: + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // </TerrainComponent> - if(stringw("TerrainComponent") == file->getNodeName()) - return true; + rootAttribute->drop(); // We no longer need this attribute. - break; + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "SceneComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - default: + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - break; - } + // Clean up. + wrappedAttribute->drop(); + } - } + else if(attribute->getName() == "heightMap") loadHeightMap(attribute->getString()); - // The code should never get here. - return false; + // We no longer need a reference to the attribute. + attribute->drop(); + } + + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/TerrainComponent.h =================================================================== --- trunk/src/components/scene/TerrainComponent.h 2009-11-24 10:00:35 UTC (rev 160) +++ trunk/src/components/scene/TerrainComponent.h 2009-11-24 10:20:41 UTC (rev 161) @@ -73,7 +73,7 @@ //! //! <b>XML:</b> //! \code - //! <heightMap fileName="" /> + //! <heightMap type="string" value="" /> //! \endcode //! //! @param fileName Filename of the heightmap to load. @@ -83,12 +83,6 @@ SColor(255, 255, 255, 255), s32 smoothFactor = 0); //! Scales the base texture. - //! - //! <b>XML:</b> - //! \code - //! <textureScale scale="" scale2="" /> - //! \endcode - //! //! @param scale The scaling amount. Values above 1.0 increase the number of time //! the texture is drawn on the terrain. Values below 0 will decrease //! the number of times the texture is drawn on the terrain. Using @@ -104,10 +98,13 @@ //! @note For internal use only! void onHeightMap(void *p); - // XML - //! Parses for a TerrainComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-24 10:00:48
|
Revision: 160 http://sirrf.svn.sourceforge.net/sirrf/?rev=160&view=rev Author: zccdark203 Date: 2009-11-24 10:00:35 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Serialized SkyDomeComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/SkyDomeComponent.cpp trunk/src/components/scene/SkyDomeComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-24 09:40:57 UTC (rev 159) +++ trunk/src/components/components.cpp 2009-11-24 10:00:35 UTC (rev 160) @@ -29,7 +29,6 @@ parsers.push_back(AnimatedMeshComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); - parsers.push_back(SkyDomeComponent::parseXML); parsers.push_back(TerrainComponent::parseXML); #ifdef __COMPILE_WITH_SFML_AUDIO__ Modified: trunk/src/components/scene/SkyDomeComponent.cpp =================================================================== --- trunk/src/components/scene/SkyDomeComponent.cpp 2009-11-24 09:40:57 UTC (rev 159) +++ trunk/src/components/scene/SkyDomeComponent.cpp 2009-11-24 10:00:35 UTC (rev 160) @@ -70,56 +70,63 @@ mMetaSelector = NULL; } -// Parses for a SkyDomeComponent. -bool SkyDomeComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool SkyDomeComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - SkyDomeComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a SkyDomeComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("SkyDomeComponent") == file->getNodeName()) - { - u32 hRes = file->getAttributeValueAsInt(L"hRes"); - u32 vRes = file->getAttributeValueAsInt(L"vRes"); - f32 texturePerc = file->getAttributeValueAsFloat(L"texturePerc"); - f32 spherePerc = file->getAttributeValueAsFloat(L"spherePerc"); - f32 radius = file->getAttributeValueAsFloat(L"radius"); + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); - // Initialise the component. - component = new SkyDomeComponent(entity, hRes, vRes, texturePerc, spherePerc, radius); - } - } + // Add root to the given collection of attributes. + attributes->pushObject("SkyDomeComponent", root); + root->drop(); - if(component == NULL) - return false; + // Return + return true; +} - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: +// Deserializes this object. +bool SkyDomeComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - break; + if(rootAttribute == NULL || rootAttribute->getName() != "SkyDomeComponent") + return false; - case io::EXN_ELEMENT_END: + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // </SkyDomeComponent> - if(stringw("SkyDomeComponent") == file->getNodeName()) - return true; + rootAttribute->drop(); // We no longer need this attribute. - break; + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "SceneComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - default: + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - break; + // Clean up. + wrappedAttribute->drop(); } + + // We no longer need a reference to the attribute. + attribute->drop(); } - // The code should never get here. - return false; + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/SkyDomeComponent.h =================================================================== --- trunk/src/components/scene/SkyDomeComponent.h 2009-11-24 09:40:57 UTC (rev 159) +++ trunk/src/components/scene/SkyDomeComponent.h 2009-11-24 10:00:35 UTC (rev 160) @@ -26,7 +26,7 @@ //! //! <b>XML:</b> //! \code -//! <SkyDomeComponent hRes="" vRes="" texturePerc="" spherePerc="" radius=""> +//! <SkyDomeComponent> //! <!-- Properties --> //! </SkyDomeComponent> //! \endcode @@ -74,10 +74,13 @@ //! Deconstructor ~SkyDomeComponent(); - // XML - //! Parses for a SkyDomeComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-24 09:41:07
|
Revision: 159 http://sirrf.svn.sourceforge.net/sirrf/?rev=159&view=rev Author: zccdark203 Date: 2009-11-24 09:40:57 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Serialized SkyBoxComponent and adjusted the class' documentation to reflect this change. Besides that the BillboardComponent class now properly deserializes attributes inherited from the SceneComponent class. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/BillboardComponent.cpp trunk/src/components/scene/SkyBoxComponent.cpp trunk/src/components/scene/SkyBoxComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-24 09:21:54 UTC (rev 158) +++ trunk/src/components/components.cpp 2009-11-24 09:40:57 UTC (rev 159) @@ -29,7 +29,6 @@ parsers.push_back(AnimatedMeshComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); - parsers.push_back(SkyBoxComponent::parseXML); parsers.push_back(SkyDomeComponent::parseXML); parsers.push_back(TerrainComponent::parseXML); Modified: trunk/src/components/scene/BillboardComponent.cpp =================================================================== --- trunk/src/components/scene/BillboardComponent.cpp 2009-11-24 09:21:54 UTC (rev 158) +++ trunk/src/components/scene/BillboardComponent.cpp 2009-11-24 09:40:57 UTC (rev 159) @@ -144,9 +144,22 @@ // Process all attributes in the root collection. for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) { - // Color attribute - if(attribute->getName() == "color") + // Deserialize attributes + if(attribute->getName() == "SceneComponent") { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); + + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); + + // Clean up. + wrappedAttribute->drop(); + } + + else if(attribute->getName() == "color") + { // Convert to a collection of attributes. SerializedAttributes *color = reinterpret_cast<SerializedAttributes*>(attribute->getObject()); @@ -172,7 +185,6 @@ } } - // Size attribute else if(attribute->getName() == "size") setSize(attribute->getDimension2df()); Modified: trunk/src/components/scene/SkyBoxComponent.cpp =================================================================== --- trunk/src/components/scene/SkyBoxComponent.cpp 2009-11-24 09:21:54 UTC (rev 158) +++ trunk/src/components/scene/SkyBoxComponent.cpp 2009-11-24 09:40:57 UTC (rev 159) @@ -200,64 +200,99 @@ mSceneNode->getMaterial(side).setTexture(0, texture); } -// Parses for a SkyBoxComponent. -bool SkyBoxComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool SkyBoxComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - SkyBoxComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a SkyBoxComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("SkyBoxComponent") == file->getNodeName()) - { - // Initialise the component. - component = new SkyBoxComponent(entity); - } - } + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); - if(component == NULL) + // Serialize attributes. + // Serialize textures. + SerializedAttributes *textures = new SerializedAttributes(); + + textures->pushString("top", mTextureFileNames[4]); + textures->pushString("bottom", mTextureFileNames[5]); + textures->pushString("left", mTextureFileNames[1]); + textures->pushString("right", mTextureFileNames[3]); + textures->pushString("front", mTextureFileNames[0]); + textures->pushString("back", mTextureFileNames[2]); + + root->pushObject("textures", textures); + textures->drop(); + + // Add root to the given collection of attributes. + attributes->pushObject("SkyBoxComponent", root); + root->drop(); + + // Return + return true; +} + +// Deserializes this object. +bool SkyBoxComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); + + if(rootAttribute == NULL || rootAttribute->getName() != "SkyBoxComponent") return false; - // Continue parsing the file. - while(file->read()) + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); + + rootAttribute->drop(); // We no longer need this attribute. + + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) { - switch(file->getNodeType()) + // Deserialize attributes + if(attribute->getName() == "SceneComponent") { - case io::EXN_ELEMENT: + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - // <textures> - if(stringw("textures") == file->getNodeName()) - { - stringc top = file->getAttributeValue(L"top"); - stringc bottom = file->getAttributeValue(L"bottom"); - stringc left = file->getAttributeValue(L"left"); - stringc right = file->getAttributeValue(L"right"); - stringc front = file->getAttributeValue(L"front"); - stringc back = file->getAttributeValue(L"back"); + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - component->setTextures(top.c_str(), bottom.c_str(), left.c_str(), right.c_str(), - front.c_str(), back.c_str(), false); - } + // Clean up. + wrappedAttribute->drop(); + } - break; + else if(attribute->getName() == "textures") + { + // Convert to a collection of attributes. + SerializedAttributes *textures = reinterpret_cast<SerializedAttributes*>(attribute->getObject()); - case io::EXN_ELEMENT_END: + // Predeclaration of needed variables. + std::string top, bottom, left, right, front, back; - // </SkyBoxComponent> - if(stringw("SkyBoxComponent") == file->getNodeName()) - return true; + // Process all attributes in the textures collection. + for(SerializedAttribute *innerAttribute = textures->pullAttribute(); innerAttribute != NULL; innerAttribute = textures->pullAttribute()) + { + if(attribute->getName() == "top") top = innerAttribute->getString(); + else if(attribute->getName() == "bottom") bottom = innerAttribute->getString(); + else if(attribute->getName() == "left") left = innerAttribute->getString(); + else if(attribute->getName() == "right") right = innerAttribute->getString(); + else if(attribute->getName() == "front") front = innerAttribute->getString(); + else if(attribute->getName() == "back") back = innerAttribute->getString(); + } - break; + setTextures(top, bottom, left, right, front, back, false); + } - default: - - break; - } + // We no longer need a reference to the attribute. + attribute->drop(); } - // The code should never get here. - return false; + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/SkyBoxComponent.h =================================================================== --- trunk/src/components/scene/SkyBoxComponent.h 2009-11-24 09:21:54 UTC (rev 158) +++ trunk/src/components/scene/SkyBoxComponent.h 2009-11-24 09:40:57 UTC (rev 159) @@ -68,7 +68,14 @@ //! //! <b>XML:</b> //! \code - //! <textures top="" bottom="" left="" right="" front="" back="" /> + //! <textures> + //! <top type="string" value="" /> + //! <bottom type="string" value="" /> + //! <left type="string" value="" /> + //! <right type="string" value="" /> + //! <front type="string" value="" /> + //! <back type="string" value="" / + //! </textures> //! \endcode //! //! @param top File with the texture for the top plane of the box. @@ -98,10 +105,13 @@ //! @note For internal use only! void onTextureSkyBox(void *p); - // XML - //! Parses for a SkyBoxComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-24 09:22:00
|
Revision: 158 http://sirrf.svn.sourceforge.net/sirrf/?rev=158&view=rev Author: zccdark203 Date: 2009-11-24 09:21:54 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Serialized OctTreeComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/OctTreeComponent.cpp trunk/src/components/scene/OctTreeComponent.h trunk/src/core/EntityComponent.cpp Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-23 11:01:17 UTC (rev 157) +++ trunk/src/components/components.cpp 2009-11-24 09:21:54 UTC (rev 158) @@ -28,7 +28,6 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(OctTreeComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); parsers.push_back(SkyBoxComponent::parseXML); parsers.push_back(SkyDomeComponent::parseXML); Modified: trunk/src/components/scene/OctTreeComponent.cpp =================================================================== --- trunk/src/components/scene/OctTreeComponent.cpp 2009-11-23 11:01:17 UTC (rev 157) +++ trunk/src/components/scene/OctTreeComponent.cpp 2009-11-24 09:21:54 UTC (rev 158) @@ -169,54 +169,65 @@ mLocalMetaSelector->addTriangleSelector(mOctTreeSelector); } -// Parses for a OctTreeComponent. -bool OctTreeComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool OctTreeComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - OctTreeComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a OctTreeComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("OctTreeComponent") == file->getNodeName()) - { - // Get attributes. - s32 minPolysPerNode = file->getAttributeValueAsInt(L"minPolysPerNode"); + // Serialize attributes inherited from MeshComponent. + MeshComponent::onSerialization(root); - // Initialise the component. - component = new OctTreeComponent(entity, minPolysPerNode); - } - } + // Add root to the given collection of attributes. + attributes->pushObject("OctTreeComponent", root); + root->drop(); - if(component == NULL) - return false; + // Return + return true; +} - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - // Derived elements. +// Deserializes this object. +bool OctTreeComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - break; + if(rootAttribute == NULL || rootAttribute->getName() != "OctTreeComponent") + return false; - case io::EXN_ELEMENT_END: + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // </OctTreeComponent> - if(stringw("OctTreeComponent") == file->getNodeName()) - return true; + rootAttribute->drop(); // We no longer need this attribute. - break; + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "MeshComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - default: + // Deserialize the component. + MeshComponent::onDeserialization(wrappedAttribute); - break; - } + // Clean up. + wrappedAttribute->drop(); + } - } + else if(attribute->getName() == "mesh") setMesh(attribute->getString()); - // The code should never get here. - return false; + // We no longer need a reference to the attribute. + attribute->drop(); + } + + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/OctTreeComponent.h =================================================================== --- trunk/src/components/scene/OctTreeComponent.h 2009-11-23 11:01:17 UTC (rev 157) +++ trunk/src/components/scene/OctTreeComponent.h 2009-11-24 09:21:54 UTC (rev 158) @@ -26,7 +26,7 @@ //! //! <b>XML:</b> //! \code -//! <OctTreeComponent minPolysPerNode=""> +//! <OctTreeComponent> //! <!-- Properties --> //! </OctTreeComponent> //! \endcode @@ -81,10 +81,13 @@ //! @note For internal use only! void onMesh(void *p); - // XML - //! Parses for a OctTreeComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: Modified: trunk/src/core/EntityComponent.cpp =================================================================== --- trunk/src/core/EntityComponent.cpp 2009-11-23 11:01:17 UTC (rev 157) +++ trunk/src/core/EntityComponent.cpp 2009-11-24 09:21:54 UTC (rev 158) @@ -71,11 +71,13 @@ // Serializes this object. bool EntityComponent::onSerialization(SerializedAttributes *attributes) { + return true; } // Deserializes this object. bool EntityComponent::onDeserialization(SerializedAttributes *attributes) { + return true; } // End of File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-23 11:01:24
|
Revision: 157 http://sirrf.svn.sourceforge.net/sirrf/?rev=157&view=rev Author: zccdark203 Date: 2009-11-23 11:01:17 +0000 (Mon, 23 Nov 2009) Log Message: ----------- Serialized MeshComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/MeshComponent.cpp trunk/src/components/scene/MeshComponent.h trunk/src/components/scene/OctTreeComponent.cpp Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-23 10:52:09 UTC (rev 156) +++ trunk/src/components/components.cpp 2009-11-23 11:01:17 UTC (rev 157) @@ -28,7 +28,6 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(MeshComponent::parseXML); parsers.push_back(OctTreeComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); parsers.push_back(SkyBoxComponent::parseXML); Modified: trunk/src/components/scene/MeshComponent.cpp =================================================================== --- trunk/src/components/scene/MeshComponent.cpp 2009-11-23 10:52:09 UTC (rev 156) +++ trunk/src/components/scene/MeshComponent.cpp 2009-11-23 11:01:17 UTC (rev 157) @@ -151,70 +151,68 @@ mMeshSN->setMesh(mesh); } -// Parses for a MeshComponent. -bool MeshComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool MeshComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - MeshComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a MeshComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("MeshComponent") == file->getNodeName()) - { - // Initialise the component. - component = new MeshComponent(entity); - } - } + // Serialize attributes inherited from SceneComponent. + SceneComponent::onSerialization(root); - if(component == NULL) - return false; + // Serialize attributes. + root->pushString("mesh", mMeshFileName); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Add root to the given collection of attributes. + attributes->pushObject("MeshComponent", root); + root->drop(); - // Derived elements. - MeshComponent::parseBaseXML(file, component); + // Return + return true; +} - break; +// Deserializes this object. +bool MeshComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - case io::EXN_ELEMENT_END: + if(rootAttribute == NULL || rootAttribute->getName() != "MeshComponent") + return false; - // </MeshComponent> - if(stringw("MeshComponent") == file->getNodeName()) - return true; + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - break; + rootAttribute->drop(); // We no longer need this attribute. - default: + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "SceneComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - break; - } + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - } + // Clean up. + wrappedAttribute->drop(); + } - // The code should never get here. - return false; -} + else if(attribute->getName() == "mesh") setMesh(attribute->getString()); -// Parses for the base elements of a MeshComponent. -bool MeshComponent::parseBaseXML(IXMLReader *file, MeshComponent *component) -{ - // <mesh> - if(stringw("mesh") == file->getNodeName()) - { - stringc fileName = file->getAttributeValue(L"fileName"); - component->setMesh(fileName.c_str()); - - return true; + // We no longer need a reference to the attribute. + attribute->drop(); } - // We couldn't find any known elements. - return false; + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/MeshComponent.h =================================================================== --- trunk/src/components/scene/MeshComponent.h 2009-11-23 10:52:09 UTC (rev 156) +++ trunk/src/components/scene/MeshComponent.h 2009-11-23 11:01:17 UTC (rev 157) @@ -67,7 +67,7 @@ //! //! <b>XML:</b> //! \code - //! <mesh fileName="" /> + //! <mesh type="string" value"" /> //! \endcode //! //! fileName Filename of the mesh to load. @@ -82,13 +82,13 @@ //! @note For internal use only! void onMesh(void *p); - // XML - //! Parses for a MeshComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); - //! Parses for the base elements of a MeshComponent. - //! @note For internal use only! - static bool parseBaseXML(IXMLReader *file, MeshComponent *component); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); protected: Modified: trunk/src/components/scene/OctTreeComponent.cpp =================================================================== --- trunk/src/components/scene/OctTreeComponent.cpp 2009-11-23 10:52:09 UTC (rev 156) +++ trunk/src/components/scene/OctTreeComponent.cpp 2009-11-23 11:01:17 UTC (rev 157) @@ -197,7 +197,6 @@ switch(file->getNodeType()) { // Derived elements. - MeshComponent::parseBaseXML(file, component); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-23 10:52:18
|
Revision: 156 http://sirrf.svn.sourceforge.net/sirrf/?rev=156&view=rev Author: zccdark203 Date: 2009-11-23 10:52:09 +0000 (Mon, 23 Nov 2009) Log Message: ----------- Serialized LightComponent and adjusted the class' documentation to reflect this change. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/LightComponent.cpp trunk/src/components/scene/LightComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-23 10:34:32 UTC (rev 155) +++ trunk/src/components/components.cpp 2009-11-23 10:52:09 UTC (rev 156) @@ -28,7 +28,6 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(LightComponent::parseXML); parsers.push_back(MeshComponent::parseXML); parsers.push_back(OctTreeComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); Modified: trunk/src/components/scene/LightComponent.cpp =================================================================== --- trunk/src/components/scene/LightComponent.cpp 2009-11-23 10:34:32 UTC (rev 155) +++ trunk/src/components/scene/LightComponent.cpp 2009-11-23 10:52:09 UTC (rev 156) @@ -91,84 +91,83 @@ mLightSN->setRadius(radius); } -// Parses for a LightComponent. -bool LightComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool LightComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - LightComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a LightComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("LightComponent") == file->getNodeName()) - { - // Initialise the component. - component = new LightComponent(entity); - } - } + // Serialize attributes inherited from SceneComponent. + SceneComponent::onSerialization(root); - if(component == NULL) - return false; + // Serialize attributes. + root->pushBool("castShadow", getCastShadow()); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + if(getLightType() == ELT_POINT) root->pushString("lightType", "ELT_POINT"); + else if(getLightType() == ELT_SPOT) root->pushString("lightType", "ELT_SPOT"); + else if(getLightType() == ELT_DIRECTIONAL) root->pushString("lightType", "ELT_DIRECTIONAL"); - // <castShadow> - if(stringw("castShadow") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setCastShadow( (value == "true") ? true : false ); - } + root->pushFloat("radius", getRadius()); - // <lightType> - else if(stringw("lightType") == file->getNodeName()) - { - stringc lightType = file->getAttributeValue(L"value"); - E_LIGHT_TYPE type; + // Add root to the given collection of attributes. + attributes->pushObject("LightComponent", root); + root->drop(); -#define retrieveLightType(x) \ -else if(lightType == #x) \ - type = x + // Return + return true; +} - if(lightType== "") - type = ELT_POINT; // Dummy behaviour. +// Deserializes this object. +bool LightComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - retrieveLightType(ELT_POINT); - retrieveLightType(ELT_SPOT); - retrieveLightType(ELT_DIRECTIONAL); + if(rootAttribute == NULL || rootAttribute->getName() != "LightComponent") + return false; -#undef retrieveLightType + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - component->setLightType(type); - } + rootAttribute->drop(); // We no longer need this attribute. - // <radius> - else if(stringw("radius") == file->getNodeName()) - component->setRadius(file->getAttributeValueAsFloat(L"value")); + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes. + if(attribute->getName() == "SceneComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - break; + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - case io::EXN_ELEMENT_END: + // Clean up. + wrappedAttribute->drop(); + } - // </LightComponent> - if(stringw("LightComponent") == file->getNodeName()) - return true; + else if(attribute->getName() == "castShadow") setCastShadow(attribute->getBool()); - break; + else if(attribute->getName() == "lightType") + { + if(attribute->getString() == "ELT_POINT") setLightType(ELT_POINT); + else if(attribute->getString() == "ELT_SPOT") setLightType(ELT_SPOT); + else if(attribute->getString() == "ELT_DIRECTIONAL") setLightType(ELT_DIRECTIONAL); + } - default: + else if(attribute->getName() == "radius") setRadius(attribute->getFloat()); - break; - } + // We no longer need a reference to the attribute. + attribute->drop(); + } - } + // We no longer need a reference to the root. + root->drop(); - // The code should never get here. - return false; + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/LightComponent.h =================================================================== --- trunk/src/components/scene/LightComponent.h 2009-11-23 10:34:32 UTC (rev 155) +++ trunk/src/components/scene/LightComponent.h 2009-11-23 10:52:09 UTC (rev 156) @@ -59,7 +59,7 @@ //! //! <b>XML:</b> //! \code - //! <castShadow value="" /> + //! <castShadow type="bool" value="" /> //! \endcode //! //! @param shadow Value to enable or disable this option. @@ -68,7 +68,7 @@ //! //! <b>XML:</b> //! \code - //! <lightType value="" /> + //! <lightType type="string" value="" /> //! \endcode //! //! @param type The light type (see: Irrlicht API documentation) @@ -77,16 +77,19 @@ //! //! <b>XML:</b> //! \code - //! <radius value="" /> + //! <radius type="number" value="" /> //! \endcode //! //! @param radius The new radius. void setRadius(f32 radius); - // XML - //! Parses for a LightComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-23 10:34:49
|
Revision: 155 http://sirrf.svn.sourceforge.net/sirrf/?rev=155&view=rev Author: zccdark203 Date: 2009-11-23 10:34:32 +0000 (Mon, 23 Nov 2009) Log Message: ----------- Serialized ImageComponent and adjusted the documentation of the BillboardComponent, CameraComponent and ImageComponent classes to reflect the migration to the new serialization system. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/BillboardComponent.h trunk/src/components/scene/CameraComponent.cpp trunk/src/components/scene/CameraComponent.h trunk/src/components/scene/ImageComponent.cpp trunk/src/components/scene/ImageComponent.h Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/components.cpp 2009-11-23 10:34:32 UTC (rev 155) @@ -28,7 +28,6 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(ImageComponent::parseXML); parsers.push_back(LightComponent::parseXML); parsers.push_back(MeshComponent::parseXML); parsers.push_back(OctTreeComponent::parseXML); Modified: trunk/src/components/scene/BillboardComponent.h =================================================================== --- trunk/src/components/scene/BillboardComponent.h 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/scene/BillboardComponent.h 2009-11-23 10:34:32 UTC (rev 155) @@ -55,10 +55,25 @@ //! @param overallColor The color to set. void setColor(const SColor &overallColor); //! Sets the color of the top and bottom vertices of the billboard. + //! + //! <b>XML:</b> + //! \code + //! <color> + //! <topColor type="color" value="" /> + //! <bottomColor type="color" value="" /> + //! </color> + //! \endcode + //! //! @param topColor The color to set the top vertices. //! @param bottomColor The color to set the bottom vertices. void setColor(const SColor &topColor, const SColor &bottomColor); //! Sets the size of the billboard. + //! + //! <b>XML:</b> + //! \code + //! <size type="dimension2d" value="" /> + //! \endcode + //! //! @param size Size of the billboard. void setSize(const dimension2df &size); Modified: trunk/src/components/scene/CameraComponent.cpp =================================================================== --- trunk/src/components/scene/CameraComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/scene/CameraComponent.cpp 2009-11-23 10:34:32 UTC (rev 155) @@ -231,13 +231,11 @@ // Create a root. SerializedAttributes *root = new SerializedAttributes(); - // Serialize SceneComponent elements. - SceneComponent::onSerialization(root); - // Serialize attributes inherited from SceneComponent. SceneComponent::onSerialization(root); // Serialize attributes. + root->pushBool("asMainCamera", GameManager::Instance()->getSceneManager()->getActiveCamera() == mCameraSN); root->pushFloat("aspectRatio", getAspectRatio()); root->pushFloat("farValue", getFarValue()); root->pushFloat("FOV", getFOV()); @@ -284,6 +282,12 @@ wrappedAttribute->drop(); } + else if(attribute->getName() == "asMainCamera") + { + if(attribute->getBool()) + setAsMainCamera(); + } + else if(attribute->getName() == "aspectRatio") setAspectRatio(attribute->getFloat()); else if(attribute->getName() == "farValue") setFarValue(attribute->getFloat()); else if(attribute->getName() == "FOV") setFOV(attribute->getFloat()); Modified: trunk/src/components/scene/CameraComponent.h =================================================================== --- trunk/src/components/scene/CameraComponent.h 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/scene/CameraComponent.h 2009-11-23 10:34:32 UTC (rev 155) @@ -76,7 +76,7 @@ //! //! <b>XML:</b> //! \code - //! <setAsMainCamera /> + //! <setAsMainCamera type="bool" value="" /> //! \endcode //! void setAsMainCamera(); @@ -84,7 +84,7 @@ //! //! <b>XML:</b> //! \code - //! <aspectRatio value="" /> + //! <aspectRatio type="number" value="" /> //! \endcode //! //! @param aspect New aspect ratio. @@ -93,7 +93,7 @@ //! //! <b>XML:</b> //! \code - //! <farValue value="" /> + //! <farValue type="number" value="" /> //! \endcode //! //! @param value New far value. @@ -102,7 +102,7 @@ //! //! <b>XML:</b> //! \code - //! <FOV value="" /> + //! <FOV type="number" value="" /> //! \endcode //! //! @param value New field of view. @@ -111,7 +111,7 @@ //! //! <b>XML:</b> //! \code - //! <nearValue value="" /> + //! <nearValue type="numnber" value="" /> //! \endcode //! //! @param value New near value. @@ -127,7 +127,7 @@ //! //! <b>XML:</b> //! \code - //! <target x="" y="" z=""/> + //! <target type="vector3d" value="" /> //! \endcode //! //! @param position New target. @@ -136,7 +136,7 @@ //! //! <b>XML:</b> //! \code - //! <upVector x="" y="" z="" /> + //! <upVector type="vector3d" value="" /> //! \endcode //! //! @param position New up vector of the camera. Modified: trunk/src/components/scene/ImageComponent.cpp =================================================================== --- trunk/src/components/scene/ImageComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/scene/ImageComponent.cpp 2009-11-23 10:34:32 UTC (rev 155) @@ -274,113 +274,64 @@ mTexture->grab(); } -// Parses for a ImageComponent. -bool ImageComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool ImageComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - ImageComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a ImageComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("ImageComponent") == file->getNodeName()) - { - // Initialise the component. - component = new ImageComponent(entity); - } - } + // Serialize attributes. + root->pushColor("alphaColor", getAlphaColor()); + root->pushRect("clipRect", getClipRect()); + root->pushColor("color", getColor()); + root->pushVector2di("position", getPosition()); + root->pushRect("sourceRect", getSourceRect()); + root->pushString("texture", mTextureFileName); + root->pushBool("useAlphaColor", getUseAlphaColor()); - if(component == NULL) - return false; + // Add root to the given collection of attributes. + attributes->pushObject("ImageComponent", root); + root->drop(); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Return + return true; +} - // <alphaColor> - if(stringw("alphaColor") == file->getNodeName()) - { - component->setAlphaColor( SColor(file->getAttributeValueAsInt(L"a"), - file->getAttributeValueAsInt(L"r"), - file->getAttributeValueAsInt(L"g"), - file->getAttributeValueAsInt(L"b")) ); - } +// Deserializes this object. +bool ImageComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - // <clipRect> - else if(stringw("clipRect") == file->getNodeName()) - { - rect<s32> clipRect = rect<s32>( file->getAttributeValueAsInt(L"x1"), - file->getAttributeValueAsInt(L"y1"), - file->getAttributeValueAsInt(L"x2"), - file->getAttributeValueAsInt(L"y2") ); + if(rootAttribute == NULL || rootAttribute->getName() != "ImageComponent") + return false; - component->setClipRect(clipRect); - } + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // <color> - else if(stringw("color") == file->getNodeName()) - { - component->setColor( SColor(file->getAttributeValueAsInt(L"a"), - file->getAttributeValueAsInt(L"r"), - file->getAttributeValueAsInt(L"g"), - file->getAttributeValueAsInt(L"b")) ); - } + rootAttribute->drop(); // We no longer need this attribute. - // <position> - else if(stringw("position") == file->getNodeName()) - { - component->setPosition(vector2di(file->getAttributeValueAsInt(L"x"), - file->getAttributeValueAsInt(L"y")) ); - } + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "alphaColor") setAlphaColor(attribute->getColor()); + else if(attribute->getName() == "clipRect") setClipRect(attribute->getRect()); + else if(attribute->getName() == "color") setColor(attribute->getColor()); + else if(attribute->getName() == "position") setPosition(attribute->getVector2di()); + else if(attribute->getName() == "sourceRect") setSourceRect(attribute->getRect()); + else if(attribute->getName() == "texture") setTexture(attribute->getString()); + else if(attribute->getName() == "useAlphaColor") setUseAlphaColor(attribute->getBool()); - // <sourceRect> - else if(stringw("sourceRect") == file->getNodeName()) - { - rect<s32> sourceRect = rect<s32>( file->getAttributeValueAsInt(L"x1"), - file->getAttributeValueAsInt(L"y1"), - file->getAttributeValueAsInt(L"x2"), - file->getAttributeValueAsInt(L"y2") ); + // We no longer need a reference to the attribute. + attribute->drop(); + } - component->setSourceRect(sourceRect); - } + // We no longer need a reference to the root. + root->drop(); - // <texture> - else if(stringw("texture") == file->getNodeName()) - { - stringc fileName = file->getAttributeValue(L"fileName"); - component->setTexture(fileName.c_str()); - } - - // <useAlphaColor> - else if(stringw("useAlphaColor") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setUseAlphaColor( (value == "true") ? true : false ); - } - - - break; - - case io::EXN_ELEMENT_END: - - // </ImageComponent> - if(stringw("ImageComponent") == file->getNodeName()) - return true; - - break; - - default: - - break; - } - - } - - // The code should never get here. - return false; + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/ImageComponent.h =================================================================== --- trunk/src/components/scene/ImageComponent.h 2009-11-22 20:42:09 UTC (rev 154) +++ trunk/src/components/scene/ImageComponent.h 2009-11-23 10:34:32 UTC (rev 155) @@ -91,7 +91,7 @@ //! //! <b>XML:</b> //! \code - //! <alphaColor a="" r="" g="" b="" /> + //! <alphaColor type="color" value="" /> //! \endcode //! //! @param color New alpha color of the image. @@ -100,7 +100,7 @@ //! //! <b>XML:</b> //! \code - //! <clipRect x1="" y1="" x2="" y2="" /> + //! <clipRect type="rect" value="" /> //! \endcode //! //! @param rectangle Pointer to rectangle on the screen where the image is clipped to. @@ -110,7 +110,7 @@ //! //! <b>XML:</b> //! \code - //! <color a="" r="" g="" b="" /> + //! <color type="color" value="" /> //! \endcode //! //! @param color New color. @@ -119,7 +119,7 @@ //! //! <b>XML:</b> //! \code - //! <position x="" y="" /> + //! <position type="vector2d" value="" /> //! \endcode //! //! @param position New position. @@ -128,7 +128,7 @@ //! //! <b>XML:</b> //! \code - //! <sourceRect x1="" y1="" x2="" y2="" /> + //! <sourceRect type="rect" value="" /> //! \endcode //! //! @param rectangle New source rectangle from where the image is retrieved. @@ -137,7 +137,7 @@ //! //! <b>XML:</b> //! \code - //! <texture fileName="" /> + //! <texture type="string" value="" /> //! \endcode //! //! @param fileName Filename of the texture to load. @@ -150,7 +150,7 @@ //! //! <b>XML:</b> //! \code - //! <useAlphaColor value="" /> + //! <useAlphaColor type="bool" value="" /> //! \endcode //! //! @param value Value to enable or disble this option. @@ -170,10 +170,13 @@ //! @note For internal use only! void onTexture(void *p); - // XML - //! Parses for a ImageComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-22 20:42:18
|
Revision: 154 http://sirrf.svn.sourceforge.net/sirrf/?rev=154&view=rev Author: zccdark203 Date: 2009-11-22 20:42:09 +0000 (Sun, 22 Nov 2009) Log Message: ----------- Continued with the component's migration to our new serialization system. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/AnimatedMeshComponent.cpp trunk/src/components/scene/BillboardComponent.cpp trunk/src/components/scene/CameraComponent.cpp trunk/src/components/scene/CameraComponent.h trunk/src/components/scene/LightComponent.cpp trunk/src/components/scene/MeshComponent.cpp trunk/src/components/scene/OctTreeComponent.cpp trunk/src/components/scene/ParticleSysComponent.cpp trunk/src/components/scene/SceneComponent.cpp trunk/src/components/scene/SceneComponent.h trunk/src/components/scene/SkyBoxComponent.cpp trunk/src/components/scene/SkyDomeComponent.cpp trunk/src/components/scene/TerrainComponent.cpp trunk/src/core/Entity.cpp Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/components.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -28,13 +28,11 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(CameraComponent::parseXML); parsers.push_back(ImageComponent::parseXML); parsers.push_back(LightComponent::parseXML); parsers.push_back(MeshComponent::parseXML); parsers.push_back(OctTreeComponent::parseXML); parsers.push_back(ParticleSysComponent::parseXML); - parsers.push_back(SceneComponent::parseXML); parsers.push_back(SkyBoxComponent::parseXML); parsers.push_back(SkyDomeComponent::parseXML); parsers.push_back(TerrainComponent::parseXML); Modified: trunk/src/components/scene/AnimatedMeshComponent.cpp =================================================================== --- trunk/src/components/scene/AnimatedMeshComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/AnimatedMeshComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -381,9 +381,6 @@ else if(stringw("transitionTime") == file->getNodeName()) component->setTransitionTime(file->getAttributeValueAsFloat(L"value")); - // Derived elements. - else SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/components/scene/BillboardComponent.cpp =================================================================== --- trunk/src/components/scene/BillboardComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/BillboardComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -101,6 +101,9 @@ // Create a root. SerializedAttributes *root = new SerializedAttributes(); + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); + // Serialize color. SerializedAttributes *color = new SerializedAttributes(); @@ -117,7 +120,7 @@ root->pushDimension2df("size", mBillboardSN->getSize()); // Add root to the given collection of attributes. - attributes->pushObject("BillBoardComponent", root); + attributes->pushObject("BillboardComponent", root); root->drop(); // Return @@ -134,6 +137,7 @@ return false; SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); rootAttribute->drop(); // We no longer need this attribute. Modified: trunk/src/components/scene/CameraComponent.cpp =================================================================== --- trunk/src/components/scene/CameraComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/CameraComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -225,108 +225,81 @@ mCameraAnimator = animMaya; } -// Parses for a CameraComponent. -bool CameraComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool CameraComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - CameraComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a CameraComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("CameraComponent") == file->getNodeName()) - { - // Initialise the component. - component = new CameraComponent(entity); - } - } + // Serialize SceneComponent elements. + SceneComponent::onSerialization(root); - if(component == NULL) - return false; + // Serialize attributes inherited from SceneComponent. + SceneComponent::onSerialization(root); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + // Serialize attributes. + root->pushFloat("aspectRatio", getAspectRatio()); + root->pushFloat("farValue", getFarValue()); + root->pushFloat("FOV", getFOV()); + root->pushFloat("nearValue", getNearValue()); + root->pushVector3df("target", getTarget()); + root->pushVector3df("upVector", getUpVector()); - // <isMainCamera> - if(stringw("asMainCamera") == file->getNodeName()) - component->setAsMainCamera(); + // Add root to the given collection of attributes. + attributes->pushObject("CameraComponent", root); + root->drop(); - // <aspectRatio> - else if(stringw("aspectRatio") == file->getNodeName()) - component->setAspectRatio(file->getAttributeValueAsFloat(L"value")); + // Return + return true; +} - // <farValue> - else if(stringw("farValue") == file->getNodeName()) - component->setFarValue(file->getAttributeValueAsFloat(L"value")); +// Deserializes this object. +bool CameraComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - // <FOV> - else if(stringw("FOV") == file->getNodeName()) - component->setFOV(file->getAttributeValueAsFloat(L"value")); + if(rootAttribute == NULL || rootAttribute->getName() != "CameraComponent") + return false; - // <farValue> - else if(stringw("nearValue") == file->getNodeName()) - component->setNearValue(file->getAttributeValueAsFloat(L"value")); + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // <target> - else if(stringw("target") == file->getNodeName()) - { - component->setTarget( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } + rootAttribute->drop(); // We no longer need this attribute. - // <upVector> - else if(stringw("upVector") == file->getNodeName()) - { - component->setUpVector( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Deserialize attributes + if(attribute->getName() == "SceneComponent") + { + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedAttribute = new SerializedAttributes(); + wrappedAttribute->pushAttribute(attribute); - // <FPSMode> - else if(stringw("FPSMode") == file->getNodeName()) - { - component->setFPSMode( file->getAttributeValueAsFloat(L"rotateSpeed"), - file->getAttributeValueAsFloat(L"moveSpeed"), - ( stringc(file->getAttributeValue(L"verticalMovement")) == "true" ) - ? true : false, - file->getAttributeValueAsFloat(L"jumpSpeed")); - } + // Deserialize the component. + SceneComponent::onDeserialization(wrappedAttribute); - // <MayaMode> - else if(stringw("MayaMode") == file->getNodeName()) - { - component->setMayaMode( file->getAttributeValueAsFloat(L"rotateSpeed"), - file->getAttributeValueAsFloat(L"zoomSpeed"), - file->getAttributeValueAsFloat(L"translationSpeed") ); - } + // Clean up. + wrappedAttribute->drop(); + } - // Derived elements. - else SceneComponent::parseBaseXML(file, component); + else if(attribute->getName() == "aspectRatio") setAspectRatio(attribute->getFloat()); + else if(attribute->getName() == "farValue") setFarValue(attribute->getFloat()); + else if(attribute->getName() == "FOV") setFOV(attribute->getFloat()); + else if(attribute->getName() == "nearValue") setNearValue(attribute->getFloat()); + else if(attribute->getName() == "target") setTarget(attribute->getVector3df()); + else if(attribute->getName() == "upVector") setUpVector(attribute->getVector3df()); - break; + // We no longer need a reference to the attribute. + attribute->drop(); + } - case io::EXN_ELEMENT_END: + // We no longer need a reference to the root. + root->drop(); - // </CameraComponent> - if(stringw("CameraComponent") == file->getNodeName()) - return true; - - break; - - default: - - break; - } - - } - - // The code should never get here. - return false; + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/CameraComponent.h =================================================================== --- trunk/src/components/scene/CameraComponent.h 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/CameraComponent.h 2009-11-22 20:42:09 UTC (rev 154) @@ -172,10 +172,13 @@ void setMayaMode(f32 rotateSpeed = -1500.0f, f32 zoomSpeed = 200.0f, f32 translationSpeed = 1500.0f); - // XML - //! Parses for a CameraComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); private: Modified: trunk/src/components/scene/LightComponent.cpp =================================================================== --- trunk/src/components/scene/LightComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/LightComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -150,9 +150,6 @@ else if(stringw("radius") == file->getNodeName()) component->setRadius(file->getAttributeValueAsFloat(L"value")); - // Derived elements. - else SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/components/scene/MeshComponent.cpp =================================================================== --- trunk/src/components/scene/MeshComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/MeshComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -178,8 +178,7 @@ case io::EXN_ELEMENT: // Derived elements. - if(!MeshComponent::parseBaseXML(file, component)) - SceneComponent::parseBaseXML(file, component); + MeshComponent::parseBaseXML(file, component); break; Modified: trunk/src/components/scene/OctTreeComponent.cpp =================================================================== --- trunk/src/components/scene/OctTreeComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/OctTreeComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -197,8 +197,7 @@ switch(file->getNodeType()) { // Derived elements. - if(!MeshComponent::parseBaseXML(file, component)) - SceneComponent::parseBaseXML(file, component); + MeshComponent::parseBaseXML(file, component); break; Modified: trunk/src/components/scene/ParticleSysComponent.cpp =================================================================== --- trunk/src/components/scene/ParticleSysComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/ParticleSysComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -1323,9 +1323,6 @@ lifeTimeMax, maxAngleDegrees, minStartSize, maxStartSize); } - // Derived elements. - else SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/components/scene/SceneComponent.cpp =================================================================== --- trunk/src/components/scene/SceneComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/SceneComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -444,403 +444,48 @@ mSceneNode->setMaterialTexture(layer, texture); } -// Parses for a SceneComponent. -bool SceneComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool SceneComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - SceneComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a SceneComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("SceneComponent") == file->getNodeName()) - { - // Initialise the component. - component = new SceneComponent(entity); - } - } + // Serialize attributes. - if(component == NULL) - return false; + // Add root to the given collection of attributes. + attributes->pushObject("SceneComponent", root); + root->drop(); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: - - // Derived elements. - SceneComponent::parseBaseXML(file, component); - - break; - - case io::EXN_ELEMENT_END: - - // </SceneComponent> - if(stringw("SceneComponent") == file->getNodeName()) - return true; - - break; - - default: - - break; - } - - } - - // The code should never get here. - return false; + // Return + return true; } -// Parses for the base elements of a SceneComponent. -void SceneComponent::parseBaseXML(IXMLReader *file, SceneComponent *component) +// Deserializes this object. +bool SceneComponent::onDeserialization(SerializedAttributes *attributes) { - // <CollisionResponseAnimator> - if(stringw("CollisionResponseAnimator") == file->getNodeName()) - { - // Retrieve required variables from internal loop. - vector3df ellipsoidRadius; - vector3df gravityPerSecond; - vector3df ellipsoidTranslation; - f32 slidingValue; + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - bool doneParsing = false; + if(rootAttribute == NULL || rootAttribute->getName() != "SceneComponent") + return false; - while(file->read() && !doneParsing) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); - // <ellipsoidRadius> - if(stringw("ellipsoidRadius") == file->getNodeName()) - { - ellipsoidRadius = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } + rootAttribute->drop(); // We no longer need this attribute. - // <gravityPerSecond> - else if(stringw("gravityPerSecond") == file->getNodeName()) - { - gravityPerSecond = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - // <ellipsoidTranslation> - else if(stringw("ellipsoidTranslation") == file->getNodeName()) - { - ellipsoidTranslation = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - // <slidingValue> - else if(stringw("slidingValue") == file->getNodeName()) - slidingValue = file->getAttributeValueAsFloat(L"value"); - - break; - - case io::EXN_ELEMENT_END: - - // </CollisionRespondAnimator> - if(stringw("CollisionRespondAnimator") == file->getNodeName()) - doneParsing = true; - - break; - - default: - - break; - } - } - - // We create the animator. - component->addCollisionResponseAnimator(ellipsoidRadius, gravityPerSecond, - ellipsoidTranslation, slidingValue); - } - - // <FlyCircleAnimator> - else if(stringw("FlyCircleAnimator") == file->getNodeName()) + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) { - // Retrieve required variables from internal loop. - vector3df center; - f32 radius; - f32 speed; - vector3df direction; - - bool doneParsing = false; - - while(file->read() && !doneParsing) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: - - // <center> - if(stringw("center") == file->getNodeName()) - { - center = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - // <radius> - else if(stringw("radius") == file->getNodeName()) - radius = file->getAttributeValueAsFloat(L"value"); - - // <slidingValue> - else if(stringw("speed") == file->getNodeName()) - speed = file->getAttributeValueAsFloat(L"value"); - - // <direction> - else if(stringw("direction") == file->getNodeName()) - { - direction = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - break; - - case io::EXN_ELEMENT_END: - - // </FlyCircleAnimator> - if(stringw("FlyCircleAnimator") == file->getNodeName()) - doneParsing = true; - - break; - - default: - - break; - } - } - - // We create the animator. - component->addFlyCircleAnimator(center, radius, speed, direction); + // We no longer need a reference to the attribute. + attribute->drop(); } - // <FlyStraightAnimator> - else if(stringw("FlyStraightAnimator") == file->getNodeName()) - { - // Retrieve required variables from internal loop. - vector3df startPoint; - vector3df endPoint; - u32 timeForWay; - bool loop; + // We no longer need a reference to the root. + root->drop(); - bool doneParsing = false; - - while(file->read() && !doneParsing) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: - - // <startPoint> - if(stringw("startPoint") == file->getNodeName()) - { - startPoint = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - // <endPoint> - else if(stringw("endPoint") == file->getNodeName()) - { - endPoint = vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ); - } - - // <timeForWay> - else if(stringw("timeForWay") == file->getNodeName()) - timeForWay = (u32)file->getAttributeValueAsInt(L"timeForWay"); - - // <slidingValue> - else if(stringw("slidingValue") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - loop = (value == "true") ? true : false ; - } - - break; - - case io::EXN_ELEMENT_END: - - // </FlyStraightAnimator> - if(stringw("FlyStraightAnimator") == file->getNodeName()) - doneParsing = true; - - break; - - default: - - break; - } - } - - // We create the animator. - component->addFlyStraightAnimator(startPoint, endPoint, timeForWay, loop); - } - - // <absolutePosition> - else if(stringw("absolutePosition") == file->getNodeName()) - { - component->setAbsolutePosition( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } - - // <automaticCulling> - else if(stringw("automaticCulling") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - E_CULLING_TYPE type; - -#define retrieveCullingType(x) \ -else if(value == #x) \ - type = x - - if(value == "") - type = EAC_OFF; // Dummy behaviour. - - retrieveCullingType(EAC_OFF); - retrieveCullingType(EAC_BOX); - retrieveCullingType(EAC_FRUSTUM_BOX); - retrieveCullingType(EAC_FRUSTUM_SPHERE); - -#undef retrieveCullingType - - component->setAutomaticCulling(type); - } - - // <canAffectParent> - else if(stringw("canAffectParent") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setCanAffectParent( (value == "true") ? true : false ); - } - - // <materialFlag> - else if(stringw("materialFlag") == file->getNodeName()) - { - stringc materialFlag = file->getAttributeValue(L"flag"); - E_MATERIAL_FLAG flag; - -#define retrieveMaterialFlag(x) \ -else if(materialFlag == #x) \ - flag = x - - if(materialFlag == "") - flag = EMF_WIREFRAME; // Dummy behaviour. - - retrieveMaterialFlag(EMF_WIREFRAME); - retrieveMaterialFlag(EMF_POINTCLOUD); - retrieveMaterialFlag(EMF_GOURAUD_SHADING); - retrieveMaterialFlag(EMF_LIGHTING); - retrieveMaterialFlag(EMF_ZBUFFER); - retrieveMaterialFlag(EMF_ZWRITE_ENABLE); - retrieveMaterialFlag(EMF_BACK_FACE_CULLING); - retrieveMaterialFlag(EMF_FRONT_FACE_CULLING); - retrieveMaterialFlag(EMF_BILINEAR_FILTER); - retrieveMaterialFlag(EMF_TRILINEAR_FILTER); - retrieveMaterialFlag(EMF_ANISOTROPIC_FILTER); - retrieveMaterialFlag(EMF_FOG_ENABLE); - retrieveMaterialFlag(EMF_NORMALIZE_NORMALS); - retrieveMaterialFlag(EMF_TEXTURE_WRAP); - -#undef retrieveMaterialFlag - - stringc value = file->getAttributeValue(L"value"); - - component->setMaterialFlag(flag, (value == "true") ? true : false ); - } - - // <materialTexture> - else if(stringw("materialTexture") == file->getNodeName()) - { - stringc fileName = file->getAttributeValue(L"fileName"); - component->setMaterialTexture(file->getAttributeValueAsInt(L"layer"), fileName.c_str()); - } - - // <materialType> - else if(stringw("materialType") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - E_MATERIAL_TYPE type; - -#define retrieveMaterialType(x) \ -else if(value == #x) \ - type = x - - if(value == "") - type = EMT_SOLID; // Dummy behaviour. - - retrieveMaterialType(EMT_SOLID); - retrieveMaterialType(EMT_SOLID_2_LAYER); - retrieveMaterialType(EMT_LIGHTMAP); - retrieveMaterialType(EMT_LIGHTMAP_ADD); - retrieveMaterialType(EMT_LIGHTMAP_M2); - retrieveMaterialType(EMT_LIGHTMAP_M4); - retrieveMaterialType(EMT_LIGHTMAP_LIGHTING); - retrieveMaterialType(EMT_LIGHTMAP_LIGHTING_M2); - retrieveMaterialType(EMT_LIGHTMAP_LIGHTING_M4); - retrieveMaterialType(EMT_DETAIL_MAP); - retrieveMaterialType(EMT_SPHERE_MAP); - retrieveMaterialType(EMT_REFLECTION_2_LAYER); - retrieveMaterialType(EMT_TRANSPARENT_ADD_COLOR); - retrieveMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL); - retrieveMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL_REF); - retrieveMaterialType(EMT_TRANSPARENT_VERTEX_ALPHA); - retrieveMaterialType(EMT_TRANSPARENT_REFLECTION_2_LAYER); - retrieveMaterialType(EMT_NORMAL_MAP_SOLID); - retrieveMaterialType(EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR); - retrieveMaterialType(EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA); - retrieveMaterialType(EMT_PARALLAX_MAP_SOLID); - retrieveMaterialType(EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR); - retrieveMaterialType(EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA); - retrieveMaterialType(EMT_ONETEXTURE_BLEND); - -#undef retrieveMaterialType - - component->setMaterialType(type); - } - - // <position> - else if(stringw("position") == file->getNodeName()) - { - component->setPosition( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } - - // <rotation> - else if(stringw("rotation") == file->getNodeName()) - { - component->setRotation( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } - - // <scale> - else if(stringw("scale") == file->getNodeName()) - { - component->setScale( vector3df(file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") ) ); - } - - // <visisble> - else if(stringw("visible") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setVisible( (value == "true") ? true : false ); - } + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/SceneComponent.h =================================================================== --- trunk/src/components/scene/SceneComponent.h 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/SceneComponent.h 2009-11-22 20:42:09 UTC (rev 154) @@ -284,13 +284,13 @@ //! @note For internal use only! void onTexture(void *p); - // XML - //! Parses for a SceneComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); - //! Parses for the base elements of a SceneComponent. - //! @note For internal use only! - static void parseBaseXML(IXMLReader *file, SceneComponent *component); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); protected: Modified: trunk/src/components/scene/SkyBoxComponent.cpp =================================================================== --- trunk/src/components/scene/SkyBoxComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/SkyBoxComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -240,9 +240,6 @@ front.c_str(), back.c_str(), false); } - // Derived elements. - else SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/components/scene/SkyDomeComponent.cpp =================================================================== --- trunk/src/components/scene/SkyDomeComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/SkyDomeComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -102,9 +102,6 @@ { case io::EXN_ELEMENT: - // Derived elements. - SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/components/scene/TerrainComponent.cpp =================================================================== --- trunk/src/components/scene/TerrainComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/components/scene/TerrainComponent.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -205,9 +205,6 @@ file->getAttributeValueAsFloat(L"scale2")); } - // Derived elements. - else SceneComponent::parseBaseXML(file, component); - break; case io::EXN_ELEMENT_END: Modified: trunk/src/core/Entity.cpp =================================================================== --- trunk/src/core/Entity.cpp 2009-11-15 20:26:04 UTC (rev 153) +++ trunk/src/core/Entity.cpp 2009-11-22 20:42:09 UTC (rev 154) @@ -555,6 +555,7 @@ return false; SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + root->grab(); rootAttribute->drop(); // We no longer need this attribute. @@ -571,9 +572,6 @@ // Convert to a collection of attributes. SerializedAttributes *components = reinterpret_cast<SerializedAttributes*>(attribute->getObject()); - // Predeclaration of needed variables. - SColor topColor, bottomColor; - // Process all attributes in the components collection. for(SerializedAttribute *innerAttribute = components->pullAttribute(); innerAttribute != NULL; innerAttribute = components->pullAttribute()) { @@ -592,6 +590,7 @@ // Clean up. wrappedComponent->drop(); + component->drop(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-15 20:26:11
|
Revision: 153 http://sirrf.svn.sourceforge.net/sirrf/?rev=153&view=rev Author: zccdark203 Date: 2009-11-15 20:26:04 +0000 (Sun, 15 Nov 2009) Log Message: ----------- NOTE: This revision is not advised for use in productive environments, only update for testing and Sirrf development! I made various changes to Sirrf's serialization system. Most noticeable is the change that the Serializable class now inherits from the ReferenceCounted class. This change makes it a lot easier to manage the memory of the serialization system. Furthermore I've started with making Sirrf's entity system serializable. As a result parsing XML-files for entities is currently broken. This feature will be back up as soon as all components have been made serializable. Modified Paths: -------------- trunk/src/components/components.cpp trunk/src/components/scene/BillboardComponent.cpp trunk/src/components/scene/BillboardComponent.h trunk/src/components/scene/TextBillboardComponent.cpp trunk/src/components/scene/TextBillboardComponent.h trunk/src/core/Entity.cpp trunk/src/core/Entity.h trunk/src/core/EntityComponent.cpp trunk/src/core/EntityComponent.h trunk/src/core/Serializable.cpp trunk/src/core/Serializable.h trunk/src/core/SerializedAttributes.h trunk/src/core/SerializedAttributesImpl.cpp Modified: trunk/src/components/components.cpp =================================================================== --- trunk/src/components/components.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/components/components.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -28,7 +28,6 @@ std::vector<bool (*)(IXMLReader*, Entity*)> parsers; parsers.push_back(AnimatedMeshComponent::parseXML); - parsers.push_back(BillboardComponent::parseXML); parsers.push_back(CameraComponent::parseXML); parsers.push_back(ImageComponent::parseXML); parsers.push_back(LightComponent::parseXML); @@ -39,7 +38,6 @@ parsers.push_back(SkyBoxComponent::parseXML); parsers.push_back(SkyDomeComponent::parseXML); parsers.push_back(TerrainComponent::parseXML); - parsers.push_back(TextBillboardComponent::parseXML); #ifdef __COMPILE_WITH_SFML_AUDIO__ parsers.push_back(SoundListenerComponent::parseXML); Modified: trunk/src/components/scene/BillboardComponent.cpp =================================================================== --- trunk/src/components/scene/BillboardComponent.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/components/scene/BillboardComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -95,99 +95,92 @@ mBillboardSN->setSize(size); } -// Parses for a BillboardComponent. -bool BillboardComponent::parseXML(IXMLReader *file, Entity *entity) +// Serializes this object. +bool BillboardComponent::onSerialization(SerializedAttributes *attributes) { - // Forward declaration. - BillboardComponent *component = NULL; + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); - // Are we dealing with a BillboardComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("BillboardComponent") == file->getNodeName()) - { - // Initialise the component. - component = new BillboardComponent(entity); - } - } + // Serialize color. + SerializedAttributes *color = new SerializedAttributes(); - if(component == NULL) - return false; + SColor topColor, bottomColor; + mBillboardSN->getColor(topColor, bottomColor); - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: + color->pushColor("top", topColor); + color->pushColor("bottom", bottomColor); - // Derived elements. - if(!BillboardComponent::parseBaseXML(file, component)) - SceneComponent::parseBaseXML(file, component); + root->pushObject("color", color); + color->drop(); - break; + // Serialize size. + root->pushDimension2df("size", mBillboardSN->getSize()); - case io::EXN_ELEMENT_END: + // Add root to the given collection of attributes. + attributes->pushObject("BillBoardComponent", root); + root->drop(); - // </BillboardComponent> - if(stringw("BillboardComponent") == file->getNodeName()) - return true; + // Return + return true; +} - break; +// Deserializes this object. +bool BillboardComponent::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); - default: + if(rootAttribute == NULL || rootAttribute->getName() != "BillboardComponent") + return false; - break; - } + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); - } + rootAttribute->drop(); // We no longer need this attribute. - // The code should never get here. - return false; -} - -// Parses for the base elements of a BillboardComponent. -bool BillboardComponent::parseBaseXML(IXMLReader *file, BillboardComponent *component) -{ - // <color> - if(stringw("color") == file->getNodeName()) + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) { - if(stringw("") != file->getAttributeValue(L"overallR")) + // Color attribute + if(attribute->getName() == "color") { - component->setColor( SColor( file->getAttributeValueAsInt(L"overallA"), - file->getAttributeValueAsInt(L"overallR"), - file->getAttributeValueAsInt(L"overallG"), - file->getAttributeValueAsInt(L"overallB") ) ); + // Convert to a collection of attributes. + SerializedAttributes *color = reinterpret_cast<SerializedAttributes*>(attribute->getObject()); - return true; - } + // Predeclaration of needed variables. + SColor topColor, bottomColor; - else - { - component->setColor( SColor( file->getAttributeValueAsInt(L"topA"), - file->getAttributeValueAsInt(L"topR"), - file->getAttributeValueAsInt(L"topG"), - file->getAttributeValueAsInt(L"topB") ), - SColor( file->getAttributeValueAsInt(L"bottomA"), - file->getAttributeValueAsInt(L"bottomR"), - file->getAttributeValueAsInt(L"bottomG"), - file->getAttributeValueAsInt(L"bottomB") ) ); + // Process all attributes in the color collection. + for(SerializedAttribute *innerAttribute = color->pullAttribute(); innerAttribute != NULL; innerAttribute = color->pullAttribute()) + { + // Top attribute. + if(innerAttribute->getName() == "top") + { + topColor = innerAttribute->getColor(); + setColor(topColor, bottomColor); + } - return true; + // Bottom attribute. + if(innerAttribute->getName() == "bottom") + { + bottomColor = innerAttribute->getColor(); + setColor(topColor, bottomColor); + } + } } - } - // <size> - else if(stringw("size") == file->getNodeName()) - { - component->setSize(dimension2df( file->getAttributeValueAsFloat(L"width"), - file->getAttributeValueAsFloat(L"height") ) ); + // Size attribute + else if(attribute->getName() == "size") + setSize(attribute->getDimension2df()); - return true; + // We no longer need a reference to the attribute. + attribute->drop(); } - // We couldn't find any known elements. - return false; + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; } // End of File Modified: trunk/src/components/scene/BillboardComponent.h =================================================================== --- trunk/src/components/scene/BillboardComponent.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/components/scene/BillboardComponent.h 2009-11-15 20:26:04 UTC (rev 153) @@ -23,13 +23,6 @@ // BillboardComponent class //! Component wrapper of Irrlicht's IBillboardSceneNode. -//! -//! <b>XML:</b> -//! \code -//! <BillboardComponent> -//! <!-- Properties --> -//! </BillboardComponent> -//! \endcode class BillboardComponent : public SceneComponent { public: @@ -59,43 +52,24 @@ const dimension2df& getSize() const; //! Sets the color of all vertices of the billboard. - //! - //! <b>XML:</b> - //! \code - //! <color overallA="" overallR="" overallG="" overallB="" /> - //! \endcode - //! //! @param overallColor The color to set. void setColor(const SColor &overallColor); //! Sets the color of the top and bottom vertices of the billboard. - //! - //! <b>XML:</b> - //! \code - //! <color topA="" topR="" topG="" topB="" bottomA="" bottomR="" bottomG="" bottomB=""/> - //! \endcode - //! //! @param topColor The color to set the top vertices. //! @param bottomColor The color to set the bottom vertices. void setColor(const SColor &topColor, const SColor &bottomColor); //! Sets the size of the billboard. - //! - //! <b>XML:</b> - //! \code - //! <size width="" height=""/> - //! \endcode - //! //! @param size Size of the billboard. void setSize(const dimension2df &size); - //! Parses for a BillboardComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); - // XML - //! Parses for the base elements of a BillboardComponent. - //! @note For internal use only! - static bool parseBaseXML(IXMLReader *file, BillboardComponent *component); - protected: // Initialisation Modified: trunk/src/components/scene/TextBillboardComponent.cpp =================================================================== --- trunk/src/components/scene/TextBillboardComponent.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/components/scene/TextBillboardComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -113,71 +113,4 @@ mBillboardTextSN->setTextColor(color); } -// Parses for a TextBillboardComponent. -bool TextBillboardComponent::parseXML(IXMLReader *file, Entity *entity) -{ - // Forward declaration. - TextBillboardComponent *component = NULL; - - // Are we dealing with a TextBillboardComponent? - if(file->getNodeType() == io::EXN_ELEMENT) - { - if(stringw("TextBillboardComponent") == file->getNodeName()) - { - // Initialise the component. - component = new TextBillboardComponent(entity); - } - } - - if(component == NULL) - return false; - - // Continue parsing the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: - - // <text> - if(stringw("text") == file->getNodeName()) - { - stringc value = file->getAttributeValue(L"value"); - component->setText(value.c_str()); - } - - // <textColor> - else if(stringw("textColor") == file->getNodeName()) - { - component->setColor( SColor( file->getAttributeValueAsInt(L"a"), - file->getAttributeValueAsInt(L"r"), - file->getAttributeValueAsInt(L"g"), - file->getAttributeValueAsInt(L"b") ) ); - } - - // Derived elements. - else if(!BillboardComponent::parseBaseXML(file, component)) - SceneComponent::parseBaseXML(file, component); - - break; - - case io::EXN_ELEMENT_END: - - // </TextBillboardComponent> - if(stringw("TextBillboardComponent") == file->getNodeName()) - return true; - - break; - - default: - - break; - } - - } - - // The code should never get here. - return false; -} - // End of File Modified: trunk/src/components/scene/TextBillboardComponent.h =================================================================== --- trunk/src/components/scene/TextBillboardComponent.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/components/scene/TextBillboardComponent.h 2009-11-15 20:26:04 UTC (rev 153) @@ -91,11 +91,6 @@ //! @param color New color of the text. void setTextColor(const SColor &color); - // XML - //! Parses for a TextBillboardComponent. - //! @note For internal use only! - static bool parseXML(IXMLReader *file, Entity *entity); - private: // Private methods Modified: trunk/src/core/Entity.cpp =================================================================== --- trunk/src/core/Entity.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/Entity.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -189,137 +189,6 @@ return mRotation; } -// Loads Entity data from a XML file. -bool Entity::loadXML(const std::string &fileName) -{ - // Get pointer to the File System of Irrlicht. - IFileSystem *fileSystem = GameManager::Instance()->getDevice()->getFileSystem(); - - // Does the file exist? - if(!fileSystem->existFile(fileName.c_str())) - return false; - - // Open the file. - IXMLReader *file = fileSystem->createXMLReader(fileName.c_str()); - - bool result = loadXML(file); - - file->drop(); - return result; -} - -// Loads Entity data from a XML file through a IXMLReader object. -bool Entity::loadXML(IXMLReader *file) -{ - // Did we get a valid pointer? - if(!file) - return false; - - // Read from the file. - while(file->read()) - { - switch(file->getNodeType()) - { - case io::EXN_ELEMENT: - - // <Entity> - if(stringw("Entity") == file->getNodeName()) - { - stringc parentFile = file->getAttributeValue(L"parent"); - - // Check the value we retrieved. - if(parentFile != "") - { - // Try to get a pointer to the parent. - Entity *retrievedParent = NULL; - - if(pAssetGroup != NULL) - { - EntityProcessor *processor = static_cast<EntityProcessor*> - (pAssetGroup->getAssetProcessor("entities")); - - retrievedParent = processor->getEntity(parentFile.c_str()); - } - - else - retrievedParent = GameManager::Instance()->getEntityManager()->getEntity(parentFile.c_str()); - - if(retrievedParent == NULL && pAssetGroup == NULL) - { - if(GameManager::Instance()->getEntityManager()->getEntity(mName) != NULL) - { - retrievedParent = GameManager::Instance()->getEntityManager()-> - createEntityFromXML(parentFile.c_str()); - } - - else - { - retrievedParent = GameManager::Instance()->getEntityManager()-> - createEntityFromXML(parentFile.c_str(), NULL, NULL, false); - } - } - - // Set parent, if available. - if(retrievedParent != NULL) - setParent(retrievedParent); - } - } - - // <absolutePosition> - if(stringw("absolutePosition") == file->getNodeName()) - { - setAbsolutePosition(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <position> - else if(stringw("position") == file->getNodeName()) - { - setPosition(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <absoluteRotation> - else if(stringw("absoluteRotation") == file->getNodeName()) - { - setAbsoluteRotation(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <rotation> - else if(stringw("rotation") == file->getNodeName()) - { - setRotation(vector3df( file->getAttributeValueAsFloat(L"x"), - file->getAttributeValueAsFloat(L"y"), - file->getAttributeValueAsFloat(L"z") )); - } - - // <components> - else if(stringw("components") == file->getNodeName()) - parseComponentsXML(file, this); - - break; - - case io::EXN_ELEMENT_END: - - // </Entityr> - if(stringw("Entity") == file->getNodeName()) - return true; - - break; - - default: - break; - } - } - - // The code shouldn't get here. - return false; -} - // Removes all children. void Entity::removeChildren() { @@ -639,4 +508,103 @@ emitEvent("onUnPause", p); } +// Serializes this object. +bool Entity::onSerialization(SerializedAttributes *attributes) +{ + // Create a root. + SerializedAttributes *root = new SerializedAttributes(); + + // Serialize name. + root->pushString("name", mName); + + // Serialize children. + SerializedAttributes *children = new SerializedAttributes(); + + vector<Entity*>::iterator itChildren; + for(itChildren = mChildren.begin(); itChildren < mChildren.end(); itChildren++) + children->pushObject("", *itChildren); + + root->pushObject("Children", children); + children->drop(); + + // Serialize components. + SerializedAttributes *components = new SerializedAttributes(); + + vector<EntityComponent*>::iterator itComponents; + for(itComponents = mComponents.begin(); itComponents < mComponents.end(); itComponents++) + components->pushObject("", *itComponents); + + root->pushObject("Components", components); + components->drop(); + + // Add root to the given collection of attributes. + attributes->pushObject("Entity", root); + root->drop(); + + // Return + return true; +} + +// Deserializes this object. +bool Entity::onDeserialization(SerializedAttributes *attributes) +{ + // Retrieve root attribute from the collection. + SerializedAttribute *rootAttribute = attributes->pullAttribute(); + + if(rootAttribute == NULL || rootAttribute->getName() != "Entity") + return false; + + SerializedAttributes *root = reinterpret_cast<SerializedAttributes*>(rootAttribute->getObject()); + + rootAttribute->drop(); // We no longer need this attribute. + + // Process all attributes in the root collection. + for(SerializedAttribute *attribute = root->pullAttribute(); attribute != NULL; attribute = root->pullAttribute()) + { + // Name attribute + if(attribute->getName() == "name") + mName = attribute->getString(); + + // Size attribute + else if(attribute->getName() == "Components") + { + // Convert to a collection of attributes. + SerializedAttributes *components = reinterpret_cast<SerializedAttributes*>(attribute->getObject()); + + // Predeclaration of needed variables. + SColor topColor, bottomColor; + + // Process all attributes in the components collection. + for(SerializedAttribute *innerAttribute = components->pullAttribute(); innerAttribute != NULL; innerAttribute = components->pullAttribute()) + { + // Top attribute. + if(innerAttribute->getName() == "BillboardComponent") + { + // Create the component. + BillboardComponent *component = new BillboardComponent(this); + + // Rewrap attribute so that it can be deserialized properly. + SerializedAttributes *wrappedComponent = new SerializedAttributes(); + wrappedComponent->pushAttribute(innerAttribute); + + // Deserialize the component. + component->onDeserialization(wrappedComponent); + + // Clean up. + wrappedComponent->drop(); + } + } + } + + // We no longer need a reference to the attribute. + attribute->drop(); + } + + // We no longer need a reference to the root. + root->drop(); + + // We're done. + return true; +} + // End of File Modified: trunk/src/core/Entity.h =================================================================== --- trunk/src/core/Entity.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/Entity.h 2009-11-15 20:26:04 UTC (rev 153) @@ -18,10 +18,10 @@ // Include files #include "../dependencies.h" -#include "ReferenceCounted.h" #include "AssetGroup.h" #include "HasEvents.h" #include "EntityComponent.h" +#include "Serializable.h" // Forward declarations class EntityComponent; @@ -39,7 +39,7 @@ //! </Components> //! </Entity> //! \endcode -class Entity : public ReferenceCounted, public HasEvents, public HasSlots +class Entity : public HasEvents, public HasSlots, public Serializable { public: @@ -98,13 +98,6 @@ //! Gets the rotation of the entity. const vector3df& getRotation() const; - //! Loads Entity data from a XML file. - //! @param fileName Filename of the file where the data is retrieved from. - bool loadXML(const std::string &fileName); - //! Loads Entity data from a XML file through a IXMLReader object. - //! @param file Pointer to the IXMLReader object that will be used. - bool loadXML(IXMLReader *file); - //! Removes all children. void removeChildren(); //! Removes all components. @@ -197,6 +190,14 @@ //! @note For internal use only! void onUnPause(void *p); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); + private: // Static members Modified: trunk/src/core/EntityComponent.cpp =================================================================== --- trunk/src/core/EntityComponent.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/EntityComponent.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -68,4 +68,14 @@ return pParent; } +// Serializes this object. +bool EntityComponent::onSerialization(SerializedAttributes *attributes) +{ +} + +// Deserializes this object. +bool EntityComponent::onDeserialization(SerializedAttributes *attributes) +{ +} + // End of File Modified: trunk/src/core/EntityComponent.h =================================================================== --- trunk/src/core/EntityComponent.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/EntityComponent.h 2009-11-15 20:26:04 UTC (rev 153) @@ -18,7 +18,7 @@ // Include files #include "../dependencies.h" -#include "ReferenceCounted.h" +#include "Serializable.h" #include "Entity.h" // Forward declarations @@ -27,7 +27,7 @@ // EntityComponent class //! Abstraction base class for adding new functionalities to entities. -class EntityComponent : public ReferenceCounted, public HasSlots +class EntityComponent : public HasSlots, public Serializable { friend class ScriptedEntityComponent; @@ -49,6 +49,14 @@ //! Gets the parent of this component. const Entity* getParent(); + // Serialization + //! Serializes this object. + //! @param attributes + virtual bool onSerialization(SerializedAttributes *attributes); + //! Deserializes this object. + //! @param attributes + virtual bool onDeserialization(SerializedAttributes *attributes); + protected: // Normal members Modified: trunk/src/core/Serializable.cpp =================================================================== --- trunk/src/core/Serializable.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/Serializable.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -60,7 +60,7 @@ bool Serializable::loadXML(IXMLReader *file) { // Check if we got a valid pointer. - if(file != NULL) + if(file == NULL) return false; // Create a SerializedAttributes object to hold our attributes. @@ -73,17 +73,19 @@ { case io::EXN_ELEMENT: + // Check how many attributes the current node has. + // In case the current node has zero nodes, it indicates that it is an serialized object. if(file->getAttributeCount() == 0) { SerializedAttributes *object = new SerializedAttributes(); - - SerializedAttribute *attribute = new SerializedObject(stringc(file->getNodeName()).c_str(), object); - attributes->pushAttribute(attribute); - attribute->drop(); - object->loadXML(file); + + attributes->pushObject(stringc(file->getNodeName()).c_str(), object); + object->drop(); } + // In case the current node has more than zero nodes, it indicates that we're dealing + // with a "normal" serialized value. else { SerializedAttribute *attribute = parseAttribute( stringc(file->getNodeName()).c_str(), @@ -103,19 +105,6 @@ bool success = onDeserialization(attributes); // Clean up and return whether we've been successful or not. - // Please note that we don't rely on SerializedAttributes' internal removeAttributes method, - // because our SerializedAttributes might contain SerializedObject's which might contain - // pointers to resources that need to be released. - while(!attributes->isEmpty()) - { - SerializedAttribute *attribute = attributes->pullAttribute(); - - if(attribute->getObject() != NULL) - delete attribute->getObject(); - - attribute->drop(); - } - attributes->drop(); return success; @@ -133,19 +122,6 @@ bool success = onDeserialization(attributes); // Clean up and return whether we've been successful or not. - // Please note that we don't rely on SerializedAttributes' internal removeAttributes method, - // because our SerializedAttributes might contain SerializedObject's which might contain - // pointers to resources that need to be released. - while(!attributes->isEmpty()) - { - SerializedAttribute *attribute = attributes->pullAttribute(); - - if(attribute->getObject() != NULL) - delete attribute->getObject(); - - attribute->drop(); - } - attributes->drop(); return success; Modified: trunk/src/core/Serializable.h =================================================================== --- trunk/src/core/Serializable.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/Serializable.h 2009-11-15 20:26:04 UTC (rev 153) @@ -24,6 +24,7 @@ // Include files #include "../dependencies.h" +#include "ReferenceCounted.h" // Forward declarations @@ -35,7 +36,7 @@ //! The Serializable class provides a base for classes that need serialization. //! By deriving from this class, the derived class gains all required methods //! for serialization. -class Serializable +class Serializable : public ReferenceCounted { public: Modified: trunk/src/core/SerializedAttributes.h =================================================================== --- trunk/src/core/SerializedAttributes.h 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/SerializedAttributes.h 2009-11-15 20:26:04 UTC (rev 153) @@ -29,7 +29,7 @@ // SerializedAttributes class //! The SerializaedAttributes class describes a FIFO collection of serialized //! attributes. This class provides various methods to manage these attributes. -class SerializedAttributes : public ReferenceCounted, public Serializable +class SerializedAttributes : public Serializable { public: Modified: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp 2009-11-15 16:01:30 UTC (rev 152) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-15 20:26:04 UTC (rev 153) @@ -482,14 +482,16 @@ // SerializedObject class // SerializedObject constructor. SerializedObject::SerializedObject(const std::string &name, Serializable *object) -: SerializedAttribute(name, "object") +: SerializedAttribute(name, "object"), mObject(NULL) { - mObject = object; + setObject(object); } // SerializedObject deconstructor. SerializedObject::~SerializedObject() { + if(mObject != NULL) + mObject->drop(); } Serializable* SerializedObject::getObject() @@ -499,7 +501,13 @@ void SerializedObject::setObject(Serializable *object) { + if(mObject != NULL) + mObject->drop(); + mObject = object; + + if(mObject != NULL) + mObject->grab(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-15 16:01:39
|
Revision: 152 http://sirrf.svn.sourceforge.net/sirrf/?rev=152&view=rev Author: zccdark203 Date: 2009-11-15 16:01:30 +0000 (Sun, 15 Nov 2009) Log Message: ----------- Finished the implementation of Sirrf's serialization system. Classes that require serialization should inherit from the Serializable class and reimplement the required methods. Furthermore I've added some missing methods to the AngelScript binding of the Entity class. Modified Paths: -------------- trunk/CHANGES trunk/src/core/SerializedAttribute.cpp trunk/src/core/SerializedAttribute.h trunk/src/core/SerializedAttributesImpl.cpp trunk/src/core/SerializedAttributesImpl.h trunk/src/scripting/core/asEntity.cpp trunk/src/scripting/core/asGameState.cpp Modified: trunk/CHANGES =================================================================== --- trunk/CHANGES 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/CHANGES 2009-11-15 16:01:30 UTC (rev 152) @@ -2,6 +2,17 @@ Sirrf version 0.3.0 (SVN) - Changes ========================================================================== + * Implemenented a serialization system. Any class that requires + serialization needs to inherit from the Serializable class and + reimplement the required methods (onSerialization, onDeserialization). + + * Added missing methods to the AngelScript binding of the Entity class: + + * getAbsolutePosition + * getAbsoluteRotation + * getPosition + * getRotation + * Made the HasSlots typedef for sigslot::has_slots. * Updated to Irrlicht 1.6 and AngelScript 2.17.2. Modified: trunk/src/core/SerializedAttribute.cpp =================================================================== --- trunk/src/core/SerializedAttribute.cpp 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/core/SerializedAttribute.cpp 2009-11-15 16:01:30 UTC (rev 152) @@ -71,7 +71,7 @@ while(tempString.find(",") != std::string::npos) tempString.replace(tempString.find(","), 1, " "); - ss2 << tempString; + ss2 << tempString << " "; } // Return the new stringstream. Modified: trunk/src/core/SerializedAttribute.h =================================================================== --- trunk/src/core/SerializedAttribute.h 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/core/SerializedAttribute.h 2009-11-15 16:01:30 UTC (rev 152) @@ -38,53 +38,53 @@ const std::string& getType() const; //! Returns the value of this attribute as an aabbox3df. - virtual aabbox3df getAabbox3df() const { return aabbox3df(); }; + virtual aabbox3df getAabbox3df() { return aabbox3df(); }; //! Returns the value of this attribute as an aabbox3di. - virtual aabbox3di getAabbox3di() const { return aabbox3di(); }; + virtual aabbox3di getAabbox3di() { return aabbox3di(); }; //! Returns the value of this attribute as an bool. - virtual bool getBool() const { return false; } + virtual bool getBool() { return false; } //! Returns the value of this attribute as a SColor. - virtual SColor getColor() const { return SColor(255, 255, 255, 255); }; + virtual SColor getColor() { return SColor(255, 255, 255, 255); }; //! Returns the value of this attribute as a SColorf. - virtual SColorf getColorf() const { return SColorf(1.0f, 1.0f, 1.0f, 1.0f); }; + virtual SColorf getColorf() { return SColorf(1.0f, 1.0f, 1.0f, 1.0f); }; //! Returns the value of this attribute as a dimension2df. - virtual dimension2df getDimension2df() const { return dimension2df(); }; + virtual dimension2df getDimension2df() { return dimension2df(); }; //! Returns the value of this attribute as a dimension2di. - virtual dimension2di getDimension2di() const { return dimension2di(); }; + virtual dimension2di getDimension2di() { return dimension2di(); }; //! Returns the value of this attribute as a float. - virtual f32 getFloat() const { return 0.0f; }; + virtual f32 getFloat() { return 0.0f; }; //! Returns the value of this attribute as an integer. - virtual s32 getInt() const { return 0; }; + virtual s32 getInt() { return 0; }; //! Returns the value of this attribute as a line2df. - virtual line2df getLine2df() const { return line2df(); }; + virtual line2df getLine2df() { return line2df(); }; //! Returns the value of this attribute as a line2di. - virtual line2di getLine2di() const { return line2di(); }; + virtual line2di getLine2di() { return line2di(); }; //! Returns the value of this attribute as a line3df. - virtual line3df getLine3df() const { return line3df(); }; + virtual line3df getLine3df() { return line3df(); }; //! Returns the value of this attribute as a line3di. - virtual line3di getLine3di() const { return line3di(); }; + virtual line3di getLine3di() { return line3di(); }; //! Returns the value of this attribute as a Serializable object. - virtual Serializable* getObject() const { return NULL; } + virtual Serializable* getObject() { return NULL; } //! Returns the value of this attribute as a plane3df. - virtual plane3df getPlane3df() const { return plane3df(); }; + virtual plane3df getPlane3df() { return plane3df(); }; //! Returns the value of this attribute as a plane3di. - virtual plane3di getPlane3di() const { return plane3di(); }; + virtual plane3di getPlane3di() { return plane3di(); }; //! Returns the value of this attribute as a quaternion. - virtual quaternion getQuaternion() const { return quaternion(); }; + virtual quaternion getQuaternion() { return quaternion(); }; //! Returns the value of this attribute as a rect<s32>. - virtual rect<s32> getRect() const { return rect<s32>(); }; + virtual rect<s32> getRect() { return rect<s32>(); }; //! Returns the value of this attribute as a string. - virtual std::string getString() const { return std::string(""); }; + virtual std::string getString() { return std::string(""); }; //! Returns the value of this attribute as a wide string. - virtual stringw getStringW() const { return stringw( stringc( getString().c_str() ).c_str() ); }; + virtual stringw getStringW() { return stringw( stringc( getString().c_str() ).c_str() ); }; //! Returns the value of this attribute as a vector2df. - virtual vector2df getVector2df() const { return vector2df(); }; + virtual vector2df getVector2df() { return vector2df(); }; //! Returns the value of this attribute as a vector2di. - virtual vector2di getVector2di() const { return vector2di(); }; + virtual vector2di getVector2di() { return vector2di(); }; //! Returns the value of this attribute as a vector3df. - virtual vector3df getVector3df() const { return vector3df(); }; + virtual vector3df getVector3df() { return vector3df(); }; //! Returns the value of this attribute as a vector3di. - virtual vector3di getVector3di() const { return vector3di(); }; + virtual vector3di getVector3di() { return vector3di(); }; //! Sets the value of this attribute as a aabbox3df. virtual void setAabbox3df(const aabbox3df &value) {}; Modified: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-15 16:01:30 UTC (rev 152) @@ -38,33 +38,23 @@ { } -aabbox3df SerializedAabbox3d::getAabbox3df() const -{ - return getAabbox3df(); -} - aabbox3df SerializedAabbox3d::getAabbox3df() { return convert<f32, f64>(mValue); } -aabbox3di SerializedAabbox3d::getAabbox3di() const -{ - return getAabbox3di(); -} - aabbox3di SerializedAabbox3d::getAabbox3di() { return convert<s32, f64>(mValue); } -std::string SerializedAabbox3d::getString() const +std::string SerializedAabbox3d::getString() { SerializedVector3d MaxEdge("", mValue.MaxEdge); SerializedVector3d MinEdge("", mValue.MinEdge); stringstream ss; - ss << "aabbox3d(" << MaxEdge.getString() << ", " << MinEdge.getString() << ")"; + ss << "aabbox3d(" << MinEdge.getString() << ", " << MaxEdge.getString() << ")"; return ss.str(); } @@ -81,6 +71,19 @@ void SerializedAabbox3d::setString(const std::string &value) { + std::string typelessValue = removeStringFormatting(value, "aabbox3d"); + + SerializedVector3d MinEdge("", vector3df()); + MinEdge.setString(typelessValue.substr(0, typelessValue.find(")")+1)); + + SerializedVector3d MaxEdge("", vector3df()); + MaxEdge.setString(typelessValue.substr(typelessValue.find(")")+1)); + + aabbox3df aabbox; + aabbox.MinEdge = MinEdge.getVector3df(); + aabbox.MaxEdge = MaxEdge.getVector3df(); + + mValue = convert<f64, f32>(aabbox); } @@ -98,22 +101,22 @@ } // Reimplementations of superclass' methods. -bool SerializedBool::getBool() const +bool SerializedBool::getBool() { return mValue; } -f32 SerializedBool::getFloat() const +f32 SerializedBool::getFloat() { return (mValue) ? 1.0f : 0.0f; } -s32 SerializedBool::getInt() const +s32 SerializedBool::getInt() { return (mValue) ? 1 : 0; } -std::string SerializedBool::getString() const +std::string SerializedBool::getString() { return (mValue) ? "true" : "false"; } @@ -153,27 +156,27 @@ } // Reimplementations of superclass' methods. -SColor SerializedColor::getColor() const +SColor SerializedColor::getColor() { return mValue.toSColor(); } -SColorf SerializedColor::getColorf() const +SColorf SerializedColor::getColorf() { return mValue; } -f32 SerializedColor::getFloat() const +f32 SerializedColor::getFloat() { return (f32)mValue.toSColor().color; } -s32 SerializedColor::getInt() const +s32 SerializedColor::getInt() { return (s32)mValue.toSColor().color; } -std::string SerializedColor::getString() const +std::string SerializedColor::getString() { stringstream ss; ss << "color(" << mValue.getAlpha() << ", " << mValue.getRed() << ", " @@ -235,7 +238,7 @@ { } -std::string SerializedDimension2d::getString() const +std::string SerializedDimension2d::getString() { stringstream ss; ss << "dimension2d(" << mValue.Width << ", " << mValue.Height << ")"; @@ -243,21 +246,11 @@ return ss.str(); } -dimension2df SerializedDimension2d::getDimension2df() const -{ - return getDimension2df(); -} - dimension2df SerializedDimension2d::getDimension2df() { return convert<f32, f64>(mValue); } -dimension2di SerializedDimension2d::getDimension2di() const -{ - return getDimension2di(); -} - dimension2di SerializedDimension2d::getDimension2di() { return convert<s32, f64>(mValue); @@ -304,7 +297,7 @@ { } -std::string SerializedLine2d::getString() const +std::string SerializedLine2d::getString() { SerializedVector2d start("", mValue.start); SerializedVector2d end("", mValue.end); @@ -315,21 +308,11 @@ return ss.str(); } -line2df SerializedLine2d::getLine2df() const -{ - return getLine2df(); -} - line2df SerializedLine2d::getLine2df() { return convert<f32, f64>(mValue); } -line2di SerializedLine2d::getLine2di() const -{ - return getLine2di(); -} - line2di SerializedLine2d::getLine2di() { return convert<s32, f64>(mValue); @@ -347,9 +330,21 @@ void SerializedLine2d::setString(const std::string &value) { -} + std::string typelessValue = removeStringFormatting(value, "line2d"); + SerializedVector2d start("", vector2df()); + start.setString(typelessValue.substr(0, typelessValue.find(")")+1)); + SerializedVector2d end("", vector2df()); + end.setString(typelessValue.substr(typelessValue.find(")")+1)); + + line2df line; + line.start = start.getVector2df(); + line.end = end.getVector2df(); + + mValue = convert<f64, f32>(line); +} + // SerializedLine3d class // SerializedLine3d constructor (line3df). SerializedLine3d::SerializedLine3d(const std::string &name, const line3df &value) @@ -370,7 +365,7 @@ { } -std::string SerializedLine3d::getString() const +std::string SerializedLine3d::getString() { SerializedVector3d start("", mValue.start); SerializedVector3d end("", mValue.end); @@ -381,21 +376,11 @@ return ss.str(); } -line3df SerializedLine3d::getLine3df() const -{ - return getLine3df(); -} - line3df SerializedLine3d::getLine3df() { return convert<f32, f64>(mValue); } -line3di SerializedLine3d::getLine3di() const -{ - return getLine3di(); -} - line3di SerializedLine3d::getLine3di() { return convert<s32, f64>(mValue); @@ -413,9 +398,21 @@ void SerializedLine3d::setString(const std::string &value) { -} + std::string typelessValue = removeStringFormatting(value, "line3d"); + SerializedVector3d start("", vector3df()); + start.setString(typelessValue.substr(0, typelessValue.find(")")+1)); + SerializedVector3d end("", vector3df()); + end.setString(typelessValue.substr(typelessValue.find(")")+1)); + + line3df line; + line.start = start.getVector3df(); + line.end = end.getVector3df(); + + mValue = convert<f64, f32>(line); +} + // SerializedNumber class // SerializedNumber constructor. SerializedNumber::SerializedNumber(const std::string &name, s32 value) @@ -437,22 +434,22 @@ } // Reimplementations of superclass' methods. -bool SerializedNumber::getBool() const +bool SerializedNumber::getBool() { return (mValue != 0.0f); } -f32 SerializedNumber::getFloat() const +f32 SerializedNumber::getFloat() { return (f32)mValue; } -s32 SerializedNumber::getInt() const +s32 SerializedNumber::getInt() { return (s32)mValue; } -std::string SerializedNumber::getString() const +std::string SerializedNumber::getString() { stringstream ss; ss << mValue; @@ -495,7 +492,7 @@ { } -Serializable* SerializedObject::getObject() const +Serializable* SerializedObject::getObject() { return mObject; } @@ -526,7 +523,7 @@ { } -std::string SerializedPlane3d::getString() const +std::string SerializedPlane3d::getString() { SerializedVector3d normal("", mValue.Normal); @@ -536,21 +533,11 @@ return ss.str(); } -plane3df SerializedPlane3d::getPlane3df() const -{ - return getPlane3df(); -} - plane3df SerializedPlane3d::getPlane3df() { return convert<f32, f64>(mValue); } -plane3di SerializedPlane3d::getPlane3di() const -{ - return getPlane3di(); -} - plane3di SerializedPlane3d::getPlane3di() { return convert<s32, f64>(mValue); @@ -568,6 +555,18 @@ void SerializedPlane3d::setString(const std::string &value) { + std::string typelessValue = removeStringFormatting(value, "plane3d"); + + SerializedVector3d normal("", vector3df()); + normal.setString(typelessValue.substr(0, typelessValue.find(")")+1)); + + stringstream D(typelessValue.substr(typelessValue.find(")")+1)); + + plane3df plane; + plane.Normal = normal.getVector3df(); + D >> plane.D; + + mValue = convert<f64, f32>(plane); } @@ -584,7 +583,7 @@ { } -std::string SerializedQuaternion::getString() const +std::string SerializedQuaternion::getString() { stringstream ss; ss << "quaternion(" << mValue.X << ", " << mValue.Y << ", " << mValue.Z << ", " << mValue.W << ")"; @@ -592,7 +591,7 @@ return ss.str(); } -quaternion SerializedQuaternion::getQuaternion() const +quaternion SerializedQuaternion::getQuaternion() { return mValue; } @@ -628,10 +627,10 @@ { } -std::string SerializedRect::getString() const +std::string SerializedRect::getString() { - SerializedVector2d LowerRightCorner("", mValue.LowerRightCorner); SerializedVector2d UpperLeftCorner("", mValue.UpperLeftCorner); + SerializedVector2d LowerRightCorner("", mValue.LowerRightCorner); stringstream ss; ss << "rect(" << UpperLeftCorner.getString() << ", " << LowerRightCorner.getString() << ")"; @@ -639,7 +638,7 @@ return ss.str(); } -rect<s32> SerializedRect::getRect() const +rect<s32> SerializedRect::getRect() { return mValue; } @@ -651,6 +650,16 @@ void SerializedRect::setString(const std::string &value) { + std::string typelessValue = removeStringFormatting(value, "rect"); + + SerializedVector2d UpperLeftCorner("", vector2df()); + UpperLeftCorner.setString(typelessValue.substr(typelessValue.find(")")+1)); + + SerializedVector2d LowerRightCorner("", vector2df()); + LowerRightCorner.setString(typelessValue.substr(0, typelessValue.find(")")+1)); + + mValue.UpperLeftCorner = UpperLeftCorner.getVector2di(); + mValue.LowerRightCorner = LowerRightCorner.getVector2di(); } @@ -674,12 +683,12 @@ { } -std::string SerializedString::getString() const +std::string SerializedString::getString() { return stringc(getStringW().c_str()).c_str(); } -stringw SerializedString::getStringW() const +stringw SerializedString::getStringW() { return mValue; } @@ -722,7 +731,7 @@ { } -std::string SerializedVector2d::getString() const +std::string SerializedVector2d::getString() { stringstream ss; ss << "vector2d(" << mValue.X << ", " << mValue.Y << ")"; @@ -730,21 +739,11 @@ return ss.str(); } -vector2df SerializedVector2d::getVector2df() const -{ - return getVector2df(); -} - vector2df SerializedVector2d::getVector2df() { return convert<f32, f64>(mValue); } -vector2di SerializedVector2d::getVector2di() const -{ - return getVector2di(); -} - vector2di SerializedVector2d::getVector2di() { return convert<s32, f64>(mValue); @@ -798,7 +797,7 @@ { } -std::string SerializedVector3d::getString() const +std::string SerializedVector3d::getString() { stringstream ss; ss << "vector3d(" << mValue.X << ", " << mValue.Y << ", " << mValue.Z << ")"; @@ -806,21 +805,11 @@ return ss.str(); } -vector3df SerializedVector3d::getVector3df() const -{ - return getVector3df(); -} - vector3df SerializedVector3d::getVector3df() { return convert<f32, f64>(mValue); } -vector3di SerializedVector3d::getVector3di() const -{ - return getVector3di(); -} - vector3di SerializedVector3d::getVector3di() { return convert<s32, f64>(mValue); Modified: trunk/src/core/SerializedAttributesImpl.h =================================================================== --- trunk/src/core/SerializedAttributesImpl.h 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/core/SerializedAttributesImpl.h 2009-11-15 16:01:30 UTC (rev 152) @@ -40,9 +40,9 @@ ~SerializedAabbox3d(); // Public methods - aabbox3df getAabbox3df() const; - aabbox3di getAabbox3di() const; - std::string getString() const; + aabbox3df getAabbox3df(); + aabbox3di getAabbox3di(); + std::string getString(); void setAabbox3df(const aabbox3df &value); void setAabbox3di(const aabbox3di &value); @@ -57,19 +57,16 @@ aabbox3d<R> r; r.MinEdge.X = (R)t.MinEdge.X; - r.MinEdge.X = (R)t.MinEdge.Y; - r.MinEdge.X = (R)t.MinEdge.Z; + r.MinEdge.Y = (R)t.MinEdge.Y; + r.MinEdge.Z = (R)t.MinEdge.Z; r.MaxEdge.X = (R)t.MaxEdge.X; - r.MaxEdge.X = (R)t.MaxEdge.Y; - r.MaxEdge.X = (R)t.MaxEdge.Z; + r.MaxEdge.Y = (R)t.MaxEdge.Y; + r.MaxEdge.Z = (R)t.MaxEdge.Z; return r; } - aabbox3df getAabbox3df(); - aabbox3di getAabbox3di(); - // Private members aabbox3d<f64> mValue; }; @@ -90,10 +87,10 @@ ~SerializedBool(); // Public methods - bool getBool() const; - f32 getFloat() const; - s32 getInt() const; - std::string getString() const; + bool getBool(); + f32 getFloat(); + s32 getInt(); + std::string getString(); void setBool(bool value); void setFloat(f32 value); @@ -122,11 +119,11 @@ ~SerializedColor(); // Public methods - SColor getColor() const; - SColorf getColorf() const; - f32 getFloat() const; - s32 getInt() const; - std::string getString() const; + SColor getColor(); + SColorf getColorf(); + f32 getFloat(); + s32 getInt(); + std::string getString(); void setColor(const SColor &value); void setColorf(const SColorf &value); @@ -160,9 +157,9 @@ ~SerializedDimension2d(); // Public methods - std::string getString() const; - dimension2df getDimension2df() const; - dimension2di getDimension2di() const; + std::string getString(); + dimension2df getDimension2df(); + dimension2di getDimension2di(); void setDimension2df(const dimension2df &value); void setDimension2di(const dimension2di &value); @@ -177,9 +174,6 @@ return dimension2d<R>((R)t.Width, (R)t.Height); } - dimension2df getDimension2df(); - dimension2di getDimension2di(); - // Private members dimension2d<f64> mValue; }; @@ -204,9 +198,9 @@ ~SerializedLine2d(); // Public methods - std::string getString() const; - line2df getLine2df() const; - line2di getLine2di() const; + std::string getString(); + line2df getLine2df(); + line2di getLine2di(); void setLine2df(const line2df &value); void setLine2di(const line2di &value); @@ -229,9 +223,6 @@ return r; } - line2df getLine2df(); - line2di getLine2di(); - // Private members line2d<f64> mValue; }; @@ -256,9 +247,9 @@ ~SerializedLine3d(); // Public methods - std::string getString() const; - line3df getLine3df() const; - line3di getLine3di() const; + std::string getString(); + line3df getLine3df(); + line3di getLine3di(); void setLine3df(const line3df &value); void setLine3di(const line3di &value); @@ -283,9 +274,6 @@ return r; } - line3df getLine3df(); - line3di getLine3di(); - // Private members line3d<f64> mValue; }; @@ -310,10 +298,10 @@ ~SerializedNumber(); // Public methods - bool getBool() const; - f32 getFloat() const; - s32 getInt() const; - std::string getString() const; + bool getBool(); + f32 getFloat(); + s32 getInt(); + std::string getString(); void setBool(bool value); void setFloat(f32 value); @@ -346,7 +334,7 @@ ~SerializedObject(); // Public methods - Serializable* getObject() const; + Serializable* getObject(); void setObject(Serializable *object); @@ -376,9 +364,9 @@ ~SerializedPlane3d(); // Public methods - std::string getString() const; - plane3df getPlane3df() const; - plane3di getPlane3di() const; + std::string getString(); + plane3df getPlane3df(); + plane3di getPlane3di(); void setPlane3df(const plane3df &value); void setPlane3di(const plane3di &value); @@ -402,9 +390,6 @@ return r; } - plane3df getPlane3df(); - plane3di getPlane3di(); - // Private members plane3d<f64> mValue; }; @@ -425,8 +410,8 @@ ~SerializedQuaternion(); // Public methods - std::string getString() const; - quaternion getQuaternion() const; + std::string getString(); + quaternion getQuaternion(); void setQuaternion(const quaternion &value); void setString(const std::string &value); @@ -454,8 +439,8 @@ ~SerializedRect(); // Public methods - std::string getString() const; - rect<s32> getRect() const; + std::string getString(); + rect<s32> getRect(); void setRect(const rect<s32> &value); void setString(const std::string &value); @@ -486,8 +471,8 @@ ~SerializedString(); // Public methods - std::string getString() const; - stringw getStringW() const; + std::string getString(); + stringw getStringW(); void setString(const std::string &value); void setStringW(const stringw &value); @@ -522,9 +507,9 @@ ~SerializedVector2d(); // Public methods - std::string getString() const; - vector2df getVector2df() const; - vector2di getVector2di() const; + std::string getString(); + vector2df getVector2df(); + vector2di getVector2di(); void setString(const std::string &value); void setVector2df(const vector2df &value); @@ -539,9 +524,6 @@ return vector2d<R>((R)t.X, (R)t.Y); } - vector2df getVector2df(); - vector2di getVector2di(); - // Private members vector2d<f64> mValue; }; @@ -570,9 +552,9 @@ ~SerializedVector3d(); // Public methods - std::string getString() const; - vector3df getVector3df() const; - vector3di getVector3di() const; + std::string getString(); + vector3df getVector3df(); + vector3di getVector3di(); void setString(const std::string &value); void setVector3df(const vector3df &value); @@ -587,9 +569,6 @@ return vector3d<R>((R)t.X, (R)t.Y, (R)t.Z); } - vector3df getVector3df(); - vector3di getVector3di(); - // Private members vector3d<f64> mValue; }; Modified: trunk/src/scripting/core/asEntity.cpp =================================================================== --- trunk/src/scripting/core/asEntity.cpp 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/scripting/core/asEntity.cpp 2009-11-15 16:01:30 UTC (rev 152) @@ -99,6 +99,15 @@ r = engine->RegisterObjectMethod("Entity", "Entity@ getParent()", asMETHOD(Entity, getParent), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Entity", "const vector3df& getAbsolutePosition()", + asMETHOD(Entity, getAbsolutePosition), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Entity", "const vector3df& getPosition()", + asMETHOD(Entity, getPosition), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Entity", "const vector3df& getAbsoluteRotation()", + asMETHOD(Entity, getAbsoluteRotation), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Entity", "const vector3df& getRotation()", + asMETHOD(Entity, getRotation), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Entity", "bool loadXML(const string &in)", asMETHODPR(Entity, loadXML, (const std::string&), bool), asCALL_THISCALL); assert(r >= 0); Modified: trunk/src/scripting/core/asGameState.cpp =================================================================== --- trunk/src/scripting/core/asGameState.cpp 2009-11-12 15:10:50 UTC (rev 151) +++ trunk/src/scripting/core/asGameState.cpp 2009-11-15 16:01:30 UTC (rev 152) @@ -133,7 +133,7 @@ r = engine->RegisterObjectMethod("GameState", "void init()", asMETHOD(GameState, init), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("GameState", "void clear()", - asMETHOD(DataStack, clear), asCALL_THISCALL); assert(r >= 0); + asMETHOD(GameState, clear), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("GameState", "void update(f32)", asMETHOD(GameState, update), asCALL_THISCALL); assert(r >= 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-12 15:11:23
|
Revision: 151 http://sirrf.svn.sourceforge.net/sirrf/?rev=151&view=rev Author: zccdark203 Date: 2009-11-12 15:10:50 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Added (re)implementations of the setString method for various "simple" implementations of SerializedAttribute (Vector2d, Vector3d, etc). Implementations of the more complex implementations of SerializedAttribute (aabbox3d, plane3d, etc) will follow soon. Modified Paths: -------------- trunk/src/core/SerializedAttribute.cpp trunk/src/core/SerializedAttribute.h trunk/src/core/SerializedAttributesImpl.cpp trunk/src/core/SerializedAttributesImpl.h Modified: trunk/src/core/SerializedAttribute.cpp =================================================================== --- trunk/src/core/SerializedAttribute.cpp 2009-11-08 18:42:57 UTC (rev 150) +++ trunk/src/core/SerializedAttribute.cpp 2009-11-12 15:10:50 UTC (rev 151) @@ -41,4 +41,41 @@ return mType; } +// Removes all formatting from the given string in order to extract the base values of the +// attribute. +std::string SerializedAttribute::removeStringFormatting(const std::string &value, const std::string &type) +{ + // Determine the location of the base elements of an attribute string (type name, '(' and ')'). + unsigned int typeLocation = value.find(type); + unsigned int leftBracketLocation = value.find("("); + unsigned int rightBracketLocation = value.rfind(")"); + + // Determine the type of the attribute this string describes. + if(typeLocation == std::string::npos || leftBracketLocation == std::string::npos || + rightBracketLocation == std::string::npos) + return std::string(""); + + // Make sure that the base elements are in the right order. + if(typeLocation > leftBracketLocation || leftBracketLocation > rightBracketLocation) + return std::string(""); + + // Create a new string without formatting. + stringstream ss1(value.substr(leftBracketLocation+1, rightBracketLocation-leftBracketLocation-1)); + stringstream ss2; + + while(!ss1.eof()) + { + std::string tempString; + ss1 >> tempString; + + while(tempString.find(",") != std::string::npos) + tempString.replace(tempString.find(","), 1, " "); + + ss2 << tempString; + } + + // Return the new stringstream. + return ss2.str(); +} + // End of File Modified: trunk/src/core/SerializedAttribute.h =================================================================== --- trunk/src/core/SerializedAttribute.h 2009-11-08 18:42:57 UTC (rev 150) +++ trunk/src/core/SerializedAttribute.h 2009-11-12 15:10:50 UTC (rev 151) @@ -143,6 +143,13 @@ //! @param type String describing the type of this attribute. SerializedAttribute(const std::string &name, const std::string &type); + // Protected methods + //! Removes all formatting from the given string in order to extract the base values of the + //! attribute. + //! @param value String that will be examined + //! @param type Type to be removed + std::string removeStringFormatting(const std::string &value, const std::string &type); + private: // Private members Modified: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp 2009-11-08 18:42:57 UTC (rev 150) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-12 15:10:50 UTC (rev 151) @@ -79,7 +79,11 @@ mValue = convert<f64, s32>(value); } +void SerializedAabbox3d::setString(const std::string &value) +{ +} + // SerializedBool class // SerializedBool constructor. SerializedBool::SerializedBool(const std::string &name, bool value) @@ -198,7 +202,19 @@ mValue = SColor(value); } +void SerializedColor::setString(const std::string &value) +{ + // Remove formatting from the given string. + stringstream ss(removeStringFormatting(value, "color")); + // Set the new values of the color. + ss >> mValue.a; + ss >> mValue.r; + ss >> mValue.g; + ss >> mValue.b; +} + + // SerializedDimension2d class // SerializedDimension2d constructor (dimension2df). SerializedDimension2d::SerializedDimension2d(const std::string &name, const dimension2df &value) @@ -257,7 +273,17 @@ mValue = convert<f64, s32>(value); } +void SerializedDimension2d::setString(const std::string &value) +{ + // Remove formatting from the given string. + stringstream ss(removeStringFormatting(value, "dimension2d")); + // Set the new values of the dimension2d. + ss >> mValue.Width; + ss >> mValue.Height; +} + + // SerializedLine2d class // SerializedLine2d constructor (line2df). SerializedLine2d::SerializedLine2d(const std::string &name, const line2df &value) @@ -319,7 +345,11 @@ mValue = convert<f64, s32>(value); } +void SerializedLine2d::setString(const std::string &value) +{ +} + // SerializedLine3d class // SerializedLine3d constructor (line3df). SerializedLine3d::SerializedLine3d(const std::string &name, const line3df &value) @@ -381,7 +411,11 @@ mValue = convert<f64, s32>(value); } +void SerializedLine3d::setString(const std::string &value) +{ +} + // SerializedNumber class // SerializedNumber constructor. SerializedNumber::SerializedNumber(const std::string &name, s32 value) @@ -532,7 +566,11 @@ mValue = convert<f64, s32>(value); } +void SerializedPlane3d::setString(const std::string &value) +{ +} + // SerializedQuaternion class // SerializedQuaternion constructor. SerializedQuaternion::SerializedQuaternion(const std::string &name, const quaternion &value) @@ -564,7 +602,19 @@ mValue = value; } +void SerializedQuaternion::setString(const std::string &value) +{ + // Remove formatting from the given string. + stringstream ss(removeStringFormatting(value, "quaternion")); + // Set the new values of the quaternion. + ss >> mValue.X; + ss >> mValue.Y; + ss >> mValue.Z; + ss >> mValue.W; +} + + // SerializedRect class // SerializedRect constructor. SerializedRect::SerializedRect(const std::string &name, const rect<s32> &value) @@ -599,7 +649,11 @@ mValue = value; } +void SerializedRect::setString(const std::string &value) +{ +} + // SerializedString class // SerializedString constructor (std::string). SerializedString::SerializedString(const std::string &name, const std::string &value) @@ -696,6 +750,16 @@ return convert<s32, f64>(mValue); } +void SerializedVector2d::setString(const std::string &value) +{ + // Remove formatting from the given string. + stringstream ss(removeStringFormatting(value, "vector2d")); + + // Set the new values of the vector2d. + ss >> mValue.X; + ss >> mValue.Y; +} + void SerializedVector2d::setVector2df(const vector2df &value) { mValue = convert<f64, f32>(value); @@ -762,6 +826,17 @@ return convert<s32, f64>(mValue); } +void SerializedVector3d::setString(const std::string &value) +{ + // Remove formatting from the given string. + stringstream ss(removeStringFormatting(value, "vector3d")); + + // Set the new values of the vector3d. + ss >> mValue.X; + ss >> mValue.Y; + ss >> mValue.Z; +} + void SerializedVector3d::setVector3df(const vector3df &value) { mValue = convert<f64, f32>(value); Modified: trunk/src/core/SerializedAttributesImpl.h =================================================================== --- trunk/src/core/SerializedAttributesImpl.h 2009-11-08 18:42:57 UTC (rev 150) +++ trunk/src/core/SerializedAttributesImpl.h 2009-11-12 15:10:50 UTC (rev 151) @@ -46,6 +46,7 @@ void setAabbox3df(const aabbox3df &value); void setAabbox3di(const aabbox3di &value); + void setString(const std::string &value); private: @@ -131,6 +132,7 @@ void setColorf(const SColorf &value); void setFloat(f32 value); void setInt(s32 value); + void setString(const std::string &value); private: @@ -164,6 +166,7 @@ void setDimension2df(const dimension2df &value); void setDimension2di(const dimension2di &value); + void setString(const std::string &value); private: @@ -207,6 +210,7 @@ void setLine2df(const line2df &value); void setLine2di(const line2di &value); + void setString(const std::string &value); private: @@ -258,6 +262,7 @@ void setLine3df(const line3df &value); void setLine3di(const line3di &value); + void setString(const std::string &value); private: @@ -377,7 +382,9 @@ void setPlane3df(const plane3df &value); void setPlane3di(const plane3di &value); + void setString(const std::string &value); + private: // Private methods @@ -422,7 +429,9 @@ quaternion getQuaternion() const; void setQuaternion(const quaternion &value); + void setString(const std::string &value); + private: // Private members @@ -449,6 +458,7 @@ rect<s32> getRect() const; void setRect(const rect<s32> &value); + void setString(const std::string &value); private: @@ -516,6 +526,7 @@ vector2df getVector2df() const; vector2di getVector2di() const; + void setString(const std::string &value); void setVector2df(const vector2df &value); void setVector2di(const vector2di &value); @@ -563,6 +574,7 @@ vector3df getVector3df() const; vector3di getVector3di() const; + void setString(const std::string &value); void setVector3df(const vector3df &value); void setVector3di(const vector3di &value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-08 18:43:09
|
Revision: 150 http://sirrf.svn.sourceforge.net/sirrf/?rev=150&view=rev Author: zccdark203 Date: 2009-11-08 18:42:57 +0000 (Sun, 08 Nov 2009) Log Message: ----------- Modified the SerializedString class so that it stores strings internally as wide strings (this should prevent data loss). Furthermore the SerializedString class now also takes wide strings as one of the constructor parameters. Modified Paths: -------------- trunk/src/core/Serializable.cpp trunk/src/core/SerializedAttributes.cpp trunk/src/core/SerializedAttributesImpl.cpp trunk/src/core/SerializedAttributesImpl.h Modified: trunk/src/core/Serializable.cpp =================================================================== --- trunk/src/core/Serializable.cpp 2009-11-08 18:27:50 UTC (rev 149) +++ trunk/src/core/Serializable.cpp 2009-11-08 18:42:57 UTC (rev 150) @@ -167,7 +167,7 @@ else if(type == "plane3d") attribute = new SerializedPlane3d(name, plane3df()); else if(type == "quaternion") attribute = new SerializedQuaternion(name, quaternion()); else if(type == "rect") attribute = new SerializedRect(name, rect<s32>()); - else if(type == "string") attribute = new SerializedString(name, ""); + else if(type == "string") attribute = new SerializedString(name, L""); else if(type == "vector2d") attribute = new SerializedVector2d(name, vector2df()); else if(type == "vector3d") attribute = new SerializedVector3d(name, vector3df()); Modified: trunk/src/core/SerializedAttributes.cpp =================================================================== --- trunk/src/core/SerializedAttributes.cpp 2009-11-08 18:27:50 UTC (rev 149) +++ trunk/src/core/SerializedAttributes.cpp 2009-11-08 18:42:57 UTC (rev 150) @@ -625,7 +625,7 @@ // Pushes an attribute into the queue as a wide string. void SerializedAttributes::pushStringW(const std::string &name, const stringw &value) { - SerializedString *attribute = new SerializedString(name, stringc( value.c_str() ).c_str() ); + SerializedString *attribute = new SerializedString(name, value); pushAttribute(attribute); attribute->drop(); } Modified: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp 2009-11-08 18:27:50 UTC (rev 149) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-08 18:42:57 UTC (rev 150) @@ -601,10 +601,17 @@ // SerializedString class -// SerializedString constructor. +// SerializedString constructor (std::string). SerializedString::SerializedString(const std::string &name, const std::string &value) : SerializedAttribute(name, "string") { + setString(value); +} + +// SerializedString constructor (stringw). +SerializedString::SerializedString(const std::string &name, const stringw &value) +: SerializedAttribute(name, "string") +{ mValue = value; } @@ -615,11 +622,21 @@ std::string SerializedString::getString() const { + return stringc(getStringW().c_str()).c_str(); +} + +stringw SerializedString::getStringW() const +{ return mValue; } void SerializedString::setString(const std::string &value) { + setStringW( value.c_str() ); +} + +void SerializedString::setStringW(const stringw &value) +{ mValue = value; } Modified: trunk/src/core/SerializedAttributesImpl.h =================================================================== --- trunk/src/core/SerializedAttributesImpl.h 2009-11-08 18:27:50 UTC (rev 149) +++ trunk/src/core/SerializedAttributesImpl.h 2009-11-08 18:42:57 UTC (rev 150) @@ -464,22 +464,28 @@ public: // Initialisation and deinitialisation - //! Constructor + //! Constructor (std::string) //! @param name Name of the attribute //! @param value Initial value of this attribute. SerializedString(const std::string &name, const std::string &value); + //! Constructor (stringw) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedString(const std::string &name, const stringw &value); //! Deconstructor ~SerializedString(); // Public methods std::string getString() const; + stringw getStringW() const; void setString(const std::string &value); + void setStringW(const stringw &value); private: // Private members - std::string mValue; + stringw mValue; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-08 18:27:58
|
Revision: 149 http://sirrf.svn.sourceforge.net/sirrf/?rev=149&view=rev Author: zccdark203 Date: 2009-11-08 18:27:50 +0000 (Sun, 08 Nov 2009) Log Message: ----------- Added various convenience methods to the SerializedAttributes class. Modified Paths: -------------- trunk/src/core/SerializedAttributes.cpp trunk/src/core/SerializedAttributes.h Modified: trunk/src/core/SerializedAttributes.cpp =================================================================== --- trunk/src/core/SerializedAttributes.cpp 2009-11-08 16:02:32 UTC (rev 148) +++ trunk/src/core/SerializedAttributes.cpp 2009-11-08 18:27:50 UTC (rev 149) @@ -17,6 +17,7 @@ // Include files #include "SerializedAttributes.h" +#include "SerializedAttributesImpl.h" // SerializedAttributes class @@ -78,6 +79,390 @@ return NULL; } +// Pulls an attribute from the queue and interprete it as an aabbox3df object. +aabbox3df SerializedAttributes::pullAabbox3df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + aabbox3df value = attribute->getAabbox3df(); + attribute->drop(); + + return value; + } + + return aabbox3df(); +} + +// RPulls an attribute from the queue and interprete it as an aabbox3di object. +aabbox3di SerializedAttributes::pullAabbox3di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + aabbox3di value = attribute->getAabbox3di(); + attribute->drop(); + + return value; + } + + return aabbox3di(); +} + +// Pulls an attribute from the queue and interprete it as a boolean value. +bool SerializedAttributes::pullBool() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + bool value = attribute->getBool(); + attribute->drop(); + + return value; + } + + return false; +} + +// Pulls an attribute from the queue and interprete it as a SColor object. +SColor SerializedAttributes::pullColor() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + SColor value = attribute->getColor(); + attribute->drop(); + + return value; + } + + return SColor(); +} + +// Pulls an attribute from the queue and interprete it as a SColorf object. +SColorf SerializedAttributes::pullColorf() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + SColorf value = attribute->getColorf(); + attribute->drop(); + + return value; + } + + return SColorf(); +} + +// Pulls an attribute from the queue and interprete it as a dimension2df object. +dimension2df SerializedAttributes::pullDimension2df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + dimension2df value = attribute->getDimension2df(); + attribute->drop(); + + return value; + } + + return dimension2df(); +} + +// Pulls an attribute from the queue and interprete it as a dimension2di object. +dimension2di SerializedAttributes::pullDimension2di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + dimension2di value = attribute->getDimension2di(); + attribute->drop(); + + return value; + } + + return dimension2di(); +} + +// Pulls an attribute from the queue and interprete it as a float value. +f32 SerializedAttributes::pullFloat() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + f32 value = attribute->getFloat(); + attribute->drop(); + + return value; + } + + return 0.0f; +} + +// Pulls an attribute from the queue and interprete it as an integer value. +s32 SerializedAttributes::pullInt() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + s32 value = attribute->getInt(); + attribute->drop(); + + return value; + } + + return 0; +} + +// Pulls an attribute from the queue and interprete it as a line2df object. +line2df SerializedAttributes::pullLine2df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + line2df value = attribute->getLine2df(); + attribute->drop(); + + return value; + } + + return line2df(); +} + +// Pulls an attribute from the queue and interprete it as a line2di object. +line2di SerializedAttributes::pullLine2di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + line2di value = attribute->getLine2di(); + attribute->drop(); + + return value; + } + + return line2di(); +} + +// Pulls an attribute from the queue and interprete it as a line3df object. +line3df SerializedAttributes::pullLine3df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + line3df value = attribute->getLine3df(); + attribute->drop(); + + return value; + } + + return line3df(); +} + +// Pulls an attribute from the queue and interprete it as a line3di object. +line3di SerializedAttributes::pullLine3di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + line3di value = attribute->getLine3di(); + attribute->drop(); + + return value; + } + + return line3di(); +} + +// Pulls an attribute from the queue and interprete it as a Serializable object. +Serializable* SerializedAttributes::pullObject() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + Serializable *object = attribute->getObject(); + attribute->drop(); + + return object; + } + + return NULL; +} + +// Pulls an attribute from the queue and interprete it as a plane3df object. +plane3df SerializedAttributes::pullPlane3df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + plane3df value = attribute->getPlane3df(); + attribute->drop(); + + return value; + } + + return plane3df(); +} + +// Pulls an attribute from the queue and interprete it as a plane3di object. +plane3di SerializedAttributes::pullPlane3di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + plane3di value = attribute->getPlane3di(); + attribute->drop(); + + return value; + } + + return plane3di(); +} + +// Pulls an attribute from the queue and interprete it as a quaternion object. +quaternion SerializedAttributes::pullQuaternion() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + quaternion value = attribute->getQuaternion(); + attribute->drop(); + + return value; + } + + return quaternion(); +} + +// Pulls an attribute from the queue and interprete it as a rect<s32> object. +rect<s32> SerializedAttributes::pullRect() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + rect<s32> value = attribute->getRect(); + attribute->drop(); + + return value; + } + + return rect<s32>(); +} + +// Pulls an attribute from the queue and interprete it as a string. +std::string SerializedAttributes::pullString() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + std::string value = attribute->getString(); + attribute->drop(); + + return value; + } + + return ""; +} + +// Pulls an attribute from the queue and interprete it as a wide string. +stringw SerializedAttributes::pullStringW() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + stringw value = attribute->getStringW(); + attribute->drop(); + + return value; + } + + return L""; +} + +// Pulls an attribute from the queue and interprete it as a vector2df object. +vector2df SerializedAttributes::pullVector2df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + vector2df value = attribute->getVector2df(); + attribute->drop(); + + return value; + } + + return vector2df(); +} + +// Pulls an attribute from the queue and interprete it as a vector2di object. +vector2di SerializedAttributes::pullVector2di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + vector2di value = attribute->getVector2di(); + attribute->drop(); + + return value; + } + + return vector2di(); +} + +// Pulls an attribute from the queue and interprete it as a vector3df object +vector3df SerializedAttributes::pullVector3df() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + vector3df value = attribute->getVector3df(); + attribute->drop(); + + return value; + } + + return vector3df(); +} + +// Pulls an attribute from the queue and interprete it as a vector3di object. +vector3di SerializedAttributes::pullVector3di() +{ + SerializedAttribute *attribute = pullAttribute(); + + if(attribute != NULL) + { + vector3di value = attribute->getVector3di(); + attribute->drop(); + + return value; + } + + return vector3di(); +} + // Pushes a new attribute into the internal attribute queue. void SerializedAttributes::pushAttribute(SerializedAttribute *attribute) { @@ -85,6 +470,198 @@ mQueue.push(attribute); } +// Pushes an attribute into the queue as an aabbox3df object. +void SerializedAttributes::pushAabbox3df(const std::string &name, const aabbox3df &value) +{ + SerializedAabbox3d *attribute = new SerializedAabbox3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as an aabbox3di object. +void SerializedAttributes::pushAabbox3di(const std::string &name, const aabbox3di &value) +{ + SerializedAabbox3d *attribute = new SerializedAabbox3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a boolean value. +void SerializedAttributes::pushBool(const std::string &name, bool value) +{ + SerializedBool *attribute = new SerializedBool(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a SColor object. +void SerializedAttributes::pushColor(const std::string &name, const SColor &value) +{ + SerializedColor *attribute = new SerializedColor(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a SColorf object. +void SerializedAttributes::pushColorf(const std::string &name, const SColorf &value) +{ + SerializedColor *attribute = new SerializedColor(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a dimension2df object. +void SerializedAttributes::pushDimension2df(const std::string &name, const dimension2df &value) +{ + SerializedDimension2d *attribute = new SerializedDimension2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a dimension2di object. +void SerializedAttributes::pushDimension2di(const std::string &name, const dimension2di &value) +{ + SerializedDimension2d *attribute = new SerializedDimension2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a float value. +void SerializedAttributes::pushFloat(const std::string &name, f32 value) +{ + SerializedNumber *attribute = new SerializedNumber(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as an integer value. +void SerializedAttributes::pushInt(const std::string &name, s32 value) +{ + SerializedNumber *attribute = new SerializedNumber(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a line2df object. +void SerializedAttributes::pushLine2df(const std::string &name, const line2df &value) +{ + SerializedLine2d *attribute = new SerializedLine2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a line2di object. +void SerializedAttributes::pushLine2di(const std::string &name, const line2di &value) +{ + SerializedLine2d *attribute = new SerializedLine2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a line3df object. +void SerializedAttributes::pushLine3df(const std::string &name, const line3df &value) +{ + SerializedLine3d *attribute = new SerializedLine3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a line3di object. +void SerializedAttributes::pushLine3di(const std::string &name, const line3di &value) +{ + SerializedLine3d *attribute = new SerializedLine3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a Serializable object. +void SerializedAttributes::pushObject(const std::string &name, Serializable *object) +{ + SerializedObject *attribute = new SerializedObject(name, object); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a plane3df object. +void SerializedAttributes::pushPlane3df(const std::string &name, const plane3df &value) +{ + SerializedPlane3d *attribute = new SerializedPlane3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a plane3di object. +void SerializedAttributes::pushPlane3di(const std::string &name, const plane3di &value) +{ + SerializedPlane3d *attribute = new SerializedPlane3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a quaternion object. +void SerializedAttributes::pushQuaternion(const std::string &name, const quaternion &value) +{ + SerializedQuaternion *attribute = new SerializedQuaternion(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a rect<s32> object. +void SerializedAttributes::pushRect(const std::string &name, const rect<s32> &value) +{ + SerializedRect *attribute = new SerializedRect(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a string. +void SerializedAttributes::pushString(const std::string &name, const std::string &value) +{ + SerializedString *attribute = new SerializedString(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a wide string. +void SerializedAttributes::pushStringW(const std::string &name, const stringw &value) +{ + SerializedString *attribute = new SerializedString(name, stringc( value.c_str() ).c_str() ); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a vector2df object. +void SerializedAttributes::pushVector2df(const std::string &name, const vector2df &value) +{ + SerializedVector2d *attribute = new SerializedVector2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a vector2di object. +void SerializedAttributes::pushVector2di(const std::string &name, const vector2di &value) +{ + SerializedVector2d *attribute = new SerializedVector2d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a vector3df object. +void SerializedAttributes::pushVector3df(const std::string &name, const vector3df &value) +{ + SerializedVector3d *attribute = new SerializedVector3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + +// Pushes an attribute into the queue as a vector3di object. +void SerializedAttributes::pushVector3di(const std::string &name, const vector3di &value) +{ + SerializedVector3d *attribute = new SerializedVector3d(name, value); + pushAttribute(attribute); + attribute->drop(); +} + // Removes all attributes from the internal attribute queue. void SerializedAttributes::removeAttributes() { Modified: trunk/src/core/SerializedAttributes.h =================================================================== --- trunk/src/core/SerializedAttributes.h 2009-11-08 16:02:32 UTC (rev 148) +++ trunk/src/core/SerializedAttributes.h 2009-11-08 18:27:50 UTC (rev 149) @@ -51,9 +51,107 @@ //! Pulls the first attribute from the internal attribute queue. SerializedAttribute* pullAttribute(); + //! Pulls an attribute from the queue and interprete it as an aabbox3df object. + aabbox3df pullAabbox3df(); + //! RPulls an attribute from the queue and interprete it as an aabbox3di object. + aabbox3di pullAabbox3di(); + //! Pulls an attribute from the queue and interprete it as a boolean value. + bool pullBool(); + //! Pulls an attribute from the queue and interprete it as a SColor object. + SColor pullColor(); + //! Pulls an attribute from the queue and interprete it as a SColorf object. + SColorf pullColorf(); + //! Pulls an attribute from the queue and interprete it as a dimension2df object. + dimension2df pullDimension2df(); + //! Pulls an attribute from the queue and interprete it as a dimension2di object. + dimension2di pullDimension2di(); + //! Pulls an attribute from the queue and interprete it as a float value. + f32 pullFloat(); + //! Pulls an attribute from the queue and interprete it as an integer value. + s32 pullInt(); + //! Pulls an attribute from the queue and interprete it as a line2df object. + line2df pullLine2df(); + //! Pulls an attribute from the queue and interprete it as a line2di object. + line2di pullLine2di(); + //! Pulls an attribute from the queue and interprete it as a line3df object. + line3df pullLine3df(); + //! Pulls an attribute from the queue and interprete it as a line3di object. + line3di pullLine3di(); + //! Pulls an attribute from the queue and interprete it as a Serializable object. + Serializable* pullObject(); + //! Pulls an attribute from the queue and interprete it as a plane3df object. + plane3df pullPlane3df(); + //! Pulls an attribute from the queue and interprete it as a plane3di object. + plane3di pullPlane3di(); + //! Pulls an attribute from the queue and interprete it as a quaternion object. + quaternion pullQuaternion(); + //! Pulls an attribute from the queue and interprete it as a rect<s32> object. + rect<s32> pullRect(); + //! Pulls an attribute from the queue and interprete it as a string. + std::string pullString(); + //! Pulls an attribute from the queue and interprete it as a wide string. + stringw pullStringW(); + //! Pulls an attribute from the queue and interprete it as a vector2df object. + vector2df pullVector2df(); + //! Pulls an attribute from the queue and interprete it as a vector2di object. + vector2di pullVector2di(); + //! Pulls an attribute from the queue and interprete it as a vector3df object. + vector3df pullVector3df(); + //! Pulls an attribute from the queue and interprete it as a vector3di object. + vector3di pullVector3di(); + //! Pushes a new attribute into the internal attribute queue. void pushAttribute(SerializedAttribute *attribute); + //! Pushes an attribute into the queue as an aabbox3df object. + void pushAabbox3df(const std::string &name, const aabbox3df &value); + //! Pushes an attribute into the queue as an aabbox3di object. + void pushAabbox3di(const std::string &name, const aabbox3di &value); + //! Pushes an attribute into the queue as a boolean value. + void pushBool(const std::string &name, bool value); + //! Pushes an attribute into the queue as a SColor object. + void pushColor(const std::string &name, const SColor &value); + //! Pushes an attribute into the queue as a SColorf object. + void pushColorf(const std::string &name, const SColorf &value); + //! Pushes an attribute into the queue as a dimension2df object. + void pushDimension2df(const std::string &name, const dimension2df &value); + //! Pushes an attribute into the queue as a dimension2di object. + void pushDimension2di(const std::string &name, const dimension2di &value); + //! Pushes an attribute into the queue as a float value. + void pushFloat(const std::string &name, f32 value); + //! Pushes an attribute into the queue as an integer value. + void pushInt(const std::string &name, s32 value); + //! Pushes an attribute into the queue as a line2df object. + void pushLine2df(const std::string &name, const line2df &value); + //! Pushes an attribute into the queue as a line2di object. + void pushLine2di(const std::string &name, const line2di &value); + //! Pushes an attribute into the queue as a line3df object. + void pushLine3df(const std::string &name, const line3df &value); + //! Pushes an attribute into the queue as a line3di object. + void pushLine3di(const std::string &name, const line3di &value); + //! Pushes an attribute into the queue as a Serializable object. + void pushObject(const std::string &name, Serializable *object); + //! Pushes an attribute into the queue as a plane3df object. + void pushPlane3df(const std::string &name, const plane3df &value); + //! Pushes an attribute into the queue as a plane3di object. + void pushPlane3di(const std::string &name, const plane3di &value); + //! Pushes an attribute into the queue as a quaternion object. + void pushQuaternion(const std::string &name, const quaternion &value); + //! Pushes an attribute into the queue as a rect<s32> object. + void pushRect(const std::string &name, const rect<s32> &value); + //! Pushes an attribute into the queue as a string. + void pushString(const std::string &name, const std::string &value); + //! Pushes an attribute into the queue as a wide string. + void pushStringW(const std::string &name, const stringw &value); + //! Pushes an attribute into the queue as a vector2df object. + void pushVector2df(const std::string &name, const vector2df &value); + //! Pushes an attribute into the queue as a vector2di object. + void pushVector2di(const std::string &name, const vector2di &value); + //! Pushes an attribute into the queue as a vector3df object. + void pushVector3df(const std::string &name, const vector3df &value); + //! Pushes an attribute into the queue as a vector3di object. + void pushVector3di(const std::string &name, const vector3di &value); + private: // Private methods This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-08 16:02:46
|
Revision: 148 http://sirrf.svn.sourceforge.net/sirrf/?rev=148&view=rev Author: zccdark203 Date: 2009-11-08 16:02:32 +0000 (Sun, 08 Nov 2009) Log Message: ----------- Added the required code to perform I/O to XML files for serialized data. Also, I fixed some small issues with the memory management in Sirrf's serialization system. Modified Paths: -------------- trunk/src/core/Serializable.cpp trunk/src/core/Serializable.h trunk/src/core/SerializedAttribute.h trunk/src/core/SerializedAttributes.cpp trunk/src/core/SerializedAttributes.h Modified: trunk/src/core/Serializable.cpp =================================================================== --- trunk/src/core/Serializable.cpp 2009-11-07 21:13:58 UTC (rev 147) +++ trunk/src/core/Serializable.cpp 2009-11-08 16:02:32 UTC (rev 148) @@ -18,6 +18,7 @@ // Include files #include "Serializable.h" #include "GameManager.h" +#include "SerializedAttributesImpl.h" // Serializable class @@ -66,16 +67,114 @@ SerializedAttributes *attributes = new SerializedAttributes(); // Load contents from the XML file. - // TODO + while(file->read()) + { + switch(file->getNodeType()) + { + case io::EXN_ELEMENT: + if(file->getAttributeCount() == 0) + { + SerializedAttributes *object = new SerializedAttributes(); + + SerializedAttribute *attribute = new SerializedObject(stringc(file->getNodeName()).c_str(), object); + attributes->pushAttribute(attribute); + attribute->drop(); + + object->loadXML(file); + } + + else + { + SerializedAttribute *attribute = parseAttribute( stringc(file->getNodeName()).c_str(), + stringc(file->getAttributeValue(L"type")).c_str(), + stringc(file->getAttributeValue(L"value")).c_str() ); + attributes->pushAttribute(attribute); + attribute->drop(); + } + + break; + + case io::EXN_ELEMENT_END: + // This case has been encapsulated in order to gaurantee the initialisation of the + // "success" variable. + { + // Deserialize the attributes. + bool success = onDeserialization(attributes); + + // Clean up and return whether we've been successful or not. + // Please note that we don't rely on SerializedAttributes' internal removeAttributes method, + // because our SerializedAttributes might contain SerializedObject's which might contain + // pointers to resources that need to be released. + while(!attributes->isEmpty()) + { + SerializedAttribute *attribute = attributes->pullAttribute(); + + if(attribute->getObject() != NULL) + delete attribute->getObject(); + + attribute->drop(); + } + + attributes->drop(); + + return success; + } + + default: + break; + } + } + + // We might not have read all the required data, but we're going to try to deserialize it + // as there's also chance that we've all the data we need. + // Deserialize the attributes. bool success = onDeserialization(attributes); // Clean up and return whether we've been successful or not. - delete attributes; + // Please note that we don't rely on SerializedAttributes' internal removeAttributes method, + // because our SerializedAttributes might contain SerializedObject's which might contain + // pointers to resources that need to be released. + while(!attributes->isEmpty()) + { + SerializedAttribute *attribute = attributes->pullAttribute(); + if(attribute->getObject() != NULL) + delete attribute->getObject(); + + attribute->drop(); + } + + attributes->drop(); + return success; +} +// Creates a new attribute with the given parameters. +SerializedAttribute* Serializable::parseAttribute(const std::string &name, const std::string &type, + const std::string &value) +{ + SerializedAttribute *attribute = NULL; + + if(type == "aabbox3d") attribute = new SerializedAabbox3d(name, aabbox3df()); + else if(type == "bool") attribute = new SerializedBool(name, false); + else if(type == "color") attribute = new SerializedColor(name, SColor()); + else if(type == "dimension2d") attribute = new SerializedDimension2d(name, dimension2df()); + else if(type == "line2d") attribute = new SerializedLine2d(name, line2df()); + else if(type == "line3d") attribute = new SerializedLine3d(name, line3df()); + else if(type == "number") attribute = new SerializedNumber(name, 0); + else if(type == "plane3d") attribute = new SerializedPlane3d(name, plane3df()); + else if(type == "quaternion") attribute = new SerializedQuaternion(name, quaternion()); + else if(type == "rect") attribute = new SerializedRect(name, rect<s32>()); + else if(type == "string") attribute = new SerializedString(name, ""); + else if(type == "vector2d") attribute = new SerializedVector2d(name, vector2df()); + else if(type == "vector3d") attribute = new SerializedVector3d(name, vector3df()); + + if(attribute != NULL) + attribute->setString(value); + + return attribute; } // Saves this object to a XML file. @@ -92,6 +191,9 @@ IXMLWriter *xml = fileSystem->createXMLWriter(file); + // Write header to the file. + xml->writeXMLHeader(); + // Save our attributes to the file. bool success = saveXML(xml); @@ -106,22 +208,59 @@ bool Serializable::saveXML(IXMLWriter *file) { // Check if we got a valid pointer. - if(file != NULL) + if(file == NULL) return false; // Create a SerializedAttributes object to hold our attributes. SerializedAttributes *attributes = new SerializedAttributes(); + // Serialize the attributes. + if(!onSerialization(attributes)) + { + attributes->drop(); + return false; + } + // Save contents to the XML file. - // TODO + while(!attributes->isEmpty()) + { + // Pull an attribute from the attributes collection. + SerializedAttribute *attribute = attributes->pullAttribute(); - // Serialize the attributes. - bool success = onSerialization(attributes); + // Check the type of the attribute. + if(attribute->getType() == "object") + { + if(attribute->getName() != "") + { + file->writeElement( stringw( stringc( attribute->getName().c_str() ).c_str() ).c_str() ); + file->writeLineBreak(); - // Clean up and return whether we've been successful or not. - delete attributes; + attribute->getObject()->saveXML(file); - return success; + file->writeClosingTag( stringw( stringc( attribute->getName().c_str() ).c_str() ).c_str()); + file->writeLineBreak(); + } + + else + attribute->getObject()->saveXML(file); + } + + else + { + file->writeElement( stringw( stringc( attribute->getName().c_str() ).c_str() ).c_str(), true, + L"type", stringw( stringc( attribute->getType().c_str() ).c_str() ).c_str(), + L"value", attribute->getStringW().c_str()); + file->writeLineBreak(); + } + + // Drop the reference to the attribute. + attribute->drop(); + } + + // Clean up. + attributes->drop(); + + return true; } // End of File Modified: trunk/src/core/Serializable.h =================================================================== --- trunk/src/core/Serializable.h 2009-11-07 21:13:58 UTC (rev 147) +++ trunk/src/core/Serializable.h 2009-11-08 16:02:32 UTC (rev 148) @@ -28,6 +28,7 @@ // Forward declarations class SerializedAttributes; +class SerializedAttribute; // Serializable class @@ -64,6 +65,12 @@ //! Saves this object to a XML file through the given IXMLWriter object. //! @param file Pointer to the IXMLWriter object that will be used. bool saveXML(IXMLWriter *file); + +private: + + // Private methods + SerializedAttribute* parseAttribute(const std::string &name, const std::string &type, + const std::string &value); }; #endif // __SERIALIZABLE_H__ Modified: trunk/src/core/SerializedAttribute.h =================================================================== --- trunk/src/core/SerializedAttribute.h 2009-11-07 21:13:58 UTC (rev 147) +++ trunk/src/core/SerializedAttribute.h 2009-11-08 16:02:32 UTC (rev 148) @@ -64,7 +64,7 @@ //! Returns the value of this attribute as a line3di. virtual line3di getLine3di() const { return line3di(); }; //! Returns the value of this attribute as a Serializable object. - virtual Serializable* getSerializable() const { return NULL; } + virtual Serializable* getObject() const { return NULL; } //! Returns the value of this attribute as a plane3df. virtual plane3df getPlane3df() const { return plane3df(); }; //! Returns the value of this attribute as a plane3di. Modified: trunk/src/core/SerializedAttributes.cpp =================================================================== --- trunk/src/core/SerializedAttributes.cpp 2009-11-07 21:13:58 UTC (rev 147) +++ trunk/src/core/SerializedAttributes.cpp 2009-11-08 16:02:32 UTC (rev 148) @@ -31,6 +31,12 @@ removeAttributes(); } +// Returns whether there are attributes in the internal queue. +bool SerializedAttributes::isEmpty() const +{ + return mQueue.empty(); +} + // Moves all attributes from this object to the given object. void SerializedAttributes::moveAttributesTo(SerializedAttributes *attributes) { @@ -84,7 +90,7 @@ { while(!mQueue.empty()) { - delete mQueue.front(); + mQueue.front()->drop(); mQueue.pop(); } } Modified: trunk/src/core/SerializedAttributes.h =================================================================== --- trunk/src/core/SerializedAttributes.h 2009-11-07 21:13:58 UTC (rev 147) +++ trunk/src/core/SerializedAttributes.h 2009-11-08 16:02:32 UTC (rev 148) @@ -40,6 +40,9 @@ ~SerializedAttributes(); // Public methods + //! Returns whether there are attributes in the internal queue. + bool isEmpty() const; + // Serializes this object. bool onSerialization(SerializedAttributes *attributes); // Deserializes this object. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-07 21:14:15
|
Revision: 147 http://sirrf.svn.sourceforge.net/sirrf/?rev=147&view=rev Author: zccdark203 Date: 2009-11-07 21:13:58 +0000 (Sat, 07 Nov 2009) Log Message: ----------- Made the HasSlots typedef for sigslot::has_slots. In terms of features nothing has changed. This is a cosmetic change; the code will look slightly cleaner now. Modified Paths: -------------- trunk/CHANGES trunk/src/core/Entity.h trunk/src/core/EntityComponent.h trunk/src/core/GameState.h trunk/src/dependencies.h trunk/src/scripting/core/ScriptedEvent.h Modified: trunk/CHANGES =================================================================== --- trunk/CHANGES 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/CHANGES 2009-11-07 21:13:58 UTC (rev 147) @@ -2,6 +2,8 @@ Sirrf version 0.3.0 (SVN) - Changes ========================================================================== + * Made the HasSlots typedef for sigslot::has_slots. + * Updated to Irrlicht 1.6 and AngelScript 2.17.2. * The AssetGroup class didn't remove its AssetProcessors. This has been Modified: trunk/src/core/Entity.h =================================================================== --- trunk/src/core/Entity.h 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/src/core/Entity.h 2009-11-07 21:13:58 UTC (rev 147) @@ -39,7 +39,7 @@ //! </Components> //! </Entity> //! \endcode -class Entity : public sigslot::has_slots<>, public ReferenceCounted, public HasEvents +class Entity : public ReferenceCounted, public HasEvents, public HasSlots { public: Modified: trunk/src/core/EntityComponent.h =================================================================== --- trunk/src/core/EntityComponent.h 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/src/core/EntityComponent.h 2009-11-07 21:13:58 UTC (rev 147) @@ -27,7 +27,7 @@ // EntityComponent class //! Abstraction base class for adding new functionalities to entities. -class EntityComponent : public sigslot::has_slots<>, public ReferenceCounted +class EntityComponent : public ReferenceCounted, public HasSlots { friend class ScriptedEntityComponent; Modified: trunk/src/core/GameState.h =================================================================== --- trunk/src/core/GameState.h 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/src/core/GameState.h 2009-11-07 21:13:58 UTC (rev 147) @@ -25,7 +25,7 @@ // GameState class //! The GameState object is a base class which is implemented through derived sub-classes. -class GameState : public sigslot::has_slots<>, public ReferenceCounted +class GameState : public ReferenceCounted, public HasSlots { friend class ScriptedGameState; Modified: trunk/src/dependencies.h =================================================================== --- trunk/src/dependencies.h 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/src/dependencies.h 2009-11-07 21:13:58 UTC (rev 147) @@ -69,4 +69,8 @@ using namespace io; using namespace gui; + +// Typedefs +typedef sigslot::has_slots<> HasSlots; + #endif Modified: trunk/src/scripting/core/ScriptedEvent.h =================================================================== --- trunk/src/scripting/core/ScriptedEvent.h 2009-11-07 20:54:12 UTC (rev 146) +++ trunk/src/scripting/core/ScriptedEvent.h 2009-11-07 21:13:58 UTC (rev 147) @@ -27,7 +27,7 @@ // ScriptedEvent class //! Internal class for allowing AngelScript to interface with the event system. -class ScriptedEvent : public sigslot::has_slots<>, public ReferenceCounted +class ScriptedEvent : public ReferenceCounted, public HasSlots { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-07 20:54:21
|
Revision: 146 http://sirrf.svn.sourceforge.net/sirrf/?rev=146&view=rev Author: zccdark203 Date: 2009-11-07 20:54:12 +0000 (Sat, 07 Nov 2009) Log Message: ----------- Refined Sirrf's serialization system; Serializable objects can now also be stored in a class derived from SerializedAttribute, SerializedObject. Please keep in mind that Serializable are inherintently NOT reference counted (we want to avoid the diamond problem). In general this should not be a problem, though. Modified Paths: -------------- trunk/src/core/Serializable.h trunk/src/core/SerializedAttribute.h trunk/src/core/SerializedAttributes.cpp trunk/src/core/SerializedAttributes.h trunk/src/core/SerializedAttributesImpl.cpp trunk/src/core/SerializedAttributesImpl.h Modified: trunk/src/core/Serializable.h =================================================================== --- trunk/src/core/Serializable.h 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/Serializable.h 2009-11-07 20:54:12 UTC (rev 146) @@ -13,14 +13,23 @@ // // ///////////////////////////////////////////////////////////////////////////// +// Makes sure that SerializedAttributes can inherit from Serializable. +#ifndef __SERIALIZABLE_H_UPPER_TIER__ + +#include "SerializedAttributes.h" + #ifndef __SERIALIZABLE_H__ #define __SERIALIZABLE_H__ +#define __SERIALIZABLE_H_UPPER_TIER__ // Include files #include "../dependencies.h" -#include "SerializedAttributes.h" +// Forward declarations +class SerializedAttributes; + + // Serializable class //! The Serializable class provides a base for classes that need serialization. //! By deriving from this class, the derived class gains all required methods @@ -57,4 +66,6 @@ bool saveXML(IXMLWriter *file); }; -#endif +#endif // __SERIALIZABLE_H__ + +#endif // __SERIALIZABLE_H_UPPER_TIER__ Modified: trunk/src/core/SerializedAttribute.h =================================================================== --- trunk/src/core/SerializedAttribute.h 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/SerializedAttribute.h 2009-11-07 20:54:12 UTC (rev 146) @@ -18,10 +18,12 @@ // Include files #include "../dependencies.h" +#include "ReferenceCounted.h" +#include "Serializable.h" // SerializedAttribute class -class SerializedAttribute +class SerializedAttribute : public ReferenceCounted { public: @@ -61,6 +63,8 @@ virtual line3df getLine3df() const { return line3df(); }; //! Returns the value of this attribute as a line3di. virtual line3di getLine3di() const { return line3di(); }; + //! Returns the value of this attribute as a Serializable object. + virtual Serializable* getSerializable() const { return NULL; } //! Returns the value of this attribute as a plane3df. virtual plane3df getPlane3df() const { return plane3df(); }; //! Returns the value of this attribute as a plane3di. @@ -108,6 +112,8 @@ virtual void setLine3df(const line3df &value) {}; //! Sets the value of this attribute as a line3di object. virtual void setLine3di(const line3di &value) {}; + //! Sets the value of this attribute as a Serializable object. + virtual void setObject(Serializable *object) {}; //! Sets the value of this attribute as a plane3df object. virtual void setPlane3df(const plane3df &value) {}; //! Sets the value of this attribute as a plane3di object. Modified: trunk/src/core/SerializedAttributes.cpp =================================================================== --- trunk/src/core/SerializedAttributes.cpp 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/SerializedAttributes.cpp 2009-11-07 20:54:12 UTC (rev 146) @@ -31,6 +31,31 @@ removeAttributes(); } +// Moves all attributes from this object to the given object. +void SerializedAttributes::moveAttributesTo(SerializedAttributes *attributes) +{ + // Remove attributes from the receiver. + attributes->removeAttributes(); + + // Move our attributes to the receiver. + while(!mQueue.empty()) + attributes->pushAttribute(pullAttribute()); +} + +// Serializes this object. +bool SerializedAttributes::onSerialization(SerializedAttributes *attributes) +{ + moveAttributesTo(attributes); + return true; +} + +// Deserializes this object. +bool SerializedAttributes::onDeserialization(SerializedAttributes *attributes) +{ + attributes->moveAttributesTo(this); + return true; +} + // Pulls the first attribute from the internal attribute queue. SerializedAttribute* SerializedAttributes::pullAttribute() { @@ -50,6 +75,7 @@ // Pushes a new attribute into the internal attribute queue. void SerializedAttributes::pushAttribute(SerializedAttribute *attribute) { + attribute->grab(); mQueue.push(attribute); } Modified: trunk/src/core/SerializedAttributes.h =================================================================== --- trunk/src/core/SerializedAttributes.h 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/SerializedAttributes.h 2009-11-07 20:54:12 UTC (rev 146) @@ -18,13 +18,18 @@ // Include files #include "../dependencies.h" +#include "ReferenceCounted.h" +#include "Serializable.h" #include "SerializedAttribute.h" +// Forward declarations +class SerializedAttribute; + // SerializedAttributes class //! The SerializaedAttributes class describes a FIFO collection of serialized //! attributes. This class provides various methods to manage these attributes. -class SerializedAttributes +class SerializedAttributes : public ReferenceCounted, public Serializable { public: @@ -35,6 +40,11 @@ ~SerializedAttributes(); // Public methods + // Serializes this object. + bool onSerialization(SerializedAttributes *attributes); + // Deserializes this object. + bool onDeserialization(SerializedAttributes *attributes); + //! Pulls the first attribute from the internal attribute queue. SerializedAttribute* pullAttribute(); @@ -45,6 +55,7 @@ // Private methods void removeAttributes(); + void moveAttributesTo(SerializedAttributes *attributes); // Private members queue<SerializedAttribute*> mQueue; Modified: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-07 20:54:12 UTC (rev 146) @@ -448,6 +448,30 @@ } +// SerializedObject class +// SerializedObject constructor. +SerializedObject::SerializedObject(const std::string &name, Serializable *object) +: SerializedAttribute(name, "object") +{ + mObject = object; +} + +// SerializedObject deconstructor. +SerializedObject::~SerializedObject() +{ +} + +Serializable* SerializedObject::getObject() const +{ + return mObject; +} + +void SerializedObject::setObject(Serializable *object) +{ + mObject = object; +} + + // SerializedPlane3d class // SerializedPlane3d constructor (plane3df). SerializedPlane3d::SerializedPlane3d(const std::string &name, const plane3df &value) Modified: trunk/src/core/SerializedAttributesImpl.h =================================================================== --- trunk/src/core/SerializedAttributesImpl.h 2009-11-07 18:17:55 UTC (rev 145) +++ trunk/src/core/SerializedAttributesImpl.h 2009-11-07 20:54:12 UTC (rev 146) @@ -322,6 +322,36 @@ }; +// SerializedObject class +//! SerializedAttribute subclass for Serializable objects. +//! @note The Serializable class doesn't derive from the ReferencedCounted. So it's up to the +//! programmer to make sure that the referenced object is available when it's needed. +//! Normally this shouldn't be a problem as SerializedAttribute subclasses are supposed +//! to be used (and deleted) shortly after initialisation. +class SerializedObject : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param object Pointer to Serializable object. + SerializedObject(const std::string &name, Serializable *object); + //! Deconstructor + ~SerializedObject(); + + // Public methods + Serializable* getObject() const; + + void setObject(Serializable *object); + +private: + + // Private members + Serializable *mObject; +}; + + // SerializedPlane3d class //! SerializedAttribute subclass for serialized plane3d objects. class SerializedPlane3d : public SerializedAttribute This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zcc...@us...> - 2009-11-07 18:18:06
|
Revision: 145 http://sirrf.svn.sourceforge.net/sirrf/?rev=145&view=rev Author: zccdark203 Date: 2009-11-07 18:17:55 +0000 (Sat, 07 Nov 2009) Log Message: ----------- Created serialization wrapper classes for various primitive types and most of Irrlicht's core classes. Modified Paths: -------------- trunk/build/CMake/CMakeLists.txt trunk/build/CodeBlocks/sirrf.cbp trunk/src/core/SerializedAttribute.cpp trunk/src/core/SerializedAttribute.h Added Paths: ----------- trunk/src/core/SerializedAttributesImpl.cpp trunk/src/core/SerializedAttributesImpl.h Modified: trunk/build/CMake/CMakeLists.txt =================================================================== --- trunk/build/CMake/CMakeLists.txt 2009-10-26 18:54:17 UTC (rev 144) +++ trunk/build/CMake/CMakeLists.txt 2009-11-07 18:17:55 UTC (rev 145) @@ -58,6 +58,7 @@ ${SOURCE_DIR}core/Serializable.cpp ${SOURCE_DIR}core/SerializedAttribute.cpp ${SOURCE_DIR}core/SerializedAttributes.cpp + ${SOURCE_DIR}core/SerializedAttributesImpl.cpp # /src/game ${SOURCE_DIR}game/InitState.cpp Modified: trunk/build/CodeBlocks/sirrf.cbp =================================================================== --- trunk/build/CodeBlocks/sirrf.cbp 2009-10-26 18:54:17 UTC (rev 144) +++ trunk/build/CodeBlocks/sirrf.cbp 2009-11-07 18:17:55 UTC (rev 145) @@ -137,6 +137,8 @@ <Unit filename="../../src/core/SerializedAttribute.h" /> <Unit filename="../../src/core/SerializedAttributes.cpp" /> <Unit filename="../../src/core/SerializedAttributes.h" /> + <Unit filename="../../src/core/SerializedAttributesImpl.cpp" /> + <Unit filename="../../src/core/SerializedAttributesImpl.h" /> <Unit filename="../../src/dependencies.h" /> <Unit filename="../../src/game/InitState.cpp" /> <Unit filename="../../src/game/InitState.h" /> Modified: trunk/src/core/SerializedAttribute.cpp =================================================================== --- trunk/src/core/SerializedAttribute.cpp 2009-10-26 18:54:17 UTC (rev 144) +++ trunk/src/core/SerializedAttribute.cpp 2009-11-07 18:17:55 UTC (rev 145) @@ -19,8 +19,8 @@ // SerializedAttribute class // SerializedAttribute constructor. -SerializedAttribute::SerializedAttribute(const std::string &name) -: mName(name) +SerializedAttribute::SerializedAttribute(const std::string &name, const std::string &type) +: mName(name), mType(type) { } @@ -35,4 +35,10 @@ return mName; } +// Gets the type of this attribute as a string. +const std::string& SerializedAttribute::getType() const +{ + return mType; +} + // End of File Modified: trunk/src/core/SerializedAttribute.h =================================================================== --- trunk/src/core/SerializedAttribute.h 2009-10-26 18:54:17 UTC (rev 144) +++ trunk/src/core/SerializedAttribute.h 2009-11-07 18:17:55 UTC (rev 145) @@ -26,19 +26,122 @@ public: // Initialisation and deinitialisation - //! Constructor - SerializedAttribute(const std::string &name); //! Deconstructor virtual ~SerializedAttribute(); // Public methods //! Gets the name of this attribute. const std::string& getName() const; + //! Gets the type of this attribute as a string. + const std::string& getType() const; + //! Returns the value of this attribute as an aabbox3df. + virtual aabbox3df getAabbox3df() const { return aabbox3df(); }; + //! Returns the value of this attribute as an aabbox3di. + virtual aabbox3di getAabbox3di() const { return aabbox3di(); }; + //! Returns the value of this attribute as an bool. + virtual bool getBool() const { return false; } + //! Returns the value of this attribute as a SColor. + virtual SColor getColor() const { return SColor(255, 255, 255, 255); }; + //! Returns the value of this attribute as a SColorf. + virtual SColorf getColorf() const { return SColorf(1.0f, 1.0f, 1.0f, 1.0f); }; + //! Returns the value of this attribute as a dimension2df. + virtual dimension2df getDimension2df() const { return dimension2df(); }; + //! Returns the value of this attribute as a dimension2di. + virtual dimension2di getDimension2di() const { return dimension2di(); }; + //! Returns the value of this attribute as a float. + virtual f32 getFloat() const { return 0.0f; }; + //! Returns the value of this attribute as an integer. + virtual s32 getInt() const { return 0; }; + //! Returns the value of this attribute as a line2df. + virtual line2df getLine2df() const { return line2df(); }; + //! Returns the value of this attribute as a line2di. + virtual line2di getLine2di() const { return line2di(); }; + //! Returns the value of this attribute as a line3df. + virtual line3df getLine3df() const { return line3df(); }; + //! Returns the value of this attribute as a line3di. + virtual line3di getLine3di() const { return line3di(); }; + //! Returns the value of this attribute as a plane3df. + virtual plane3df getPlane3df() const { return plane3df(); }; + //! Returns the value of this attribute as a plane3di. + virtual plane3di getPlane3di() const { return plane3di(); }; + //! Returns the value of this attribute as a quaternion. + virtual quaternion getQuaternion() const { return quaternion(); }; + //! Returns the value of this attribute as a rect<s32>. + virtual rect<s32> getRect() const { return rect<s32>(); }; + //! Returns the value of this attribute as a string. + virtual std::string getString() const { return std::string(""); }; + //! Returns the value of this attribute as a wide string. + virtual stringw getStringW() const { return stringw( stringc( getString().c_str() ).c_str() ); }; + //! Returns the value of this attribute as a vector2df. + virtual vector2df getVector2df() const { return vector2df(); }; + //! Returns the value of this attribute as a vector2di. + virtual vector2di getVector2di() const { return vector2di(); }; + //! Returns the value of this attribute as a vector3df. + virtual vector3df getVector3df() const { return vector3df(); }; + //! Returns the value of this attribute as a vector3di. + virtual vector3di getVector3di() const { return vector3di(); }; + + //! Sets the value of this attribute as a aabbox3df. + virtual void setAabbox3df(const aabbox3df &value) {}; + //! Sets the value of this attribute as a aabbox3di. + virtual void setAabbox3di(const aabbox3di &value) {}; + //! Sets the value of this attribute as a boolean value. + virtual void setBool(bool value) {}; + //! Sets the value of this attribute as a SColor object. + virtual void setColor(const SColor &value) {}; + //! Sets the value of this attribute as a SColorf object. + virtual void setColorf(const SColorf &value) {}; + //! Sets the value of this attribute as a dimension2df object. + virtual void setDimension2df(const dimension2df &value) {}; + //! Sets the value of this attribute as a dimension2di object. + virtual void setDimension2di(const dimension2di &value) {}; + //! Sets the value of this attribute as float value. + virtual void setFloat(f32 value) {}; + //! Sets the value of this attribute as an integer value. + virtual void setInt(s32 value) {}; + //! Sets the value of this attribute as a line2df object. + virtual void setLine2df(const line2df &value) {}; + //! Sets the value of this attribute as a line2di object. + virtual void setLine2di(const line2di &value) {}; + //! Sets the value of this attribute as a line3df object. + virtual void setLine3df(const line3df &value) {}; + //! Sets the value of this attribute as a line3di object. + virtual void setLine3di(const line3di &value) {}; + //! Sets the value of this attribute as a plane3df object. + virtual void setPlane3df(const plane3df &value) {}; + //! Sets the value of this attribute as a plane3di object. + virtual void setPlane3di(const plane3di &value) {}; + //! Sets the value of this attribute as a quaternion object. + virtual void setQuaternion(const quaternion &value) {}; + //! Sets the value of this attribute as a rect<s32> object. + virtual void setRect(const rect<s32> &value) {}; + //! Sets the value of this attribute as a string. + virtual void setString(const std::string &value) {}; + //! Sets the value of this attribute as a wide string. + virtual void setStringW(const stringw &value) { setString( stringc( value.c_str() ).c_str() ); }; + //! Sets the value of this attribute as a vector2df object. + virtual void setVector2df(const vector2df &value) {}; + //! Sets the value of this attribute as a vector2di object. + virtual void setVector2di(const vector2di &value) {}; + //! Sets the value of this attribute as a vector3df object. + virtual void setVector3df(const vector3df &value) {}; + //! Sets the value of this attribute as a vector3di object. + virtual void setVector3di(const vector3di &value) {}; + +protected: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param type String describing the type of this attribute. + SerializedAttribute(const std::string &name, const std::string &type); + private: // Private members std::string mName; + std::string mType; }; #endif Added: trunk/src/core/SerializedAttributesImpl.cpp =================================================================== --- trunk/src/core/SerializedAttributesImpl.cpp (rev 0) +++ trunk/src/core/SerializedAttributesImpl.cpp 2009-11-07 18:17:55 UTC (rev 145) @@ -0,0 +1,734 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: SerializedAttributesImpl.cpp +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : This file contains various implementations of the +// SerializedAttribute class. +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +// Include files +#include "SerializedAttributesImpl.h" + + +// SerializedAabbox3d class +// SerializedAabbox3d constructor (aabbox3di). +SerializedAabbox3d::SerializedAabbox3d(const std::string &name, const aabbox3di &value) +: SerializedAttribute(name, "aabbox3d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedAabbox3d constructor (aabbox3df). +SerializedAabbox3d::SerializedAabbox3d(const std::string &name, const aabbox3df &value) +: SerializedAttribute(name, "aabbox3d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedAabbox3d deconstructor. +SerializedAabbox3d::~SerializedAabbox3d() +{ +} + +aabbox3df SerializedAabbox3d::getAabbox3df() const +{ + return getAabbox3df(); +} + +aabbox3df SerializedAabbox3d::getAabbox3df() +{ + return convert<f32, f64>(mValue); +} + +aabbox3di SerializedAabbox3d::getAabbox3di() const +{ + return getAabbox3di(); +} + +aabbox3di SerializedAabbox3d::getAabbox3di() +{ + return convert<s32, f64>(mValue); +} + +std::string SerializedAabbox3d::getString() const +{ + SerializedVector3d MaxEdge("", mValue.MaxEdge); + SerializedVector3d MinEdge("", mValue.MinEdge); + + stringstream ss; + ss << "aabbox3d(" << MaxEdge.getString() << ", " << MinEdge.getString() << ")"; + + return ss.str(); +} + +void SerializedAabbox3d::setAabbox3df(const aabbox3df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedAabbox3d::setAabbox3di(const aabbox3di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedBool class +// SerializedBool constructor. +SerializedBool::SerializedBool(const std::string &name, bool value) +: SerializedAttribute(name, "bool") +{ + mValue = value; +} + +// SerializedBool deconstructor. +SerializedBool::~SerializedBool() +{ +} + +// Reimplementations of superclass' methods. +bool SerializedBool::getBool() const +{ + return mValue; +} + +f32 SerializedBool::getFloat() const +{ + return (mValue) ? 1.0f : 0.0f; +} + +s32 SerializedBool::getInt() const +{ + return (mValue) ? 1 : 0; +} + +std::string SerializedBool::getString() const +{ + return (mValue) ? "true" : "false"; +} + +void SerializedBool::setBool(bool value) +{ + mValue = value; +} + +void SerializedBool::setFloat(f32 value) +{ + mValue = (value != 0.0f); +} + +void SerializedBool::setInt(s32 value) +{ + mValue = (value != 0); +} + +void SerializedBool::setString(const std::string &value) +{ + mValue = (value == "true"); +} + + +// SerializedColor class +// SerializedColor constructor. +SerializedColor::SerializedColor(const std::string &name, const SColorf &value) +: SerializedAttribute(name, "color") +{ + mValue = value; +} + +// SerializedColor deconstructor. +SerializedColor::~SerializedColor() +{ +} + +// Reimplementations of superclass' methods. +SColor SerializedColor::getColor() const +{ + return mValue.toSColor(); +} + +SColorf SerializedColor::getColorf() const +{ + return mValue; +} + +f32 SerializedColor::getFloat() const +{ + return (f32)mValue.toSColor().color; +} + +s32 SerializedColor::getInt() const +{ + return (s32)mValue.toSColor().color; +} + +std::string SerializedColor::getString() const +{ + stringstream ss; + ss << "color(" << mValue.getAlpha() << ", " << mValue.getRed() << ", " + << mValue.getGreen() << ", " << mValue.getBlue() << ")"; + + return ss.str(); +} + +void SerializedColor::setColor(const SColor &value) +{ + mValue = value; +} + +void SerializedColor::setColorf(const SColorf &value) +{ + mValue = value; +} + +void SerializedColor::setFloat(f32 value) +{ + setInt((s32)value); +} + +void SerializedColor::setInt(s32 value) +{ + mValue = SColor(value); +} + + +// SerializedDimension2d class +// SerializedDimension2d constructor (dimension2df). +SerializedDimension2d::SerializedDimension2d(const std::string &name, const dimension2df &value) +: SerializedAttribute(name, "dimension2d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedDimension2d constructor (dimension2di). +SerializedDimension2d::SerializedDimension2d(const std::string &name, const dimension2di &value) +: SerializedAttribute(name, "dimension2d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedDimension2d deconstructor. +SerializedDimension2d::~SerializedDimension2d() +{ +} + +std::string SerializedDimension2d::getString() const +{ + stringstream ss; + ss << "dimension2d(" << mValue.Width << ", " << mValue.Height << ")"; + + return ss.str(); +} + +dimension2df SerializedDimension2d::getDimension2df() const +{ + return getDimension2df(); +} + +dimension2df SerializedDimension2d::getDimension2df() +{ + return convert<f32, f64>(mValue); +} + +dimension2di SerializedDimension2d::getDimension2di() const +{ + return getDimension2di(); +} + +dimension2di SerializedDimension2d::getDimension2di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedDimension2d::setDimension2df(const dimension2df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedDimension2d::setDimension2di(const dimension2di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedLine2d class +// SerializedLine2d constructor (line2df). +SerializedLine2d::SerializedLine2d(const std::string &name, const line2df &value) +: SerializedAttribute(name, "line2d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedLine2d constructor (line2di). +SerializedLine2d::SerializedLine2d(const std::string &name, const line2di &value) +: SerializedAttribute(name, "line2d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedLine2d deconstructor. +SerializedLine2d::~SerializedLine2d() +{ +} + +std::string SerializedLine2d::getString() const +{ + SerializedVector2d start("", mValue.start); + SerializedVector2d end("", mValue.end); + + stringstream ss; + ss << "line2d(" << start.getString() << ", " << end.getString() << ")"; + + return ss.str(); +} + +line2df SerializedLine2d::getLine2df() const +{ + return getLine2df(); +} + +line2df SerializedLine2d::getLine2df() +{ + return convert<f32, f64>(mValue); +} + +line2di SerializedLine2d::getLine2di() const +{ + return getLine2di(); +} + +line2di SerializedLine2d::getLine2di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedLine2d::setLine2df(const line2df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedLine2d::setLine2di(const line2di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedLine3d class +// SerializedLine3d constructor (line3df). +SerializedLine3d::SerializedLine3d(const std::string &name, const line3df &value) +: SerializedAttribute(name, "line3d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedLine3d constructor (line3di). +SerializedLine3d::SerializedLine3d(const std::string &name, const line3di &value) +: SerializedAttribute(name, "line3d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedLine3d deconstructor. +SerializedLine3d::~SerializedLine3d() +{ +} + +std::string SerializedLine3d::getString() const +{ + SerializedVector3d start("", mValue.start); + SerializedVector3d end("", mValue.end); + + stringstream ss; + ss << "line3d(" << start.getString() << ", " << end.getString() << ")"; + + return ss.str(); +} + +line3df SerializedLine3d::getLine3df() const +{ + return getLine3df(); +} + +line3df SerializedLine3d::getLine3df() +{ + return convert<f32, f64>(mValue); +} + +line3di SerializedLine3d::getLine3di() const +{ + return getLine3di(); +} + +line3di SerializedLine3d::getLine3di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedLine3d::setLine3df(const line3df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedLine3d::setLine3di(const line3di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedNumber class +// SerializedNumber constructor. +SerializedNumber::SerializedNumber(const std::string &name, s32 value) +: SerializedAttribute(name, "number") +{ + mValue = (f64)value; +} + +// SerializedNumber constructor. +SerializedNumber::SerializedNumber(const std::string &name, f32 value) +: SerializedAttribute(name, "number") +{ + mValue = (f64)value; +} + +// SerializedNumber deconstructor. +SerializedNumber::~SerializedNumber() +{ +} + +// Reimplementations of superclass' methods. +bool SerializedNumber::getBool() const +{ + return (mValue != 0.0f); +} + +f32 SerializedNumber::getFloat() const +{ + return (f32)mValue; +} + +s32 SerializedNumber::getInt() const +{ + return (s32)mValue; +} + +std::string SerializedNumber::getString() const +{ + stringstream ss; + ss << mValue; + + return ss.str(); +} + +void SerializedNumber::setBool(bool value) +{ + mValue = (f64)value; +} + +void SerializedNumber::setFloat(f32 value) +{ + mValue = (f64)value; +} + +void SerializedNumber::setInt(s32 value) +{ + mValue = (f64)value; +} + +void SerializedNumber::setString(const std::string &value) +{ + stringstream ss(value); + ss >> mValue; +} + + +// SerializedPlane3d class +// SerializedPlane3d constructor (plane3df). +SerializedPlane3d::SerializedPlane3d(const std::string &name, const plane3df &value) +: SerializedAttribute(name, "plane3d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedPlane3d constructor (plane3di). +SerializedPlane3d::SerializedPlane3d(const std::string &name, const plane3di &value) +: SerializedAttribute(name, "plane3d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedPlane3d deconstructor. +SerializedPlane3d::~SerializedPlane3d() +{ +} + +std::string SerializedPlane3d::getString() const +{ + SerializedVector3d normal("", mValue.Normal); + + stringstream ss; + ss << "plane3d(" << normal.getString() << ", " << mValue.D << ")"; + + return ss.str(); +} + +plane3df SerializedPlane3d::getPlane3df() const +{ + return getPlane3df(); +} + +plane3df SerializedPlane3d::getPlane3df() +{ + return convert<f32, f64>(mValue); +} + +plane3di SerializedPlane3d::getPlane3di() const +{ + return getPlane3di(); +} + +plane3di SerializedPlane3d::getPlane3di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedPlane3d::setPlane3df(const plane3df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedPlane3d::setPlane3di(const plane3di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedQuaternion class +// SerializedQuaternion constructor. +SerializedQuaternion::SerializedQuaternion(const std::string &name, const quaternion &value) +: SerializedAttribute(name, "quaternion") +{ + mValue = value; +} + +// SerializedQuaternion deconstructor. +SerializedQuaternion::~SerializedQuaternion() +{ +} + +std::string SerializedQuaternion::getString() const +{ + stringstream ss; + ss << "quaternion(" << mValue.X << ", " << mValue.Y << ", " << mValue.Z << ", " << mValue.W << ")"; + + return ss.str(); +} + +quaternion SerializedQuaternion::getQuaternion() const +{ + return mValue; +} + +void SerializedQuaternion::setQuaternion(const quaternion &value) +{ + mValue = value; +} + + +// SerializedRect class +// SerializedRect constructor. +SerializedRect::SerializedRect(const std::string &name, const rect<s32> &value) +: SerializedAttribute(name, "rect") +{ + mValue = value; +} + +// SerializedRect deconstructor. +SerializedRect::~SerializedRect() +{ +} + +std::string SerializedRect::getString() const +{ + SerializedVector2d LowerRightCorner("", mValue.LowerRightCorner); + SerializedVector2d UpperLeftCorner("", mValue.UpperLeftCorner); + + stringstream ss; + ss << "rect(" << UpperLeftCorner.getString() << ", " << LowerRightCorner.getString() << ")"; + + return ss.str(); +} + +rect<s32> SerializedRect::getRect() const +{ + return mValue; +} + +void SerializedRect::setRect(const rect<s32> &value) +{ + mValue = value; +} + + +// SerializedString class +// SerializedString constructor. +SerializedString::SerializedString(const std::string &name, const std::string &value) +: SerializedAttribute(name, "string") +{ + mValue = value; +} + +// SerializedString deconstructor. +SerializedString::~SerializedString() +{ +} + +std::string SerializedString::getString() const +{ + return mValue; +} + +void SerializedString::setString(const std::string &value) +{ + mValue = value; +} + + +// SerializedVector2d class +// SerializedVector2d constructor (vector2df). +SerializedVector2d::SerializedVector2d(const std::string &name, const vector2df &value) +: SerializedAttribute(name, "vector2d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedVector2d constructor (vector2di). +SerializedVector2d::SerializedVector2d(const std::string &name, const vector2di &value) +: SerializedAttribute(name, "vector2d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedVector2d constructor (vector2d<f64>). +SerializedVector2d::SerializedVector2d(const std::string &name, const vector2d<f64> &value) +: SerializedAttribute(name, "vector2d") +{ + mValue = value; +} + +// SerializedVector2d deconstructor. +SerializedVector2d::~SerializedVector2d() +{ +} + +std::string SerializedVector2d::getString() const +{ + stringstream ss; + ss << "vector2d(" << mValue.X << ", " << mValue.Y << ")"; + + return ss.str(); +} + +vector2df SerializedVector2d::getVector2df() const +{ + return getVector2df(); +} + +vector2df SerializedVector2d::getVector2df() +{ + return convert<f32, f64>(mValue); +} + +vector2di SerializedVector2d::getVector2di() const +{ + return getVector2di(); +} + +vector2di SerializedVector2d::getVector2di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedVector2d::setVector2df(const vector2df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedVector2d::setVector2di(const vector2di &value) +{ + mValue = convert<f64, s32>(value); +} + + +// SerializedVector3d class +// SerializedVector3d constructor (vector3df). +SerializedVector3d::SerializedVector3d(const std::string &name, const vector3df &value) +: SerializedAttribute(name, "vector3d") +{ + mValue = convert<f64, f32>(value); +} + +// SerializedVector3d constructor (vector3di). +SerializedVector3d::SerializedVector3d(const std::string &name, const vector3di &value) +: SerializedAttribute(name, "vector3d") +{ + mValue = convert<f64, s32>(value); +} + +// SerializedVector3d constructor (vector3d<f64>). +SerializedVector3d::SerializedVector3d(const std::string &name, const vector3d<f64> &value) +: SerializedAttribute(name, "vector3d") +{ + mValue = value; +} + +// SerializedVector3d deconstructor. +SerializedVector3d::~SerializedVector3d() +{ +} + +std::string SerializedVector3d::getString() const +{ + stringstream ss; + ss << "vector3d(" << mValue.X << ", " << mValue.Y << ", " << mValue.Z << ")"; + + return ss.str(); +} + +vector3df SerializedVector3d::getVector3df() const +{ + return getVector3df(); +} + +vector3df SerializedVector3d::getVector3df() +{ + return convert<f32, f64>(mValue); +} + +vector3di SerializedVector3d::getVector3di() const +{ + return getVector3di(); +} + +vector3di SerializedVector3d::getVector3di() +{ + return convert<s32, f64>(mValue); +} + +void SerializedVector3d::setVector3df(const vector3df &value) +{ + mValue = convert<f64, f32>(value); +} + +void SerializedVector3d::setVector3di(const vector3di &value) +{ + mValue = convert<f64, s32>(value); +} + +// End of File Added: trunk/src/core/SerializedAttributesImpl.h =================================================================== --- trunk/src/core/SerializedAttributesImpl.h (rev 0) +++ trunk/src/core/SerializedAttributesImpl.h 2009-11-07 18:17:55 UTC (rev 145) @@ -0,0 +1,549 @@ +// ///////////////////////////////////////////////////////////////////////////// +// +// Name: SerializedAttributesImpl.h +// Author: Michael Bartsch (ZCCdark203) +// +// Desc : Declarations of various subclasses of the +// SerializedAttribute class. +// +// License: Copyright (C) 2009 Michael Bartsch and Contributors +// +// This program is free software: you can redistribute it +// and/or modify it under the terms of the zlib/libpng License. +// See main.cpp for conditions of distribution and use. +// +// ///////////////////////////////////////////////////////////////////////////// + +#ifndef __SERIALIZEDATTRIBUTEIMPL_H__ +#define __SERIALIZEDATTRIBUTEIMPL_H__ + +// Include files +#include "SerializedAttribute.h" + + +// SerializedAabbox3d class +//! SerializedAttribute subclass for serialized aabbox3d objects. +class SerializedAabbox3d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (aabbox3df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedAabbox3d(const std::string &name, const aabbox3df &value); + //! Constructor (aabbox3di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedAabbox3d(const std::string &name, const aabbox3di &value); + //! Deconstructor + ~SerializedAabbox3d(); + + // Public methods + aabbox3df getAabbox3df() const; + aabbox3di getAabbox3di() const; + std::string getString() const; + + void setAabbox3df(const aabbox3df &value); + void setAabbox3di(const aabbox3di &value); + +private: + + // Private methods + template<typename R, typename T> + aabbox3d<R> convert(const aabbox3d<T> &t) + { + aabbox3d<R> r; + + r.MinEdge.X = (R)t.MinEdge.X; + r.MinEdge.X = (R)t.MinEdge.Y; + r.MinEdge.X = (R)t.MinEdge.Z; + + r.MaxEdge.X = (R)t.MaxEdge.X; + r.MaxEdge.X = (R)t.MaxEdge.Y; + r.MaxEdge.X = (R)t.MaxEdge.Z; + + return r; + } + + aabbox3df getAabbox3df(); + aabbox3di getAabbox3di(); + + // Private members + aabbox3d<f64> mValue; +}; + + +// SerializedBool class +//! SerializedAttribute subclass for boolean values. +class SerializedBool : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedBool(const std::string &name, bool value); + //! Deconstructor + ~SerializedBool(); + + // Public methods + bool getBool() const; + f32 getFloat() const; + s32 getInt() const; + std::string getString() const; + + void setBool(bool value); + void setFloat(f32 value); + void setInt(s32 value); + void setString(const std::string &value); + +private: + + // Private members + bool mValue; +}; + + +// SerializedColor +//! SerializedAttribute subclass for serialized color objects. +class SerializedColor : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedColor(const std::string &name, const SColorf &value); + //! Deconstructor + ~SerializedColor(); + + // Public methods + SColor getColor() const; + SColorf getColorf() const; + f32 getFloat() const; + s32 getInt() const; + std::string getString() const; + + void setColor(const SColor &value); + void setColorf(const SColorf &value); + void setFloat(f32 value); + void setInt(s32 value); + +private: + + // Private members + SColorf mValue; +}; + + +// SerializedDimension2d class +//! SerializedAttribute subclass for serialized dimension2d objects. +class SerializedDimension2d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (dimension2df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedDimension2d(const std::string &name, const dimension2df &value); + //! Constructor (dimension2di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedDimension2d(const std::string &name, const dimension2di &value); + //! Deconstructor + ~SerializedDimension2d(); + + // Public methods + std::string getString() const; + dimension2df getDimension2df() const; + dimension2di getDimension2di() const; + + void setDimension2df(const dimension2df &value); + void setDimension2di(const dimension2di &value); + +private: + + // Private methods + template<typename R, typename T> + dimension2d<R> convert(const dimension2d<T> &t) + { + return dimension2d<R>((R)t.Width, (R)t.Height); + } + + dimension2df getDimension2df(); + dimension2di getDimension2di(); + + // Private members + dimension2d<f64> mValue; +}; + + +// SerializedLine2d class +//! SerializedAttribute subclass for serialized line2d objects. +class SerializedLine2d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (line2df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedLine2d(const std::string &name, const line2df &value); + //! Constructor (line2di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedLine2d(const std::string &name, const line2di &value); + //! Deconstructor + ~SerializedLine2d(); + + // Public methods + std::string getString() const; + line2df getLine2df() const; + line2di getLine2di() const; + + void setLine2df(const line2df &value); + void setLine2di(const line2di &value); + +private: + + // Private methods + template<typename R, typename T> + line2d<R> convert(const line2d<T> &t) + { + line2d<R> r; + + r.start.X = (R)t.start.X; + r.start.Y = (R)t.start.Y; + + r.end.X = (R)t.end.X; + r.end.Y = (R)t.end.Y; + + return r; + } + + line2df getLine2df(); + line2di getLine2di(); + + // Private members + line2d<f64> mValue; +}; + + +// SerializedLine3d class +//! SerializedAttribute subclass for serialized line3d objects. +class SerializedLine3d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (line3df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedLine3d(const std::string &name, const line3df &value); + //! Constructor (line3di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedLine3d(const std::string &name, const line3di &value); + //! Deconstructor + ~SerializedLine3d(); + + // Public methods + std::string getString() const; + line3df getLine3df() const; + line3di getLine3di() const; + + void setLine3df(const line3df &value); + void setLine3di(const line3di &value); + +private: + + // Private methods + template<typename R, typename T> + line3d<R> convert(const line3d<T> &t) + { + line3d<R> r; + + r.start.X = (R)t.start.X; + r.start.Y = (R)t.start.Y; + r.start.Z = (R)t.start.Z; + + r.end.X = (R)t.end.X; + r.end.Y = (R)t.end.Y; + r.end.Z = (R)t.end.Z; + + return r; + } + + line3df getLine3df(); + line3di getLine3di(); + + // Private members + line3d<f64> mValue; +}; + + +// SerializedNumber class +//! SerializedAttribute subclass for number values. +class SerializedNumber : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (s32) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedNumber(const std::string &name, s32 value); + //! Constructor (f32) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedNumber(const std::string &name, f32 value); + //! Deconstructor + ~SerializedNumber(); + + // Public methods + bool getBool() const; + f32 getFloat() const; + s32 getInt() const; + std::string getString() const; + + void setBool(bool value); + void setFloat(f32 value); + void setInt(s32 value); + void setString(const std::string &value); + +private: + + // Private members + f64 mValue; +}; + + +// SerializedPlane3d class +//! SerializedAttribute subclass for serialized plane3d objects. +class SerializedPlane3d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (plane3df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedPlane3d(const std::string &name, const plane3df &value); + //! Constructor (plane3di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedPlane3d(const std::string &name, const plane3di &value); + //! Deconstructor + ~SerializedPlane3d(); + + // Public methods + std::string getString() const; + plane3df getPlane3df() const; + plane3di getPlane3di() const; + + void setPlane3df(const plane3df &value); + void setPlane3di(const plane3di &value); + +private: + + // Private methods + template<typename R, typename T> + plane3d<R> convert(const plane3d<T> &t) + { + plane3d<R> r; + + r.Normal.X = (R)t.Normal.X; + r.Normal.Y = (R)t.Normal.Y; + r.Normal.Z = (R)t.Normal.Z; + + r.D = (R)t.D; + + return r; + } + + plane3df getPlane3df(); + plane3di getPlane3di(); + + // Private members + plane3d<f64> mValue; +}; + + +// SerializedQuaternion class +//! SerializedAttribute subclass for serialized quaternion objects. +class SerializedQuaternion : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedQuaternion(const std::string &name, const quaternion &value); + //! Deconstructor + ~SerializedQuaternion(); + + // Public methods + std::string getString() const; + quaternion getQuaternion() const; + + void setQuaternion(const quaternion &value); + +private: + + // Private members + quaternion mValue; +}; + + +// SerializedRect class +//! SerializedAttribute subclass for serialized rect objects. +class SerializedRect : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedRect(const std::string &name, const rect<s32> &value); + //! Deconstructor + ~SerializedRect(); + + // Public methods + std::string getString() const; + rect<s32> getRect() const; + + void setRect(const rect<s32> &value); + +private: + + // Private members + rect<s32> mValue; +}; + + +// SerializedString class +//! SerializedAttribute subclass for serialized strings. +class SerializedString : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedString(const std::string &name, const std::string &value); + //! Deconstructor + ~SerializedString(); + + // Public methods + std::string getString() const; + + void setString(const std::string &value); + +private: + + // Private members + std::string mValue; +}; + + +// SerializedVector2d class +//! SerializedAttribute subclass for serialized vector2d objects. +class SerializedVector2d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (vector2df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector2d(const std::string &name, const vector2df &value); + //! Constructor (vector2di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector2d(const std::string &name, const vector2di &value); + //! Constructor (vector2d<f64>) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector2d(const std::string &name, const vector2d<f64> &value); + //! Deconstructor + ~SerializedVector2d(); + + // Public methods + std::string getString() const; + vector2df getVector2df() const; + vector2di getVector2di() const; + + void setVector2df(const vector2df &value); + void setVector2di(const vector2di &value); + +private: + + // Private methods + template<typename R, typename T> + vector2d<R> convert(const vector2d<T> &t) + { + return vector2d<R>((R)t.X, (R)t.Y); + } + + vector2df getVector2df(); + vector2di getVector2di(); + + // Private members + vector2d<f64> mValue; +}; + + +// SerializedVector3d class +//! SerializedAttribute subclass for serialized vector3d objects. +class SerializedVector3d : public SerializedAttribute +{ +public: + + // Initialisation and deinitialisation + //! Constructor (vector3df) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector3d(const std::string &name, const vector3df &value); + //! Constructor (vector3di) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector3d(const std::string &name, const vector3di &value); + //! Constructor (vector3d<f64>) + //! @param name Name of the attribute + //! @param value Initial value of this attribute. + SerializedVector3d(const std::string &name, const vector3d<f64> &value); + //! Deconstructor + ~SerializedVector3d(); + + // Public methods + std::string getString() const; + vector3df getVector3df() const; + vector3di getVector3di() const; + + void setVector3df(const vector3df &value); + void setVector3di(const vector3di &value); + +private: + + // Private methods + template<typename R, typename T> + vector3d<R> convert(const vector3d<T> &t) + { + return vector3d<R>((R)t.X, (R)t.Y, (R)t.Z); + } + + vector3df getVector3df(); + vector3di getVector3di(); + + // Private members + vector3d<f64> mValue; +}; + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |