Optimizing primary systems that won't change much can be done earlier if done in parallel by another person. Besides, optimization will bring more bugs that you will have to fix later anyway. Also if optimization requires adding some data to objects, it's better to add it before you have 100500 objects to retroactively add it later on, right?
Optimization done after the fact is done to clean up sloppy original coding(though you are right we are working on pre-release content so in effect we are correcting bugs and optimizing while the product is not yet fully released, so it is in parellel). However in the 6 years I've been doing this I've never had new bugs arise from optimization and the second half of each piece I work on is profiling and testing it for dramatic improvements(largely because we need to report how much cpu/gpu time was corrected and give detailed explanations for how it was corrected in much the same way we hand in bug reports with resulting corrections) so I would of ran headfirst into any bugs that resulted from it.
I brought up these points, because I have had multiple RPGmaker games where the problem was -definitely- too many events and more specifically, events which were left open that were executing for no reason.
You won't believe me, but ANY game is basically main loop that only pauses when it has free time after doing everything in loop (and, I assure you, RPGMaker does same pause to not do more FPS than it's told to). You cannot make any smooth movement in any other way. And as soon as you remove "turn-based" tag A.I. decisions need to be made in any random point in time and often need to do it every other frame to check if there's new hostile in sight.
What was the point of this statement? ALL software is a main loop, because the objective for everything in a computer is taking an input and giving an output. My statement wasn't to pause the main loop, my statement is NPCs do not need to be commanded to random walk for every second. It doesn't contribute to the challenge or immersion and I've played more games than this to know movement is perfectly fine when the NPCs aren't spamming right angle turns every other second. MOST professional games draw a point 2-3 tiles away and have them go to it precisely because it's immersion breaking to see enemies jumping left and right for no reason. Additionally the NPC sight checks are performed regardless if the AI is actively moving on the screen(I know you know this, but I guess we're at the level where we have to make obvious statements).
In particular when I opened all of the mobile AI this command is right at the top "return [:move_random] if tgt.nil?" and this is defined even for followers.
Typical approach to NPC random walk that is used in like 70% cases (pseudo code):
val=rand(100)
if(0<val<50)stay_in_place()
if(50<val<100)move_to_random_tile()
in 25% more cases you don't move to random tile, but instead pathfind to random tile within range or objects npc wants to interact with.
2-3 pathfind checks are nothing for pc. 20 A.I. doing 2-3 pathfind checks are nothing for pc. Average modern pc can handle 500 units all pathfinding, being rendered and finding target to shoot at at same time. Even provided it's Ruby and not C++, that it's RPGMaker and half of rendering is software it still should pull 30 A.I. doing half of that at 60 FPS.
And in fact, when you see that in battle map with 5 A.I.s moving and searching/attacking you you get 50+ FPS easily. But in tavern where 2 A.I.s are moving and like 10 standing around and some events lying around you get 20-25 FPS - you know something is wrong not about A.I., am I wrong?
Typical approach? We KNOW how he programmed it, the function is inside of Game_Character.rb
"def move_random
move_straight(2 + rand(4) * 2, false)
end"
It is also never the typical approach to use a 50% chance the NPC stands still for a random walk, in fact it's not even common that random walk is "true random". Most developers will put a sanity check to make sure immersion doesn't break for the user, otherwise a computer can and will pull 1 through 49, 50 times(statistics), resulting in an AI that just stands there lifeless. Absolute random for AI is hilarious and those are my favorite days of fixing bugs when I watch an AI fighting me spam "HEAL HEAL HEAL HEAL" while at full HP.
I cracked it open and yep RPGmaker does not even utilize any kind of pathfinding system at all(well I guess you could say it processes where they are on the screen at least, but that would be processed under graphics). In actual 3D games pathfinding is one of the most intense drains of resources on the system, but no such thing exists for RPGmaker.
I still don't regret getting rid of that spam of random walk, because I quite enjoy playing a stealth archer and the feeling of these enemies doing the
You must be registered to see the links
when I'm trying to line up a shot is quite surreal.
And, in fact, my profiling shown me... This is not the case. A.I. uses very small amount of CPU time except for few problems, two of which I've highlighted before. Things that eat performance are mostly sprites and graphics updating (you cannot do it every other frame because that update is literally "frame").
As for exact numbers, approximate relation between Graphics.update : $game_player.update : @spriteset.update time consumed is approximately 5 : 2.5 : 5 out of which check_stat was around 1-1.5 inside $game_player.update; removing it gained few fps at 20 FPS (from 14-20 it went to 18-25), you can do maths and see that whole loop of just updating graphics is at least 30-40ms which already brings us to 60 FPS or below.
I really should be less lazy and use profiler rather than assume it's the same as previous scenarios.
I disabled the option for enemies to have lights on them and you're right, my FPS was 60 only occasionally dropping to upper 50's while I was moving.