Skip to content

Atom Initialization

Erki edited this page Jun 16, 2018 · 5 revisions

The /atom initialization process has changed dramatically. All /atom types including /turf and /area can use Initialize(), and arguments to New() are passed along to Initialize().

New() and Initialize() overrides should not be mixed when possible as one is not guaranteed to occur before the other; their order varies based on when the atom is created.

Basic Usage

Overriding/defining New() should be avoided when possible in favor of Initialize().

Initialize() always has at least one argument: mapload. It is always the first argument. mapload is TRUE if the atom is being initialized during map loading (such as at server startup), FALSE otherwise. If any other arguments are passed to New(), they will come after mapload. Initialize must return parent or call parent and return an initialization hint.

Example:

/obj/myobj/Initialize(mapload)
	. = ..()
	if (mapload)
		world << "[src] initialized at mapload!"
	else
		world << "[src] initialized normally!"

Important notice: sleeping in Initialize and LateInitialize is not permitted. Doing so would interrupt the game controller's work order. If you need to sleep in Initialize, for example, in cases of pulling large data, you can use a 0-delay timer or INVOKE_ASYNC.

Initialization Hints

Initialize can return a hint instead of parent (although parent should still be called), allowing for special post-initialization behavior. The following hints are understood.

INITIALIZE_HINT_NORMAL -> Default. Nothing special happens.

INITIALIZE_HINT_LATELOAD -> LateInitialize() is called.

INITIALIZE_HINT_QDEL -> The atom is qdeleted after Initialize() returns.

INITIALIZE_HINT_LATEQDEL -> The atom is qdeleted after server initialization completes, or immediately after Initialize() if the server is already initialized.

LateInitialize()

LateInitialize() is another initialization proc that can be defined to do things that require the rest of the objects in the world to be initialized first. It does not need to return anything or call parent.

Example:

/obj/myobj/Initialize()
	..()
	world << "[src] initialized!"
	return INITIALIZE_HINT_LATELOAD

/obj/myobj/LateInitialize()
	world << "[src] late initialized!"

LateInitialize() will only be called if Initialize() returns INITIALIZE_HINT_LATELOAD. If the atom is initialized during server load, it will LateInitialize() after all Initialize() calls complete. If the atom is initialized later, LateInitialize() will be called immediately after Initialize().

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