Skip to content
Matt Atlas edited this page Jan 10, 2023 · 2 revisions

Singletons, full type being /datum/singleton, are a class of lazy-initialized global singletons for holding shared information and state. They are unique by type.

Let's unpack a little:

  • Lazy-initialized: a singleton of a given type does not exist until it has first been queried. After that, it will remain alive in the game world.
  • Global singleton: a single instance of every singleton subtype should exist at any one time. This instance is shared between all users.
  • Unique by type: the "name" of a singleton is its full type. As mentioned before, no more than one instance of any singleton type should exist.

Basic Usage

Behind the scenes, singletons are simple datums with a special interaction via the Singletons repository, accessed through the GET_SINGLETON() defines. So you can simply create them as you would create a unique datum class:

/singleton/my_singleton
	var/a = 4

As said, this class gets created once we first query for it. To do so, we simply use the GET_SINGLETON(singleton) define:

/proc/main()
	var/singleton/my_singleton/s = GET_SINGLETON(/singleton/my_singleton)
	world << s.a // will print "4"

Variations

The Singletons contains functions to get multiple singleton, or all types of a specific singleton, or all subtypes. See the following defines:

  • GET_SINGLETON_TYPE_MAP(singleton)
  • GET_SINGLETON_SUBTYPE_MAP(singleton)
  • GET_SINGLETON_TYPE_LIST(singleton)
  • GET_SINGLETON_SUBTYPE_LIST(singleton)

Standards and Guidelines

A collection of standards and guidelines applied to the codebase.

Common API Documentation

Documentation regarding common APIs which speed up feature implementation and should be known by all coders.

Less Common APIs

Documentation for less used APIs that are not often needed.

Subsystems

Documentation regarding our implementation of StonedMC (SMC).

Decrepit

Decrepit or unused systems.

  • Dynamic Maps (Not to be confused with the newer away mission implementation.)
Clone this wiki locally