Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cev_eris.dme
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
#include "code\__HELPERS\shell.dm"
#include "code\__HELPERS\spawn_sync.dm"
#include "code\__HELPERS\stack_trace.dm"
#include "code\__HELPERS\stoplag.dm"
#include "code\__HELPERS\text.dm"
#include "code\__HELPERS\time.dm"
#include "code\__HELPERS\turfs.dm"
Expand Down Expand Up @@ -276,6 +277,7 @@
#include "code\controllers\hooks-defs.dm"
#include "code\controllers\hooks.dm"
#include "code\controllers\master.dm"
#include "code\controllers\profiler.dm"
#include "code\controllers\subsystem.dm"
#include "code\controllers\verbs.dm"
#include "code\controllers\configuration\config_entry.dm"
Expand Down Expand Up @@ -394,7 +396,6 @@
#include "code\datums\http.dm"
#include "code\datums\interaction_particle.dm"
#include "code\datums\licences.dm"
#include "code\datums\loot_spawner.dm"
#include "code\datums\mind.dm"
#include "code\datums\mixed.dm"
#include "code\datums\mob_stats.dm"
Expand Down
49 changes: 42 additions & 7 deletions code/__DEFINES/MC.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define MC_AVG_SLOW_UP_FAST_DOWN(average, current) (average < current ? MC_AVERAGE_SLOW(average, current) : MC_AVERAGE_FAST(average, current))

///creates a running average of "things elapsed" per time period when you need to count via a smaller time period.
///eg you want an average number of things happening per second but you measure the event every tick (100 milliseconds).
///eg you want an average number of things happening per second but you measure the event every tick (50 milliseconds).
///make sure both time intervals are in the same units. doesnt work if current_duration > total_duration or if total_duration == 0
#define MC_AVG_OVER_TIME(average, current, total_duration, current_duration) ((((total_duration) - (current_duration)) / (total_duration)) * (average) + (current))

