Exemple #1
0
        // Blits given source's lightMap onto the global lightmap given
        private static void blitSenseSource(SenseSource source, double[,] destination, HashSet <Coord> sourceMap, IMapView <double> resMap)
        {
            // Calculate actual radius bounds, given constraint based on location
            int minX = Math.Min((int)source.Radius, source.Position.X);
            int minY = Math.Min((int)source.Radius, source.Position.Y);
            int maxX = Math.Min((int)source.Radius, resMap.Width - 1 - source.Position.X);
            int maxY = Math.Min((int)source.Radius, resMap.Height - 1 - source.Position.Y);

            // Use radius bounds to extrapalate global coordinate scheme mins and maxes
            Coord gMin = source.Position - new Coord(minX, minY);
            //Coord gMax = source.Position + Coord.Get(maxX, maxY);

            // Use radius bound to extrapalate light-local coordinate scheme min and max bounds that
            // are actually blitted
            Coord lMin = new Coord((int)source.Radius - minX, (int)source.Radius - minY);
            Coord lMax = new Coord((int)source.Radius + maxX, (int)source.Radius + maxY);

            for (int xOffset = 0; xOffset <= lMax.X - lMin.X; xOffset++)
            //Parallel.For(0, lMax.X - lMin.X + 1, xOffset => // By light radius 30 or so, there is enough work to get benefit here.  Manual thread splitting may also be an option.
            {
                for (int yOffset = 0; yOffset <= lMax.Y - lMin.Y; yOffset++)
                {
                    // Offset local/current by proper amount, and update lightmap
                    Coord c    = new Coord(xOffset, yOffset);
                    Coord gCur = gMin + c;
                    Coord lCur = lMin + c;

                    destination[gCur.X, gCur.Y] = destination[gCur.X, gCur.Y] + source.light[lCur.X, lCur.Y];                     // Add source values,
                    if (destination[gCur.X, gCur.Y] > 0.0)
                    {
                        sourceMap.Add(gCur);
                    }
                }
            }             //);
        }
Exemple #2
0
 /// <summary>
 /// Removes the given source from the list of sources. Generally, use this if a source is permanently removed
 /// from a map. For temporary disabling, you should generally use the <see cref="SenseSource.Enabled" /> flag.
 /// </summary>
 /// <remarks>
 /// The source values that this sense source was responsible for are NOT removed from the sensory output values
 /// until <see cref="Calculate" /> is next called.
 /// </remarks>
 /// <param name="senseSource">The source to remove.</param>
 public void RemoveSenseSource(SenseSource senseSource)
 {
     _senseSources.Remove(senseSource);
     senseSource._resMap = null;
 }
Exemple #3
0
 /// <summary>
 /// Adds the given source to the list of sources. If the source has its
 /// <see cref="SenseSource.Enabled" /> flag set when <see cref="Calculate" /> is next called, then
 /// it will be counted as a source.
 /// </summary>
 /// <param name="senseSource">The source to add.</param>
 public void AddSenseSource(SenseSource senseSource)
 {
     _senseSources.Add(senseSource);
     senseSource._resMap = _resMap;
 }