BeeStation-Hornet icon indicating copy to clipboard operation
BeeStation-Hornet copied to clipboard

Removes some major sleepers (100% lag free)

Open PowerfulBacon opened this issue 1 year ago • 9 comments

Thanks to TheFinalPotato from coderbus for helping diagnose this issue.

Downstream Notice: Breaking changes

This PR changes the way that /datum/map_template are loaded.

Previously, map_templates would have their completion awaited for, however now the loading operates on a subsystem, meaning .load() will no longer freeze the current proc until loading is completed. /datum/parsed_map (Used for loading the station at roundstart and loading z-levels) is not affected by this and will run using CHECK_TICK (This is fine for roundstart, but shouldn't be used during a round). All instances of /proc/load from /datum/map_template and subtypes need to be checked to ensure that any code after .load() doesn't depend on the results of .load. Any code that needs to be run after the completion of the map load need to use the completion callbacks.

Completion Callbacks:

If you are calling /datum/map_template.load() from somewhere else: Map template load returns the map generator being used to generate the map, you can use .on_completion to register a completion callback which will be called after the map successfully loads. image


If you are calling /datum/map_generator.generate(), then you can register completion callbacks using the .on_completion() proc to register as many completion procs as you want. image


Old code:

ship.load(T)
message_admins("Ship loaded")

New code:

/datum/whatever/proc/load_ship(turf/T)
	var/datum/map_generator/ship_placer = ship.load(T)
	ship_placer.on_completion(CALLBACK(src, .proc/on_ship_loaded))

/datum/whatever/proc/on_ship_loaded(datum/map_generator/map_gen, turf/T, init_atmos, datum/parsed_map/parsed, register = TRUE)
	message_admins("Ship loaded")

If you want, you can probably make the code closer to /TG/ by just using UNTIL and waiting until the generation is completed, however its a somewhat janky solution and won't be able to utilize all of the subsystem for concurrent loading.

About The Pull Request

Removes some major sleepers that could result in the MC freezing up (Sleeping procs may wake up before the MC, leading to the MC's maptick being consumed before the MC has a chance to fire).

Why It's Good For The Game

Sleeping inside some extremely long function, or something that loops can cause the sleeps to wake up before the MC, meaning the MCs maptick is consumed before it even has a chance to fire, leading to the MC freezing up and everything going to shit.

Testing Photographs and Procedure

Round > Trigger Event > Catastrophic Meteors Watch as meteors approach the station and blow shit up. Some systems will queue up, however the MC will still run and that list will slowly get shorter and shorter. The MC no longer freezes during meteors as a result of airlocks losing power.

Ruin Generation: Harder to test this one since it never happened locally anyway. Just try it on the server and hope for the best. Of course I tested to make sure the ruins generate properly. I'm going to TM this anyway.

I've tested every form of map place that is affected, except for fugatives since it requires players to trigger the event.

image

image

Changelog

:cl: PowerfulBacon, TheFinalPotato fix: Removes a sleep loop from airlocks fix: Makes ruin generation a subsystem process rather than using CHECK_TICK, so that its execution flow can be managed by the MC rather than byond. /:cl:

PowerfulBacon avatar Sep 09 '22 07:09 PowerfulBacon

next up: Ruin generation

PowerfulBacon avatar Sep 09 '22 07:09 PowerfulBacon

You are the Syndicate Sleeper Agent

Your job is to lag the MC, as much as possible. Spend as much time sleeping as physically possible.

Your PDA has been embedded with a remote uplink to retrieve items useful to your objectives. Enter the code Charlie 204 as your ringtone to unlock it.

itsmeow avatar Sep 09 '22 08:09 itsmeow

code/game/machinery/doors/airlock.dm, line 501, column 3:
error: undefined field: "proc" on /obj/machinery/door/airlock

code/game/machinery/doors/airlock.dm, line 501, column 3:
error: undefined var: "restorePower"

RIP

itsmeow avatar Sep 09 '22 08:09 itsmeow

I'm not done yet, I still got generators to refactor

PowerfulBacon avatar Sep 09 '22 08:09 PowerfulBacon

This is going to need a pretty major rework to map loading, since the map loader checks tick a bunch and will probably need its own subsystem for running while the game isn't loading. Will continue tomorrow

PowerfulBacon avatar Sep 09 '22 09:09 PowerfulBacon

A side note is that this will increase the speed of ruin generation since all rooms can be generated at the same time rather than one after the other

PowerfulBacon avatar Sep 18 '22 11:09 PowerfulBacon

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Sep 22 '22 16:09 github-actions[bot]

image Random ruins can spawn inside each other due to the async nature of loading only blocking off ruins at the end.

PowerfulBacon avatar Sep 30 '22 18:09 PowerfulBacon

It seems like the asteroid station can run before map place completes, making the areas have invalid lighting

PowerfulBacon avatar Oct 02 '22 20:10 PowerfulBacon

This breaks the fuck out of the holodeck

It doesn't use the callbacks

itsmeow avatar Nov 01 '22 11:11 itsmeow

The issue with preview shuttles not working has been fixed. Passing async references around is honestly not the most ideal solution and SSshuttle is a little messy but it works.

PowerfulBacon avatar Nov 06 '22 10:11 PowerfulBacon

It does use the callbacks in the holodeck, I think its runtiming. Let me have a look and get this fixed

PowerfulBacon avatar Nov 06 '22 11:11 PowerfulBacon

Im so dumb, finish_spawning calls itself

PowerfulBacon avatar Nov 06 '22 11:11 PowerfulBacon

I had a report that the backup shuttle was sent, however haven't been provided with the round ID. I assume its an issue with either admin shuttle spawning, or purchasing shuttles (or both).

PowerfulBacon avatar Nov 07 '22 10:11 PowerfulBacon