示例#1
0
            public void Iteration(ref EntityChunk chunk, int index)
            {
                Vector3 pos = Vector3.Zero;

                if (chunk.TryGetComponent(index, out C_Position positionComponent))
                {
                    pos = (Vector3)positionComponent.value;
                }

                Quaternion rot = Quaternion.Identity;

                if (chunk.TryGetComponent(index, out C_Rotation rotationComponent))
                {
                    rot = rotationComponent.value;
                }

                Vector3 scale = Vector3.One;

                if (chunk.TryGetComponent(index, out C_UniformScale scaleComponent))
                {
                    scale *= scaleComponent.value;
                }

                Matrix4 transform = Matrix4.Identity;

                transform *= Matrix4.CreateScale(scale);
                transform *= Matrix4.CreateFromQuaternion(rot);
                transform *= Matrix4.CreateTranslation(pos);
                chunk.SetComponent(index, new C_Transform()
                {
                    value = transform
                });
            }
示例#2
0
 public void SetComponent <T0>(Entity entity, T0 component) where T0 : IComponent
 {
     for (int i = 0; i < chunks.Count; i++)
     {
         ref EntityChunk chunk = ref chunks[i];
         for (int e = 0; e < chunk.Count; e++)
         {
             Entity currEntity = chunk.GetEntity(e);
             if (currEntity.id == entity.id)
             {
                 chunk.SetComponent(e, component);
                 chunk.UpdateVersion(version);
                 return;
             }
         }
     }
示例#3
0
        public bool NeedsUpdate(ref EntityChunk chunk)
        {
            if (anyTypes == null)
            {
                return(false);
            }

            for (int i = 0; i < anyTypes.Length; i++)
            {
                TypeCache type = anyTypes[i];
                if (chunk.Archetype.HasTypes(type) && !type.IsReadOnly)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        public void DEBUG_LOG_INFO()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Entity Manager: \n");
            StructArray <EntityChunk> chunks = entityManager.GetChunks();

            sb.Append("Chunks Count: " + chunks.Count + "\n");
            sb.Append($"----------------------------------- \n");
            for (int i = 0; i < chunks.Count; i++)
            {
                EntityChunk chunk = chunks[i];
                sb.Append($"Entities: {chunk.Count} / Version: {chunk.ChunkVersion} \n");
                sb.Append($"Archetype: {chunk.Archetype} \n");
                sb.Append($"----------------------------------- \n");
            }
            sb.Append("\n");
            Console.WriteLine(sb);
        }
示例#5
0
        private static void PerformChunkIteration(EntityWorld world, IQueryChunkIterator chunkIterator, EntityQuery query, bool checkVersion, uint version)
        {
            StructArray <EntityChunk> chunks = world.EntityManager.GetChunks();
            bool generalWrite = query.IsGeneralWrite();

            for (int i = 0; i < chunks.Count; i++)
            {
                ref EntityChunk chunk = ref chunks[i];
                if (query.Matches(chunk.Archetype))
                {
                    if (checkVersion && !chunk.HasChanged(version))
                    {
                        continue;
                    }

                    chunkIterator.Iteration(ref chunk);

                    if (generalWrite || query.NeedsUpdate(ref chunk))
                    {
                        chunk.UpdateVersion(world.EntityManager.Version);
                    }
                }
            }
示例#6
0
 public bool ArchetypeMatch(EntityChunk chunk)
 {
     return(HasArchetype(Archetype) && HasSharedComponents(sharedComponents));
 }