Sleep AI processing when nobody on their Zlevel

This commit is contained in:
Aronai Sieyes
2020-05-17 10:00:14 -04:00
parent 190e8bdd5a
commit 0bad4363b8
6 changed files with 39 additions and 5 deletions

View File

@@ -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

View File

@@ -648,10 +648,15 @@ 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()
maxz++

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)