Author Topic: Fastest/Most Optimized way to move a character around the homescreen  (Read 8774 times)

0 Members and 1 Guest are viewing this topic.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Hey, I was just curious, what is the fastest/most optimized way to move a character around the home screen?
what I currently have is this:
Code: [Select]
ClrHome
1->A
1->B
Repeat C=45
Output(B,A,"*")
Repeat C
getkey->C
End
Output(B,A," ")
max(min(A-(C=24)+(C=26),16),1)->A
max(min(B-(C=25)+(C=34),8),1)->B
End

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #1 on: July 24, 2013, 12:17:51 pm »
You can replace variables with Ans in a few places.
Code: [Select]
ClrHome
1→A
Ans→B
Repeat C=45
Output(B,A,"*")
Repeat Ans
getKey→C
End
Output(B,A," ")
max(min(A-(Ans=24)+(Ans=26),16),1)→A
max(min(B-(C=25)+(C=34),8),1)→B
End

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #2 on: July 24, 2013, 12:44:29 pm »
You can also remove some of the closing parentheses but that won't affect speed at all, sadly.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #3 on: July 24, 2013, 12:45:45 pm »
You can replace variables with Ans in a few places.
why didn't i think of ans x.x
You can also remove some of the closing parentheses but that won't affect speed at all, sadly.
i know that, but idk why i put 'em in in this prog....

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #4 on: July 24, 2013, 12:47:46 pm »
Personally, I would organise it as:
Code: [Select]
ClrHome
1→A
Ans→B
Repeat C=45
Output(B,A,"*
Repeat Ans
getKey→C
End
Output(B,A,"
max(1,min(16,A-(Ans=24)+(Ans=26→A
max(1,min(8,B-(C=25)+(C=34→B
End
But that is just  size optimsation with probably a negligible speed boost. That is pretty close to my typical routine :P

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #5 on: July 24, 2013, 05:25:30 pm »
Oh, and you can also reorganize it so that the getkey loop is last. That way, you can replace the Repeat C=45 with Repeat Ans=45.
Code: [Select]
ClrHome
DelVarC1→A
Ans→B
Repeat Ans=45
Output(B,A,"
max(1,min(16,A-(Ans=24)+(Ans=26→A
max(1,min(8,B-(C=25)+(C=34→B
Output(B,A,"*
Repeat Ans
getKey→C
End
End
But that requires a DelVar of C in case C somehow had a value of 26 or 34... x.x
EDIT:
And let's not forget the ultimate tool for the guy who desperately wants to use Ans, and Ans only... LISTS! I'm not sure if a list in Ans is faster than variables accessed normally... Probably the list is slower... anyone want to test this code? My calc is bricked...
Code: [Select]
ClrHome
{1,1,0
Repeat 45=Ans(3
Output(Ans(1),Ans(2),"*
Repeat Ans(3
{Ans(1),Ans(2),getKey
End
Output(Ans(1),Ans(2),"
{max(1,min(16,Ans(1)-(Ans(3)=24)+(Ans(3)=26))),max(1,min(8,Ans(2)-(Ans(3)=25)+(Ans(3)=34))),Ans(3
End
Oh gahwd, this is messy. It's definitely not faster lol.
« Last Edit: July 24, 2013, 05:47:14 pm by dinosteven »

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #6 on: July 24, 2013, 05:26:34 pm »
um, why is there a DelVar C, you don't need that.

Also, that is some pretty nice optimizing :D

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #7 on: July 24, 2013, 05:50:10 pm »
um, why is there a DelVar C, you don't need that.
But that requires a DelVar of C in case C somehow had a value of 26 or 34... x.x
If C=26 or C=34 before launching the program, then it'll start off in the wrong place, having already moved. lol, doesn't really matter, but just in case.

Offline Joshuasm32

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 142
  • Rating: +19/-7
    • View Profile
    • Network
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #8 on: July 24, 2013, 09:11:35 pm »
I still have never really figured out how Repeat works...  I do this:

ClrHome
DelVar K
1->X
1->Z
While K!=45
getkey->K
If K!=0:Then
ClrHome
X+(K=26 and X<16)-(K=24 and X>0)=->X
Z+(K=34 and Z>0)-(K=25 and Z<8)->Z
Output(X,Z,"X
End
End
ClrHome

It is less efficient and probably slower...  D:  Can someone help me understand how to use Repeat?
My name is Josh and I a developer at Moonzean. I enjoy Radiohead, web development, Java, and cryptograms.
Spoiler For No Surprises, by Radiohead:
A heart that's full up like a landfill
A job that slowly kills you
Bruises that won't heal

You look so tired unhappy
Bring down the government
They don't, they don't speak for us

I'll take a quiet life
A handshake of carbon monoxide

And no alarms and no surprises
No alarms and no surprises
No alarms and no surprises
Silent, silent

This is my final fit
My final bellyache

With no alarms and no surprises
No alarms and no surprises
No alarms and no surprises please

Such a pretty house
And such a pretty garden

No alarms and no surprises
No alarms and no surprises
No alarms and no surprises please

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #9 on: July 24, 2013, 09:17:44 pm »
Repeat executes the inner body at least once, because it checks whether its condition is true after running each iteration of the body. While doesn't make this guarantee.
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #10 on: July 25, 2013, 01:35:56 am »
Repeat executes the inner body at least once, because it checks whether its condition is true after running each iteration of the body. While doesn't make this guarantee...
... as it checks the condition first. Also Repeat executes until the condition turns true and While until it turns false. ;)

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #11 on: July 25, 2013, 02:48:48 am »
um, why is there a DelVar C, you don't need that.
But that requires a DelVar of C in case C somehow had a value of 26 or 34... x.x
If C=26 or C=34 before launching the program, then it'll start off in the wrong place, having already moved. lol, doesn't really matter, but just in case.
But in TI-Basic a loop is alwys entered at least once (I thought), so even if C is 45 in the beginning it'll enter the loop and'll be overwritten by getKey->C
Also, just tested it and i'm right, it enteres the repeat loop once in the beginning

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #12 on: July 25, 2013, 08:10:02 am »
Yes, as was said before, Repeat works like this:
Code: [Select]
Lbl 1
<code code code>
If K≠45
Goto 1
While works like this:
Code: [Select]
Lbl 1
If K=45
Then
<code code code>
Goto 1
End
I hope that helps a little. I personally prefer Repeat loops over While loops in most cases.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #13 on: July 25, 2013, 08:35:01 am »
um, why is there a DelVar C, you don't need that.
But that requires a DelVar of C in case C somehow had a value of 26 or 34... x.x
If C=26 or C=34 before launching the program, then it'll start off in the wrong place, having already moved. lol, doesn't really matter, but just in case.
But in TI-Basic a loop is alwys entered at least once (I thought), so even if C is 45 in the beginning it'll enter the loop and'll be overwritten by getKey->C
Also, just tested it and i'm right, it enteres the repeat loop once in the beginning
No, I didn't mean that it will quit early if C=45. I meant C=26 or C=34. Do 26->C or 34->C before executing my code (without the DelVar). I'm almost positive that the * will NOT be in the upper left corner, it will be shifted right or down.
...and after testing, 26->C doesn't do this, as my code changes A with Ans, which is initialized as 1. But do a 34->C before executing my code. The * will start out at 2,1 rather than 1,1. That's what I was saying, not that it would quit.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #14 on: July 25, 2013, 08:37:33 am »
No, again same thing (just tried it out), as xeda pointed out with lables.
You enter the inner loop at least once, the keypress is stored an there you go, C is again 0 until you hit a key.

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!