5#include "MemoryContext.h"
7#include "Foundation/Memory/Allocator.h"
8#include "Foundation/Reflection/TypeDatabase.h"
23 void(*destroy)(
void *);
52 template<
typename Service,
typename... Args>
55 auto & type = Reflection::TypeDatabase::getType<Service>();
57 if (!ensureUniqueService(type.getTypeId())) {
58 return getService<Service>();
61 auto s = Memory::create<Service>(context->
memory->baseAllocator, args...);
65 service.size =
sizeof(Service);
66 service.id = type.getTypeId();
67 service.destroy = [](
void * t) {
static_cast<Service *
>(t)->~Service(); };
69 services.push_back(service);
77 template<
typename Service>
80 auto & type = Reflection::TypeDatabase::getType<Service>();
82 if (!ensureUniqueService(type.getTypeId())) {
88 service.id = type.getTypeId();
90 services.push_back(service);
93 template<
typename Service>
94 Service * getService()
96 const auto typeId = Reflection::TypeDatabase::getType<Service>().getTypeId();
98 return static_cast<Service *
>(locateService(typeId));
101 void addFrameCallback(std::function<
void(
void)> callback);
102 void dispatchFrameCallbacks();
108 std::vector<RegisteredService> services;
109 std::vector<std::function<void(
void)>> callbacks;
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< struct MemoryContext > memory
Memory and allocation info.
void registerServiceReference(Service *s)
Registers an externally managed service instance.
Service * registerService(Args... args)
Registers a service of the given type.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Contains all Cogs related functionality.
Registered service structure.