diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-12-23 14:42:15 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-12-26 04:39:12 +0100 |
commit | 3370445a2e22ee00687ecef2e9dc88f47bb2b4c6 (patch) | |
tree | a99ec32a02fc91d729205fc26d7183b6b4214b28 | |
parent | c141a9efcfaecadffe771bd0c37bea0e46a3f9aa (diff) |
a
-rw-r--r-- | blender/.gitignore | 3 | ||||
-rw-r--r-- | blender/concrete-wall1/concrete1.tpl.json (renamed from blender/concrete-wall1/concrete-wall1.tpl.json) | 2 | ||||
-rw-r--r-- | compat/map.hpp | 40 | ||||
-rw-r--r-- | doc/.gitignore | 3 | ||||
-rw-r--r-- | doc/bad-corners.png | bin | 0 -> 51464 bytes | |||
-rw-r--r-- | doc/saves/quicksave - Copy (44).dat | bin | 0 -> 4137 bytes | |||
-rw-r--r-- | doc/saves/quicksave - Copy (45).dat | bin | 0 -> 4832 bytes | |||
-rw-r--r-- | editor/wall-editor.cpp | 4 | ||||
m--------- | external/sdl2 | 0 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 3 | ||||
-rw-r--r-- | shaders/lightmap.cpp | 4 | ||||
-rw-r--r-- | shaders/shader.hpp | 2 | ||||
-rw-r--r-- | src/anim-atlas.cpp | 16 | ||||
-rw-r--r-- | src/chunk-walls.cpp | 38 | ||||
-rw-r--r-- | src/chunk.cpp | 29 | ||||
-rw-r--r-- | src/chunk.hpp | 5 | ||||
-rw-r--r-- | src/tile-atlas.hpp | 2 | ||||
-rw-r--r-- | src/tile-defs.hpp | 2 | ||||
-rw-r--r-- | src/tile-image.hpp | 3 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 5 | ||||
-rw-r--r-- | src/wall-atlas.hpp | 3 | ||||
-rw-r--r-- | src/wall-defs.hpp | 2 | ||||
-rw-r--r-- | test/map.cpp | 37 | ||||
-rw-r--r-- | test/wall-atlas.cpp | 8 |
24 files changed, 141 insertions, 70 deletions
diff --git a/blender/.gitignore b/blender/.gitignore new file mode 100644 index 00000000..23032064 --- /dev/null +++ b/blender/.gitignore @@ -0,0 +1,3 @@ +*.blend[0-9] +*.blend[0-9][0-9] +*.blend[0-9][0-9][0-9] diff --git a/blender/concrete-wall1/concrete-wall1.tpl.json b/blender/concrete-wall1/concrete1.tpl.json index ae29a94e..079bbc98 100644 --- a/blender/concrete-wall1/concrete-wall1.tpl.json +++ b/blender/concrete-wall1/concrete1.tpl.json @@ -1,5 +1,5 @@ { - "name": "concrete-wall1", + "name": "concrete1", "depth": 20, "n": { "pass-mode": "blocked", diff --git a/compat/map.hpp b/compat/map.hpp new file mode 100644 index 00000000..def97d0e --- /dev/null +++ b/compat/map.hpp @@ -0,0 +1,40 @@ +#pragma once +#include "compat/integer-types.hpp" +#include <type_traits> +#include <array> +#include <concepts> +#include <Corrade/Utility/Macros.h> + +namespace floormat::detail::map { + +template<typename T, typename F, size_t N, size_t... Indexes> +CORRADE_ALWAYS_INLINE +constexpr auto map0(const std::array<T, N>& array, const F& fun, std::index_sequence<Indexes...>) +{ + return std::array { fun(array[Indexes])... }; +} + +template<typename T, typename F> +[[deprecated("zero-length array!")]] +CORRADE_ALWAYS_INLINE +constexpr auto map0(const std::array<T, 0>&, const F& fun, std::index_sequence<>) +{ + return std::array<std::decay_t<decltype( fun(std::declval<const T&>()) )> , 0>{}; +} + +} // namespace floormat::detail::map + +namespace floormat { + +template<typename T, std::invocable<const T&> F, size_t N> +constexpr auto map(const std::array<T, N>& array, const F& fun) +{ + using return_type = std::decay_t<decltype( fun(array[0]) )>; + static_assert(!std::is_same_v<return_type, void>); + static_assert(std::is_same_v<T, std::decay_t<T>>); + static_assert(sizeof(return_type) > 0); + using ::floormat::detail::map::map0; + return map0(array, fun, std::make_index_sequence<N>{}); +} + +} // namespace floormat diff --git a/doc/.gitignore b/doc/.gitignore index 84b61228..5aad3f84 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1 +1,4 @@ *.pdn +*.blend[0-9] +*.blend[0-9][0-9] +*.blend[0-9][0-9][0-9] diff --git a/doc/bad-corners.png b/doc/bad-corners.png Binary files differnew file mode 100644 index 00000000..af092488 --- /dev/null +++ b/doc/bad-corners.png diff --git a/doc/saves/quicksave - Copy (44).dat b/doc/saves/quicksave - Copy (44).dat Binary files differnew file mode 100644 index 00000000..a0fc36bd --- /dev/null +++ b/doc/saves/quicksave - Copy (44).dat diff --git a/doc/saves/quicksave - Copy (45).dat b/doc/saves/quicksave - Copy (45).dat Binary files differnew file mode 100644 index 00000000..e06b36c3 --- /dev/null +++ b/doc/saves/quicksave - Copy (45).dat diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp index d1bcd650..b2dce5fe 100644 --- a/editor/wall-editor.cpp +++ b/editor/wall-editor.cpp @@ -76,8 +76,8 @@ void wall_editor::place_tile(world& w, global_coords coords, const std::shared_p auto [c, t] = w[coords]; switch (_r) { - case rotation::N: t.wall_north() = { atlas, (uint8_t)-1 }; break; - case rotation::W: t.wall_west() = { atlas, (uint8_t)-1 }; break; + case rotation::N: t.wall_north() = { atlas, (variant_t)-1 }; break; + case rotation::W: t.wall_west() = { atlas, (variant_t)-1 }; break; default: std::unreachable(); } c.mark_walls_modified(); diff --git a/external/sdl2 b/external/sdl2 -Subproject 10c292b0550d98bf891416162b50e91c14928ef +Subproject e7c4575719ba104ee7173640f9f82e37b9446f9 diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index c7e9bb2b..a79c68d4 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -86,7 +86,8 @@ std::shared_ptr<class wall_atlas> loader_impl::wall_atlas(StringView name, bool fm_throw("no such wall atlas '{}'"_cf, name); else { - DBG_nospace << "wall_atlas '" << name << "'doesn't exist"; + if (name != "<invalid>"_s) + DBG_nospace << "wall_atlas '" << name << "' doesn't exist"; return make_invalid_wall_atlas().atlas; } } diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index fcb32619..f925cc98 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -135,7 +135,7 @@ void lightmap_shader::end_occlusion() } } -std::array<Vector3, 4>& lightmap_shader::alloc_rect() +quad& lightmap_shader::alloc_rect() { if (count == capacity) { @@ -192,7 +192,7 @@ lightmap_shader::lightmap_shader(texture_unit_cache& tuc) : tuc{tuc} framebuffer = make_framebuffer(Vector2i((int)real_image_size)); - auto blend_vertexes = std::array<Vector3, 4>{{ + auto blend_vertexes = quad {{ { 1, -1, 0 }, /* 3--1 1 */ { 1, 1, 0 }, /* | / /| */ { -1, -1, 0 }, /* |/ / | */ diff --git a/shaders/shader.hpp b/shaders/shader.hpp index dc87a2cc..5b46fcb2 100644 --- a/shaders/shader.hpp +++ b/shaders/shader.hpp @@ -44,7 +44,7 @@ struct tile_shader final : private GL::AbstractShaderProgram static constexpr float scenery_depth_offset = 1 + 2./64; static constexpr float ground_depth_offset = 0; static constexpr float wall_depth_offset = 1; - static constexpr float wall_overlay_depth_offset = 1 + 1./64; + static constexpr float wall_overlay_depth_offset = 1 + 1./64; // todo add this static constexpr float wall_side_offset = 1 - 4./64; static constexpr float z_depth_offset = 1 + 4./64; static constexpr float depth_tile_size = 1.f/(TILE_MAX_DIM * 2 * max_screen_tiles.product()); 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 }; diff --git a/test/map.cpp b/test/map.cpp new file mode 100644 index 00000000..62860b22 --- /dev/null +++ b/test/map.cpp @@ -0,0 +1,37 @@ +#ifdef __GNUG__ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +#include "compat/map.hpp" +#include "compat/assert.hpp" + +namespace floormat { + +namespace { + +constexpr bool test1() +{ + constexpr auto array = std::array{0, 1, 2, 3, 4}; + auto array2 = map(array, [](int x) constexpr { + return (unsigned)(x - 1); + }); + constexpr auto array3 = std::array{(unsigned)-1, 0u, 1u, 2u, 3u}; + fm_assert(array2.size() == array.size()); + fm_assert(array3.size() == array.size()); + for (auto i = 0uz; i < array.size(); i++) + fm_assert(array2[i] == array3[i]); + return true; +} + +constexpr bool test2() +{ + fm_assert(map(std::array<int, 0>{}, [](int x) constexpr { return x;}).size() == 0); + return true; +} + +static_assert(test1()); +static_assert(test2()); + +} // namespace + +} // namespace floormat diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp index d6b0f564..9258863c 100644 --- a/test/wall-atlas.cpp +++ b/test/wall-atlas.cpp @@ -85,17 +85,11 @@ void test_from_rotation(StringView filename) const auto& D_w = atlas.direction_array[DAI_w.val]; constexpr auto null = (uint8_t)-1; resolve_wall_rotations(atlas.direction_array, atlas.direction_map); - fm_assert(!D_n.corner_R.is_defined && D_n.corner_R.from_rotation == null); fm_assert(D_n.top.is_defined); fm_assert(D_n.top.from_rotation != null); fm_assert(D_n.top.from_rotation != null); fm_assert(D_w.top.from_rotation == null); fm_assert(D_w.top.is_defined); - fm_assert(D_n.corner_L.is_defined); - fm_assert(D_n.corner_L.from_rotation == null); - fm_assert(D_w.corner_L.is_defined); - fm_assert(D_w.corner_L.from_rotation == DAI_n.val); - fm_assert(atlas.direction_array[D_w.corner_L.from_rotation].corner_L.count == 11); fm_assert(atlas.direction_array[D_n.top.from_rotation].top.count == 12); } @@ -124,8 +118,6 @@ void test_expected_size() { fm_assert_equal(Vector2ui{64, 192}, wall_atlas::expected_size(42, Group_::wall)); fm_assert_equal(Vector2ui{42, 192}, wall_atlas::expected_size(42, Group_::side)); - fm_assert_equal(Vector2ui{32, 192}, wall_atlas::expected_size(42, Group_::corner_L)); - fm_assert_equal(Vector2ui{32, 192}, wall_atlas::expected_size(42, Group_::corner_R)); // swapped in atlas.json during reading and writing, rotated counter-clockwise in atlas image file fm_assert_equal(Vector2ui{42, 192}, wall_atlas::expected_size(42, Group_::top)); } |