Expand Down Expand Up @@ -58,32 +58,49 @@ if(Datum.is_processing) {\
//! SubSystem flags (Please design any new flags so that the default is off, to make adding flags to subsystems easier)

/// subsystem does not initialize.
#define SS_NO_INIT 1
#define SS_NO_INIT (1 << 0)

/** subsystem does not fire. */
/// (like can_fire = 0, but keeps it from getting added to the processing subsystems list)
/// (Requires a MC restart to change)
#define SS_NO_FIRE 2
#define SS_NO_FIRE (1 << 1)

/** Subsystem only runs on spare cpu (after all non-background subsystems have ran that tick) */
/// SS_BACKGROUND has its own priority bracket, this overrides SS_TICKER's priority bump
#define SS_BACKGROUND 4
#define SS_BACKGROUND (1 << 2)

/** Treat wait as a tick count, not DS, run every wait ticks. */
/// (also forces it to run first in the tick (unless SS_BACKGROUND))
/// (We don't want to be choked out by other subsystems queuing into us)
/// (implies all runlevels because of how it works)
/// This is designed for basically anything that works as a mini-mc (like SStimer)
#define SS_TICKER 8
#define SS_TICKER (1 << 3)

/** keep the subsystem's timing on point by firing early if it fired late last fire because of lag */
/// ie: if a 20ds subsystem fires say 5 ds late due to lag or what not, its next fire would be in 15ds, not 20ds.
#define SS_KEEP_TIMING 16
#define SS_KEEP_TIMING (1 << 4)

/** Calculate its next fire after its fired. */
/// (IE: if a 5ds wait SS takes 2ds to run, its next fire should be 5ds away, not 3ds like it normally would be)
/// This flag overrides SS_KEEP_TIMING
#define SS_POST_FIRE_TIMING 32
#define SS_POST_FIRE_TIMING (1 << 5)

/// If this subsystem doesn't initialize, it should not report as a hard error in CI.
/// This should be used for subsystems that are flaky for complicated reasons, such as
/// the Lua subsystem, which relies on auxtools, which is unstable.
/// It should not be used simply to silence CI.
#define SS_OK_TO_FAIL_INIT (1 << 6)

/// This subsystem should not be queued if it has no work.
/// Populate the [hibernate_checks] list with the names of vars to check before a subsystem is queued.
/// If the length() of each var is 0, it will not be queued.
#define SS_HIBERNATE (1 << 7)

/// Don't show when this has init'd
#define SS_NO_INIT_MESSAGE (1 << 8)

/// Allows the subsystem to be dynamically swapped between backgrounding.
#define SS_DYNAMIC (1 << 9)

//! SUBSYSTEM STATES
#define SS_IDLE 0 /// ain't doing shit.
Expand All @@ -102,6 +119,7 @@ if(Datum.is_processing) {\
/datum/controller/subsystem/##X/New(){\
NEW_SS_GLOBAL(SS##X);\
PreInit();\
ss_id=#X;\
}\
/datum/controller/subsystem/##X

Expand All @@ -113,10 +131,27 @@ if(Datum.is_processing) {\
/datum/controller/subsystem/timer/##X/fire() {..() /*just so it shows up on the profiler*/} \
/datum/controller/subsystem/timer/##X

#define MOVEMENT_SUBSYSTEM_DEF(X) GLOBAL_REAL(SS##X, /datum/controller/subsystem/movement/##X);\
/datum/controller/subsystem/movement/##X/New(){\
NEW_SS_GLOBAL(SS##X);\
PreInit();\
}\
/datum/controller/subsystem/movement/##X/fire() {..() /*just so it shows up on the profiler*/} \
/datum/controller/subsystem/movement/##X

#define PROCESSING_SUBSYSTEM_DEF(X) GLOBAL_REAL(SS##X, /datum/controller/subsystem/processing/##X);\
/datum/controller/subsystem/processing/##X/New(){\
NEW_SS_GLOBAL(SS##X);\
PreInit();\
ss_id="processing_[#X]";\
}\
/datum/controller/subsystem/processing/##X/fire() {..() /*just so it shows up on the profiler*/} \
/datum/controller/subsystem/processing/##X

#define MOBS_SUBSYSTEM_DEF(X) GLOBAL_REAL(SS##X, /datum/controller/subsystem/mobs/##X);\
/datum/controller/subsystem/mobs/##X/New(){\
NEW_SS_GLOBAL(SS##X);\
PreInit();\
}\
/datum/controller/subsystem/mobs/##X/fire() {..() /*just so it shows up on the profiler*/} \
/datum/controller/subsystem/mobs/##X
22 changes: 0 additions & 22 deletions code/__DEFINES/gamemode.dm
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@

//SSticker.current_state values
/// Game is loading
#define GAME_STATE_STARTUP 0
/// Game is loaded and in pregame lobby
#define GAME_STATE_PREGAME 1
/// Game is attempting to start the round
#define GAME_STATE_SETTING_UP 2
/// Game has round in progress
#define GAME_STATE_PLAYING 3
/// Game has round finished
#define GAME_STATE_FINISHED 4

// Used for SSticker.force_ending
/// Default, round is not being forced to end.
#define END_ROUND_AS_NORMAL 0
/// End the round now as normal
#define FORCE_END_ROUND 1
/// For admin forcing roundend, can be used to distinguish the two
#define ADMIN_FORCE_END_ROUND 2


#define BE_PLANT "BE_PLANT"
#define BE_SYNTH "BE_SYNTH"
#define BE_PAI "BE_PAI"
Expand Down
2 changes: 0 additions & 2 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define INVISIBILITY_ABSTRACT 101 //only used for abstract objects (e.g. spacevine_controller), things that are not really there.

// Some arbitrary defines to be used by self-pruning global lists.
#define PROCESS_KILL 26 // Used to trigger removal from a processing list.
#define MAX_GEAR_COST 5 // Used in chargen for accessory loadout limit.

// For secHUDs and medHUDs and variants. The number is the location of the image on the list hud_list of humans.
Expand Down Expand Up @@ -374,6 +373,5 @@
#define TRACY_DLL_PATH (world.system_type == MS_WINDOWS ? "prof.dll" : "./libprof.so")

/// Path for the byond-memorystats dll

#define MEMORYSTATS_DLL_PATH (world.system_type == MS_WINDOWS ? "memorystats.dll" : "./libmemorystats.so")

2 changes: 1 addition & 1 deletion code/__DEFINES/subsystems-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SS_TICKER
// < none >

var/list/bitflags = list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)
GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768))

