Browse Source

Fixed some issues with RTTI plain value setter/getters (any_cast wasn't able to cast to base types, so I had to encapsulate things a bit further)
Start/Shutdown UndoRedo module

Marko Pintera 12 years ago
parent
commit
46094b3bfa

+ 3 - 2
CamelotClient/Include/BsCmdEditPlainFieldGO.h

@@ -2,6 +2,7 @@
 
 
 #include "BsEditorPrerequisites.h"
 #include "BsEditorPrerequisites.h"
 #include "BsEditorCommand.h"
 #include "BsEditorCommand.h"
+#include "BsUndoRedo.h"
 
 
 namespace BansheeEditor
 namespace BansheeEditor
 {
 {
@@ -19,10 +20,10 @@ namespace BansheeEditor
 				cm_free(mOldData);
 				cm_free(mOldData);
 		}
 		}
 
 
-		void execute(const CM::GameObjectHandleBase& gameObject, const CM::String& fieldName, const T& fieldValue)
+		static void execute(const CM::GameObjectHandleBase& gameObject, const CM::String& fieldName, const T& fieldValue)
 		{
 		{
 			// Register command and commit it
 			// Register command and commit it
-			CmdEditFieldGO* command = cm_new<CmdEditFieldGO>(gameObject, fieldName, fieldValue);
+			CmdEditPlainFieldGO* command = new (cm_alloc<CmdEditPlainFieldGO>()) CmdEditPlainFieldGO(gameObject, fieldName, fieldValue);
 			UndoRedo::instance().registerCommand(command);
 			UndoRedo::instance().registerCommand(command);
 			command->commit();
 			command->commit();
 		}
 		}

+ 3 - 0
CamelotClient/Source/BsEditorApplication.cpp

@@ -5,6 +5,7 @@
 #include "CmApplication.h"
 #include "CmApplication.h"
 #include "CmRenderWindow.h"
 #include "CmRenderWindow.h"
 #include "BsEditorGUI.h"
 #include "BsEditorGUI.h"
+#include "BsUndoRedo.h"
 
 
 // DEBUG ONLY
 // DEBUG ONLY
 #include "DbgEditorWidget1.h"
 #include "DbgEditorWidget1.h"
@@ -214,6 +215,7 @@ namespace BansheeEditor
 		/* 							END DEBUG CODE                      		*/
 		/* 							END DEBUG CODE                      		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
+		UndoRedo::startUp(cm_new<UndoRedo>());
 		EditorWindowManager::startUp(cm_new<EditorWindowManager>());
 		EditorWindowManager::startUp(cm_new<EditorWindowManager>());
 		MainEditorWindow* mainWindow = MainEditorWindow::create(gApplication().getPrimaryWindow());
 		MainEditorWindow* mainWindow = MainEditorWindow::create(gApplication().getPrimaryWindow());
 
 
@@ -225,6 +227,7 @@ namespace BansheeEditor
 		gBansheeApp().runMainLoop();
 		gBansheeApp().runMainLoop();
 
 
 		EditorWindowManager::shutDown();
 		EditorWindowManager::shutDown();
+		UndoRedo::shutDown();
 
 
 
 
 		/************************************************************************/
 		/************************************************************************/

+ 3 - 1
CamelotClient/Source/BsGUISceneTreeView.cpp

@@ -13,6 +13,7 @@
 #include "BsGUICommandEvent.h"
 #include "BsGUICommandEvent.h"
 #include "CmSceneObject.h"
 #include "CmSceneObject.h"
 #include "CmSceneManager.h"
 #include "CmSceneManager.h"
+#include "BsCmdEditPlainFieldGO.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 using namespace BansheeEngine;
 using namespace BansheeEngine;
@@ -378,7 +379,8 @@ namespace BansheeEditor
 
 
 		if(applyChanges)
 		if(applyChanges)
 		{
 		{
-			// TODO - Actually rename GameObject. Don't forget Undo/Redo
+			String newName = toString(mNameEditBox->getText());
+			CmdEditPlainFieldGO<String>::execute(mEditElement->mSceneObject, "mName", newName);
 		}
 		}
 
 
 		mNameEditBox->disableRecursively();
 		mNameEditBox->disableRecursively();

+ 4 - 3
CamelotCore/Include/CmGameObjectHandle.h

@@ -34,6 +34,8 @@ namespace CamelotFramework
 	class CM_EXPORT GameObjectHandleBase
 	class CM_EXPORT GameObjectHandleBase
 	{
 	{
 	public:
 	public:
+		GameObjectHandleBase(const std::shared_ptr<GameObjectHandleData> data);
+
 		/**
 		/**
 		 * @brief	Checks if the object has been destroyed
 		 * @brief	Checks if the object has been destroyed
 		 */
 		 */
@@ -106,10 +108,9 @@ namespace CamelotFramework
 			return *this;
 			return *this;
 		}
 		}
 
 
-		GameObjectHandleBase toBase()
+		inline operator GameObjectHandleBase()
 		{
 		{
-			GameObjectHandleBase base;
-			base.mData = this->mData;
+			GameObjectHandleBase base(mData);
 
 
 			return base;
 			return base;
 		}
 		}

+ 4 - 0
CamelotCore/Source/CmGameObjectHandle.cpp

@@ -5,6 +5,10 @@
 
 
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
+	GameObjectHandleBase::GameObjectHandleBase(std::shared_ptr<GameObjectHandleData> data)
+		:mData(data)
+	{ }
+
 	GameObjectHandleBase::GameObjectHandleBase()
 	GameObjectHandleBase::GameObjectHandleBase()
 	{ }
 	{ }
 
 

+ 30 - 62
CamelotUtility/Include/CmRTTIPlainField.h

@@ -45,58 +45,6 @@ namespace CamelotFramework
 			return 0;
 			return 0;
 		}
 		}
 
 
