internal static bool Prefix(Navigator ___navigator, int ___cell)
            {
                // If nothing has changed since last time, it is a hit!
                var  cached = PathCacher.Lookup(___navigator.PathProber);
                bool hit    = cached.CheckAndUpdate(___navigator, ___cell);

                if (debug)
                {
                    DebugMetrics.LogHit(hit);
                }
                return(!hit);
            }
Example #2
0
 /// <summary>
 /// Looks up the path cache for the given prober.
 /// </summary>
 /// <param name="prober">The path prober to look up.</param>
 /// <returns>The path cache for this path prober's ID.</returns>
 internal static PathCacher Lookup(PathProber prober)
 {
     if (prober == null)
     {
         throw new ArgumentNullException("prober");
     }
     if (!pathCache.TryGetValue(prober, out PathCacher cache))
     {
         pathCache.Add(prober, cache = new PathCacher());
     }
     return(cache);
 }
Example #3
0
            internal static bool Prefix(PathProber __instance, int cell, NavType nav_type,
                                        PathFinder.PotentialPath.Flags flags, NavGrid nav_grid,
                                        PathFinderAbilities abilities)
            {
                // If nothing has changed since last time, it is a hit!
                var  cached = PathCacher.Lookup(__instance);
                bool hit;

                if (hit = cached.CheckAndUpdate(nav_grid, cell, nav_type, abilities, flags))
                {
                    Interlocked.Increment(ref hits);
                }
                Interlocked.Increment(ref total);
                return(!hit);
            }
        internal static void OnStartGame()
        {
            var inst    = Game.Instance;
            var options = FastTrackOptions.Instance;

            if (options.CachePaths)
            {
                var fences = NavFences.AllFences;
                PathCacher.Init();
                foreach (var nav_grid in NAV_GRID_LIST.Get(Pathfinding.Instance))
                {
                    string id = nav_grid.id;
#if DEBUG
                    PUtil.LogDebug("Add nav grid: {0}".F(id));
#endif
                    if (fences.TryGetValue(id, out NavFences current))
                    {
                        current.Reset();
                    }
                    else
                    {
                        fences.Add(id, new NavFences());
                    }
                }
            }
            // Slices updates to Duplicant sensors
            if (inst != null)
            {
                var go = inst.gameObject;
                if (options.SensorOpts || options.PickupOpts)
                {
                    go.AddOrGet <SensorWrapperUpdater>();
                }
                if (options.AsyncPathProbe)
                {
                    go.AddOrGet <PathProbeJobManager>();
                }
                // If debugging is on, start logging
                if (debug)
                {
                    go.AddOrGet <DebugMetrics>();
                }
            }
        }
Example #5
0
        internal static void InitNavGrids()
        {
            var fences = NavFences.AllFences;

            PathCacher.Init();
            foreach (var nav_grid in NAV_GRID_LIST.Get(Pathfinding.Instance))
            {
                string id = nav_grid.id;
#if DEBUG
                PUtil.LogDebug("Add nav grid: {0}".F(id));
#endif
                if (fences.TryGetValue(id, out NavFences current))
                {
                    current.Reset();
                }
                else
                {
                    fences.Add(id, new NavFences());
                }
            }
        }