Ejemplo n.º 1
0
        /// <summary>
        ///     Checks to see if any pending entities can be added to the world and
        ///     adds them if applicable.
        /// </summary>
        private void UpdatePendingEntities(Tick serverTick)
        {
            foreach (RailEntityClient entity in pendingEntities.Values)
            {
                if (!entity.HasReadyState(serverTick))
                {
                    continue;
                }

                // Note: We're using ToRemove here to remove from the *pending* list
                ToRemove.Add(entity);

                // If the entity was removed while pending, forget about it
                Tick removeTick = entity.RemovedTick; // Can't use ShouldRemove
                if (removeTick.IsValid && removeTick <= serverTick)
                {
                    knownEntities.Remove(entity.Id);
                }
                else
                {
                    RegisterEntity(entity);
                }
            }

            foreach (RailEntityClient entity in ToRemove)
            {
                pendingEntities.Remove(entity.Id);
            }

            ToRemove.Clear();
        }
Ejemplo n.º 2
0
 protected override void RemoveItem(int index)
 {
     ToRemove.Add(this[index]);
     foreach (var trigger in this.Property.Triggers.Where(p => p.PropertyTriggerType == PropertyTriggerType.ItemsDelete))
     {
         new ModelMethodContext(this.Con, this.ConFac).ExcuteOperation(this[index], trigger as IOperation);
     }
     base.RemoveItem(index);
 }
Ejemplo n.º 3
0
 public bool Remove(string name)
 {
     if (!Dictionary.ContainsKey(name))
     {
         return(false);
     }
     ToRemove.Add(name);
     return(true);
 }
Ejemplo n.º 4
0
 public void RemoveChild(UIElement child)
 {
     if (Children.Contains(child))
     {
         if (!ToRemove.Add(child))
         {
             throw new Exception("Tried to remove a child twice!");
         }
     }
     else
     {
         throw new Exception("Tried to remove a child that does not belong to this element!");
     }
 }
