Files
Yogstation/code/controllers/subsystem.dm
Chubbygummibear 0fda5cfc6a Icon smoothing, and Rendering overhaul, and Camera fix, and mapmerge.py fix, and Multi-z, and THE PLANE CUBE (#21221)
* why no work

angy

* weird errors

shit sucks

* fixved it

I can spell good

* fix?

POSSIBLY

* nope

wasnt this

* no more immutable

thhanks koffee

* ok

ok

* removes all the pref stuff

""removes""

* remove this

idiot

* this goes bye

 bye

* these go too

genius

* bye

bye

* better night vision

* tries to fix camera

maybe

* ok fuck it we ball

we ball

* ok lets go back

go back go back go back

* WORK

DAMNIT

* ha

fuc kyou

* this

maybe

* this doesnt work :(

* maybe fix

maybe

* fucks everything

why do i do this

* test update

test

* Revert "tries to fix camera"

This reverts commit 2d14fbae66.

* reverts everything I just did

peko pain

* bye

bitch

* oh yeah add this

I guess

* Fucks up the camera net + chunk

why

* test maybe revert

* Revert "test maybe revert"

This reverts commit 98c5ef1b93.

* Revert "Fucks up the camera net + chunk"

This reverts commit 0e421ebf5f.

* this isnt going well

uh oh

* Attempts to rework out security camera

and probably more

* Revert "this isnt going well"

This reverts commit 1d8ceac867.

* Revert "Revert "this isnt going well""

This reverts commit e26fb61415.

* ok

ok

* Revert "ok"

This reverts commit 7e7a7f8372.

* Revert "Merge remote-tracking branch 'upstream/master' into NahI'dPortit"

This reverts commit 01094731c1, reversing
changes made to c0cf69ebf1.

* this doesn't need to be redefined

I guess

* no we need this

totally

* a familiar pain

* 515 is L

* yeah

yeah

* ok god

fine

* bye bye basemap :(

doesnt work on runtime station

* Fixes AI statis not working

god im good

* remove this

oh god

* Revert "Revert "Merge remote-tracking branch 'upstream/master' into NahI'dPortit""

This reverts commit b3fb3ba0db.

* proves to god I exist

and im pissed

* yog exclusive feature (tm)

plane master

* bring this back from previous push

* updates vendor emissives

as well as firealarms

* Updates barsign

and fucks everything up

* Fixes barsigns breaks all lights and updates barsigns to be machines and not structures

We will address this in a later patch

* not sure who changed that

oh well

* yeah

this got moved

* this needs updating

yeah

* turns off the carbon monoxide alarm

duh

* FIXES IT YES

thank you biome

* turns this off too

yeah

* Can't compile yet but ports a ton of shit

* L

* the game opens ig

* extra shit

* fixes

* signals and smooth queue

* look ma im going horribly out of scope

* fixes chasms

* this fixed nothing

* ???

* more barsigns

for later

* forgive me cowboy. also fuck diagonals

* oops

we need this apparently

* fuck it we ball

* Update _lists.dm

* Update icon_smoothing.dm

* it now works kinda

* Update atom_initializing_EXPENSIVE.dm

* lighting don't work

* we have light

* sort turfs better

* big fucking reorganize

* like everything except templates

* boy i sure hope nothing bad happens to these bar templates

* we're back

* no runtimes baby

* no errors

* shuttles are almost fixed i think

* Revert "shuttles are almost fixed i think"

This reverts commit 046058827c.

* Revert "Merge remote-tracking branch 'upstream/master' into icon_smoothing"

This reverts commit 863e1b776d, reversing
changes made to 884623e600.

* Revert "no errors"

This reverts commit 884623e600.

* too far back i think

* midround smoothing runtimes fixed i think

* comment cleanup

* should fix the component runtimes

* Revert "Revert "Merge remote-tracking branch 'upstream/master' into icon_smoothing""

This reverts commit a8ff8d63aa.

* NO RUNTIMES AND ICEMETA WORKS LET'S GOOOOOO

* please stay fixed icemeta

* organizing render dms

* woops this too in the reorganizing

* cryo fixed

* nah, i'd win

* parallax isn't my problem

* pls don't break icemeta

* runtime station gets a cam console

* well it compiles

* maybe fix the map

* woops

* man i hate maps

* was that it?

* PLEASE

* missing focus tests

* maybe that was it

* maybe

* let's take the batteries out of the carbon monoxide detector

* fuck osha

* i hate vending machines

* that's not a computer

* slot machine fix

* PLEASE

* that wasn't supposed to be there

* fuck it i can't fix everything at once

* BLUESPACE LOCKER?

* literally why

* hhh

* does this fix chasms?

* that should fix bad index

* please?

* turf_flags for reservations

* haha oops

* yolo (kill me)

* fix wood walls and other walls

* fix stairs

* that might have fixed shittles

* baseturfs are good now i think

* should fix plasma windows

* decals fixed

* please fix changelog

* shuttle lighting still fucky

* lighting is stinky slow and doesn't finish updating by the time the server starts guh

* lighting seemingly works

* slipping works

* shuttle sounds, slips, and windoors fixed

* why am i here

* fuck the changelog

* of course someone touched smoothing as i'm almost done

* we good?

* updating ai_eye and rename

* z updates and more ai cam updates

* ice fixed

* weather and ice fix

* clockies can see and other clean up catches

* windows fixed

* cowbot forgive me i'm trying to update flashlights to tg because there's no light on lower multi-z z's like ice meta bottom floor

* movable lighting works on multi-z

* gps fix

* item stacking from drag works

* falsewall fix

* job panel fixed

* AI HANDLED

* woops that comment should be gone

* i hate ai i hate ai

* brass glass visible again

* vents on top of tiles now

* sigdrobe sprite back

* centcomm portals work

* portals and see openspace mapping icons fixed

* icemeta my behated

* kill

* is that it

* lighting cutoff is old hat

* angery overlay

* not super necessary

* also extra but whatever

* ticker but thicker

* job fix i hope

* this isn't needed anymore

* latejoin fix?

* laserpointer, pipecrawl, and some consoles fixed

* i hate fixing bugs as they're made

* we're not ready for that

* redef cleanup

* gps arrows, gun flashlights, shuttle console placement, multi-z pulling fixed

* goofy ah gun code

* this was a good idea and necessary

* should fix caltrop component

* does this please the linter

* linter please accept this async function

* THERE

* take the batteries out

* make it stop

* cowbot stopped me from letting ghosts dab

* recycler loc fix

* fix border firedoors not blocking movement

* should fix screen fade out and fade in on round start and end

* darker command tile trim and fixed bronze wall sprites

* fuck you linter

* railings actually stop you from leaving

* probably fixes gibtonite overlay when struck

* armaments dispenser and clockwork catwalk

* turbine fix probably

* pointing at inhand items should be fixed

* fix overwatch app

* should hopefully fix cable rotation on shuttle move

* flashlights have better directionality logic

* hopefully fixes shuttle atmos on move

* grilles fixed

* hopefully this fixes shuttle buttons, airolocks, and other machinery not working after moving

* ice meta mining area finally not freezing

* fix lightbulb icons not updating

* lava mask and lighting dots

* we actually have this

* fuck glowshrooms GC

* fix light fixture interactions and icon updates

* hopefully catches all the updates

* lava lighting good to go

* seclite was missing inhands

* smoothing in replays

* light updates accurate in replays

* biome's multi-z requests

---------

Co-authored-by: cowbot92 <75333826+cowbot92@users.noreply.github.com>
Co-authored-by: Molti <gamingjoelouis@gmail.com>
Co-authored-by: Ringalong <53777086+JohnFulpWillard@users.noreply.github.com>
2024-02-18 13:16:55 -06:00

325 lines
11 KiB
Plaintext

/**
* # Subsystem base class
*
* Defines a subsystem to be managed by the [Master Controller][/datum/controller/master]
*
* Simply define a child of this subsystem, using the [SUBSYSTEM_DEF] macro, and the MC will handle registration.
* Changing the name is required
**/
/datum/controller/subsystem
// Metadata; you should define these.
/// Name of the subsystem - you must change this
name = "fire coderbus"
/// Order of initialization. Higher numbers are initialized first, lower numbers later. Use or create defines such as [INIT_ORDER_DEFAULT] so we can see the order in one file.
var/init_order = INIT_ORDER_DEFAULT
/// Time to wait (in deciseconds) between each call to fire(). Must be a positive integer.
var/wait = 20
/// Priority Weight: When mutiple subsystems need to run in the same tick, higher priority subsystems will be given a higher share of the tick before MC_TICK_CHECK triggers a sleep, higher priority subsystems also run before lower priority subsystems
var/priority = FIRE_PRIORITY_DEFAULT
/// [Subsystem Flags][SS_NO_INIT] to control binary behavior. Flags must be set at compile time or before preinit finishes to take full effect. (You can also restart the mc to force them to process again)
var/flags = NONE
/// Which stage does this subsystem init at. Earlier stages can fire while later stages init.
var/init_stage = INITSTAGE_MAIN
/// This var is set to TRUE after the subsystem has been initialized.
var/initialized = FALSE
/// Set to 0 to prevent fire() calls, mostly for admin use or subsystems that may be resumed later
/// use the [SS_NO_FIRE] flag instead for systems that never fire to keep it from even being added to list that is checked every tick
var/can_fire = TRUE
///Bitmap of what game states can this subsystem fire at. See [RUNLEVELS_DEFAULT] for more details.
var/runlevels = RUNLEVELS_DEFAULT //points of the game at which the SS can fire
/*
* The following variables are managed by the MC and should not be modified directly.
*/
/// Last world.time the subsystem completed a run (as in wasn't paused by [MC_TICK_CHECK])
var/last_fire = 0
/// Scheduled world.time for next fire()
var/next_fire = 0
/// Running average of the amount of milliseconds it takes the subsystem to complete a run (including all resumes but not the time spent paused)
var/cost = 0
/// Running average of the amount of tick usage in percents of a tick it takes the subsystem to complete a run
var/tick_usage = 0
/// Running average of the amount of tick usage (in percents of a game tick) the subsystem has spent past its allocated time without pausing
var/tick_overrun = 0
/// How much of a tick (in percents of a tick) were we allocated last fire.
var/tick_allocation_last = 0
/// How much of a tick (in percents of a tick) do we get allocated by the mc on avg.
var/tick_allocation_avg = 0
/// Tracks the current execution state of the subsystem. Used to handle subsystems that sleep in fire so the mc doesn't run them again while they are sleeping
var/state = SS_IDLE
/// Tracks how many times a subsystem has ever slept in fire().
var/slept_count = 0
/// Tracks how many fires the subsystem has consecutively paused on in the current run
var/paused_ticks = 0
/// Tracks how much of a tick the subsystem has consumed in the current run
var/paused_tick_usage
/// Tracks how many fires the subsystem takes to complete a run on average.
var/ticks = 1
/// 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
/// Priority at the time the subsystem entered the queue. Needed to avoid changes in priority (by admins and the like) from breaking things.
var/queued_priority
/// How many times we suspect a subsystem type has crashed the MC, 3 strikes and you're out!
var/static/list/failure_strikes
/// Next subsystem in the queue of subsystems to run this tick
var/datum/controller/subsystem/queue_next
/// Previous subsystem in the queue of subsystems to run this tick
var/datum/controller/subsystem/queue_prev
//Do not blindly add vars here to the bottom, put it where it goes above
//If your var only has two values, put it in as a flag.
//yogs start -- loading time stuff
var/static/total_loading_points_progress = 0 //! How much progress we've made in loading all the subsystems so far.
var/static/total_loading_points = 0 //! The total amount of loading points among all subsystems. Should be defined by MC before subsystem inits.
var/loading_points = 0 //! The amount of loading points this subsystem has, measured in deciseconds of approximate load time. This being 0 is fine.
//yogs end
//Do not override
///datum/controller/subsystem/New()
// Used to initialize the subsystem BEFORE the map has loaded
// Called AFTER Recover if that is called
// Prefer to use Initialize if possible
/datum/controller/subsystem/proc/PreInit()
return
///This is used so the mc knows when the subsystem sleeps. do not override.
/datum/controller/subsystem/proc/ignite(resumed = FALSE)
SHOULD_NOT_OVERRIDE(TRUE)
set waitfor = FALSE
. = SS_IDLE
tick_allocation_last = Master.current_ticklimit-(TICK_USAGE)
tick_allocation_avg = MC_AVERAGE(tick_allocation_avg, tick_allocation_last)
. = SS_SLEEPING
fire(resumed)
. = state
if (state == SS_SLEEPING)
slept_count++
state = SS_IDLE
if (state == SS_PAUSING)
slept_count++
var/QT = queued_time
enqueue()
state = SS_PAUSED
queued_time = QT
///previously, this would have been named 'process()' but that name is used everywhere for different things!
///fire() seems more suitable. This is the procedure that gets called every 'wait' deciseconds.
///Sleeping in here prevents future fires until returned.
/datum/controller/subsystem/proc/fire(resumed = FALSE)
flags |= SS_NO_FIRE
CRASH("Subsystem [src]([type]) does not fire() but did not set the SS_NO_FIRE flag. Please add the SS_NO_FIRE flag to any subsystem that doesn't fire so it doesn't get added to the processing list and waste cpu.")
/datum/controller/subsystem/Destroy()
dequeue()
can_fire = 0
flags |= SS_NO_FIRE
if (Master)
Master.subsystems -= src
return ..()
/** Update next_fire for the next run.
* reset_time (bool) - Ignore things that would normally alter the next fire, like tick_overrun, and last_fire. (also resets postpone)
*/
/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)
/datum/controller/subsystem/proc/enqueue()
var/SS_priority = priority
var/SS_flags = flags
var/datum/controller/subsystem/queue_node
var/queue_node_priority
var/queue_node_flags
for (queue_node = Master.queue_head; queue_node; queue_node = queue_node.queue_next)
queue_node_priority = queue_node.queued_priority
queue_node_flags = queue_node.flags
if (queue_node_flags & (SS_TICKER|SS_BACKGROUND) == SS_TICKER)
if ((SS_flags & (SS_TICKER|SS_BACKGROUND)) != SS_TICKER)
continue
if (queue_node_priority < SS_priority)
break
else if (queue_node_flags & SS_BACKGROUND)
if (!(SS_flags & SS_BACKGROUND))
break
if (queue_node_priority < SS_priority)
break
else
if (SS_flags & SS_BACKGROUND)
continue
if (SS_flags & SS_TICKER)
break
if (queue_node_priority < SS_priority)
break
queued_time = world.time
queued_priority = SS_priority
state = SS_QUEUED
if (SS_flags & SS_BACKGROUND) //update our running total
Master.queue_priority_count_bg += SS_priority
else
Master.queue_priority_count += SS_priority
queue_next = queue_node
if (!queue_node)//we stopped at the end, add to tail
queue_prev = Master.queue_tail
if (Master.queue_tail)
Master.queue_tail.queue_next = src
else //empty queue, we also need to set the head
Master.queue_head = src
Master.queue_tail = src
else if (queue_node == Master.queue_head)//insert at start of list
Master.queue_head.queue_prev = src
Master.queue_head = src
queue_prev = null
else
queue_node.queue_prev.queue_next = src
queue_prev = queue_node.queue_prev
queue_node.queue_prev = src
/datum/controller/subsystem/proc/dequeue()
if (queue_next)
queue_next.queue_prev = queue_prev
if (queue_prev)
queue_prev.queue_next = queue_next
if (Master && (src == Master.queue_tail))
Master.queue_tail = queue_prev
if (Master && (src == Master.queue_head))
Master.queue_head = queue_next
queued_time = 0
if (state == SS_QUEUED)
state = SS_IDLE
/datum/controller/subsystem/proc/pause()
. = 1
switch(state)
if(SS_RUNNING)
state = SS_PAUSED
if(SS_SLEEPING)
state = SS_PAUSING
/// Called after the config has been loaded or reloaded.
/datum/controller/subsystem/proc/OnConfigLoad()
/**
* Used to initialize the subsystem. This is expected to be overriden by subtypes.
*/
/datum/controller/subsystem/Initialize()
return SS_INIT_NONE
/datum/controller/subsystem/stat_entry(msg)
if(can_fire && !(SS_NO_FIRE & flags) && init_stage <= Master.init_stage_completed)
msg = "[round(cost,1)]ms|[round(tick_usage,1)]%([round(tick_overrun,1)]%)|[round(ticks,0.1)]\t[msg]"
else
msg = "OFFLINE\t[msg]"
return msg
/datum/controller/subsystem/proc/state_letter()
switch (state)
if (SS_RUNNING)
. = "R"
if (SS_QUEUED)
. = "Q"
if (SS_PAUSED, SS_PAUSING)
. = "P"
if (SS_SLEEPING)
. = "S"
if (SS_IDLE)
. = " "
/// Causes the next "cycle" fires to be missed. Effect is accumulative but can reset by calling update_nextfire(reset_time = TRUE)
/datum/controller/subsystem/proc/postpone(cycles = 1)
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
/datum/controller/subsystem/Recover()
/datum/controller/subsystem/vv_edit_var(var_name, var_value)
switch (var_name)
if (NAMEOF(src, can_fire))
//this is so the subsystem doesn't rapid fire to make up missed ticks causing more lag
if (var_value)
update_nextfire(reset_time = TRUE)
if (NAMEOF(src, queued_priority)) //editing this breaks things.
return FALSE
. = ..()
/datum/controller/subsystem/proc/get_metrics()
SHOULD_CALL_PARENT(TRUE)
. = list()
.["@measurement"] = "subsystem"
.["@tags"] = list("subsystem" = type)
.["$cost"] = cost
.["$tick_usage"] = tick_usage
.["$tick_overrun"] = tick_overrun
.["$last_fire"] = last_fire
.["$next_fire"] = next_fire
.["$tick_allocation_avg"] = tick_allocation_avg
.["$times_fired"] = times_fired
.["$postponed_fires"] = postponed_fires