示例#1
0
        // Redo later while cycling through world chunk references rather then all worlds
        public void DestroyWorld(Entity worldEntity)
        {
            if (!World.EntityManager.Exists(worldEntity))
            {
                return;
            }
            List <int> removeIDs = new List <int>();
            World      world     = World.EntityManager.GetComponentData <World>(worldEntity);
            var        worldID   = World.EntityManager.GetComponentData <ZoxID>(worldEntity).id;

            //foreach (Entity e in chunks.Values)
            for (int i = 0; i < world.chunks.Length; i++)
            {
                var e       = world.chunks[i];
                var chunk   = World.EntityManager.GetComponentData <Chunk>(e);
                var chunkID = World.EntityManager.GetComponentData <ZoxID>(e).id;
                //if (chunk.worldID == worldID)
                //{
                var lookupTable = worldSpawnSystem.worldLookups[worldID];
                lookupTable.chunks.Remove(chunk.Value.chunkPosition);
                worldSpawnSystem.worldLookups[worldID] = lookupTable;

                removeIDs.Add(chunkID);
                // chunk.renderIDs
                if (World.EntityManager.HasComponent <MonsterSpawnZone>(e))
                {
                    var monsterSpawner = World.EntityManager.GetComponentData <MonsterSpawnZone>(e);
                    for (int a = 0; a < monsterSpawner.spawnedIDs.Length; a++)
                    {
                        characterDeathSystem.DestroyCharacter(monsterSpawner.spawnedIDs[a]);
                    }
                }

                // for all chunkRenders (should be)
                for (int a = 0; a < chunk.chunkRenders.Length; a++)
                {
                    var chunkRender = chunk.chunkRenders[a];
                    ChunkRenderSystem.DestroyChunkRender(World.EntityManager, chunkRender);
                }
                if (World.EntityManager.Exists(e))
                {
                    World.EntityManager.DestroyEntity(e);
                }
                //}
            }
            foreach (int removeID in removeIDs)
            {
                chunks.Remove(removeID);
            }
        }
示例#2
0
 public void RemoveRenderEntitiesFromChunk(ref Chunk chunk)
 {
     if (ChunkSpawnSystem.isDebugLog)
     {
         Debug.LogError("Removing chunk renders from chunk: " + chunk.Value.chunkPosition);
     }
     if (chunk.chunkRenders.Length != 0)
     {
         for (int i = 0; i < chunk.chunkRenders.Length; i++)
         {
             var chunkRenderEntity = chunk.chunkRenders[i];
             ChunkRenderSystem.DestroyChunkRender(World.EntityManager, chunkRenderEntity);
         }
         chunk.chunkRenders = new BlitableArray <Entity>(0, Allocator.Persistent);
     }
 }
示例#3
0
 public void RemoveChunk(Entity chunkEntity, bool isRemoveFromWorld = true)
 {
     //if (chunks.ContainsKey(chunkID))
     {
         //Entity chunkEntity = chunks[chunkID];
         Chunk chunk       = World.EntityManager.GetComponentData <Chunk>(chunkEntity);
         var   chunkID     = World.EntityManager.GetComponentData <ZoxID>(chunkEntity).id;
         var   worldID     = World.EntityManager.GetComponentData <ZoxID>(chunkEntity).creatorID;
         var   lookupTable = worldSpawnSystem.worldLookups[worldID];
         lookupTable.chunks.Remove(chunk.Value.chunkPosition);
         worldSpawnSystem.worldLookups[worldID] = lookupTable;
         if (isRemoveFromWorld)
         {
             Entity worldEntity   = chunk.world;
             World  world         = World.EntityManager.GetComponentData <World>(worldEntity);
             int3[] positions     = new int3[0];
             var    chunkPosition = chunk.Value.chunkPosition;
             RemovePositionIndex(ref world, chunkPosition, chunkID, positions, int3.Forward()); //new float3(0, 0, 1));
             RemovePositionIndex(ref world, chunkPosition, chunkID, positions, int3.Back());    //new float3(0, 0, -1));
             RemovePositionIndex(ref world, chunkPosition, chunkID, positions, int3.Right());   // new float3(1, 0, 0));
             RemovePositionIndex(ref world, chunkPosition, chunkID, positions, int3.Left());    //new float3(-1, 0, 0));
             World.EntityManager.SetComponentData(worldEntity, world);
         }
         for (int j = 0; j < chunk.chunkRenders.Length; j++)
         {
             Entity chunkRender = chunk.chunkRenders[j];
             if (World.EntityManager.Exists(chunkRender))
             {
                 ChunkRenderSystem.DestroyChunkRender(World.EntityManager, chunkRender);
             }
         }
         if (World.EntityManager.HasComponent <MonsterSpawnZone>(chunkEntity))
         {
             MonsterSpawnZone monsterSpawner = World.EntityManager.GetComponentData <MonsterSpawnZone>(chunkEntity);
             int[]            spawnedIDs     = monsterSpawner.spawnedIDs.ToArray();
             for (int j = 0; j < spawnedIDs.Length; j++)
             {
                 characterDeathSystem.DestroyCharacter(spawnedIDs[j]);
             }
         }
         chunks.Remove(chunkID);
         Chunk.Destroy(World.EntityManager, chunkEntity);
     }
 }