summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-12-23 14:42:15 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-12-26 04:39:12 +0100
commit3370445a2e22ee00687ecef2e9dc88f47bb2b4c6 (patch)
treea99ec32a02fc91d729205fc26d7183b6b4214b28 /src
parentc141a9efcfaecadffe771bd0c37bea0e46a3f9aa (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/anim-atlas.cpp16
-rw-r--r--src/chunk-walls.cpp38
-rw-r--r--src/chunk.cpp29
-rw-r--r--src/chunk.hpp5
-rw-r--r--src/tile-atlas.hpp2
-rw-r--r--src/tile-defs.hpp2
-rw-r--r--src/tile-image.hpp3
-rw-r--r--src/wall-atlas.cpp5
-rw-r--r--src/wall-atlas.hpp3
-rw-r--r--src/wall-defs.hpp2
10 files changed, 50 insertions, 55 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp
index 129229c5..c6a7c2f2 100644
--- a/src/anim-atlas.cpp
+++ b/src/anim-atlas.cpp
@@ -97,17 +97,17 @@ auto anim_atlas::texcoords_for_frame(rotation r, size_t i, bool mirror) const no
const auto size = _info.pixel_size;
if (!mirror)
return {{
- { (x0+x1) / size[0], 1 - (y0+y1) / size[1] }, // bottom right
- { (x0+x1) / size[0], 1 - y0 / size[1] }, // top right
- { x0 / size[0], 1 - (y0+y1) / size[1] }, // bottom left
- { x0 / size[0], 1 - y0 / size[1] }, // top left
+ { (x0+x1) / size.x(), 1 - (y0+y1) / size.y() }, // bottom right
+ { (x0+x1) / size.x(), 1 - y0 / size.y() }, // top right
+ { x0 / size.x(), 1 - (y0+y1) / size.y() }, // bottom left
+ { x0 / size.x(), 1 - y0 / size.y() }, // top left
}};
else
return {{
- { x0 / size[0], 1 - (y0+y1) / size[1] }, // bottom right
- { x0 / size[0], 1 - y0 / size[1] }, // top right
- { (x0+x1) / size[0], 1 - (y0+y1) / size[1] }, // bottom left
- { (x0+x1) / size[0], 1 - y0 / size[1] }, // top left
+ { x0 / size.x(), 1 - (y0+y1) / size.y() }, // bottom right
+ { x0 / size.x(), 1 - y0 / size.y() }, // top right
+ { (x0+x1) / size.x(), 1 - (y0+y1) / size.y() }, // bottom left
+ { (x0+x1) / size.x(), 1 - y0 / size.y() }, // top left
}};
}
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp
index 378b75af..0532193a 100644
--- a/src/chunk-walls.cpp
+++ b/src/chunk-walls.cpp
@@ -62,24 +62,6 @@ constexpr Quads::quad get_quad(Direction_ D, Group_ G, float depth)
{-X, Y, Z },
{-X, Y, 0 },
}};
- case corner_L: {
- constexpr float x_offset = (float)(unsigned)X;
- return {{
- { -X + x_offset, -Y, Z },
- { -X + x_offset, -Y, 0 },
- { -X, -Y, Z },
- { -X, -Y, 0 },
- }};
- }
- case corner_R: {
- constexpr float y_offset = TILE_SIZE.y() - (float)(unsigned)Y;
- return {{
- {-X, -Y, Z },
- {-X, -Y, 0 },
- {-X, -Y + y_offset, Z },
- {-X, -Y + y_offset, 0 },
- }};
- }
case side:
if (!is_west)
{
@@ -149,9 +131,9 @@ constexpr auto depth_offset_for_group(Group_ G)
return tile_shader::wall_depth_offset;
case Wall::Group_::side:
return tile_shader::wall_side_offset;
- case Wall::Group_::corner_L:
- case Wall::Group_::corner_R:
- return tile_shader::wall_overlay_depth_offset;
+ // // todo
+ // case corner:
+ // return tile_shader::wall_overlay_depth_offset
}
}
@@ -180,20 +162,6 @@ GL::Mesh chunk::make_wall_mesh()
{
CORRADE_ASSUME(G < Group_::COUNT);
- switch (G)
- {
- case Wall::Group_::corner_L:
- if (D != Direction_::N || !_walls->atlases[k+1])
- continue;
- break;
- case Wall::Group_::corner_R:
- if (D != Direction_::W || !_walls->atlases[k-1])
- continue;
- break;
- default:
- break;
- }
-
const auto& group = dir.*member;
if (!group.is_defined)
continue;
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 17fe1b49..652bd63d 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -1,5 +1,6 @@
#include "chunk.hpp"
#include "object.hpp"
+#include "world.hpp"
#include "tile-iterator.hpp"
#include <algorithm>
#include <Magnum/GL/Context.h>
@@ -42,6 +43,34 @@ tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile
tile_ref chunk::operator[](local_coords xy) noexcept { return operator[](xy.to_index()); }
tile_proto chunk::operator[](local_coords xy) const noexcept { return operator[](xy.to_index()); }
+tile_ref chunk::at_offset(local_coords pos, Vector2i off)
+{
+ const auto coord = global_coords{_coord, pos};
+ const auto coord2 = coord + off;
+ if (coord.chunk() == coord2.chunk()) [[likely]]
+ return operator[](coord2.local());
+ else
+ return (*_world)[coord2].t;
+}
+
+Optional<tile_ref> chunk::at_offset_(local_coords pos, Vector2i off)
+{
+ const auto coord = global_coords{_coord, pos};
+ const auto coord2 = coord + off;
+ if (coord.chunk() == coord2.chunk()) [[likely]]
+ return operator[](coord2.local());
+ else
+ {
+ if (auto* ch = _world->at({coord2}))
+ return (*ch)[coord2.local()];
+ else
+ return NullOpt;
+ }
+}
+
+tile_ref chunk::at_offset(tile_ref r, Vector2i off) { return at_offset(local_coords{r.index()}, off); }
+Optional<tile_ref> chunk::at_offset_(tile_ref r, Vector2i off) { return at_offset_(local_coords{r.index()}, off); }
+
auto chunk::begin() noexcept -> iterator { return iterator { *this, 0 }; }
auto chunk::end() noexcept -> iterator { return iterator { *this, TILE_COUNT }; }
auto chunk::cbegin() const noexcept -> const_iterator { return const_iterator { *this, 0 }; }
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 2331bef8..89892d90 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -44,6 +44,11 @@ struct chunk final
tile_ref operator[](local_coords xy) noexcept;
tile_proto operator[](local_coords xy) const noexcept;
+ tile_ref at_offset(local_coords pos, Vector2i off);
+ tile_ref at_offset(tile_ref r, Vector2i off);
+ Optional<tile_ref> at_offset_(local_coords pos, Vector2i off);
+ Optional<tile_ref> at_offset_(tile_ref r, Vector2i off);
+
using iterator = tile_iterator;
using const_iterator = tile_const_iterator;
diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp
index 4f837cf1..a4334b1a 100644
--- a/src/tile-atlas.hpp
+++ b/src/tile-atlas.hpp
@@ -13,7 +13,7 @@ namespace floormat {
class tile_atlas final
{
- using quad = std::array<Vector3, 4>;
+ using quad = Quads::quad;
using texcoords = std::array<Vector2, 4>;
static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count);
diff --git a/src/tile-defs.hpp b/src/tile-defs.hpp
index 2736cd08..46e72984 100644
--- a/src/tile-defs.hpp
+++ b/src/tile-defs.hpp
@@ -4,6 +4,8 @@
namespace floormat {
+using variant_t = uint8_t;
+
constexpr inline uint32_t TILE_MAX_DIM = 16;
constexpr inline size_t TILE_COUNT = size_t{TILE_MAX_DIM}*size_t{TILE_MAX_DIM};
diff --git a/src/tile-image.hpp b/src/tile-image.hpp
index 50cf0a33..facf9945 100644
--- a/src/tile-image.hpp
+++ b/src/tile-image.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "tile-defs.hpp"
#include <memory>
namespace floormat {
@@ -6,8 +7,6 @@ namespace floormat {
class tile_atlas;
class wall_atlas;
-using variant_t = uint8_t;
-
template<typename Atlas>
struct image_proto_
{
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index b56a845b..fa6e99a6 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -81,7 +81,6 @@ wall_atlas::~wall_atlas() noexcept = default;
Vector2ui wall_atlas::expected_size(unsigned depth, Group_ group)
{
constexpr auto size = Vector3ui{iTILE_SIZE};
- constexpr auto half_tile = size.x()/2u;
static_assert(size.x() == size.y());
fm_assert(depth > 0 && depth < 1<<15);
@@ -95,10 +94,6 @@ Vector2ui wall_atlas::expected_size(unsigned depth, Group_ group)
case top:
case side:
return { depth, size.z() };
- case corner_L:
- return { half_tile, size.z() };
- case corner_R:
- return { size.x() - half_tile, size.z() };
default:
std::unreachable();
fm_assert(false);
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index 1f18489a..e9421653 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -47,7 +47,6 @@ struct Direction
struct member_tuple { StringView name; memfn_ptr member; Group_ tag; };
Group wall{}, side{}, top{};
- Group corner_L{}, corner_R{};
const Group& group(Group_ i) const;
const Group& group(size_t i) const;
@@ -58,8 +57,6 @@ struct Direction
{ "wall"_s, &Direction::wall, Group_::wall },
{ "side"_s, &Direction::side, Group_::side },
{ "top"_s, &Direction::top, Group_::top },
- { "corner-L"_s, &Direction::corner_L, Group_::corner_L, },
- { "corner-R"_s, &Direction::corner_R, Group_::corner_R, },
};
static_assert(std::size(groups) == (size_t)Group_::COUNT);
diff --git a/src/wall-defs.hpp b/src/wall-defs.hpp
index 0f33ae4c..ea36605b 100644
--- a/src/wall-defs.hpp
+++ b/src/wall-defs.hpp
@@ -3,7 +3,7 @@
namespace floormat::Wall {
-enum class Group_ : uint8_t { wall, side, top, corner_L, corner_R, COUNT };
+enum class Group_ : uint8_t { wall, side, top, COUNT };
enum class Direction_ : uint8_t { N, W, COUNT };