Example #1
0
            public void UpdateLights(IEnumerable <LightSource> lights, vec3 camera, uint count)
            {
                var change = false;

                LightCount = 0u;
                LightsHeap.Clear();                 // Generates garbage

                foreach (var light in lights)
                {
                    LightsHeap.Insert(light ^ camera, light);
                }

                for (LightCount = 0u; LightCount < count; ++LightCount)
                {
                    if (LightsHeap.Count == 0)
                    {
                        break;
                    }

                    var i = (int)LightCount;

                    var light = LightsHeap.RemoveMin().Data;

                    if (i < OrderedLights.Count)
                    {
                        if (LightSource.AreEqual(light, OrderedLights[i]))
                        {
                            continue;
                        }
                        OrderedLights[i] = light;
                    }
                    else
                    {
                        OrderedLights.Add(light);
                    }

                    change = true;
                }

                if (change)
                {
                    ++LightingState;
                }
            }