Пример #1
0
 /// <summary>
 ///   Clears the spawners
 /// </summary>
 public void Clear()
 {
     spawnTypes.Clear();
     queuedSpawns           = null;
     previousPlayerPosition = new Vector3(0, 0, 0);
     elapsed = 0;
 }
Пример #2
0
    private int HandleQueuedSpawns(int spawnsLeftThisFrame)
    {
        // If we don't have room, just abandon spawning
        if (estimateEntityCount >= maxAliveEntities)
        {
            queuedSpawns.Spawns.Dispose();
            queuedSpawns = null;
            return(spawnsLeftThisFrame);
        }

        // Spawn from the queue
        while (estimateEntityCount < maxAliveEntities && spawnsLeftThisFrame > 0)
        {
            if (!queuedSpawns.Spawns.MoveNext())
            {
                // Ended
                queuedSpawns.Spawns.Dispose();
                queuedSpawns = null;
                break;
            }

            // Next was spawned
            ProcessSpawnedEntity(queuedSpawns.Spawns.Current, queuedSpawns.SpawnType);

            ++estimateEntityCount;
            --spawnsLeftThisFrame;
        }

        return(spawnsLeftThisFrame);
    }
Пример #3
0
        /// <summary>
        /// Removes a queued spawn.
        /// </summary>
        /// <param name="queuedSpawn">The queued spawn to remove.</param>
        private static void RemoveQueuedSpawn(QueuedSpawn queuedSpawn)
        {
            var spawnDetail = _spawns[queuedSpawn.SpawnDetailId];

            _queuedSpawns.Remove(queuedSpawn);
            _queuedSpawnsByArea[spawnDetail.Area].Remove(queuedSpawn);
        }
Пример #4
0
    /// <summary>
    ///   Despawns all spawned entities
    /// </summary>
    public void DespawnAll()
    {
        queuedSpawns = null;
        var spawnedEntities = worldRoot.GetTree().GetNodesInGroup(Constants.SPAWNED_GROUP);

        foreach (Node entity in spawnedEntities)
        {
            if (!entity.IsQueuedForDeletion())
            {
                entity.DetachAndQueueFree();
            }
        }
    }
Пример #5
0
    /// <summary>
    ///   Does a single spawn with a spawner
    /// </summary>
    /// <returns>True if we have exceeded the spawn limit and no further spawns should be done this frame</returns>
    private bool SpawnWithSpawner(Spawner spawnType, Vector3 location, int existing, ref int spawnsLeftThisFrame,
                                  ref int spawned)
    {
        var enumerable = spawnType.Spawn(worldRoot, location);

        if (enumerable == null)
        {
            return(false);
        }

        var spawner = enumerable.GetEnumerator();

        while (spawner.MoveNext())
        {
            if (spawner.Current == null)
            {
                throw new NullReferenceException("spawn enumerator is not allowed to return null");
            }

            // Spawned something
            ProcessSpawnedEntity(spawner.Current, spawnType);
            spawned += 1;
            --spawnsLeftThisFrame;

            // Check if we are out of quota for this frame

            // TODO: this is a bit awkward if this
            // stops compound clouds from spawning as
            // well...
            if (spawned + existing >= maxAliveEntities)
            {
                // We likely couldn't spawn things next frame anyway if we are at the entity limit,
                // so the spawner is not stored here
                return(true);
            }

            if (spawnsLeftThisFrame <= 0)
            {
                // This spawner might still have something left to spawn next frame, so store it
                queuedSpawns = new QueuedSpawn(spawner, spawnType);
                return(true);
            }
        }

        // Can still spawn more stuff
        return(false);
    }
Пример #6
0
        /// <summary>
        /// Creates a queued spawn record which is picked up by the processor.
        /// The spawn object will be created when the respawn time has passed.
        /// </summary>
        /// <param name="spawnDetailId">The ID of the spawn detail.</param>
        /// <param name="respawnTime">The time the spawn will be created.</param>
        private static void CreateQueuedSpawn(Guid spawnDetailId, DateTime respawnTime)
        {
            var queuedSpawn = new QueuedSpawn
            {
                RespawnTime   = respawnTime,
                SpawnDetailId = spawnDetailId
            };

            _queuedSpawns.Add(queuedSpawn);

            var spawnDetail = _spawns[spawnDetailId];

            if (!_queuedSpawnsByArea.ContainsKey(spawnDetail.Area))
            {
                _queuedSpawnsByArea[spawnDetail.Area] = new List <QueuedSpawn>();
            }

            _queuedSpawnsByArea[spawnDetail.Area].Add(queuedSpawn);
        }
Пример #7
0
    /// <summary>
    ///   Despawns all spawned entities
    /// </summary>
    public void DespawnAll()
    {
        queuedSpawns = null;
        var spawnedEntities = worldRoot.GetTree().GetNodesInGroup(Constants.SPAWNED_GROUP);

        foreach (Node entity in spawnedEntities)
        {
            if (!entity.IsQueuedForDeletion())
            {
                var spawned = entity as ISpawned;

                if (spawned == null)
                {
                    GD.PrintErr("A node has been put in the spawned group but it isn't derived from ISpawned");
                    continue;
                }

                spawned.DestroyDetachAndQueueFree();
            }
        }
    }
Пример #8
0
 /// <summary>
 ///   Clears the spawners
 /// </summary>
 public void Clear()
 {
     spawnTypes.Clear();
     queuedSpawns = null;
     elapsed      = 0;
 }