diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 13:28:37 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 13:28:37 +0200 |
commit | 7f01dc47b0fd322d8c2b3f27eb1a94cd450a26a5 (patch) | |
tree | ac6201f9179a0315449ad46d742d2db325775eff /main/draw.cpp | |
parent | e65ebe30d3f2af77d57cb15e5e2b30efa454b6a8 (diff) |
a
Diffstat (limited to 'main/draw.cpp')
-rw-r--r-- | main/draw.cpp | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/main/draw.cpp b/main/draw.cpp index 91277c34..fde48915 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -25,7 +25,7 @@ void app::drawEvent() { } _shader.set_tint({1, 1, 1, 1}); - draw_chunk(_chunk); + draw_world(); draw_cursor_tile(); display_menu(); @@ -34,16 +34,17 @@ void app::drawEvent() { timeline.nextFrame(); } -void app::draw_chunk(chunk& c) +void app::draw_world() { + // TODO chunk offset + std::int16_t minx = 0, maxx = 0, miny = 0, maxy = 0; { - int minx = 0, maxx = 0, miny = 0, maxy = 0; - auto fn = [&](int x, int y) { - const auto pos = pixel_to_tile({(float)x, (float)y}) / Vector2{TILE_MAX_DIM, TILE_MAX_DIM}; - minx = std::min(minx, (int)std::floor(pos[0])); - maxx = std::max(maxx, (int)(pos[0])); - miny = std::min(miny, (int)std::floor(pos[1])); - maxy = std::max(maxy, (int)(pos[1])); + const auto fn = [&](int x, int y) { + const auto pos = pixel_to_tile({(float)x, (float)y}).chunk(); + minx = std::min(minx, pos.x); + maxx = std::max(maxx, pos.x); + miny = std::min(miny, pos.y); + maxy = std::max(maxy, pos.y); }; const auto sz = windowSize(); const auto x = sz[0], y = sz[1]; @@ -51,22 +52,49 @@ void app::draw_chunk(chunk& c) fn(x, 0); fn(0, y); fn(x, y); - - // TODO - printf(""); // put breakpoint here } + const auto old_camera_offset = _shader.camera_offset(); _shader.set_tint({1, 1, 1, 1}); - _floor_mesh.draw(_shader, c); - _wall_mesh.draw(_shader, c); + + for (std::int16_t y = miny; y <= maxy; y++) + for (std::int16_t x = minx; x <= maxx; x++) + { + const auto offset = project({float(x)*TILE_MAX_DIM*TILE_SIZE[0], + float(y)*TILE_MAX_DIM*TILE_SIZE[1], + 0}); + _shader.set_camera_offset(offset + old_camera_offset); + auto c = _world[chunk_coords{x, y}]; + _floor_mesh.draw(_shader, *c); + } + + for (std::int16_t y = miny; y <= maxy; y++) + for (std::int16_t x = minx; x <= maxx; x++) + { + const auto offset = project({float(x)*TILE_MAX_DIM*TILE_SIZE[0], + float(y)*TILE_MAX_DIM*TILE_SIZE[1], + 0}); + _shader.set_camera_offset(offset + old_camera_offset); + auto c = _world[chunk_coords{x, y}]; + _wall_mesh.draw(_shader, *c); + } + + _shader.set_camera_offset(old_camera_offset); } -void app::draw_wireframe_quad(local_coords pt) +void app::draw_wireframe_quad(global_coords pos) { constexpr float LINE_WIDTH = 1; + { + const auto c = _world[pos.chunk()]; + if (const auto& tile = (*c)[pos.local()]; !tile.ground_image) + return; + } + + const auto pt = pos.to_signed(); constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1]; - const Vector3 center {X*pt.x, Y*pt.y, 0}; + const Vector3 center {X*pt[0], Y*pt[1], 0}; _shader.set_tint({1, 0, 0, 1}); _wireframe_quad.draw(_shader, {center, {TILE_SIZE[0], TILE_SIZE[1]}, LINE_WIDTH}); } @@ -83,22 +111,3 @@ void app::draw_wireframe_box(local_coords pt) } } // namespace floormat - -MAGNUM_APPLICATION_MAIN(floormat::app) - -#ifdef _MSC_VER -#include <cstdlib> // for __arg{c,v} -#ifdef __clang__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wmain" -#endif -extern "C" int __stdcall WinMain(void*, void*, void*, int); - -extern "C" int __stdcall WinMain(void*, void*, void*, int) -{ - return main(__argc, __argv); -} -#ifdef __clang__ -# pragma clang diagnostic pop -#endif -#endif |