-		template<class ObjectType, class DataType>
-		void getValue(ObjectType* object, DataType& value)
-		{
-			checkIsArray(false);
-			checkType<DataType>();
-
-			boost::function<DataType&(ObjectType*)> f = boost::any_cast<boost::function<DataType&(ObjectType*)>>(valueGetter);
-			value = f(object);
-		}
-
-		template<class ObjectType, class DataType>
-		void getArrayValue(ObjectType* object, UINT32 index, DataType& value)
-		{
-			checkIsArray(true);
-			checkType<DataType>();
-
-			boost::function<DataType&(ObjectType*, UINT32)> f = boost::any_cast<boost::function<DataType&(ObjectType*, UINT32)>>(valueGetter);
-			value = f(object, index);
-		}
-
-		template<class ObjectType, class DataType>
-		void setValue(ObjectType* object, DataType& value)
-		{
-			checkIsArray(false);
-			checkType<DataType>();
-
-			if(valueSetter.empty())
-			{
-				CM_EXCEPT(InternalErrorException,
-					"Specified field (" + mName + ") has no setter.");
-			}
-
-			boost::function<void(ObjectType*, DataType&)> f = boost::any_cast<boost::function<void(ObjectType*, DataType&)>>(valueSetter);
-			f(object, value);
-		}
-
-		template<class ObjectType, class DataType>
-		void setArrayValue(ObjectType* object, UINT32 index, DataType& value)
-		{
-			checkIsArray(true);
-			checkType<DataType>();
-
-			if(valueSetter.empty())
-			{
-				CM_EXCEPT(InternalErrorException, 
-					"Specified field (" + mName + ") has no setter.");
-			}
-
-			boost::function<void(ObjectType*, UINT32, DataType&)> f = boost::any_cast<boost::function<void(ObjectType*, UINT32, DataType&)>>(valueSetter);
-			f(object, index, value);
-		}
-
 		/**
 		/**
 		 * @brief	Retrieves the value from the provided field of the provided object, and copies
 		 * @brief	Retrieves the value from the provided field of the provided object, and copies
 		 * 			it into the buffer. WARNING - It does not check if buffer is large enough.
 		 * 			it into the buffer. WARNING - It does not check if buffer is large enough.
@@ -210,8 +158,9 @@ namespace CamelotFramework
 
 
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 
 
-			DataType value;
-			getValue(castObject, value);
+			boost::function<DataType&(ObjectType*)> f = boost::any_cast<boost::function<DataType&(ObjectType*)>>(valueGetter);
+			DataType value = f(castObject);
+
 			return RTTIPlainType<DataType>::getDynamicSize(value);
 			return RTTIPlainType<DataType>::getDynamicSize(value);
 		}
 		}
 
 
@@ -222,8 +171,9 @@ namespace CamelotFramework
 
 
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 
 
-			DataType value;
-			getArrayValue(castObject, index, value);
+			boost::function<DataType&(ObjectType*, UINT32)> f = boost::any_cast<boost::function<DataType&(ObjectType*, UINT32)>>(valueGetter);
+			DataType value = f(castObject, index);
+
 			return RTTIPlainType<DataType>::getDynamicSize(value);
 			return RTTIPlainType<DataType>::getDynamicSize(value);
 		}
 		}
 
 
@@ -258,8 +208,9 @@ namespace CamelotFramework
 
 
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 
 
-			DataType value;
-			getValue(castObject, value);
+			boost::function<DataType&(ObjectType*)> f = boost::any_cast<boost::function<DataType&(ObjectType*)>>(valueGetter);
+			DataType value = f(castObject);
+
 			RTTIPlainType<DataType>::toMemory(value, (char*)buffer);
 			RTTIPlainType<DataType>::toMemory(value, (char*)buffer);
 		}
 		}
 
 
@@ -270,8 +221,9 @@ namespace CamelotFramework
 
 
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 			ObjectType* castObject = static_cast<ObjectType*>(object);
 
 
-			DataType value;
-			getArrayValue(castObject, index, value);
+			boost::function<DataType&(ObjectType*, UINT32)> f = boost::any_cast<boost::function<DataType&(ObjectType*, UINT32)>>(valueGetter);
+			DataType value = f(castObject, index);
+
 			RTTIPlainType<DataType>::toMemory(value, (char*)buffer);
 			RTTIPlainType<DataType>::toMemory(value, (char*)buffer);
 		}
 		}
 
 
@@ -284,7 +236,15 @@ namespace CamelotFramework
 
 
 			DataType value;
 			DataType value;
 			RTTIPlainType<DataType>::fromMemory(value, (char*)buffer);
 			RTTIPlainType<DataType>::fromMemory(value, (char*)buffer);
-			setValue(castObject, value);
+
+			if(valueSetter.empty())
+			{
+				CM_EXCEPT(InternalErrorException,
+					"Specified field (" + mName + ") has no setter.");
+			}
+
+			boost::function<void(ObjectType*, DataType&)> f = boost::any_cast<boost::function<void(ObjectType*, DataType&)>>(valueSetter);
+			f(castObject, value);
 		}
 		}
 
 
 		virtual void arrayElemFromBuffer(void* object, int index, void* buffer)
 		virtual void arrayElemFromBuffer(void* object, int index, void* buffer)
@@ -296,7 +256,15 @@ namespace CamelotFramework
 
 
 			DataType value;
 			DataType value;
 			RTTIPlainType<DataType>::fromMemory(value, (char*)buffer);
 			RTTIPlainType<DataType>::fromMemory(value, (char*)buffer);
-			setArrayValue(castObject, index, value);
+
+			if(valueSetter.empty())
+			{
+				CM_EXCEPT(InternalErrorException, 
+					"Specified field (" + mName + ") has no setter.");
+			}
+
+			boost::function<void(ObjectType*, UINT32, DataType&)> f = boost::any_cast<boost::function<void(ObjectType*, UINT32, DataType&)>>(valueSetter);
+			f(castObject, index, value);
 		}
 		}
 	};
 	};
 }
 }

+ 52 - 4
CamelotUtility/Include/CmRTTIType.h

@@ -64,7 +64,19 @@ namespace CamelotFramework
 			genericField->checkIsPlain(false);
 			genericField->checkIsPlain(false);
 
 
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
-			field->setValue(object, value);
+
+			UINT32 typeSize = 0;
+			if(RTTIPlainType<DataType>::hasDynamicSize)
+				typeSize = RTTIPlainType<DataType>::getDynamicSize(value);
+			else
+				typeSize = sizeof(DataType);
+
+			UINT8* tempBuffer = stackAlloc(typeSize);
+			RTTIPlainType<DataType>::toMemory(value, (char*)tempBuffer);
+			
+			field->fromBuffer(object, tempBuffer);
+
+			stackDeallocLast(tempBuffer);
 		}
 		}
 
 
 		template <class ObjectType, class DataType>
 		template <class ObjectType, class DataType>
@@ -74,7 +86,19 @@ namespace CamelotFramework
 			genericField->checkIsPlain(true);
 			genericField->checkIsPlain(true);
 
 
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
-			field->setArrayValue(object, index, value);
+
+			UINT32 typeSize = 0;
+			if(RTTIPlainType<DataType>::hasDynamicSize)
+				typeSize = RTTIPlainType<DataType>::getDynamicSize(value);
+			else
+				typeSize = sizeof(DataType);
+
+			UINT8* tempBuffer = stackAlloc(typeSize);
+			RTTIPlainType<DataType>::toMemory(value, (char*)tempBuffer);
+
+			field->arrayElemFromBuffer(object, index, tempBuffer);
+
+			stackDeallocLast(tempBuffer);
 		}
 		}
 
 
 		template <class ObjectType, class DataType>
 		template <class ObjectType, class DataType>
@@ -147,7 +171,19 @@ namespace CamelotFramework
 			genericField->checkIsPlain(false);
 			genericField->checkIsPlain(false);
 
 
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
-			field->getValue(object, value);
+
+			UINT32 typeSize = 0;
+			if(field->hasDynamicSize())
+				typeSize = field->getDynamicSize(object);
+			else
+				typeSize = field->getTypeSize();
+
+			UINT8* tempBuffer = stackAlloc(typeSize);
+
+			field->toBuffer(object, tempBuffer);
+			RTTIPlainType<DataType>::fromMemory(value, (char*)tempBuffer);
+
+			stackDeallocLast(tempBuffer);
 		}
 		}
 
 
 		template <class ObjectType, class DataType>
 		template <class ObjectType, class DataType>
@@ -157,7 +193,19 @@ namespace CamelotFramework
 			genericField->checkIsPlain(true);
 			genericField->checkIsPlain(true);
 
 
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
 			RTTIPlainFieldBase* field = static_cast<RTTIPlainFieldBase*>(genericField);
-			field->getArrayValue(object, index, value);
+
+			UINT32 typeSize = 0;
+			if(field->hasDynamicSize())
+				typeSize = field->getArrayElemDynamicSize(object, arrIdx);
+			else
+				typeSize = field->getTypeSize();
+
+			UINT8* tempBuffer = stackAlloc(typeSize);
+
+			field->arrayElemToBuffer(object, index, tempBuffer);
+			RTTIPlainType<DataType>::fromMemory(value, (char*)tempBuffer);
+
+			stackDeallocLast(tempBuffer);
 		}	
 		}	
 
 
 		template <class ObjectType>
 		template <class ObjectType>