#define FIRE_PRIORITY_DEFAULT 50 // Default priority for both normal and background processes

Expand Down
86 changes: 83 additions & 3 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! Defines for subsystems and overlays
//!
//! Lots of important stuff in here, make sure you have your brain switched on
//! when editing this file
// "My brain was never on to begin with. what makes you think I'll turn it on now?"

//! ## DB defines
/**
Expand Down Expand Up @@ -63,6 +68,9 @@
#define FLIGHTSUIT_PROCESSING_NONE 0
#define FLIGHTSUIT_PROCESSING_FULL 1

/// Used to trigger object removal from a processing list
#define PROCESS_KILL 26

//! ## Initialization subsystem

///New should not call Initialize
Expand Down Expand Up @@ -91,6 +99,7 @@
///Call qdel with a force of TRUE after initialization
#define INITIALIZE_HINT_QDEL_FORCE 3

//TODO: initialized and other stuff needs to be changed to `flags_1`
///type and all subtypes should always immediately call Initialize in New()
#define INITIALIZE_IMMEDIATE(X) ##X/New(loc, ...){\
..();\
Expand All @@ -103,10 +112,30 @@
}\
}

//! ### SS initialization hints
/**
* Negative values incidate a failure or warning of some kind, positive are good.
* 0 and 1 are unused so that TRUE and FALSE are guarenteed to be invalid values.
*/

/// Subsystem failed to initialize entirely. Print a warning, log, and disable firing.
#define SS_INIT_FAILURE -2

/// The default return value which must be overriden. Will succeed with a warning.
#define SS_INIT_NONE -1

/// Subsystem initialized sucessfully.
#define SS_INIT_SUCCESS 2

/// Successful, but don't print anything. Useful if subsystem was disabled.
#define SS_INIT_NO_NEED 3

//! ### SS initialization load orders
// Subsystem init_order, from highest priority to lowest priority
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.

