Skip to content

Commit

Permalink
Shuttles have air again. (ParadiseSS13#27884)
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyMan3595 authored Jan 8, 2025
1 parent e1c0c06 commit ace1c17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions code/controllers/subsystem/SSair.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ SUBSYSTEM_DEF(air)
/// Are we currently running in a MILLA-safe context, i.e. is is_synchronous *guaranteed* to be TRUE. Nothing outside of this file should change this.
VAR_PRIVATE/in_milla_safe_code = FALSE

/// Are we in MILLA-safe code that can safely sleep?
VAR_PRIVATE/safe_to_sleep = FALSE

/// A list of callbacks waiting for MILLA to finish its tick and enter synchronous mode.
var/list/waiting_for_sync = list()
var/list/sleepable_waiting_for_sync = list()
Expand Down Expand Up @@ -724,16 +727,24 @@ SUBSYSTEM_DEF(air)
waiting_for_sync += CB

/// Similar to addtimer, but triggers once MILLA enters synchronous mode. This version allows for sleeping if it's absolutely necessary.
/datum/controller/subsystem/air/proc/sleepable_synchronize(datum/milla_safe/CB)
/datum/controller/subsystem/air/proc/sleepable_synchronize(datum/milla_safe_must_sleep/CB)
if(safe_to_sleep)
var/was_safe = SSair.in_milla_safe_code
SSair.in_milla_safe_code = TRUE
// This is one of two intended places to call this otherwise-unsafe proc.
CB.private_unsafe_invoke()
SSair.in_milla_safe_code = was_safe
return

sleepable_waiting_for_sync += CB

/datum/controller/subsystem/air/proc/is_in_milla_safe_code()
return in_milla_safe_code

/datum/controller/subsystem/air/proc/on_milla_tick_finished()
run_sleepless_callbacks()
run_sleeping_callbacks()
is_synchronous = TRUE
run_sleepless_callbacks()

/datum/controller/subsystem/air/proc/run_sleepless_callbacks()
// Just in case someone is naughty and decides to sleep, make sure that this method runs fully anyway.
Expand All @@ -748,11 +759,13 @@ SUBSYSTEM_DEF(air)

/datum/controller/subsystem/air/proc/run_sleeping_callbacks()
in_milla_safe_code = TRUE
safe_to_sleep = TRUE
for(var/datum/milla_safe_must_sleep/CB as anything in sleepable_waiting_for_sync)
// This is one of two intended places to call this otherwise-unsafe proc.
CB.private_unsafe_invoke()
sleepable_waiting_for_sync.Cut()
in_milla_safe_code = FALSE
safe_to_sleep = FALSE

/proc/milla_tick_finished()
// Any proc that wants MILLA to be synchronous should not sleep.
Expand Down
6 changes: 3 additions & 3 deletions code/modules/shuttle/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@
if(!canMove())
return -1

var/datum/milla_safe/docking_port_dock/milla = new()
var/datum/milla_safe_must_sleep/docking_port_dock/milla = new()
milla.invoke_async(src, S1, force, transit)

/datum/milla_safe/docking_port_dock
/datum/milla_safe_must_sleep/docking_port_dock

/datum/milla_safe/docking_port_dock/on_run(obj/docking_port/mobile/mobile_port, obj/docking_port/stationary/S1, force, transit)
/datum/milla_safe_must_sleep/docking_port_dock/on_run(obj/docking_port/mobile/mobile_port, obj/docking_port/stationary/S1, force, transit)
// Re-check that it's OK to dock.
if(S1.get_docked() == mobile_port)
mobile_port.remove_ripples()
Expand Down

0 comments on commit ace1c17

Please sign in to comment.