public static void CreateWorldUpdate(EntityManager EntityManager, Entity world, List <int> worldsChunkIDs, List <int> oldChunkIDs, Dictionary <int, bool> allRenders) { Entity e = EntityManager.CreateEntity(); WorldStreamCommand worldStreamCommand = new WorldStreamCommand { }; worldStreamCommand.world = world; worldStreamCommand.SetIDs(worldsChunkIDs, oldChunkIDs); worldStreamCommand.SetRenders(allRenders); EntityManager.AddComponentData(e, worldStreamCommand); }
void UpdateWorld(WorldStreamCommand command) { // , Dictionary<int, bool> allRenders Entity worldEntity = command.world; World world = World.EntityManager.GetComponentData <World>(worldEntity); var ids = command.newIDs.ToArray(); if (command.isModel == 1) { //Debug.LogError("Adding Chunk Renders for World: " + world.id); for (int i = 0; i < ids.Length; i++) { var chunkEntity = chunkSpawnSystem.chunks[ids[i]]; Chunk chunk = World.EntityManager.GetComponentData <Chunk>(chunkEntity); chunkRenderSystem.AddRenderEntitiesToChunk(world, chunkEntity, ref chunk); World.EntityManager.SetComponentData(chunkSpawnSystem.chunks[ids[i]], chunk); } } // for all old worlds that stayed else { var oldIDs = command.oldIDs.ToArray(); var renders = command.newRenders.ToArray(); for (int i = 0; i < ids.Length; i++) { // if new and old id! bool doesContain = false; for (int j = 0; j < oldIDs.Length; j++) { if (ids[i] == oldIDs[j]) { doesContain = true; break; } } if (doesContain) { // now get old render and see if changed Entity chunkEntity = chunkSpawnSystem.chunks[ids[i]]; Chunk chunk = World.EntityManager.GetComponentData <Chunk>(chunkEntity); if (chunk.chunkRenders.Length == 0 && renders[i] == 1) { if (World.EntityManager.HasComponent <ChunkBuilder>(chunkEntity)) { World.EntityManager.SetComponentData(chunkEntity, new ChunkBuilder { }); } else { World.EntityManager.AddComponentData(chunkEntity, new ChunkBuilder { }); } if (chunkRenderSystem != null) { chunkRenderSystem.AddRenderEntitiesToChunk(world, chunkEntity, ref chunk); } } else if (chunk.chunkRenders.Length != 0 && renders[i] == 0) { if (chunkRenderSystem != null) { chunkRenderSystem.RemoveRenderEntitiesFromChunk(ref chunk); } } World.EntityManager.SetComponentData(chunkEntity, chunk); } } } World.EntityManager.SetComponentData(worldEntity, world); }