Project Zomboid

Project Zomboid

Superb Survivor 2024 BETA (SP Only) (V41 ONLY)
Batmane  [developer] 28 Apr, 2024 @ 10:44pm
Dev Log #1 Performance
Currently working mainly on FPS improvements.
So far I can run 8 NPCS around 100 ish zombies. Playing 4x pop on Lousville mansions.
Get about 30 - 47 FPS with no blood, simple zombie clothes, 1920 x 1080 res, Better FPS mod (1080p).

I think I can get this to be better. It basically comes down to how much I should nerf each individual NPC. The slower, their reaction time, the better the FPS.

So far NPCs aren't allow to process zombies or other player-like characters more than 18 squares in any direction.
NPCs can only visually process new information 1 time per second (at 60 FPS)
NPCs change tasks 3 times per second when in critical danger (zombies within 4 tiles)
and 2 times per second in mild danger (zombies within 9 tiles)
NPCs seemingly swing their weapon/push up to 3 times per second.
They shoot once per second.
They always run directly away from the nearest zombie


Aside from nerfing processing time, I can also trim down the AI routine.
The AI checks a list of tasks that it needs to do. They check this every single second.
The check rate increases to 2 and then 3 times per second when they are in danger.

There are critical tasks and then there are base building tasks. I might need to break this up so that critical tasks are processed quickly whereas base building tasks are processed periodically.


Thirdly, I can rewrite some functions. Many functions use brute force to accomplish tasks.
For instance, a function to find the nearest rope will scan every single tile in the whole building at that floor. A better function would just be to tell the ai to run to the last known player location at the same level and then scan outward for a rope at roughly 3 squares in each direction.


April 29 2024
Made a major break through. Replaced the vision function (which looked at every moving object in a cell) and replaced it with a built in zomboid function that gets only the zombies that the NPC can actually see. This should reduce the number of zombies and characters processed from 400 per vision tick to like 20!

Also, I reduced to rate at which ai need to 'see/process the enemies around them' to 1 time per second. I also hard locked other 'routine' functions to be processed once per second or per 2 seconds to save even more performance.
Hopefully, eventually the only tasks that need to be processed more than once per second is shooting the gun or swinging a weapon.


April 30 2024 - Reworked task manager (HUGE PERFORMANCE BOOST)
Broke up essential and non essential tasks.
Previously, the task manager would literally try to execute every task at once and just use checks to prematurely prevent them from running.
Now we just check going down the list and if we find a task we need to do, we pick that task (if it is not already in progress) and then execute it.
We dont think about other priorities on the list until we get there.

Essential Tasks are checked and prioritized if the following order.
The AI will not perform tasks near the bottom of this list until the ones near the top are satisfied?
In short, the follow a thought process
1. Injured and have space? Then heal when you can
2. Need to Flee (too many zombies, need to kite, or injured)? Then flee
3. Need to Follow? Then Follow
4. Ran out of ammo for current gun? Switch to another gun (but this doesnt block tasks below from executing)
5. Have a weapon AND you arent holding one? Equip the weapon
6. Seen an enemy very close? Go over there and threaten them (if they are a player and not activtely attacking you) otherwise just attack them
7. See an enemy in the distance? Pursue them until you are in range for the above attack task to fire in the next 'ai thought process'

If and only if ALL of the above tasks do not need to be worked on does the ai even consider doing their other tasks (guarding, building, eating, etc.).
This DRASTICALLY improves ai performance when in combat. Im getting 10 - 15 fps improvements from prior to this change.
Last edited by Batmane; 30 Apr, 2024 @ 7:59pm
< >
Showing 1-2 of 2 comments
ProtecTron 29 Apr, 2024 @ 9:46am 
Hi there! Is it ok to post, comment here?

First of all, thanks for taking this task and work on it, as many said in the comments, keep it up, slowly, chilling, at your phase, ignore "multiplayer" or nonsense requests. Now, I have the programming skills to make a pretty basic calculator in VB, so I might not be the best helper but here it goes, some thoughts or ideas, according to your info:

* It looks kind of overkill for performance they process data/ decide actions more than once per second, if what we are looking for is to have more npcs and not smarter ones, or at least have different versions and see how it goes. Have you tested a super nerf to their cognition of once every two seconds, for example, how does that look; also lowering 18 squares to 15 or so?

* What are critical tasks? Checking surroundings for danger/ other entities right? Again, might look dumb NPCs but having that timer increased, ¿really affects their quality, or is it tolerable? lol.

Functions, i'll leave that to you and other good modder that wanna help. The one you mentioned is way better than the default brute force option. I wonder if weapon switching is actually checking for too many variables when it could be called by the group leader, if he switch to melee, they copy it, blunt function but it lowers processing or calling more functions.

Speaking of functions, you could post here heavy lines of code or ask for help? Might not be me but those who know better might see it and share "how to" make it better, hopefully.
Last edited by ProtecTron; 29 Apr, 2024 @ 9:52am
Batmane  [developer] 29 Apr, 2024 @ 5:43pm 
Thanks for the feedback. I recently capped some routine functions to 1/s or 1/2s. So far, the ai still seems to be performing well. Let me know if the AI is acting stupid and Ill see what I can do regarding its behavior. I think the AI needs better quality procedures rather than more rapid actions.

Critical Tasks would Swing your weapon, Deciding and Fleeing from an enemy, Running away to heal, Shooting your weapon, deciding to run to the player (following). Theres a few others
The way task manager are set up is that the ai thinks about what it needs to do every second and that executes that action once. Currently working on isolating building tasks from every day movements to save memory.

It may be difficult to post here as there are a few thousand lines in the task manager across many files but if a small example comes up Ill post it.
< >
Showing 1-2 of 2 comments
Per page: 1530 50