1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Components/BsCLight.h"
4#include "Private/RTTI/BsCLightRTTI.h"
5#include "Scene/BsSceneManager.h"
6
7namespace bs
8{
9 CLight::CLight()
10 {
11 setFlag(ComponentFlag::AlwaysRun, true);
12 setName("Light");
13 }
14
15 CLight::CLight(const HSceneObject& parent, LightType type, Color color,
16 float intensity, float range, bool castsShadows, Degree spotAngle, Degree spotFalloffAngle)
17 : Component(parent), mType(type), mColor(color), mIntensity(intensity), mRange(range),
18 mCastsShadows(castsShadows), mSpotAngle(spotAngle), mSpotFalloffAngle(spotFalloffAngle)
19 {
20 setFlag(ComponentFlag::AlwaysRun, true);
21 setName("Light");
22 }
23
24 CLight::~CLight()
25 { }
26
27 Sphere CLight::getBounds() const
28 {
29 mInternal->_updateState(*SO());
30
31 return mInternal->getBounds();
32 }
33
34 void CLight::onInitialized()
35 {
36 // If mInternal already exists this means this object was deserialized,
37 // so all we need to do is initialize it.
38 if (mInternal != nullptr)
39 mInternal->initialize();
40 else
41 {
42 mInternal = Light::create(
43 mType,
44 mColor,
45 mIntensity,
46 mRange,
47 mCastsShadows,
48 mSpotAngle,
49 mSpotFalloffAngle);
50 }
51
52 gSceneManager()._bindActor(mInternal, sceneObject());
53 }
54
55 void CLight::onDestroyed()
56 {
57 gSceneManager()._unbindActor(mInternal);
58 mInternal->destroy();
59 }
60
61 RTTITypeBase* CLight::getRTTIStatic()
62 {
63 return CLightRTTI::instance();
64 }
65
66 RTTITypeBase* CLight::getRTTI() const
67 {
68 return CLight::getRTTIStatic();
69 }
70}
71