4 using System.Collections.Generic;
6 using SiliconStudio.Core.Diagnostics;
7 using SiliconStudio.Core.Extensions;
8 using SiliconStudio.Paradox.Games;
9 using System.Threading.Tasks;
10 using SiliconStudio.Core;
12 namespace SiliconStudio.
Paradox.EntityModel
17 private bool enabled =
true;
24 get {
return enabled; }
25 set { enabled = value; }
57 protected internal abstract void OnSystemAdd();
62 protected internal abstract void OnSystemRemove();
68 protected internal abstract void SetEnabled(
Entity entity,
bool enabled);
80 protected internal abstract void EntityCheck(
Entity entity, List<EntityProcessor> processors,
bool forceRemove =
false);
87 protected internal void InternalAddEntity(
Entity entity)
89 EntitySystem.InternalAddEntity(entity);
98 protected internal void InternalRemoveEntity(Entity entity,
bool removeParent)
100 EntitySystem.InternalRemoveEntity(entity, removeParent);
109 protected Dictionary<Entity, T> enabledEntities =
new Dictionary<Entity, T>();
110 protected Dictionary<Entity, T> matchingEntities =
new Dictionary<Entity, T>();
111 protected HashSet<Entity> reentrancyCheck =
new HashSet<Entity>();
116 this.requiredKeys = requiredKeys;
123 get {
return requiredKeys; }
127 protected internal override void OnSystemAdd()
132 protected internal override void OnSystemRemove()
137 protected internal override void SetEnabled(Entity entity,
bool enabled)
142 if (!matchingEntities.TryGetValue(entity, out entityData))
143 throw new InvalidOperationException(
"EntityProcessor: Tried to enable an unknown entity.");
145 enabledEntities.Add(entity, matchingEntities[entity]);
149 if (!enabledEntities.Remove(entity))
150 throw new InvalidOperationException(
"Invalid Entity Enabled state");
153 OnEnabledChanged(entity, enabled);
157 protected internal override void EntityCheck(Entity entity, List<EntityProcessor> processors,
bool forceRemove)
160 bool entityMatch = !forceRemove && EntityMatch(entity);
162 bool entityAdded = matchingEntities.TryGetValue(entity, out entityData);
164 if (entityMatch && !entityAdded)
169 lock (reentrancyCheck)
171 if (!reentrancyCheck.Add(entity))
176 entityData = GenerateAssociatedData(entity);
178 processors.Add(
this);
179 OnEntityAdding(entity, entityData);
180 matchingEntities.Add(entity, entityData);
183 if (EntitySystem.IsEnabled(entity))
184 enabledEntities.Add(entity, entityData);
186 lock (reentrancyCheck)
188 reentrancyCheck.Remove(entity);
191 else if (entityAdded && !entityMatch)
194 OnEntityRemoved(entity, entityData);
195 processors.SwapRemove(
this);
198 enabledEntities.Remove(entity);
199 matchingEntities.Remove(entity);
207 protected abstract T GenerateAssociatedData(Entity entity);
211 return RequiredKeys.All(x => entity.Tags.Get(x) != null);
217 if (matchingEntities.TryGetValue(entity, out data))
221 OnEntityRemoved(entity, data);
222 OnEntityAdding(entity, data);
226 enabledEntities.Remove(entity);
227 matchingEntities.Remove(entity);
228 throw new Exception(
"Error during entity readd.");
EntityProcessor(PropertyKey[] requiredKeys)
virtual void Draw(GameTime time)
Performs work related to this processor.
virtual bool EntityMatch(Entity entity)
Game entity. It usually aggregates multiple EntityComponent
A key to identify a specific profile.
virtual void Update(GameTime time)
Performs work related to this processor.
static readonly ProfilingKey GameUpdate
Profiling Update() method of a GameBase. This profiling is only used through markers published every ...
A service registry is a IServiceProvider that provides methods to register and unregister services...
Keys used for profiling the game class.
Entity processor, triggered on various EntitySystem events such as Entity and Component additions and...
PropertyKey[] requiredKeys
Current timing used for variable-step (real time) or fixed-step (game time) games.
virtual void EntityReadd(Entity entity)
Manage a collection of entities.
virtual void OnEntityRemoved(Entity entity, T data)
Run when a matching entity is removed from this entity processor.
virtual void OnEnabledChanged(Entity entity, bool enabled)
virtual void OnEntityAdding(Entity entity, T data)
Run when a matching entity is added to this entity processor.
static readonly ProfilingKey GameDraw
Profiling Draw() method of a GameBase. This profiling is only used through markers published every se...
A class that represents a tag propety.