Skip to content

Commit

Permalink
mc update: init stages, better subsystem init tracking, etc (#6857)
Browse files Browse the repository at this point in the history
modifies the hollow metrics API; that'll probably be implemented soon
adds init stages
changes SSatoms to not abuse its `initialized` variable

closes #6858
  • Loading branch information
silicons authored Nov 15, 2024
1 parent 33a0709 commit 9d6a141
Show file tree
Hide file tree
Showing 102 changed files with 1,343 additions and 925 deletions.
20 changes: 15 additions & 5 deletions citadel.dme
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#include "code\__DEFINES\maps.dm"
#include "code\__DEFINES\math.dm"
#include "code\__DEFINES\matrices.dm"
#include "code\__DEFINES\MC.dm"
#include "code\__DEFINES\metrics.dm"
#include "code\__DEFINES\misc.dm"
#include "code\__DEFINES\move_force.dm"
#include "code\__DEFINES\movement.dm"
Expand Down Expand Up @@ -156,9 +156,14 @@
#include "code\__DEFINES\combat\damage.dm"
#include "code\__DEFINES\combat\explosions.dm"
#include "code\__DEFINES\combat\shieldcall.dm"
#include "code\__DEFINES\controllers\_repositories.dm"
#include "code\__DEFINES\controllers\_subsystems.dm"
#include "code\__DEFINES\controllers\_master-runlevel.dm"
#include "code\__DEFINES\controllers\_master.dm"
#include "code\__DEFINES\controllers\_repository.dm"
#include "code\__DEFINES\controllers\_subsystem-init.dm"
#include "code\__DEFINES\controllers\_subsystem-priority.dm"
#include "code\__DEFINES\controllers\_subsystem.dm"
#include "code\__DEFINES\controllers\assets.dm"
#include "code\__DEFINES\controllers\atoms.dm"
#include "code\__DEFINES\controllers\dbcore.dm"
#include "code\__DEFINES\controllers\grids.dm"
#include "code\__DEFINES\controllers\persistence.dm"
Expand Down Expand Up @@ -570,7 +575,6 @@
#include "code\controllers\subsystem\legacy_atc.dm"
#include "code\controllers\subsystem\legacy_lore.dm"
#include "code\controllers\subsystem\lighting.dm"
#include "code\controllers\subsystem\lobby.dm"
#include "code\controllers\subsystem\machines.dm"
#include "code\controllers\subsystem\materials.dm"
#include "code\controllers\subsystem\media_tracks.dm"
Expand Down Expand Up @@ -606,6 +610,7 @@
#include "code\controllers\subsystem\ticker.dm"
#include "code\controllers\subsystem\time_track.dm"
#include "code\controllers\subsystem\timer.dm"
#include "code\controllers\subsystem\titlescreen.dm"
#include "code\controllers\subsystem\transcore_vr.dm"
#include "code\controllers\subsystem\transfer.dm"
#include "code\controllers\subsystem\turbolift.dm"
Expand Down Expand Up @@ -3494,9 +3499,14 @@
#include "code\modules\media\media_tracks.dm"
#include "code\modules\media\mediamanager.dm"
#include "code\modules\media\walkpod.dm"
#include "code\modules\metrics\api.dm"
#include "code\modules\metrics\metric.dm"
#include "code\modules\metrics\metric_base.dm"
#include "code\modules\metrics\api\nested_numerical.dm"
#include "code\modules\metrics\api\numerical.dm"
#include "code\modules\metrics\api\spatial_series.dm"
#include "code\modules\metrics\api\string_set.dm"
#include "code\modules\metrics\api\time_series.dm"
#include "code\modules\metrics\metrics\controllers.dm"
#include "code\modules\mining\mine_turfs.dm"
#include "code\modules\mining\drilling\drill.dm"
#include "code\modules\mining\drilling\scanner.dm"
Expand Down
118 changes: 0 additions & 118 deletions code/__DEFINES/MC.dm

This file was deleted.

32 changes: 32 additions & 0 deletions code/__DEFINES/controllers/_master-runlevel.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//* Runlevels *//
//* Must be powers of 2. Runlevels should be in order of progression. *//
//* Only subsystem with a runlevel matching the MC's will be ticked. *//
//* The first runlevel (value '1') will be the default runlevel when the MC is first initialized. *//

/// "Initialize Only" - Used for subsystems that should never be fired (Should also have SS_NO_FIRE set).
#define RUNLEVEL_INIT 0
/// Initial runlevel before setup. Returns to here if setup fails.
#define RUNLEVEL_LOBBY 1
/// While the gamemode setup is running. I.E gameticker.setup()
#define RUNLEVEL_SETUP 2
/// After successful game ticker setup, while the round is running.
#define RUNLEVEL_GAME 4
/// When round completes but before reboot.
#define RUNLEVEL_POSTGAME 8

/// default runlevels for most subsystems
#define RUNLEVELS_DEFAULT (RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME)
/// all valid runlevels - subsystems with this will run all the time after their MC init stage.
#define RUNLEVELS_ALL (RUNLEVEL_LOBBY | RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME)

var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_GAME, RUNLEVEL_POSTGAME)
/// Convert from the runlevel bitfield constants to index in runlevel_flags list.
#define RUNLEVEL_FLAG_TO_INDEX(flag) (log(2, flag) + 1)

