Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes some major sleepers, Refactors maploading to be async (100% lag free) #7659

Closed
wants to merge 58 commits into from

Conversation

PowerfulBacon
Copy link
Member

@PowerfulBacon PowerfulBacon commented Sep 9, 2022

Thanks to TheFinalPotato from coderbus for helping diagnose this issue.

closes #7967
closes #7927

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

image

Changelog

🆑 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.
code: Adds in a unit test for shuttle files that are just completely broken.
/:cl:

@PowerfulBacon
Copy link
Member Author

next up: Ruin generation

@itsmeow
Copy link
Member

itsmeow commented Sep 9, 2022

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
Copy link
Member

itsmeow commented Sep 9, 2022

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

@PowerfulBacon
Copy link
Member Author

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

@PowerfulBacon PowerfulBacon changed the title Removes some major sleepers Removes some major sleepers (100% lag free) Sep 9, 2022
@PowerfulBacon
Copy link
Member Author

PowerfulBacon commented Sep 9, 2022

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 PowerfulBacon added the Priority: Critical THIS IS VERY IMPORTANT label Sep 18, 2022
@PowerfulBacon
Copy link
Member Author

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

@github-actions
Copy link

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

@PowerfulBacon PowerfulBacon marked this pull request as ready for review September 30, 2022 14:27
@PowerfulBacon
Copy link
Member Author

PowerfulBacon commented Sep 30, 2022

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

@PowerfulBacon
Copy link
Member Author

image
epic

@github-actions
Copy link

github-actions bot commented Dec 8, 2022

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

@PowerfulBacon
Copy link
Member Author

Fuck this imma just copy and paste the map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants