Remove turbolift_controller proccess, just use SSprocessing instead.

- Design based on BayStation: Refactor turbolift.do_move() to remove all sleep()'s, instead have wait_state to keep track of where it was.
- Add in process() proc to do appropriate action based on wait_state.
- Register/deregister with SSprocessing instead of turbolift_controller
This commit is contained in:
Leshana
2020-03-25 13:49:26 -04:00
parent 2e623e5aa8
commit 43fc65d529
3 changed files with 49 additions and 45 deletions

View File

@@ -11,7 +11,8 @@
var/doors_closing = 0 // Whether doors are in the process of closing
var/tmp/moving_upwards
var/tmp/busy
var/tmp/busy_state // Used for controller processing.
var/tmp/next_process // world.time process() should next do something
/datum/turbolift/proc/emergency_stop()
queued_floors.Cut()
@@ -38,7 +39,42 @@
door.close()
return
#define LIFT_MOVING 1 // Lift will try moving.
#define LIFT_WAITING_A 2 // Waiting 15ds after arrival to announce, then goto LIFT_WAITING_B
#define LIFT_WAITING_B 3 // Waiting floor_wait_delay after announcement before potentially moving again.
/datum/turbolift/process()
if(world.time < next_process)
return
switch(busy_state)
if(LIFT_MOVING)
if(!do_move())
if(target_floor)
// TODO - This logic copied from old processor. Would be better to have error states.
target_floor.ext_panel.reset()
target_floor = null
return PROCESS_KILL
else if(!next_process)
log_debug("Turbolift [src] do_move() returned 1 but next_process = null; busy_state=[busy_state]")
return PROCESS_KILL
if(LIFT_WAITING_A)
var/area/turbolift/origin = locate(current_floor.area_ref)
control_panel_interior.visible_message("<b>The elevator</b> announces, \"[origin.lift_announce_str]\"")
next_process = world.time + floor_wait_delay
busy_state = LIFT_WAITING_B
if(LIFT_WAITING_B)
if(queued_floors.len)
busy_state = LIFT_MOVING
else
busy_state = null
return PROCESS_KILL
else
log_debug("Turbolift [src] process() called with unknown busy_state='[busy_state]'")
return PROCESS_KILL
// Called by process when in LIFT_MOVING
/datum/turbolift/proc/do_move()
next_process = null
var/current_floor_index = floors.Find(current_floor)
@@ -56,6 +92,7 @@
if(!doors_closing)
close_doors()
doors_closing = 1
next_process = world.time + 1 SECOND // Wait for doors to close
return 1
else // We failed to close the doors - probably, someone is blocking them; stop trying to move
doors_closing = 0
@@ -74,10 +111,8 @@
target_floor.arrived(src)
target_floor = null
sleep(15)
control_panel_interior.visible_message("<b>The elevator</b> announces, \"[origin.lift_announce_str]\"")
sleep(floor_wait_delay)
next_process = world.time + 15
busy_state = LIFT_WAITING_A
return 1
// Work out where we're headed.
@@ -110,15 +145,21 @@
current_floor = next_floor
control_panel_interior.visible_message("The elevator [moving_upwards ? "rises" : "descends"] smoothly.")
return (next_floor.delay_time || move_delay || 30)
next_process = world.time + (next_floor.delay_time || move_delay)
return 1
/datum/turbolift/proc/queue_move_to(var/datum/turbolift_floor/floor)
if(!floor || !(floor in floors) || (floor in queued_floors))
return // STOP PRESSING THE BUTTON.
floor.pending_move(src)
queued_floors |= floor
turbolift_controller.lift_is_moving(src)
busy_state = LIFT_MOVING
START_PROCESSING(SSprocessing, src)
// TODO: dummy machine ('lift mechanism') in powered area for functionality/blackout checks.
/datum/turbolift/proc/is_functional()
return 1
return 1
#undef LIFT_MOVING
#undef LIFT_WAITING_A
#undef LIFT_WAITING_B

View File

@@ -1,36 +0,0 @@
var/datum/controller/process/turbolift/turbolift_controller
/datum/controller/process/turbolift
var/list/moving_lifts = list()
/datum/controller/process/turbolift/New()
..()
turbolift_controller = src
/datum/controller/process/turbolift/setup()
name = "turbolift controller"
schedule_interval = 10
/datum/controller/process/turbolift/doWork()
for(var/liftref in moving_lifts)
if(world.time < moving_lifts[liftref])
continue
var/datum/turbolift/lift = locate(liftref)
if(lift.busy)
continue
spawn(0)
lift.busy = 1
var/floor_delay
if(!(floor_delay = lift.do_move()))
moving_lifts[liftref] = null
moving_lifts -= liftref
if(lift.target_floor)
lift.target_floor.ext_panel.reset()
lift.target_floor = null
else
lift_is_moving(lift,floor_delay)
lift.busy = 0
SCHECK
/datum/controller/process/turbolift/proc/lift_is_moving(var/datum/turbolift/lift,var/floor_delay)
moving_lifts["\ref[lift]"] = world.time + floor_delay