Try SpatialOS



Providing your components

Since C++ has no reflection capability, C++ SDK 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<
    // Must include standard library components you care about, too.
    ...> 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 C++ SDK” section assumes you have defined a MyComponents function like this.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums