summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-07 16:05:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-07 16:05:34 +0200
commit38440873ac8bf0862de7ba225657df09c5aee9e4 (patch)
tree45d06046aedac4111610a40c6f020f2f7feceef6 /src
parent2caeb3de2a3b6c79d6c3bce6898eaee07249836f (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/floor-mesh.cpp16
-rw-r--r--src/tile.hpp7
2 files changed, 18 insertions, 5 deletions
diff --git a/src/floor-mesh.cpp b/src/floor-mesh.cpp
index 7156661e..ce0a3d19 100644
--- a/src/floor-mesh.cpp
+++ b/src/floor-mesh.cpp
@@ -19,11 +19,15 @@ floor_mesh::floor_mesh()
void floor_mesh::set_tile(quad_data& data, tile& x)
{
- CORRADE_INTERNAL_ASSERT(x.ground_image);
-
- auto texcoords = x.ground_image.atlas->texcoords_for_id(x.ground_image.variant);
- for (size_t i = 0; i < 4; i++)
- data[i] = { texcoords[i] };
+ if (x.ground_image)
+ {
+ auto texcoords = x.ground_image.atlas->texcoords_for_id(x.ground_image.variant);
+ for (size_t i = 0; i < 4; i++)
+ data[i] = { texcoords[i] };
+ }
+ else
+ for (size_t i = 0; i < 4; i++)
+ data[i] = {};
}
void floor_mesh::draw(tile_shader& shader, chunk& c)
@@ -37,6 +41,8 @@ void floor_mesh::draw(tile_shader& shader, chunk& c)
mesh.setCount(quad_index_count);
const tile_atlas* last_tile_atlas = nullptr;
c.foreach_tile([&](tile& x, std::size_t i, local_coords) {
+ if (!x.ground_image)
+ return;
mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*TILE_COUNT - 1);
if (auto* atlas = x.ground_image.atlas.get(); atlas != last_tile_atlas)
{
diff --git a/src/tile.hpp b/src/tile.hpp
index 169c941b..f559ce79 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -36,12 +36,19 @@ struct tile final
struct local_coords final {
std::uint8_t x = 0, y = 0;
+ explicit constexpr local_coords(std::size_t idx);
constexpr local_coords() = default;
constexpr local_coords(std::size_t x, std::size_t y);
constexpr local_coords(std::uint8_t x, std::uint8_t y) : x{x}, y{y} {}
constexpr std::size_t to_index() const { return y*TILE_MAX_DIM + x; }
};
+constexpr local_coords::local_coords(std::size_t index) :
+ x{(std::uint8_t)(index % TILE_MAX_DIM)},
+ y{(std::uint8_t)(index / TILE_MAX_DIM)}
+{
+}
+
constexpr local_coords::local_coords(std::size_t x, std::size_t y)
: x{(std::uint8_t)x}, y{(std::uint8_t)y}
{