User Tag List

Results 1 to 8 of 8

Thread: Game Of Life - Fast Loop = not that fast :)

  1. #1
    Clicker Fusion 2.5 (Steam)
    bad_rick's Avatar
    Join Date
    Jul 2014
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Game Of Life - Fast Loop = not that fast :)

    Hi,

    I created a "game of life" example.

    So, if you don't know what that is, here is a link:
    https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

    But, to keep things short: just create a shape by clicking on the screen and after that press the START button to get it on
    (only shapes with exactly 3 neighbors stay alive in the next generation. So, a single cell just dies by clicking START )

    The problem in my example is, that when I create a too big "data-grid" (in this example 80x60 cells) it slows down to 1 FPS.

    Could it be that my code just sucks?! Why is the "state update" of the active object's sooooo slooooooow.
    Too much objects? Fast loops maybe not that fast?! :P

    Maybe I should try to realize this example with the surface object?!

    Any ideas or suggestions?

    ps.
    if you decrease the global values "xCells" and "yCells" the program runs much faster.
    But I guess it should also be possible to handle about 4500 objects without any problems.
    (I mean, in other programming languages this is really not a big deal :P )

    Thx
    Attached files Attached files

  2. #2
    Clickteam Clickteam
    Jeff's Avatar
    Join Date
    Jun 2006
    Location
    Battle Ground Washington
    Posts
    11,825
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)
    I can't seem to run your MFA in the lastest build of Fusion -- So that's odd.
    I don't have my computer with the stock steam version at this time

    Looking over the code I am wondering about the always events you have -- Do those need to be always or checked once when the other conditions are true?
    That might optimize a little not sure if it would help that much.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Very cool.
    Can't see anything wrong you're doing conceptually.
    I'm experiencing a somewhat similar problem with a kinda tiled "minimap", that's now become very mini
    (being on android, can't use the Surface).

    Maybe you could avoid the array entirely, and use a foreach + test neighbors by their X/Y values related to fastloop index?
    Not sure though, didn't analyze your cell generation very closely.
    Parsing the array shouldn't be the issue anyway, as is a very quick operation,
    you can do well above the iterations you currently do without any issue... so where's the issue?

    Maybe somewhere between the syncing with cells,
    I wonder if this is an issue with "conditions" slowing down things,
    something going bad when objects start getting above a certain number
    (particularly "same objects" going above a certain number .. maybe scoping get difficult?)

    Never tried something similar with the Surface,
    might be worth a try with callbacks...
    should be faster but how much.....?


    (EDIT: on my computer runs but hangs for some seconds, unless you trim down grid size in global values)

  4. #4
    Clicker Fusion 2.5 (Steam)
    bad_rick's Avatar
    Join Date
    Jul 2014
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx for the first quick replies

    Looking over the code I am wondering about the always events you have -- Do those need to be always or checked once when the other conditions are true?
    That might optimize a little not sure if it would help that much.
    yeah, you are right - this one doesn't make sense. But it doesn't speed my code up if i fix these lines...

    Maybe you could avoid the array entirely, and use a foreach + test neighbors by their X/Y values related to fastloop index?
    using for-each instead could be a possibility, but I'm afraid it wouldn't help a lot...
    But I will try it...

    I keep on searching - maybe there are some other ways to speed my code up

  5. #5
    Clickteam Clickteam
    Jeff's Avatar
    Join Date
    Jun 2006
    Location
    Battle Ground Washington
    Posts
    11,825
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)
    Did you try limiting those lines to also one action when events loop?
    I don't know if it will have a big effect but I don't like to have events firing over and over if their job is done.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by bad_rick View Post

    using for-each instead could be a possibility, but I'm afraid it wouldn't help a lot...
    But I will try it...
    I agree, I think it would hardly help that much,

    maybe the best thing would be relying completely on the array for calculations,
    avoiding scoping cells while looping entirely (you only need to update array basing on "active cells" while user clicks, after all)
    and just as last thing, refreshing cells with the new value stored in the array

    If all is still crappy slow, then you could easily test with a Surface object as a last try,
    since would only mean parsing the ready-to-go array and displaying its values

  7. #7
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleXNA Export Module
    ProdigyX's Avatar
    Join Date
    Jan 2011
    Posts
    1,197
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey bad_rick

    I also made an example Conway's Game of Life, which is very similar to yours. In my example, I also create an object for every cell in the grid. I am pretty sure the performance degrade comes from the referencing the cell object in the "Check Neighbor Calls" group. If you can find a way to use the same thing without needing to find the correct cell, you should be good to go. In my example, I just added another dimension (let's call it the neighbor dimension) to my array, which stores the number of neighbors for a given cell. This way, I am reference only one object (the array object) in most of my events; the cells are just a graphical representation of the array.

    You could do this with minimal effort by simply adding 1 to the neighbor dimension of the array, instead of adding 1 to _neighbors for the respective cell object. Since you have the x and y fastloop indices, you already know which cell the loop iteration applies to. Then you would just need to recreate the world by using the values from the neighbor dimension of the array instead of each _neighbor Alterable Value from each individual cell, if that makes sense.

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleMac Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    AyreGuitar's Avatar
    Join Date
    Jan 2011
    Location
    Wales, UK
    Posts
    1,113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bad_rick - Just noticed your post whilst searching for something similar. Probably a bit late, but I've managed to speed it up considerably!

    The reason it's so slow is all the conditions that reference the cell object have to loop through all (4800) cell objects to find which ones fulfill those conditions, so it could be more like 4800^2 loops, even though you probably don't expect it to!

    The trick is to use another array to store the neighbours without having to access the cell objects (similar to ProdigyX's example in this post), and a For Each (or On Each) loop to transfer the cell array data to the cell objects. I almost didn't bother, since I thought adding another loop would just make it slower, but glad I did!

    I've attached an updated file. It starts with a randomly generated grid, but is easy to put back. I also did the nearest neighbour counting in a single event, but doubt it's saving that much time.

    One interesting thing I noticed is that with the randomly generated grid, my frame rate is around 10-15fps, but if grid starts all 0 or all 1, then I get 60fps. This is before clicking the start button! With the loops running I get around 25fps. So it's actually running faster with the loops!!!
    Attached files Attached files

Similar Threads

  1. Replies: 2
    Last Post: 27th May 2015, 02:00 PM
  2. life draining really fast
    By gamebuilder in forum The Games Factory 2 - Technical Support
    Replies: 3
    Last Post: 19th June 2012, 08:35 PM
  3. Instead of Fast Loop
    By ASD in forum Multimedia Fusion 2 - Technical Support
    Replies: 17
    Last Post: 5th November 2010, 04:08 AM
  4. Fast loop within fast loop - platform game
    By Safe in forum The Games Factory 2 - Technical Support
    Replies: 1
    Last Post: 16th April 2010, 07:38 AM
  5. fast loop
    By jhonson in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 17th November 2008, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •