Worker SDK in C

Step 2. Address major API breaking changes - Worker SDK in C

See the Upgrade guide page for step 1, before following this page.

1. Update package names

Many of the packages containing Worker SDK in C binaries have been slightly renamed to be more simple and concise.

Therefore, the package names will need to be updated where packages are downloaded, either in spatialos_worker_packages.json in your worker directory (if using SPL), or in your own build system using spatial package get (if using FPL).

Updated package names can be found here but in summary, the following
changes should be applied from SpatialOS 13:

a. For Windows packages, replace msvc with vc140.
b. For macOS, iOS and Android packages, replace clang_libcpp with clang.
c. For Linux packages, replace gcc_libstdcpp with gcc510.

2. Update package structure

We have also made three changes to simplify the structure of the binary packages:

  1. Static packages (packages beginning with c-static) no longer contain a lib folder. Instead, the libraries are just contained in the root of the package.
  2. We've removed header files. Instead, you should obtain the header files from the separate c_headers package. If using the SPL, you can use this as a guide to download the header files correctly.
  3. We've renamed the worker library to improbable_worker to avoid ambiguity. For example, on Windows, we now ship improbable_worker.dll / improbable_worker.lib instead of worker.dll / worker.lib.

3. Update component and command handles

We have simplified the usage of Worker_ComponentData, Worker_ComponentUpdate, Worker_CommandRequest and Worker_CommandResponse slightly. Now, the equivalent Schema_Create functions no longer require a component ID or command index to be specified.

The information is now only specified in the Worker_ objects. Note that a command_index has been added to Worker_CommandRequest and Worker_CommandResponse, and this field needs to be set instead of passing the command index to Schema_CreateCommandRequest
and Schema_CreateCommandResponse.

For example, sending a command request has changed from this:

Worker_CommandRequest request;
update.component_id = 1234;
update.schema_type = Schema_CreateCommandRequest(1234, 1);
// serialize into update.schema_type.
Worker_Connection_SendCommandRequest(connection, entity_id, &request, 1, NULL, NULL);

to this:

Worker_CommandRequest request;
update.component_id = 1234;
update.command_index = 1;
update.schema_type = Schema_CreateCommandRequest();
// serialize into update.schema_type.
Worker_Connection_SendCommandRequest(connection, entity_id, &request, NULL, NULL);

Additionally, Schema_Get*ComponentId and Schema_GetCommand*CommandIndex functions have been removed. Therefore, when receiving and processing an operation that contains a Schema_ object, you should instead obtain the component ID and/or command index from the enclosing Worker_ object. For example, receiving a command request (when serializing directly) has changed from this:

Worker_CommandRequest* command_request = &ops[i].command_request.request;
Schema_CommandRequest* data = command_request->schema_type;

Worker_ComponentId component_id = Schema_GetCommandRequestComponentId(data);
Schema_FieldId command_index = Schema_GetCommandRequestCommandIndex(data);
DeserializeData(component_id, command_index, data);

to this:

Worker_CommandRequest* command_request = &ops[i].op.command_request.request;
Schema_CommandRequest* data = command_request->schema_type;

Worker_ComponentId component_id = command_request->component_id;
Schema_FieldId command_index = command_request->command_index;
DeserializeData(component_id, command_index, data);

4. Update ops and constraints

To make the C header files fully compliant with C90, we needed to remove usages of anonymous unions. This means that accesses to op data within a Worker_Op object need to be accessed through a nested union called op, and accesses to constraint types within a Worker_Constraint object need to be accessed through a nested union called constraint.

For example, for Worker_Op:

/* before */
Worker_Op* op = /* ... */;
Worker_ComponentUpdate* update = &op->component_update.update;

/* after */
Worker_Op* op = /* ... */;
Worker_ComponentUpdate* update = &op->op.component_update.update;

and Worker_Constraint:

/* before */
Worker_Constraint* constraint = /* ... */;
constraint->entity_id_constraint.entity_id = 1234;

/* after */
Worker_Constraint* constraint = /* ... */;
constraint->constraint.entity_id_constraint.entity_id = 1234;

Updated about a year ago


Next

Now return to the Upgrade guide and follow step 3.

Upgrade guide

Worker SDK in C


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.