-
Notifications
You must be signed in to change notification settings - Fork 516
Singletons
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.
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"
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)
A collection of standards and guidelines applied to the codebase.
Documentation regarding common APIs which speed up feature implementation and should be known by all coders.
- Atom Initialization
- Garbage, Queued Deletion, and Destroy
- Callbacks
- Timers
- Lazy Lists
- Overlays
- Processing APIs
- Common Helpers
- Global Listeners
- Singletons
Documentation for less used APIs that are not often needed.
Documentation regarding our implementation of StonedMC (SMC).
Decrepit or unused systems.
- Dynamic Maps (Not to be confused with the newer away mission implementation.)