Author Topic: Code optimization  (Read 13881 times)

0 Members and 1 Guest are viewing this topic.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Code optimization
« on: June 17, 2010, 07:53:00 pm »
please help make this code better so i can publish it

Code: [Select]
.EESKETCH
Full
diognosticoff
DispGraph
ClrDraw
0->S->O->P+1->L+9->X->Y+90->A
Text(82,0,A|>Dec
Text(1,0,L|>Dec
Untill G=15
getKey->G
asm(DB00E6036F2600)->I
If I=0:For(J,0,L):Pxl-Off(rand^96,rand^65):End:DispGraph:End
If X<95 and getKey(3):X+1->X:sub(A):End
If Y>7 and getKey(4):Y-1->Y:sub(A):End
If X>0 and getKey(2):X-1->X:sub(A):End
If Y<62 and getKey(1):Y+1->Y:sub(A):End
If G>4
While getKey(29) and (G=29):Text(1,0,L|>Dec):If L>1:L-1->L:Pause 125:End:End
While getKey(21) and (G=21):If L<255:L+1->L:Text(1,0,L|>Dec):Pause 125:End:End
While getKey(10) and (G=10):A+1->A:Text(82,0,A|>Dec):Pause 110:End
While getKey(11) and (G=11):Text(82,0,A|>Dec):If A>1:A-1->A:Pause 110:End:End
If G=13 and getKey(13):StorePic :X->O:Y->P:End
If G=12 and getKey(12):RecallPic :O->X:P->Y:DispGraph:End
If G=56 and getKey(56):ClrDraw:DispGraph:End
If G=14 and getKey(14):DrawInv :DispGraph:End
End
End
Lbl A
Pxl-On(X,Y):DispGraph:Pause A
Return
Normal
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

SirCmpwn

  • Guest
Re: Code optimization
« Reply #1 on: June 17, 2010, 07:59:48 pm »
Code: [Select]
.EESKETCH
Full
diognosticoff
DispGraph
ClrDraw
0→S→O→P+1→L+9→X→Y+90→A
Text(82,0,A|>Dec
Text(1,0,L|>Dec
Untill G=15
getKey→G
asm(DB00E6036F2600→I
!If I
For(J,0,L
Pxl-Off(rand^96,rand^65
End:DispGraph:End
If X<95 and getKey(3
X+1→X:sub(A
End
If Y>7 and getKey(4
Y-1→Y:sub(A
End
If X>0 and getKey(2
X-1→X:sub(A
End
If Y<62 and getKey(1
Y+1→Y:sub(A
End
If G>4
While G=29 and getKey(29
Text(1,0,L|>Dec
If L>1:L-1→L:Pause 125:End:End
While G=21 and getKey(21
If L<255:L+1→L:Text(1,0,L|>Dec
Pause 125:End:End
While G=10 and getKey(10
A+1→A:Text(82,0,A|>Dec):Pause 110:End
While G=11 and getKey(11
Text(82,0,A|>Dec
If A>1:A-1→A:Pause 110:End:End
If G=13 and getKey(13
StorePic :X→O:Y→P:End
If G=12 and getKey(12
RecallPic :O→X:P→Y:DispGraph:End
If G=56 and getKey(56
ClrDraw:DispGraph:End
If G=14 and getKey(14
DrawInv :DispGraph:End
End
End
Lbl A
Pxl-On(X,Y
DispGraph:Pause A

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Code optimization
« Reply #2 on: June 17, 2010, 08:03:01 pm »
There are places where you do +9 and +90 to initialize variables.  Those are not optimizations!  Its only an optimization if the number is between negative 2 and positive 2.

Also there are places of code that look like this:
A+1→A:Text(82,0,A|>Dec)

They can be optimized like this:
Text(82,0,A+1→A|>Dec)
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Code optimization
« Reply #3 on: June 17, 2010, 08:10:10 pm »
Not really optimizations, but in SirCmpwn's code, things like:
If X<95 and getKey(3
should be
If X<95 and (getKey(3)
so that the Parser doesn't throw any errors.
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Code optimization
« Reply #4 on: June 17, 2010, 08:14:04 pm »
You don't actually need parenthesis there since direct keys are binary functions that return 0 or 1 always.  And it definately shouldn't throw an error.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Code optimization
« Reply #5 on: June 17, 2010, 08:30:25 pm »
Really? it always gives me bad symbol when i leave the parentheses from getkey()
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Code optimization
« Reply #6 on: June 17, 2010, 08:37:40 pm »
You do need it for getkey(_) itself, but you don't need to do this: (getkey(_)) is what I was referring to.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Code optimization
« Reply #7 on: June 17, 2010, 08:38:27 pm »
Nope, even w/v0.3.0, leaving the closing parenthesis off of something like getKey(12) and also getKey(0) throws a bad symbol error.
Edit: Quigibo already clarified and was referring to something slightly different than I was. Ninja'd, I suppose.
« Last Edit: June 17, 2010, 08:39:20 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Code optimization
« Reply #8 on: June 17, 2010, 08:47:45 pm »
Oh, yeah I know about that. I only put 1 closing parenthesis for the getkey and left the 'and' parentheses open.
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Code optimization
« Reply #9 on: June 18, 2010, 08:59:41 am »
ok i got all that done,
btw you can have things like
if g=26 and getkey(26
it has to be
if g=26 and getkey(26)
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Code optimization
« Reply #10 on: June 18, 2010, 02:29:14 pm »
huh, I thought that there needed to be an opening parenthesis whenever you used 'and' or 'or' in if/while/repeat statements for each extra item after the first.

ex.
if X=9 and (Y=2
if X=9 and (Y=2 or (Z=6
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Code optimization
« Reply #11 on: June 18, 2010, 02:46:50 pm »
huh, I thought that there needed to be an opening parenthesis whenever you used 'and' or 'or' in if/while/repeat statements for each extra item after the first.

ex.
if X=9 and (Y=2
if X=9 and (Y=2 or (Z=6
That's only because you have an operation after the "and". If X or Y or Z, for example, would work fine.

Quigibo, why do you force closing parentheses after getKey(? It really confused me when I got bad symbol errors with that a while back.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Code optimization
« Reply #12 on: June 18, 2010, 02:52:10 pm »
I think its because getKey can only take constants as arguments? 

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Code optimization
« Reply #13 on: June 18, 2010, 02:52:22 pm »
Code: [Select]
If X<95 and getKey(3):X+1->X:sub(A):End
If Y>7 and getKey(4):Y-1->Y:sub(A):End
If X>0 and getKey(2):X-1->X:sub(A):End
If Y<62 and getKey(1):Y+1->Y:sub(A):End

...

Lbl A
Pxl-On(X,Y):DispGraph:Pause A
Return

can be (in axe 3.0)

Code: [Select]
If X<95 and getKey(3)
sub(A,X+1->X,Y)
End
If Y>7 and getKey(4)
sub(A,X,Y-1->Y)
End
If X>0 and getKey(2)
sub(A,X-1->X,Y)
End
If Y<62 and getKey(1)
sub(A,X,Y+1->Y)
End

...

Lbl A
Pxl-On(r1,r2
DispGraph
Pause A
Return


Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Code optimization
« Reply #14 on: June 18, 2010, 03:10:07 pm »
So, how exactly does the parameter passing work in 0.3.0? I know you can send up to 3 arguments to a sub, but does it just turn r1 - r6 into normal variables? what about sending r1 - r6 as parameters? I'm still trying to figure out how to use the new features as they weren't really explained in great detail.
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13