Exemplo n.º 1
0
        /// 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;
        }
Exemplo n.º 2
0
        /// 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 <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;
        }