How do I prevent my tactical game from slowing down and freezing ?

0 favourites
  • 4 posts
From the Asset Store
15 High Quality SoundTracks, and 10 Fanfares for your game! :D
  • Hi,

    I think I have a small optimization issue. I work on a very simple prototype: it is a town where zombies are hunting down civilians. I have a quite simple pathfinding and pursuit system but it does not work as well as it should.

    I have 2 problems :

    1- From 200 zombies on the map, the FPS is falling dramatically, first to 30-40 FPS, and the below 30 FPS. Can anybody tell me what is the reason ? (obviously it comes from the ZombieIA sheet)

    2- The game will always freeze before 2 minutes et I can't see why (debug seem to be ok, although I am not an expert).

    Can anybody give me some hints about what is wrong in my script ?

    The capx is here : dropbox.com/s/v8jtuj0aozdztt2/ProjectZombie_Debug.capx

    (if plugin is required, I use Rex's plugins : c2rexplugins.weebly.com/)

    And you just have to launch TacticalMap and click on the Start Game button on the left.

    Thank you ! I don't know much about optimization, but eager to learn ;)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Your code needs to be optimized for such a big number of objects. And it's not only the ZombieAI, CivilianAI event sheet is just as bad...

    You should avoid using "For each" loops on every tick for a big number of instances. First, pick suitable instances, then loop through them with For each. And don't run it on every tick.

    So, replace this:

    For each Zombie
    Zombie timer "follow" is not running
    Zombit is not eating
     -> do a whole bunch of stuff
    

    With this:

    Every random(1,2) seconds
    Zombie is not eating
    Zombie timer "follow" is not running
    For each Zombie
     -> do a whole bunch of stuff
    

    Avoid using pathfinder too often for too many objects, avoid regenerating obstacle map too often. Consider making pathfinding cells bigger.

    Also, your "While" loops have no emergency exit, so they can get into an infinite loop, or simply run for too long. Add another condition "Loopindex<10" to them to avoid this.

    Try disabling big blocks of code to find what's affecting performance the most. Try to decrease the number of collision checks per tick (it's currently too high).

    Add debug output into your events to see if they work as expected. For example, if you add Browser log "failed" into Civilian On Failed to find path event, you'll see that after a few seconds this event starts running hundreds of times on every second! Which means there is some problem with civilians pathfinding.

    You may need to compromise many things to improve performance..

  • Thank you !

    I will try these modifications asap :)

  • It works much better now and it is not freezing anymore, thank you very much :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)