psemek/libs/ecs/include/psemek/ecs/entity_container.hpp
2023-08-19 15:21:17 +03:00

53 lines
1.5 KiB
C++

#pragma once
#include <psemek/ecs/component_index.hpp>
#include <psemek/ecs/component_mask.hpp>
#include <psemek/ecs/entity_handle.hpp>
#include <psemek/ecs/table_container.hpp>
#include <psemek/util/span.hpp>
namespace psemek::ecs
{
struct entity_container
{
template <typename ... Components>
entity_handle create(Components && ... components)
{
component_mask mask = component_index_.make_component_mask(components.uuid()...);
// TODO
return {};
}
bool alive(entity_handle const & entity) const;
void destroy(entity_handle const & entity);
template <typename Function>
void apply(Function && function, util::span<util::uuid const> component_uuids)
{
component_mask mask = component_index_.make_component_mask(component_uuids);
table_container_.apply([&](table & table){
// TODO: extract specific component pointers and apply the function
// to each element, using stride to advance pointers
// TODO: maybe store UUIDS or component indices in the table to simplify
// extracting the component pointers
}, mask);
}
template <typename ... Components, typename Function>
void apply(Function && function)
{
util::uuid component_uuids[] { Components::uuid() ... };
// TODO: call function, casting the raw uint8_t component pointers
// to actual component types
}
private:
mutable component_index component_index_;
table_container table_container_;
// TODO: store entity epochs
// TODO: store entity id -> table * mapping
};
}