NOGDUS

Articles, Tutorials, and other things. => Pixie Game Programming => Topic started by: Cycl0ne on April 08, 2011, 07:11:43 AM



Title: Question about using Float instead of Int
Post by: Cycl0ne on April 08, 2011, 07:11:43 AM
Hi,

i was stumbling about the code, that you use float for your sprites, how come? Im just curious, because the ARM Cpus have no FPU, thus Google says on Android:
"As a rule of thumb, floating-point is about 2x slower than integer on Android devices." It could be even that the device doenst even have an FPU (and to be worse, even no divider ;-).

So one Question that arises from me, why are sprites then in Float and not in INT ? (Thought float was used in opengl or any other 3d engine)?

Brgds

C.


Title: Re: Question about using Float instead of Int
Post by: Mattias Gustavsson on April 12, 2011, 01:05:40 PM
Well, at an early stage of the development, I did actually use integers for sprite positions etc. The reason I changed it, was because I noticed while making games, that I often had to keep track of, for example, a characters x and y position (which had to be floats, as I'm deciding how far to move things depending on the time elapsed since last frame, to get framerate independent movement) and then every frame pass it to the sprite. By changing the sprite position to float, I could just store the positions of the characters directly in the sprite, and that was a bit neater.

There's a few different ways to solve this... you could change the sprites to use integer, and leave it up to the game to store correct positions and pass them to the sprites. Or, you could have the sprites use a fixed-point datatype, which means it would work pretty much the same as it does now, as the floating precision you'd get in a float is not really relevant in this particular case.

Let me know if you'd like any more details on this (or if you need help implementing a fixed-point type, should you opt to go down that route)  :)


Title: Re: Question about using Float instead of Int
Post by: Cycl0ne on April 12, 2011, 01:38:11 PM
Ohh its ok. Since im still waiting for my android to get the 2.3 update for the full c/c++ Api, i cant really test this speed issue. We will see, when i get the baby compiled, until then i still code on Windows to get pixie better to know. ;)