Просмотр исходного кода

Each game object now has an unique instance id

Marko Pintera 12 лет назад
Родитель
Сommit
3ce6e0bc8f

+ 1 - 1
CamelotClient/Source/BsEditorApplication.cpp

@@ -40,7 +40,7 @@ namespace BansheeEditor
 		const String& renderSystemLibraryName = getLibraryNameForRenderSystem(renderSystemPlugin);
 		gBansheeApp().startUp(renderWindowDesc, renderSystemLibraryName, "BansheeForwardRenderer", "D:\\CamelotResourceMetas"); // TODO - Make renderer and resource cache dir customizable
 		EditorGUI::startUp(cm_new<EditorGUI>());
-		gApplication().loadPlugin("SBansheeEditor"); // Managed part of the editor
+		//gApplication().loadPlugin("SBansheeEditor"); // Managed part of the editor
 
 		/************************************************************************/
 		/* 								DEBUG CODE                      		*/

+ 2 - 0
CamelotCore/CamelotCore.vcxproj

@@ -282,6 +282,7 @@
     <ClInclude Include="Include\CmEventQuery.h" />
     <ClInclude Include="Include\CmGameObjectHandle.h" />
     <ClInclude Include="Include\CmGameObject.h" />
+    <ClInclude Include="Include\CmGameObjectManager.h" />
     <ClInclude Include="Include\CmGameObjectRTTI.h" />
     <ClInclude Include="Include\CmGpuResourceData.h" />
     <ClInclude Include="Include\CmGpuParamBlockBuffer.h" />
@@ -439,6 +440,7 @@
     <ClCompile Include="Source\CmFont.cpp" />
     <ClCompile Include="Source\CmFontImportOptions.cpp" />
     <ClCompile Include="Source\CmFontManager.cpp" />
+    <ClCompile Include="Source\CmGameObjectManager.cpp" />
     <ClCompile Include="Source\CmGpuBuffer.cpp" />
     <ClCompile Include="Source\CmGpuBufferView.cpp" />
     <ClCompile Include="Source\CmGpuParamBlock.cpp" />

+ 6 - 0
CamelotCore/CamelotCore.vcxproj.filters

@@ -525,6 +525,9 @@
     <ClInclude Include="Include\CmPixelVolume.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmGameObjectManager.h">
+      <Filter>Header Files\Scene</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmApplication.cpp">
@@ -824,5 +827,8 @@
     <ClCompile Include="Source\CmPixelVolume.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmGameObjectManager.cpp">
+      <Filter>Source Files\Scene</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 7 - 2
CamelotCore/Include/CmGameObject.h

@@ -8,8 +8,13 @@ namespace CamelotFramework
 	class CM_EXPORT GameObject : public IReflectable
 	{
 	public:
-		virtual ~GameObject() 
-		{ }
+		GameObject();
+		virtual ~GameObject();
+
+		UINT64 getInstanceID() const { return mInstanceId; }
+
+	private:
+		UINT64 mInstanceId;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 24 - 0
CamelotCore/Include/CmGameObjectManager.h

@@ -0,0 +1,24 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotFramework
+{
+	class CM_EXPORT GameObjectManager : public Module<GameObjectManager>
+	{
+	public:
+		GameObjectManager();
+		~GameObjectManager();
+
+		UINT64 registerObject(GameObject* object);
+		void unregisterObject(GameObject* object);
+
+		GameObject* getObject(UINT64 id) const;
+		bool objectExists(UINT64 id) const;
+
+	private:
+		UINT64 mNextAvailableID; // 0 is not a valid ID
+		Map<UINT64, GameObject*>::type mObjects;
+	};
+}

+ 3 - 0
CamelotCore/Source/CmApplication.cpp

@@ -11,6 +11,7 @@
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmCoreObjectManager.h"
+#include "CmGameObjectManager.h"
 #include "CmDynLib.h"
 #include "CmDynLibManager.h"
 #include "CmSceneManager.h"
@@ -58,6 +59,7 @@ namespace CamelotFramework
 		Time::startUp(cm_new<Time>());
 		DynLibManager::startUp(cm_new<DynLibManager>());
 		CoreGpuObjectManager::startUp(cm_new<CoreGpuObjectManager>());
+		GameObjectManager::startUp(cm_new<GameObjectManager>());
 		Resources::startUp(cm_new<Resources>(desc.resourceCacheDirectory));
 		HighLevelGpuProgramManager::startUp(cm_new<HighLevelGpuProgramManager>());
 
@@ -185,6 +187,7 @@ namespace CamelotFramework
 
 		HighLevelGpuProgramManager::shutDown();
 		Resources::shutDown();
+		GameObjectManager::shutDown();
 		CoreGpuObjectManager::shutDown(); // Must shut down before DynLibManager to ensure all objects are destroyed before unloading their libraries
 		DynLibManager::shutDown();
 		Time::shutDown();

+ 12 - 0
CamelotCore/Source/CmGameObject.cpp

@@ -1,8 +1,20 @@
 #include "CmGameObject.h"
 #include "CmGameObjectRTTI.h"
+#include "CmGameObjectManager.h"
 
 namespace CamelotFramework
 {
+	GameObject::GameObject()
+		:mInstanceId(0)
+	{
+		mInstanceId = GameObjectManager::instance().registerObject(this);
+	}
+
+	GameObject::~GameObject()
+	{
+		GameObjectManager::instance().unregisterObject(this);
+	}
+	
 	RTTITypeBase* GameObject::getRTTIStatic()
 	{
 		return GameObjectRTTI::instance();

+ 45 - 0
CamelotCore/Source/CmGameObjectManager.cpp

@@ -0,0 +1,45 @@
+#include "CmGameObjectManager.h"
+#include "CmGameObject.h"
+
+namespace CamelotFramework
+{
+	GameObjectManager::GameObjectManager()
+		:mNextAvailableID(1)
+	{
+
+	}
+
+	GameObjectManager::~GameObjectManager()
+	{ }
+
+	GameObject* GameObjectManager::getObject(UINT64 id) const 
+	{ 
+		auto iterFind = mObjects.find(id);
+
+		if(iterFind != mObjects.end())
+			return iterFind->second;
+		
+		return nullptr;
+	}
+
+	bool GameObjectManager::objectExists(UINT64 id) const 
+	{ 
+		return mObjects.find(id) != mObjects.end(); 
+	}
+
+	UINT64 GameObjectManager::registerObject(GameObject* object)
+	{
+		assert(object != nullptr);
+
+		mObjects[mNextAvailableID] = object;
+
+		return mNextAvailableID++;
+	}
+
+	void GameObjectManager::unregisterObject(GameObject* object)
+	{
+		assert(object != nullptr);
+
+		mObjects.erase(object->getInstanceID());
+	}
+}

+ 5 - 0
TODO.txt

@@ -4,6 +4,11 @@ Editor localization should be different from in-game one.
  - Because what happens when user decides to set "File" localized string to something else? It will also modify the editor string.
  - HString probably needs to accept an optional parameter of which StringTable to use
 
+CROSS MODULE SINGLETON ISSUE:
+ - I cannot have any singletons in CamelotClient (the .exe) as each loaded .dll will then use their own copy of the singleton
+ - I should move all BansheeEditor functionality into a separate .dll, and then make the .exe perform just a single DynLib call.
+ - This issue manifests when I try to load MBansheeEditor.dll and it accesses EditorGUI singleton from SBansheeEditor, where the instance is wrong
+
 Optimization notes:
  - submitToCoreThread calls are EXTREMELY slow. In 10-50ms range.