private bool findShortestPath(uint unit, bool skipQueue)
        {
            int[]          maxPathLength = { 10000000 };
            CustomPathFind pathFind      = null;

            foreach (var pathFind2 in _replacementPathFinds.Where(pathFind2 => pathFind2.IsAvailable && pathFind2.m_queuedPathFindCount < maxPathLength[0]))
            {
                maxPathLength[0] = pathFind2.m_queuedPathFindCount;
                pathFind         = pathFind2;
            }

            if (pathFind != null && pathFind.CalculatePath(unit, skipQueue))
            {
                return(true);
            }
            ReleasePath(unit);
            return(false);
        }
Ejemplo n.º 2
0
        private bool findShortestPath(uint unit, bool skipQueue)
        {
            int            maxPathLength = 10000000;
            CustomPathFind pathFind      = null;

            for (int i = 0; i < this.replacementPathFinds.Length; i++)
            {
                CustomPathFind pathFind2 = this.replacementPathFinds[i];
                if (pathFind2.IsAvailable && pathFind2.m_queuedPathFindCount < maxPathLength)
                {
                    maxPathLength = pathFind2.m_queuedPathFindCount;
                    pathFind      = pathFind2;
                }
            }

            if (pathFind != null && pathFind.CalculatePath(unit, skipQueue))
            {
                return(true);
            }
            this.ReleasePath(unit);
            return(false);
        }
Ejemplo n.º 3
0
        public bool CreatePath(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, RoadManager.VehicleType vehicleType)
        {
            while (!Monitor.TryEnter(this.m_bufferLock, SimulationManager.SYNCHRONIZE_TIMEOUT))
            {
            }
            uint num;

            try
            {
                if (!this.m_pathUnits.CreateItem(out num, ref randomizer))
                {
                    unit = 0u;
                    bool result = false;
                    return(result);
                }
                this.m_pathUnitCount = (int)(this.m_pathUnits.ItemCount() - 1u);
            }
            finally
            {
                Monitor.Exit(this.m_bufferLock);
            }
            unit = num;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_simulationFlags = 1;
            if (isHeavyVehicle)
            {
                PathUnit[] expr_92_cp_0 = this.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 = this.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 = this.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);
            }
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_pathFindFlags  = 0;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_buildIndex     = buildIndex;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position00     = startPosA;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position01     = endPosA;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position02     = startPosB;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position03     = endPosB;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position11     = vehiclePosition;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_nextPathUnit   = 0u;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_laneTypes      = (byte)laneTypes;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_vehicleTypes   = (byte)vehicleTypes;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_length         = maxLength;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_positionCount  = 20;
            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_referenceCount = 1;
            int            num2     = 10000000;
            CustomPathFind pathFind = null;

            for (int i = 0; i < this.m_pathFinds.Length; i++)
            {
                CustomPathFind pathFind2 = this.m_pathFinds[i];
                if (pathFind2.IsAvailable && pathFind2.m_queuedPathFindCount < num2)
                {
                    num2     = pathFind2.m_queuedPathFindCount;
                    pathFind = pathFind2;
                }
            }
            if (pathFind != null && pathFind.CalculatePath(unit, skipQueue, vehicleType))
            {
                return(true);
            }
            this.ReleasePath(unit);
            return(false);
        }
        public bool CreatePath(out uint unit, ref Randomizer randomizer, PathCreationArgs args)
        {
            uint pathUnitId;

            try {
                Monitor.Enter(this.m_bufferLock);

                int numIters = 0;
                while (true)                   // NON-STOCK CODE
                {
                    ++numIters;

                    if (!this.m_pathUnits.CreateItem(out pathUnitId, ref randomizer))
                    {
                        unit = 0u;
                        return(false);
                    }

                    this.m_pathUnits.m_buffer[pathUnitId].m_simulationFlags = 1;
                    this.m_pathUnits.m_buffer[pathUnitId].m_referenceCount  = 1;
                    this.m_pathUnits.m_buffer[pathUnitId].m_nextPathUnit    = 0u;

                    // NON-STOCK CODE START
                    if (queueItems[pathUnitId].queued)
                    {
                        ReleasePath(pathUnitId);

                        if (numIters > 10)
                        {
                            unit = 0u;
                            return(false);
                        }

                        continue;
                    }
                    break;
                }

                queueItems[pathUnitId].vehicleType = args.extVehicleType;
                queueItems[pathUnitId].vehicleId   = args.vehicleId;
                queueItems[pathUnitId].pathType    = args.extPathType;
                queueItems[pathUnitId].spawned     = args.spawned;
                queueItems[pathUnitId].queued      = true;
                // NON-STOCK CODE END

                this.m_pathUnitCount = (int)(this.m_pathUnits.ItemCount() - 1u);
            } finally {
                Monitor.Exit(this.m_bufferLock);
            }
            unit = pathUnitId;

            if (args.isHeavyVehicle)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IS_HEAVY;
            }
            if (args.ignoreBlocked || args.ignoreFlooded)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_BLOCKED;
            }
            if (args.stablePath)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_STABLE_PATH;
            }
            if (args.randomParking)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_RANDOM_PARKING;
            }
            if (args.ignoreFlooded)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_FLOODED;
            }
            if (args.hasCombustionEngine)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_COMBUSTION;
            }
            if (args.ignoreCosts)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_COST;
            }
            this.m_pathUnits.m_buffer[unit].m_pathFindFlags = 0;
            this.m_pathUnits.m_buffer[unit].m_buildIndex    = args.buildIndex;
            this.m_pathUnits.m_buffer[unit].m_position00    = args.startPosA;
            this.m_pathUnits.m_buffer[unit].m_position01    = args.endPosA;
            this.m_pathUnits.m_buffer[unit].m_position02    = args.startPosB;
            this.m_pathUnits.m_buffer[unit].m_position03    = args.endPosB;
            this.m_pathUnits.m_buffer[unit].m_position11    = args.vehiclePosition;
            this.m_pathUnits.m_buffer[unit].m_laneTypes     = (byte)args.laneTypes;
            this.m_pathUnits.m_buffer[unit].m_vehicleTypes  = (ushort)args.vehicleTypes;
            this.m_pathUnits.m_buffer[unit].m_length        = args.maxLength;
            this.m_pathUnits.m_buffer[unit].m_positionCount = 20;
            int minQueued = 10000000;

