Optimization question floating point
Posted: January 20th, 2019, 8:12 am
I know the PS1 does not have native floating point on the CPU but I was making a game where not many things use it so I felt like it was an ok trade off to use it. I did come across one instance where its noticeable but its not a big deal if I can't fix it.
I have a knock back function and its basically like this, I omitted not necessary code:
I have commented out and tested each part of the code. I have found that atan2 is slowing it down a lot, It skips like 1-3 frames when I use it. I only use it for one frame when something uses knock back so its not too bad, and its only really bad in big explosions with lots of objects getting hit. I did google "fast atan2 in c" but what I found was slower than the one from the SDK or was X86 specific.
Im ok with replacing it with something that's much less accurate. Finding the distance is the next slowest part but "abs(tmpYSub) + abs(tmpXSub)" was a good trade off for me, so im mostly looking to replace atan2. Thanks for reading!
I have a knock back function and its basically like this, I omitted not necessary code:
Code: Select all
float angle, tmpYSub, tmpXSub;
tmpYSub = npc.x - knockback.x;
tmpYSub = npc.y - knockback.y;
if (sqrt(tmpYSub * tmpYSub + tmpXSub * tmpXSub) < knockback.range){
angle = atan2(tmpYSub, tmpXSub);
*npcHspeedInOut += knockback->intensity * cos(angle);
*npcVspeedInOut += knockback->intensity * sin(angle);
}
Im ok with replacing it with something that's much less accurate. Finding the distance is the next slowest part but "abs(tmpYSub) + abs(tmpXSub)" was a good trade off for me, so im mostly looking to replace atan2. Thanks for reading!