Skip to content

Commit

Permalink
qdel optimize (shiptest-ss13#3558)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

That PR optimizes qdel and SSgarbage procs.

Based on:
tgstation/tgstation#79568
tgstation/tgstation#76956
tgstation/tgstation#80443
tgstation/tgstation#80628

## Why It's Good For The Game

Better performance. Tested on downstream:
CeladonSS13#1025

## Changelog

:cl:
code: Changing qdel() and SSgarbage procs
code: rewrite /Destroy(force, silent) to /Destroy(force)
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Signed-off-by: Feenie <[email protected]>
  • Loading branch information
FeenieRU authored and zimon9 committed Oct 29, 2024
1 parent 82ef5c7 commit d3c9dd6
Show file tree
Hide file tree
Showing 28 changed files with 426 additions and 284 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/dcs/signals/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define COMSIG_COMPONENT_REMOVING "component_removing"
/// before a datum's Destroy() is called: (force), returning a nonzero value will cancel the qdel operation
#define COMSIG_PARENT_PREQDELETED "parent_preqdeleted"
#define COMSIG_PREQDELETED "parent_preqdeleted"
/// just before a datum's Destroy() is called: (force), at this point none of the other components chose to interrupt qdel and Destroy will be called
#define COMSIG_PARENT_QDELETING "parent_qdeleting"
/// generic topic handler (usr, href_list)
Expand Down
4 changes: 4 additions & 0 deletions code/controllers/master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
continue
if ((SS_flags & (SS_TICKER|SS_KEEP_TIMING)) == SS_KEEP_TIMING && SS.last_fire + (SS.wait * 0.75) > world.time)
continue
if (SS.postponed_fires >= 1)
SS.postponed_fires--
SS.update_nextfire()
continue
SS.enqueue()
. = 1

Expand Down
27 changes: 25 additions & 2 deletions code/controllers/subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
/// Tracks the amount of completed runs for the subsystem
var/times_fired = 0

/// How many fires have we been requested to postpone
var/postponed_fires = 0

/// Time the subsystem entered the queue, (for timing and priority reasons)
var/queued_time = 0

Expand Down Expand Up @@ -132,6 +135,26 @@
Master.subsystems -= src
return ..()

/datum/controller/subsystem/proc/update_nextfire(reset_time = FALSE)
var/queue_node_flags = flags

if (reset_time)
postponed_fires = 0
if (queue_node_flags & SS_TICKER)
next_fire = world.time + (world.tick_lag * wait)
else
next_fire = world.time + wait
return

if (queue_node_flags & SS_TICKER)
next_fire = world.time + (world.tick_lag * wait)
else if (queue_node_flags & SS_POST_FIRE_TIMING)
next_fire = world.time + wait + (world.tick_lag * (tick_overrun/100))
else if (queue_node_flags & SS_KEEP_TIMING)
next_fire += wait
else
next_fire = queued_time + wait + (world.tick_lag * (tick_overrun/100))

//Queue it to run.
// (we loop thru a linked list until we get to the end or find the right point)
// (this lets us sort our run order correctly without having to re-sort the entire already sorted list)
Expand Down Expand Up @@ -251,8 +274,8 @@
//could be used to postpone a costly subsystem for (default one) var/cycles, cycles
//for instance, during cpu intensive operations like explosions
/datum/controller/subsystem/proc/postpone(cycles = 1)
if(next_fire - world.time < wait)
next_fire += (wait*cycles)
if (can_fire && cycles >= 1)
postponed_fires += cycles

//usually called via datum/controller/subsystem/New() when replacing a subsystem (i.e. due to a recurring crash)
//should attempt to salvage what it can from the old instance of subsystem
Expand Down
Loading

0 comments on commit d3c9dd6

Please sign in to comment.