Get SpatialOS

Sites

Menu

Introduction to the C++ worker SDK

The C++ worker SDK allows anyone to write a worker in C++ to connect to a SpatialOS simulated world. Like any other worker, a C++ worker can subscribe to information for a part of a simulated world, visualize it, and perform some computation on behalf of the simulated world.

A typical C++ worker makes use of both the core API defined in <improbable/worker.h>, and C++ generated code based on the user-specified simulated world schema. See Compiling a C++ Worker for details.

The SDK also includes methods to load and save snapshots of the entire simulation from and to a file. This lets you write tools to perform offline transformations of the simulation state, or to programmatically create the starting point of a simulation. This functionality is documented in the C++ worker SDK docs.

Obtaining the SDK

Once you’ve got a project set up (examples at the SpatialOS GitHub repository), obtain the SDK through worker packages, our package management framework.

You can obtain the relevant worker package as follows:

  1. Add the following configuration within <root>/workers/<your_worker>/spatialos_worker_packages.json to download the header files and libraries to link against:

      {
        "targets": [
          {
            "path": "worker_sdk",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "<package>"
              }
            ]
          }
        ]
      }
    

    The supported options for <package> are currently:

    • cpp-static-x86-msvc_md-win32 - Windows 32-bit compiled using MSVC (with /MD runtime).
    • cpp-static-x86_64-msvc_md-win32 - Windows 64-bit compiled using MSVC (with /MD runtime).
    • cpp-static-x86_64-msvc_mdd-win32 - Windows 64-bit compiled using MSVC (with /MDd runtime).
    • cpp-static-x86_64-msvc_mt-win32 - Windows 64-bit compiled using MSVC (with /MT runtime).
    • cpp-static-x86_64-msvc_mtd-win32 - Windows 64-bit compiled using MSVC (with /MTd runtime).
    • cpp-static-x86_64-clang_libcpp-macos - macOS 64-bit compiled using Xcode 8.
    • cpp-static-x86_64-gcc_libstdcpp-linux - Linux 64-bit compiled using GCC 5.4.0 with the libstdc++ standard library.

    Multiple packages can be specified at once as multiple entries in the targets array with different paths if desired. For example, when using Debug and Release configurations on Windows, we can download both the /MD and /MDd builds of the worker SDK, and point the MSVC project to the correct lib directories for each configuration. The spatialos_worker_packages.json will look similar to:

      {
        "targets": [
          {
            "path": "worker_sdk/windows/debug",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "cpp-static-x86_64-msvc_mdd-win32"
              }
            ]
          },
          {
            "path": "worker_sdk/windows/release",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "cpp-static-x86_64-msvc_md-win32"
              }
            ]
          }
        ]
      }
    
  2. Run spatial worker package unpack.

    This will unpack the worker SDK (type) for the specified language and platform into the specified sub-directory (path). The downloaded worker package will be compatible with the SpatialOS SDK version used for your application (specified in <root>/spatialos.json under sdk_version).

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums