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

0 Members and 2 Guests are viewing this topic.

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #15 on: July 25, 2013, 08:45:42 am »
But C is evaluated before the getkey.

Code: [Select]
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  //C is evaluated here! If C is 25 or 34, the thing will move
Output(B,A,"*
Repeat Ans
getKey→C     //and here C is being reset
End
End

That means the first time it may happen that the thing moves without a key being pressed because C was not cleared before. It's unlikely because quitting the loop sets C to 45, but if there was a different part of the program that uses C, it may happen (or the program was quit with on before).

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 #16 on: July 25, 2013, 08:46:57 am »
oh, right, i forgot that optimization.....i was still at the one where the inner loop was before evaluating.
Thanks for clarifying MGOS

EDIT: wouldn't it be quicker to do Ans->C then instead of DelVar C?
« Last Edit: July 25, 2013, 08:49:28 am by Sorunome »

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 #17 on: July 25, 2013, 12:57:28 pm »
Oh, so we were talking about completely different codes lol.
I was interested in whether Ans would be faster than DelVar or not.
Code: [Select]
For(A,1,500
DelVar CEnd
vs
Code: [Select]
For(A,1,500
Ans->C
End
Anyone wanna time this? I would do it, but my calc is bricked...
« Last Edit: July 25, 2013, 01:09:50 pm by dinosteven »

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #18 on: July 26, 2013, 07:43:15 am »
The first code takes about 3,2secs whereas the second takes 5,7 secs on my calc, so it would be a great optimisation to use "Delvar C" I think

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 #19 on: July 26, 2013, 07:45:15 am »
Coudln't we also optimize it to Delvar A,B,C then?

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

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #20 on: July 26, 2013, 08:16:55 am »
I think so Sorunome

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #21 on: July 26, 2013, 08:51:56 am »
Coudln't we also optimize it to Delvar A,B,C then?
I think so Sorunome
Nope. ERR:Syntax.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #22 on: July 26, 2013, 09:06:34 am »
You could do
Code: [Select]
DelVar ADelVar BDelVar CThat's the same size (since you don't need new lines in between), but be aware that the homescreen coordinates start at 1,1 in TI-Basic instead of 0,0.
another
Code: [Select]
Delvar AA+1->A would be slower again slower than just
Code: [Select]
1->A so it wouldn't be an optimization.

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 #23 on: July 26, 2013, 09:31:11 am »
Oh, I forgot that part x.x

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

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #24 on: July 26, 2013, 09:35:50 am »
You could do
Code: [Select]
DelVar ADelVar BDelVar CThat's the same size (since you don't need new lines in between)
Nope, "DelVar " is a two-byte token and "," is a one-byte token.

Also, I understand that you want to optimize speed-wise what's inside the loop to get the fastest movement, but the initialization (what is before the loop) should be optimized for size, shouldn't it ?
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

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 #25 on: July 27, 2013, 01:07:51 am »
Actually, you CAN do the DelVars. The min() and max() reset it, remember? All we need to do is move the erasing Output to the end of the loop, so that it doesn't give an error for out of bounds coordinates.
Like so:
Code: [Select]
DelVar ADelVarBDelVarCClrHome //I don't think commas work for DelVars.
Repeat Ans=45
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
Output(B,A,"
End

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Fastest/Most Optimized way to move a character around the homescreen
« Reply #26 on: July 27, 2013, 02:15:10 am »
Actually, you CAN do the DelVars.
Yeah, my "Nope" was not a "Nope, it doesn't work", but a "Nope, it doesn't take the same size" since the DelVar always take one more byte than the period.
« Last Edit: July 27, 2013, 02:15:34 am by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

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 #27 on: July 27, 2013, 08:50:26 am »
Oh, I was responding to MGOS about the DelVarA vs the 1->A.

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 #28 on: July 28, 2013, 04:01:16 am »
And further, you can remove the DelVar C because the maximum the numbers can become is 1, and the minimum is -1, but is overwritten in the bound check.

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 #29 on: July 28, 2013, 07:39:41 am »
What again?
You need the DelVar C otherwise the thing can move right/down when first looping.

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