mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-26 17:11:52 +00:00
Basically, they key difference between StonedMC and CarnMC is that when multiple ticks want to run at the same byond tick, we divvy up the tick between the subsystems, rather then allow one subsystem to hog it all. The key difference between StonedMC and GoonPS is that we allow the subsystems to tell us how to divvy up the tick using flags and priority. The new SS_ flags allows us to select behaviors that used to be piggybacked as side effects of dynamic wait or default but sometimes unneeded behavior. Dynamic wait is 100% gone, lower priority and SS_BACKGROUND are better more refined ways of doing this when combined with MC_TICK_CHECK I have by design never looked at the inners of goonPS, so this is all original code but I know it uses two loops because of comments by goon devs on reddit threads, that design didn't make sense before, but when I can tell a SS how much of a byond tick it is allowed to have, knowing how many need to run this tick is helpful I also know a bit more about how it works from piecing together comments in #vgstation. Detailed list of changes: Subsystems now have flags, allowing fine grain control over things like rather or not it processes, inits, rather it's wait is how long between runs (post run timing) or how long between starts, and rather or not late fires should cause the next fire to be earlier. Mc now has two loops One loop handles queuing shit, one loop handles running shit. MC now splits up tick allotment rather than first come first serve Subsystems can even request a bigger share using higher priorities. (It will even resume subsystems it paused if other subsystems hadn't used as much as it predicted they might need) Default fps is now 20 This is related enough to the MC and it's a change that's really long since over due All code oddities are most likely to be necessities to lower overhead on the mc since it runs every tick
117 lines
3.8 KiB
Plaintext
117 lines
3.8 KiB
Plaintext
var/datum/subsystem/lighting/SSlighting
|
|
|
|
#define SSLIGHTING_LIGHTS 1
|
|
#define SSLIGHTING_TURFS 2
|
|
|
|
/datum/subsystem/lighting
|
|
name = "Lighting"
|
|
init_order = 1
|
|
wait = 1
|
|
flags = SS_POST_FIRE_TIMING
|
|
priority = 40
|
|
display_order = 5
|
|
|
|
var/list/changed_lights = list() //list of all datum/light_source that need updating
|
|
var/changed_lights_workload = 0 //stats on the largest number of lights (max changed_lights.len)
|
|
var/list/changed_turfs = list() //list of all turfs which may have a different light level
|
|
var/changed_turfs_workload = 0 //stats on the largest number of turfs changed (max changed_turfs.len)
|
|
|
|
|
|
/datum/subsystem/lighting/New()
|
|
NEW_SS_GLOBAL(SSlighting)
|
|
return ..()
|
|
|
|
|
|
/datum/subsystem/lighting/stat_entry()
|
|
..("L:[round(changed_lights_workload,1)]|T:[round(changed_turfs_workload,1)]")
|
|
|
|
|
|
//Workhorse of lighting. It cycles through each light that needs updating. It updates their
|
|
//effects and then processes every turf in the queue, updating their lighting object's appearance
|
|
//Any light that returns 1 in check() deletes itself
|
|
//By using queues we are ensuring we don't perform more updates than are necessary
|
|
/datum/subsystem/lighting/fire(resumed = 0)
|
|
var/ticklimit = CURRENT_TICKLIMIT
|
|
//split our tick allotment in half so we don't spend it all on lightshift checks
|
|
CURRENT_TICKLIMIT = world.tick_usage + ((ticklimit-world.tick_usage)/2)
|
|
|
|
var/list/changed_lights = src.changed_lights
|
|
if (!resumed)
|
|
changed_lights_workload = MC_AVERAGE(changed_lights_workload, changed_lights.len)
|
|
var/i = 1
|
|
while (i <= changed_lights.len)
|
|
var/datum/light_source/LS = changed_lights[i++]
|
|
LS.check()
|
|
if (MC_TICK_CHECK)
|
|
break
|
|
if (i > 1)
|
|
changed_lights.Cut(1,i)
|
|
|
|
CURRENT_TICKLIMIT = ticklimit
|
|
var/list/changed_turfs = src.changed_turfs
|
|
if (!resumed)
|
|
changed_turfs_workload = MC_AVERAGE(changed_turfs_workload, changed_turfs.len)
|
|
i = 1
|
|
while (i <= changed_turfs.len)
|
|
var/turf/T = changed_turfs[i++]
|
|
if(T.lighting_changed)
|
|
T.redraw_lighting()
|
|
if (MC_TICK_CHECK)
|
|
return
|
|
if (i > 1)
|
|
changed_turfs.Cut(1,i)
|
|
|
|
//same as above except it attempts to shift ALL turfs in the world regardless of lighting_changed status
|
|
/datum/subsystem/lighting/Initialize(timeofday)
|
|
var/list/turfs_to_init = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz))
|
|
if (config.starlight)
|
|
for(var/area/A in world)
|
|
if (A.lighting_use_dynamic == DYNAMIC_LIGHTING_IFSTARLIGHT)
|
|
A.luminosity = 0
|
|
|
|
for(var/thing in changed_lights)
|
|
var/datum/light_source/LS = thing
|
|
LS.check()
|
|
changed_lights.Cut()
|
|
|
|
for(var/thing in turfs_to_init)
|
|
var/turf/T = thing
|
|
T.init_lighting()
|
|
changed_turfs.Cut()
|
|
|
|
..()
|
|
|
|
//Used to strip valid information from an existing instance and transfer it to the replacement. i.e. when a crash occurs
|
|
//It works by using spawn(-1) to transfer the data, if there is a runtime the data does not get transfered but the loop
|
|
//does not crash
|
|
/datum/subsystem/lighting/Recover()
|
|
if(!istype(SSlighting.changed_turfs))
|
|
SSlighting.changed_turfs = list()
|
|
if(!istype(SSlighting.changed_lights))
|
|
SSlighting.changed_lights = list()
|
|
|
|
for(var/thing in SSlighting.changed_lights)
|
|
var/datum/light_source/LS = thing
|
|
spawn(-1) //so we don't crash the loop (inefficient)
|
|
LS.check()
|
|
|
|
for(var/thing in changed_turfs)
|
|
var/turf/T = thing
|
|
if(T.lighting_changed)
|
|
spawn(-1)
|
|
T.redraw_lighting()
|
|
|
|
var/msg = "## DEBUG: [time2text(world.timeofday)] [name] subsystem restarted. Reports:\n"
|
|
for(var/varname in SSlighting.vars)
|
|
switch(varname)
|
|
if("tag","bestF","type","parent_type","vars")
|
|
continue
|
|
else
|
|
var/varval1 = SSlighting.vars[varname]
|
|
var/varval2 = vars[varname]
|
|
if(istype(varval1,/list))
|
|
varval1 = "/list([length(varval1)])"
|
|
varval2 = "/list([length(varval2)])"
|
|
msg += "\t [varname] = [varval1] -> [varval2]\n"
|
|
world.log << msg
|