Worker SDK in C
The Worker SDK in C exposes the lowest level interface with the SpatialOS Runtime. It is designed for high performance game engine integrations, and for creating high-level abstraction layers for writing workers in any language that can interoperate with a C API. It is unopinionated and is the Worker SDK option that gives you the most control.
- integration into a game engine for production use.
- development of a higher-level, opinionated abstraction layer on top of SpatialOS for production use.
- production use of workers written in any language that can interact with a C API (likely via a suitable abstraction).
May also be suitable for:
- understanding SpatialOS’s concepts and abstractions.
- evaluating SpatialOS’s capabilities.
Not recommended for:
- quick prototyping of workers (for this we recommend the Worker SDK in C++ or the .NET Core C# worker (preview)).
Unlike C++, C# and Java, the Worker SDK in C does not provide any generated code. Instead, it exposes serialization functions to read and write:
- component data
- component updates
- command requests and responses.
This requires substantially more work to get started, because you will likely need to implement code generation yourself using custom codegen. However, this approach enables far more flexibility. For example, if you use the Worker SDK in C to create a worker in a dynamic language, you could write fully dynamic serialization code which uses reflection (perhaps after being validated using some custom generated code based off the project’s schema). You could also generate serialization code directly in the dynamic language, which can then be hot reloaded without restarting the worker.
In addition to connecting to a simulation, the API also includes methods to load and save snapshots of the entire simulation from and to a file. This lets you write tooling to modify the state of the simulation offline, or to programmatically create the initial point of a simulation.
The API includes a low-level gRPC client called ngRPC, which you can use to communicate with the Platform SDK or any gRPC services you host yourself. This is convenient as it runs on any of the supported platforms of the Worker SDK, and requires no additional dependencies.
Using the C example project
The C example project is a fairly minimal example of project structure and build configuration for workers using the Worker SDK in C. We recommend you use it as a starting point, along with Setup and installation and Building a worker.
2019-12-13 Page updated with editorial review: added introductory section