From 190e8bdd5a207d6bf37008253d1778e9d34c4f08 Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 09:40:39 -0400 Subject: [PATCH 1/6] Try to ensure some mobs don't end up processing in SSmobs --- code/_helpers/unsorted.dm | 5 +++++ code/modules/integrated_electronics/subtypes/output.dm | 1 + code/modules/mob/living/silicon/ai/ai.dm | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/code/_helpers/unsorted.dm b/code/_helpers/unsorted.dm index 2362ff1b3d..ec946e66bd 100644 --- a/code/_helpers/unsorted.dm +++ b/code/_helpers/unsorted.dm @@ -1303,6 +1303,11 @@ var/mob/dview/dview_mob = new else living_mob_list -= src +/mob/dview/Life() + mob_list -= src + dead_mob_list -= src + living_mob_list -= src + /mob/dview/Destroy(var/force) crash_with("Attempt to delete the dview_mob: [log_info_line(src)]") if (!force) diff --git a/code/modules/integrated_electronics/subtypes/output.dm b/code/modules/integrated_electronics/subtypes/output.dm index 8745591d7f..5154804b05 100644 --- a/code/modules/integrated_electronics/subtypes/output.dm +++ b/code/modules/integrated_electronics/subtypes/output.dm @@ -152,6 +152,7 @@ /obj/item/integrated_circuit/output/text_to_speech/advanced/Initialize() ..() my_voice = new (src) + mob_list -= my_voice // no life() ticks my_voice.name = "TTS Circuit" /obj/item/integrated_circuit/output/text_to_speech/advanced/do_work() diff --git a/code/modules/mob/living/silicon/ai/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index 22707c6dbb..63564aaa53 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -985,9 +985,15 @@ var/list/ai_verbs_default = list( dead_mob_list -= src ai_list -= src silicon_mob_list -= src + QDEL_NULL(eyeobj) /mob/living/silicon/ai/announcer/Life() - return + mob_list -= src + living_mob_list -= src + dead_mob_list -= src + ai_list -= src + silicon_mob_list -= src + QDEL_NULL(eyeobj) #undef AI_CHECK_WIRELESS #undef AI_CHECK_RADIO From 0bad4363b8e25e7e29b0bf6a04a112fe14577a83 Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 10:00:14 -0400 Subject: [PATCH 2/6] Sleep AI processing when nobody on their Zlevel --- code/controllers/subsystems/ai.dm | 21 +++++++++++++++---- code/game/world.dm | 5 +++++ code/modules/ai/ai_holder.dm | 3 +++ code/modules/ai/ai_holder_disabled.dm | 2 +- .../mob/living/simple_mob/simple_mob.dm | 3 +++ code/modules/mob/mob.dm | 10 +++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/code/controllers/subsystems/ai.dm b/code/controllers/subsystems/ai.dm index 5ebbb22a2f..0641453f2b 100644 --- a/code/controllers/subsystems/ai.dm +++ b/code/controllers/subsystems/ai.dm @@ -9,14 +9,22 @@ SUBSYSTEM_DEF(ai) var/list/processing = list() var/list/currentrun = list() + var/slept_mobs = 0 + var/list/process_z = list() + /datum/controller/subsystem/ai/stat_entry(msg_prefix) - var/list/msg = list(msg_prefix) - msg += "P:[processing.len]" - ..(msg.Join()) + ..("P: [processing.len] | S: [slept_mobs]") /datum/controller/subsystem/ai/fire(resumed = 0) if (!resumed) src.currentrun = processing.Copy() + process_z.Cut() + slept_mobs = 0 + var/level = 1 + while(process_z.len < GLOB.living_players_by_zlevel.len) + process_z.len++ + process_z[level] = GLOB.living_players_by_zlevel[level].len + level++ //cache for sanic speed (lists are references anyways) var/list/currentrun = src.currentrun @@ -26,7 +34,12 @@ SUBSYSTEM_DEF(ai) --currentrun.len if(!A || QDELETED(A) || A.busy) // Doesn't exist or won't exist soon or not doing it this tick continue - A.handle_strategicals() + + if(process_z[get_z(A.holder)]) + A.handle_strategicals() + else + slept_mobs++ + A.set_stance(STANCE_IDLE) if(MC_TICK_CHECK) return diff --git a/code/game/world.dm b/code/game/world.dm index 18568ed60d..8d0f5cd02c 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -648,9 +648,14 @@ proc/establish_old_db_connection() /world/proc/max_z_changed() if(!istype(GLOB.players_by_zlevel, /list)) GLOB.players_by_zlevel = new /list(world.maxz, 0) + GLOB.living_players_by_zlevel = new /list(world.maxz, 0) + while(GLOB.players_by_zlevel.len < world.maxz) GLOB.players_by_zlevel.len++ GLOB.players_by_zlevel[GLOB.players_by_zlevel.len] = list() + + GLOB.living_players_by_zlevel.len++ + GLOB.living_players_by_zlevel[GLOB.living_players_by_zlevel.len] = list() // Call this to make a new blank z-level, don't modify maxz directly. /world/proc/increment_max_z() diff --git a/code/modules/ai/ai_holder.dm b/code/modules/ai/ai_holder.dm index 0a3acbf297..d99247fe58 100644 --- a/code/modules/ai/ai_holder.dm +++ b/code/modules/ai/ai_holder.dm @@ -318,9 +318,11 @@ if(STANCE_MOVE) if(hostile && find_target()) // This will switch its stance. ai_log("handle_stance_strategical() : STANCE_MOVE, found target and was inturrupted.", AI_LOG_TRACE) + return if(STANCE_FOLLOW) if(hostile && find_target()) // This will switch its stance. ai_log("handle_stance_strategical() : STANCE_FOLLOW, found target and was inturrupted.", AI_LOG_TRACE) + return else if(leader) ai_log("handle_stance_strategical() : STANCE_FOLLOW, going to calculate_path([leader]).", AI_LOG_TRACE) calculate_path(leader) @@ -359,5 +361,6 @@ if(ai_holder) ai_holder.receive_taunt(taunter, force_target_switch) +#undef AI_NO_PROCESS #undef AI_PROCESSING #undef AI_FASTPROCESSING \ No newline at end of file diff --git a/code/modules/ai/ai_holder_disabled.dm b/code/modules/ai/ai_holder_disabled.dm index d68e2ecf5d..796f094776 100644 --- a/code/modules/ai/ai_holder_disabled.dm +++ b/code/modules/ai/ai_holder_disabled.dm @@ -6,7 +6,7 @@ // If our holder is able to do anything. /datum/ai_holder/proc/can_act() if(!holder) // Holder missing. - manage_processing(AI_NO_PROCESS) + manage_processing(0) return FALSE if(holder.stat) // Dead or unconscious. ai_log("can_act() : Stat was non-zero ([holder.stat]).", AI_LOG_TRACE) diff --git a/code/modules/mob/living/simple_mob/simple_mob.dm b/code/modules/mob/living/simple_mob/simple_mob.dm index 6a750ea518..ba77999be8 100644 --- a/code/modules/mob/living/simple_mob/simple_mob.dm +++ b/code/modules/mob/living/simple_mob/simple_mob.dm @@ -156,6 +156,9 @@ // contained in a cage var/in_stasis = 0 + // don't process me if there's nobody around to see it + low_priority = TRUE + /mob/living/simple_mob/Initialize() verbs -= /mob/verb/observe health = maxHealth diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 4d3187bdd2..9d1374ea49 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -1200,6 +1200,16 @@ mob/proc/yank_out_object() else registered_z = null +GLOBAL_LIST_EMPTY(living_players_by_zlevel) +/mob/living/update_client_z(new_z) + var/precall_reg_z = registered_z + . = ..() // will update registered_z if necessary + if(precall_reg_z != registered_z) // parent did work, let's do work too + if(precall_reg_z) + GLOB.living_players_by_zlevel[precall_reg_z] -= src + if(registered_z) + GLOB.living_players_by_zlevel[registered_z] += src + /mob/onTransitZ(old_z, new_z) ..() update_client_z(new_z) From ebc0bf425b6429fd2cc9492acb9ac822a2ab4a1e Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 09:41:43 -0400 Subject: [PATCH 3/6] Nullify ai_log statements unless someone comments this out --- code/modules/ai/_defines.dm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/modules/ai/_defines.dm b/code/modules/ai/_defines.dm index 7b49f18ddb..8075c6d2ee 100644 --- a/code/modules/ai/_defines.dm +++ b/code/modules/ai/_defines.dm @@ -4,7 +4,8 @@ #define AI_NORMAL 2 // Default level. #define AI_SMART 3 // Will do more processing to be a little smarter, like not walking while confused if it could risk stepping randomly onto a bad tile. -#define ai_log(M,V) if(debug_ai) ai_log_output(M,V) +//#define ai_log(M,V) if(debug_ai) ai_log_output(M,V) +#define ai_log(M,V) // Logging level defines. #define AI_LOG_OFF 0 // Don't show anything. From 0f1d00d13bf6139b5d7024e1ef507781add91494 Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 09:44:07 -0400 Subject: [PATCH 4/6] Make the global announcer really global --- code/controllers/subsystems/ticker.dm | 4 ++++ code/game/objects/items/devices/radio/radio.dm | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/code/controllers/subsystems/ticker.dm b/code/controllers/subsystems/ticker.dm index f213c6bf30..4cfdfc4b9e 100644 --- a/code/controllers/subsystems/ticker.dm +++ b/code/controllers/subsystems/ticker.dm @@ -55,6 +55,10 @@ var/global/datum/controller/subsystem/ticker/ticker /datum/controller/subsystem/ticker/Initialize() pregame_timeleft = config.pregame_time send2mainirc("Server lobby is loaded and open at byond://[config.serverurl ? config.serverurl : (config.server ? config.server : "[world.address]:[world.port]")]") + + // Set up the global announcer + GLOB.autospeaker = new (null, null, null, 1) + return ..() /datum/controller/subsystem/ticker/fire(resumed = FALSE) diff --git a/code/game/objects/items/devices/radio/radio.dm b/code/game/objects/items/devices/radio/radio.dm index 4ef7cc576a..2049d96a7d 100644 --- a/code/game/objects/items/devices/radio/radio.dm +++ b/code/game/objects/items/devices/radio/radio.dm @@ -284,7 +284,10 @@ var/global/list/default_medbay_channels = list( if(.) SSnanoui.update_uis(src) +GLOBAL_DATUM(autospeaker, /mob/living/silicon/ai/announcer) /obj/item/device/radio/proc/autosay(var/message, var/from, var/channel, var/list/zlevels) //BS12 EDIT + if(!GLOB.autospeaker) + return var/datum/radio_frequency/connection = null if(channel && channels && channels.len > 0) if(channel == "department") @@ -299,9 +302,8 @@ var/global/list/default_medbay_channels = list( if(!LAZYLEN(zlevels)) zlevels = list(0) - var/static/mob/living/silicon/ai/announcer/A = new /mob/living/silicon/ai/announcer(src, null, null, 1) - A.SetName(from) - Broadcast_Message(connection, A, + GLOB.autospeaker.SetName(from) + Broadcast_Message(connection, GLOB.autospeaker, 0, "*garbled automated announcement*", src, message_to_multilingual(message), from, "Automated Announcement", from, "synthesized voice", DATA_FAKE, 0, zlevels, connection.frequency, "states") From 8eb77a04ec687de21292382b7e7cd45826c728ce Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 09:59:58 -0400 Subject: [PATCH 5/6] Redo mobs subsystem to be more like SSai with regards to skipping --- code/controllers/subsystems/mobs.dm | 36 ++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/code/controllers/subsystems/mobs.dm b/code/controllers/subsystems/mobs.dm index a42caad0d9..4f7d524a8f 100644 --- a/code/controllers/subsystems/mobs.dm +++ b/code/controllers/subsystems/mobs.dm @@ -15,24 +15,23 @@ SUBSYSTEM_DEF(mobs) var/list/currentrun = list() var/log_extensively = FALSE var/list/timelog = list() - var/list/busy_z_levels = list() + var/slept_mobs = 0 + var/list/process_z = list() /datum/controller/subsystem/mobs/stat_entry() ..("P: [global.mob_list.len] | S: [slept_mobs]") /datum/controller/subsystem/mobs/fire(resumed = 0) - var/list/busy_z_levels = src.busy_z_levels - if (!resumed) - slept_mobs = 0 src.currentrun = mob_list.Copy() - busy_z_levels.Cut() - for(var/played_mob in player_list) - if(!played_mob || isobserver(played_mob)) - continue - var/mob/pm = played_mob - busy_z_levels |= pm.z + process_z.Cut() + slept_mobs = 0 + var/level = 1 + while(process_z.len < GLOB.living_players_by_zlevel.len) + process_z.len++ + process_z[level] = GLOB.living_players_by_zlevel[level].len + level++ //cache for sanic speed (lists are references anyways) var/list/currentrun = src.currentrun @@ -41,18 +40,13 @@ SUBSYSTEM_DEF(mobs) var/mob/M = currentrun[currentrun.len] currentrun.len-- - if(QDELETED(M)) + if(!M || QDELETED(M)) mob_list -= M - else - // Right now mob.Life() is unstable enough I think we need to use a try catch. - // Obviously we should try and get rid of this for performance reasons when we can. - try - if(M.low_priority && !(M.z in busy_z_levels)) - slept_mobs++ - continue - M.Life(times_fired) - catch(var/exception/e) - log_runtime(e, M, "Caught by [name] subsystem") + else if(M.low_priority && !(process_z[get_z(M)])) + slept_mobs++ + continue + + M.Life(times_fired) if (MC_TICK_CHECK) return From 71a07cf06e4ac78efd0369ffbc6976015b9d6482 Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Sun, 17 May 2020 10:07:38 -0400 Subject: [PATCH 6/6] Make even more sure dummies don't end up processing --- .../mob/living/carbon/human/human_species.dm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/code/modules/mob/living/carbon/human/human_species.dm b/code/modules/mob/living/carbon/human/human_species.dm index 5d4cd86e1c..90949f401f 100644 --- a/code/modules/mob/living/carbon/human/human_species.dm +++ b/code/modules/mob/living/carbon/human/human_species.dm @@ -3,11 +3,22 @@ status_flags = GODMODE|CANPUSH has_huds = FALSE -/mob/living/carbon/human/dummy/mannequin/Initialize() +/mob/living/carbon/human/dummy/Initialize() . = ..() mob_list -= src living_mob_list -= src dead_mob_list -= src + human_mob_list -= src + +/mob/living/carbon/human/dummy/Life() + mob_list -= src + living_mob_list -= src + dead_mob_list -= src + human_mob_list -= src + return + +/mob/living/carbon/human/dummy/mannequin/Initialize() + . = ..() delete_inventory() /mob/living/carbon/human/skrell/Initialize(var/new_loc)