|
@@ -1,19 +1,17 @@
|
|
#include "client/rendering/renderer/WorldRenderer.h"
|
|
#include "client/rendering/renderer/WorldRenderer.h"
|
|
|
|
|
|
WorldRenderer::WorldRenderer(const World& world) : world(world), texture("resources/textures.png") {
|
|
WorldRenderer::WorldRenderer(const World& world) : world(world), texture("resources/textures.png") {
|
|
|
|
+ TypedBuffer<Triangle> buffer(100);
|
|
for(int x = 0; x < World::WORLD_SIZE; x++) {
|
|
for(int x = 0; x < World::WORLD_SIZE; x++) {
|
|
for(int y = 0; y < World::WORLD_SIZE; y++) {
|
|
for(int y = 0; y < World::WORLD_SIZE; y++) {
|
|
for(int z = 0; z < World::WORLD_SIZE; z++) {
|
|
for(int z = 0; z < World::WORLD_SIZE; z++) {
|
|
if(world.getBlock(x, y, z).getId() != 0) {
|
|
if(world.getBlock(x, y, z).getId() != 0) {
|
|
- addCube(x, y, z,
|
|
+ addCube(buffer, x, y, z);
|
|
- isAir(x, y - 1, z), isAir(x, y + 1, z),
|
|
|
|
- isAir(x - 1, y, z), isAir(x + 1, y, z),
|
|
|
|
- isAir(x, y, z + 1), isAir(x, y, z - 1));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- mesh.build();
|
|
+ mesh.build(buffer);
|
|
}
|
|
}
|
|
|
|
|
|
void WorldRenderer::render(float lag, Renderer& renderer) {
|
|
void WorldRenderer::render(float lag, Renderer& renderer) {
|
|
@@ -27,7 +25,7 @@ bool WorldRenderer::isAir(int x, int y, int z) const {
|
|
return world.getBlock(x, y, z).getId() == 0;
|
|
return world.getBlock(x, y, z).getId() == 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void WorldRenderer::addCube(float x, float y, float z, bool bottom, bool top, bool left, bool right, bool front, bool back) {
|
|
+void WorldRenderer::addCube(TypedBuffer<Triangle>& buffer, float x, float y, float z) {
|
|
Vector3 v000(x, y, z);
|
|
Vector3 v000(x, y, z);
|
|
Vector3 v001(x, y, z + 1);
|
|
Vector3 v001(x, y, z + 1);
|
|
Vector3 v010(x, y + 1, z);
|
|
Vector3 v010(x, y + 1, z);
|
|
@@ -42,31 +40,30 @@ void WorldRenderer::addCube(float x, float y, float z, bool bottom, bool top, bo
|
|
Vector2 t3(0.25f, 0.0625f);
|
|
Vector2 t3(0.25f, 0.0625f);
|
|
Vector2 t4(0.1875f, 0.0625f);
|
|
Vector2 t4(0.1875f, 0.0625f);
|
|
|
|
|
|
- if(bottom) {
|
|
+ if(isAir(x, y - 1, z)) {
|
|
Vector2 tb(0.125f, 0.0625f);
|
|
Vector2 tb(0.125f, 0.0625f);
|
|
- mesh.add(Triangle(Vertex(v000, Vector2(0.125f, 0.0f)), Vertex(v100, t1), Vertex(v001, tb)));
|
|
+ buffer.add(Triangle(Vertex(v000, Vector2(0.125f, 0.0f)), Vertex(v100, t1), Vertex(v001, tb)));
|
|
- mesh.add(Triangle(Vertex(v100, t1), Vertex(v101, t4), Vertex(v001, tb)));
|
|
+ buffer.add(Triangle(Vertex(v100, t1), Vertex(v101, t4), Vertex(v001, tb)));
|
|
}
|
|
}
|
|
- if(top) {
|
|
+ if(isAir(x, y + 1, z)) {
|
|
Vector2 tt(0.3125f, 0.0f);
|
|
Vector2 tt(0.3125f, 0.0f);
|
|
- mesh.add(Triangle(Vertex(v010, t2), Vertex(v011, t3), Vertex(v110, tt)));
|
|
+ buffer.add(Triangle(Vertex(v010, t2), Vertex(v011, t3), Vertex(v110, tt)));
|
|
- mesh.add(Triangle(Vertex(v110, tt), Vertex(v011, t3), Vertex(v111, Vector2(0.3125f, 0.0625f))));
|
|
+ buffer.add(Triangle(Vertex(v110, tt), Vertex(v011, t3), Vertex(v111, Vector2(0.3125f, 0.0625f))));
|
|
}
|
|
}
|
|
- if(left) {
|
|
+ if(isAir(x - 1, y, z)) {
|
|
- mesh.add(Triangle(Vertex(v000, t4), Vertex(v001, t3), Vertex(v010, t1)));
|
|
+ buffer.add(Triangle(Vertex(v000, t4), Vertex(v001, t3), Vertex(v010, t1)));
|
|
- mesh.add(Triangle(Vertex(v001, t3), Vertex(v011, t2), Vertex(v010, t1)));
|
|
+ buffer.add(Triangle(Vertex(v001, t3), Vertex(v011, t2), Vertex(v010, t1)));
|
|
}
|
|
}
|
|
- if(right) {
|
|
+ if(isAir(x + 1, y, z)) {
|
|
- mesh.add(Triangle(Vertex(v100, t3), Vertex(v110, t2), Vertex(v101, t4)));
|
|
+ buffer.add(Triangle(Vertex(v100, t3), Vertex(v110, t2), Vertex(v101, t4)));
|
|
- mesh.add(Triangle(Vertex(v101, t4), Vertex(v110, t2), Vertex(v111, t1)));
|
|
+ buffer.add(Triangle(Vertex(v101, t4), Vertex(v110, t2), Vertex(v111, t1)));
|
|
}
|
|
}
|
|
- if(front) {
|
|
+ if(isAir(x, y, z + 1)) {
|
|
- mesh.add(Triangle(Vertex(v001, t4), Vertex(v101, t3), Vertex(v011, t1)));
|
|
+ buffer.add(Triangle(Vertex(v001, t4), Vertex(v101, t3), Vertex(v011, t1)));
|
|
- mesh.add(Triangle(Vertex(v111, t2), Vertex(v011, t1), Vertex(v101, t3)));
|
|
+ buffer.add(Triangle(Vertex(v111, t2), Vertex(v011, t1), Vertex(v101, t3)));
|
|
}
|
|
}
|
|
- if(back) {
|
|
+ if(isAir(x, y, z - 1)) {
|
|
- mesh.add(Triangle(Vertex(v000, t3), Vertex(v010, t2), Vertex(v100, t4)));
|
|
+ buffer.add(Triangle(Vertex(v000, t3), Vertex(v010, t2), Vertex(v100, t4)));
|
|
-
|
|
+ buffer.add(Triangle(Vertex(v110, t1), Vertex(v100, t4), Vertex(v010, t2)));
|
|
- mesh.add(Triangle(Vertex(v110, t1), Vertex(v100, t4), Vertex(v010, t2)));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|