Ejemplo n.º 5
0
 public void RemoveChild(UIElement child)
 {
     if (Children.Contains(child))
     {
         if (!ToRemove.Add(child))
         {
             // This is probably fine actually.
             //throw new Exception("Tried to remove a child twice!");
         }
     }
     else if (ToAdd.Contains(child))
     {
         ToAdd.Remove(child);
     }
     else
     {
         throw new Exception("Tried to remove a child that does not belong to this element!");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Updates the room a number of ticks. If we have entities waiting to be
        ///     added, this function will check them and add them if applicable.
        /// </summary>
        public void ClientUpdate(Tick localTick, Tick estimatedServerTick)
        {
            Tick = estimatedServerTick;
            UpdatePendingEntities(estimatedServerTick);
            OnPreRoomUpdate(Tick);

            // Collect the entities in the priority order and
            // separate them out for either update or removal
            foreach (RailEntityBase railEntityBase in Entities)
            {
                RailEntityClient entity = (RailEntityClient)railEntityBase;
                if (entity.ShouldRemove)
                {
                    ToRemove.Add(entity);
                }
                else
                {
                    ToUpdate.Add(entity);
                }
            }

            // Wave 0: Remove all sunsetted entities
            ToRemove.ForEach(RemoveEntity);

            // Wave 1: Start/initialize all entities
            ToUpdate.ForEach(e => e.PreUpdate());

            // Wave 2: Update all entities
            ToUpdate.ForEach(e => e.ClientUpdate(localTick));

            // Wave 3: Post-update all entities
            ToUpdate.ForEach(e => e.PostUpdate());

            ToRemove.Clear();
            ToUpdate.Clear();
            OnPostRoomUpdate(Tick);
        }
Ejemplo n.º 7
0
        public void ServerUpdate()
        {
            Tick = Tick.GetNext();
            OnPreRoomUpdate(Tick);

            // Collect the entities in the priority order and
            // separate them out for either update or removal
            foreach (RailEntityBase railEntityBase in Entities)
            {
                RailEntityServer entity = (RailEntityServer)railEntityBase;
                if (entity.ShouldRemove)
                {
                    ToRemove.Add(entity);
                }
                else
                {
                    ToUpdate.Add(entity);
                }
            }

            // Wave 0: Remove all sunsetted entities
            ToRemove.ForEach(RemoveEntity);

            // Wave 1: Start/initialize all entities
            ToUpdate.ForEach(e => e.PreUpdate());

            // Wave 2: Update all entities
            ToUpdate.ForEach(e => e.ServerUpdate());

            // Wave 3: Post-update all entities
            ToUpdate.ForEach(e => e.PostUpdate());

            ToRemove.Clear();
            ToUpdate.Clear();
            OnPostRoomUpdate(Tick);
        }
Ejemplo n.º 8
0
 /// <summary>Remove an object that matches the given id.</summary>
 void ICollectionRef <T> .Remove(Guid id) => ToRemove.Add(id);
Ejemplo n.º 9
0
        public void Update(GameTime gameTime)
        {
            foreach (Bullet b in Bullets.ToArray())
            {
                b.Update(gameTime);
                if (b.Bounds.Intersects(Parent.Player.Bounds))
                {
                    Parent.Health.Value--;
                    AssetManager.PlaySound("Hit", 1f);
                    Parent.GFM.SpawnMiniExplosion(b);
                    Bullets.Remove(b);
                }
                else if (b.ShouldRemove)
                {
                    Parent.GFM.SpawnMiniExplosion(b);
                    Bullets.Remove(b);
                }
            }

            CurrentTime += gameTime.ElapsedGameTime.TotalSeconds;
            if (CurrentTime >= SpawnInterval)
            {
                CurrentTime = 0;
                for (int i = 0; i < Rand.Next(5); i++)
                {
                    //Spawn at top of screen, choose random enemy
                    int R = Rand.Next(4);
                    if (R == 1)
                    {
                        Enemies.Add(new ShooterEnemy(new Rectangle(Rand.Next(64, 64 + 192 - 9), Rand.Next(-32, 0), 7, 14), this));
                    }
                    else if (R == 2)
                    {
                        Enemies.Add(new FighterEnemy(new Rectangle(Rand.Next(64, 64 + 192 - 9), Rand.Next(-32, 0), 9, 13), this));
                    }
                    else if (R == 3)
                    {
                        Enemies.Add(new FollowEnemy(new Rectangle(Rand.Next(64, 64 + 192 - 9), Rand.Next(-32, 0), 9, 9), this));
                    }
                    else
                    {
                        Enemies.Add(new SpikeEnemy(new Rectangle(Rand.Next(64, 64 + 192 - 9), Rand.Next(-32, 0), 13, 13), this));
                    }
                }
            }

            ToRemove.Clear();
            foreach (IEnemy E in Enemies)
            {
                E.Update(gameTime);

                if (E.Bounds.Intersects(Parent.Player.Bounds))
                {
                    ToRemove.Add(E);
                    Parent.Health.Value--;
                }

                foreach (Bullet B in Parent.Player.Bullets.ToArray())
                {
                    if (B.Bounds.Intersects(E.Bounds))
                    {
                        E.Health--;
                        Parent.GFM.SpawnMiniExplosion(E);
                        if (E.Health <= 0)
                        {
                            Parent.Score.Value++;
                            ToRemove.Add(E);
                        }
                        else
                        {
                            AssetManager.PlaySound("Hit");
                        }
                        Parent.Player.Bullets.Remove(B);
                    }
                }
            }

            foreach (IEnemy E in ToRemove)
            {
                if (Enemies.Contains(E))
                {
                    Parent.GFM.SpawnExplosion(E);
                    Parent.Camera.ScreenShake(20, 0.075f);
                    Enemies.Remove(E);
                }
            }
        }
 public void RemoveUserRole(UserRole model)
 {
     ToRemove.Add(model.RoleId);
 }