|
20 | 20 | using namespace Supernova; |
21 | 21 |
|
22 | 22 | Scene::Scene(){ |
23 | | - registerSystem<ActionSystem>(); |
24 | | - registerSystem<MeshSystem>(); |
25 | | - registerSystem<UISystem>(); |
26 | | - registerSystem<RenderSystem>(); |
27 | | - registerSystem<PhysicsSystem>(); |
28 | | - registerSystem<AudioSystem>(); |
| 23 | + registerSystem<ActionSystem>(); |
| 24 | + registerSystem<MeshSystem>(); |
| 25 | + registerSystem<UISystem>(); |
| 26 | + registerSystem<RenderSystem>(); |
| 27 | + registerSystem<PhysicsSystem>(); |
| 28 | + registerSystem<AudioSystem>(); |
29 | 29 |
|
30 | | - camera = NULL_ENTITY; |
31 | | - defaultCamera = NULL_ENTITY; |
| 30 | + camera = NULL_ENTITY; |
| 31 | + defaultCamera = NULL_ENTITY; |
32 | 32 |
|
33 | | - backgroundColor = Vector4(0.0, 0.0, 0.0, 1.0); //sRGB |
34 | | - shadowsPCF = true; |
| 33 | + backgroundColor = Vector4(0.0, 0.0, 0.0, 1.0); //sRGB |
| 34 | + shadowsPCF = true; |
35 | 35 |
|
36 | | - lightState = LightState::AUTO; |
37 | | - globalIllumColor = Vector3(1.0, 1.0, 1.0); |
38 | | - globalIllumIntensity = 0.1; |
| 36 | + lightState = LightState::AUTO; |
| 37 | + globalIllumColor = Vector3(1.0, 1.0, 1.0); |
| 38 | + globalIllumIntensity = 0.1; |
39 | 39 |
|
40 | | - enableUIEvents = true; |
| 40 | + enableUIEvents = true; |
41 | 41 | } |
42 | 42 |
|
43 | 43 | Scene::~Scene(){ |
44 | | - destroy(); |
| 44 | + destroy(); |
45 | 45 | } |
46 | 46 |
|
47 | 47 | void Scene::setCamera(Camera* camera){ |
48 | | - setCamera(camera->getEntity()); |
| 48 | + setCamera(camera->getEntity()); |
49 | 49 | } |
50 | 50 |
|
51 | 51 | void Scene::setCamera(Entity camera){ |
52 | | - if (findComponent<CameraComponent>(camera)){ |
53 | | - this->camera = camera; |
54 | | - if (defaultCamera != NULL_ENTITY){ |
55 | | - destroyEntity(defaultCamera); |
56 | | - defaultCamera = NULL_ENTITY; |
57 | | - } |
58 | | - }else{ |
59 | | - Log::error("Invalid camera entity: need CameraComponent"); |
60 | | - } |
| 52 | + if (findComponent<CameraComponent>(camera)){ |
| 53 | + this->camera = camera; |
| 54 | + if (defaultCamera != NULL_ENTITY){ |
| 55 | + destroyEntity(defaultCamera); |
| 56 | + defaultCamera = NULL_ENTITY; |
| 57 | + } |
| 58 | + }else{ |
| 59 | + Log::error("Invalid camera entity: need CameraComponent"); |
| 60 | + } |
61 | 61 | } |
62 | 62 |
|
63 | 63 | Entity Scene::getCamera() const{ |
64 | | - return camera; |
| 64 | + return camera; |
65 | 65 | } |
66 | 66 |
|
67 | 67 | Entity Scene::createDefaultCamera(){ |
68 | | - defaultCamera = createEntity(); |
69 | | - addComponent<CameraComponent>(defaultCamera, {}); |
70 | | - addComponent<Transform>(defaultCamera, {}); |
| 68 | + defaultCamera = createEntity(); |
| 69 | + addComponent<CameraComponent>(defaultCamera, {}); |
| 70 | + addComponent<Transform>(defaultCamera, {}); |
71 | 71 |
|
72 | | - CameraComponent& camera = getComponent<CameraComponent>(defaultCamera); |
73 | | - camera.type = CameraType::CAMERA_2D; |
74 | | - camera.transparentSort = false; |
| 72 | + CameraComponent& camera = getComponent<CameraComponent>(defaultCamera); |
| 73 | + camera.type = CameraType::CAMERA_2D; |
| 74 | + camera.transparentSort = false; |
75 | 75 |
|
76 | | - Transform& cameratransform = getComponent<Transform>(defaultCamera); |
77 | | - cameratransform.position = Vector3(0.0, 0.0, 1.0); |
| 76 | + Transform& cameratransform = getComponent<Transform>(defaultCamera); |
| 77 | + cameratransform.position = Vector3(0.0, 0.0, 1.0); |
78 | 78 |
|
79 | | - return defaultCamera; |
| 79 | + return defaultCamera; |
80 | 80 | } |
81 | 81 |
|
82 | 82 | void Scene::setBackgroundColor(Vector4 color){ |
83 | | - this->backgroundColor = color; |
| 83 | + this->backgroundColor = color; |
84 | 84 | } |
85 | 85 |
|
86 | 86 | void Scene::setBackgroundColor(float red, float green, float blue){ |
87 | | - setBackgroundColor(Vector4(red, green, blue, 1.0)); |
| 87 | + setBackgroundColor(Vector4(red, green, blue, 1.0)); |
88 | 88 | } |
89 | 89 |
|
90 | 90 | void Scene::setBackgroundColor(float red, float green, float blue, float alpha){ |
91 | | - setBackgroundColor(Vector4(red, green, blue, alpha)); |
| 91 | + setBackgroundColor(Vector4(red, green, blue, alpha)); |
92 | 92 | } |
93 | 93 |
|
94 | 94 | Vector4 Scene::getBackgroundColor() const{ |
95 | | - return backgroundColor; |
| 95 | + return backgroundColor; |
96 | 96 | } |
97 | 97 |
|
98 | 98 | void Scene::setShadowsPCF(bool shadowsPCF){ |
99 | | - if (this->shadowsPCF != shadowsPCF){ |
100 | | - this->shadowsPCF = shadowsPCF; |
101 | | - getSystem<RenderSystem>()->needReloadMeshes(); |
102 | | - } |
| 99 | + if (this->shadowsPCF != shadowsPCF){ |
| 100 | + this->shadowsPCF = shadowsPCF; |
| 101 | + getSystem<RenderSystem>()->needReloadMeshes(); |
| 102 | + } |
103 | 103 | } |
104 | 104 |
|
105 | 105 | bool Scene::isShadowsPCF() const{ |
106 | | - return this->shadowsPCF; |
| 106 | + return this->shadowsPCF; |
107 | 107 | } |
108 | 108 |
|
109 | 109 | void Scene::setLightState(LightState state){ |
110 | | - if (this->lightState != state){ |
111 | | - this->lightState = state; |
112 | | - getSystem<RenderSystem>()->needReloadMeshes(); |
113 | | - } |
| 110 | + if (this->lightState != state){ |
| 111 | + this->lightState = state; |
| 112 | + getSystem<RenderSystem>()->needReloadMeshes(); |
| 113 | + } |
114 | 114 | } |
115 | 115 |
|
116 | 116 | LightState Scene::getLightState() const{ |
117 | | - return this->lightState; |
| 117 | + return this->lightState; |
118 | 118 | } |
119 | 119 |
|
120 | 120 | void Scene::setGlobalIllumination(float intensity, Vector3 color){ |
121 | | - this->globalIllumIntensity = intensity; |
122 | | - this->globalIllumColor = Color::sRGBToLinear(color); |
| 121 | + this->globalIllumIntensity = intensity; |
| 122 | + this->globalIllumColor = Color::sRGBToLinear(color); |
123 | 123 | } |
124 | 124 |
|
125 | 125 | void Scene::setGlobalIllumination(float intensity){ |
126 | | - this->globalIllumIntensity = intensity; |
| 126 | + this->globalIllumIntensity = intensity; |
127 | 127 | } |
128 | 128 |
|
129 | 129 | void Scene::setGlobalIllumination(Vector3 color){ |
130 | | - this->globalIllumColor = Color::sRGBToLinear(color); |
| 130 | + this->globalIllumColor = Color::sRGBToLinear(color); |
131 | 131 | } |
132 | 132 |
|
133 | 133 | float Scene::getGlobalIlluminationIntensity() const{ |
134 | | - return this->globalIllumIntensity; |
| 134 | + return this->globalIllumIntensity; |
135 | 135 | } |
136 | 136 |
|
137 | 137 | Vector3 Scene::getGlobalIlluminationColor() const{ |
138 | | - return Color::linearTosRGB(this->globalIllumColor); |
| 138 | + return Color::linearTosRGB(this->globalIllumColor); |
139 | 139 | } |
140 | 140 |
|
141 | 141 | Vector3 Scene::getGlobalIlluminationColorLinear() const{ |
142 | | - return this->globalIllumColor; |
| 142 | + return this->globalIllumColor; |
143 | 143 | } |
144 | 144 |
|
145 | 145 | bool Scene::canReceiveUIEvents(){ |
146 | | - if (Engine::getLastScene() == this && this->enableUIEvents){ |
147 | | - return true; |
148 | | - } |
149 | | - return false; |
| 146 | + if (Engine::getLastScene() == this && this->enableUIEvents){ |
| 147 | + return true; |
| 148 | + } |
| 149 | + return false; |
150 | 150 | } |
151 | 151 |
|
152 | 152 | bool Scene::isEnableUIEvents() const{ |
153 | | - return this->enableUIEvents; |
| 153 | + return this->enableUIEvents; |
154 | 154 | } |
155 | 155 |
|
156 | 156 | void Scene::setEnableUIEvents(bool enableUIEvents){ |
157 | | - this->enableUIEvents = enableUIEvents; |
| 157 | + this->enableUIEvents = enableUIEvents; |
158 | 158 | } |
159 | 159 |
|
160 | 160 | void Scene::load(){ |
161 | | - if (camera == NULL_ENTITY){ |
162 | | - camera = createDefaultCamera(); |
163 | | - } |
164 | | - |
165 | | - for (auto const &pair: systems) { |
166 | | - if (Engine::isViewLoaded()){ |
167 | | - pair.second->load(); |
168 | | - } |
169 | | - } |
| 161 | + if (camera == NULL_ENTITY){ |
| 162 | + camera = createDefaultCamera(); |
| 163 | + } |
| 164 | + |
| 165 | + for (auto const &pair: systems) { |
| 166 | + if (Engine::isViewLoaded()){ |
| 167 | + pair.second->load(); |
| 168 | + } |
| 169 | + } |
170 | 170 | } |
171 | 171 |
|
172 | 172 | void Scene::destroy(){ |
173 | | - for (auto const& pair : systems){ |
174 | | - pair.second->destroy(); |
175 | | - } |
| 173 | + for (auto const& pair : systems){ |
| 174 | + pair.second->destroy(); |
| 175 | + } |
176 | 176 | } |
177 | 177 |
|
178 | 178 | void Scene::draw(){ |
179 | | - for (auto const& pair : systems){ |
180 | | - pair.second->draw(); |
181 | | - } |
| 179 | + for (auto const& pair : systems){ |
| 180 | + pair.second->draw(); |
| 181 | + } |
182 | 182 | } |
183 | 183 |
|
184 | 184 |
|
185 | 185 | void Scene::update(double dt){ |
186 | | - for (auto const& pair : systems){ |
187 | | - pair.second->update(dt); |
188 | | - } |
| 186 | + for (auto const& pair : systems){ |
| 187 | + pair.second->update(dt); |
| 188 | + } |
189 | 189 | } |
190 | 190 |
|
191 | 191 | void Scene::updateSizeFromCamera(){ |
192 | | - getSystem<RenderSystem>()->updateCameraSize(getCamera()); |
| 192 | + getSystem<RenderSystem>()->updateCameraSize(getCamera()); |
193 | 193 | } |
0 commit comments