public static void TestAddChunkToUnloadedChunks(GameSave gameSave, Header header) { ChunkTable oldChunkTable = header.SaveIndex.ChunkTable; var octree = new Octree(gameSave, new BitArray(new[] { false, false }), new byte[] { 1 }); var blockTypeTable = new BlockTypeTable(gameSave, new[] { new StringBlock(gameSave, "Block 0"), new StringBlock(gameSave, "Block 1"), new StringBlock(gameSave, "Block 2"), new StringBlock(gameSave, "Block 2") }, new[] { 0, 0, 0, 1 }); var chunk = new Chunk(gameSave, blockTypeTable, new[] { octree }); var r = new Random(); int x = r.Next(); int z = r.Next(); List <Tuple <int, int, Chunk> > chunks = oldChunkTable.GetChunks().Where(c => c.Item1 != x || c.Item2 != z).ToList(); chunks.Add(new Tuple <int, int, Chunk>(x, z, chunk)); var chunkTable = new ChunkTable(gameSave, chunks.ToArray()); var mainIndex = new SavedStateIndex(gameSave, DateTime.UtcNow.Ticks, new StringBlock(gameSave, "ChunkTable Length: " + chunkTable.Length), chunkTable); var newHeader = new Header(gameSave, mainIndex); newHeader.Write(true); }
public static void TestMarkModify(GameSave gameSave, Header header) { var newChunkTable = new ChunkTable(gameSave, header.SaveIndex.ChunkTable.GetChunks().Concat( header.SaveIndex.ChunkTable.GetChunks().Take(1).Select( x => new Tuple <int, int, Chunk>(x.Item1 + 1, x.Item2 - 1, x.Item3))).ToArray()); var newHeader = new Header(gameSave, new SavedStateIndex(gameSave, DateTime.UtcNow.Ticks, new StringBlock(gameSave, "Modified Save"), newChunkTable)); newHeader.Write(true); }
protected override void OnUpdate() { //There is an option to do culling per chunk by leaving out the PerInstanceCulling tag component. Meaning for each chunk we use the combined bounding volume.For grass likely a good choice. Entities.WithAll <MegaChunk>().WithNone <RenderMesh, HasMeshDataFlag>().ForEach((Entity en, ref MegaChunk chunk) => { if (!MeshComponents._lookupMesh.ContainsKey(chunk.center)) { Mesh hex = HexChunk(chunk.center, chunk); ChunkTable chunkTable = new ChunkTable(en, hex); ////EntityManager.AddSharedComponentData(en, new RenderMesh { mesh = hex, material = material, castShadows = UnityEngine.Rendering.ShadowCastingMode.On }); //EntityManager.AddSharedComponentData(en, new RenderMesh { mesh = hex, material = material }); //EntityManager.AddComponentData(en, new RenderBounds { Value = hex.bounds.ToAABB() }); ////EntityManager.AddComponentData(en, new PerInstanceCullingTag { }); //EntityManager.AddComponentData(en, new LocalToWorld { }); //chunkTable.isDrawn = true; MeshComponents._lookupMesh.Add(chunk.center, chunkTable); PostUpdateCommands.AddComponent(en, new HasMeshDataFlag { }); } }); }
public static void TestSaving(GameSave gameSave, string saveName) { var octree = new Octree(gameSave, new BitArray(new[] { false, false }), new byte[] { 1 }); var blockTypeTable = new BlockTypeTable(gameSave, new[] { new StringBlock(gameSave, "Block 0"), new StringBlock(gameSave, "Block 1"), new StringBlock(gameSave, "Block 2"), new StringBlock(gameSave, "Block 2") }, new[] { 0, 0, 0, 1 }); var chunk = new Chunk(gameSave, blockTypeTable, new[] { octree }); var chunkTable = new ChunkTable(gameSave, new[] { 0 }, new[] { 0 }, new[] { chunk }); var mainIndex = new SavedStateIndex(gameSave, DateTime.UtcNow.Ticks, new StringBlock(gameSave, saveName), chunkTable); var header = new Header(gameSave, mainIndex); header.Write(true); }