Quick Links: Gideros Home | Download Gideros | Developer Guide
Faster Maths...
  • SinisterSoftSinisterSoft +1 -1 (+3 / -0 )
    Maintainer
    @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

  • SinisterSoftSinisterSoft +1 -1 (+3 / -0 )
    Maintainer
    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) -- outputs 30

  • SinisterSoftSinisterSoft +1 -1 (+1 / -0 )
    Maintainer
    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


    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 <.<br />
    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

  • keszegh +1 -1 (+1 / -0 )
    Member
    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

  • SinisterSoftSinisterSoft +1 -1 (+2 / -0 )
    Maintainer
    @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

  • antixantix +1 -1 (+3 / -0 )
    Member
    @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 :)
    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters