(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
mouse input right away instead of waiting for GameLoop. (KUDr)
This commit is contained in:
		@@ -404,6 +404,7 @@ static void QZ_MouseMovedEvent(int x, int y)
 | 
			
		||||
		_cursor.pos.y = y;
 | 
			
		||||
		_cursor.dirty = true;
 | 
			
		||||
	}
 | 
			
		||||
	HandleMouseEvents();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -417,6 +418,7 @@ static void QZ_MouseButtonEvent(int button, BOOL down)
 | 
			
		||||
				_left_button_down = false;
 | 
			
		||||
				_left_button_clicked = false;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case 1:
 | 
			
		||||
@@ -426,6 +428,7 @@ static void QZ_MouseButtonEvent(int button, BOOL down)
 | 
			
		||||
			} else {
 | 
			
		||||
				_right_button_down = false;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -325,6 +325,7 @@ static int PollEvent(void)
 | 
			
		||||
				_cursor.pos.y = ev.motion.y;
 | 
			
		||||
				_cursor.dirty = true;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case SDL_MOUSEBUTTONDOWN:
 | 
			
		||||
@@ -347,6 +348,7 @@ static int PollEvent(void)
 | 
			
		||||
 | 
			
		||||
				default: break;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case SDL_MOUSEBUTTONUP:
 | 
			
		||||
@@ -360,6 +362,7 @@ static int PollEvent(void)
 | 
			
		||||
			} else if (ev.button.button == SDL_BUTTON_RIGHT) {
 | 
			
		||||
				_right_button_down = false;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case SDL_ACTIVEEVENT:
 | 
			
		||||
 
 | 
			
		||||
@@ -266,23 +266,27 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
 | 
			
		||||
		case WM_LBUTTONDOWN:
 | 
			
		||||
			SetCapture(hwnd);
 | 
			
		||||
			_left_button_down = true;
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		case WM_LBUTTONUP:
 | 
			
		||||
			ReleaseCapture();
 | 
			
		||||
			_left_button_down = false;
 | 
			
		||||
			_left_button_clicked = false;
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		case WM_RBUTTONDOWN:
 | 
			
		||||
			SetCapture(hwnd);
 | 
			
		||||
			_right_button_down = true;
 | 
			
		||||
			_right_button_clicked = true;
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		case WM_RBUTTONUP:
 | 
			
		||||
			ReleaseCapture();
 | 
			
		||||
			_right_button_down = false;
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		case WM_MOUSELEAVE:
 | 
			
		||||
@@ -290,6 +294,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
 | 
			
		||||
			_cursor.in_window = false;
 | 
			
		||||
 | 
			
		||||
			if (!_left_button_down && !_right_button_down) MyShowCursor(true);
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		case WM_MOUSEMOVE: {
 | 
			
		||||
@@ -337,6 +342,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
 | 
			
		||||
				_cursor.dirty = true;
 | 
			
		||||
			}
 | 
			
		||||
			MyShowCursor(false);
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -483,6 +489,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
 | 
			
		||||
			} else if (delta > 0) {
 | 
			
		||||
				_cursor.wheel--;
 | 
			
		||||
			}
 | 
			
		||||
			HandleMouseEvents();
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										63
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								window.c
									
									
									
									
									
								
							@@ -1461,27 +1461,22 @@ void HandleKeypress(uint32 key)
 | 
			
		||||
extern void UpdateTileSelection(void);
 | 
			
		||||
extern bool VpHandlePlaceSizingDrag(void);
 | 
			
		||||
 | 
			
		||||
static void MouseLoop(int click, int mousewheel)
 | 
			
		||||
static int _input_events_this_tick = 0;
 | 
			
		||||
 | 
			
		||||
