فهرست منبع

Skybox related fixes

BearishSun 8 سال پیش
والد
کامیت
b905718c34

+ 17 - 14
Source/BansheeCore/Include/BsCSkybox.h

@@ -6,7 +6,7 @@
 #include "BsSkybox.h"
 #include "BsComponent.h"
 
-namespace bs 
+namespace bs
 {
 	/** @addtogroup Components
 	 *  @{
@@ -17,28 +17,28 @@ namespace bs
 	 *
 	 * Wraps Skybox as a Component.
 	 */
-    class BS_CORE_EXPORT CSkybox : public Component
-    {
-    public:
-        CSkybox(const HSceneObject& parent);
+	class BS_CORE_EXPORT CSkybox : public Component
+	{
+	public:
+		CSkybox(const HSceneObject& parent);
 		virtual ~CSkybox();
 
-        /** @copydoc Skybox::getTexture */
-        HTexture getTexture() const { return mInternal->getTexture(); }
+		/** @copydoc Skybox::getTexture */
+		HTexture getTexture() const { return mInternal->getTexture(); }
 
-        /** @copydoc Skybox::setTexture */
-        void setTexture(const HTexture& texture) { mInternal->setTexture(texture); }
+		/** @copydoc Skybox::setTexture */
+		void setTexture(const HTexture& texture) { mInternal->setTexture(texture); }
 
-		/** @name Internal 
+		/** @name Internal
 		 *  @{
 		 */
 
-	    /**	Returns the skybox that this component wraps. */
+		/**	Returns the skybox that this component wraps. */
 		SPtr<Skybox> _getSkybox() const { return mInternal; }
 
 		/** @} */
 
-    protected:
+	protected:
 		mutable SPtr<Skybox> mInternal;
 
 		/************************************************************************/
@@ -47,6 +47,9 @@ namespace bs
 	protected:
 		friend class SceneObject;
 
+		/** @copydoc Component::onInitialized */
+		void onInitialized() override;
+
 		/** @copydoc Component::update */
 		void update() override { }
 
@@ -60,7 +63,7 @@ namespace bs
 
 	protected:
 		CSkybox(); // Serialization only
-     };
+	};
 
-	 /** @} */
+	/** @} */
 }

+ 4 - 0
Source/BansheeCore/Include/BsCorePrerequisites.h

@@ -344,6 +344,8 @@ namespace bs
 	class GraphicsPipelineState;
 	class ComputePipelineState;
 	class ReflectionProbe;
+    class CReflectionProbe;
+    class CSkybox;
 	// Asset import
 	class SpecificImporter;
 	class Importer;
@@ -640,6 +642,8 @@ namespace bs
 	typedef GameObjectHandle<CFixedJoint> HFixedJoint;
 	typedef GameObjectHandle<CD6Joint> HD6Joint;
 	typedef GameObjectHandle<CCharacterController> HCharacterController;
+    typedef GameObjectHandle<CReflectionProbe> HReflectionProbe;
+    typedef GameObjectHandle<CSkybox> HSkybox;
 
 	/** @} */
 }

+ 14 - 3
Source/BansheeCore/Source/BsCSkybox.cpp

@@ -3,27 +3,38 @@
 #include "BsCSkybox.h"
 #include "BsCSkyboxRTTI.h"
 #include "BsSceneManager.h"
