Originally reported by: Per-Morten Straume (Bitbucket: Per-Morten, GitHub: Per-Morten)
The event system we are going for now will look a lot like the one already existing within Suttung. That is intentional as we don't want to take on to much in the start of the project. However we do want to be able to change that event system out with something more reminiscent of we do the meta information.
Doing it this way might still allow us to avoid heavy template usage, as well as easier use of an own allocator.
#!c++
struct Event
{
////////////////////////////////////////////////////////////
/// \brief The id of the receiving component.
////////////////////////////////////////////////////////////
EntityId receiver;
////////////////////////////////////////////////////////////
/// \brief The component type.
////////////////////////////////////////////////////////////
TypeIdentifier eventType;
////////////////////////////////////////////////////////////
/// \brief Constructs the event with the id of the receiver
/// and the event type.
////////////////////////////////////////////////////////////
Event(const EntityId& receiver,
const TypeIdentifier& eventType);
void
addArgument(const EventArgument& argument);
};
struct EventArgument
{
TypeIdentifier type;
char* payload;
using Destructor = void(*)(char*);
Destructor destructor;
};
template<class T>
createEventArgument(const T& value,
const TypeIdentifier& identifier)
{
EventArgument arg;
arg.type = identifier;
arg.payload = allocator.allocate(sizeof(T));
// Inplace construct the payload.
new(payload)T(value);
auto destructor = [](char* payload_)
{
((T*)payload_)->~T();
allocator.deallocate(sizeof(T),payload_);
};
arg.destructor = destructor;
}
Originally reported by: Per-Morten Straume (Bitbucket: Per-Morten, GitHub: Per-Morten)
The event system we are going for now will look a lot like the one already existing within Suttung. That is intentional as we don't want to take on to much in the start of the project. However we do want to be able to change that event system out with something more reminiscent of we do the meta information. Doing it this way might still allow us to avoid heavy template usage, as well as easier use of an own allocator.