public Pool(int totalComponents, int startCreationIndex, PoolMetaData metaData) {
            _totalComponents = totalComponents;
            _creationIndex = startCreationIndex;

            if (metaData != null) {
                _metaData = metaData;

                if (metaData.componentNames.Length != totalComponents) {
                    throw new PoolMetaDataException(this, metaData);
                }
            } else {
                var componentNames = new string[totalComponents];
                const string suffix = "Index ";
                for (int i = 0, componentNamesLength = componentNames.Length; i < componentNamesLength; i++) {
                    componentNames[i] = suffix + i;
                }
                _metaData = new PoolMetaData("Unnamed Pool", componentNames);
            }

            _groupsForIndex = new List<Group>[totalComponents];

            // Cache delegates to avoid gc allocations
            _cachedUpdateGroupsComponentAddedOrRemoved = updateGroupsComponentAddedOrRemoved;
            _cachedUpdateGroupsComponentReplaced = updateGroupsComponentReplaced;
            _cachedOnEntityReleased = onEntityReleased;
        }
Beispiel #2
0
        /// The prefered way is to use the generated methods from the code generator to create a Pool, e.g. var pool = Pools.pool;
        public Pool(int totalComponents, int startCreationIndex, PoolMetaData metaData)
        {
            _totalComponents = totalComponents;
            _componentPools = new Stack<IComponent>[totalComponents];
            _creationIndex = startCreationIndex;

            if (metaData != null) {
                _metaData = metaData;

                if (metaData.componentNames.Length != totalComponents) {
                    throw new PoolMetaDataException(this, metaData);
                }
            } else {

                // If Pools.pool was used to create the pool, we will never end up here.
                // This is a fallback when the pool is created manually.

                var componentNames = new string[totalComponents];
                const string prefix = "Index ";
                for (int i = 0, componentNamesLength = componentNames.Length; i < componentNamesLength; i++) {
                    componentNames[i] = prefix + i;
                }
                _metaData = new PoolMetaData("Unnamed Pool", componentNames, null);
            }

            _groupsForIndex = new List<Group>[totalComponents];

            // Cache delegates to avoid gc allocations
            _cachedUpdateGroupsComponentAddedOrRemoved = updateGroupsComponentAddedOrRemoved;
            _cachedUpdateGroupsComponentReplaced = updateGroupsComponentReplaced;
            _cachedOnEntityReleased = onEntityReleased;
        }
Beispiel #3
0
        /// The prefered way is to use the generated methods from the code generator to create a Pool, e.g. var pool = Pools.pool;
        public Pool(int totalComponents, int startCreationIndex, PoolMetaData metaData)
        {
            _totalComponents = totalComponents;
            _componentPools  = new Stack <IComponent> [totalComponents];
            _creationIndex   = startCreationIndex;

            if (metaData != null)
            {
                _metaData = metaData;

                if (metaData.componentNames.Length != totalComponents)
                {
                    throw new PoolMetaDataException(this, metaData);
                }
            }
            else
            {
                var          componentNames = new string[totalComponents];
                const string prefix         = "Index ";
                for (int i = 0, componentNamesLength = componentNames.Length; i < componentNamesLength; i++)
                {
                    componentNames[i] = prefix + i;
                }
                _metaData = new PoolMetaData("Unnamed Pool", componentNames);
            }

            _groupsForIndex = new List <Group> [totalComponents];

            // Cache delegates to avoid gc allocations
            _cachedUpdateGroupsComponentAddedOrRemoved = updateGroupsComponentAddedOrRemoved;
            _cachedUpdateGroupsComponentReplaced       = updateGroupsComponentReplaced;
            _cachedOnEntityReleased = onEntityReleased;
        }
Beispiel #4
0
        public Pool(int totalComponents, int startCreationIndex) {
            _totalComponents = totalComponents;
            _creationIndex = startCreationIndex;
            _groupsForIndex = new List<Group>[totalComponents];

            // Cache delegates to avoid gc allocations
            _cachedUpdateGroupsComponentAddedOrRemoved = updateGroupsComponentAddedOrRemoved;
            _cachedUpdateGroupsComponentReplaced = updateGroupsComponentReplaced;
            _cachedOnEntityReleased = onEntityReleased;
        }
