BsScriptLight.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Wrappers/BsScriptLight.h"
  4. #include "Wrappers/BsScriptSceneObject.h"
  5. #include "Scene/BsSceneObject.h"
  6. #include "Scene/BsSceneManager.h"
  7. namespace bs
  8. {
  9. ScriptLight::ScriptLight(MonoObject* managedInstance, const HSceneObject& parentSO)
  10. :ScriptObject(managedInstance), mLight(nullptr), mLastUpdateHash(0)
  11. {
  12. mLight = Light::create();
  13. gSceneManager()._registerLight(mLight, parentSO);
  14. }
  15. ScriptLight::~ScriptLight()
  16. { }
  17. void ScriptLight::initRuntimeData()
  18. {
  19. metaData.scriptClass->addInternalCall("Internal_Create", (void*)&ScriptLight::internal_create);
  20. metaData.scriptClass->addInternalCall("Internal_GetType", (void*)&ScriptLight::internal_getType);
  21. metaData.scriptClass->addInternalCall("Internal_SetType", (void*)&ScriptLight::internal_setType);
  22. metaData.scriptClass->addInternalCall("Internal_GetCastsShadow", (void*)&ScriptLight::internal_getCastsShadow);
  23. metaData.scriptClass->addInternalCall("Internal_SetCastsShadow", (void*)&ScriptLight::internal_setCastsShadow);
  24. metaData.scriptClass->addInternalCall("Internal_GetUseAutoAttenuation",
  25. (void*)&ScriptLight::internal_getUseAutoAttenuation);
  26. metaData.scriptClass->addInternalCall("Internal_SetUseAutoAttenuation",
  27. (void*)&ScriptLight::internal_setUseAutoAttenuation);
  28. metaData.scriptClass->addInternalCall("Internal_GetColor", (void*)&ScriptLight::internal_getColor);
  29. metaData.scriptClass->addInternalCall("Internal_SetColor", (void*)&ScriptLight::internal_setColor);
  30. metaData.scriptClass->addInternalCall("Internal_GetAttenuationRadius", (void*)&ScriptLight::internal_getAttenuationRadius);
  31. metaData.scriptClass->addInternalCall("Internal_SetAttenuationRadius", (void*)&ScriptLight::internal_setAttenuationRadius);
  32. metaData.scriptClass->addInternalCall("Internal_GetSourceRadius", (void*)&ScriptLight::internal_getSourceRadius);
  33. metaData.scriptClass->addInternalCall("Internal_SetSourceRadius", (void*)&ScriptLight::internal_setSourceRadius);
  34. metaData.scriptClass->addInternalCall("Internal_GetIntensity", (void*)&ScriptLight::internal_getIntensity);
  35. metaData.scriptClass->addInternalCall("Internal_SetIntensity", (void*)&ScriptLight::internal_setIntensity);
  36. metaData.scriptClass->addInternalCall("Internal_GetSpotAngle", (void*)&ScriptLight::internal_getSpotAngle);
  37. metaData.scriptClass->addInternalCall("Internal_SetSpotAngle", (void*)&ScriptLight::internal_setSpotAngle);
  38. metaData.scriptClass->addInternalCall("Internal_GetSpotFalloffAngle", (void*)&ScriptLight::internal_getSpotFalloffAngle);
  39. metaData.scriptClass->addInternalCall("Internal_SetSpotFalloffAngle", (void*)&ScriptLight::internal_setSpotFalloffAngle);
  40. metaData.scriptClass->addInternalCall("Internal_GetBounds", (void*)&ScriptLight::internal_getBounds);
  41. metaData.scriptClass->addInternalCall("Internal_UpdateTransform", (void*)&ScriptLight::internal_updateTransform);
  42. metaData.scriptClass->addInternalCall("Internal_OnDestroy", (void*)&ScriptLight::internal_onDestroy);
  43. }
  44. void ScriptLight::internal_create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
  45. {
  46. HSceneObject so;
  47. if (parentSO != nullptr)
  48. so = parentSO->getNativeHandle();
  49. new (bs_alloc<ScriptLight>()) ScriptLight(managedInstance, so);
  50. }
  51. LightType ScriptLight::internal_getType(ScriptLight* thisPtr)
  52. {
  53. return thisPtr->getInternal()->getType();
  54. }
  55. void ScriptLight::internal_setType(ScriptLight* thisPtr, LightType type)
  56. {
  57. thisPtr->getInternal()->setType(type);
  58. }
  59. bool ScriptLight::internal_getCastsShadow(ScriptLight* thisPtr)
  60. {
  61. return thisPtr->getInternal()->getCastsShadow();
  62. }
  63. void ScriptLight::internal_setCastsShadow(ScriptLight* thisPtr, bool castsShadow)
  64. {
  65. thisPtr->getInternal()->setCastsShadow(castsShadow);
  66. }
  67. bool ScriptLight::internal_getUseAutoAttenuation(ScriptLight* thisPtr)
  68. {
  69. return thisPtr->getInternal()->getUseAutoAttenuation();
  70. }
  71. void ScriptLight::internal_setUseAutoAttenuation(ScriptLight* thisPtr, bool value)
  72. {
  73. thisPtr->getInternal()->setUseAutoAttenuation(value);
  74. }
  75. void ScriptLight::internal_getColor(ScriptLight* thisPtr, Color* color)
  76. {
  77. *color = thisPtr->getInternal()->getColor();
  78. }
  79. void ScriptLight::internal_setColor(ScriptLight* thisPtr, Color color)
  80. {
  81. thisPtr->getInternal()->setColor(color);
  82. }
  83. float ScriptLight::internal_getAttenuationRadius(ScriptLight* thisPtr)
  84. {
  85. return thisPtr->getInternal()->getAttenuationRadius();
  86. }
  87. void ScriptLight::internal_setAttenuationRadius(ScriptLight* thisPtr, float radius)
  88. {
  89. thisPtr->getInternal()->setAttenuationRadius(radius);
  90. }
  91. float ScriptLight::internal_getSourceRadius(ScriptLight* thisPtr)
  92. {
  93. return thisPtr->getInternal()->getSourceRadius();
  94. }
  95. void ScriptLight::internal_setSourceRadius(ScriptLight* thisPtr, float radius)
  96. {
  97. thisPtr->getInternal()->setSourceRadius(radius);
  98. }
  99. float ScriptLight::internal_getIntensity(ScriptLight* thisPtr)
  100. {
  101. return thisPtr->getInternal()->getIntensity();
  102. }
  103. void ScriptLight::internal_setIntensity(ScriptLight* thisPtr, float intensity)
  104. {
  105. thisPtr->getInternal()->setIntensity(intensity);
  106. }
  107. float ScriptLight::internal_getSpotAngle(ScriptLight* thisPtr)
  108. {
  109. return thisPtr->getInternal()->getSpotAngle().valueDegrees();
  110. }
  111. void ScriptLight::internal_setSpotAngle(ScriptLight* thisPtr, float spotAngle)
  112. {
  113. thisPtr->getInternal()->setSpotAngle(Degree(spotAngle));
  114. }
  115. float ScriptLight::internal_getSpotFalloffAngle(ScriptLight* thisPtr)
  116. {
  117. return thisPtr->getInternal()->getSpotFalloffAngle().valueDegrees();
  118. }
  119. void ScriptLight::internal_setSpotFalloffAngle(ScriptLight* thisPtr, float spotFalloffAngle)
  120. {
  121. thisPtr->getInternal()->setSpotFalloffAngle(Degree(spotFalloffAngle));
  122. }
  123. void ScriptLight::internal_getBounds(ScriptLight* thisPtr, Sphere* bounds)
  124. {
  125. *bounds = thisPtr->getInternal()->getBounds();
  126. }
  127. void ScriptLight::internal_updateTransform(ScriptLight* thisPtr, ScriptSceneObject* parent)
  128. {
  129. HSceneObject parentSO = parent->getNativeSceneObject();
  130. if (!parentSO.isDestroyed())
  131. {
  132. thisPtr->getInternal()->_updateTransform(parentSO);
  133. if (parentSO->getActive() != thisPtr->getInternal()->getIsActive())
  134. {
  135. thisPtr->getInternal()->setIsActive(parentSO->getActive());
  136. }
  137. }
  138. }
  139. void ScriptLight::internal_onDestroy(ScriptLight* instance)
  140. {
  141. instance->destroy();
  142. }
  143. void ScriptLight::destroy()
  144. {
  145. if (mLight->isDestroyed())
  146. return;
  147. gSceneManager()._unregisterLight(mLight);
  148. mLight->destroy();
  149. }
  150. void ScriptLight::_onManagedInstanceDeleted()
  151. {
  152. destroy();
  153. ScriptObject::_onManagedInstanceDeleted();
  154. }
  155. }