Background Worker
Simulate partitions a simulation into areas of space managed by Cell Workers. However it is often necessary to do processing that is not linked to a specific location in simulation space, or is not able to be subdivided into Simulate Cells.
Simulate provides the ability to create a Background Worker that is a process able to subscribe to and send Simulate messages in the same manner as a Cell Worker, but is not tied to a location in virtual space and will be persistent for the life of the simulation.
In order to create a Background Worker you will need to
  1. 1.
    Create a class implementing two required lifecycle functions
  2. 2.
    Registering the new class with the Simulate Manager

1. Defining a Background Worker Class

The background worker has a simpler lifecycle than a cell worker. There is no specific initialisation stage, rather the following callbacks are triggered once per tick.
The Background Worker has access to a get_tick() method that will return the current tick value. Note that the background worker is not able to access the key-value store, however it does have access to the aether messaging system and so can send targeted messages to the Aether Cell Workers.
Function
Description
Lifecycle
get_topics
Indicates which messages you would like the Background worker to receive in additions to those addressed directly to it
Called every tick
process_messages
Implements logic to handle incoming messages
Called every tick
An implementation of a background worker must inherit from aether::global_state_base<octreetraits> and override the following functions
The signature for these functions can be seen below for our example background worker class
class example_background_worker : public aether::global_state_base<octree_traits> {
public:
void process_messages(reader_type &reader, writer_type &writer) override;
std::vector<subscriber_topic_type> get_topics() override;
};
The reader and writer types used in process_messagesare documented in messaging.

2. Registering The Background Worker

To register your Background Worker you will need to pass in additional arguments with a reference to your new Background Worker Class when initialising your Manager with the key line being the addition of your class to the configuration arguments.
static_args.configure_global_state<example_background_worker>();
This is shown in context in the example main.cc below
main.cc
int main(int argc, char *argv[]) {
// ...
// Construct the octree arguments from parsed command line parameters
auto static_args = arguments.to_octree_params<octree_traits>();
// Use an instance of example_global_state as the global state process
static_args.configure_global_state<example_background_worker>();
// Construct the manager
auto manager = aether::build_entity_simulation_manager<user_cell_state_impl>(arguments.workers, static_args);
// ...
}

Best practices

The Background Worker is an excellent location to receive and process unclaimed messages, subscribe to the unclaimed_events topic in order to receive messages that would otherwise be discarded.
Whilst the Background Worker can be an excellent location for processing data from across multiple cells, for simple data that needs to be made available across multiple workers, consider using the Global key/value store, since it is more lightweight.