private void _read() { if (ChunkOfs < 0) { _saveChunkOfs = m_io.ReadBytes(0); } _chunk = new ChunkClass(m_io, this, m_root); }
public static bool SeedChunk(ChunkClass Chunk) { int AirBlocks = 0; int NonAir = 0; Vector3Int _position = Chunk.Position; Noise.SetPerturbType(FastNoiseSIMD.PerturbType.None); Noise.SetAxisScales(1, 1, 1); Noise.SetNoiseType(FastNoiseSIMD.NoiseType.Cubic); Noise.SetFrequency(0.01f); var LongPeriod = Noise.GetSampledNoiseSet(_position.x, 0, _position.z, Globals.ChunkSize, 1, Globals.ChunkSize, 1); Noise.SetNoiseType(FastNoiseSIMD.NoiseType.SimplexFractal); Noise.SetFractalType(FastNoiseSIMD.FractalType.FBM); Noise.SetFrequency(0.01f); var ShortPeriod = Noise.GetSampledNoiseSet(_position.x, 0, _position.z, Globals.ChunkSize, 1, Globals.ChunkSize, 1); int index = 0; for (int y = 0; y < Globals.ChunkSize; y++) { index = 0; for (int x = 0; x < Globals.ChunkSize; x++) { for (int z = 0; z < Globals.ChunkSize; z++) { float v = LongPeriod[index] * 32 + 16 + ShortPeriod[index++] * 16;// * (float)(Biom[x, z] * 8); if (v >= Chunk.Position.y + y) { Chunk.Blocks[x][y][z].SubBlock = new subBlockClass(); Chunk.Blocks[x][y][z].SetDensity(v - (Chunk.Position.y + y)); NonAir++; } else { Chunk.Blocks[x][y][z].SubBlock = new AirBlock(); Chunk.Blocks[x][y][z].SetDensity(v - (Chunk.Position.y + y)); AirBlocks++; } } } } if (NonAir == 0) { Chunk.FillState = ChunkClass.FillStateEnum.Empty; } else if (AirBlocks == 0) { Chunk.FillState = ChunkClass.FillStateEnum.Solid; } else { Chunk.FillState = ChunkClass.FillStateEnum.Mixed; } return(true); }
public static void AddItemToChunk(DroppedItem Item) { if (ChunkExists(Item.Translation)) { List <DroppedItem> Items = Chunks[GetChunkTuple(Item.Translation)].Items; Items.Add(Item); Chunks[GetChunkTuple(Item.Translation)].Items = Items; } else { ChunkClass Chunk = new ChunkClass(); Chunk.Items.Add(Item); Chunks.Add(GetChunkTuple(Item.Translation), Chunk); } }
void LateUpdate() { if (!InitialSceneLoaded || Globals._player == null) { return; } //StopCoroutine(InitialSceneLoad()); Vector3Int WPt; // Check State of Chunks CameraPosI = Vector3Int.FloorToInt(Globals._player.transform.position / 16f) * 16; CameraPosI.y = 0; for (int i = 0; i < Globals.Chunks.Count; i++) { tempCO = Globals.Chunks[i].GetComponent <ChunkClass>(); tempV = tempCO.Position - CameraPosI; tempBool = false; for (int i2 = 0; i2 < Globals.RenderList.Count; i2++) { if (Globals.RenderList[i2].x == tempV.x) { if (Globals.RenderList[i2].y == tempV.y) { if (Globals.RenderList[i2].z == tempV.z) { tempBool = true; break; } } } } if (!tempBool) { Globals.Chunks[i].GetComponent <ChunkClass>().SleepChunk(); InActiveChunks.Add(Globals.Chunks[i]); Globals.Chunks.RemoveAt(i); } } for (int i = 0; i < Globals.RenderList.Count; i++) { WPt = Globals.RenderList[i] + CameraPosI; if (!GetChunk(WPt, out tempGO)) { LoadNewChunk(WPt); break; } } }
public static void AddMobToChunk(MobClass Mob) { var ChunkTuple = GetChunkTuple(Mob.Translation); Mob.CurrentChunkTuple = ChunkTuple; if (ChunkExists(Mob.Translation)) { Chunks[ChunkTuple].Mobs.Add(Mob); } else { ChunkClass Chunk = new ChunkClass(); Chunk.Mobs.Add(Mob); Chunks.Add(ChunkTuple, Chunk); } }
static void AddTileToChunk(Tile Branch) { if (ChunkExists(Branch.Translation)) { List <Tile> Chunk = Chunks[GetChunkTuple(Branch.Translation)].Tiles; Chunk.Add(Branch); Chunks[GetChunkTuple(Branch.Translation)].Tiles = Chunk; } else { ChunkClass Chunk = new ChunkClass(); Chunk.Tiles = new List <Tile> { Branch }; Chunks.Add(GetChunkTuple(Branch.Translation), Chunk); } }
public static void AddEntityToChunk(IEntity Entity) { var ChunkTuple = GetChunkTuple(Entity.Translation); if (Chunks.TryGetValue(ChunkTuple, out var Chunk)) { Chunk.Entities.Add(Entity); } else { Chunk = new ChunkClass(); Chunk.Entities.Add(Entity); Chunks.Add(ChunkTuple, Chunk); } Entity.CurrentChunk = ChunkTuple; }
static void AddStructureToChunk(Structure Branch) { if (ChunkExists(Branch.Translation)) { List <Structure> Chunk = Chunks[GetChunkTuple(Branch.Translation)].Structures; Chunk.Add(Branch); Chunks[GetChunkTuple(Branch.Translation)].Structures = Chunk; } else { ChunkClass Chunk = new ChunkClass(); Chunk.Structures = new List <Structure> { Branch }; Chunks.Add(GetChunkTuple(Branch.Translation), Chunk); } }
private void LinkChunks() { Vector3Int Pos = Position; for (int i = 0; i < Globals.NeighborOffset.Length; i++) { Vector3Int V = Globals.NeighborOffset[i]; Vector3Int VN = new Vector3Int(-V.x, -V.y, -V.z); Vector3Int NeighborChunkPosition = Pos + V * Globals.ChunkSize; GameObject NeighborGO; if (Globals.ActiveWorld.GetChunk(NeighborChunkPosition, out NeighborGO)) { ChunkClass NeighborChunk = NeighborGO.GetComponent <ChunkClass>(); Neighbor[V.x + 1, V.y + 1, V.z + 1] = NeighborChunk; NeighborChunk.Neighbor[-V.x + 1, -V.y + 1, -V.z + 1] = this; State = StateEnum.Seeded; } } }
private void _read() { _chunk = new ChunkClass(m_io, this, m_root); }