mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
Implement SSshuttles subsystem
* Replaces the shuttle_controller and shuttle process with the shuttles subsystem. Instead of docking ports being initialized by the game ticker, its part of the StonedMC Master init order. * The main advantage of this is control over the initialization order, as well as letting Master be aware of CPU we're using up with shuttle processing. * By being part of the Master init order, we reduce the uncertainty about "are objects initialized yet?" which is nice, since shuttle docks break if machines aren't finished initializing!
This commit is contained in:
@@ -27,5 +27,6 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
|
||||
#define INIT_ORDER_DECALS 16
|
||||
#define INIT_ORDER_ATOMS 15
|
||||
#define INIT_ORDER_MACHINES 10
|
||||
#define INIT_ORDER_SHUTTLES 3
|
||||
#define INIT_ORDER_LIGHTING 0
|
||||
#define INIT_ORDER_AIR -1
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/datum/controller/process/Shuttle/setup()
|
||||
name = "shuttle controller"
|
||||
schedule_interval = 20 // every 2 seconds
|
||||
|
||||
if(!shuttle_controller)
|
||||
shuttle_controller = new
|
||||
|
||||
/datum/controller/process/Shuttle/doWork()
|
||||
shuttle_controller.process()
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
var/global/datum/shuttle_controller/shuttle_controller
|
||||
|
||||
|
||||
/datum/shuttle_controller
|
||||
var/list/shuttles //maps shuttle tags to shuttle datums, so that they can be looked up.
|
||||
var/list/process_shuttles //simple list of shuttles, for processing
|
||||
|
||||
/datum/shuttle_controller/proc/process()
|
||||
//process ferry shuttles
|
||||
for (var/datum/shuttle/shuttle in process_shuttles)
|
||||
if(istype(shuttle, /datum/shuttle/ferry))
|
||||
var/datum/shuttle/ferry/F = shuttle
|
||||
if(F.process_state || F.always_process)
|
||||
F.process()
|
||||
else
|
||||
shuttle.process()
|
||||
|
||||
|
||||
//This is called by gameticker after all the machines and radio frequencies have been properly initialized
|
||||
/datum/shuttle_controller/proc/setup_shuttle_docks()
|
||||
// for(var/shuttle_tag in shuttles)
|
||||
// var/datum/shuttle/shuttle = shuttles[shuttle_tag]
|
||||
for(var/shuttle_type in subtypesof(/datum/shuttle))
|
||||
var/datum/shuttle/shuttle = shuttle_type
|
||||
if(initial(shuttle.category) == shuttle_type)
|
||||
continue
|
||||
shuttle = new shuttle()
|
||||
shuttle.init_docking_controllers()
|
||||
shuttle.dock() //makes all shuttles docked to something at round start go into the docked state
|
||||
|
||||
for(var/obj/machinery/embedded_controller/C in machines)
|
||||
if(istype(C.program, /datum/computer/file/embedded_program/docking))
|
||||
C.program.tag = null //clear the tags, 'cause we don't need 'em anymore
|
||||
|
||||
/datum/shuttle_controller/New()
|
||||
shuttles = list()
|
||||
process_shuttles = list()
|
||||
|
||||
68
code/controllers/subsystems/shuttles.dm
Normal file
68
code/controllers/subsystems/shuttles.dm
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// SSshuttles subsystem - Handles initialization and processing of shuttles.
|
||||
//
|
||||
|
||||
// This global variable exists for legacy support so we don't have to rename every shuttle_controller to SSshuttles yet.
|
||||
var/global/datum/controller/subsystem/shuttles/shuttle_controller
|
||||
|
||||
SUBSYSTEM_DEF(shuttles)
|
||||
name = "Shuttles"
|
||||
wait = 2 SECONDS
|
||||
priority = 5
|
||||
init_order = INIT_ORDER_SHUTTLES
|
||||
flags = SS_KEEP_TIMING|SS_NO_TICK_CHECK
|
||||
runlevels = RUNLEVEL_GAME|RUNLEVEL_POSTGAME
|
||||
|
||||
var/list/shuttles = list() // Maps shuttle tags to shuttle datums, so that they can be looked up.
|
||||
var/list/process_shuttles = list() // Simple list of shuttles, for processing
|
||||
var/list/current_run = list() // Shuttles remaining to process this fire() tick
|
||||
|
||||
/datum/controller/subsystem/shuttles/Initialize(timeofday)
|
||||
global.shuttle_controller = src
|
||||
setup_shuttle_docks()
|
||||
return ..()
|
||||
|
||||
/datum/controller/subsystem/shuttles/fire(resumed = 0)
|
||||
do_process_shuttles(resumed)
|
||||
|
||||
/datum/controller/subsystem/shuttles/stat_entry()
|
||||
var/msg = list()
|
||||
msg += "AS:[shuttles.len]|"
|
||||
msg += "PS:[process_shuttles.len]|"
|
||||
..(jointext(msg, null))
|
||||
|
||||
/datum/controller/subsystem/shuttles/proc/do_process_shuttles(resumed = 0)
|
||||
if (!resumed)
|
||||
src.current_run = process_shuttles.Copy()
|
||||
|
||||
var/list/current_run = src.current_run // Cache for sanic speed
|
||||
while(current_run.len)
|
||||
var/datum/shuttle/S = current_run[current_run.len]
|
||||
current_run.len--
|
||||
if(istype(S) && !QDELETED(S))
|
||||
if(istype(S, /datum/shuttle/ferry)) // Ferry shuttles get special treatment
|
||||
var/datum/shuttle/ferry/F = S
|
||||
if(F.process_state || F.always_process)
|
||||
F.process()
|
||||
else
|
||||
S.process()
|
||||
else
|
||||
process_shuttles -= S
|
||||
if(MC_TICK_CHECK)
|
||||
return
|
||||
|
||||
// This should be called after all the machines and radio frequencies have been properly initialized
|
||||
/datum/controller/subsystem/shuttles/proc/setup_shuttle_docks()
|
||||
// Find all declared shuttle datums and initailize them.
|
||||
for(var/shuttle_type in subtypesof(/datum/shuttle))
|
||||
var/datum/shuttle/shuttle = shuttle_type
|
||||
if(initial(shuttle.category) == shuttle_type)
|
||||
continue
|
||||
shuttle = new shuttle()
|
||||
shuttle.init_docking_controllers()
|
||||
shuttle.dock() //makes all shuttles docked to something at round start go into the docked state
|
||||
CHECK_TICK
|
||||
|
||||
for(var/obj/machinery/embedded_controller/C in machines)
|
||||
if(istype(C.program, /datum/computer/file/embedded_program/docking))
|
||||
C.program.tag = null //clear the tags, 'cause we don't need 'em anymore
|
||||
@@ -134,8 +134,6 @@ var/global/datum/controller/gameticker/ticker
|
||||
|
||||
callHook("roundstart")
|
||||
|
||||
shuttle_controller.setup_shuttle_docks()
|
||||
|
||||
// TODO - Leshana - Dear God Fix This. Fix all of this. Not just this line, this entire proc. This entire file!
|
||||
spawn(0)//Forking here so we dont have to wait for this to finish
|
||||
mode.post_setup()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//These lists are populated in /datum/shuttle_controller/New()
|
||||
//Shuttle controller is instantiated in master_controller.dm.
|
||||
//These lists are populated in /datum/controller/subsystem/shuttles/proc/setup_shuttle_docks()
|
||||
//Shuttle subsystem is instantiated in shuttles.dm.
|
||||
|
||||
//shuttle moving state defines are in setup.dm
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@
|
||||
#include "code\controllers\hooks.dm"
|
||||
#include "code\controllers\master.dm"
|
||||
#include "code\controllers\master_controller.dm"
|
||||
#include "code\controllers\shuttle_controller.dm"
|
||||
#include "code\controllers\subsystem.dm"
|
||||
#include "code\controllers\verbs.dm"
|
||||
#include "code\controllers\voting.dm"
|
||||
@@ -184,7 +183,6 @@
|
||||
#include "code\controllers\Processes\planet.dm"
|
||||
#include "code\controllers\Processes\radiation.dm"
|
||||
#include "code\controllers\Processes\scheduler.dm"
|
||||
#include "code\controllers\Processes\Shuttle.dm"
|
||||
#include "code\controllers\Processes\sun.dm"
|
||||
#include "code\controllers\Processes\supply.dm"
|
||||
#include "code\controllers\Processes\ticker.dm"
|
||||
@@ -203,6 +201,7 @@
|
||||
#include "code\controllers\subsystems\mobs.dm"
|
||||
#include "code\controllers\subsystems\orbits.dm"
|
||||
#include "code\controllers\subsystems\persist_vr.dm"
|
||||
#include "code\controllers\subsystems\shuttles.dm"
|
||||
#include "code\controllers\subsystems\transcore_vr.dm"
|
||||
#include "code\datums\ai_law_sets.dm"
|
||||
#include "code\datums\ai_laws.dm"
|
||||
|
||||
Reference in New Issue
Block a user