Séparation Chunk::Update et VertexBuffer::SetMeshData, Cleanup
This commit is contained in:
		| @@ -124,34 +124,38 @@ void Chunk::CheckNeighbors(int x, int z, World* world) { | ||||
|  | ||||
| void Chunk::GetPosition(int& x, int& y) const { x = m_posX; y = m_posY; } | ||||
|  | ||||
| void Chunk::FlushMeshToVBO() { | ||||
|     m_vertexBuffer.SetMeshData(m_vd, m_vcount); | ||||
|     m_vcount = 0; | ||||
|     delete[] m_vd; | ||||
| } | ||||
|  | ||||
| void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST], World* world) { | ||||
|     float u, v, s; | ||||
|     // Update mesh | ||||
|     if (m_isDirty) { | ||||
|         int maxVertexCount = (CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z) * (6 * 4); | ||||
|         VertexBuffer::VertexData* vd = new VertexBuffer::VertexData[maxVertexCount]; | ||||
|         int count = 0; | ||||
|         m_vd = new VertexBuffer::VertexData[maxVertexCount]; | ||||
|         m_vcount = 0; | ||||
|         for (int x = 0; x < CHUNK_SIZE_X; ++x) { | ||||
|             for (int z = 0; z < CHUNK_SIZE_Z; ++z) { | ||||
|                 for (int y = 0; y < CHUNK_SIZE_Y; ++y) { | ||||
|                     if (count > USHRT_MAX) | ||||
|                     if (m_vcount > USHRT_MAX) | ||||
|                         break; | ||||
|  | ||||
|                     BlockType bt = GetBlock(x, y, z); | ||||
|  | ||||
|                     if (bt != BTYPE_AIR) { | ||||
|                         blockinfo[bt]->GetTexture(u, v, s); | ||||
|                         AddBlockToMesh(vd, count, bt, x, y, z, u, v, s, world); | ||||
|                         AddBlockToMesh(m_vd, m_vcount, bt, x, y, z, u, v, s, world); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (count > USHRT_MAX) { | ||||
|             count = USHRT_MAX; | ||||
|         if (m_vcount > USHRT_MAX) { | ||||
|             m_vcount = USHRT_MAX; | ||||
|             std::cout << "[ Chunk :: Update ] Chunk data truncaned , too much vertices to have a 16 bit index " << std::endl; | ||||
|         } | ||||
|         m_vertexBuffer.SetMeshData(vd, count); | ||||
|         delete[] vd; | ||||
|     } | ||||
|     m_isDirty = false; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user