@@ -22,12 +22,11 @@ LightSystem* LightSystem::GetSingleton()
22
22
StaticPointLightsInfo LightSystem::getStaticPointLights ()
23
23
{
24
24
StaticPointLightsInfo staticLights;
25
- Vector <StaticPointLightComponent>& staticPointLightComponents = ECSFactory::GetAllStaticPointLightComponent ();
25
+ ComponentArray <StaticPointLightComponent>& staticPointLightComponents = ECSFactory::GetAllStaticPointLightComponent ();
26
26
27
27
int i = 0 ;
28
- for (; i < staticPointLightComponents. size () && i < MAX_STATIC_POINT_LIGHTS; i++ )
28
+ for (auto && staticLight : staticPointLightComponents )
29
29
{
30
- StaticPointLightComponent& staticLight = staticPointLightComponents[i];
31
30
Vector3 transformedPosition = staticLight.getAbsoluteTransform ().Translation ();
32
31
const PointLight& pointLight = staticLight.getPointLight ();
33
32
@@ -39,6 +38,11 @@ StaticPointLightsInfo LightSystem::getStaticPointLights()
39
38
staticLights.pointLightInfos [i].attQuad = pointLight.attQuad ;
40
39
staticLights.pointLightInfos [i].lightPos = transformedPosition;
41
40
staticLights.pointLightInfos [i].range = pointLight.range ;
41
+ i++;
42
+ if (i == MAX_STATIC_POINT_LIGHTS)
43
+ {
44
+ break ;
45
+ }
42
46
}
43
47
return staticLights;
44
48
}
@@ -56,13 +60,14 @@ LightsInfo LightSystem::getDynamicLights()
56
60
return Vector3::DistanceSquared (cameraPos, aa) < Vector3::DistanceSquared (cameraPos, bb);
57
61
};
58
62
59
- Vector<PointLightComponent>& pointLightComponents = ECSFactory::GetAllPointLightComponent ();
60
- sort (pointLightComponents.begin (), pointLightComponents.end (), pointLightSortingLambda);
63
+ ComponentArray<PointLightComponent>& pointLightComponents = ECSFactory::GetAllPointLightComponent ();
64
+ // TODO: Implement sorting. Currently due to raw pointers in components it is not possible to sort without guaranteeing there
65
+ // won't be any memory corruption.
66
+ // sort(pointLightComponents.begin(), pointLightComponents.end(), pointLightSortingLambda);
61
67
62
68
int i = 0 ;
63
- for (; i < pointLightComponents. size () && i < MAX_DYNAMIC_POINT_LIGHTS; i++ )
69
+ for (auto && light : pointLightComponents )
64
70
{
65
- PointLightComponent& light = pointLightComponents[i];
66
71
Vector3 transformedPosition = light.getAbsoluteTransform ().Translation ();
67
72
const PointLight& pointLight = light.getPointLight ();
68
73
@@ -74,10 +79,15 @@ LightsInfo LightSystem::getDynamicLights()
74
79
lights.pointLightInfos [i].attQuad = pointLight.attQuad ;
75
80
lights.pointLightInfos [i].lightPos = transformedPosition;
76
81
lights.pointLightInfos [i].range = pointLight.range ;
82
+ i++;
83
+ if (i == MAX_DYNAMIC_POINT_LIGHTS)
84
+ {
85
+ break ;
86
+ }
77
87
}
78
88
lights.pointLightCount = i;
79
89
80
- Vector <DirectionalLightComponent>& directionalLightComponents = ECSFactory::GetAllDirectionalLightComponent ();
90
+ ComponentArray <DirectionalLightComponent>& directionalLightComponents = ECSFactory::GetAllDirectionalLightComponent ();
81
91
if (directionalLightComponents.size () > 0 )
82
92
{
83
93
if (directionalLightComponents.size () > 1 )
@@ -104,16 +114,18 @@ LightsInfo LightSystem::getDynamicLights()
104
114
return Vector3::DistanceSquared (cameraPos, aa) < Vector3::DistanceSquared (cameraPos, bb);
105
115
};
106
116
107
- Vector<SpotLightComponent>& spotLightComponents = ECSFactory::GetAllSpotLightComponent ();
108
- sort (spotLightComponents.begin (), spotLightComponents.end (), spotLightSortingLambda);
117
+ ComponentArray<SpotLightComponent>& spotLightComponents = ECSFactory::GetAllSpotLightComponent ();
118
+ // TODO: Implement sorting. Currently due to raw pointers in components it is not possible to sort without guarrateeing there
119
+ // won't be any memory corruption.
120
+ // sort(spotLightComponents.begin(), spotLightComponents.end(), spotLightSortingLambda);
109
121
110
122
i = 0 ;
111
- for (; i < spotLightComponents. size () && i < MAX_DYNAMIC_SPOT_LIGHTS; i++ )
123
+ for (auto && light : spotLightComponents )
112
124
{
113
- SpotLightComponent& light = spotLightComponents[i];
114
125
Matrix transform = light.getAbsoluteTransform ();
115
126
const SpotLight& spotLight = light.getSpotLight ();
116
-
127
+
128
+ i++;
117
129
lights.spotLightInfos [i] = {
118
130
spotLight.ambientColor ,
119
131
spotLight.diffuseColor ,
0 commit comments