Author Topic: Routines  (Read 292070 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #420 on: October 06, 2010, 04:03:50 pm »
As a side note, when it has been below the time limit you should probably use the EDIT button to not double-post, else you can lose the game. :P

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #421 on: October 18, 2010, 09:31:56 am »
Well I wanted to post the source for a routine I had just made, but the option to attach files seems to have vanished... ???
« Last Edit: October 18, 2010, 09:37:06 am by Runer112 »

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Routines
« Reply #422 on: October 18, 2010, 11:11:37 am »
Well I wanted to post the source for a routine I had just made, but the option to attach files seems to have vanished... ???
It's because of the server move, I think.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #423 on: October 18, 2010, 02:00:49 pm »
Yeah I disabled them because anything uploaded as of today will be lost after the move (and may cause errors). The backup was made last night and will not be in sync with the database backup.

You can use Mediafire.com for the time being. Or you can just post in a CODE tag.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #424 on: October 20, 2010, 02:38:42 am »
Cool, I now have access to the forums again.

Anyways, the routines I had were a pair of deadly accurate sine and cosine routines. And by deadly accurate I mean percent errors in the hundredths or thousandths of a percent. Whereas the built-in routines accept integer inputs and give signed 8-bit integer outputs, these routines accept 8.8 fixed point inputs and give signed 8.8 fixed point outputs. That means it accepts inputs with 256 times the precision, and gives outputs with 256 times the precision as well!


The first file (TRIGLIB.8xp) is the library you probably want to use in most situations, as it's slower than the second library but over 300 bytes smaller. This is because, whereas the first library uses a 128-byte LUT for one quarter of the period and makes use of the symmetry of the sine wave to do extra calculations for values anywhere in the period, the second uses a 512-byte LUT for the full period.


EDIT: Oh right, I forgot to say: use sub(SIN,value) and sub(COS,value) to use them. And to properly insert a library like this into your program, put a line saying prgmTRIGLIB in the subroutine section of your code.
« Last Edit: October 20, 2010, 02:53:38 am by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #425 on: October 20, 2010, 02:41:22 am »
YAY! Welcome back from the other side of the universe, Runer112. ;D

Those routines seems pretty nice. Are they much slower than the regular Axe sin routine or is it almost the same?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #426 on: October 20, 2010, 03:23:38 am »
Well obviously they're not going to be as fast as the built-in sine and cosine routines, as not only are those written in pure, optimized assembly, but they don't have to be nearly as accurate. Timing the routines at 6MHz gave these results:

  • The built-in sine routine calculates the sines of 1-65535 in about 4.4. seconds (let's call this 100% speed)
  • My size-optimized sine routine calculates the sines of 1-65535 in about 23.1 seconds (19% speed)
  • My speed-optimized sine routine calculates the sines of 1-65535 in about 17.7 seconds (25% speed)

19% speed may sound a bit slow, but that's still almost 3,000 calculations per second. So these routines are about 4 (speed-optimized routine) or 5 (size optimized routine) times slower than the built-in routines. My routines are also 12 (size-optimized routine) or 22 (speed-optimized routine) times the size of the built-in routines (378 or 695 vs. 31 bytes). But you get 256 times the accuracy, so depending upon what you need, it could be worth it.
« Last Edit: October 20, 2010, 03:25:54 am by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #427 on: October 20, 2010, 04:37:28 am »
Ah ok. Seems kinda good I guess for Axe. One question, though: I never learned Sin/Cos much in hi school and never got into 3D stuff, but with your routine, what kind of game could be possible that wouldn't be with the built-in routine?

ASHBAD_ALVIN

  • Guest
Re: Routines
« Reply #428 on: October 20, 2010, 08:08:11 am »
making accurate polygons :D


Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #429 on: October 20, 2010, 08:12:52 am »
Ah ok. Seems kinda good I guess for Axe. One question, though: I never learned Sin/Cos much in hi school and never got into 3D stuff, but with your routine, what kind of game could be possible that wouldn't be with the built-in routine?

Raycaster :P

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #430 on: October 20, 2010, 11:20:02 am »
Although if you wanted to get the highest speed you would prerender a sin table into somewhere in memory to get high accuracy and high speed ^^

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #431 on: October 20, 2010, 11:23:50 am »
Although if you wanted to get the highest speed you would prerender a sin table into somewhere in memory to get high accuracy and high speed ^^

Well that's the point of the library called "TRIGLIB - Fast 512-byte LUT.8xp" :P

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #432 on: October 20, 2010, 11:28:03 am »
Oh whoops i misread your post :O It already is a LUT! *party*

EDIT: Wow that is really clever with the blending!
« Last Edit: October 20, 2010, 11:30:59 am by Builderboy »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #433 on: October 20, 2010, 01:24:36 pm »
Now go make a raycaster in Axe ;)
« Last Edit: October 20, 2010, 01:25:00 pm by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #434 on: October 20, 2010, 01:41:07 pm »
Ah I see. So I take it that the regular routines cannot achieve 3D and raycasting, or is it just too innacurate to achieve decent ones?