summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-17 07:01:45 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-17 23:23:11 +0100
commit34ae7b665919d05660263bf522c78ebdb735d30d (patch)
treed58a83c5b5b71763c71e51cf421079380cac00c1 /src
parent34a0239ad6e6d84bd0027d9029d0d74419247d01 (diff)
aaa
Diffstat (limited to 'src')
-rw-r--r--src/character.cpp2
-rw-r--r--src/character.hpp4
-rw-r--r--src/chunk-collision.cpp1
-rw-r--r--src/chunk.hpp1
-rw-r--r--src/chunk.inl2
-rw-r--r--src/entity.cpp8
-rw-r--r--src/entity.hpp5
-rw-r--r--src/scenery.cpp26
-rw-r--r--src/scenery.hpp3
9 files changed, 33 insertions, 19 deletions
diff --git a/src/character.cpp b/src/character.cpp
index b4e42a4f..e0645ddb 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -51,7 +51,7 @@ constexpr auto arrows_to_dir(bool L, bool R, bool U, bool D)
} // namespace
-character::character(std::uint64_t id, struct chunk& c, entity_type type) : entity{id, c, type}
+character::character(std::uint64_t id, struct chunk& c, entity_type type, bool playable) : entity{id, c, type}, playable{playable}
{
atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH);
bbox_size = Vector2ub(iTILE_SIZE2/2);
diff --git a/src/character.hpp b/src/character.hpp
index b5bba8fb..9e2617ae 100644
--- a/src/character.hpp
+++ b/src/character.hpp
@@ -14,16 +14,18 @@ struct character final : entity
~character() override;
void set_keys(bool L, bool R, bool U, bool D);
bool update(std::size_t i, float dt) override;
+ bool is_playable() const { return playable; }
private:
int allocate_frame_time(float dt);
static Vector2 move_vec(int left_right, int top_bottom);
friend struct world;
- character(std::uint64_t id, struct chunk& c, entity_type type);
+ character(std::uint64_t id, struct chunk& c, entity_type type, bool playable);
Vector2s offset_frac;
bool b_L : 1 = false, b_R : 1 = false, b_U : 1 = false, b_D : 1 = false;
+ bool playable : 1 = false;
};
template<> struct entity_type_<struct character> : std::integral_constant<entity_type, entity_type::character> {};
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index b78f43a4..c64d9a5b 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -7,7 +7,6 @@
namespace floormat {
-const chunk::RTree* chunk::rtree() const noexcept { return &_rtree; }
chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &_rtree; }
namespace {
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 5b0e6d74..d5070f02 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -99,7 +99,6 @@ struct chunk final
using RTree = ::RTree<std::uint64_t, float, 2, float>;
- const RTree* rtree() const noexcept;
RTree* rtree() noexcept;
struct world& world() noexcept { return *_world; }
diff --git a/src/chunk.inl b/src/chunk.inl
index bbfec37a..038b5863 100644
--- a/src/chunk.inl
+++ b/src/chunk.inl
@@ -13,7 +13,7 @@ void chunk::with_scenery_update(entity& s, F&& fun)
// todo handle coord & offset fields
auto ch = s.coord.chunk();
- entity_proto s0 = s;
+ entity_proto s0(s);
bbox bb0; bool b0 = _bbox_for_scenery(s, bb0);
bool modified = true;
diff --git a/src/entity.cpp b/src/entity.cpp
index c0b89195..c9c1a4ab 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -88,14 +88,6 @@ std::size_t entity::index() const
return (std::size_t)std::distance(es.cbegin(), it);
}
-bool entity::operator==(const entity_proto& o) const
-{
- return atlas.get() == o.atlas.get() &&
- type == o.type && frame == o.frame && r == o.r && pass == o.pass &&
- offset == o.offset && bbox_offset == o.bbox_offset &&
- bbox_size == o.bbox_size && delta == o.delta;
-}
-
void entity::rotate(std::size_t, rotation new_r)
{
auto& w = *c->_world;
diff --git a/src/entity.hpp b/src/entity.hpp
index 9c6dc2d1..da6ccca3 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -29,7 +29,7 @@ struct entity_proto
entity_proto();
entity_proto(const entity_proto&);
- bool operator==(const entity_proto&) const;
+ virtual bool operator==(const entity_proto&) const;
virtual ~entity_proto() noexcept;
};
@@ -56,8 +56,7 @@ struct entity
struct chunk& chunk() const;
std::size_t index() const;
- virtual bool operator==(const entity_proto& e0) const;
- operator entity_proto() const;
+ explicit operator entity_proto() const;
virtual bool can_activate(std::size_t i) const;
virtual bool activate(std::size_t i);
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 5fe6d573..be0249d2 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -85,9 +85,12 @@ bool scenery::activate(std::size_t)
return false;
}
-bool scenery::operator==(const entity_proto& e0) const
+bool scenery_proto::operator==(const entity_proto& e0) const
{
- if (!entity::operator==(e0))
+ if (type != e0.type)
+ return false;
+
+ if (!entity_proto::operator==(e0))
return false;
const auto& s0 = static_cast<const scenery_proto&>(e0);
@@ -95,6 +98,25 @@ bool scenery::operator==(const entity_proto& e0) const
closing == s0.closing && interactive == s0.interactive;
}
+scenery::operator scenery_proto() const
+{
+ scenery_proto ret;
+ ret.sc_type = sc_type;
+ ret.active = active;
+ ret.closing = closing;
+ ret.interactive = interactive;
+ ret.atlas = atlas;
+ ret.offset = offset;
+ ret.bbox_offset = bbox_offset;
+ ret.bbox_size = bbox_size;
+ ret.delta = delta;
+ ret.frame = frame;
+ ret.type = entity_type::character;
+ ret.r = r;
+ ret.pass = pass;
+ return ret;
+}
+
scenery::scenery(std::uint64_t id, struct chunk& c, entity_type type, const scenery_proto& proto) :
entity{id, c, type}, sc_type{proto.sc_type}, active{proto.active},
closing{proto.closing}, interactive{proto.interactive}
diff --git a/src/scenery.hpp b/src/scenery.hpp
index 2939fe7d..68ba1607 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -30,6 +30,7 @@ struct scenery_proto : entity_proto
scenery_proto(const scenery_proto&);
~scenery_proto() noexcept override;
scenery_proto& operator=(const scenery_proto&);
+ bool operator==(const entity_proto& proto) const override;
operator bool() const;
};
@@ -43,7 +44,7 @@ struct scenery final : entity
bool can_activate(std::size_t i) const override;
bool activate(std::size_t i) override;
bool update(std::size_t i, float dt) override;
- bool operator==(const entity_proto& p) const override;
+ explicit operator scenery_proto() const;
private:
friend struct world;