Wednesday, March 25, 2009

No update tonight

I've been uploading versions of Plague so often recently that it feels weird to not do one tonight, but there aren't really any substantial changes from a user perspective so it doesnt really seem worthwhile. 

Instead I've spent most of my time reading open source licences again and mucking about on the SourceForge page for Plague that has finally come through. It'll be good to get stuff like a forum, an open web bzr repository, bug tacking lists etc. I havent even scratched the surface of what SourceForge can do, so it'll probably be a few days before any stuff starts appearing there. 


sean said...

Ok, I changed around the way the ai is called for survivors and zombies so that only 1 in 10 of them are updated each frame. I didn't notice any extreme weirdness in behavior from this, but I also didn't notice any qualitative increase in FPS.

I found that to be kind of odd, and profile confirmed a drop in ai calls and time of almost exactly 10x. I'll post the changes for you once I get them cleaned up, but I think the problem, unfortunatly, lies somewhere outside the ai for now.

The good news is that you can probably load the ai up with goodies for smarter formation and the tickets that smiboo mentioned without hurting the FPS

Also, I didn't touch the ai code itself, so if any of y'all are inclined to have a go at it, feel free.

sean said...

Pretty simple changes so I'll just stick them in here.

The first part of this code goes at the end of main.Game_Tactical.__init__ and the 2 methods can go anywhere below.

engine.Engine should get a call to self.ai_update() in __mainloop() and an empty ai_update() method.

in take all the ai stuff out of update() for zombies and survivors, then add this line at the end of their add_ai() methods
self.ai_loc =

finally, give the Biped class a remove_sim() method with these 2 lines:[self.ai_loc].remove(

Benedict Carter said...

Hmmmm. I'm surprised since I noticed the drop in performance when I added squads and associated stuff. The only other new addition is walking animation, but I wouldnt have thought that was CPU expensive.

Just did a profile, and the major hog is still Line of Sight stuff (because I want using the "fast optimisation that leads to artifacts). Then physics. Etc. AI is way down the line, on average.

But I'm still pretty sure the AI is responsible for the spikes in performance, because of the way I've written the code (lots of checking through lists).

Benedict Carter said...

Your AI optimisation code has been added. I've done a few more speed optmisations generally around the place (based on profile results), but all the "hard things" like physics and LOS I've been over a few times already.

Benedict Carter said...

The other thing it could be is multiple reflections of bullets between parallel lines of blocks (that are right next to each other).

Theres "no room" in between them so the bullet does LOTS of reflecting. Might be time to decrease the accuracy on that to increase the speed.

Benedict Carter said...

I think I'll add a check so that if it reflects twice in a row, it gets killed.

sean said...
This comment has been removed by the author.
sean said...

Good stuff. I've noticed guns spiking when being fired before so hopefully that cuts it out.

I've got a little fix that speeds the timer's update by about 5x, unless you got to them already.

Benedict Carter said...

I have not. I'd love to see the timer speed update.

Benedict Carter said...

The killing of reflecty bullets has worked well, Plague was getting 10fps spike drops with a gun like a sniper rifle fired into a group of rocks, this no longer occurs.

Benedict Carter said...

Hey Sean, I was just testing Plague for my changes, and I really like the distributed update to AI. It's working a lot more how I initially envisioned it would (because AIs shouldn't update every frame, its wasteful and less realistic) and its done in a smart way thats easily scalable to get better performance. Nicely done!

Benedict Carter said...

I think I've had enough for tonight.

I just wanted to check if either of you guys (Sean, SanityImpaired) has started hacking into the AI code to speed it up or was planning on doing so in the near future?

If not, I'll do that in the weekend. :)

sean said...

Here's the timer stuff. Basically what I figured is that most timers will usually be at 0 and there's no sense in iterating over them, so world.timers only holds timers with value > 0. Whatever object is using the timer still has its own reference to it so no worries (I hope) that it'll get lost. Whenever a timer has its value set or initialized, it goes back into world.timers. There's a timer_buffer used so that all the adding/removing can be done after the iteration. Should cut the update_timers() loop from ~1500 objects to ~100.

I'm kind of worried that there will be some sinister bug where a timer gets lost somehow and a fire doesn't go out or guns never reload but I havn't noticed anything yet. There's also a chance that it'll be slower if there's a lot of timers being created/removed at the same time but again, didn't see that.

Change ui.timer class to this. In main.Game_Tactical, these guys get changed and added respectively.
Then add:
self.timer_buffer = {'new': [], 'old': []}
to __init__ and you should be set

小小彬 said...