#if PF2
            CustomPathFind2 pathFind = null;
#else
            CustomPathFind pathFind = null;
#endif

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#endif
            for (int i = 0; i < _replacementPathFinds.Length; ++i)
            {
#if PF2
                CustomPathFind2 pathFindCandidate = _replacementPathFinds[i];
#else
                CustomPathFind pathFindCandidate = _replacementPathFinds[i];
#endif

#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#endif
                if (pathFindCandidate.IsAvailable &&
                    pathFindCandidate.m_queuedPathFindCount < minQueued)
                {
                    minQueued = pathFindCandidate.m_queuedPathFindCount;
                    pathFind  = pathFindCandidate;
                }
            }

#if PF2
            if (pathFind != null && pathFind.CalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#else
            if (pathFind != null && pathFind.ExtCalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#endif

            // NON-STOCK CODE START
            try {
                Monitor.Enter(this.m_bufferLock);

                queueItems[pathUnitId].queued = false;
                // NON-STOCK CODE END
                this.ReleasePath(unit);

                // NON-STOCK CODE START
                this.m_pathUnitCount = (int)(this.m_pathUnits.ItemCount() - 1u);
            } finally {
                Monitor.Exit(this.m_bufferLock);
            }
            // NON-STOCK CODE END
            return(false);
        }
Ejemplo n.º 5
0
        public bool CreatePath(ExtVehicleType vehicleType, 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)
        {
            uint num;

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

            for (int i = 0; i < _replacementPathFinds.Length; i++)
            {
                CustomPathFind pathFindCandidate = _replacementPathFinds[i];
                if (pathFindCandidate.IsAvailable && pathFindCandidate.m_queuedPathFindCount < num2)
                {
                    num2     = pathFindCandidate.m_queuedPathFindCount;
                    pathFind = pathFindCandidate;
                }
            }
            if (pathFind != null && pathFind.CalculatePath(vehicleType, unit, skipQueue))
            {
                return(true);
            }
            this.ReleasePath(unit);
            return(false);
        }
Ejemplo n.º 6
0
        public bool CustomCreatePath(out uint unit,
                                     ref Randomizer randomizer,
                                     PathCreationArgs args)
        {
            uint pathUnitId;

            lock (m_bufferLock) {
                int numIters = 0;
                while (true)
                {
                    // NON-STOCK CODE
                    ++numIters;

                    if (!m_pathUnits.CreateItem(out pathUnitId, ref randomizer))
                    {
                        unit = 0u;
                        return(false);
                    }

                    m_pathUnits.m_buffer[pathUnitId].m_simulationFlags = 1;
                    m_pathUnits.m_buffer[pathUnitId].m_referenceCount  = 1;
                    m_pathUnits.m_buffer[pathUnitId].m_nextPathUnit    = 0u;

                    // NON-STOCK CODE START
                    if (QueueItems[pathUnitId].queued)
                    {
                        CustomReleasePath(pathUnitId);

                        if (numIters > 10)
                        {
                            unit = 0u;
                            return(false);
                        }

                        continue;
                    }

                    break;
                }

                QueueItems[pathUnitId].vehicleType = args.extVehicleType;
                QueueItems[pathUnitId].vehicleId   = args.vehicleId;
                QueueItems[pathUnitId].pathType    = args.extPathType;
                QueueItems[pathUnitId].spawned     = args.spawned;
                QueueItems[pathUnitId].queued      = true;
                // NON-STOCK CODE END

                m_pathUnitCount = (int)(m_pathUnits.ItemCount() - 1u);
            }

            unit = pathUnitId;

            if (args.isHeavyVehicle)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IS_HEAVY;
            }

            if (args.ignoreBlocked || args.ignoreFlooded)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_BLOCKED;
            }

            if (args.stablePath)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_STABLE_PATH;
            }

            if (args.randomParking)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_RANDOM_PARKING;
            }

            if (args.ignoreFlooded)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_FLOODED;
            }

            if (args.hasCombustionEngine)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_COMBUSTION;
            }

            if (args.ignoreCosts)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_COST;
            }

            m_pathUnits.m_buffer[unit].m_pathFindFlags = 0;
            m_pathUnits.m_buffer[unit].m_buildIndex    = args.buildIndex;
            m_pathUnits.m_buffer[unit].m_position00    = args.startPosA;
            m_pathUnits.m_buffer[unit].m_position01    = args.endPosA;
            m_pathUnits.m_buffer[unit].m_position02    = args.startPosB;
            m_pathUnits.m_buffer[unit].m_position03    = args.endPosB;
            m_pathUnits.m_buffer[unit].m_position11    = args.vehiclePosition;
            m_pathUnits.m_buffer[unit].m_laneTypes     = (byte)args.laneTypes;
            m_pathUnits.m_buffer[unit].m_vehicleTypes  = (uint)args.vehicleTypes;
            m_pathUnits.m_buffer[unit].m_length        = args.maxLength;
            m_pathUnits.m_buffer[unit].m_positionCount = 20;

            int            minQueued = 10000000;
            CustomPathFind pathFind  = null;

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#endif
            foreach (CustomPathFind pathFindCandidate in _replacementPathFinds)
            {
#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#endif
                if (!pathFindCandidate.IsAvailable ||
                    pathFindCandidate.m_queuedPathFindCount >= minQueued)
                {
                    continue;
                }

                minQueued = pathFindCandidate.m_queuedPathFindCount;
                pathFind  = pathFindCandidate;
            }

            if (pathFind != null && pathFind.CalculatePath(unit, args.skipQueue))
            {
                return(true);
            }

            // NON-STOCK CODE START
            lock (m_bufferLock) {
                QueueItems[pathUnitId].queued = false;
                // NON-STOCK CODE END
                CustomReleasePath(unit);

                // NON-STOCK CODE START
                m_pathUnitCount = (int)(m_pathUnits.ItemCount() - 1u);
            }

            // NON-STOCK CODE END
            return(false);
        }