#include "entityx/Event.h"
#include "entityx/help/NonCopyable.h"
+class Archive;
+
namespace entityx {
typedef std::uint32_t uint32_t;
void operator delete([[maybe_unused]] void *p) { fail(); }
void operator delete[]([[maybe_unused]] void *p) { fail(); }
+ virtual void save([[maybe_unused]] Archive& ar) {}
+ virtual void load([[maybe_unused]] Archive& ar) {}
protected:
static void fail() {
virtual ~BaseComponentHelper() {}
virtual void remove_component(Entity e) = 0;
virtual void copy_component_to(Entity source, Entity target) = 0;
+ virtual BaseComponent *get_component(Entity e) = 0;
};
template <typename C>
void copy_component_to(Entity source, Entity target) override {
target.assign_from_copy<C>(*(source.component<C>().get()));
}
+ BaseComponent *get_component(Entity e) override {
+ return e.component<C>().get();
+ }
};
/**
return std::make_tuple(component<const Components>(id)...);
}
+ /**
+ * EDIT by tcsullivan
+ * Iterates through all components of a given Entity.
+ */
+ void entity_each_component(Entity entity, std::function<void(BaseComponent*)> f)
+ {
+ auto mask = entity.component_mask();
+ for (size_t i = 0; i < component_helpers_.size(); i++) {
+ BaseComponentHelper *helper = component_helpers_[i];
+ if (helper && mask.test(i))
+ f(helper->get_component(entity));
+ }
+ }
+
/**
* Find Entities that have all of the specified Components.
*