Is Sin and Cos calculated in c2 via look up tables?

Discussion and feedback on Construct 2

Post » Wed Mar 18, 2015 2:41 am

Hey,

Does anyone know if sin and cos have look up tables in c2 to speed it up or is it calculated every time it is called?

Thanks
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Wed Mar 18, 2015 3:04 am

I don't know, but based on performance results I'm leaning towards calculated every time.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Wed Mar 18, 2015 3:06 am

It uses javascript's Math.sin , Math.cos function call.
B
108
S
26
G
259
Posts: 4,430
Reputation: 145,679

Post » Wed Mar 18, 2015 3:08 am

@ruskul

lookup tables don't innately speed things up, and would only really be used on weaker hardware, or places where you need the same sin/cos value over and over, which is rarely true when they're being fed continuously changing floats like they are in construct.

C2 afaik uses the JS Math.sin() / Math.cos() functions, which likely work using the fastest possible implementation of trig functions using your hardware. You're not going to get a performance improvement by using a lookup table, and you'll likely get way worse performance if you try. If you have to recalculate the same sin/cos multiple times, do it once in a variable. this is the "fast" way to do things. Even if you do this you might not get any performance gains since most new js engines will dynamically find these little things and optimize them with their JIT compiler, unless its a really significant overuse in your code.
B
75
S
13
G
8
Posts: 1,973
Reputation: 9,841

Post » Wed Mar 18, 2015 5:49 am

@QuaziGNRLnose

That's good to know, It's crazy how smart compilers are at this point. My problem is, is that I am never sure if I am slowing things down or doing good. I have been setting a system that sorts the objects and tries to ensure I can compute sin(a) and then use it on all objects with the same angle calculation. after those are taken care of I then calculate the rest. I try to save as much cpu time as possible due to a heavy physics system.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests