summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-10 14:11:02 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-11 00:33:47 +0200
commitf29ee994108bf443de4aeeabd7519f13ca4b7a4d (patch)
tree6f1ad0d719dcfcc5c5c199ce1d25c5531550835d /src
parentaad0d8fd8e2d3409db1b591c6dbc401e02eaeef3 (diff)
wip virtual entity stuff
Diffstat (limited to 'src')
-rw-r--r--src/character.cpp3
-rw-r--r--src/chunk-scenery.cpp13
-rw-r--r--src/entity.cpp13
-rw-r--r--src/entity.hpp1
-rw-r--r--src/scenery.cpp1
-rw-r--r--src/world.cpp1
6 files changed, 19 insertions, 13 deletions
diff --git a/src/character.cpp b/src/character.cpp
index d75070e8..88a575f9 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -92,6 +92,7 @@ character_proto& character_proto::operator=(const character_proto&) = default;
character_proto::character_proto()
{
type = entity_type::character;
+ atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH);
}
bool character_proto::operator==(const entity_proto& e0) const
@@ -215,8 +216,6 @@ character::character(object_id id, struct chunk& c, const character_proto& proto
{
if (!name)
name = "(Unnamed)"_s;
- if (!atlas)
- const_cast<std::shared_ptr<anim_atlas>&>(atlas) = loader.anim_atlas("npc-walk", loader.ANIM_PATH);
fm_soft_assert(atlas->check_rotation(r));
entity::set_bbox_(offset, bbox_offset, Vector2ub(iTILE_SIZE2/2), pass);
}
diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp
index 989670e4..edfbfeb1 100644
--- a/src/chunk-scenery.cpp
+++ b/src/chunk-scenery.cpp
@@ -139,7 +139,7 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce
const auto count = fm_begin(
size_t ret = 0;
for (const auto& e : _entities)
- ret += !e->is_dynamic();
+ ret += !e->is_dynamic() && !e->is_virtual();
return ret;
);
@@ -150,7 +150,8 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce
{
if (e->is_dynamic())
continue;
-
+ if (e->is_virtual())
+ continue;
const auto& atlas = e->atlas;
const auto& fr = *e;
const auto pos = e->coord.local();
@@ -178,13 +179,15 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce
const auto size = _entities.size();
auto& array = buffers.array;
- uint32_t j = 0;
- for (uint32_t i = 0; const auto& e : _entities)
+ uint32_t j = 0, i = 0;
+ for (const auto& e : _entities)
{
+ if (e->is_virtual())
+ continue;
auto index = e->is_dynamic() ? (uint32_t)-1 : j++;
array[i++] = { e.get(), (uint32_t)-1, e->ordinal(), make_topo_sort_data(*e, index) };
}
- topological_sort(array, size);
+ topological_sort(array, i);
return { scenery_mesh, ArrayView<entity_draw_order>{array, size}, j };
}
diff --git a/src/entity.cpp b/src/entity.cpp
index 93233aae..6361c118 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -29,11 +29,9 @@ entity::entity(object_id id, struct chunk& c, const entity_proto& proto) :
bbox_size{proto.bbox_size}, delta{proto.delta},
frame{proto.frame}, r{proto.r}, pass{proto.pass}
{
- if (atlas)
- {
- fm_soft_assert(atlas->check_rotation(r));
- fm_soft_assert(frame < atlas->info().nframes);
- }
+ fm_soft_assert(atlas);
+ fm_soft_assert(atlas->check_rotation(r));
+ fm_soft_assert(frame < atlas->info().nframes);
}
entity::~entity() noexcept
@@ -76,6 +74,11 @@ size_t entity::index() const
return (size_t)std::distance(es.cbegin(), it);
}
+bool entity::is_virtual() const
+{
+ return false;
+}
+
bool entity::can_rotate(global_coords coord, rotation new_r, rotation old_r, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size)
{
if (bbox_offset.isZero() && bbox_size[0] == bbox_size[1])
diff --git a/src/entity.hpp b/src/entity.hpp
index 183892d5..b49999e7 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -57,6 +57,7 @@ struct entity
float ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const;
struct chunk& chunk() const;
size_t index() const;
+ virtual bool is_virtual() const;
explicit operator entity_proto() const;
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 99d277e5..ee774282 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -161,6 +161,7 @@ scenery::scenery(object_id id, struct chunk& c, const scenery_proto& proto) :
entity{id, c, proto}, sc_type{proto.sc_type}, active{proto.active},
closing{proto.closing}, interactive{proto.interactive}
{
+ fm_debug_assert(atlas); // todo add placeholder graphic
}
} // namespace floormat
diff --git a/src/world.cpp b/src/world.cpp
index 6749210a..e829ab5e 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -163,7 +163,6 @@ void world::do_make_entity(const std::shared_ptr<entity>& e, global_coords pos,
fm_assert(e->id > 0);
fm_debug_assert(_unique_id && e->c->world()._unique_id == _unique_id);
fm_assert(!_entities.contains(e->id));
- fm_assert(Vector2ui(e->bbox_size).product() > 0);
fm_assert(e->type() != entity_type::none);
const_cast<global_coords&>(e->coord) = pos;
_entities[e->id] = e;