Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Macros | Functions
ComponentRegistry.h File Reference
#include "World.h"
#include "ComponentDefinition.h"
#include <functional>
#include <iostream>
+ Include dependency graph for ComponentRegistry.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AUTO_REGISTER_COMPONENT(ComponentType)
 Macro for auto-registering a component at program startup Place this immediately after the struct definition.
 

Functions

template<typename T >
bool InstantiateComponentGeneric (EntityID entity, const ComponentDefinition &def)
 Generic template function for instantiating any ECS component This handles the common case: create component if missing, get reference Specialized behavior can still use custom InstantiateXYZ() functions.
 

Macro Definition Documentation

◆ AUTO_REGISTER_COMPONENT

#define AUTO_REGISTER_COMPONENT (   ComponentType)
Value:
namespace { \
}; \
} \
inline ComponentRegistrar_##ComponentType::ComponentRegistrar_##ComponentType() { \
extern void RegisterComponentFactory_Internal(const char*, std::function<bool(EntityID, const ComponentDefinition&)>); \
[](EntityID entity, const ComponentDefinition& def) { \
} \
); \
}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
ComponentType
void RegisterComponentFactory_Internal(const char *componentName, std::function< bool(EntityID, const ComponentDefinition &)> factory)

Macro for auto-registering a component at program startup Place this immediately after the struct definition.

Example: struct Position_data { Vector position; }; AUTO_REGISTER_COMPONENT(Position_data);

This creates a static dummy variable whose constructor executes before main()

Definition at line 76 of file ComponentRegistry.h.

Function Documentation

◆ InstantiateComponentGeneric()

template<typename T >
bool InstantiateComponentGeneric ( EntityID  entity,
const ComponentDefinition def 
)

Generic template function for instantiating any ECS component This handles the common case: create component if missing, get reference Specialized behavior can still use custom InstantiateXYZ() functions.

Returns
true if component was created successfully, false otherwise Note: Currently always returns true for generic components. Custom factory functions can return false to indicate failure.

Definition at line 47 of file ComponentRegistry.h.

References World::AddComponent(), World::Get(), World::GetComponent(), and GetComponentTypeID_Static().

+ Here is the call graph for this function: