Providing your components
Since C++ has no reflection capability, the Worker SDK in C++ makes no attempt to discover your components automatically. Instead, you must explicitly provide the list of components you want to work with to SDK methods that need to know about them (including standard library components).
To do this, pass an instance of the worker::Components
variadic template class:
// MyComponents can be passed to SDK functions.
const worker::Components<
my_schema::FooComponent,
my_schema::BarComponent,
// Must include standard library components you care about, too.
improbable::EntityAcl,
improbable::Position,
...> MyComponents;
Since worker::Components
is a template, you need to
include the generated code for every component you want to work with in order to define MyComponents
. However,
since this class implements the worker::ComponentRegistry
interface, this only needs to be done in one source file:
// This function can be called from other translation units without including generated code.
const worker::ComponentRegistry& MyComponents() {
static const worker::Components<my_schema::FooComponent, my_schema::BarComponent> components;
return components;
}
The rest of the “Using the Worker SDK in C++” section assumes you have defined a MyComponents
function like this.