Przeglądaj źródła

Clear states in RenderStateManager before shutdown as states try to access that manager when they're destructed
Added a missing renamed file

BearishSun 10 lat temu
rodzic
commit
4bfb7023eb

+ 5 - 0
BansheeCore/Include/BsRenderStateManager.h

@@ -241,6 +241,11 @@ namespace BansheeEngine
 		friend class RasterizerStateCore;
 		friend class DepthStencilStateCore;
 
+		/**
+		 * @copydoc	Module::onShutDown
+		 */
+		void onShutDown() override;
+
 		/**
 		 * @copydoc	createSamplerState
 		 */

+ 8 - 0
BansheeCore/Source/BsRenderStateManager.cpp

@@ -240,6 +240,14 @@ namespace BansheeEngine
 		return state;
 	}
 
+	void RenderStateCoreManager::onShutDown()
+	{
+		mDefaultBlendState = nullptr;
+		mDefaultDepthStencilState = nullptr;
+		mDefaultRasterizerState = nullptr;
+		mDefaultSamplerState = nullptr;
+	}
+
 	const SPtr<SamplerStateCore>& RenderStateCoreManager::getDefaultSamplerState() const
 	{
 		if (mDefaultSamplerState == nullptr)

+ 70 - 0
SBansheeEngine/Include/BsScriptLight.h

@@ -0,0 +1,70 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsVector3.h"
+#include "BsQuaternion.h"
+#include "BsDegree.h"
+#include "BsColor.h"
+#include "BsLight.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for Light.
+	 */
+	class BS_SCR_BE_EXPORT ScriptLight : public ScriptObject <ScriptLight>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "NativeLight")
+
+		/**
+		 * @brief	Gets the wrapped native LightInternal object.
+		 */
+		SPtr<Light> getInternal() const { return mLight; }
+
+	private:
+		ScriptLight(MonoObject* managedInstance, const HSceneObject& parentSO);
+		~ScriptLight();
+
+		SPtr<Light> mLight;
+		UINT32 mLastUpdateHash;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_create(MonoObject* managedInstance, ScriptSceneObject* parentSO);
+
+		static Vector3 internal_getPosition(ScriptLight* thisPtr);
+		static void internal_setPosition(ScriptLight* thisPtr, Vector3 position);
+
+		static Quaternion internal_getRotation(ScriptLight* thisPtr);
+		static void internal_setRotation(ScriptLight* thisPtr, Quaternion rotation);
+
+		static LightType internal_getType(ScriptLight* thisPtr);
+		static void internal_setType(ScriptLight* thisPtr, LightType type);
+
+		static bool internal_getCastsShadow(ScriptLight* thisPtr);
+		static void internal_setCastsShadow(ScriptLight* thisPtr, bool castsShadow);
+
+		static Color internal_getColor(ScriptLight* thisPtr);
+		static void internal_setColor(ScriptLight* thisPtr, Color color);
+
+		static float internal_getRange(ScriptLight* thisPtr);
+		static void internal_setRange(ScriptLight* thisPtr, float range);
+
+		static float internal_getIntensity(ScriptLight* thisPtr);
+		static void internal_setIntensity(ScriptLight* thisPtr, float intensity);
+
+		static Degree internal_getSpotAngle(ScriptLight* thisPtr);
+		static void internal_setSpotAngle(ScriptLight* thisPtr, Degree spotAngle);
+
+		static Degree internal_getSpotFalloffAngle(ScriptLight* thisPtr);
+		static void internal_setSpotFalloffAngle(ScriptLight* thisPtr, Degree spotFalloffAngle);
+
+		static Sphere internal_getBounds(ScriptLight* thisPtr);
+
+		static void internal_updateTransform(ScriptLight* thisPtr, ScriptSceneObject* parent);
+		static void internal_onDestroy(ScriptLight* instance);
+	};
+}

+ 165 - 0
SBansheeEngine/Source/BsScriptLight.cpp

@@ -0,0 +1,165 @@
+#include "BsScriptLight.h"
+#include "BsScriptSceneObject.h"
+#include "BsSceneObject.h"
+#include "BsScriptSceneObject.h"
+#include "BsSceneManager.h"
+
+namespace BansheeEngine
+{
+	ScriptLight::ScriptLight(MonoObject* managedInstance, const HSceneObject& parentSO)
+		:ScriptObject(managedInstance), mLight(nullptr), mLastUpdateHash(0)
+	{
+		mLight = Light::create();
+		gSceneManager()._registerLight(mLight, parentSO);
+	}
+
+	ScriptLight::~ScriptLight()
+	{
+
+	}
+
+	void ScriptLight::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptLight::internal_create);
+
+		metaData.scriptClass->addInternalCall("Internal_GetPosition", &ScriptLight::internal_getPosition);
+		metaData.scriptClass->addInternalCall("Internal_SetPosition", &ScriptLight::internal_setPosition);
+		metaData.scriptClass->addInternalCall("Internal_GetRotation", &ScriptLight::internal_getRotation);
+		metaData.scriptClass->addInternalCall("Internal_SetRotation", &ScriptLight::internal_setRotation);
+		metaData.scriptClass->addInternalCall("Internal_GetType", &ScriptLight::internal_getType);
+		metaData.scriptClass->addInternalCall("Internal_SetType", &ScriptLight::internal_setType);
+		metaData.scriptClass->addInternalCall("Internal_GetCastsShadow", &ScriptLight::internal_getCastsShadow);
+		metaData.scriptClass->addInternalCall("Internal_SetCastsShadow", &ScriptLight::internal_setCastsShadow);
+		metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptLight::internal_getColor);
+		metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptLight::internal_setColor);
+		metaData.scriptClass->addInternalCall("Internal_GetRange", &ScriptLight::internal_getRange);
+		metaData.scriptClass->addInternalCall("Internal_SetRange", &ScriptLight::internal_setRange);
+		metaData.scriptClass->addInternalCall("Internal_GetIntensity", &ScriptLight::internal_getIntensity);
+		metaData.scriptClass->addInternalCall("Internal_SetIntensity", &ScriptLight::internal_setIntensity);
+		metaData.scriptClass->addInternalCall("Internal_GetSpotAngle", &ScriptLight::internal_getSpotAngle);
+		metaData.scriptClass->addInternalCall("Internal_SetSpotAngle", &ScriptLight::internal_setSpotAngle);
+		metaData.scriptClass->addInternalCall("Internal_GetSpotFalloffAngle", &ScriptLight::internal_getSpotFalloffAngle);
+		metaData.scriptClass->addInternalCall("Internal_SetSpotFalloffAngle", &ScriptLight::internal_setSpotFalloffAngle);
+		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptLight::internal_getBounds);
+		metaData.scriptClass->addInternalCall("Internal_UpdateTransform", &ScriptLight::internal_updateTransform);
+		metaData.scriptClass->addInternalCall("Internal_OnDestroy", &ScriptLight::internal_onDestroy);
+	}
+
+	void ScriptLight::internal_create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
+	{
+		HSceneObject so;
+		if (parentSO != nullptr)
+			so = parentSO->getNativeHandle();
+
+		ScriptLight* nativeInstance = new (bs_alloc<ScriptLight>()) ScriptLight(managedInstance, so);
+	}
+
+	Vector3 ScriptLight::internal_getPosition(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getPosition();
+	}
+
+	void ScriptLight::internal_setPosition(ScriptLight* thisPtr, Vector3 position)
+	{
+		thisPtr->getInternal()->setPosition(position);
+	}
+
+	Quaternion ScriptLight::internal_getRotation(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getRotation();
+	}
+
+	void ScriptLight::internal_setRotation(ScriptLight* thisPtr, Quaternion rotation)
+	{
+		thisPtr->getInternal()->setRotation(rotation);
+	}
+
+	LightType ScriptLight::internal_getType(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getType();
+	}
+
+	void ScriptLight::internal_setType(ScriptLight* thisPtr, LightType type)
+	{
+		thisPtr->getInternal()->setType(type);
+	}
+
+	bool ScriptLight::internal_getCastsShadow(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getCastsShadow();
+	}
+
+	void ScriptLight::internal_setCastsShadow(ScriptLight* thisPtr, bool castsShadow)
+	{
+		thisPtr->getInternal()->setCastsShadow(castsShadow);
+	}
+
+	Color ScriptLight::internal_getColor(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getColor();
+	}
+
+	void ScriptLight::internal_setColor(ScriptLight* thisPtr, Color color)
+	{
+		thisPtr->getInternal()->setColor(color);
+	}
+
+	float ScriptLight::internal_getRange(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getRange();
+	}
+
+	void ScriptLight::internal_setRange(ScriptLight* thisPtr, float range)
+	{
+		thisPtr->getInternal()->setRange(range);
+	}
+
+	float ScriptLight::internal_getIntensity(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getIntensity();
+	}
+
+	void ScriptLight::internal_setIntensity(ScriptLight* thisPtr, float intensity)
+	{
+		thisPtr->getInternal()->setIntensity(intensity);
+	}
+
+	Degree ScriptLight::internal_getSpotAngle(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getSpotAngle();
+	}
+
+	void ScriptLight::internal_setSpotAngle(ScriptLight* thisPtr, Degree spotAngle)
+	{
+		thisPtr->getInternal()->setSpotAngle(spotAngle);
+	}
+
+	Degree ScriptLight::internal_getSpotFalloffAngle(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getSpotFalloffAngle();
+	}
+
+	void ScriptLight::internal_setSpotFalloffAngle(ScriptLight* thisPtr, Degree spotFalloffAngle)
+	{
+		thisPtr->getInternal()->setSpotFalloffAngle(spotFalloffAngle);
+	}
+
+	Sphere ScriptLight::internal_getBounds(ScriptLight* thisPtr)
+	{
+		return thisPtr->getInternal()->getBounds();
+	}
+
+	void ScriptLight::internal_updateTransform(ScriptLight* thisPtr, ScriptSceneObject* parent)
+	{
+		HSceneObject parentSO = parent->getNativeSceneObject();
+
+		if (!parentSO.isDestroyed())
+			thisPtr->getInternal()->_updateTransform(parentSO);
+	}
+
+	void ScriptLight::internal_onDestroy(ScriptLight* instance)
+	{
+		gSceneManager()._unregisterLight(instance->getInternal());
+		instance->getInternal()->destroy();
+	}
+}