randrew / uxn32

Uxn emulator for Windows and Wine
171 stars 7 forks source link

Support full sprite flipping #17

Closed neauoire closed 1 year ago

randrew commented 1 year ago

fx = flipx ? -1 : 1;

🤔 I think you could use the 0x10 bit from the sprite variable to directly determine the sign, without needing to do a ? conditional. (Same for flipy/fy.) Maybe not worth it?

        for (i = 0; i <= n; i++, x += dy * fx, y += dx * fy)

For Uxn32, since it's often built with unsophisticated compilers, I think it's a good idea to hoist constant operations like dy * fx out of the loop, so that the code to repeatedly calculate them won't be included in the body of the loop. A good compiler will do this automatically, but Uxn32 works with older/blunter compilers. Maybe it's not a big deal in this case, since it's not in an innermost loop. I think it would add a couple more lines to the program. Maybe not worth it? Hmm.

neauoire commented 1 year ago

I think it's worth taking that out of the loop, I edited the PR.

I think you could use the 0x10 bit from the sprite variable to directly determine the sign, without needing to do a ? conditional. (Same for flipy/fy.) Maybe not worth it?

I've tried that but I couldn't get it to work, you mean like shifting it to 0x80 and using Uint8 cast to do the multiplication, or ORing the negative bit? It doesn't work I think, but I couldn't figure out why, any idea?

randrew commented 1 year ago

I've tried that but I couldn't get it to work, you mean like shifting it to 0x80 and using Uint8 cast to do the multiplication, or ORing the negative bit? It doesn't work I think, but I couldn't figure out why, any idea?

Dunno, I'd have to spend some more time thinking about it. I think we can worry about it later (or never) since it's good enough as it is now. Thanks :) I'll merge this when I boot up my PC tomorrow.