Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Faster Maths... - Gideros Forum

Faster Maths...

SinisterSoftSinisterSoft Maintainer
edited February 2017 in General questions
@N1cke added support for Macros some time ago, but there hasn't been much discussion about them. So I decided to share what I have to start a conversation about different things that can be used to speed up the maths side of things.

Here are some examples of macros to speed things up:
pi@3.14159265358979324
deg@|(180.0/pi)*|
rad@|(pi/180.0)*|

by using something like d=deg(angle)
This gets converted before the text is parsed into:
d=(180.0*3.14159265358979324)*angle

The tokeniser evaluates the (180.0*3.14159265358979324) before it gets tokenised, so it becomes 565.486678*angle in tokens.

This is much faster than using the math lib deg function.

Likes: antix, jdbc, MobAmuse

+1 -1 (+3 / -0 ) Share on Facebook

Comments

  • SinisterSoftSinisterSoft Maintainer
    edited February 2017
    In the 2017.3 version of Gideros I have added a max and min operator to get rid of the need to use the math max and min functions, by making them operators they should be much faster as there is no need for the interpreter to search for the function then call the c version of the function outside of lua. The syntax is a little unusual though...

    <> is used for max and >< is used for min...
    a=30
    b=40
    print(a<>b) -- outputs 40
    print(a><b>
    </b>
    +1 -1 (+3 / -0 ) Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited February 2017
    In the 2017.3 version of Gideros I (together with some help from @hgy29 in getting it fully working) have added deg and rad operators. Like max and min these should be much faster than using the math library.
    d=^>pi  -- d will be set to 180
    a=^<180 -- a will be set to pi</pre>
     
    An easy way to remember which is which is that radians are small so they go at the narrow end of the > and degrees are usually bigger so they go at the wide end of the <.
     
    Gideros uses radians for the math library (sin, cos, etc) and degrees for the gfx api (rotation, etc) so these two functions are usually used a lot.

    Likes: stetso

    +1 -1 (+1 / -0 ) Share on Facebook
  • i wonder how many people will be able to remember such magic tricks. the min/max could be useful for me too, though.
    all in all they look funny but i hope there won't be much more of them...

    Likes: Holonist

    +1 -1 (+1 / -0 ) Share on Facebook
  • @keszegh You don't need to use them, you can use the math lib versions if you don't like the syntax. :)

    They will be a *lot* faster though than using the lib versions - there is a lot less overhead as they are dealt with directly by the interpreter rather than the interpreter searching for the lib entry and then using the lua-c interface.

    Likes: antix, keszegh

    +1 -1 (+2 / -0 ) Share on Facebook
  • @keszegh, once you use them a couple of times they will be cemented in the old grey matter, just like the math functions currently are :D

    For places where you use a load of these kind of calculations it should speed things up considerably. I'm looking forward to them :)
    Follow me on FaceBook Check out my DevBlog, my GitHub, and try my games...
    Falling Animals | Breaky Wall | Exetor | Mini Putt Golfing | Ninja Fruit Master
    +1 -1 (+3 / -0 ) Share on Facebook
Sign In or Register to comment.