Repository navigation
Expand file tree
/
Copy pathLight.cpp
More file actions
93 lines (81 loc) · 1.94 KB
/
Copy pathLight.cpp
File metadata and controls
93 lines (81 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Light.h"
#include <deki/Engine.h>
#include <deki/Object.h>
#include <deki/SceneSystem.h>
#include <algorithm>
namespace DekiRendering
{
namespace
{
// Every Light alive, in the order they were made. A scene holds tens of
// lights at most, so the renderers scan this once a frame instead of walking
// the scene for them.
std::vector<Light*>& Lights()
{
static std::vector<Light*> s_Lights;
return s_Lights;
}
uint32_t s_ListVersion = 0;
bool IsPersistent(const Deki::Object* obj)
{
while (obj->GetParent())
{
obj = obj->GetParent();
}
const auto& persistent = Deki::Engine::GetInstance().GetSceneSystem().GetPersistentObjects();
return std::find(persistent.begin(), persistent.end(), obj) != persistent.end();
}
} // namespace
Light::Light()
{
Lights().push_back(this);
s_ListVersion++;
}
Light::~Light()
{
auto& lights = Lights();
lights.erase(std::remove(lights.begin(), lights.end(), this), lights.end());
s_ListVersion++;
}
bool Light::Shines() const
{
const Deki::Object* owner = GetOwner();
if (!owner || !owner->IsActiveInHierarchy() || !(intensity > 0.0f))
{
return false;
}
if (color.r == 0 && color.g == 0 && color.b == 0)
{
return false;
}
if ((type == LightType::Point || type == LightType::Spot) && !(range > 0.0f))
{
return false;
}
return true;
}
void Light::InScene(const Deki::Scene* scene, std::vector<const Light*>& out)
{
out.clear();
for (const Light* light : Lights())
{
const Deki::Object* owner = light->GetOwner();
if (!owner || !owner->IsActiveInHierarchy())
{
continue;
}
if (owner->GetOwnerScene() == scene || IsPersistent(owner))
{
out.push_back(light);
}
}
}
const std::vector<Light*>& Light::All()
{
return Lights();
}
uint32_t Light::ListVersion()
{
return s_ListVersion;
}
} // namespace DekiRendering