static void HandleAutoscroll(void)
 | 
			
		||||
{
 | 
			
		||||
	int x,y;
 | 
			
		||||
	Window *w;
 | 
			
		||||
	ViewPort *vp;
 | 
			
		||||
	int x = _cursor.pos.x;
 | 
			
		||||
	int y = _cursor.pos.y;
 | 
			
		||||
 | 
			
		||||
	DecreaseWindowCounters();
 | 
			
		||||
	HandlePlacePresize();
 | 
			
		||||
	UpdateTileSelection();
 | 
			
		||||
	if (!VpHandlePlaceSizingDrag())  return;
 | 
			
		||||
	if (!HandleDragDrop())           return;
 | 
			
		||||
	if (!HandlePopupMenu())          return;
 | 
			
		||||
	if (!HandleWindowDragging())     return;
 | 
			
		||||
	if (!HandleScrollbarScrolling()) return;
 | 
			
		||||
	if (!HandleViewportScroll())     return;
 | 
			
		||||
	if (!HandleMouseOver())          return;
 | 
			
		||||
	if (_input_events_this_tick != 0) {
 | 
			
		||||
		/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */
 | 
			
		||||
		_input_events_this_tick = 0;
 | 
			
		||||
		/* there were some inputs this tick, don't scroll ??? */
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	x = _cursor.pos.x;
 | 
			
		||||
	y = _cursor.pos.y;
 | 
			
		||||
 | 
			
		||||
	if (click == 0 && mousewheel == 0) {
 | 
			
		||||
	if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
 | 
			
		||||
		w = FindWindowFromPt(x, y);
 | 
			
		||||
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
 | 
			
		||||
@@ -1504,8 +1499,29 @@ static void MouseLoop(int click, int mousewheel)
 | 
			
		||||
#undef scrollspeed
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MouseLoop(int click, int mousewheel)
 | 
			
		||||
{
 | 
			
		||||
	int x,y;
 | 
			
		||||
	Window *w;
 | 
			
		||||
	ViewPort *vp;
 | 
			
		||||
 | 
			
		||||
	DecreaseWindowCounters();
 | 
			
		||||
	HandlePlacePresize();
 | 
			
		||||
	UpdateTileSelection();
 | 
			
		||||
	if (!VpHandlePlaceSizingDrag())  return;
 | 
			
		||||
	if (!HandleDragDrop())           return;
 | 
			
		||||
	if (!HandlePopupMenu())          return;
 | 
			
		||||
	if (!HandleWindowDragging())     return;
 | 
			
		||||
	if (!HandleScrollbarScrolling()) return;
 | 
			
		||||
	if (!HandleViewportScroll())     return;
 | 
			
		||||
	if (!HandleMouseOver())          return;
 | 
			
		||||
 | 
			
		||||
	x = _cursor.pos.x;
 | 
			
		||||
	y = _cursor.pos.y;
 | 
			
		||||
 | 
			
		||||
	if (click == 0 && mousewheel == 0) return;
 | 
			
		||||
 | 
			
		||||
	w = FindWindowFromPt(x, y);
 | 
			
		||||
	if (w == NULL) return;
 | 
			
		||||
@@ -1562,7 +1578,7 @@ static void MouseLoop(int click, int mousewheel)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void InputLoop(void)
 | 
			
		||||
void HandleMouseEvents(void)
 | 
			
		||||
{
 | 
			
		||||
	int click;
 | 
			
		||||
	int mousewheel;
 | 
			
		||||
@@ -1583,20 +1599,29 @@ void InputLoop(void)
 | 
			
		||||
	if (_left_button_down && !_left_button_clicked) {
 | 
			
		||||
		_left_button_clicked = true;
 | 
			
		||||
		click = 1;
 | 
			
		||||
		_input_events_this_tick++;
 | 
			
		||||
	} else if (_right_button_clicked) {
 | 
			
		||||
		_right_button_clicked = false;
 | 
			
		||||
		click = 2;
 | 
			
		||||
		_input_events_this_tick++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mousewheel = 0;
 | 
			
		||||
	if (_cursor.wheel) {
 | 
			
		||||
		mousewheel = _cursor.wheel;
 | 
			
		||||
		_cursor.wheel = 0;
 | 
			
		||||
		_input_events_this_tick++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	MouseLoop(click, mousewheel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void InputLoop(void)
 | 
			
		||||
{
 | 
			
		||||
	HandleMouseEvents();
 | 
			
		||||
	HandleAutoscroll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UpdateWindows(void)
 | 
			
		||||
{
 | 
			
		||||
	Window *w;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								window.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								window.h
									
									
									
									
									
								
							@@ -802,6 +802,7 @@ void ResetWindowSystem(void);
 | 
			
		||||
int GetMenuItemIndex(const Window *w, int x, int y);
 | 
			
		||||
void InputLoop(void);
 | 
			
		||||
void HandleKeypress(uint32 key);
 | 
			
		||||
void HandleMouseEvents(void);
 | 
			
		||||
void UpdateWindows(void);
 | 
			
		||||
void InvalidateWidget(const Window *w, byte widget_index);
 | 
			
		||||
void InvalidateThisWindowData(Window *w);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user