I need help optimising my cellular automata

project link

I'm trying to build an engine for cellular automata (for things like Sam Hogan's Cell Machine, falling sand simulators, Conway's GoL, World Gen, etc.), but I keep running into issues with lag. The draw (the grid)::#ffd127 block (sorry for the hideous colour) is at a level I'm happy with in terms of performance, but update (the grid)::#ffd127 is taking way too long to run. According to my FPS block, I'm getting 0.38ish FPS with the update block, and about 50 without. I'm using a lot of nested loops in the logic of update, so it definitely can be optimised, but I have absolutely no idea how to go about with it.

(also, spawn [1 V] at x: (1) y: (1)::#ffd127 can be used to set cells to specific materials, if it helps see what I'm doing. (The new scriptable menu system is so useful!))

(Also, should this be Requests to the Community?)

There are Undefined blocks in your project. (CATCH is one of them, for example.)

Crud. On my computer, it's fine. Hang on...

I've learned my lesson: never use the unused blocks dialog.

Yep - I've been caught out by using it in the past - it seems to be a little bit too aggressive in what it prunes :frowning:

Fixed. Try it now.

Use the "set" block not "let".

Do not repeat the same calculations for every iteration. Calculate the the "pen size" once and the step for the "change X" only once for a row, not for each cell.

I wonder if it would result in a net speedup if you turned the neighborhood into a list of nine squares, instead of a list of three rows of three squares each.

And I wonder if you could gain speed by turning the MAP blocks into compiled
untitled script pic (6)
blocks (right click on the MAP block and choose "compile").

I haven't actually tried timing either of these.

Thanks. Your suggestions have sped up my project considerably.

For some reason, compiling my maps has decreased my framerate. Not sure why...

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.