示例#1
0
        /// <summary>
        /// Update system state. This causes the implementation of <see cref="Update(long, EntityQueryResult)"/> to
        /// be called with a set of entities chosen based on the currently set filters, and the implementations
        /// of <see cref="OnEntityAdded"/> and <see cref="OnEntityRemoved"/> to be called accordingly.
        /// </summary>
        /// <param name="elapsedTicks">The amount of ticks that elapsed since the last update</param>
        public override void Update(long elapsedTicks)
        {
            // Retrieve new query result containing all entities that satisfy the current filter
            var result = EntityManager.AllEntities.GetEntities(Filters.ToArray());

            // If the currently stored last result is null, this is the first update.
            // This means all entities are to be handled as new.
            if (LastResult == null)
            {
                foreach (var e in result)
                {
                    OnEntityAdded(e);
                }
            }
            else
            {
                // Determine all entities that got removed
                foreach (var e in LastResult.Except(result))
                {
                    OnEntityRemoved(e);
                }

                // Determine all entites that got added
                foreach (var e in result.Except(LastResult))
                {
                    OnEntityAdded(e);
                }
            }


            // Save current result for next update
            LastResult = result;

            // Call the internal update implementation
            base.Update(elapsedTicks);
        }
示例#2
0
 /// <summary>
 /// Method that implements the actual work the system does.
 /// </summary>
 /// <param name="elapsedTicks">The amount of ticks that elapsed since the last update</param>
 /// <param name="entities">Set of pre-filtered entities that the system can work on</param>
 protected abstract void Update(long elapsedTicks, EntityQueryResult entities);