NcEngine
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
nc::ComponentHandler< T > Struct Template Reference

Optional data and callbacks for generic component operations. More...

#include <Component.h>

Public Types

using Factory_t = std::move_only_function< T(Entity entity, const std::any &userData)>
 Function type for the Factory handler.
 
using Serialize_t = std::move_only_function< void(std::ostream &binaryStream, const T &component, const SerializationContext &ctx, const std::any &userData)>
 Function type for the serialize handler.
 
using Deserialize_t = std::move_only_function< T(std::istream &binaryStream, const DeserializationContext &ctx, const std::any &userData)>
 Function type for the deserialize handler.
 
using DrawUI_t = std::move_only_function< void(T &component, ui::editor::EditorContext &ctx, const std::any &userData)>
 Function type for the DrawUI handler.
 

Public Attributes

size_t id = 0ull
 A unique identifier for the component. More...
 
std::string name = "User Component"
 A name for the component with no uniqueness constraints.
 
std::any userData = std::any{}
 Optional user data, which is passed to the factory, serialize, and deserialize handlers.
 
Factory_t factory = nullptr
 Callback for creating an instance of T. More...
 
Serialize_t serialize = nullptr
 Callback for serializing an instance of T. More...
 
Deserialize_t deserialize = nullptr
 Callback for deserializing an instance of T. More...
 
DrawUI_t drawUI = nullptr
 Callback for drawing T's UI widget.
 

Detailed Description

template<PooledComponent T>
struct nc::ComponentHandler< T >

Optional data and callbacks for generic component operations.

Member Data Documentation

◆ deserialize

template<PooledComponent T>
Deserialize_t nc::ComponentHandler< T >::deserialize = nullptr

Callback for deserializing an instance of T.

Note
This is called when deserializing scene fragments if and only if both serialize and deserialize are set.

◆ factory

template<PooledComponent T>
Factory_t nc::ComponentHandler< T >::factory = nullptr

Callback for creating an instance of T.

Note
This enables adding/removing types through the editor.

◆ id

template<PooledComponent T>
size_t nc::ComponentHandler< T >::id = 0ull

A unique identifier for the component.

Note
Set to 0 to get assigned an available id. The range [1, 100] is reserved for engine components. Automatically assigned ids are assigned in reverse order starting from std::numeric_limits<size_t>::max().

◆ serialize

template<PooledComponent T>
Serialize_t nc::ComponentHandler< T >::serialize = nullptr

Callback for serializing an instance of T.

Note
This is called when serializing scene fragments if and only if both serialize and deserialize are set.

The documentation for this struct was generated from the following file: