5Fermer
CosmicRLe 22/08/2023 à 01:15
Artemis (./5) :
if you want to get the final "float" result, don't divide by 256.0 it's too slow, shift right by 8, the idea is to keep integer number at all times (except for the init maybe)
int float_result = fixed_result >> 8; // you loose the floating point, but you have the closest integer value of your result

Thanks Artemis. Yes i was planning to do a shift. I think I can keep it *all* integer (like you say) now I am doing the multiply/shift (by 256). I don't need the fixed point numbers any more as far as I can see. The multiply gives me the extra precision I needed

I looked around the net and saw the ultimate way to do gradients is with a look-up table.

You can store all the reciprocals : 1/2,1/3,1/4,1/5 etc and then multiply to get your gradient

or for even more speed store all the gradients up to a certain length of slope. It doesn't take up that much memory - especially for Neo Geo which has some space to spare on cart