Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
    /**
     *  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));
    }
Ejemplo n.º 3
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 public override bool RegenerateMesh(ChunkMesher m)
 {
     return(false);
 }
Ejemplo n.º 7
0
 public abstract bool RegenerateMesh(ChunkMesher m);
Ejemplo n.º 8
0
 private void CreateMesh()
 {
     this.Mesh = ChunkMesher.GetCubeMesh(this.Color, this.Position);
 }