output()
message to two outputs at once on different windows instead of using 2 lines of code for separate messages that are the same?I profiled my AI system for a duration of 1 hour with around 20 players casually fighting mobs.
It reached the highest CPU usage, even more than my RSC procs that I heavily reduced with object recycling.
Profile results (total time)(duration: 1 hour)
Proc Name Self CPU Total CPU Real Time Calls
-------------------------------------------- --------- --------- --------- ---------
/mob/Antagonist/proc/intelligence_system 15.358 17.317 10704.060 334
/mob/Antagonist/proc/fight_back 1.816 1.954 1.957 5786
/mob/Antagonist/proc/antagonist_death 0.009 0.250 0.252 4279
/mob/Antagonist/proc/reset_antagonist 0.000 0.000 0.000 299
/icon/proc/RscFile 3.283 3.283 3.283 521
Here's the code(Ignore my annotations/comments, they're for someone learning.):
proc
intelligence_system()
set background = /* cpu intensive proc(?) */ 1
if( already_reacting /* check if the bully is reacting. */ ) return
if( isbully ( src ) /* check if the source is a bully. */ ) already_reacting = 1
while( 1 /* forever true. */ )
if( dead /* check for death. */ || !target /* check for the target. */ || ! ( target in view ( 7 , src ) /* check for the target. */ ) ) break
if( stamina >= stamina_percentage /* check their stamina. */ )
if( get_dist ( src , target ) > 1 /* check the distance. */ )
step_to( src , target )
else if( world.time > on_delay /* check punch delay. */ )
on_delay = world.time + 13 ; fight_back()
else step_away( src , target )
sleep( 4 /* wait 4 ticks to move again. */ )
if( !dead /* check for death. */ ) reset_antagonist()
I'm not sure if you can do this with a single call to output(), but you can create your own proc that takes a single message and calls output() twice.
If I'm reading it correctly, I don't see a problem. 17 seconds of CPU time spread over 1 hour is less than 1% CPU usage.
The only things that look costly in the intelligence_system proc are the call to step_to() and "target in view ( 7 , src )". If you can change those to step_towards() and "get_dist(src, target) <= 7" that'll help.
You might also want to take a look at this: http://www.byond.com/developer/Forum_account/EnemyAI