summary refs log tree commit diff
path: root/src/World/Generation/ChunkMeshing.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-08 03:25:44 +0200
committerMel <einebeere@gmail.com>2023-07-08 03:25:44 +0200
commitfe2baedc760c2f29e2c720f6b1132a2de33c5430 (patch)
treedfbe1c72a17805a3cab6e0d47433e9021890c9ca /src/World/Generation/ChunkMeshing.cpp
parent41fbca10f6c6cdd9c1623f1347e7ecb40f5e7f59 (diff)
downloadmeowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.tar.zst
meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.zip
Use own size types
Diffstat (limited to 'src/World/Generation/ChunkMeshing.cpp')
-rw-r--r--src/World/Generation/ChunkMeshing.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/World/Generation/ChunkMeshing.cpp b/src/World/Generation/ChunkMeshing.cpp
index e065987..8996169 100644
--- a/src/World/Generation/ChunkMeshing.cpp
+++ b/src/World/Generation/ChunkMeshing.cpp
@@ -2,20 +2,20 @@
 
 namespace MC::World::Generation {
 
-std::array<Vector<2>, 4> face_tex_coords(BlockType type, BlockSide side) {
-    uint8_t atlas_width = 4;
-    uint8_t atlas_height = 4;
+std::array<Vector<2, F32>, 4> face_tex_coords(BlockType type, BlockSide side) {
+    U8 atlas_width = 4;
+    U8 atlas_height = 4;
 
-    float width_step = 1.0f / atlas_width;
-    float height_step = 1.0f / atlas_height;
+    Real width_step = 1.0f / atlas_width;
+    Real height_step = 1.0f / atlas_height;
 
-    auto block_coords = [=](uint8_t x, uint8_t y) {
+    auto block_coords = [=](U8 x, U8 y) {
         auto t = y * height_step;
         auto l = x * width_step;
         auto b = t + height_step;
         auto r = l + width_step;
 
-        return std::array<Vector<2>, 4>{{
+        return std::array<Vector<2, F32>, 4>{{
             {l, b}, {r, b}, {r, t}, {l, t},
         }};
     };
@@ -71,10 +71,10 @@ std::array<Vector<2>, 4> face_tex_coords(BlockType type, BlockSide side) {
     }
 }
 
-std::array<Vector<3>, 4> face_normals(BlockSide side) {
-    auto is_side = [=](BlockSide s) -> float { return s == side; };
+std::array<Vector<3, F32>, 4> face_normals(BlockSide side) {
+    auto is_side = [=](BlockSide s) -> Real { return s == side; };
 
-    Vector<3> normal = {
+    Vector<3, F32> normal = {
         is_side(BlockSide::Right) - is_side(BlockSide::Left),
         is_side(BlockSide::Top) - is_side(BlockSide::Bottom),
         is_side(BlockSide::Front) - is_side(BlockSide::Back),
@@ -83,8 +83,8 @@ std::array<Vector<3>, 4> face_normals(BlockSide side) {
     return {normal, normal, normal, normal};
 }
 
-bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors, uint32_t x, uint32_t y, uint32_t z, BlockSide side) {
-    Vector<3, int32_t> offset{};
+Bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side) {
+    Vector<3, I32> offset{};
     switch (side) {
         case BlockSide::Front:
             offset[2] = 1;
@@ -106,8 +106,8 @@ bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors
             break;
     }
 
-    Vector<3, int32_t> neighbor_pos{
-        (int32_t)x + offset.x(), (int32_t)y + offset.y(), (int32_t)z + offset.z(),
+    Vector<3, I32> neighbor_pos{
+        (I32)x + offset.x(), (I32)y + offset.y(), (I32)z + offset.z(),
     };
 
     Chunk* chunk_to_ask;
@@ -115,10 +115,10 @@ bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors
     if (neighbor_pos.z() < 0) {
         chunk_to_ask = &neighbors.north;
         neighbor_pos.z() += Chunk::Width;
-    } else if (neighbor_pos.x() >= (int32_t)Chunk::Width) {
+    } else if (neighbor_pos.x() >= (I32)Chunk::Width) {
         chunk_to_ask = &neighbors.east;
         neighbor_pos.x() -= Chunk::Width;
-    } else if (neighbor_pos.z() >= (int32_t)Chunk::Width) {
+    } else if (neighbor_pos.z() >= (I32)Chunk::Width) {
         chunk_to_ask = &neighbors.south;
         neighbor_pos.z() -= Chunk::Width;
     } else if (neighbor_pos.x() < 0) {
@@ -133,14 +133,14 @@ bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors
 }
 
 GFX::Mesh ChunkMeshing::create_mesh_for_chunk(Chunk& chunk, const ChunkNeighbors& neighbors) {
-    std::vector<Vector<3>> positions{};
-    std::vector<Vector<3>> normals{};
-    std::vector<Vector<2>> tex_coords{};
-    std::vector<uint32_t> indices{};
-
-    for (int x = 0; x < Chunk::Width; x++) {
-        for (int y = 0; y < Chunk::Height; y++) {
-            for (int z = 0; z < Chunk::Width; z++) {
+    std::vector<Vector<3, F32>> positions{};
+    std::vector<Vector<3, F32>> normals{};
+    std::vector<Vector<2, F32>> tex_coords{};
+    std::vector<U32> indices{};
+
+    for (Int x = 0; x < Chunk::Width; x++) {
+        for (Int y = 0; y < Chunk::Height; y++) {
+            for (Int z = 0; z < Chunk::Width; z++) {
                 auto type = chunk.get(x, y, z).type;
                 if (type == BlockType::Air) {
                     continue;
@@ -156,10 +156,10 @@ GFX::Mesh ChunkMeshing::create_mesh_for_chunk(Chunk& chunk, const ChunkNeighbors
                     auto side_tex_coords = face_tex_coords(type, side);
 
                     for (auto& position : side_positions) {
-                        position = position + Vector<3>{static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)};
+                        position = position + Vector<3, F32>{x, y, z};
                     }
 
-                    uint32_t s = positions.size();
+                    U32 s = positions.size();
 
                     positions.insert(positions.end(), side_positions.begin(), side_positions.end());
                     normals.insert(normals.end(), side_normals.begin(), side_normals.end());
@@ -170,7 +170,7 @@ GFX::Mesh ChunkMeshing::create_mesh_for_chunk(Chunk& chunk, const ChunkNeighbors
         }
     }
 
-    return GFX::Mesh{
+    return {
         {positions, normals, tex_coords},
         indices,
     };