summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-09 20:40:31 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-09 20:40:31 +0100
commit0ec88d181a5a5c3c3e791426b7fa01d44195ec8c (patch)
tree0c72a6fed79d5a4bb2e9d610cf03079cc342fae2
parent9482f370e56397d50e5d7efef81a33af7390d07a (diff)
add forgotten animation drawing
-rw-r--r--draw/anim.cpp28
-rw-r--r--draw/anim.hpp8
-rw-r--r--main/draw.cpp20
-rw-r--r--main/main-impl.hpp2
4 files changed, 44 insertions, 14 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index a096711c..aa5ee1f6 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -1,8 +1,8 @@
#include "anim.hpp"
#include "anim-atlas.hpp"
+#include "chunk.hpp"
#include "shaders/tile.hpp"
-#include "wireframe.hpp"
-#include "quad-floor.hpp"
+#include <Magnum/GL/Texture.h>
namespace floormat {
@@ -22,7 +22,28 @@ std::array<UnsignedShort, 6> anim_mesh::make_index_array()
}};
}
-void anim_mesh::draw(tile_shader& shader, const anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy)
+void anim_mesh::draw(tile_shader& shader, chunk& c)
+{
+ for (std::size_t i = 0; i < TILE_COUNT; i++)
+ {
+ const local_coords pos{i};
+ if (auto [atlas, s] = c[pos].scenery(); atlas)
+ {
+ draw(shader, *atlas, s.r, s.frame, pos);
+#if 1
+ // todo debugging
+ static std::size_t N = 0;
+ N++;
+ auto nframes = atlas->info().nframes;
+ if (N > nframes*3)
+ N = 0;
+ s.frame = (scenery::frame_t)std::min(N, nframes-1);
+#endif
+ }
+ }
+}
+
+void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy)
{
const auto center = Vector3(xy.x, xy.y, 0.f) * TILE_SIZE;
const auto pos = atlas.frame_quad(center, r, frame);
@@ -32,6 +53,7 @@ void anim_mesh::draw(tile_shader& shader, const anim_atlas& atlas, rotation r, s
for (std::size_t i = 0; i < 4; i++)
array[i] = { pos[i], texcoords[i], depth };
_vertex_buffer.setSubData(0, array);
+ atlas.texture().bind(0);
shader.draw(_mesh);
}
diff --git a/draw/anim.hpp b/draw/anim.hpp
index 163c5b1a..324d8c3b 100644
--- a/draw/anim.hpp
+++ b/draw/anim.hpp
@@ -10,18 +10,20 @@
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Buffer.h>
-namespace floormat::Serialize { struct anim_frame; }
+//namespace floormat::Serialize { struct anim_frame; }
namespace floormat {
struct tile_shader;
struct anim_atlas;
-using anim_frame = Serialize::anim_frame;
+struct chunk;
+//using anim_frame = Serialize::anim_frame;
struct anim_mesh final
{
anim_mesh();
- void draw(tile_shader& shader, const anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy);
+ void draw(tile_shader& shader, chunk& c);
+ void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy);
private:
struct vertex_data final {
diff --git a/main/draw.cpp b/main/draw.cpp
index 2b17ce9b..86d93582 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -86,12 +86,12 @@ void main_impl::draw_world() noexcept
for (std::int16_t y = miny; y <= maxy; y++)
for (std::int16_t x = minx; x <= maxx; x++)
{
- if (const chunk_coords c = {x, y}; !_world.contains(c))
- app.maybe_initialize_chunk(c, _world[c]);
- const chunk_coords c{x, y};
- const with_shifted_camera_offset o{_shader, c};
+ const chunk_coords pos{x, y};
+ if (!_world.contains(pos))
+ app.maybe_initialize_chunk(pos, _world[pos]);
+ const with_shifted_camera_offset o{_shader, pos};
if (check_chunk_visible(_shader.camera_offset(), sz))
- _floor_mesh.draw(_shader, _world[c]);
+ _floor_mesh.draw(_shader, _world[pos]);
}
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
@@ -104,10 +104,14 @@ void main_impl::draw_world() noexcept
for (std::int16_t y = miny; y <= maxy; y++)
for (std::int16_t x = minx; x <= maxx; x++)
{
- const chunk_coords c{x, y};
- const with_shifted_camera_offset o{_shader, c};
+ const chunk_coords pos{x, y};
+ auto& c = _world[pos];
+ const with_shifted_camera_offset o{_shader, pos};
if (check_chunk_visible(_shader.camera_offset(), sz))
- _wall_mesh.draw(_shader, _world[c]);
+ {
+ _wall_mesh.draw(_shader, c);
+ _anim_mesh.draw(_shader, c);
+ }
}
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
}
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index e62ce261..9efdd2ae 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -4,6 +4,7 @@
#include "src/world.hpp"
#include "draw/floor.hpp"
#include "draw/wall.hpp"
+#include "draw/anim.hpp"
#include "shaders/tile.hpp"
#include <Corrade/Containers/String.h>
@@ -67,6 +68,7 @@ private:
struct world _world{};
floor_mesh _floor_mesh;
wall_mesh _wall_mesh;
+ anim_mesh _anim_mesh;
Magnum::Timeline timeline;
struct {
float value = 0;