public Chunk2 GetChunk(int x, int z) { //TODO should I have the concept of an empty chunk? Chunk2 chunk = (Chunk2)chunkCollection [x + ":" + z]; return(chunk); }
public void PerformTick(bool useQueue) { Vector3 pos = world.GetPlayerPos(); int chunkX = (int)pos.x >> 4; int chunkZ = (int)pos.z >> 4; int xMax = chunkX + 4; int zMax = chunkZ + 4; for (int x = chunkX - 4; x < xMax; x++) { for (int z = chunkZ - 4; z < zMax; z++) { Chunk2 chunk = GetChunk(x, z); if (chunk != null) { chunk.CheckStatusUpdate(useQueue); } //if (chunk != null && chunk.isDataLoaded && chunk.isNeighboursLoaded) //{ // chunk.SpreadDaylight_tick(); //} } } }
public bool LoadChunkWithinDist(int startChunkX, int startChunkZ, int blockDist, int maxLoad) { int currentLoad = 0; int chunkx = startChunkX >> 4; int chunkz = startChunkZ >> 4; int chunkdist = blockDist >> 4; int minX = chunkx - chunkdist; int minZ = chunkz - chunkdist; int maxX = chunkx + chunkdist; int maxZ = chunkz + chunkdist; for (int x = minX; x < maxX; x++) { for (int z = minZ; z < maxZ; z++) { Chunk2 chunk = GetChunk(x, z); if (chunk == null) { LoadChunk(x, z, true); //ChunkLoader.RequestChunk(this, x, z); //this.LoadChunk(x, z); currentLoad++; if (currentLoad >= maxLoad) { return(true); } } } } return(false); }
/// <summary> /// Move from status 1 to 2 (data generated to light generated /// </summary> /// <param name="chunk">Chunk.</param> public static void GenerateLight(Chunk2 chunk) { queue.EngueueItem(() => { chunk.SpreadDaylight(); chunk.status = 2; }); }
public static void RenderChunk(Chunk2 chunk) { queue.EngueueItem(() => { chunk.manager.renderer.RenderChunk(chunk); chunk.status = 3; }); }
public static void GenerateData(Chunk2 chunk) { // status 0 to 1 queue.EngueueItem(() => { PerlinWorldGenerator.CreateChunk(chunk); chunk.status = 1; }); }
Chunk2 createChild(Vector3 start, Vector3 end, Algorithm2 algorithm) { Chunk2 child = (Instantiate(chunkPrefab, start, Quaternion.identity) as GameObject).GetComponent <Chunk2>(); child.transform.parent = transform; child.name = "Chunk " + start.x + "_" + start.z; child.startPoint = start; child.endPoint = end; child.createGeometry(meshRenderer.sharedMaterial, algorithm); return(child); }
void enterlastChunk() { int chunkSizeDifference = lastChunk.chunkSize.x - currentChunk.chunkSize.x; if (chunkSizeDifference > 0 || (chunkPos.x >= -chunkSizeDifference / 2 && chunkPos.x < -chunkSizeDifference / 2 + lastChunk.chunkSize.x)) { currentChunk = lastChunk; chunkPos.y = currentChunk.chunkSize.y - 1; chunkPos.x += (currentChunk.chunkSize.x - nextChunk.chunkSize.x) / 2; } }
public int GetHeightAt(int x, int z) { int xPos = x / 16; int zPos = z / 16; int xSectionPos = x % 16; int zSectionPos = z % 16; Chunk2 chunk = this.GetChunk(xPos, zPos); return(chunk.heightMap[xSectionPos + 16 * zSectionPos]); }
//int doScore() { // if (scoreint < transform.position.y) // { // scoreint = (int)transform.position.y; // } // return scoreint; //} void enterNextChunk() { int chunkSizeDifference = nextChunk.chunkSize.x - currentChunk.chunkSize.x; if (chunkSizeDifference > 0 || (chunkPos.x >= -chunkSizeDifference / 2 && chunkPos.x < -chunkSizeDifference / 2 + nextChunk.chunkSize.x)) { lastChunk = currentChunk; currentChunk = nextChunk; chunkPos.y = 0; chunkPos.x += (currentChunk.chunkSize.x - lastChunk.chunkSize.x) / 2; } }
Chunk2 loadChunk(int i) { if (i < chunksToLoad.Length) { Chunk2 chunk = GameObject.Instantiate(chunkPrefab, transform.position, Quaternion.identity).GetComponent <Chunk2>(); chunk.chunkSize = new Vector2Int(chunksToLoad[i].ChunkWidth, chunkSize.y); chunk.randomBombPercent = chunksToLoad[i].randomBombPercent; chunk.randomFillPercent = chunksToLoad[i].randomFillPercent; chunk.gameObject.GetComponent <GenerateTiledCilinderChunk2>().chunkIndex = i; chunk.gameObject.GetComponent <GenerateTiledCilinderChunk2>().chunkWidth = chunksToLoad[i].ChunkWidth; return(chunk); } else { return(null); } }
public void SetBlockId(int x, int y, int z, byte id) { if (y >= 256 || y < 0) { return; } else { int xPos = x / 16; int zPos = z / 16; int xSectionPos = x - (xPos * 16); int zSectionPos = z - (zPos * 16); Chunk2 chunk = this.GetChunk(xPos, zPos); if (chunk == null) { return; } chunk.SetBlockId(xSectionPos, y, zSectionPos, id); } }
public void Initialise() { chunk = gameObject.GetComponent <Chunk2>(); meshes = new Mesh[chunkLength]; for (int i = 0; i < chunkLength; i++) { meshes[i] = GameObject.Instantiate(chunkTileObject, transform.position, Quaternion.identity, transform).GetComponent <MeshFilter>().mesh; } radius = (chunkCount * chunkLength) / (2 * Mathf.PI); circlePosses = possesOnCircle(chunkLength + 1, radius, chunkIndex); dugCirclePosses = possesOnCircle(chunkLength + 1, radius - digDepth, chunkIndex); chunk.chunkSize = new Vector2Int(chunkWidth, chunkLength); chunk.generateChunk(); for (int i = 0; i < chunkLength; i++) { GenerateTileMesh(chunk.walls, i); } }
public void SetLightValue(int x, int y, int z, int level) { if (y >= 256 || y < 0) { return; } else { int xPos = x / 16; int zPos = z / 16; int xSectionPos = x - (xPos * 16); int zSectionPos = z - (zPos * 16); Chunk2 chunk = this.GetChunk(xPos, zPos); if (chunk == null) { return; } chunk.SetDaylightValue(xSectionPos, y, zSectionPos, (byte)level); } }
public void createGeometry(Material material, Algorithm2 algorithm) { init(); // Generate the quads float quadSize = (new Vector3(startPoint.x, 0, endPoint.z) - startPoint).magnitude / (float)quads; for (int i = 0; i < quads; i++) { for (int j = 0; j < quads; j++) { Chunk2.createQuad((float)i * quadSize, (float)j * quadSize, quadSize, algorithm, meshData, transform); } } // Pass the data to the mesh meshRenderer.sharedMaterial = material; meshData.GenerateData(meshFilter.sharedMesh); // Recalculate bounds and normals meshFilter.sharedMesh.RecalculateBounds(); NormalSolver.RecalculateNormals(meshFilter.sharedMesh, 60); }
public int GetBlockId(int x, int y, int z) { if (y >= 256 || y < 0) { return(0); } else { int xPos = x / 16; int zPos = z / 16; int xSectionPos = x - (xPos * 16); int zSectionPos = z - (zPos * 16); Chunk2 chunk = this.GetChunk(xPos, zPos); if (chunk == null) { return(3); //throw new ArgumentNullException(); } return(chunk.GetBlockId(xSectionPos, y, zSectionPos)); } }
/*public void SpreadLightToAllChunks() * { * * System.DateTime start = System.DateTime.Now; * foreach (var key in chunkCollection.Keys) * { * if (((Chunk2)chunkCollection[key]).SpreadDaylight()) * { * ((Chunk2)chunkCollection[key]).isNeighboursLoaded = true; * } * } * StatsEngine.ChunkSpreadLight += (float)System.DateTime.Now.Subtract(start).TotalSeconds; * * }*/ public int GetLightValue(int x, int y, int z) { if (y >= 256 || y < 0) { return(15); } else { int xPos = x / 16; int zPos = z / 16; int xSectionPos = x - (xPos * 16); int zSectionPos = z - (zPos * 16); Chunk2 chunk = this.GetChunk(xPos, zPos); if (chunk == null) { return(15); //throw new ArgumentNullException(); } return((int)chunk.GetDaylightValue(xSectionPos, y, zSectionPos)); } }
public void SetChunk(int x, int z, Chunk2 chunk) { chunkCollection.Add(x + ":" + z, chunk); }
public void LoadChunk(int x, int z, bool useQueue) { System.DateTime genStart = System.DateTime.Now; Chunk2 chunk = new Chunk2(this, x, z); chunkCollection.Add(x + ":" + z, chunk); chunk.pendingStatus = 1; Chunk2 n = GetChunk(chunk.xPosition, chunk.zPosition + 1); Chunk2 ne = GetChunk(chunk.xPosition + 1, chunk.zPosition + 1); Chunk2 e = GetChunk(chunk.xPosition + 1, chunk.zPosition); Chunk2 se = GetChunk(chunk.xPosition + 1, chunk.zPosition - 1); Chunk2 s = GetChunk(chunk.xPosition, chunk.zPosition - 1); Chunk2 sw = GetChunk(chunk.xPosition - 1, chunk.zPosition - 1); Chunk2 w = GetChunk(chunk.xPosition - 1, chunk.zPosition); Chunk2 nw = GetChunk(chunk.xPosition - 1, chunk.zPosition + 1); if (n != null) { chunk.ChunkNorth = n; n.ChunkSouth = chunk; } if (ne != null) { chunk.ChunkNorthEast = ne; ne.ChunkSouthWest = chunk; } if (e != null) { chunk.ChunkEast = e; e.ChunkWest = chunk; } if (se != null) { chunk.ChunkSouthEast = se; se.ChunkNorthWest = chunk; } if (s != null) { chunk.ChunkSouth = s; s.ChunkNorth = chunk; } if (sw != null) { chunk.ChunkSouthWest = sw; sw.ChunkNorthEast = chunk; } if (w != null) { chunk.ChunkWest = w; w.ChunkEast = chunk; } if (nw != null) { chunk.ChunkNorthWest = nw; nw.ChunkSouthEast = chunk; } if (useQueue) { ChunkLoader.GenerateData(chunk); } else { PerlinWorldGenerator.CreateChunk(chunk); chunk.status = 1; } chunk.isDataLoaded = true; StatsEngine.ChunkGenTime += (float)System.DateTime.Now.Subtract(genStart).TotalSeconds; }