Re: [AD] object_message() and scare_mouse() |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> Would it not be profitable to let object_message() automatically
> scare/unscare the mouse, so that Elias could apply his improvement to it
> too ?
The patch is almost ready, but I ran into a problem when experimenting with
Elias' improvement (scare_mouse_area instead of scare_mouse) on top of it:
artifacts are left on the screen by the mouse cursor.
There is a flaw in scare_mouse_area(). Here are the problematic code:
was_frozen = freeze_mouse_flag;
freeze_mouse_flag = TRUE;
if ((mouse_x - mouse_x_focus < x + w) &&
(mouse_y - mouse_y_focus < y + h) &&
(mouse_x - mouse_x_focus + mouse_sprite->w >= x) &&
(mouse_y - mouse_y_focus + mouse_sprite->h >= y)) {
if (scared_size < SCARED_SIZE) {
scared_screen[scared_size] = _mouse_screen;
scared_freeze[scared_size] = FALSE;
}
freeze_mouse_flag = was_frozen;
show_mouse(NULL);
}
freeze_mouse_flag freezes the mouse cursor and simultaneously blocks mouse_x
and mouse_y at the latest position of the cursor. Theoretically fine. But
freeze_mouse_flag may be set to TRUE *after* the test in update_move() has
passed and *before* the test in mouse_move() has passed, leading to mouse_x
and mouse_y being updated but not the pointer. Therefore the mouse may not be
scared while the pointer and the drawing area overlap.
The fix is to really use the latest position of the cursor, which is hold into
mx and my. Patch attached.
--
Eric Botcazou
--- /cvs/allegro/src/mouse.c Mon Sep 16 01:10:38 2002
+++ allegro/src/mouse.c Sat Nov 9 18:58:52 2002
@@ -104,7 +104,7 @@
static int got_hw_cursor = FALSE; /* hardware pointer available? */
static int hw_cursor_dirty = FALSE; /* need to set a new pointer? */
-static int mx, my; /* previous mouse position */
+static int mx, my; /* previous mouse pointer position */
static BITMAP *ms = NULL; /* previous screen data */
static BITMAP *mtemp = NULL; /* double-buffer drawing area */
@@ -561,10 +561,6 @@
void scare_mouse_area(int x, int y, int w, int h)
{
int was_frozen;
- ASSERT(x >= 0);
- ASSERT(y >= 0);
- ASSERT(w > 0);
- ASSERT(h > 0);
if (!mouse_driver)
return;
@@ -573,10 +569,10 @@
was_frozen = freeze_mouse_flag;
freeze_mouse_flag = TRUE;
- if ((mouse_x - mouse_x_focus < x + w) &&
- (mouse_y - mouse_y_focus < y + h) &&
- (mouse_x - mouse_x_focus + mouse_sprite->w >= x) &&
- (mouse_y - mouse_y_focus + mouse_sprite->h >= y)) {
+ if ((mx - mouse_x_focus < x + w) &&
+ (my - mouse_y_focus < y + h) &&
+ (mx - mouse_x_focus + mouse_sprite->w >= x) &&
+ (my - mouse_y_focus + mouse_sprite->h >= y)) {
if (scared_size < SCARED_SIZE) {
scared_screen[scared_size] = _mouse_screen;