Commit 1a923be6 authored by Florian Oetke's avatar Florian Oetke
Browse files

fixed hot-reloading for ECS blueprints and stupid buffer overflow in pool::_move_elements

parent bf977a2e
......@@ -24,22 +24,22 @@ namespace mirrage::ecs {
class Blueprint {
public:
Blueprint(std::string id, std::string content, asset::Asset_manager* asset_mgr);
Blueprint(std::string id, std::string content, asset::Asset_manager*);
Blueprint(Blueprint&&) noexcept;
Blueprint(const Blueprint&) = delete;
~Blueprint() noexcept;
Blueprint& operator=(Blueprint&&) noexcept;
void detach(Entity_handle target) const;
void detach(Entity_facet target) const;
void on_reload();
mutable std::vector<Entity_handle> users;
mutable std::vector<Blueprint*> children;
std::string id;
std::string content;
asset::Ptr<Blueprint> parent;
asset::Asset_manager* asset_mgr;
mutable Entity_manager* entity_manager = nullptr;
mutable std::vector<Entity_facet> users;
mutable std::vector<Blueprint*> children;
std::string id;
std::string content;
asset::Ptr<Blueprint> parent;
asset::Asset_manager* asset_mgr;
mutable Entity_manager* entity_manager = nullptr;
};
......@@ -110,13 +110,12 @@ namespace mirrage::ecs {
}
for(auto&& u : users) {
auto entity = entity_manager->get(u);
MIRRAGE_INVARIANT(entity.is_some(), "dead entity in blueprint.users");
apply(*this, entity.get_or_throw());
MIRRAGE_INVARIANT(u.valid(), "dead entity in blueprint.users");
apply(*this, u);
}
}
void Blueprint::detach(Entity_handle target) const { util::erase_fast(users, target); }
void Blueprint::detach(Entity_facet target) const { util::erase_fast(users, target); }
} // namespace
} // namespace mirrage::ecs
......@@ -154,7 +153,7 @@ namespace mirrage::ecs {
~Blueprint_component()
{
if(blueprint) {
blueprint->detach(owner_handle());
blueprint->detach(owner(*_manager));
blueprint.reset();
}
}
......@@ -162,7 +161,7 @@ namespace mirrage::ecs {
void set(asset::Ptr<Blueprint> blueprint)
{
if(this->blueprint) {
this->blueprint->detach(owner_handle());
this->blueprint->detach(owner(*_manager));
}
this->blueprint = std::move(blueprint);
......@@ -183,9 +182,11 @@ namespace mirrage::ecs {
auto blueprint = state.assets.load<Blueprint>(
AID{"blueprint"_strid, blueprintName}); // TODO: could/should be async
comp.set(blueprint);
blueprint->users.push_back(comp.owner_handle());
auto owner = comp.owner(comp.manager());
blueprint->users.push_back(owner);
blueprint->entity_manager = &comp.manager();
apply(*blueprint, comp.owner(comp.manager()));
apply(*blueprint, owner);
}
void save_component(ecs::Serializer& state, const Blueprint_component& comp)
......@@ -254,7 +255,7 @@ namespace mirrage::ecs {
else
e.get<Blueprint_component>().get_or_throw().set(b);
b->users.push_back(e.handle());
b->users.push_back(e);
apply(*b, e);
}
......
......@@ -282,7 +282,7 @@ namespace mirrage::util {
} else {
// nay, have to check if valid and call move-assignment / placement-new
if(src < dst) {
std::move_backward(&get(c_src), &get(c_src) + step, &get(c_dst));
std::move_backward(&get(c_src), &get(c_src) + step, &get(c_dst) + step);
} else {
std::move(&get(c_src), &get(c_src) + step, &get(c_dst));
}
......
......@@ -165,8 +165,8 @@ namespace mirrage::util {
}
template <typename T>
void erase_fast(std::vector<T>& c, const T& v)
template <typename T, typename K>
void erase_fast(std::vector<T>& c, const K& v)
{
using std::swap;
......@@ -176,8 +176,8 @@ namespace mirrage::util {
c.pop_back();
}
}
template <typename T>
void erase_fast_stable(std::vector<T>& c, const T& v)
template <typename T, typename K>
void erase_fast_stable(std::vector<T>& c, const K& v)
{
auto ne = std::remove(c.begin(), c.end(), v);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment