KermMartian wrote:
I really think you should be able to optimize Fireball further in pure TI-BASIC; it felt more sluggish than it should have to me. Can you please perhaps post in your original Fireball topic (if there is one) asking us for some optimization help, mainly in your innermost main loop?


Well, here is the code:


Code:
:Func
:StoreGDB 1
:FnOff
:PlotsOff
:AxesOff
:CoordOff
:ExprOff
:GridOff
:RectGC
:ClrDraw
:Full
:0→Xmin
:94→Xmax
:{-}62→Ymin
:0→Ymax
:SetUpEditor FB,FBHI
:3→dim(∟FB
:8→dim(∟FBHI
:UnArchivePic1
:Lbl ME
:Menu("FIREBALL","CONTINUE",CO,"NEW GAME",NG,"QUIT",QU
:Lbl QU
:ArchivePic1
:Archive∟FB
:Archive∟FBHI
:DelVar [A]
:RecallGDB 1
:DelVar GDB1
:FnOn
:ClrHome
:Disp "PROGRAMMED BY","AARON ROTH"
:Stop
:Lbl HS
:ClrHome
:For(A,1,8
:Output(A,1,A
:Output(A,2,":
:Output(A,4,∟FBHI(A
:End
:Pause
:ClrHome
:Goto ME
:Lbl CO
:If not(∟FB(1
:Goto NG
:If ∟FB(1)=1
:Goto L1
:If ∟FB(1)=2
:Goto L2
:If ∟FB(1)=3
:Goto L3
:If ∟FB(1)=4
:Goto L4
:If ∟FB(1)=5
:Goto L5
:If ∟FB(1)=6
:Goto L6
:If ∟FB(1)=7
:Goto L7
:If ∟FB(1)=8
:Goto L8
:If ∟FB(1)=9
:Goto L9
:If ∟FB(1)=10
:Goto L0
:
:Lbl NG
:Lbl L1
:1→∟FB(1
:18→∟FB(2
:[[11,11,11,11,11,11,11,11,11,11,11,11][0,1,0,1,0,1,0,1,0,1,0,1][11,11,11,11,11,11,11,11,11,11,11,11][2,3,2,3,2,3,2,3,2,3,2,3][11,11,11,11,11,11,11,11,11,11,11,11][6,7,6,7,6,7,6,7,6,7,6,7]]→[A]
:Goto GM
:Lbl L2
:2→∟FB(1
:28→∟FB(2
:[[12,13,12,13,11,11,11,11,14,15,14,15][12,13,12,13,12,13,14,15,14,15,14,15][11,11,12,13,12,13,14,15,14,15,11,11][11,11,14,15,14,15,12,13,12,13,11,11][14,15,14,15,14,15,12,13,12,13,12,13][14,15,14,15,11,11,11,11,12,13,12,13]]→[A]
:Goto GM
:Lbl L3
:3→∟FB(1
:16→∟FB(2
:[[11,11,11,11,2,3,2,3,11,11,11,11][11,11,2,3,11,11,11,11,2,3,11,11][2,3,11,11,6,7,6,7,11,11,2,3][2,3,11,11,6,7,6,7,11,11,2,3][11,11,2,3,11,11,11,11,2,3,11,11][11,11,11,11,2,3,2,3,11,11,11,11]]→[A]
:Goto GM
:Lbl L4
:4→∟FB(1
:18→∟FB(2
:[[4,5,11,11,16,17,11,11,4,5,11,11][11,11,16,17,11,11,4,5,11,11,16,17][16,17,11,11,4,5,11,11,16,17,11,11][11,11,4,5,11,11,16,17,11,11,4,5][4,5,11,11,16,17,11,11,4,5,11,11][11,11,16,17,11,11,4,5,11,11,16,17]]→[A]
:Goto GM
:Lbl L5
:5→∟FB(1
:16→∟FB(2
:[[0,1,0,1,11,11,11,11,14,15,14,15][0,1,11,11,11,11,11,11,11,11,14,15][11,11,11,11,14,15,0,1,11,11,11,11][11,11,11,11,0,1,14,15,11,11,11,11][14,15,11,11,11,11,11,11,11,11,0,1][14,15,14,15,11,11,11,11,0,1,0,1]]→[A]
:Goto GM
:Lbl L6
:6→∟FB(1
:18→∟FB(2
:[[20,21,11,11,6,7,20,21,11,11,6,7][11,11,20,21,11,11,11,11,6,7,11,11][20,21,11,11,6,7,20,21,11,11,6,7][11,11,20,21,11,11,11,11,6,7,11,11][20,21,11,11,6,7,20,21,11,11,6,7][11,11,20,21,11,11,11,11,6,7,11,11]]→[A]
:Goto GM
:Lbl L7
:7→∟FB(1
:23→∟FB(2
:[[12,13,6,7,12,13,6,7,12,13,6,7][6,7,11,11,11,11,11,11,11,11,12,13][12,13,11,11,12,13,6,7,11,11,6,7][6,7,11,11,6,7,11,11,11,11,12,13][12,13,11,11,12,13,11,11,11,11,6,7][6,7,11,11,6,7,12,13,6,7,12,13]]→[A]
:Goto GM
:Lbl L8
:8→∟FB(1
:24→∟FB(2
:[[11,11,11,11,11,11,2,3,16,17,2,3][11,11,11,11,2,3,16,17,2,3,16,17][11,11,2,3,16,17,2,3,16,17,2,3][2,3,16,17,2,3,16,17,2,3,11,11][16,17,2,3,16,17,2,3,11,11,11,11][2,3,16,17,2,3,11,11,11,11,11,11]]→[A]
:Goto GM
:Lbl L9
:9→∟FB(1
:14→∟FB(2
:[[11,11,20,21,11,11,11,11,20,21,11,11][11,11,20,21,11,11,11,11,20,21,11,11][11,11,11,11,11,11,11,11,11,11,11,11][12,13,11,11,11,11,11,11,11,11,12,13][12,13,12,13,11,11,11,11,12,13,12,13][11,11,12,13,12,13,12,13,12,13,11,11]]→[A]
:Goto GM
:Lbl L0
:10→∟FB(1
:28→∟FB(2
:[[2,3,2,3,2,3,2,3,2,3,2,3][4,5,11,11,11,11,11,11,11,11,4,5][4,5,4,5,2,3,2,3,4,5,4,5][4,5,4,5,2,3,2,3,4,5,4,5][4,5,11,11,11,11,11,11,11,11,4,5][2,3,2,3,2,3,2,3,2,3,2,3]]→[A]
:Lbl GM
:40→A:1→θ:1→T:1→U
:real(2,0,0,0,12,6,0,12,0,6,1,0,8,1
:real(1,A,56,2,8,1,2,16,0,0,1
:Pt-On(A+9,{-}57,3
:Lbl BL
:getKey→K
:If K=45
:Goto ME
:If K=24 or K=26
:Then
:real(1,A,56,2,8,1,4,16,0,0,1
:If θ
:Pt-Off(A+9,{-}57,3
:A+4(K=26 and A≠80)-4(K=24 and A≠0→A
:real(1,A,56,2,8,1,2,16,0,0,1
:If θ
:Pt-On(A+9,{-}57,3
:End
:
:If K=21 or K=105
:Then
:0→θ
:A+9→V:{-}57→W
:Pt-Off(V,W,3
:End
:
:If not(θ
:Then
:Pt-Off(V,W,3
:V+2T-2not(T→V
:W+2U-2not(U→W
:Pt-On(V,W,3
:
:If V=93 or V=1 or W={-}1 or (pxl-Test({-}W+3,V) and W<{-}48)
:Then
:If pxl-Test({-}W+3,V) and W<{-}48
:Then
:1→U
:∟FB(3)+5→∟FB(3
:End
:If V=93
:0→T
:If V=1
:1→T
:If W={-}1
:0→U
:End
:DelVar R
:If V≠93
:pxl-Test({-}W,V+3
:R+Ans→R
:If V≠1
:pxl-Test({-}W,V-2
:R+Ans→R
:If W≠{-}1
:pxl-Test({-}W-2,V
:R+Ans→R
:If (pxl-Test({-}W+3,V) and W≥{-}48) or R or pxl-Test({-}W+1,V-1) or pxl-Test({-}W-1,V+1) or pxl-Test({-}W+1,V+1) or pxl-Test({-}W-1,V-1
:Then
:If pxl-Test({-}W+3,V
:Then
:{-}W+3→L
:8(2int(V/16→K
:1→U:End
:If W≠{-}1:Then
:If pxl-Test({-}W-2,V)
:Then
:{-}W-9→L
:8(2int(V/16→K
:0→U:End:End
:If V≠93:Then
:If pxl-Test({-}W,V+3)
:Then
:V+3→K
:8int({-}W/8→L
:0→T:End:End
:If V≠1:Then
:If pxl-Test({-}W,V-2)
:Then
:V-17→K
:8int({-}W/8→L
:1→T:End:End
:If pxl-Test({-}W-1,V-1
:Then
:V-15→K:{-}W-7→L
:1→T:0→U:End
:If pxl-Test({-}W-1,V+1
:Then
:V-1→K:{-}W-7→K
:0→T:0→U:End
:If pxl-Test({-}W+1,V-1
:Then
:V-15→K:{-}W+1→L
:1→T:1→U:End
:If pxl-Test({-}W+1,V+1
:Then
:V+1→K:{-}W+1→L
:0→T:1→U
:End
:real(1,K,L,2,8,1,4,16,0,0,1
:∟FB(2)-1→∟FB(2
:∟FB(3)+10→∟FB(3
:End
:End
:If not(∟FB(2
:Then
:If ∟FB(1)≠10
:Then
:∟FB(1)+1→∟FB(1
:real(1,A,56,2,8,1,2,16,0,0,1
:Else
:Goto 10
:End:End
:If W<{-}58 and not(θ
:Goto LL
:If not(∟FB(2
:Goto CO
:Goto BL
:Lbl LL
:Goto CO
:Lbl 10
:ClrDraw
:ClrHome
:Pause "YOU WIN!
:ClrHome
:Goto ME


I would love to kow if any of you have any suggestions for code on how to speed it up. Thanks.
To start out in optimizing, we need to be rid of the Lbl/Goto loop you've got this set up in. Everytime it comes across a Goto command, it restarts the program, which effectively sets the search pointer at the top of the program, and begins looking for the proper Lbl command. This will cause a massive slow down. Need to wrap Lbl BL/Goto BL into a While or Repeat loop, pending what you feel comfortable using.

Though, I'm having a hard time not saying to remove all Lbl and Goto commands, but that's just me. Kerm knows of my distaste with those 2 functions. :p

But putting the engine loop into the proper point is where it needs to start for sure.

Sadly, looking deeper into that engine, you have several Goto commands in that. So yeah, the engine will need a bit of an overhaul to remove those so you don't cause memory leaks.
Whats the best way to avoid a memory leak without using goto commands? I block memory leaks by assigning a var within a loop then checking after and using a goto...
Well, I use


Code:
While iPart(W)=# <- 'Master loop'
If fPart(W)= <- conditionals based on the decimal value of W, lets you skip on to a different value of W

<various While W= loops, or If W= conditionals>


Of course, hardest part of this is keeping tabs on where End statements are. To leave loops, just change the value of W.
I use something like this:


Code:
:// start of game
:Lbl AA
:// Main menu
:DelVar WWhile not(W
:// Outer loop: rendering and stuff
:While not(W
:// Inner loop: keys and stuff
:Repeat K:getKey->K:End
:If K=45:1->W // 1== quit prematurely
:If [lose condition]:2->W // 2 == lose
:If [win condition]:3->W // 3 == win
:End // end inner loop
: Rerender or whatever
:End // end outer loop
:If W=1:Goto AA
:If W=2://display lose message
:If W=3://display win message and deal with high scores
:Goto AA
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement