public void Update(bool parallelUpdate)
        {
            /*
             * if (IntersectionTestsLastFrame > 0)
             *  Debug.WriteLine("{0} intersection tests last frame", IntersectionTestsLastFrame);
             */

            IntersectionTestsLastFrame = 0;

            var options = new ParallelOptions();

            if (!parallelUpdate)
            {
                options.MaxDegreeOfParallelism = 1;
            }

            _ObstructionsByLight.Clear();
#if SDL2
            // Parallel is Satan -flibit
            foreach (LightSource ls in Environment.LightSources)
            {
                LineGeneratorContext ctx = new LineGeneratorContext(Environment.Obstructions.Count * 2);
                GenerateLinesForLightSource(ref ctx, ls);
                lock (_ObstructionsByLight)
                {
                    foreach (var kvp in ctx.Queue)
                    {
                        _ObstructionsByLight.Add(kvp.LightSource, kvp.Lines);
                    }
                }
                ctx.Dispose();
            }
#else
            using (var buffer = BufferPool <LightSource> .Allocate(Environment.LightSources.Count)) {
                Environment.LightSources.CopyTo(buffer.Data);

                Parallel.For(
                    0, Environment.LightSources.Count,
                    options,
                    () => new LineGeneratorContext(Environment.Obstructions.Count * 2),
                    (idx, pls, ctx) => {
                    var ls = buffer.Data[idx];
                    GenerateLinesForLightSource(ref ctx, ls);
                    return(ctx);
                },
                    (ctx) => {
                    lock (_ObstructionsByLight)
                        foreach (var kvp in ctx.Queue)
                        {
                            _ObstructionsByLight.Add(kvp.LightSource, kvp.Lines);
                        }

                    ctx.Dispose();
                }
                    );
            }
#endif
        }
        private void GenerateLinesForLightSource(ref LineGeneratorContext context, LightSource lightSource)
        {
            context.LineWriter.CropBounds = lightSource.Bounds;

            Environment.EnumerateObstructionLinesInBounds(lightSource.Bounds, context.LineWriter);

            context.LineWriter.CropBounds = null;

            context.Queue.Add(new LinesForLightSource(lightSource, context.LineWriter));
            context.LineWriter.Reset();
        }