Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Life changes #19560

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/__DEFINES/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
// Normal
#define SS_PRIORITY_TICKER 100 // Gameticker.
//#define FIRE_PRIORITY_DEFAULT 50 // This is defined somewhere else.
#define SS_PRIORITY_MOB 40 // Mob Life().
#define SS_PRIORITY_AIR 40 // ZAS processing.
#define SS_PRIORITY_STATPANELS 25 // Statpanels.
#define SS_PRIORITY_LIGHTING 25 // Queued lighting engine updates.
Expand Down
8 changes: 8 additions & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
#define INIT_ORDER_SOUNDS 83
#define INIT_ORDER_DISCORD 78
#define INIT_ORDER_JOBS 65 // Must init before atoms, to set up properly the dynamic job lists.
#define INIT_ORDER_AI_CONTROLLERS 55 //So the controller can get the ref
#define INIT_ORDER_TICKER 55
#define INIT_ORDER_SEEDS 52 // More aurora snowflake, needs to load before the atoms init as it generates images for seeds that are used
#define INIT_ORDER_MISC_FIRST 51 //Another aurora snowflake system? Who would have guessed... Anyways, need to load before mapping or global HUDs are not ready when atoms request them
Expand Down Expand Up @@ -252,11 +253,14 @@
#define FIRE_PRIORITY_PING 10
#define FIRE_PRIORITY_GARBAGE 15
#define FIRE_PRIORITY_ASSETS 20
#define FIRE_PRIORITY_NPC_MOVEMENT 21
#define FIRE_PRIORITY_NPC_ACTIONS 22
#define FIRE_PRIORITY_PATHFINDING 23
#define FIRE_PRIORITY_PROCESS 25
#define FIRE_PRIORITY_THROWING 25
#define FIRE_PRIORITY_SPACEDRIFT 30
#define FIRE_PRIORITY_DEFAULT 50
#define FIRE_PRIORITY_MOBS 100
#define FIRE_PRIORITY_STATPANEL 390
#define FIRE_PRIORITY_CHAT 400
#define FIRE_PRIORITY_RUNECHAT 410
Expand All @@ -273,6 +277,10 @@
*/
#define addtimer(args...) _addtimer(args, file = __FILE__, line = __LINE__)

// Subsystem delta times or tickrates, in seconds. I.e, how many seconds in between each process() call for objects being processed by that subsystem.
// Only use these defines if you want to access some other objects processing seconds_per_tick, otherwise use the seconds_per_tick that is sent as a parameter to process()
#define SSMOBS_DT (SSmobs.wait/10)

/* AURORA SHIT */

// Don't display in processes panel.
Expand Down
32 changes: 13 additions & 19 deletions code/controllers/subsystems/mob.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
SUBSYSTEM_DEF(mobs)
name = "Mobs - Life"
init_order = INIT_ORDER_MISC // doesn't really matter when we init
priority = SS_PRIORITY_MOB
runlevels = RUNLEVELS_PLAYING

var/list/slept = list()
priority = FIRE_PRIORITY_MOBS
flags = SS_KEEP_TIMING
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
wait = 2 SECONDS

var/list/currentrun = list()
var/list/processing = list()
Expand Down Expand Up @@ -70,7 +69,7 @@ SUBSYSTEM_DEF(mobs)
return SS_INIT_SUCCESS

/datum/controller/subsystem/mobs/stat_entry(msg)
msg = "P:[GLOB.mob_list.len]"
msg = "P:[length(GLOB.mob_list)]"
return ..()

/datum/controller/subsystem/mobs/fire(resumed = 0)
Expand All @@ -82,24 +81,26 @@ SUBSYSTEM_DEF(mobs)
//the mobs that we didn't in the previous run, hence we have to pay the price of a list subtraction
//with &= we say to remove any item in the first list that is not in the second one
//of course, if we haven't resumed, this comparison would be useless, hence we skip it
var/list/currentrun = resumed ? (src.currentrun &= GLOB.mob_list) : src.currentrun
var/list/currentrun = resumed ? (src.currentrun &= (GLOB.mob_list + processing)) : src.currentrun

var/seconds_per_tick = wait / (1 SECONDS)

while (currentrun.len)
var/datum/thing = currentrun[currentrun.len]
while(length(currentrun))
var/datum/thing = currentrun[length(currentrun)]
currentrun.len--
if(!ismob(thing))
if(!QDELETED(thing))
if(thing.process(wait, times_fired) == PROCESS_KILL)
stop_processing(thing)
else
processing -= thing
if (MC_TICK_CHECK)
if(MC_TICK_CHECK)
return
continue

var/mob/M = thing

if (QDELETED(M))
if(QDELETED(M))
LOG_DEBUG("SSmobs: QDELETED mob [DEBUG_REF(M)] left in processing list!")
// We can just go ahead and remove them from all the mob lists.
GLOB.mob_list -= M
Expand All @@ -110,15 +111,8 @@ SUBSYSTEM_DEF(mobs)
return
continue

var/time = world.time

if (!M.frozen)
M.Life()

if (time != world.time && !slept[M.type])
slept[M.type] = TRUE
var/diff = world.time - time
LOG_DEBUG("SSmobs: Type '[M.type]' slept for [diff] ds in Life()! Suppressing further warnings.")
M.Life(seconds_per_tick, times_fired)

if (MC_TICK_CHECK)
return
Expand Down
25 changes: 13 additions & 12 deletions code/controllers/subsystems/mob_ai.dm
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
SUBSYSTEM_DEF(mob_ai)
name = "Mobs - AI"
flags = SS_NO_INIT
priority = SS_PRIORITY_MOB
runlevels = RUNLEVELS_PLAYING
flags = SS_POST_FIRE_TIMING | SS_BACKGROUND | SS_NO_INIT
priority = FIRE_PRIORITY_NPC_MOVEMENT
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
init_order = INIT_ORDER_AI_CONTROLLERS

var/list/processing = list()
var/list/currentrun = list()

///A list of mutex locks, to avoid reentry and starting new processings on mobs that were already processing from the previous run
var/list/datum/weakref/mutexes = list() //Yes i know they're opinionably not mutexes as there's only one process shut up
VAR_PRIVATE/list/datum/weakref/mutexes = list() //Yes i know they're opinionably not mutexes as there's only one process shut up

/datum/controller/subsystem/mob_ai/stat_entry(msg)
msg = "P:[processing.len]"
msg = "P:[length(processing)]"
return ..()

/datum/controller/subsystem/mob_ai/fire(resumed = FALSE)
Expand All @@ -21,7 +22,7 @@ SUBSYSTEM_DEF(mob_ai)
var/list/currentrun = src.currentrun

//Remove the mobs that have a mutex from being reprocessed again, this run
for(var/datum/weakref/locked_mob in mutexes)
for(var/datum/weakref/locked_mob as anything in mutexes)
var/mob/possible_locked_mob = locked_mob.resolve()

//The mob got QDEL'd, or otherwise somehow disappeared
Expand All @@ -31,24 +32,24 @@ SUBSYSTEM_DEF(mob_ai)

currentrun -= possible_locked_mob

while (currentrun.len)
var/mob/M = currentrun[currentrun.len]
while(length(currentrun))
var/mob/M = currentrun[length(currentrun)]
currentrun.len--

if (QDELETED(M))
if(QDELETED(M))
processing -= M
continue

if (M.ckey)
if(M.ckey)
// cliented mobs are not allowed to think
LOG_DEBUG("SSmob_ai: Type '[M.type]' was still thinking despite having a client!")
MOB_STOP_THINKING(M)
continue

if (!M.frozen && !M.stat)
if(!M.frozen && !M.stat)
INVOKE_ASYNC(src, PROC_REF(async_think), M)

if (MC_TICK_CHECK)
if(MC_TICK_CHECK)
return

/**
Expand Down
7 changes: 7 additions & 0 deletions code/controllers/subsystems/mob_fast_ai.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* This is the fast AI subsystem, used for mobs that are doing something visible and thus have priority over other mobs processing
*
* You should promote mobs to fast thinking if eg. they are fighting players or similar, and de-promote them once they resume their normal routine
*/
MOB_AI_SUBSYSTEM_DEF(mob_fast_ai)
name = "Mobs - Fast AI"
flags = SS_KEEP_TIMING | SS_BACKGROUND | SS_NO_INIT
priority = FIRE_PRIORITY_NPC_ACTIONS
wait = 5
4 changes: 3 additions & 1 deletion code/defines/procs/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ the HUD updates properly! */
// if(get_dist(H, T) <= client?.view)
// viewed += H
// return viewed
return get_hearers_in_range(client?.view, T)

//Some virtual eyes eg. the AI eye doesn't have a client but an owner, select it as preferred if so, otherwise use the mob's client itself
return get_hearers_in_range((src.owner ? src.owner.client?.view : src.client?.view), T)

/proc/get_sec_hud_icon(var/mob/living/carbon/human/H)//This function is called from human/life,dm, ~line 1663
var/state
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/tools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
damtype = DAMAGE_BURN
w_class = ITEMSIZE_LARGE
welding = TRUE
hitsound = SOUNDS_LASER_MEAT
hitsound = pick(SOUNDS_LASER_MEAT)
attack_verb = list("scorched", "burned", "blasted", "blazed")
update_icon()
set_processing(TRUE)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/heavy_vehicle/mech_life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/mob/living/heavy_vehicle/handle_status_effects()
return

