get_mouse_mickeys() and OS X
Ben Moreno

I've been working on a project that uses Allegro 4.2-svn (svn is needed for intel Mac support) and OpenLayer (and thus AllegroGL and the other OpenLayer support libraries). Everything works fine on Windows and Linux (except for the fact that I have to rest(0) before calling get_mouse_mickeys() on Linux for some odd reason). However, on OS X, only the first call to get_mouse_mickeys() sets the arguments to something other than 0. After the fist call, mickeyx and mickeyy are always set to 0.

I am curently using OS X 10.4.7 and Xcode (FWIW, I've also used gcc on the command line as well) to build the project. I have tried the lastest (as of yesterday) SVN of Allegro. Oddly, the exmouse program seems to work perfectly. My project is fullscreen, so that may be part of the problem. Everything other than get_mouse_mickeys() seems to be working.

I have tried calling poll_mouse() before get_mouse_mickeys, but that doesn't make a difference.

If anyone has any ideas, it would be greatly appreciated.

Thanks,
ben

Evert
Quote:

except for the fact that I have to rest(0) before calling get_mouse_mickeys() on Linux for some odd reason

That's weird. You're not using the hardware cursor, are you?

Quote:

Oddly, the exmouse program seems to work perfectly.

That's even stranger.
Can you post a small demo program that does reproduce the problem for you so we can test it?

Quote:

I have tried calling poll_mouse() before get_mouse_mickeys, but that doesn't make a difference.

Nah, it wouldn't. We should probably deprecate poll_mouse() at some point to tell people that it's a rather useless function...

Richard Phipps

Is get_mouse_mickeys being called twice in the main loop? That would zero the 2nd call..

Peter Hull

Mmm.

1#include <allegro.h>
2// This is C++
3 
4int main()
5{
6 allegro_init();
7 install_mouse();
8 set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0);
9 while (!mouse_b)
10 {
11 int x, y;
12 get_mouse_mickeys(&x, &y);
13 textprintf_ex(screen, font, 100, 100,
14 makecol(255,255,0), makecol(0,0,0), "(%d, %d) ", x, y);
15 rest(50); //replace with rest(0)
16 }
17 set_gfx_mode(GFX_TEXT, 0,0,0,0);
18 return 0;
19}
20END_OF_MAIN();

Works fine, but if I replace the rest(50) with rest(0), it always returns zero as reported.
OS X mouse coordinates are floats; is it possible that the loop runs so fast that the mouse move per cycle always gets rounded down to zero?

I'll have a look.

Pete

Richard Phipps

So a temporary solution would be to only call the rest(0) if the OS is linux?

Peter Hull

Actually, I'm wrong, it only appears to always return zero. New program (attached)

1#include <allegro.h>
2 
3int main()
4{
5 allegro_init();
6 install_mouse();
7 set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0);
8 while (!mouse_b)
9 {
10 int x, y;
11 get_mouse_mickeys(&x, &y);
12 if (x!=0 || y!=0) {
13 textprintf_ex(screen, font, 100, 100,
14 makecol(255,255,0), makecol(0,0,0), "(%d, %d) ", x, y);
15 }
16 rest(0);
17 }
18 set_gfx_mode(GFX_TEXT, 0,0,0,0);
19 return 0;
20}
21END_OF_MAIN();

How does this work for you, Ben?

Otherwise I have a simple patch to use floats internally when calculating the mickeys, attached. Can you try it, if the program above doesn't work.

Pete

Richard Phipps

Is it possible that the rest(0) is causing the process to switch to the OS and back again and that is destroying the old mouse data?

Ben Moreno

I tried the code you posted, it seems to work correctly. The problem doesn't appear to be rest(0) - I've tried running the program with rest() commented out. I'll try the patch, though, to see if that helps.

Thanks for helping.

Thread #587372. Printed from Allegro.cc