/// The prefered way to create a context is to use the generated methods /// from the code generator, e.g. var context = new GameContext(); public Context(int totalComponents, int startCreationIndex, ContextInfo contextInfo) { _totalComponents = totalComponents; _creationIndex = startCreationIndex; if (contextInfo != null) { _contextInfo = contextInfo; if (contextInfo.componentNames.Length != totalComponents) { throw new ContextInfoException(this, contextInfo); } } else { _contextInfo = createDefaultContextInfo(); } _groupsForIndex = new List <IGroup <TEntity> > [totalComponents]; _componentPools = new Stack <IComponent> [totalComponents]; _entityIndices = new Dictionary <string, IEntityIndex>(); // Cache delegates to avoid gc allocations _cachedEntityChanged = updateGroupsComponentAddedOrRemoved; _cachedComponentReplaced = updateGroupsComponentReplaced; _cachedEntityReleased = onEntityReleased; }
/// The prefered way to create a context is to use the generated methods /// from the code generator, e.g. var context = new GameContext(); public Context(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func <IEntity, IAERC> aercFactory, Func <TEntity> createEntity) { _totalComponents = totalComponents; _creationIndex = startCreationIndex; if (contextInfo != null) { _contextInfo = contextInfo; if (contextInfo.componentNames.Length != totalComponents) { throw new ContextInfoException(this, contextInfo); } } else { _contextInfo = createDefaultContextInfo(); } _aercFactory = aercFactory ?? (entity => new SafeAERC(entity)); _createEntity = createEntity ?? (() => (TEntity)Activator.CreateInstance(typeof(TEntity))); // cedric _groupsForIndex = new List <IGroup <TEntity> > [totalComponents]; _componentPools = new Stack <IComponent> [totalComponents]; _entityIndices = new Dictionary <string, IEntityIndex>(); _groupChangedListPool = new ObjectPool <List <GroupChanged <TEntity> > >( () => new List <GroupChanged <TEntity> >(), list => list.Clear() ); // Cache delegates to avoid gc allocations _cachedEntityChanged = updateGroupsComponentAddedOrRemoved; _cachedComponentReplaced = updateGroupsComponentReplaced; _cachedEntityReleased = onEntityReleased; _cachedDestroyEntity = onDestroyEntity; }
public EntitasGameEntity() { entityOnOnComponentAddedCache = EntityOnOnComponentAdded; entityOnOnComponentRemovedCache = EntityOnOnComponentRemoved; entityOnOnComponentReplacedCache = EntityOnOnComponentReplaced; entityOnOnDestroyEntityCache = EntityOnOnDestroyEntity; }
// private int ownerIdIndex; // private int positionIndex; protected EntitasGameContext(Context <TEntity> context, Type[] componentTypes, Bin2D <IGameEntity> bin) { this.bin = bin; entitasContext = context; indexLookUp = new GameComponentIndexLookUp <TEntity>(componentTypes); context.OnEntityCreated += ContextOnOnEntityCreated; context.OnEntityWillBeDestroyed += ContextOnOnEntityDestroyed; onOnComponentAddedCache = OnOnComponentAdded; onOnComponentRemovedCache = OnOnComponentRemoved; onOnComponentReplacedCache = OnOnComponentReplaced; }
public EntityContext() { if (!SystemIndexer.Indexed) { SystemIndexer.Index(); } if (!ComponentIndexer.Indexed) { ComponentIndexer.Index(); } m_CachedEntityChanged = UpdateGroupsComponentAddedOrRemoved; }
void init() { _onDestroyEntity = destroyEntity; _onEntityChanged = updateEntityName; _snapEntityToSystem = snapEntityToSystem; _systemsBehaviour = FindObjectOfType <DebugSystemsBehaviour>(); DontDestroyOnLoad(gameObject); DontDestroyOnLoad(_systemsBehaviour.gameObject); mapEntitiesToBehaviours(FindObjectsOfType <EntityBehaviour>()); createSystems(_systemsBehaviour.systems.executeSystemInfos); snapEntitiesToSystem(_contextEntities, null); ObservableSystem.OnEntityWillBeExecuted -= _snapEntityToSystem; ObservableSystem.OnEntityWillBeExecuted += _snapEntityToSystem; }
/// The prefered way to create a context is to use the generated methods /// from the code generator, e.g. var context = new GameContext(); public Context(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func <IEntity, IAERC> aercFactory) { _totalComponents = totalComponents; _creationIndex = startCreationIndex; if (contextInfo != null) { _contextInfo = contextInfo; if (contextInfo.componentNames.Length != totalComponents) { throw new ContextInfoException(this, contextInfo); } } else { _contextInfo = createDefaultContextInfo(); } _aercFactory = aercFactory == null ? (entity) => new SafeAERC(entity) : aercFactory; _groupsForIndex = new List <IGroup> [totalComponents]; _groupForSingle = new IGroup[totalComponents]; _componentPools = new Stack <IComponent> [totalComponents]; _entityIndices = new Dictionary <string, IEntityIndex>(); _groupChangedListPool = new ObjectPool <List <GroupChanged> >( () => new List <GroupChanged>(), list => list.Clear() ); // Cache delegates to avoid gc allocations _cachedEntityChanged = updateGroupsComponentAddedOrRemoved; _cachedComponentReplaced = updateGroupsComponentReplaced; _cachedEntityReleased = onEntityReleased; _cachedDestroyEntity = onDestroyEntity; // Add listener for updating lookup OnEntityCreated += (c, entity) => _entitiesLookup.Add(entity.creationIndex, (Entity)entity); OnEntityDestroyed += (c, entity) => _entitiesLookup.Remove(entity.creationIndex); }
/// The prefered way to create a context is to use the generated methods /// from the code generator, e.g. var context = new GameContext(); public Context(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func <IEntity, IRefCounter> aercFactory) { mTotalComponents = totalComponents; _creationIndex = startCreationIndex; if (contextInfo != null) { _contextInfo = contextInfo; if (contextInfo.ComponentNames.Length != totalComponents) { throw new ContextInfoException(this, contextInfo); } } else { _contextInfo = createDefaultContextInfo(); } _aercFactory = aercFactory == null ? (entity) => new SafeARC(entity) : aercFactory; _groupsForIndex = new List <IGroup <TEntity> > [totalComponents]; mComponentPools = new Stack <IComponent> [totalComponents]; _entityIndices = new Dictionary <string, IEntityIndex>(); mGroupChangedListSimpleObjectPool = new SimpleObjectPool <List <GroupChanged <TEntity> > >( () => new List <GroupChanged <TEntity> >(), list => list.Clear() ); // Cache delegates to avoid gc allocations _cachedEntityChanged = updateGroupsComponentAddedOrRemoved; _cachedComponentReplaced = updateGroupsComponentReplaced; _cachedEntityReleased = onEntityReleased; _cachedDestroyEntity = onDestroyEntity; }
void AttachWhenGameObjectAdded(GameEntity entity, GameEntity player) { // Making lambdas unsubscribe themselves is kinda tricky, // but we need to use a lambda since we need to capture the player variable. EntityComponentChanged onComponentAddedHandler = null; onComponentAddedHandler = (e, index, component) => { if (index != GameComponentsLookup.GameObject) { return; } if (!player.hasHandheld || player.handheld.id != entity.id.value) { return; } Attach(entity, player); entity.OnComponentAdded -= onComponentAddedHandler; }; entity.OnComponentAdded += onComponentAddedHandler; }
protected EntitasGameContext(Context <TEntity> context, Type[] componentTypes, Bin2D <IGameEntity> bin) { _bin = bin; _context = context; _indexLookUp = new ComponentIndexLookUp <TEntity>(componentTypes); _entityKeyIndex = _indexLookUp.GetComponentIndex <EntityKeyComponent>(); _ownerIdIndex = _indexLookUp.GetComponentIndex <OwnerIdComponent>(); _positionIndex = _indexLookUp.GetComponentIndex <PositionComponent>(); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <PositionComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <EntityKeyComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <OwnerIdComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagCompensationComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagDestroyComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSelfComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSyncSelfComponent>()); _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSyncNonSelfComponent>()); _context.OnEntityCreated += ContextOnOnEntityCreated; _context.OnEntityWillBeDestroyed += ContextOnOnEntityDestroyed; _onOnComponentAddedCache = OnOnComponentAdded; _onOnComponentRemovedCache = OnOnComponentRemoved; _onOnComponentReplacedCache = OnOnComponentReplaced; }
public Context() : this(0) { m_CachedEntityChanged = updateGroupsComponentAddedOrRemoved; m_CachedComponentReplaced = updateGroupsComponentReplaced; }