+#include "BsSkybox.h"
 
 namespace bs
 {
-    CSkybox::CSkybox()
+	CSkybox::CSkybox()
 	{
 		setFlag(ComponentFlag::AlwaysRun, true);
 		setName("Skybox");
 	}
 
-    CSkybox::CSkybox(const HSceneObject& parent)
+	CSkybox::CSkybox(const HSceneObject& parent)
 		: Component(parent)
 	{
 		setFlag(ComponentFlag::AlwaysRun, true);
 		setName("Skybox");
 	}
 
-    CSkybox::~CSkybox()
+	CSkybox::~CSkybox()
 	{
 		mInternal->destroy();
 	}
 
+	void CSkybox::onInitialized()
+	{
+		// If mInternal already exists this means this object was deserialized,
+		// so all we need to do is initialize it.
+		if (mInternal != nullptr)
+			mInternal->initialize();
+		else
+			mInternal = Skybox::create();
+	}
+
 	RTTITypeBase* CSkybox::getRTTIStatic()
 	{
 		return CSkyboxRTTI::instance();

+ 1 - 1
Source/BansheeCore/Source/BsReflectionProbe.cpp

@@ -137,7 +137,7 @@ namespace bs
 		size += rttiGetElemSize(mIsActive);
 		size += rttiGetElemSize(getCoreDirtyFlags());
 		size += rttiGetElemSize(mBounds);
-		size += rttiGetElemSize(sizeof(SPtr<ct::Texture>));
+		size += sizeof(SPtr<ct::Texture>);
 		size += rttiGetElemSize(mUUID);
 
 		UINT8* buffer = allocator->alloc(size);

+ 135 - 135
Source/BansheeCore/Source/BsSkybox.cpp

@@ -10,139 +10,139 @@
 
 namespace bs
 {
-    SkyboxBase::SkyboxBase()
-        : mIsActive(true)
-    { }
-
-    template <bool Core>
-    TSkybox<Core>::TSkybox()
-        : SkyboxBase()
-    { }
-
-    template class TSkybox<true>;
-    template class TSkybox<false>;
-
-    Skybox::Skybox()
-    { }
-
-    SPtr<ct::Skybox> Skybox::getCore() const
-    {
-        return std::static_pointer_cast<ct::Skybox>(mCoreSpecific);
-    }
-
-    SPtr<Skybox> Skybox::create()
-    {
-        Skybox* skybox = new (bs_alloc<Skybox>()) Skybox();
-        SPtr<Skybox> skyboxPtr = bs_core_ptr<Skybox>(skybox);
-        skyboxPtr->_setThisPtr(skyboxPtr);
-        skyboxPtr->mUUID = UUIDGenerator::generateRandom();
-        skyboxPtr->initialize();
-
-        return skyboxPtr;
-    }
-
-    SPtr<ct::CoreObject> Skybox::createCore() const
-    {
-        ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox();
-        SPtr<ct::Skybox> skyboxPtr = bs_shared_ptr<ct::Skybox>(skybox);
-        skyboxPtr->mUUID = mUUID;
-        skyboxPtr->_setThisPtr(skyboxPtr);
-
-        return skyboxPtr;
-    }
-
-    CoreSyncData Skybox::syncToCore(FrameAlloc* allocator)
-    {
-        UINT32 size = 0;
-        size += rttiGetElemSize(mIsActive);
-        size += rttiGetElemSize(sizeof(SPtr<ct::Texture>));
-        size += rttiGetElemSize(mUUID);
-        size += rttiGetElemSize(getCoreDirtyFlags());
-
-        UINT8* buffer = allocator->alloc(size);
-
-        char* dataPtr = (char*)buffer;
-        dataPtr = rttiWriteElem(mIsActive, dataPtr);
-        dataPtr = rttiWriteElem(mUUID, dataPtr);
-        dataPtr = rttiWriteElem(getCoreDirtyFlags(), dataPtr);
-
-        SPtr<ct::Texture>* texture = new (dataPtr) SPtr<ct::Texture>();
-        if (mTexture.isLoaded(false))
-            *texture = mTexture->getCore();
-        else
-            *texture = nullptr;
-
-        dataPtr += sizeof(SPtr<ct::Texture>);
-
-        return CoreSyncData(buffer, size);
-    }
-
-    void Skybox::_markCoreDirty(SkyboxDirtyFlag flags)
-    {
-        markCoreDirty((UINT32)flags);
-    }
-
-    RTTITypeBase* Skybox::getRTTIStatic()
-    {
-        return SkyboxRTTI::instance();
-    }
-
-    RTTITypeBase* Skybox::getRTTI() const
-    {
-        return Skybox::getRTTIStatic();
-    }
-
-    namespace ct
-    {
-        Skybox::Skybox()
-        { }
-
-        Skybox::~Skybox()
-        {
-            gRenderer()->notifySkyboxRemoved(this);
-        }
-
-        void Skybox::initialize()
-        {
-            gRenderer()->notifySkyboxAdded(this);
-
-            CoreObject::initialize();
-        }
-
-        void Skybox::syncToCore(const CoreSyncData& data)
-        {
-            char* dataPtr = (char*)data.getBuffer();
-
-            SkyboxDirtyFlag dirtyFlags;
-            bool oldIsActive = mIsActive;
-
-            dataPtr = rttiReadElem(mIsActive, dataPtr);
-            dataPtr = rttiReadElem(mUUID, dataPtr);
-            dataPtr = rttiReadElem(dirtyFlags, dataPtr);
-
-            SPtr<Texture>* texture = (SPtr<Texture>*)dataPtr;
-
-            mTexture = *texture;
-            texture->~SPtr<Texture>();
-            dataPtr += sizeof(SPtr<Texture>);
-
-            if (oldIsActive != mIsActive)
-            {
-                if (mIsActive)
-                    gRenderer()->notifySkyboxAdded(this);
-                else
-                    gRenderer()->notifySkyboxRemoved(this);
-            }
-            else
-            {
-                if (dirtyFlags == SkyboxDirtyFlag::Texture)
-                    gRenderer()->notifySkyboxTextureChanged(this);
-                else
-                {
-                    gRenderer()->notifySkyboxRemoved(this);
-                    gRenderer()->notifySkyboxAdded(this);
-                }
-            }
-        }
-    }
+	SkyboxBase::SkyboxBase()
+		: mIsActive(true)
+	{ }
+
+	template <bool Core>
+	TSkybox<Core>::TSkybox()
+		: SkyboxBase()
+	{ }
+
+	template class TSkybox<true>;
+	template class TSkybox<false>;
+
+	Skybox::Skybox()
+	{ }
+
+	SPtr<ct::Skybox> Skybox::getCore() const
+	{
+		return std::static_pointer_cast<ct::Skybox>(mCoreSpecific);
+	}
+
+	SPtr<Skybox> Skybox::create()
+	{
+		Skybox* skybox = new (bs_alloc<Skybox>()) Skybox();
+		SPtr<Skybox> skyboxPtr = bs_core_ptr<Skybox>(skybox);
+		skyboxPtr->_setThisPtr(skyboxPtr);
+		skyboxPtr->mUUID = UUIDGenerator::generateRandom();
+		skyboxPtr->initialize();
+
+		return skyboxPtr;
+	}
+
+	SPtr<ct::CoreObject> Skybox::createCore() const
+	{
+		ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox();
+		SPtr<ct::Skybox> skyboxPtr = bs_shared_ptr<ct::Skybox>(skybox);
+		skyboxPtr->mUUID = mUUID;
+		skyboxPtr->_setThisPtr(skyboxPtr);
+
+		return skyboxPtr;
+	}
+
+	CoreSyncData Skybox::syncToCore(FrameAlloc* allocator)
+	{
+		UINT32 size = 0;
+		size += rttiGetElemSize(mIsActive);
+		size += sizeof(SPtr<ct::Texture>);
+		size += rttiGetElemSize(mUUID);
+		size += rttiGetElemSize(getCoreDirtyFlags());
+
+		UINT8* buffer = allocator->alloc(size);
+
+		char* dataPtr = (char*)buffer;
+		dataPtr = rttiWriteElem(mIsActive, dataPtr);
+		dataPtr = rttiWriteElem(mUUID, dataPtr);
+		dataPtr = rttiWriteElem(getCoreDirtyFlags(), dataPtr);
+
+		SPtr<ct::Texture>* texture = new (dataPtr) SPtr<ct::Texture>();
+		if (mTexture.isLoaded(false))
+			*texture = mTexture->getCore();
+		else
+			*texture = nullptr;
+
+		dataPtr += sizeof(SPtr<ct::Texture>);
+
+		return CoreSyncData(buffer, size);
+	}
+
+	void Skybox::_markCoreDirty(SkyboxDirtyFlag flags)
+	{
+		markCoreDirty((UINT32)flags);
+	}
+
+	RTTITypeBase* Skybox::getRTTIStatic()
+	{
+		return SkyboxRTTI::instance();
+	}
+
+	RTTITypeBase* Skybox::getRTTI() const
+	{
+		return Skybox::getRTTIStatic();
+	}
+
+	namespace ct
+	{
+		Skybox::Skybox()
+		{ }
+
+		Skybox::~Skybox()
+		{
+			gRenderer()->notifySkyboxRemoved(this);
+		}
+
+		void Skybox::initialize()
+		{
+			gRenderer()->notifySkyboxAdded(this);
+
+			CoreObject::initialize();
+		}
+
+		void Skybox::syncToCore(const CoreSyncData& data)
+		{
+			char* dataPtr = (char*)data.getBuffer();
+
+			SkyboxDirtyFlag dirtyFlags;
+			bool oldIsActive = mIsActive;
+
+			dataPtr = rttiReadElem(mIsActive, dataPtr);
+			dataPtr = rttiReadElem(mUUID, dataPtr);
+			dataPtr = rttiReadElem(dirtyFlags, dataPtr);
+
+			SPtr<Texture>* texture = (SPtr<Texture>*)dataPtr;
+
+			mTexture = *texture;
+			texture->~SPtr<Texture>();
+			dataPtr += sizeof(SPtr<Texture>);
+
+			if (oldIsActive != mIsActive)
+			{
+				if (mIsActive)
+					gRenderer()->notifySkyboxAdded(this);
+				else
+					gRenderer()->notifySkyboxRemoved(this);
+			}
+			else
+			{
+				if (dirtyFlags == SkyboxDirtyFlag::Texture)
+					gRenderer()->notifySkyboxTextureChanged(this);
+				else
+				{
+					gRenderer()->notifySkyboxRemoved(this);
+					gRenderer()->notifySkyboxAdded(this);
+				}
+			}
+		}
+	}
 }