/mob/living/heavy_vehicle/Life()
/mob/living/heavy_vehicle/Life(seconds_per_tick, times_fired)

// Size offsets for large mechs.
if(offset_x && pixel_x != offset_x)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/abstract/freelook/life.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/mob/abstract/eye/Life()
/mob/abstract/eye/Life(seconds_per_tick, times_fired)
..()
// If we lost our client, reset the list of visible chunks so they update properly on return
if(owner == src && !client)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/abstract/observer/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Transfer_mind is there to check if mob is being deleted/not going to have a body
Works together with spawning an observer, noted above.
*/

/mob/abstract/observer/Life()
/mob/abstract/observer/Life(seconds_per_tick, times_fired)
..()
if(!loc) return
if(!client) return 0
Expand Down
3 changes: 2 additions & 1 deletion code/modules/mob/living/announcer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
src.voice_name = initial(voice_name)
src.accent = initial(accent)

/mob/living/announcer/Life()
/mob/living/announcer/Life(seconds_per_tick, times_fired)
SHOULD_CALL_PARENT(FALSE)
return

/mob/living/announcer/Move()
Expand Down
7 changes: 5 additions & 2 deletions code/modules/mob/living/bot/bot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@
if(pAI)
. += FONT_SMALL(SPAN_NOTICE("It has a pAI piloting it."))

/mob/living/bot/Life()
/mob/living/bot/Life(seconds_per_tick, times_fired)
..()
if(health <= 0)
death()
return
return FALSE

weakened = 0
stunned = 0
paralysis = 0

return TRUE

/mob/living/bot/movement_delay()
return 3

Expand Down
8 changes: 6 additions & 2 deletions code/modules/mob/living/bot/cleanbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ GLOBAL_LIST_INIT_TYPED(cleanbot_types, /obj/effect/decal/cleanable, typesof(/obj
/mob/living/bot/cleanbot/proc/remove_from_ignore(datum/weakref/thing_to_unignore)
ignorelist -= thing_to_unignore

/mob/living/bot/cleanbot/Life()
..()
/mob/living/bot/cleanbot/Life(seconds_per_tick, times_fired)
if(!..())
return FALSE

if(!on)
ignorelist = list()
return
Expand Down Expand Up @@ -173,6 +175,8 @@ GLOBAL_LIST_INIT_TYPED(cleanbot_types, /obj/effect/decal/cleanable, typesof(/obj
ignorelist += gib
addtimer(CALLBACK(src, PROC_REF(remove_from_ignore), gib), 600)

return TRUE

/mob/living/bot/cleanbot/think()
if(pAI) // no AI if we have a pAI installed
return
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/bot/farmbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
else
icon_state = "farmbot[on]"

/mob/living/bot/farmbot/Life()
/mob/living/bot/farmbot/Life(seconds_per_tick, times_fired)
..()
if(emagged && prob(1))
flick("farmbot_broke", src)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/alien/diona/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
diona_handle_radiation(DS)


/mob/living/carbon/alien/diona/Life()
/mob/living/carbon/alien/diona/Life(seconds_per_tick, times_fired)
if(!detached && gestalt && (gestalt.life_tick % 5 == 0)) // Minimal processing while in stasis
updatehealth()
check_status_as_organ()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/alien/life.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Alien larva are quite simple.
/mob/living/carbon/alien/Life()
/mob/living/carbon/alien/Life(seconds_per_tick, times_fired)
if (transforming) return
if(!loc) return

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/carbon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if(species && species.indefinite_sleep)
add_verb(src, /verb/toggle_indefinite_sleep)

/mob/living/carbon/Life()
/mob/living/carbon/Life(seconds_per_tick, times_fired)
if(!..())
return

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
var/pressure_alert = 0
var/temperature_alert = 0

/mob/living/carbon/human/Life()
/mob/living/carbon/human/Life(seconds_per_tick, times_fired)
if (transforming)
return

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/slime/life.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/mob/living/carbon/slime/Life()
/mob/living/carbon/slime/Life(seconds_per_tick, times_fired)
if(src.transforming)
return
..()
Expand Down
12 changes: 6 additions & 6 deletions code/modules/mob/living/life.dm
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/mob/living/Life()
/mob/living/Life(seconds_per_tick, times_fired)
if (QDELETED(src)) // If they're being deleted, why bother?
return
return FALSE

..()

if (transforming)
return
if(transforming)
return FALSE

if(!loc)
return
return FALSE

var/datum/gas_mixture/gas_environment = loc.return_air()
//Handle temperature/pressure differences between body and environment
Expand All @@ -32,7 +32,7 @@
update_pulling()

for(var/obj/item/grab/G in src)
G.process()
INVOKE_ASYNC(G, TYPE_PROC_REF(/datum, process))

handle_actions()

Expand Down
Loading
Loading