0 Favourites

Why am i loosing so much performance?

  • I just wrote a "Conway's game of life" implementation in Construct 2 it's REALLY slow. I used the same logic to make it with ruby:


    but in Construct 2 when i try to evaluate the "next generation" it takes about 20 seconds to calculate it. I don't know if i messed up the code or Contruct 2 is just slow for this, when i set the field to somthing like 10x10 it runs nicelly, if its above 40x40 then it take ages to calculate. The button press here is what triggers the "calculate next generation" action (normally that should go in an "Every X Seconds", but i'm using the button for debug purposes), and here is the code:


    Here is the first part of the code but it's probably irrelevant http://imgur.com/GBqoFDU

    Thanks for taking your time to read this <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> I really like using Construct and i hope this is not a problem related to the engine, I'm almost certain i did some anti-pattern but i just can't find it.

    * I can't link the .capx because i don't have 300 rep, if anyone needs more info on the source i can take more screenshots <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

  • You can get a good speedup by utilizing an array to make the cell lookup faster.

    See here for an example:

    The slowdown you're encountering has to do with picking. Event 23 in your capx is the bottleneck.

    If you're using 40x40 then you have 1600 cells, and event 23 does this:

    cell: coordX = checkX //this filters the 1600 cells down to 40

    cell: coordY = checkY //this filters the 40 cells down to 1

    1600 times.

    The idea in my capx is to just do everything in the array, so I can lookup if a cell is on or off with a direct check. Then to update it visually I just loop over the sprites and set their visibility depending on the value in the array.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks a lot, so let me see if i get this straight, whenever im looping a large number of items i should refrain from using filtering events? OK, seems pretty legit to me , so I should use an array to calculate everything and then just display the sprite as dead or alive (which will come from the array element as 1 or 0) and them i use the Z coordinate to have more than 1 property per element (lets say z0 is "is_alive" and z1 is "is_alive_again", then i would acces it as X,Y,0 or X,Y,1). Thanks a lot for the help.

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