


Interesting.
you can print stat(1) to see CPU usage, witch is 450%, so lots of frame skipping !
There room for improvement.
1st, you are missing a color. The code derives from C world where arrays start at index 0.
LUA has 1 as default starting index, but can start wherever you want if you ask nicely.
palette = { [0]=0, -- 0: black 8, -- 1: red 9, -- 2: orange 10, -- 3: yellow 7 -- 4: white } |
You are computing the fire logic for the entire screen. Doing so for a smaller part of the screen would reduce CPU usage.
you are doing the computations in _update, and the screen drawing in _draw.
This is the correct way in general, especially in case of frame skip, but in this case, there's a one to one correspondence between your data and the pixels, so working directly with the pixels, either with pget/pset or with peek/poke would remove the drawing phase in _draw.
You could also get rid of the palette array indirection by setting the first five colors of the display palette to your fire gradient.
I'm confident you can reach below 100% CPU, so 30FPS, but probably also below 50% CPU, in with case you can use _update60 instead of _update and get 60FPS.
[Please log in to post a comment]