Files
CHOMPStation2/code/controllers/ProcessScheduler/core/process.dm
Spades 7e84419866 September Polaris Sync (#545)
* Removes Captain as a title, sets default to Station Administrator, and adds a new title, Site Manager

* Fix atmo_control interface temperature reading

* Adds Multiple Alternative Titles

* Removed Supply Assistant

* Removed Sergeant

* Removed Computer Scientist

* Revert "Revert "Frame Cleanup""

This reverts commit 82722ba42f.

* Changed Supply Officer to Requisitions Officer

* Changed Requisitions Officer to Supply Chief and Removed Courier

* Removed Life Support Technician

* Removed Brig Officer

* Tweaks the lowest level of heat damage to be less insane

* Corrects damage amount for heat_damage_level_1

* Maybe Perhaps Last Major Technomancer PR
Adds ability to sort the spells section of the catalog into categories.  The categories available are 'All', 'Offensive', 'Defensive', 'Utility', and 'Support'.
Removes preset section on catalog as it was unused.
Projectile spells now have a sound when fired.
Haste lasts five seconds instead of three.
Repel Missiles lasts for five minutes instead of two.
All healing spells work five times as fast, healing in five seconds instead of twenty five seconds.  The amount of instability and healing done has been multiplied to remain consistent.
Passwall can now be used on more than just walls, if there's something dense on the same tile.
Force Missile is now 25% cheaper to cast, and has a cooldown of .5 seconds instead of one second, and does 5 more damage.
Beam's damage is increased by 10, and energy cost decreased by 25%.
Lightning's warm-up time is now one second instead of two.
Overload now costs 10% of total energy instead of 15%, and damage scaled with 4% of their current energy reserves, and 5% with the Scepter, instead of 3%/4%.  Additionally, instability per shot is lowered to 12 from 15.
Track now costs 25 points instead of 30 in the catalog, because roundness.
Fire Aura should look more impressive without a Scepter.
Fixes bug where shooting Lightning made you motionless for twenty seconds.

* Adds Multiple New Clothing Items

* Makes Loincloths only Availiable to Taj and Unathi

* Tweaks the contents of the captain's closet

* Smokables now give an approximation of how much longer they'll burn once lit

* make teshari not bad to play

* Tea Tweaks

- Minor changes to the color of some of the drinks such as tea and iced tea. Still not happy with the colors, but they seem better than before.
- Modification to the British cup sprite.
- Addition of a tea sprite for the coffee cups.

* fixes exception handling runtiming

* Adds missing error handler that made it difficult to debug runtimes.

* Corrects error handling proc

* Adds missing runtime viewer Topic calls.

Relocates them to the datum itself rather than it being an admin topic for maximum self-containment.
Also adds 'adminplayerobservefollow', making it possible for admins to not only jump to mobs but also follow them with a single click.
Misc tweaks from Paradise.

* gib population

* Adds the ash() mob proc, preps ninja suit

* Fixes #2352

* Changelog

* alt title

* Rigs now have suit coolers

* Map edit

- Fixes lighting in Security. Again.
- Fixes lighting in Library.
- Adds a new maint tunnel between engineering solars and atmos, now
outside the blast radius of SME explosions.

* Almost forgot emergency shutters.

* Examine Cigarette Lore

* Fixes Capitalization

* Eliminates colon

* Should clear up the usr issue

* Fixes cryopods of all types not setting occupant correctly.

* updates changelog

* Fixes runtime that occured if someone touched a blast door with an empty hand.

* Fixes check_rights() runtime.

* Adds magboots to ling spacesuits

* Adds Changelog

* Turret Fix
Turrets can now deploy properly and not be stuck in a state of deploying forever if a target is in range.

* Revert "Adds hub passwordu"

* Makes changeling recursive enhancement a passive power

* Corrects a description

* Adss changelog

* Add files via upload

* Changeling/Wizard/Future Stuff Hud Button Fix
Hopefully this stops the roundstop changeling hud wonkiness.

* Changes Mining Hardsuit slowdown to 1, from 3

* Widened hallway

* Speeds up arm_guard and leg_guard wearers slightly

* Forgot to use map cleanup tool.

* Adds changelog

* Adds changelog

* Minor Emitter Tweaks
Emitters no longer die by shooting a taser or laser tag gun at it.
Emitters don't explode if they are not on a powered wire with sufficient electricity in it.  They will just crumple away instead if integrity is reduced to zero.
Taking any damage to the emitter no longer results in instant death due to me being an idiot awhile ago.
Emitters can be examined to see if they are damaged, and can be repaired by applying metal sheets to it.

* Github, stop being stupid!

* Tweaks Sec Voidsuit values

* Fixes external airlocks

* Elevator-MMI fix

* Shoveling Snow

* Laptop ID Computer Fix
The manifest should now be updated correctly when using laptops.

* do_after is more immersive

* Fixes second bug involving inability to change title to station admin.

* Adds more unathi hair and facial options

* Adds the changelog

* Retweaks secret player requirements

* Updates changelog

* Fixes sprite not updating to not be floating when leaving non-gravity

* Adds changelog

* Fixes changeling revive not working when you're missing a limb

* Fixes #860

* Adds changelog

* Makes flash confused duration the same length as the flash blurry eyes

* Increases the change of lung rupturing

* Adds vomit as an emote

* Adds changelog

* Removes revolution shuttle delay

* Adds changelog

* Projectile flash rounds will now do the same as a flash when hitting a target

* Adds changelog

* Fixes dna-lockable gun explosion security level

* Drink Container Lore

* Decapitalizes 'Sleeper'  Because Why

* Fixes Grammatical/Flow/Sarcasm Errors

* Completes dna lockable guns implementation by adding a dna chip that can be added to guns

* Fixes + forgotten file

* Moves DNA locking stuff down to the item level rather than gun, also adds the ability to emag to remove the lock

* Adds changelog

* Adds the ability to wear ponchos as an accessory, also adds the ability to have ponchos as a suit accessory

* Adds changelog

* Closes 2 missing spans

* Adds secure briefcase to custom loadout

* Adds changelog

* Headgear Additions, and an Undershirt

* Medical splint buff and new ghetto splints.
Adds hands and feet to splint-splintable organs.
Also adds ghetto splints that can't do hands and feet.

* Fixed Sleeper... Again

* Renames "poncho" slot to "over"

* Speeds Hyperzine metabolism

* 1.5.8 Map bug fixes
-Fixed brit cup sprite.
- Replaced a maintenance door leading into atmospherics with one with the proper access.
- Fixed Missing Disposals pipe next to atmos.
- Tweaked some light placement in the main hallways.
- AI core redesign.
- Turned off medbay lobby intercom.
- Cyborg charging station added to prison wing.
- Cyborg charging station added to the research outpost.
- Medical rig suit added to medical.
- EVA rig suit for engineering added to EVA.
- Second  residential elevator installed. Due to budget cuts the size of the elevators has been reduced.

* Updates changelog

* Sombrero Code

* Fixes #2365

* Adds changelog

* Sleeper is evil.

* no message

* Changelog

* Stops observers from leaving prints on the ground.

No more spooking the mortals, ghosts.

* Allows autotraitor in secret to start with 0 players

* Adds changelog

* Makes diona slightly less slow

* Adds changelog

* Bowling Shirts

* Updates changelog

* Adds a missing description

* Flat Cap Changes and Hair Bow

* Fixed Error

* Adds an in-hand

* Lower Torso cannot be amputated

* Smoke works, adds changelog

* Updates changelog

* Makes Unathi Voidsuits Less Fat

* Medical related fixes

* Fuzzy Cuffs

* Tube Top

* Made Icons for Security Suit Less Gaunt

* Revert "Medical related fixes"

This reverts commit d7c59520e6.

* Just the fix to random med item now

* Fixes Evening Glove Coloring

* HAZMAT Suits

* Changes Unathi sprite slightly

* Tweaks skirt pathing

* Corrects changelog

* Adds changelog

* Construction Voidsuits

* makes people bleed real good

* adderino changeling

* Revert "Revert "Adds hub passwordu""

* Explosive implants should no longer gib on limbs.

* I still have no idea what I am doing.

* Resolves #331
2016-09-11 19:52:40 -04:00

359 lines
9.7 KiB
Plaintext

// Process
/datum/controller/process
/**
* State vars
*/
// Main controller ref
var/tmp/datum/controller/processScheduler/main
// 1 if process is not running or queued
var/tmp/idle = 1
// 1 if process is queued
var/tmp/queued = 0
// 1 if process is running
var/tmp/running = 0
// 1 if process is blocked up
var/tmp/hung = 0
// 1 if process was killed
var/tmp/killed = 0
// Status text var
var/tmp/status
// Previous status text var
var/tmp/previousStatus
// 1 if process is disabled
var/tmp/disabled = 0
/**
* Config vars
*/
// Process name
var/name
// Process schedule interval
// This controls how often the process would run under ideal conditions.
// If the process scheduler sees that the process has finished, it will wait until
// this amount of time has elapsed from the start of the previous run to start the
// process running again.
var/tmp/schedule_interval = PROCESS_DEFAULT_SCHEDULE_INTERVAL // run every 50 ticks
// Process sleep interval
// This controls how often the process will yield (call sleep(0)) while it is running.
// Every concurrent process should sleep periodically while running in order to allow other
// processes to execute concurrently.
var/tmp/sleep_interval
// hang_warning_time - this is the time (in 1/10 seconds) after which the server will begin to show "maybe hung" in the context window
var/tmp/hang_warning_time = PROCESS_DEFAULT_HANG_WARNING_TIME
// hang_alert_time - After this much time(in 1/10 seconds), the server will send an admin debug message saying the process may be hung
var/tmp/hang_alert_time = PROCESS_DEFAULT_HANG_ALERT_TIME
// hang_restart_time - After this much time(in 1/10 seconds), the server will automatically kill and restart the process.
var/tmp/hang_restart_time = PROCESS_DEFAULT_HANG_RESTART_TIME
// How many times in the current run has the process deferred work till the next tick?
var/tmp/cpu_defer_count = 0
// How many SCHECKs have been skipped (to limit btime calls)
var/tmp/calls_since_last_scheck = 0
/**
* recordkeeping vars
*/
// Records the time (1/10s timeoftick) at which the process last finished sleeping
var/tmp/last_slept = 0
// Records the time (1/10s timeofgame) at which the process last began running
var/tmp/run_start = 0
// Records the number of times this process has been killed and restarted
var/tmp/times_killed
// Tick count
var/tmp/ticks = 0
var/tmp/last_task = ""
var/tmp/last_object
// Counts the number of times an exception has occurred; gets reset after 10
var/tmp/list/exceptions = list()
// Number of deciseconds to delay before starting the process
var/start_delay = 0
/datum/controller/process/New(var/datum/controller/processScheduler/scheduler)
..()
main = scheduler
previousStatus = "idle"
idle()
name = "process"
schedule_interval = 50
sleep_interval = world.tick_lag / PROCESS_DEFAULT_SLEEP_INTERVAL
last_slept = 0
run_start = 0
ticks = 0
last_task = 0
last_object = null
/datum/controller/process/proc/started()
// Initialize run_start so we can detect hung processes.
run_start = TimeOfGame
// Initialize defer count
cpu_defer_count = 0
running()
main.processStarted(src)
onStart()
/datum/controller/process/proc/finished()
ticks++
idle()
main.processFinished(src)
onFinish()
/datum/controller/process/proc/doWork()
/datum/controller/process/proc/setup()
/datum/controller/process/proc/process()
started()
doWork()
finished()
/datum/controller/process/proc/running()
idle = 0
queued = 0
running = 1
hung = 0
setStatus(PROCESS_STATUS_RUNNING)
/datum/controller/process/proc/idle()
queued = 0
running = 0
idle = 1
hung = 0
setStatus(PROCESS_STATUS_IDLE)
/datum/controller/process/proc/queued()
idle = 0
running = 0
queued = 1
hung = 0
setStatus(PROCESS_STATUS_QUEUED)
/datum/controller/process/proc/hung()
hung = 1
setStatus(PROCESS_STATUS_HUNG)
/datum/controller/process/proc/handleHung()
var/datum/lastObj = last_object
var/lastObjType = "null"
if(istype(lastObj))
lastObjType = lastObj.type
var/msg = "[name] process hung at tick #[ticks]. Process was unresponsive for [(TimeOfGame - run_start) / 10] seconds and was restarted. Last task: [last_task]. Last Object Type: [lastObjType]"
log_debug(msg)
message_admins(msg)
main.restartProcess(src.name)
/datum/controller/process/proc/kill()
if (!killed)
var/msg = "[name] process was killed at tick #[ticks]."
log_debug(msg)
message_admins(msg)
//finished()
// Allow inheritors to clean up if needed
onKill()
// This should del
del(src)
// Do not call this directly - use SHECK or SCHECK_EVERY
/datum/controller/process/proc/sleepCheck(var/tickId = 0)
calls_since_last_scheck = 0
if (killed)
// The kill proc is the only place where killed is set.
// The kill proc should have deleted this datum, and all sleeping procs that are
// owned by it.
CRASH("A killed process is still running somehow...")
if (hung)
// This will only really help if the doWork proc ends up in an infinite loop.
handleHung()
CRASH("Process [name] hung and was restarted.")
if (main.getCurrentTickElapsedTime() > main.timeAllowance)
sleep(world.tick_lag)
cpu_defer_count++
last_slept = 0
else
if (TimeOfTick > last_slept + sleep_interval)
// If we haven't slept in sleep_interval deciseconds, sleep to allow other work to proceed.
sleep(0)
last_slept = TimeOfTick
/datum/controller/process/proc/update()
// Clear delta
if(previousStatus != status)
setStatus(status)
var/elapsedTime = getElapsedTime()
if (hung)
handleHung()
return
else if (elapsedTime > hang_restart_time)
hung()
else if (elapsedTime > hang_alert_time)
setStatus(PROCESS_STATUS_PROBABLY_HUNG)
else if (elapsedTime > hang_warning_time)
setStatus(PROCESS_STATUS_MAYBE_HUNG)
/datum/controller/process/proc/getElapsedTime()
return TimeOfGame - run_start
/datum/controller/process/proc/tickDetail()
return
/datum/controller/process/proc/getContext()
return "<tr><td>[name]</td><td>[main.averageRunTime(src)]</td><td>[main.last_run_time[src]]</td><td>[main.highest_run_time[src]]</td><td>[ticks]</td></tr>\n"
/datum/controller/process/proc/getContextData()
return list(
"name" = name,
"averageRunTime" = main.averageRunTime(src),
"lastRunTime" = main.last_run_time[src],
"highestRunTime" = main.highest_run_time[src],
"ticks" = ticks,
"schedule" = schedule_interval,
"status" = getStatusText(),
"disabled" = disabled
)
/datum/controller/process/proc/getStatus()
return status
/datum/controller/process/proc/getStatusText(var/s = 0)
if(!s)
s = status
switch(s)
if(PROCESS_STATUS_IDLE)
return "idle"
if(PROCESS_STATUS_QUEUED)
return "queued"
if(PROCESS_STATUS_RUNNING)
return "running"
if(PROCESS_STATUS_MAYBE_HUNG)
return "maybe hung"
if(PROCESS_STATUS_PROBABLY_HUNG)
return "probably hung"
if(PROCESS_STATUS_HUNG)
return "HUNG"
else
return "UNKNOWN"
/datum/controller/process/proc/getPreviousStatus()
return previousStatus
/datum/controller/process/proc/getPreviousStatusText()
return getStatusText(previousStatus)
/datum/controller/process/proc/setStatus(var/newStatus)
previousStatus = status
status = newStatus
/datum/controller/process/proc/setLastTask(var/task, var/object)
last_task = task
last_object = object
/datum/controller/process/proc/_copyStateFrom(var/datum/controller/process/target)
main = target.main
name = target.name
schedule_interval = target.schedule_interval
sleep_interval = target.sleep_interval
last_slept = 0
run_start = 0
times_killed = target.times_killed
ticks = target.ticks
last_task = target.last_task
last_object = target.last_object
copyStateFrom(target)
/datum/controller/process/proc/copyStateFrom(var/datum/controller/process/target)
/datum/controller/process/proc/onKill()
/datum/controller/process/proc/onStart()
/datum/controller/process/proc/onFinish()
/datum/controller/process/proc/disable()
disabled = 1
/datum/controller/process/proc/enable()
disabled = 0
/datum/controller/process/proc/getAverageRunTime()
return main.averageRunTime(src)
/datum/controller/process/proc/getLastRunTime()
return main.getProcessLastRunTime(src)
/datum/controller/process/proc/getHighestRunTime()
return main.getProcessHighestRunTime(src)
/datum/controller/process/proc/getTicks()
return ticks
/datum/controller/process/proc/statProcess()
var/averageRunTime = round(getAverageRunTime(), 0.1)/10
var/lastRunTime = round(getLastRunTime(), 0.1)/10
var/highestRunTime = round(getHighestRunTime(), 0.1)/10
stat("[name]", "T#[getTicks()] | AR [averageRunTime] | LR [lastRunTime] | HR [highestRunTime] | D [cpu_defer_count]")
/datum/controller/process/proc/catchException(var/exception/e, var/thrower)
if(istype(e)) // Real runtimes go to the real error handler
log_runtime(e, thrower, "Caught by process: [name]")
return
var/etext = "[e]"
var/eid = "[e]" // Exception ID, for tracking repeated exceptions
var/ptext = "" // "processing..." text, for what was being processed (if known)
if(istype(e))
etext += " in [e.file], line [e.line]"
eid = "[e.file]:[e.line]"
if(eid in exceptions)
if(exceptions[eid]++ >= 10)
return
else
exceptions[eid] = 1
if(istype(thrower, /datum))
var/datum/D = thrower
ptext = " processing [D.type]"
if(istype(thrower, /atom))
var/atom/A = thrower
ptext += " ([A]) ([A.x],[A.y],[A.z])"
log_to_dd("\[[time_stamp()]\] Process [name] caught exception[ptext]: [etext]")
if(exceptions[eid] >= 10)
log_to_dd("This exception will now be ignored for ten minutes.")
spawn(6000)
exceptions[eid] = 0
/datum/controller/process/proc/catchBadType(var/datum/caught)
if(isnull(caught) || !istype(caught) || !isnull(caught.gcDestroyed))
return // Only bother with types we can identify and that don't belong
catchException("Type [caught.type] does not belong in process' queue")