コード例 #1
0
        protected override void Awake()
        {
            Logger.LogInfo("PathManager hook installed");

            this.m_simulationProfiler = new ThreadProfiler();
            typeof(PathManager)
                .GetFieldByName("m_sampleName")
                .SetValue(this, base.gameObject.name);

            this.m_pathUnits = new Array32<PathUnit>(262144u);
            this.m_bufferLock = new object();
            uint num;
            this.m_pathUnits.CreateItem(out num);
            int num2 = Mathf.Clamp(SystemInfo.processorCount / 2, 1, 4);
            var facades = new ExtendedPathFindFacade[num2];
            for (int i = 0; i < num2; i++)
            {
                facades[i] = base.gameObject.AddComponent<ExtendedPathFindFacade>();
            }

            ExtendedPathManager.PathFindFacades = facades;
            typeof(PathManager)
                .GetFieldByName("m_pathfinds")
                .SetValue(this, facades.OfType<PathFind>().ToArray());
        }
コード例 #2
0
        protected override void Awake()
        {
            Logger.LogInfo("PathManager hook installed");

            this.m_simulationProfiler = new ThreadProfiler();
            typeof(PathManager)
            .GetFieldByName("m_sampleName")
            .SetValue(this, base.gameObject.name);

            this.m_pathUnits  = new Array32 <PathUnit>(262144u);
            this.m_bufferLock = new object();
            uint num;

            this.m_pathUnits.CreateItem(out num);
            int num2    = Mathf.Clamp(SystemInfo.processorCount / 2, 1, 4);
            var facades = new ExtendedPathFindFacade[num2];

            for (int i = 0; i < num2; i++)
            {
                facades[i] = base.gameObject.AddComponent <ExtendedPathFindFacade>();
            }

            ExtendedPathManager.PathFindFacades = facades;
            typeof(PathManager)
            .GetFieldByName("m_pathfinds")
            .SetValue(this, facades.OfType <PathFind>().ToArray());
        }
コード例 #3
0
        public static IExtendedPathFind CreatePathFinding(this ExtendedPathFindFacade facade)
        {
            var pf = (IExtendedPathFind)Activator.CreateInstance(sm_pathFindingType);

            pf.Facade = facade;

            return(pf);
        }
コード例 #4
0
        public static bool CreatePath(this PathManager pm, ExtendedVehicleType extendedVehicleType, out uint unit, ref Randomizer randomizer, uint buildIndex, PathUnit.Position startPosA, PathUnit.Position startPosB, PathUnit.Position endPosA, PathUnit.Position endPosB, PathUnit.Position vehiclePosition, NetInfo.LaneType laneTypes, VehicleInfo.VehicleType vehicleTypes, float maxLength, bool isHeavyVehicle, bool ignoreBlocked, bool stablePath, bool skipQueue, bool randomParking)
        {
            if (ExtendedPathManager.PathFindFacades == null)
            {
                // Redirections are not installed correctly, fallbacking on the default code
                return(pm.CreatePath(
                           out unit,
                           ref randomizer,
                           buildIndex,
                           startPosA,
                           startPosB,
                           endPosA,
                           endPosB,
                           vehiclePosition,
                           laneTypes,
                           vehicleTypes,
                           maxLength,
                           isHeavyVehicle,
                           ignoreBlocked,
                           stablePath,
                           skipQueue,
                           randomParking));
            }

            while (!Monitor.TryEnter(pm.m_bufferLock, SimulationManager.SYNCHRONIZE_TIMEOUT))
            {
            }
            uint num;

            try
            {
                if (!pm.m_pathUnits.CreateItem(out num, ref randomizer))
                {
                    unit = 0u;
                    bool result = false;
                    return(result);
                }
                pm.m_pathUnitCount = (int)(pm.m_pathUnits.ItemCount() - 1u);
            }
            finally
            {
                Monitor.Exit(pm.m_bufferLock);
            }
            unit = num;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_simulationFlags = 1;
            if (isHeavyVehicle)
            {
                PathUnit[] expr_92_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_92_cp_1 = (UIntPtr)unit;
                expr_92_cp_0[(int)expr_92_cp_1].m_simulationFlags = (byte)(expr_92_cp_0[(int)expr_92_cp_1].m_simulationFlags | 16);
            }
            if (ignoreBlocked)
            {
                PathUnit[] expr_BB_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_BB_cp_1 = (UIntPtr)unit;
                expr_BB_cp_0[(int)expr_BB_cp_1].m_simulationFlags = (byte)(expr_BB_cp_0[(int)expr_BB_cp_1].m_simulationFlags | 32);
            }
            if (stablePath)
            {
                PathUnit[] expr_E4_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_E4_cp_1 = (UIntPtr)unit;
                expr_E4_cp_0[(int)expr_E4_cp_1].m_simulationFlags = (byte)(expr_E4_cp_0[(int)expr_E4_cp_1].m_simulationFlags | 64);
            }
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_pathFindFlags  = 0;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_buildIndex     = buildIndex;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position00     = startPosA;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position01     = endPosA;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position02     = startPosB;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position03     = endPosB;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position11     = vehiclePosition;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_nextPathUnit   = 0u;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_laneTypes      = (byte)laneTypes;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_vehicleTypes   = (byte)vehicleTypes;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_length         = maxLength;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_positionCount  = 20;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_referenceCount = 1;
            int num2 = 10000000;
            ExtendedPathFindFacade pathFindFacade = null;

            for (int i = 0; i < ExtendedPathManager.PathFindFacades.Length; i++)
            {
                ExtendedPathFindFacade pathFind2 = ExtendedPathManager.PathFindFacades[i];
                if (pathFind2.IsAvailable && pathFind2.m_queuedPathFindCount < num2)
                {
                    num2           = pathFind2.m_queuedPathFindCount;
                    pathFindFacade = pathFind2;
                }
            }
            if (pathFindFacade != null && pathFindFacade.CalculatePath(unit, skipQueue, extendedVehicleType))
            {
                return(true);
            }
            pm.ReleasePath(unit);
            return(false);
        }