public void ThreadInitialize(int x, int z, ChunkMesher mesher, Vector2 offset) { this.mesher = mesher; data = new ChunkData(); data.ChunkX = x; data.ChunkZ = z; gameObject.transform.position = new Vector3(x * Constants.ChunkWidth + offset.x, 0, z * Constants.ChunkWidth + offset.y); }
/** * Creates a chunk at the requested chunk position * * The x and z are the chunk position, which is the absolute position divided by the chunk width. */ public void RequestChunk(int x, int z, ChunkMesher mesher, Vector2 offset) { chunkRequested[Hash(x, z)] = true; Chunk chunk = Instantiate(chunkPrefab).GetComponent <Chunk>(); chunk.ThreadInitialize(x, z, mesher, offset); chunk.transform.SetParent(chunkParent.transform); generationRequests.Push(new ChunkRequest(ChunkRequest.RequestType.Generation, chunk)); }
private void AddBlocksToVao() { for (var x = _min.X; x <= _max.X; x++) { for (var y = _min.Y; y <= _max.Y; y++) { for (var z = _min.Z; z <= _max.Z; z++) { if (_blockIds[x, y, z] != 0) //Remove GetBlock overhead of Air { ChunkMesher.AddBlockToVao(World, Position * Size + new Vector3i(x, y, z), x, y, z, GameRegistry.BlockRegistry[_blockIds[x, y, z]], _vao, _transparentVao); } } } } }
public override bool RegenerateMesh(ChunkMesher mesher) { Mesh m = mesher.GenerateMesh(this); if (m == null && renderer == null) { return(true); } if (m != null && renderer == null) { renderer = world.CreateChunkRenderer(this); } if (m != null) { renderer.Update(m); } renderer?.SetActive(m != null); return(true); }
public BlockWorld() { rendererPool = new ObjectPool <ChunkRenderer>(RendererPoolSize, () => new ChunkRenderer()); meshUpdateQueue = new Queue <ChunkLocation>(); chunkMap = new Dictionary <ChunkLocation, Chunk>(); chunkLoadQueue = new SimplePriorityQueue <ChunkLocation, int>(); chunkUnloadStack = new Stack <Chunk>(); currentlyLoading = new HashSet <ChunkLocation>(); loadedChunks = new ConcurrentQueue <WorldChunk>(); mesher = new ChunkMesher(); generator = new DefaultWorldGenerator((int)Stopwatch.GetTimestamp()); updateTimer = new Stopwatch(); debugTimer = new Stopwatch(); debugTimer.Start(); UpdateChunkQueues(); }
public override bool RegenerateMesh(ChunkMesher m) { return(false); }
public abstract bool RegenerateMesh(ChunkMesher m);
private void CreateMesh() { this.Mesh = ChunkMesher.GetCubeMesh(this.Color, this.Position); }