Ejemplo n.º 1
0
        public bool CreatePath(ExtVehicleType vehicleType, ushort vehicleId, ExtCitizenInstance.ExtPathType pathType, 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, bool ignoreFlooded)
        {
            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 = vehicleType;
                queueItems[pathUnitId].vehicleId   = vehicleId;
                queueItems[pathUnitId].pathType    = pathType;
                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 (isHeavyVehicle)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 16;
            }
            if (ignoreBlocked || ignoreFlooded)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 32;
            }
            if (stablePath)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 64;
            }
            if (randomParking)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 128;
            }
            this.m_pathUnits.m_buffer[unit].m_pathFindFlags = 0;
            this.m_pathUnits.m_buffer[unit].m_buildIndex    = buildIndex;
            this.m_pathUnits.m_buffer[unit].m_position00    = startPosA;
            this.m_pathUnits.m_buffer[unit].m_position01    = endPosA;
            this.m_pathUnits.m_buffer[unit].m_position02    = startPosB;
            this.m_pathUnits.m_buffer[unit].m_position03    = endPosB;
            this.m_pathUnits.m_buffer[unit].m_position11    = vehiclePosition;
            this.m_pathUnits.m_buffer[unit].m_laneTypes     = (byte)laneTypes;
            this.m_pathUnits.m_buffer[unit].m_vehicleTypes  = (ushort)vehicleTypes;
            this.m_pathUnits.m_buffer[unit].m_length        = maxLength;
            this.m_pathUnits.m_buffer[unit].m_positionCount = 20;
            int            minQueued = 10000000;
            CustomPathFind pathFind  = null;

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#if EXTRAPF
            ExtraQueuedPathFinds = 0;
#endif
#endif
            for (int i = 0; i < _replacementPathFinds.Length; ++i)
            {
                CustomPathFind pathFindCandidate = _replacementPathFinds[i];
#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#if EXTRAPF
                if (pathFindCandidate.IsExtraPathFind)
                {
                    ExtraQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
                }
#endif
#endif
                if (pathFindCandidate.IsAvailable
#if EXTRAPF
                    && (!pathFindCandidate.IsExtraPathFind)
#endif
                    && pathFindCandidate.m_queuedPathFindCount < minQueued)
                {
                    minQueued = pathFindCandidate.m_queuedPathFindCount;
                    pathFind  = pathFindCandidate;
                }
            }

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


            // 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);
        }
        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);
        }
        public bool CreatePath(bool recalc, ExtVehicleType vehicleType, ushort vehicleId, ExtCitizenInstance.ExtPathType pathType, 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, bool ignoreFlooded)
        {
            uint pathUnitId;

            try {
                Monitor.Enter(this.m_bufferLock);
                if (!this.m_pathUnits.CreateItem(out pathUnitId, 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 = pathUnitId;

            this.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_simulationFlags = 1;
            if (isHeavyVehicle)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 16;
            }
            if (ignoreBlocked || ignoreFlooded)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 32;
            }
            if (stablePath)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 64;
            }
            if (randomParking)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 128;
            }
            this.m_pathUnits.m_buffer[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            minQueued = 10000000;
            CustomPathFind pathFind  = null;

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#if EXTRAPF
            ExtraQueuedPathFinds = 0;
#endif
#endif
            for (int i = 0; i < _replacementPathFinds.Length; ++i)
            {
                CustomPathFind pathFindCandidate = _replacementPathFinds[i];
#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#if EXTRAPF
                if (pathFindCandidate.IsExtraPathFind)
                {
                    ExtraQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
                }
#endif
#endif
                if (pathFindCandidate.IsAvailable
#if EXTRAPF
                    && (!pathFindCandidate.IsExtraPathFind || recalc)
#endif
                    && pathFindCandidate.m_queuedPathFindCount < minQueued)
                {
                    minQueued = pathFindCandidate.m_queuedPathFindCount;
                    pathFind  = pathFindCandidate;
                }
            }

            pathUnitExtVehicleType[unit] = vehicleType;
            pathUnitVehicleIds[unit]     = vehicleId == 0 ? (ushort?)null : vehicleId;
            pathUnitPathTypes[unit]      = pathType;

            if (pathFind != null && pathFind.ExtCalculatePath(unit, skipQueue))
            {
                return(true);
            }
            this.ReleasePath(unit);
            return(false);
        }