Skip to content

Lifecycle

Daniel Khaapamyaki edited this page Jan 7, 2022 · 14 revisions

Lifecycle

Create a new Gameworld

The entrypoint to our service is the creation of a new Gameworld.

You can create a new Gameworld by calling the POST /gameworlds endpoint.

This will call the GameworldBuilder.create_regular_gameworld method which will initialize the Gameworld, and build all Planets/Spacestations.

We build the planets in Memory with Hash datastructures first, and finally call the update_all method to insert the Gameworld, including the Planets, into the database in a single SQL query.

As soon as the Gameworld is created, we return the json payload to the caller of the POST request. All other Gameworlds statuses are set to "inactive"

There are several things happening asynchronously after the Gameworld is created:

  • Initialize Resources in a background worker
    • Depending on the size of a Gameworld creating every part of it synchronously could potentially block other processes, that's why the creation of resources is handled by a background worker.
  • Send out "gameworld-created" event
  • Send out "spacestation-created" events

Create a new Mining

You can create a new Mining by calling the POST /planets/:planet_id/mining endpoint.

As soon as the Mining is created the planet's resource's current_amount is decreased by the amount_requested. The json payload including the actual amount_mined is returned to the caller of the POST request.

Additionally we publish the resource-mined event.

Create a new Replenishment

A replenishment of a planet's resource is triggered internally by the map service. The current_amount of the resource is (re-)set to the max_amount

This action publishes the resource-replenished event.

Clone this wiki locally