Alarm system overhaul

This commit is contained in:
Markolie
2015-08-02 07:13:03 +02:00
parent 4028c2af12
commit 73e94b5dc4
66 changed files with 1452 additions and 1887 deletions
+6
View File
@@ -0,0 +1,6 @@
/datum/controller/process/alarm/setup()
name = "alarm"
schedule_interval = 20 // every 2 seconds
/datum/controller/process/alarm/doWork()
alarm_manager.fire()
+8
View File
@@ -1,11 +1,19 @@
/var/global/machinery_sort_required = 0
/datum/controller/process/machinery/setup()
name = "machinery"
schedule_interval = 20 // every 2 seconds
/datum/controller/process/machinery/doWork()
process_sort()
process_power()
process_machines()
/datum/controller/process/machinery/proc/process_sort()
if(machinery_sort_required)
machinery_sort_required = 0
machines = dd_sortedObjectList(machines)
/datum/controller/process/machinery/proc/process_machines()
for(var/obj/machinery/M in machines)
if(M && isnull(M.gcDestroyed))
+1 -19
View File
@@ -25,7 +25,7 @@ var/global/datum/controller/failsafe/failsafe
failsafe = src
failsafe.process()
//failsafe.process()
/datum/controller/failsafe/proc/process()
processing = 1
@@ -36,22 +36,4 @@ var/global/datum/controller/failsafe/failsafe
while(1) // More efficient than recursivly calling ourself over and over. background = 1 ensures we do not trigger an infinite loop.
iteration++
if(processing)
if(master_controller.processing) // Only poke if these overrides aren't in effect
if(masterControllerIteration == master_controller.iteration) // Master controller hasn't finished processing in the defined interval.
switch(masterControllerAlertLevel)
if(0 to 3)
masterControllerAlertLevel++
if(4)
admins << "<font color='red' size='2'><b>Warning. The master Controller has not fired in the last [masterControllerAlertLevel * processing_interval] ticks. Automatic restart in [processing_interval] ticks.</b></font>"
masterControllerAlertLevel = 5
if(5)
admins << "<font color='red' size='2'><b>Warning. The master Controller has still not fired within the last [masterControllerAlertLevel * processing_interval] ticks. Killing and restarting...</b></font>"
new /datum/controller/game_controller() // Replace the old master controller (hence killing the old one's process).
master_controller.process() // Start it rolling again.
masterControllerAlertLevel = 0
else
masterControllerAlertLevel = 0
masterControllerIteration = master_controller.iteration
sleep(processing_interval)
-278
View File
@@ -18,27 +18,6 @@ var/global/pipe_processing_killed = 0
/datum/controller/proc/recover() // If we are replacing an existing controller (due to a crash) we attempt to preserve as much as we can.
datum/controller/game_controller
var/breather_ticks = 2 //a somewhat crude attempt to iron over the 'bumps' caused by high-cpu use by letting the MC have a breather for this many ticks after every loop
var/minimum_ticks = 20 //The minimum length of time between MC ticks
var/air_cost = 0
var/sun_cost = 0
var/mobs_cost = 0
var/diseases_cost = 0
var/machines_cost = 0
var/aibots_cost = 0
var/objects_cost = 0
var/networks_cost = 0
var/powernets_cost = 0
var/nano_cost = 0
var/events_cost = 0
var/puddles_cost
var/ticker_cost = 0
var/garbageCollectorCost = 0
var/total_cost = 0
var/last_thing_processed
var/list/shuttle_list // For debugging and VV
var/global/datum/garbage_collector/garbageCollector
@@ -47,7 +26,6 @@ datum/controller/game_controller/New()
//There can be only one master_controller. Out with the old and in with the new.
if(master_controller != src)
if(istype(master_controller))
Recover()
del(master_controller)
master_controller = src
@@ -59,8 +37,6 @@ datum/controller/game_controller/New()
if(!syndicate_code_phrase) syndicate_code_phrase = generate_code_phrase()
if(!syndicate_code_response) syndicate_code_response = generate_code_phrase()
//if(!emergency_shuttle) emergency_shuttle = new /datum/emergency_shuttle_controller() MOVED TO SCHEDULER
//if(!shuttle_controller) shuttle_controller = new /datum/shuttle_controller()
datum/controller/game_controller/proc/setup()
world.tick_lag = config.Ticklag
@@ -68,16 +44,6 @@ datum/controller/game_controller/proc/setup()
spawn(20)
createRandomZlevel()
/* MOVED TO SCHEDULER
if(!air_master)
air_master = new /datum/controller/air_system()
air_master.Setup()
if(!ticker)
ticker = new /datum/controller/gameticker()
*/
setup_objects()
setup_starlight()
setupgenetics()
@@ -89,14 +55,6 @@ datum/controller/game_controller/proc/setup()
make_mining_asteroid_secret()
populate_spawn_points()
/* MOVED TO SCHEDULER
spawn(0)
if(ticker)
ticker.pregame()
lighting_controller.Initialize()
*/
datum/controller/game_controller/proc/setup_objects()
world << "\red \b Initializing objects"
@@ -119,9 +77,6 @@ datum/controller/game_controller/proc/setup_objects()
var/obj/machinery/atmospherics/unary/vent_scrubber/T = U
T.broadcast_status()
//Set up roundstart seed list.
//populate_seed_list()
world << "\red \b Initializations complete."
sleep(-1)
@@ -130,236 +85,3 @@ datum/controller/game_controller/proc/setup_starlight()
for(var/turf/space/S in world)
S.update_starlight()
world << "\red \b Starlight Initilization Complete"
datum/controller/game_controller/proc/process()
processing = 1
spawn(0)
//set background = 1
while(1) //far more efficient than recursively calling ourself
if(!failsafe) new /datum/controller/failsafe()
if(processing)
var/timer
var/start_time = world.timeofday
controller_iteration++
vote.process()
// transfer_controller.process()
shuttle_controller.process()
process_newscaster()
//AIR
if(!air_processing_killed)
timer = world.timeofday
last_thing_processed = air_master.type
air_master.current_cycle++
// if(!air_master.tick()) Runtimed.
if(!air_master.process())
air_master.failed_ticks++
if(air_master.failed_ticks > 5)
world << "<font color='red'><b>RUNTIMES IN ATMOS TICKER. Killing air simulation!</font></b>"
world.log << "### LINDA SHUTDOWN"
message_admins("LINDAALERT: unable to run [air_master.tick_progress], shutting down!")
log_admin("LINDAALERT: unable run zone/process() -- [air_master.tick_progress]")
air_processing_killed = 1
air_master.failed_ticks = 0
air_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//SUN
timer = world.timeofday
last_thing_processed = sun.type
sun.calc_position()
sun_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//MOBS
timer = world.timeofday
processMobs()
mobs_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//MACHINES
timer = world.timeofday
processMachines()
machines_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//BOTS
timer = world.timeofday
process_bots()
aibots_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//OBJECTS
timer = world.timeofday
processObjects()
objects_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//PIPENETS
if(!pipe_processing_killed)
timer = world.timeofday
processPipenets()
networks_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//POWERNETS
timer = world.timeofday
processPowernets()
powernets_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//NANO UIS
timer = world.timeofday
processNano()
nano_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//EVENTS
timer = world.timeofday
processEvents()
events_cost = (world.timeofday - timer) / 10
/*
//PUDDLES
timer = world.timeofday
processPuddles()
puddles_cost = (world.timeofday - timer) / 10
*/
//TICKER
timer = world.timeofday
last_thing_processed = ticker.type
ticker.process()
ticker_cost = (world.timeofday - timer) / 10
// GC
timer = world.timeofday
last_thing_processed = garbageCollector.type
garbageCollector.process()
garbageCollectorCost = (world.timeofday - timer) / 10
//TIMING
total_cost = air_cost + sun_cost + mobs_cost + diseases_cost + machines_cost + aibots_cost + objects_cost + networks_cost + powernets_cost + nano_cost + events_cost + puddles_cost + ticker_cost + garbageCollectorCost
var/end_time = world.timeofday
if(end_time < start_time) //why not just use world.time instead?
start_time -= 864000 //deciseconds in a day
sleep( round(minimum_ticks - (end_time - start_time),1) )
else
sleep(10)
/datum/controller/game_controller/proc/processMobs()
for (var/mob/Mob in mob_list)
if (Mob)
last_thing_processed = Mob.type
Mob.Life()
continue
mob_list = mob_list - Mob
/datum/controller/game_controller/proc/processMachines()
for (var/obj/machinery/Machinery in machines)
if (Machinery && Machinery.loc)
last_thing_processed = Machinery.type
if(Machinery.process() != PROCESS_KILL)
if (Machinery) // Why another check?
if (Machinery.use_power)
Machinery.auto_use_power()
continue
if(Machinery) Machinery.removeAtProcessing()
/datum/controller/game_controller/proc/process_bots()
for(var/obj/machinery/bot/Bot in aibots)
if(Bot && isnull(Bot.gcDestroyed))
last_thing_processed = Bot.type
spawn(0)
Bot.bot_process()
continue
else
aibots -= Bot
/datum/controller/game_controller/proc/processObjects()
for (var/obj/Object in processing_objects)
if (Object && Object.loc)
last_thing_processed = Object.type
Object.process()
continue
processing_objects -= Object
/datum/controller/game_controller/proc/processPipenets()
last_thing_processed = /datum/pipe_network
for (var/datum/pipe_network/Pipe_Network in pipe_networks)
if(Pipe_Network)
Pipe_Network.process()
continue
pipe_networks -= Pipe_Network
/datum/controller/game_controller/proc/processPowernets()
last_thing_processed = /datum/powernet
for (var/datum/powernet/Powernet in powernets)
if (Powernet)
Powernet.reset()
continue
powernets -= Powernet
/datum/controller/game_controller/proc/processNano()
last_thing_processed = /datum/nanoui
for (var/datum/nanoui/Nanoui in nanomanager.processing_uis)
if (Nanoui)
Nanoui.process()
continue
nanomanager.processing_uis -= Nanoui
/datum/controller/game_controller/proc/processEvents()
last_thing_processed = /datum/event
event_manager.process()
/*
/datum/controller/game_controller/proc/processPuddles()
last_thing_processed = /datum/puddle
for (var/datum/puddle/Puddle in puddles)
if (Puddle)
Puddle.process()
continue
*/
datum/controller/game_controller/proc/Recover() //Mostly a placeholder for now.
var/msg = "## DEBUG: [time2text(world.timeofday)] MC restarted. Reports:\n"
for(var/varname in master_controller.vars)
switch(varname)
if("tag","bestF","type","parent_type","vars") continue
else
var/varval = master_controller.vars[varname]
if(istype(varval,/datum))
var/datum/D = varval
msg += "\t [varname] = [D.type]\n"
else
msg += "\t [varname] = [varval]\n"
world.log << msg
+30
View File
@@ -0,0 +1,30 @@
// We manually initialize the alarm handlers instead of looping over all existing types
// to make it possible to write: camera.triggerAlarm() rather than alarm_manager.managers[datum/alarm_handler/camera].triggerAlarm() or a variant thereof.
/var/global/datum/alarm_handler/atmosphere/atmosphere_alarm = new()
/var/global/datum/alarm_handler/camera/camera_alarm = new()
/var/global/datum/alarm_handler/fire/fire_alarm = new()
/var/global/datum/alarm_handler/motion/motion_alarm = new()
/var/global/datum/alarm_handler/power/power_alarm = new()
/datum/subsystem/alarm
name = "Alarm"
var/list/datum/alarm/all_handlers
/datum/subsystem/alarm/New()
all_handlers = list(atmosphere_alarm, camera_alarm, fire_alarm, motion_alarm, power_alarm)
/datum/subsystem/alarm/fire()
for(var/datum/alarm_handler/AH in all_handlers)
AH.process()
/datum/subsystem/alarm/proc/active_alarms()
var/list/all_alarms = new
for(var/datum/alarm_handler/AH in all_handlers)
var/list/alarms = AH.alarms
all_alarms += alarms
return all_alarms
/datum/subsystem/alarm/proc/number_of_active_alarms()
var/list/alarms = active_alarms()
return alarms.len
+46
View File
@@ -0,0 +1,46 @@
#define NEW_SS_GLOBAL(varname) if(varname != src){if(istype(varname)){Recover();qdel(varname);}varname = src;}
/datum/subsystem
//things you will want to define
var/name //name of the subsystem
var/priority = 0 //priority affects order of initialization. Higher priorities are initialized first, lower priorities later. Can be decimal and negative values.
var/wait = 20 //time to wait (in deciseconds) between each call to fire(). Must be a positive integer.
//things you will probably want to leave alone
var/can_fire = 0 //prevent fire() calls
var/last_fire = 0 //last world.time we called fire()
var/next_fire = 0 //scheduled world.time for next fire()
var/cpu = 0 //cpu-usage stats (somewhat vague)
var/cost = 0 //average time to execute
var/times_fired = 0 //number of times we have called fire()
//used to initialize the subsystem BEFORE the map has loaded
/datum/subsystem/New()
//previously, this would have been named 'process()' but that name is used everywhere for different things!
//fire() seems more suitable. This is the procedure that gets called every 'wait' deciseconds.
//fire(), and the procs it calls, SHOULD NOT HAVE ANY SLEEP OPERATIONS in them!
//YE BE WARNED!
/datum/subsystem/proc/fire()
can_fire = 0
//used to initialize the subsystem AFTER the map has loaded
/datum/subsystem/proc/Initialize(start_timeofday)
var/time = (world.timeofday - start_timeofday) / 10
var/msg = "Initialized [name] SubSystem within [time] seconds"
world << "<span class='userdanger'>[msg]</span>"
world.log << msg
//hook for printing stats to the "MC" statuspanel for admins to see performance and related stats etc.
/datum/subsystem/proc/stat_entry()
stat(name, "[round(cost,0.001)]ds\t(CPU:[round(cpu,1)]%)")
//could be used to postpone a costly subsystem for one cycle
//for instance, during cpu intensive operations like explosions
/datum/subsystem/proc/postpone()
if(next_fire - world.time < wait)
next_fire += wait
//usually called via datum/subsystem/New() when replacing a subsystem (i.e. due to a recurring crash)
//should attempt to salvage what it can from the old instance of subsystem
/datum/subsystem/proc/Recover()
+4 -5
View File
@@ -11,10 +11,6 @@
usr = null
src = null
switch(controller)
if("Master")
new /datum/controller/game_controller()
master_controller.process()
feedback_add_details("admin_verb","RMC")
if("Failsafe")
new /datum/controller/failsafe()
feedback_add_details("admin_verb","RFailsafe")
@@ -25,7 +21,7 @@
return
/client/proc/debug_controller(controller in list("Master","failsafe","Ticker","Air","Lighting","Jobs","Sun","Radio","Supply","Shuttles","Emergency Shuttle","Configuration","pAI", "Cameras","Garbage", "Transfer Controller","Event","Scheduler"))
/client/proc/debug_controller(controller in list("Master","failsafe","Ticker","Air","Lighting","Jobs","Sun","Radio","Supply","Shuttles","Emergency Shuttle","Configuration","pAI", "Cameras","Garbage", "Transfer Controller","Event","Alarm","Scheduler"))
set category = "Debug"
set name = "Debug Controller"
set desc = "Debug the various periodic loop controllers for the game (be careful!)"
@@ -77,6 +73,9 @@
if("Event")
debug_variables(event_manager)
feedback_add_details("admin_verb","DEvent")
if("Alarm")
debug_variables(alarm_manager)
feedback_add_details("admin_verb", "DAlarm")
if("Garbage")
debug_variables(garbageCollector)
feedback_add_details("admin_verb","DGarbage")