DEFINE_BITFIELD(runlevels, list(
BITFIELD(RUNLEVEL_INIT),
BITFIELD(RUNLEVEL_LOBBY),
BITFIELD(RUNLEVEL_SETUP),
BITFIELD(RUNLEVEL_GAME),
BITFIELD(RUNLEVEL_POSTGAME),
))
59 changes: 59 additions & 0 deletions code/__DEFINES/controllers/_master.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This file (and its -dash files) is called MC, but actually holds quite a lot of logic including init orders
* and subsystems as the MC and subsystems make up the global orchestration system of the codebase.
*/

#define MC_TICK_CHECK ( ( TICK_USAGE > Master.current_ticklimit || src.state != SS_RUNNING ) ? pause() : 0 )
#define MC_TICK_CHECK_USAGE ( ( TICK_USAGE > Master.current_ticklimit ) ? pause() : 0 )

#define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = Master.current_ticklimit; var/split_tick_phases = ##phase_count
#define MC_SPLIT_TICK \
if(split_tick_phases > 1){\
Master.current_ticklimit = ((original_tick_limit - TICK_USAGE) / split_tick_phases) + TICK_USAGE;\
--split_tick_phases;\
} else {\
Master.current_ticklimit = original_tick_limit;\
}

// Used to smooth out costs to try and avoid oscillation.
#define MC_AVERAGE_FAST(average, current) (0.7 * (average) + 0.3 * (current))
#define MC_AVERAGE(average, current) (0.8 * (average) + 0.2 * (current))
#define MC_AVERAGE_SLOW(average, current) (0.9 * (average) + 0.1 * (current))

#define MC_AVG_FAST_UP_SLOW_DOWN(average, current) (average > current ? MC_AVERAGE_SLOW(average, current) : MC_AVERAGE_FAST(average, current))
#define MC_AVG_SLOW_UP_FAST_DOWN(average, current) (average < current ? MC_AVERAGE_SLOW(average, current) : MC_AVERAGE_FAST(average, current))

#define START_PROCESSING(Processor, Datum) if (!(Datum.datum_flags & DF_ISPROCESSING)) {Datum.datum_flags |= DF_ISPROCESSING;Processor.processing += Datum}
#define STOP_PROCESSING(Processor, Datum) Datum.datum_flags &= ~DF_ISPROCESSING;Processor.processing -= Datum

/// Returns true if the MC is initialized and running.
/// Optional argument init_stage controls what stage the mc must have initializted to count as initialized. Defaults to INITSTAGE_MAX if not specified.
#define MC_RUNNING(INIT_STAGE...) (Master && Master.processing > 0 && Master.current_runlevel && Master.init_stage_completed == (max(min(INIT_STAGE_MAX, ##INIT_STAGE), 1)))
/// Returns true if the MC is at atleast a given init stage. Defaults to fully initialized.
///
/// * This does not check anything else about the MC, including if it's actually running.
#define MC_INITIALIZED(INIT_STAGE...) (Master?.init_stage_completed >= max(INIT_STAGE_MAX, ##INIT_STAGE))

//* Recreate_MC() return values *//

#define MC_RESTART_RTN_FAILED -1
#define MC_RESTART_RTN_COOLDOWN 0
#define MC_RESTART_RTN_SUCCESS 1

//* Master Controller Loop() return values *//

/// Unknown or error
#define MC_LOOP_RTN_UNKNOWN 0
/// New initialize stage happened
#define MC_LOOP_RTN_NEWSTAGES 1
/// We want the MC to exit.
#define MC_LOOP_RTN_GRACEFUL_EXIT 2

//* Master Controller RunQueue() return values *//

