Global State

Documentation objective

This document explains how global state is managed within the Aether Engine.

Overview

Aether Engine partitions the simulation into areas of space managed by multiple worker processes. However there is also state which has no corresponding physical location (e.g. tracking information for the top scoring players). To handle this use-case, Aether Engine creates a process dedicated to managing simulation global state.

Defining the Global State

We assume the visibility of the type octree_traits as discussed in General (Simulation). An implementation of a global state must inherit from aether::global_state_base<octree_traits>. We provide an example declaration where we call our class example_global_state:

// global_state.hh
class example_global_state : 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 global_state_base class require two functions to be implemented:

  • void process_messages(reader_type &reader, writer_type &writer)
    • called by Aether Engine each tick to send and receive messages from the global state process. The reader and writer types are documented in Messaging.
  • std::vector<subscriber_topic_type> get_topics()
    • called by Aether Engine each tick to determine which messages the global state is interested in (in additional to messages addressed directly to the global state). The operation of this function is identical to the function with the same name listed in the Messaging section.

Effectively, the global state process is a worker that can still send, receive and subscribe to messages, but does not take part in any of the any of the computation or communication related to simulating virtual space.

Configuring a simulation to use the global state

Once a global state implementation has been defined, the simulation can be configured to use it by calling a function on the parameters passed to the octree:

// 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_global_state>();
// Construct the manager
auto manager = aether::build_entity_simulation_manager<user_cell_state_impl>(
arguments.workers, static_args);
// ...
}