#define INIT_ORDER_PROFILER 101
#define INIT_ORDER_GARBAGE 99
#define INIT_ORDER_CHUNKS 95
#define INIT_ORDER_DBCORE 85
Expand Down Expand Up @@ -189,11 +218,33 @@ if(Datum.is_processing) {\
#define START_PROCESSING_POWER_OBJECT(Datum) START_PROCESSING_IN_LIST(Datum, power_objects)
#define STOP_PROCESSING_POWER_OBJECT(Datum) STOP_PROCESSING_IN_LIST(Datum, power_objects)

/// The timer key used to know how long subsystem initialization takes
#define SS_INIT_TIMER_KEY "ss_init"

#define SS_HOLOMAPS_TIMER_KEY "ss_holomaps"

//Hibernation states
#define SS_NOT_HIBERNATING 0
#define SS_WAKING_UP 1
#define SS_IS_HIBERNATING 2

//SSticker.current_state values
/// Game is loading
#define GAME_STATE_STARTUP 0
/// Game is loaded and in pregame lobby
#define GAME_STATE_PREGAME 1
/// Game is attempting to start the round
#define GAME_STATE_SETTING_UP 2
/// Game has round in progress
#define GAME_STATE_PLAYING 3
/// Game has round finished
#define GAME_STATE_FINISHED 4

// Used for SSticker.force_ending
/// Default, round is not being forced to end.
#define END_ROUND_AS_NORMAL 0
/// End the round now as normal
#define FORCE_END_ROUND 1
/// For admin forcing roundend, can be used to distinguish the two
#define ADMIN_FORCE_END_ROUND 2

/**
Create a new timer and add it to the queue.
* Arguments:
Expand All @@ -203,3 +254,32 @@ if(Datum.is_processing) {\
* * timer_subsystem the subsystem to insert this timer into
*/
#define addtimer(args...) _addtimer(args, file = __FILE__, line = __LINE__)

// Air subsystem subtasks
#define SSAIR_PIPENETS 1
#define SSAIR_ATMOSMACHINERY 2
#define SSAIR_TILES_CUR 3
#define SSAIR_TILES_DEF 4
#define SSAIR_EDGES 5
#define SSAIR_FIRE_ZONES 6
#define SSAIR_HOTSPOTS 7
#define SSAIR_ZONES 8

#define SSAIR_TICK_MULTIPLIER 2


// Subsystem delta times or tickrates, in seconds. I.e, how many seconds in between each process() call for objects being processed by that subsystem.
// Only use these defines if you want to access some other objects processing seconds_per_tick, otherwise use the seconds_per_tick that is sent as a parameter to process()
// #define SSFLUIDS_DT (SSplumbing.wait/10)
#define SSMACHINES_DT (SSmachines.wait/10)
#define SSMOBS_DT (SSmobs.wait/10)
#define SSOBJ_DT (SSobj.wait/10)

/// The change in the world's time from the subsystem's last fire in seconds.
#define DELTA_WORLD_TIME(ss) ((world.time - ss.last_fire) * 0.1)

/// Same as DELTA_WORLD_TIME but we ignore time spent hibernating
#define DELTA_WORLD_TIME_WITHOUT_HIBERNATION(ss) ss.hibernation_state ? ss.wait : DELTA_WORLD_TIME(ss)

/// The timer key used to know how long subsystem initialization takes
#define SS_INIT_TIMER_KEY "ss_init"
2 changes: 1 addition & 1 deletion code/__HELPERS/_global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GLOBAL_LIST_EMPTY_TYPED(world_uplinks, /obj/item/device/uplink)
GLOBAL_LIST_EMPTY_TYPED(krabin_linked, /mob/living/carbon/human)

// Announcer intercom, because too much stuff creates an intercom for one message then hard del()s it.
GLOBAL_DATUM(announcer, /obj/item/device/radio/intercom)
GLOBAL_DATUM_INIT(announcer, /obj/item/device/radio/intercom, new())

GLOBAL_LIST_EMPTY(lastsignalers) // Keeps last 100 signals here in format: "[src] used \ref[src] @ location [src.loc]: [freq]/[code]"

Expand Down
27 changes: 27 additions & 0 deletions code/__HELPERS/stoplag.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//Increases delay as the server gets more overloaded,
//as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
#define DELTA_CALC max(((max(world.tick_usage, world.cpu) / 100) * max(Master.sleep_delta,1)), 1)

///returns the number of ticks slept
/proc/stoplag(initial_delay)
if (!Master || Master.init_stage_completed < INITSTAGE_MAX)
sleep(world.tick_lag)
return 1
if (!initial_delay)
initial_delay = world.tick_lag
// Unit tests are not the normal environemnt. The mc can get absolutely thigh crushed, and sleeping procs running for ages is much more common
// We don't want spurious hard deletes off this, so let's only sleep for the requested period of time here yeah?
#ifdef UNIT_TESTS
sleep(initial_delay)
return CEILING(DS2TICKS(initial_delay), 1)
#else
. = 0
var/i = DS2TICKS(initial_delay)
do
. += CEILING(i * DELTA_CALC, 1)
sleep(i * world.tick_lag * DELTA_CALC)
i *= 2
while (TICK_USAGE > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))
#endif

#undef DELTA_CALC
17 changes: 0 additions & 17 deletions code/__HELPERS/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,3 @@ GLOBAL_VAR_INIT(rollovercheck_last_timeofday, 0)
response += "[counter][ticks?".[ticks]" : ""] Second[counter>1 ? "s" : ""]"
return response

//Increases delay as the server gets more overloaded,
//as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
#define DELTA_CALC max(((max(world.tick_usage, world.cpu) / 100) * max(Master.sleep_delta,1)), 1)

/proc/stoplag()
if (!Master || !(Master.current_runlevel & RUNLEVELS_DEFAULT))
sleep(world.tick_lag)
return 1
. = 0
var/i = 1
do
. += round(i*DELTA_CALC)
sleep(i*world.tick_lag*DELTA_CALC)
i *= 2
while (world.tick_usage > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))

#undef DELTA_CALC
Loading
Loading