Beispiel #5
0
        public Pool(int totalComponents, int startCreationIndex)
        {
            _totalComponents = totalComponents;
            _creationIndex   = startCreationIndex;
            _groupsForIndex  = new List <Group> [totalComponents];

            // Cache delegates to avoid gc allocations
            _cachedUpdateGroupsComponentAddedOrRemoved = updateGroupsComponentAddedOrRemoved;
            _cachedUpdateGroupsComponentReplaced       = updateGroupsComponentReplaced;
            _cachedOnEntityReleased = onEntityReleased;
        }
Beispiel #6
0
        /// The prefered way is to use the generated methods from the
        /// code generator to create a Pool,
        /// e.g. Pools.sharedInstance.pool = Pools.CreatePool();
        public Pool(int totalComponents,
                    int startCreationIndex,
                    PoolMetaData metaData)
        {
            _totalComponents = totalComponents;
            _creationIndex   = startCreationIndex;

            if (metaData != null)
            {
                _metaData = metaData;

                if (metaData.componentNames.Length != totalComponents)
                {
                    throw new PoolMetaDataException(this, metaData);
                }
            }
            else
            {
                // If Pools.CreatePool() was used to create the pool,
                // we will never end up here.
                // This is a fallback when the pool is created manually.

                var          componentNames = new string[totalComponents];
                const string prefix         = "Index ";
                for (int i = 0; i < componentNames.Length; i++)
                {
                    componentNames[i] = prefix + i;
                }
                _metaData = new PoolMetaData(
                    "Unnamed Pool", componentNames, null
                    );
            }

            _groupsForIndex = new List <Group> [totalComponents];
            _componentPools = new Stack <IComponent> [totalComponents];
            _entityIndices  = new Dictionary <string, IEntityIndex>();

            // Cache delegates to avoid gc allocations
            _cachedEntityChanged     = updateGroupsComponentAddedOrRemoved;
            _cachedComponentReplaced = updateGroupsComponentReplaced;
            _cachedEntityReleased    = onEntityReleased;
        }
        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
            {
                // If Contexts.CreateContext() was used to create the context,
                // we will never end up here.
                // This is a fallback when the context is created manually.

                var          componentNames = new string[totalComponents];
                const string prefix         = "Index ";
                for (int i = 0; i < componentNames.Length; i++)
                {
                    componentNames[i] = prefix + i;
                }
                _contextInfo = new ContextInfo(
                    "Unnamed Context", componentNames, null
                    );
            }

            _groupsForIndex = new List <Group> [totalComponents];
            _componentPools = new Stack <IComponent> [totalComponents];
            _entityIndices  = new Dictionary <string, IEntityIndex>();

            // Cache delegates to avoid gc allocations
            _cachedEntityChanged     = updateGroupsComponentAddedOrRemoved;
            _cachedComponentReplaced = updateGroupsComponentReplaced;
            _cachedEntityReleased    = onEntityReleased;
        }
Beispiel #8
0
        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 {

                // If Contexts.CreateContext() was used to create the context,
                // we will never end up here.
                // This is a fallback when the context is created manually.

                var componentNames = new string[totalComponents];
                const string prefix = "Index ";
                for (int i = 0; i < componentNames.Length; i++) {
                    componentNames[i] = prefix + i;
                }
                _contextInfo = new ContextInfo(
                    "Unnamed Context", componentNames, null
                );
            }

            _groupsForIndex = new List<Group>[totalComponents];
            _componentPools = new Stack<IComponent>[totalComponents];
            _entityIndices = new Dictionary<string, IEntityIndex>();

            // Cache delegates to avoid gc allocations
            _cachedEntityChanged = updateGroupsComponentAddedOrRemoved;
            _cachedComponentReplaced = updateGroupsComponentReplaced;
            _cachedEntityReleased = onEntityReleased;
        }