1

I am using the dev kit, programming in C.

I was wondering - Is it faster to use floats to effectively move a sprite half a pixel every frame (e.g. x_pos= xpos -0.5f)? or instead to use logic statements to move the sprite every other frame?

Thank you - Rich

2

On most retro platforms (including the Neo-Geo), there is no hardware support for floating point operations. So they are done in software, and are a lot slower than usual integer operations. It's best to avoid floating point entirely if you need performance.

But there's a way to achieve what you're looking and still run fast. Basically, you use integers, but change the units. For example, instead of storing sprite coordinates in pixels, you could store them in units of 1/16 pixel. So to move the sprite left by half a pixel, you'd do x_pos = x_pos - 8.

Of course, the Neo-Geo hardware expects coordinates in pixels, so when setting up the sprite position, you have to divide x_pos by 16.

A good choice for the scale is 1 / 2n, i.e. 1/2, 1/4, 1/8, etc. With this, instead of having to multiply/divide by 2n, you can do a left/right bit-shift by n bits instead. On the 68000, this is much faster.

Keep in mind that this reduces the range of numbers that can be used. A 16-bit integer can go from -32768 to +32767, but if your scale is 1/16, it means your actual value will be between -2048 and 2047.9375.

If you need more details, search for "fixed-point arithmetic" smile
avatar
Zeroblog

« Tout homme porte sur l'épaule gauche un singe et, sur l'épaule droite, un perroquet. » — Jean Cocteau
« Moi je cherche plus de logique non plus. C'est surement pour cela que j'apprécie les Ataris, ils sont aussi logiques que moi ! » — GT Turbo

3

Moving every other frame as he said is also good wink
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

4

Indeed it is, and it's simpler to implement, but it only works for 1/2, 1/3, 1/4...
With fixed-point arithmetic, you have much more flexibility.
avatar
Zeroblog

« Tout homme porte sur l'épaule gauche un singe et, sur l'épaule droite, un perroquet. » — Jean Cocteau
« Moi je cherche plus de logique non plus. C'est surement pour cela que j'apprécie les Ataris, ils sont aussi logiques que moi ! » — GT Turbo

5

Thank you for all the info! I have had it drilled into me over the years that floats are slower than integers but I wasn't sure how it worked out if you had to access a variable from memory in order to simulate a float

I was thinking of using that toggle variable trick where you do : tg= 1- tg and it cycles between 1 and 0. That would work for alternate frames.

@zerosquare that sounds like a good technique to emulate more complicated fractions. I wouldn't have thought of that myself. I'll keep that in mind for the future

6

Just use fix point math. it's easy to do with 16 bit numbers and gives you a lot of control about smoothness of movement.
avatar