Author Topic: What I've done?! O.o  (Read 9197 times)

0 Members and 2 Guests are viewing this topic.

Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: What I've done?! O.o
« Reply #15 on: February 15, 2013, 02:45:38 am »
Big thanks to MGOS! You helped me a lot ;)

Something you absolutely need to know : if you want to use trig, just build some LUTs (look-up tables, tables to hold constant values instead of recalculating them) and leave sin() and cos() alone. Do that at the really beginning of your code :

:E90D3→°SinLUT+2→°CosLUT
:L1→SinLUT+256→CosLUT       // L1 or whatever free RAM area of at least 512 bytes
:~1       // the negate sign, not the minus
:For(256)    // 256 possible angles, from 0 to 255
:sin(+1→r1)→{r1+SinLUT}
:cos(r1)→{r1+CosLUT}
:r1
:End


sry, but I don't understand this :( It seems to be highly optimized.. Can you give me a less optimized version, so that I can understand it? I mean, I want to understand "my" code :/

Thanks though, a LUT is a good idea ;)

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: What I've done?! O.o
« Reply #16 on: February 15, 2013, 04:48:13 am »
Basically, you calculate the sinus and cosinus of all of the 256 possible angles, and then store them in order to retrieve them rather than calculating them many times. Here's a non-optimized equivalent :

:E90D3->°SinLUT+2->°CosLUT          // gives two names to two numbers
:L1->SinLUT+256->CosLUT
:For(A,0,255)
:sin(A)->{A+SinLUT
:cos(A)->{A+CosLUT
:End


Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: What I've done?! O.o
« Reply #17 on: February 15, 2013, 01:15:23 pm »
I made a raycaster, the way I got rid of the fishbowl affect was to make the "side-rays" "jump" more. Therefore their reading will be less. If you understand what I mean. It's like making the walls on the side of your screen show up bigger.

Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: What I've done?! O.o
« Reply #18 on: February 15, 2013, 01:30:06 pm »
:E90D3->°SinLUT+2->°CosLUT          // gives two names to two numbers
:L1->SinLUT+256->CosLUT

I still don't understand these two lines..  :-\
saving L1 into something makes no sense to me :(

Can you pls explain this a little more easy?

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: What I've done?! O.o
« Reply #19 on: February 15, 2013, 02:25:14 pm »
Address->°Name will create a custom variable called “Name" at the given address. You can call the varables how you want, in this case CosLUT or SinLUT. The address should be some empty ram area at least 2 bytes large, since the varables in axe are all 16 bit - at that address the value of the variable is stored. Once you created a new variable, you can use them just like any other variable A-Z or theta.
In the second step you make those variables point to some free ram (L1 and L1+256), so now they hold the the address of the both areas which are use as LUTs.
« Last Edit: February 15, 2013, 02:26:27 pm by MGOS »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: What I've done?! O.o
« Reply #20 on: February 15, 2013, 02:29:19 pm »
:E90D3→°SinLUT+2→°CosLUT
:L1→SinLUT+256→CosLUT       // L1 or whatever free RAM area of at least 512 bytes
:~1       // the negate sign, not the minus
:For(256)    // 256 possible angles, from 0 to 255
:sin(+1→r1)→{r1+SinLUT}
:cos(r1)→{r1+CosLUT}
:r1
:End

Why not use constant pointers instead of variables, like this ?
:L1→°SinLUT+256→°CosLUT       // L1 or whatever free RAM area of at least 512 bytes
:~1       // the negate sign, not the minus
:For(256)    // 256 possible angles, from 0 to 255
:sin(+1→r1)→{r1+°SinLUT}
:cos(r1)→{r1+°CosLUT}
:r1
:End
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 Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: What I've done?! O.o
« Reply #21 on: February 15, 2013, 03:53:17 pm »
With this way of thinking, you can still directly use L1.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: What I've done?! O.o
« Reply #22 on: February 16, 2013, 01:07:58 am »
With this way of thinking, you can still directly use L1.
True, but renaming it makes the code more readable, and there is still the comment "or whatever free RAM area of at least 512 bytes" ;)
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