Why am i loosing so much performance?

Show us your works in progress and request feedback

Post » Tue Aug 25, 2015 8:35 pm

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:
https://github.com/MarcoWorms/ruby-game-of-life
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:
http://i.imgur.com/YOXKM0r.png

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 :) 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 :mrgreen:
B
7
S
2
Posts: 5
Reputation: 551

Post » Tue Aug 25, 2015 9:28 pm

You can get a good speedup by utilizing an array to make the cell lookup faster.
See here for an example:
viewtopic.php?f=147&t=121108&p=865594&hilit=cgol#p865594

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.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Aug 25, 2015 9:44 pm

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.
B
7
S
2
Posts: 5
Reputation: 551


Return to Works in Progress/Feedback Requests

Who is online

Users browsing this forum: No registered users and 3 guests