I've recently started learning AXE, and the first program I'm working on is a simple implementation of Conway's Game of Life that takes input from the graph screen, and I have a question about optimizing it.
Forgive me if the question demonstrates a profound lack of understanding of the language, but hey, that's why I'm asking it.
Currently it uses the main buffer to hold the current generation, back buffer for calculating the next generation, one labeled GDB1 for the cells that changed last generation, and GDB2, which is GDB1 with all neighbor cells turned on (Used so that the main algorithm checks only the cells and the neighbors of cells that changed last generation.)
I thought of a way I could possibly optimize the routine for copying GDB1 to GDB2 and filling in neighboring cells.
Code as it currently is:
:ClrDraw(GDB2)
:Copy(GDB1,GDB2)
:For(K,1,92
:For(L,1,61
:If pxl-Test(K,L,GDB1)
:Pxl-On(K-1,L-1,GDB2
:Pxl-On(K-1,L,GDB2
:Pxl-On(K-1,L+1,GDB2
:Pxl-On(K,L-1,GDB2
:Pxl-On(K,L+1,GDB2
:Pxl-On(K+1,L-1,GDB2
:Pxl-On(K+1,L,GDB2
:Pxl-On(K+1,L+1,GDB2
:End:End:End
If I could use the Horizontal+-/Vertical+- commands to get a buffer of GDB1 shifted one direction over then combine it into GDB2, then keep moving GDB1 around until all 8 neighbor cells are filled, I'm pretty sure it'd be a whole lot faster than using 8 Pxl-Ons for all 5460 coordinates. To do this, I'd need a way to only copy the on pixels between buffers rather than overwriting the buffer entirely, like how RecallPic works in TI-BASIC.
If I had a solid understanding of how the buffers are represented in memory, this might be fairly trivial, but I'm still figuring all that out. Until then, does anyone have an idea for how I would accomplish this in a way that will improve performance compared to the current routine?
Here's the full code for anyone who's interested:
:.GAMOLIF
:Full
:DiagnosticOff
:ClrDraw^^r
:ClrDraw(GDB1)
:ClrDraw(GDB2)
:Buff(768)->GDB1
:Buff(768)->GDB2
:
:For(A,1,92
:For(B,1,61
:If pxl-Test(A,B
:Pxl-On(A,B,GDB1
:Pxl-On(A,B)^^r
:End:End:End
:
:
:While getKey!=15
:DispGraph
:ClrDraw(GDB2)
:Copy(GDB1,GDB2
:For(K,1,92)
:For(L,1,61)
:If pxl-Test(K,L,GDB1)
:Pxl-On(K-1,L-1,GDB2
:Pxl-On(K-1,L,GDB2
:Pxl-On(K-1,L+1,GDB2
:Pxl-On(K,L-1,GDB2
:Pxl-On(K,L+1,GDB2
:Pxl-On(K+1,L-1,GDB2
:Pxl-On(K+1,L,GDB2
:Pxl-On(K+1,L+1,GDB2
:End:End:End
:
:ClrDraw(GDB1)
:For(K,1,92
:For(L,1,61
:If pxl-Test(K,L,GDB2
:pxl-Test(K-1,L-1)+pxl-Test(K-1,L)+pxl-Test(K-1,L+1)+pxl-Test(K,L-1)+pxl-Test(K,L+1)+pxl-Test(K+1,L-1)+pxl-Test(K+1,L)+pxl-Test(K+1,L+1)->M
:If M=3 or (M=2 and pxl-Test(K,L
:Pxl-On(K,L)^^r
:Else
:Pxl-Off(K,L)^^r
:End
:
:If pxl-Test(K,L)!=pxl-Test(K,L)^^r
:Pxl-On(K,L,GDB1
:End
:End
:
:End:End
:RecallPic
:End
:Return
[/code]
Forgive me if the question demonstrates a profound lack of understanding of the language, but hey, that's why I'm asking it.
Currently it uses the main buffer to hold the current generation, back buffer for calculating the next generation, one labeled GDB1 for the cells that changed last generation, and GDB2, which is GDB1 with all neighbor cells turned on (Used so that the main algorithm checks only the cells and the neighbors of cells that changed last generation.)
I thought of a way I could possibly optimize the routine for copying GDB1 to GDB2 and filling in neighboring cells.
Code as it currently is:
:ClrDraw(GDB2)
:Copy(GDB1,GDB2)
:For(K,1,92
:For(L,1,61
:If pxl-Test(K,L,GDB1)
:Pxl-On(K-1,L-1,GDB2
:Pxl-On(K-1,L,GDB2
:Pxl-On(K-1,L+1,GDB2
:Pxl-On(K,L-1,GDB2
:Pxl-On(K,L+1,GDB2
:Pxl-On(K+1,L-1,GDB2
:Pxl-On(K+1,L,GDB2
:Pxl-On(K+1,L+1,GDB2
:End:End:End
If I could use the Horizontal+-/Vertical+- commands to get a buffer of GDB1 shifted one direction over then combine it into GDB2, then keep moving GDB1 around until all 8 neighbor cells are filled, I'm pretty sure it'd be a whole lot faster than using 8 Pxl-Ons for all 5460 coordinates. To do this, I'd need a way to only copy the on pixels between buffers rather than overwriting the buffer entirely, like how RecallPic works in TI-BASIC.
If I had a solid understanding of how the buffers are represented in memory, this might be fairly trivial, but I'm still figuring all that out. Until then, does anyone have an idea for how I would accomplish this in a way that will improve performance compared to the current routine?
Here's the full code for anyone who's interested:
:.GAMOLIF
:Full
:DiagnosticOff
:ClrDraw^^r
:ClrDraw(GDB1)
:ClrDraw(GDB2)
:Buff(768)->GDB1
:Buff(768)->GDB2
:
:For(A,1,92
:For(B,1,61
:If pxl-Test(A,B
:Pxl-On(A,B,GDB1
:Pxl-On(A,B)^^r
:End:End:End
:
:
:While getKey!=15
:DispGraph
:ClrDraw(GDB2)
:Copy(GDB1,GDB2
:For(K,1,92)
:For(L,1,61)
:If pxl-Test(K,L,GDB1)
:Pxl-On(K-1,L-1,GDB2
:Pxl-On(K-1,L,GDB2
:Pxl-On(K-1,L+1,GDB2
:Pxl-On(K,L-1,GDB2
:Pxl-On(K,L+1,GDB2
:Pxl-On(K+1,L-1,GDB2
:Pxl-On(K+1,L,GDB2
:Pxl-On(K+1,L+1,GDB2
:End:End:End
:
:ClrDraw(GDB1)
:For(K,1,92
:For(L,1,61
:If pxl-Test(K,L,GDB2
:pxl-Test(K-1,L-1)+pxl-Test(K-1,L)+pxl-Test(K-1,L+1)+pxl-Test(K,L-1)+pxl-Test(K,L+1)+pxl-Test(K+1,L-1)+pxl-Test(K+1,L)+pxl-Test(K+1,L+1)->M
:If M=3 or (M=2 and pxl-Test(K,L
:Pxl-On(K,L)^^r
:Else
:Pxl-Off(K,L)^^r
:End
:
:If pxl-Test(K,L)!=pxl-Test(K,L)^^r
:Pxl-On(K,L,GDB1
:End
:End
:
:End:End
:RecallPic
:End
:Return
[/code]