예제 #1
0
        internal void Move(Entity entity, ArchetypeGroup newGroup, ref FlatMap <Entity, int> entityIndexMap)
        {
            int currentIndex = entityIndexMap[entity];
            int newIndex     = newGroup.Add(entity, ref entityIndexMap);

            foreach (var type in newGroup.componentTypes)
            {
                if (componentsMap.ContainsKey(type))
                {
                    newGroup.componentsMap[type].SetValue(componentsMap[type].GetValue(currentIndex), newIndex);
                }
            }
            Remove(entity, ref entityIndexMap);
        }
예제 #2
0
        /// <summary>
        /// Create a new archetype.
        /// </summary>
        /// <param name="types">Component types that make up the archetype</param>
        /// <returns>New archetype</returns>
        public Archetype CreateArchetype(params Type[] types)
        {
            var archetype = new Archetype(nextArchetypeId++);

            // Register the types for the archetype
            archetypeMap[archetype] = types;
            // Add types for reverse lookup
            typeMap.Add(types, archetype);
            // Create an archetype group for the new archetype
            archetypeGroupMap[archetype] = new ArchetypeGroup(archetype, types);
            // Update component groups
            foreach (var componentGroup in componentGroups)
            {
                componentGroup.archetypeGroups = GetArchetypeGroups(componentGroup.includes, componentGroup.excludes).ToArray();
            }
            return(archetype);
        }