Which is faster?

Blitz3D Forums/Blitz3D Beginners Area/Which is faster?

WarpZone(Posted 2005) [#1]
Which is faster?

mx=MouseX() Mod 5
my=MouseY() Mod 5
DrawImage CursorImage,MouseX()-mx,MouseY()-my


or

DrawImage CursorImage,MouseX()-(MouseX() Mod 5),MouseY()-(MouseY() Mod 5)


I would have thought it was the second one, but I can't tell the difference when I run my app, so I thought I'd ask.

(The idea, obviously, is to force the mouse cursor image to snap to a grid. Is there an even faster way to do it?)

Thanks in advance for any helpful replies! :)


TartanTangerine (was Indiepath)(Posted 2005) [#2]
mx# = Mousex() AND $FFFC
my# = MouseY() AND $FFFC
Drawimage blah.........


Michael Reitzenstein(Posted 2005) [#3]
You really don't need to worry about these kinds of optimisations. You might save a few cylces (in this case a function call)... but CPUs can do billions of them a second nowdays. Just get everything working, and then check to see if anything is slowing your project down.


WarpZone(Posted 2005) [#4]
Indiepath.T, I've never seen this $FFFC ting before. I was expecting it to produce an error message, but to my surprise, when I plugged it in along with the first DrawImage command, it did something. Not what I wanted it to do, but it did something. Basically, the cursor floated around between 0,0 and 5,5 as I scrolled the mouse across the screen. It didn't follow the mouse like I wanted it to.

I tried changing it to mx# = Mousex() - $FFFC, but that didn't work either. (Made the cursor nowhere to be seen.)

This new command intrigues me. $FFFC is not anywhere in the Blitz manual that I can see. What is it? How does it work? Where can I find some documentation on it? And what other "hidden" commands does Blitz3D have?


GfK(Posted 2005) [#5]
This new command intrigues me. $FFFC is not anywhere in the Blitz manual that I can see. What is it? How does it work? Where can I find some documentation on it? And what other "hidden" commands does Blitz3D have?
ROFL!

Its not a 'hidden command'!! It's a number in hexadecimal format!

(65,532, to be specific)


WarpZone(Posted 2005) [#6]
Oh, okay. :)

So why does "mx# = Mousex() AND 65,532" set mx# equal to a number between 0 and 5...? I didn't know the And command could be used as anything other than a logical operator, which means it should produce an error if used in a calculation... right?

Give me more information! XD


Yan(Posted 2005) [#7]
So why does "mx# = Mousex() AND 65,532" set mx# equal to a number between 0 and 5...?

It doesn't!

You'll get 0,0,0,0,4,4,4,4,8,8,8,8,12,12,12,12...ETC.

The nearest you can get is mx# = MouseX() AND 3 which is the equivalent of mx# = MouseX() Mod 4 but, as Michael R has said, this is all pretty academic.


WarpZone(Posted 2005) [#8]
I'm telling you, when I run the program with Indiepath.T's code, it doesn't work the same way my original program did.

I'm going to try swapping out mx# = Mousex() AND $FFFC for my code again. Maybe I made a mistake the first time, and that's why it didn't work.

I'm not too concerned with optimizing my program at this point. I'm much more concerned with learning the best possible coding practices. That means grabbing free speed where I can get it, and it also means understanding new concepts. This use of AND is totally new to me, so I want to understand it.

Is there a good tutorial, example, or article explaining how to use the AND command in calculations like this? I never knew you could do this, since it's not documented in the BB command reference. And I can't wrap my brain around the concept, either. How could a variable equal the mouse position and three at the same time? Is that what the command literally means?

Is it a throwback from another programing language, perhaps, included for programmer ease-of-use?

Is it something new that's only documented in BlitzPlus?

I'm sorry for being pushy, but I really want to fully understand this! :)


WolRon(Posted 2005) [#9]
AND and OR are bitwise operators. That's why they work that way.

And what other "hidden" commands does Blitz3D have?

Handle and Object

Do a search for any of the above for more info.


Beaker(Posted 2005) [#10]
Best programming practise is to write easily readable concise code *that you understand*. Forget optimising.

The AND as used above is a binary operation, you have to think about what it is doing to each bit of the numbers/variables.


WarpZone(Posted 2005) [#11]
I think I'm starting to understand (vaguely) what you're talking about and how it works. Thanks, WolRon and Beaker. (Mee mee mee mew!) :) So in order to understand it, I'd have to convert all my variables into hex or binary or whatever format the computer is storing them as when it is storing them as bits, THEN also understand the ways in which AND and OR manipulate bitwise data, before I can even begin to think about strategic manipulation of these commands.

You're right. :) It's totally uneccessary, and more trouble than it would be worth to learn.

But I'm glad I at least have a vague idea now of what was going on and why it's not feisible to learn to mess with variables that way. :)