Exemple #1
0
 static OctantBuilder()
 {
     // Cache the method for faster execution
     OCTANT_SCAN = typeof(DiscreteShadowCaster).CreateStaticDelegate <ScanOctantFunc>(
         "ScanOctant", typeof(Vector2I), typeof(int), typeof(int), typeof(Octant),
         typeof(double), typeof(double), typeof(List <int>));
     if (OCTANT_SCAN == null)
     {
         PLightManager.LogLightingWarning("OctantBuilder cannot find default octant scanner!");
     }
 }
Exemple #2
0
        /// <summary>
        /// Creates and initializes the lighting manager instance.
        /// </summary>
        /// <returns>true if the lighting manager was initialized and has something to do,
        /// or false otherwise.</returns>
        internal static bool InitInstance()
        {
            bool patch = false;

            lock (PSharedData.GetLock(PRegistry.KEY_LIGHTING_LOCK)) {
                // Only run if any lights were registered
                var list = PSharedData.GetData <IList <object> >(PRegistry.KEY_LIGHTING_TABLE);
                if (list != null)
                {
                    Instance = new PLightManager();
                    Instance.Init(list);
                    patch = true;
                }
            }
            // Initialize anyways if smooth lighting is forced on
            if (!patch && ForceSmoothLight)
            {
                Instance = new PLightManager();
                patch    = true;
            }
            return(patch);
        }
Exemple #3
0
        /// <summary>
        /// Adds an octant of light.
        /// </summary>
        /// <param name="range">The range of the light.</param>
        /// <param name="octant">The octant to scan.</param>
        /// <returns>This object, for call chaining.</returns>
        public OctantBuilder AddOctant(int range, Octant octant)
        {
            var points = ListPool <int, OctantBuilder> .Allocate();

            OCTANT_SCAN?.Invoke(Grid.CellToXY(SourceCell), range, 1, octant, 1.0, 0.0, points);
            // Transfer to our array using:
            foreach (int cell in points)
            {
                float intensity;
                if (SmoothLight)
                {
                    // Better, not rounded falloff
                    intensity = PLightManager.GetSmoothFalloff(Falloff, cell, SourceCell);
                }
                else
                {
                    // Default falloff
                    intensity = PLightManager.GetDefaultFalloff(Falloff, cell, SourceCell);
                }
                destination[cell] = intensity;
            }
            points.Recycle();
            return(this);
        }