summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-12-02 14:44:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-12-02 14:46:59 +0100
commit889d2c0c0933cf2fd9e068b1d2b79eb936b29b58 (patch)
treecfc5f5b6e417c28482734645a69e0d49388fa5b3 /src
parent8dbf450e34121358992e48212ae22cb7f5fc92f9 (diff)
src, serialize: work on pass mode
1. add one more value to the enum 2. serialize it properly in binary 3. serialize it as string in json
Diffstat (limited to 'src')
-rw-r--r--src/pass-mode.hpp10
-rw-r--r--src/scenery.cpp17
-rw-r--r--src/scenery.hpp6
-rw-r--r--src/tile.cpp11
-rw-r--r--src/tile.hpp10
5 files changed, 34 insertions, 20 deletions
diff --git a/src/pass-mode.hpp b/src/pass-mode.hpp
new file mode 100644
index 00000000..a60a8188
--- /dev/null
+++ b/src/pass-mode.hpp
@@ -0,0 +1,10 @@
+#pragma once
+#include <cstdint>
+
+namespace floormat {
+
+enum class pass_mode : std::uint8_t { shoot_through, pass, blocked, see_through };
+constexpr inline std::uint8_t pass_mode_COUNT = std::uint8_t(pass_mode::see_through) + 1;
+static_assert(pass_mode_COUNT == 4);
+
+} // namespace floormat
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 4056f49f..28884ad8 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -29,11 +29,11 @@ scenery_ref::operator scenery_proto() const noexcept { return { atlas, frame };
scenery_ref::operator bool() const noexcept { return atlas != nullptr; }
scenery::scenery() noexcept : scenery{none_tag_t{}} {}
-scenery::scenery(none_tag_t) noexcept : passable{true} {}
+scenery::scenery(none_tag_t) noexcept {}
scenery::scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame,
- bool passable, bool blocks_view, bool active, bool interactive) :
+ pass_mode pass, bool active, bool interactive) :
frame{frame}, r{r}, type{scenery_type::generic},
- passable{passable}, blocks_view{blocks_view}, active{active},
+ passability{pass}, active{active},
interactive{interactive}
{
fm_assert(r < rotation_COUNT);
@@ -43,7 +43,8 @@ scenery::scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t fra
scenery::scenery(door_tag_t, const anim_atlas& atlas, rotation r, bool is_open) :
frame{frame_t(is_open ? 0 : atlas.group(r).frames.size()-1)},
r{r}, type{scenery_type::door},
- passable{is_open}, blocks_view{!is_open}, interactive{true}
+ passability{is_open ? pass_mode::pass : pass_mode::blocked},
+ interactive{true}
{
fm_assert(r < rotation_COUNT);
fm_assert(atlas.group(r).frames.size() >= 2);
@@ -78,8 +79,12 @@ void scenery::update(float dt, const anim_atlas& anim)
const std::int8_t dir = closing ? 1 : -1;
const int fr = frame + dir*n;
active = fr > 0 && fr < nframes-1;
- passable = fr <= 0;
- blocks_view = !passable;
+ if (fr <= 0)
+ passability = pass_mode::pass;
+ else if (fr >= nframes-1)
+ passability = pass_mode::blocked;
+ else
+ passability = pass_mode::see_through;
frame = (frame_t)std::clamp(fr, 0, nframes-1);
if (!active)
delta = closing = 0;
diff --git a/src/scenery.hpp b/src/scenery.hpp
index 4ed55d20..b94e1d2a 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "pass-mode.hpp"
#include <cstdint>
#include <memory>
#include <type_traits>
@@ -35,8 +36,7 @@ struct scenery final
frame_t frame = 0;
rotation r : 3 = rotation::N;
scenery_type type : 3 = scenery_type::none;
- std::uint8_t passable : 1 = false;
- std::uint8_t blocks_view : 1 = false; // todo
+ pass_mode passability : 2 = pass_mode{0};
std::uint8_t active : 1 = false;
std::uint8_t closing : 1 = false;
std::uint8_t interactive : 1 = false;
@@ -44,7 +44,7 @@ struct scenery final
scenery() noexcept;
scenery(none_tag_t) noexcept;
scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame = 0,
- bool passable = false, bool blocks_view = false, bool active = false, bool interactive = false);
+ pass_mode passability = pass_mode::shoot_through, bool active = false, bool interactive = false);
scenery(door_tag_t, const anim_atlas& atlas, rotation r, bool is_open = false);
bool operator==(const scenery&) const noexcept;
diff --git a/src/tile.cpp b/src/tile.cpp
index b9ed5ab6..419e59a3 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -7,8 +7,9 @@ pass_mode_ref::pass_mode_ref(chunk& c, std::uint8_t i) noexcept : _chunk{&c}, i{
{
}
-pass_mode_ref& pass_mode_ref::operator=(pass_mode x) noexcept
+pass_mode_ref& pass_mode_ref::operator=(pass_mode val) noexcept
{
+ auto x = std::underlying_type_t<pass_mode>(val) & pass_mode_COUNT;
auto& bitset = _chunk->_passability;
bitset[i*2 + 0] = x & 1;
bitset[i*2 + 1] = x >> 1 & 1;
@@ -63,15 +64,15 @@ tile_image_proto tile_ref::wall_north() const noexcept { return { _chunk->_wall_
tile_image_proto tile_ref::wall_west() const noexcept { return { _chunk->_wall_atlases[i*2+1], _chunk->_wall_variants[i*2+1] }; }
scenery_proto tile_ref::scenery() const noexcept { return { _chunk->_scenery_atlases[i], _chunk->_scenery_variants[i] }; }
-pass_mode_ref tile_ref::pass_mode() noexcept { return { *_chunk, i }; }
-pass_mode tile_ref::pass_mode() const noexcept { return pass_mode_ref { *const_cast<struct chunk*>(_chunk), i }; }
+pass_mode_ref tile_ref::passability() noexcept { return { *_chunk, i }; }
+pass_mode tile_ref::passability() const noexcept { return pass_mode_ref { *const_cast<struct chunk*>(_chunk), i }; }
tile_ref::operator tile_proto() const noexcept
{
return {
_chunk->_ground_atlases[i], _chunk->_wall_atlases[i*2+0], _chunk->_wall_atlases[i*2+1], _chunk->_scenery_atlases[i],
_chunk->_ground_variants[i], _chunk->_wall_variants[i*2+0], _chunk->_wall_variants[i*2+1], _chunk->_scenery_variants[i],
- pass_mode(),
+ passability(),
};
}
@@ -84,7 +85,7 @@ bool operator==(const tile_ref& a, const tile_ref& b) noexcept
a.wall_north() == b.wall_north() &&
a.wall_west() == b.wall_west() &&
a.scenery() == b.scenery() &&
- a.pass_mode() == b.pass_mode();
+ a.passability() == b.passability();
}
} // namespace floormat
diff --git a/src/tile.hpp b/src/tile.hpp
index 387f7ff0..543b70b6 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -1,15 +1,13 @@
#pragma once
#include "tile-image.hpp"
#include "scenery.hpp"
+#include "pass-mode.hpp"
namespace floormat {
struct chunk;
struct anim_atlas;
-// zero is the default, see bitset in chunk.hpp
-enum pass_mode : unsigned char { pass_shoot_through, pass_ok, pass_blocked, };
-
struct pass_mode_ref final
{
pass_mode_ref(chunk& c, std::uint8_t i) noexcept;
@@ -28,7 +26,7 @@ struct tile_proto final
std::shared_ptr<anim_atlas> scenery_atlas;
variant_t ground_variant = 0, wall_north_variant = 0, wall_west_variant = 0;
struct scenery scenery_frame;
- enum pass_mode pass_mode = pass_mode::pass_shoot_through;
+ pass_mode passability = pass_mode{0};
tile_image_proto ground() const noexcept;
tile_image_proto wall_north() const noexcept;
@@ -62,8 +60,8 @@ struct tile_ref final
std::shared_ptr<const tile_atlas> wall_west_atlas() const noexcept;
std::shared_ptr<const anim_atlas> scenery_atlas() const noexcept;
- pass_mode_ref pass_mode() noexcept;
- enum pass_mode pass_mode() const noexcept;
+ pass_mode_ref passability() noexcept;
+ pass_mode passability() const noexcept;
explicit operator tile_proto() const noexcept;