Skip to content

Commit

Permalink
DPC
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustKisik committed Jul 7, 2024
1 parent da23970 commit cee068f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// SS_TICKER
#define SS_PRIORITY_OVERLAY 100 // Applies overlays. May cause overlay pop-in if it gets behind.
#define SS_PRIORITY_TIMER 20
#define SS_PRIORITY_DPC 19 //SS220 ADD

// Normal
#define SS_PRIORITY_TICKER 100 // Gameticker.
Expand Down
37 changes: 37 additions & 0 deletions code/controllers/subsystems/dpc.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This is pretty much just an optimization for wait=0 timers. They're relatively common, but generally don't actually need the more
complex features of SStimer. SSdpc can handle these timers instead (and it's a lot simpler than SStimer is), but it can't handle
complex timers with flags. This doesn't need to be explicitly used, eligible timers are automatically converted.
*/

SUBSYSTEM_DEF(dpc)
name = "Delayed Procedure Call"
wait = 1
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
priority = SS_PRIORITY_DPC
flags = SS_TICKER | SS_NO_INIT

var/list/queued_calls = list()
var/list/avg = 0

/datum/controller/subsystem/dpc/stat_entry()
return ..() + " Q: [queued_calls.len], AQ: ~[round(avg)]"

/datum/controller/subsystem/dpc/fire(resumed = FALSE)
var/list/qc = queued_calls
if (!resumed)
avg = MC_AVERAGE_FAST(avg, qc.len)

var/q_idex = 1

while (q_idex <= qc.len)
var/datum/callback/CB = qc[q_idex]
q_idex += 1

CB.InvokeAsync()

if (MC_TICK_CHECK)
break

if (q_idex > 1)
queued_calls.Cut(1, q_idex)
6 changes: 6 additions & 0 deletions code/controllers/subsystems/timer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ SUBSYSTEM_DEF(timer)
PRINT_STACK_TRACE("addtimer called with a callback assigned to a qdeleted object. In the future such timers will not \
be supported and may refuse to run or run with a 0 wait")

// SS220 ADD BEGIN
if (wait == 0 && !flags)
SSdpc.queued_calls += callback
return
// SS220 ADD END

wait = max(NONUNIT_CEILING(wait, world.tick_lag), world.tick_lag)

if(wait >= INFINITY)
Expand Down
1 change: 1 addition & 0 deletions nebula.dme
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
#include "code\controllers\subsystems\configuration.dm"
#include "code\controllers\subsystems\daycycle.dm"
#include "code\controllers\subsystems\disposals.dm"
#include "code\controllers\subsystems\dpc.dm"
#include "code\controllers\subsystems\evac.dm"
#include "code\controllers\subsystems\event.dm"
#include "code\controllers\subsystems\fluids.dm"
Expand Down

0 comments on commit cee068f

Please sign in to comment.