/// Unknown or error
#define MC_RUN_RTN_UNKNOWN 0
/// Success; full completion
#define MC_RUN_RTN_FULL_COMPLETION 1
/// Atleast one subsystem was sleeping or pausing
#define MC_RUN_RTN_PARTIAL_COMPLETION 2
File renamed without changes.
92 changes: 92 additions & 0 deletions code/__DEFINES/controllers/_subsystem-init.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//* Initialization Stages *//
//* After each stage, the MC starts ticking that stage while later stages are still waiting to init. *//
//* MC init stages must be a positive number, and init stages must all be consequetive! *//

/// Early initializations required for server function; database, timers, tgui, etc
#define INIT_STAGE_BACKEND 1
/// Pre-mapload initializations
#define INIT_STAGE_EARLY 2
/// Mapload
#define INIT_STAGE_WORLD 3
/// Late
#define INIT_STAGE_LATE 4

/// Last init stage we need to do.
///
/// * This must be set to the maximum INIT_STAGE.
#define INIT_STAGE_MAX 4

//* Initialization Orders *//

/**
*! Subsystem init_order, from highest priority to lowest priority.
*? Subsystems shutdown in the reverse of the order they initialize in.
*? Subsystems should always have init_order defined, even if they don't initialize, if they use init.
*? The numbers just define the ordering, they are meaningless otherwise.
*/

//* Backend *//

#define INIT_ORDER_FAIL2TOPIC 100
#define INIT_ORDER_DBCORE 50
#define INIT_ORDER_REPOSITORY 25
#define INIT_ORDER_TIMER 10
#define INIT_ORDER_STATPANELS 0

//* Early *//

#define INIT_ORDER_EARLY_INIT 200
#define INIT_ORDER_INPUT 170
#define INIT_ORDER_PREFERENCES 150
#define INIT_ORDER_JOBS 125
#define INIT_ORDER_ASSETS 100
#define INIT_ORDER_INSTRUMENTS 50
#define INIT_ORDER_AI_SCHEDULING 25
#define INIT_ORDER_AI_MOVEMENT 25
#define INIT_ORDER_AI_HOLDERS 25

//* World *//

#define INIT_ORDER_CHARACTERS 140
#define INIT_ORDER_SOUNDS 130
#define INIT_ORDER_GARBAGE 120
#define INIT_ORDER_VIS 90
#define INIT_ORDER_SERVER_MAINT 75
#define INIT_ORDER_MEDIA_TRACKS 65
#define INIT_ORDER_CHEMISTRY 60
#define INIT_ORDER_MATERIALS 55
#define INIT_ORDER_PHOTOGRAPHY 50
#define INIT_ORDER_MAPPING 45
#define INIT_ORDER_SPATIAL_GRIDS 43 //! must be after SSmapping so we know world.maxx and world.maxy
#define INIT_ORDER_GAME_WORLD 40
#define INIT_ORDER_LEGACY_ATC 37
#define INIT_ORDER_LEGACY_LORE 35
#define INIT_ORDER_PLANTS 25
#define INIT_ORDER_ALARMS 20
#define INIT_ORDER_RESEARCH 17
#define INIT_ORDER_ATOMS 15
#define INIT_ORDER_MACHINES 10
#define INIT_ORDER_SHUTTLES 3
#define INIT_ORDER_DEFAULT 0
#define INIT_ORDER_AIR -1
#define INIT_ORDER_PLANETS -2
#define INIT_ORDER_PERSISTENCE -3
#define INIT_ORDER_AMBIENT_OCCLUSION -5
#define INIT_ORDER_HOLOMAPS -5
#define INIT_ORDER_ICON_SMOOTHING -6
#define INIT_ORDER_EVENTS -10
#define INIT_ORDER_OVERMAPS -20
#define INIT_ORDER_TICKER -30
#define INIT_ORDER_LIGHTING -40
#define INIT_ORDER_ZMIMIC -45
#define INIT_ORDER_AMBIENT_LIGHT -46
#define INIT_ORDER_XENOARCH -50
#define INIT_ORDER_CIRCUIT -60
#define INIT_ORDER_AI -70

//* Late *//

#define INIT_ORDER_OVERLAY 200
#define INIT_ORDER_TITLESCREEN 150
#define INIT_ORDER_NIGHTSHIFT 75
#define INIT_ORDER_CHAT -100 //! Should be last to ensure chat remains smooth during init.
Loading

0 comments on commit 9d6a141

Please sign in to comment.