OK, I honestly dont know where its coming from. If you move around long enough, it just gets slower and slower. Takes about 15 seconds before you start to see it getting pretty slow. To the point that it takes about a half second between hitting an arrow key, to actually moving the sprite. To start with, its far less than 1/8th of a second.

Yes, this uses xLIB for drawing the sprites. Thats where the real(... entries come from.

ZMOVE (Main app, for now)

Code:

8→V
Ans→W
Ans→X
Ans→Y
real(1,X,Y,1,8,0,1,0,0,0,1


Lbl ZZ
Repeat Ans
getKey
End
Ans→K

If K=33:Then
prgmZSTATS
Goto ZZ
End

If K=25:Then
(Y-8)/8→U
X/8→T
prgmZOBJECTS
If S=1:Then
X→V
Y→W
Y-8→Y
Goto DR
Else
Goto ZZ
End
End


If K=34:Then
(Y+8)/8→U
X/8→T
prgmZOBJECTS
If S=1:Then
X→V
Y→W
Y+8→Y
Goto DR
Else
Goto ZZ
End
End


If K=24:Then
Y/8→U
(X-8)/8→T
prgmZOBJECTS
If S=1
Then
Y→W
X→V
X-8→X
Goto DR
Else
Goto ZZ
End
End


If K=26:Then
Y/8→U
(X+8)/8→T
prgmZOBJECTS
If S=1
Then
Y→W
X→V
X+8→X
Goto DR
Else
Goto ZZ
End
End

If K=22
ClrDraw
ClrHome
Disp "Thanks for","Playing"
Return

Lbl DR
If X>80
Then
80→X
Ans→V
Goto ZZ
Else:If X<8
Then
8→X
Ans→V
Goto ZZ
Else:If Y>48
Then
48→Y
Ans→W
Goto ZZ
Else:If Y<8
Then
8→Y
Ans→W
Goto ZZ
End

real(1,V,W,1,8,0,1,0,3,0,0

real(1,X,Y,1,8,0,1,0,0,0,1

Goto ZZ


ZOBJECTS (Collision detection subroutine)

Code:

If [A](U+1,T+1)=0
Then
1→S
Else
0→S
End
Return


Now, I have NO doubt this could be HIGHLY optimized, but for now, Im trying to find the memory leak(s) and speed up what I have so far.

This is part of Null RPG (my upcoming game). So any help would be GREATLY appreciated! Very Happy

Here is a link to my post for it:
Null RPG
First off, a goto out of an if statement will cause leaking. TIOS doesn't know about block statements, so if you just put a goto inside of a block statement (while, for, if, etc.), then you will leak memory as TIOS thinks you are still inside of that block.

Other than that, I am not an expert on TI-BASIC.
Hmmmmm, then Im not sure how I would go about restructuring this to prevent that. I dont see another way, not with it being that complex. Maybe Kerm as some ideas? He seems to be the resident genius around here. lol
It's definitely the Goto instructions inside the If:Then:End blocks. However, you can use a Goto straight after an If statement that doesn't have a Then (as you're not creating a block).

As long as K isn't affected by any of the sub-programs, then K holds the key pressed until execution returns to Lbl ZZ. From quickly scanning over the code, I've noticed that the there are only two different labels that are being jumped to (being either ZZ or DR).

My suggestion is that you do the following:

1. Have what we will call a "DR flag" variable, say A (assuming A is free to be used). Under Lbl ZZ, set A to be 0 (so that every loop the "DR flag" starts as reset/false).

2. Remove all the "Goto ZZ" instructions from inside and If:Then:End blocks.

3. Replace any "Goto DR" instructions with "1->A" (set the "DR flag").

4. After all your "If K=..." statements, say "If A=0:Goto ZZ". In the case that A was set to 1, that means that the program should not be jumping back to Lbl ZZ, but in fact should (and will) continue to Lbl DR.

I noticed also that your last K statement didn't have a Then where it should have, otherwise if code execution gets to their, it will run the ClrHome:Disp:Return instructions regardless.

I hope this is all correct, I haven't programmed in TI-BASIC in years, but hopefully this is of assistance Smile
Thanks. I will look into that this evening. I get what your saying, just need to see it in action. Im coming from Android programming, so this is a little different, although you would THINK it would be easier. lol
JamesV wrote:
It's definitely the Goto instructions inside the If:Then:End blocks. However, you can use a Goto straight after an If statement that doesn't have a Then (as you're not creating a block)


To add-on, an IF:THEN:instruction:END is basically a "If this, then all of this." While an IF:Instruction is basically "if this, then this one thing." The THEN is what tells the processor there is more than one line to this set of instructions to be executed.

It's possible to embed in while loops. Such as While X≠1. Then, when your solution happens you set x to 2 (or whatever) and outside the loop you can have IF X=2:Goto Here:If X=5:Goto That. Etc.
  
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