Skip to content

Commit

Permalink
Remove SS_NO_TICK_CHECK (tgstation#57800)
Browse files Browse the repository at this point in the history
## About The Pull Request
This is a whopper, will need @MrStonedOne to review.
In theory this flag shouldn't be needed and my own testing didn't find any issues, but I'd feel better with a lengthy test merge.

## Why It's Good For The Game
Might make nightshift subsystem lag less, MC loop has less stuff to check.
  • Loading branch information
spookydonut authored Mar 28, 2021
1 parent e692b05 commit 9be229f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 39 deletions.
9 changes: 3 additions & 6 deletions code/__DEFINES/MC.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,20 @@
/// SS_BACKGROUND has its own priority bracket, this overrides SS_TICKER's priority bump
#define SS_BACKGROUND 4

/// subsystem does not tick check, and should not run unless there is enough time (or its running behind (unless background))
#define SS_NO_TICK_CHECK 8

/** Treat wait as a tick count, not DS, run every wait ticks. */
/// (also forces it to run first in the tick (unless SS_BACKGROUND))
/// (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 16
#define SS_TICKER 8

/** 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 32
#define SS_KEEP_TIMING 16

/** 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 64
#define SS_POST_FIRE_TIMING 32

//! SUBSYSTEM STATES
#define SS_IDLE 0 /// ain't doing shit.
Expand Down
17 changes: 0 additions & 17 deletions code/controllers/master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
var/tick_precentage
var/tick_remaining
var/ran = TRUE //this is right
var/ran_non_ticker = FALSE
var/bg_calc //have we swtiched current_tick_budget to background mode yet?
var/tick_usage

Expand All @@ -467,20 +466,6 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
if (!(queue_node_flags & SS_TICKER) && skip_ticks)
queue_node = queue_node.queue_next
continue
//super special case, subsystems where we can't make them pause mid way through
//if we can't run them this tick (without going over a tick)
//we bump up their priority and attempt to run them next tick
//(unless we haven't even ran anything this tick, since its unlikely they will ever be able run
// in those cases, so we just let them run)
if (queue_node_flags & SS_NO_TICK_CHECK)
if (queue_node.tick_usage > TICK_LIMIT_RUNNING - TICK_USAGE && ran_non_ticker)
if (!(queue_node_flags & SS_BACKGROUND))
queue_node.queued_priority += queue_priority_count * 0.1
queue_priority_count -= queue_node_priority
queue_priority_count += queue_node.queued_priority
current_tick_budget -= queue_node_priority
queue_node = queue_node.queue_next
continue

if (!bg_calc && (queue_node_flags & SS_BACKGROUND))
current_tick_budget = queue_priority_count_bg
Expand All @@ -497,8 +482,6 @@ GLOBAL_REAL(Master, /datum/controller/master) = new

current_ticklimit = round(TICK_USAGE + tick_precentage)

if (!(queue_node_flags & SS_TICKER))
ran_non_ticker = TRUE
ran = TRUE

queue_node_paused = (queue_node.state == SS_PAUSED || queue_node.state == SS_PAUSING)
Expand Down
1 change: 0 additions & 1 deletion code/controllers/subsystem/blackbox.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SUBSYSTEM_DEF(blackbox)
name = "Blackbox"
wait = 6000
flags = SS_NO_TICK_CHECK
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
init_order = INIT_ORDER_BLACKBOX

Expand Down
30 changes: 18 additions & 12 deletions code/controllers/subsystem/nightshift.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
SUBSYSTEM_DEF(nightshift)
name = "Night Shift"
wait = 600
flags = SS_NO_TICK_CHECK
wait = 10 MINUTES

var/nightshift_active = FALSE
var/nightshift_start_time = 702000 //7:30 PM, station time
var/nightshift_end_time = 270000 //7:30 AM, station time
var/nightshift_first_check = 30 SECONDS

var/high_security_mode = FALSE
var/list/currentrun

/datum/controller/subsystem/nightshift/Initialize()
if(!CONFIG_GET(flag/enable_night_shifts))
can_fire = FALSE
return ..()

/datum/controller/subsystem/nightshift/fire(resumed = FALSE)
if(resumed)
update_nightshift(resumed = TRUE)
return
if(world.time - SSticker.round_start_time < nightshift_first_check)
return
check_nightshift()
Expand All @@ -41,15 +44,18 @@ SUBSYSTEM_DEF(nightshift)
if(nightshift_active != night_time)
update_nightshift(night_time, announcing)

/datum/controller/subsystem/nightshift/proc/update_nightshift(active, announce = TRUE)
nightshift_active = active
if(announce)
if (active)
announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the lights aboard the station have been dimmed for the night.")
else
announce("Good morning, crew. As it is now day time, all of the lights aboard the station have been restored to their former brightness.")
for(var/A in GLOB.apcs_list)
var/obj/machinery/power/apc/APC = A
/datum/controller/subsystem/nightshift/proc/update_nightshift(active, announce = TRUE, resumed = FALSE)
if(!resumed)
currentrun = GLOB.apcs_list.Copy()
nightshift_active = active
if(announce)
if (active)
announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the lights aboard the station have been dimmed for the night.")
else
announce("Good morning, crew. As it is now day time, all of the lights aboard the station have been restored to their former brightness.")
for(var/obj/machinery/power/apc/APC as anything in currentrun)
currentrun -= APC
if (APC.area && (APC.area.type in GLOB.the_station_areas))
APC.set_nightshift(active)
CHECK_TICK
if(MC_TICK_CHECK)
return
1 change: 0 additions & 1 deletion code/controllers/subsystem/profiler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SUBSYSTEM_DEF(profiler)
init_order = INIT_ORDER_PROFILER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
wait = 3000
flags = SS_NO_TICK_CHECK
var/fetch_cost = 0
var/write_cost = 0

Expand Down
1 change: 0 additions & 1 deletion code/controllers/subsystem/sun.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SUBSYSTEM_DEF(sun)
name = "Sun"
wait = 1 MINUTES
flags = SS_NO_TICK_CHECK

var/azimuth = 0 ///clockwise, top-down rotation from 0 (north) to 359
var/azimuth_mod = 1 ///multiplier against base_rotation
Expand Down
1 change: 0 additions & 1 deletion code/controllers/subsystem/time_track.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SUBSYSTEM_DEF(time_track)
name = "Time Tracking"
wait = 100
flags = SS_NO_TICK_CHECK
init_order = INIT_ORDER_TIMETRACK
runlevels = RUNLEVEL_LOBBY | RUNLEVELS_DEFAULT

Expand Down

0 comments on commit 9be229f

Please sign in to comment.