[Scummvm-cvs-logs] CVS: scummvm/sword2 console.cpp,1.45,1.46 controls.cpp,1.67,1.68 debug.cpp,1.40,1.41 function.cpp,1.61,1.62 module.mk,1.11,1.12 mouse.cpp,1.58,1.59 resman.cpp,1.93,1.94 speech.cpp,1.63,1.64 sword2.cpp,1.111,1.112 sword2.h,1.61,1.62

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Sun May 9 06:33:04 CEST 2004


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12787

Modified Files:
	console.cpp controls.cpp debug.cpp function.cpp module.mk 
	mouse.cpp resman.cpp speech.cpp sword2.cpp sword2.h 
Log Message:
Removed the buffering of mouse and keyboard events. I don't think any of
our other engines do this, so there is little reason for BS2 to. I did add
a filtering mechanism so that mouse button releases and scroll wheeling is
ignored during normal gameplay, but I don't know if that was necessary
either.

Since this left little more than an empty husk where the Input class used
to be, I've eliminated that class and buried its remains in Sword2Engine.


Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- console.cpp	5 May 2004 07:06:17 -0000	1.45
+++ console.cpp	9 May 2004 13:32:03 -0000	1.46
@@ -302,12 +302,17 @@
 }
 
 bool Debugger::Cmd_Rect(int argc, const char **argv) {
+	uint32 filter = _vm->setEventFilter(0);
+
 	_definingRectangles = !_definingRectangles;
 
-	if (_definingRectangles)
+	if (_definingRectangles) {
+		_vm->setEventFilter(filter & ~(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP));
 		DebugPrintf("Mouse rectangles enabled\n");
-	else
+	} else {
+		_vm->setEventFilter(filter | RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP);
 		DebugPrintf("Mouse rectangles disabled\n");
+	}
 
 	_draggingRectangle = 0;
 	return true;

Index: controls.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.cpp,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- controls.cpp	23 Apr 2004 07:01:37 -0000	1.67
+++ controls.cpp	9 May 2004 13:32:03 -0000	1.68
@@ -304,6 +304,8 @@
 }
 
 int Dialog::run() {
+	uint32 oldFilter = _gui->_vm->setEventFilter(0);
+
 	int i;
 
 	paint();
@@ -316,17 +318,16 @@
 		_gui->_vm->_graphics->processMenu();
 		_gui->_vm->_graphics->updateDisplay(false);
 
-		int16 newMouseX = _gui->_vm->_input->_mouseX;
-		int16 newMouseY = _gui->_vm->_input->_mouseY + 40;
+		int16 newMouseX = _gui->_vm->_mouseX;
+		int16 newMouseY = _gui->_vm->_mouseY + 40;
 
-		MouseEvent *me = _gui->_vm->_input->mouseEvent();
-		KeyboardEvent ke;
-		int32 keyboardStatus = _gui->_vm->_input->readKey(&ke);
+		MouseEvent *me = _gui->_vm->mouseEvent();
+		KeyboardEvent *ke = _gui->_vm->keyboardEvent();
 
-		if (keyboardStatus == RD_OK) {
-			if (ke.keycode == 27)
+		if (ke) {
+			if (ke->keycode == 27)
 				setResult(0);
-			else if (ke.keycode == '\n' || ke.keycode == '\r')
+			else if (ke->keycode == '\n' || ke->keycode == '\r')
 				setResult(1);
 		}
 
@@ -391,8 +392,8 @@
 			if (newMouseX != oldMouseX || newMouseY != oldMouseY)
 				_widgets[i]->onMouseMove(newMouseX, newMouseY);
 
-			if (keyboardStatus == RD_OK)
-				_widgets[i]->onKey(&ke);
+			if (ke)
+				_widgets[i]->onKey(ke);
 
 			_widgets[i]->onTick();
 		}
@@ -406,6 +407,7 @@
 			setResult(0);
 	}
 
+	_gui->_vm->setEventFilter(oldFilter);
 	return _result;
 }
 
@@ -1480,19 +1482,13 @@
 
 	// Wait for ESC or mouse click
 	while (1) {
-		MouseEvent *me;
-
 		_gui->_vm->_graphics->updateDisplay();
 
-		if (_gui->_vm->_input->keyWaiting()) {
-			KeyboardEvent ke;
-
-			_gui->_vm->_input->readKey(&ke);
-			if (ke.keycode == 27)
-				break;
-		}
+		KeyboardEvent *ke = _gui->_vm->keyboardEvent();
+		if (ke && ke->keycode == 27)
+			break;
 
-		me = _gui->_vm->_input->mouseEvent();
+		MouseEvent *me = _gui->_vm->mouseEvent();
 		if (me && (me->buttons & RD_LEFTBUTTONDOWN))
 			break;
 

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/debug.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- debug.cpp	5 May 2004 07:06:17 -0000	1.40
+++ debug.cpp	9 May 2004 13:32:03 -0000	1.41
@@ -183,14 +183,14 @@
 
 		if (_vm->_mouseTouching)
 			sprintf(buf, "mouse %d,%d (id %d: %s)",
-				_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x,
-				_vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y,
+				_vm->_mouseX + _vm->_thisScreen.scroll_offset_x,
+				_vm->_mouseY + _vm->_thisScreen.scroll_offset_y,
 				_vm->_mouseTouching,
 				_vm->fetchObjectName(_vm->_mouseTouching, name));
 		else
 			sprintf(buf, "mouse %d,%d (not touching)",
-				_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x,
-				_vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y);
+				_vm->_mouseX + _vm->_thisScreen.scroll_offset_x,
+				_vm->_mouseY + _vm->_thisScreen.scroll_offset_y);
 
 		makeDebugTextBlock(buf, 0, 30);
 
@@ -311,7 +311,7 @@
 	// mouse marker & coords
 
 	if (_displayMouseMarker)
-		plotCrossHair(_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x, _vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y, 215);
+		plotCrossHair(_vm->_mouseX + _vm->_thisScreen.scroll_offset_x, _vm->_mouseY + _vm->_thisScreen.scroll_offset_y, 215);
 
    	// mouse area rectangle / sprite box rectangle when testing anims
 

Index: function.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/function.cpp,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- function.cpp	23 Apr 2004 07:01:38 -0000	1.61
+++ function.cpp	9 May 2004 13:32:03 -0000	1.62
@@ -662,9 +662,9 @@
 
 		_vm->_graphics->updateDisplay();
 
-		KeyboardEvent ke;
+		KeyboardEvent *ke = _vm->keyboardEvent();
 
-		if (_vm->_input->readKey(&ke) == RD_OK && ke.keycode == 27) {
+		if (ke && ke->keycode == 27) {
 			if (!abortCredits) {
 				abortCredits = true;
 				_vm->_graphics->fadeDown();

Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/module.mk,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- module.mk	23 Apr 2004 07:01:38 -0000	1.11
+++ module.mk	9 May 2004 13:32:03 -0000	1.12
@@ -28,7 +28,6 @@
 	sword2/walker.o \
 	sword2/driver/d_draw.o \
 	sword2/driver/d_sound.o \
-	sword2/driver/keyboard.o \
 	sword2/driver/menu.o \
 	sword2/driver/_mouse.o \
 	sword2/driver/palette.o \

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/mouse.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- mouse.cpp	24 Apr 2004 12:29:35 -0000	1.58
+++ mouse.cpp	9 May 2004 13:32:03 -0000	1.59
@@ -107,7 +107,7 @@
 		systemMenuMouse();
 		break;
 	case MOUSE_holding:
-		if (_input->_mouseY < 400) {
+		if (_mouseY < 400) {
 			_mouseMode = MOUSE_normal;
 			debug(5, "   releasing");
 		}
@@ -118,13 +118,13 @@
 }
 
 int Sword2Engine::menuClick(int menu_items) {
-	if (_input->_mouseX < RDMENU_ICONSTART)
+	if (_mouseX < RDMENU_ICONSTART)
 		return -1;
 
-	if (_input->_mouseX > RDMENU_ICONSTART + menu_items * (RDMENU_ICONWIDE + RDMENU_ICONSPACING) - RDMENU_ICONSPACING)
+	if (_mouseX > RDMENU_ICONSTART + menu_items * (RDMENU_ICONWIDE + RDMENU_ICONSPACING) - RDMENU_ICONSPACING)
 		return -1;
 
-	return (_input->_mouseX - RDMENU_ICONSTART) / (RDMENU_ICONWIDE + RDMENU_ICONSPACING);
+	return (_mouseX - RDMENU_ICONSTART) / (RDMENU_ICONWIDE + RDMENU_ICONSPACING);
 }
 
 void Sword2Engine::systemMenuMouse(void) {
@@ -144,7 +144,7 @@
 	// If the mouse is moved off the menu, close it. Unless the player is
 	// dead, in which case the menu should always be visible.
 
-	if (_input->_mouseY > 0 && !Logic::_scriptVars[DEAD]) {
+	if (_mouseY > 0 && !Logic::_scriptVars[DEAD]) {
 		_mouseMode = MOUSE_normal;
 		_graphics->hideMenu(RDMENU_TOP);
 		return;
@@ -152,12 +152,12 @@
 
 	// Check if the user left-clicks anywhere in the menu area.
 
-	me = _input->mouseEvent();
+	me = mouseEvent();
 
 	if (!me || !(me->buttons & RD_LEFTBUTTONDOWN))
 		return;
 
-	if (_input->_mouseY > 0)
+	if (_mouseY > 0)
 		return;
 
 	hit = menuClick(ARRAYSIZE(icon_list));
@@ -266,7 +266,7 @@
 	// objects in the scene, so if the mouse moves off the inventory menu,
 	// then close it.
 
-	if (_input->_mouseY < 400) {
+	if (_mouseY < 400) {
 		_mouseMode = MOUSE_normal;
 		_graphics->hideMenu(RDMENU_BOTTOM);
 		return;
@@ -278,7 +278,7 @@
 
 	// Now do the normal click stuff
 
-	me = _input->mouseEvent();
+	me = mouseEvent();
 
 	if (!me)
 		return;
@@ -319,8 +319,8 @@
 
 		// These might be required by the action script about to be run
 
-		Logic::_scriptVars[MOUSE_X] = _input->_mouseX + _thisScreen.scroll_offset_x;
-		Logic::_scriptVars[MOUSE_Y] = _input->_mouseY + _thisScreen.scroll_offset_y;
+		Logic::_scriptVars[MOUSE_X] = _mouseX + _thisScreen.scroll_offset_x;
+		Logic::_scriptVars[MOUSE_Y] = _mouseY + _thisScreen.scroll_offset_y;
 
 		// For scripts to know what's been clicked. First used for
 		// 'room_13_turning_script' in object 'biscuits_13'
@@ -387,13 +387,13 @@
 
 	// If the mouse is moved off the menu, close it.
 
-	if (_input->_mouseY < 400) {
+	if (_mouseY < 400) {
 		_mouseMode = MOUSE_normal;
 		_graphics->hideMenu(RDMENU_BOTTOM);
 		return;
 	}
 
-	me = _input->mouseEvent();
+	me = mouseEvent();
 
 	if (!me)
 		return;
@@ -471,7 +471,7 @@
 	// big-object menu lock situation, of if the player is dragging an
 	// object.
 
-	if (_input->_mouseY < 0 && !_mouseModeLocked && !Logic::_scriptVars[OBJECT_HELD]) {
+	if (_mouseY < 0 && !_mouseModeLocked && !Logic::_scriptVars[OBJECT_HELD]) {
 		_mouseMode = MOUSE_system_menu;
 
 		if (_mouseTouching) {
@@ -490,7 +490,7 @@
 	// Check if the cursor has moved onto the inventory menu area. No
 	// inventory in big-object menu lock situation,
 
-	if (_input->_mouseY > 399 && !_mouseModeLocked) {
+	if (_mouseY > 399 && !_mouseModeLocked) {
 		// If an object is being held, i.e. if the mouse cursor has a
 		// luggage, go to drag mode instead of menu mode, but the menu
 		// is still opened.
@@ -523,7 +523,7 @@
 
 	mouseOnOff();
 
-	me = _input->mouseEvent();
+	me = mouseEvent();
 
 	if (!me)
 		return;
@@ -539,8 +539,8 @@
 
 			if (button_down) {
 				// set both (x1,y1) and (x2,y2) to this point
-				_debugger->_rectX1 = _debugger->_rectX2 = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x;
-				_debugger->_rectY1 = _debugger->_rectY2 = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y;
+				_debugger->_rectX1 = _debugger->_rectX2 = (uint32) _mouseX + _thisScreen.scroll_offset_x;
+				_debugger->_rectY1 = _debugger->_rectY2 = (uint32) _mouseY + _thisScreen.scroll_offset_y;
 				_debugger->_draggingRectangle = 1;
 			}
 		} else if (_debugger->_draggingRectangle == 1) {
@@ -552,8 +552,8 @@
 				_debugger->_draggingRectangle = 2;
 			} else {
 				// drag rectangle
-				_debugger->_rectX2 = (uint32) _input->_mouseX + _thisScreen.scroll_offset_x;
-				_debugger->_rectY2 = (uint32) _input->_mouseY + _thisScreen.scroll_offset_y;
+				_debugger->_rectX2 = (uint32) _mouseX + _thisScreen.scroll_offset_x;
+				_debugger->_rectY2 = (uint32) _mouseY + _thisScreen.scroll_offset_y;
 			}
 		} else {
 			// currently locked to avoid knocking out of place
@@ -582,8 +582,7 @@
 
 	// Now do the normal click stuff
 
-	// We only care about down clicks when the mouse is over an object. We
-	// ignore mouse releases
+	// We only care about down clicks when the mouse is over an object.
 
 	if (!_mouseTouching || !button_down)
 		return;
@@ -618,8 +617,8 @@
 
 	// These might be required by the action script about to be run
 
-	Logic::_scriptVars[MOUSE_X] = _input->_mouseX + _thisScreen.scroll_offset_x;
-	Logic::_scriptVars[MOUSE_Y] = _input->_mouseY + _thisScreen.scroll_offset_y;
+	Logic::_scriptVars[MOUSE_X] = _mouseX + _thisScreen.scroll_offset_x;
+	Logic::_scriptVars[MOUSE_Y] = _mouseY + _thisScreen.scroll_offset_y;
 
 	if (_mouseTouching == Logic::_scriptVars[EXIT_CLICK_ID] && (me->buttons & RD_LEFTBUTTONDOWN)) {
 		// It's the exit double click situation. Let the existing
@@ -693,7 +692,7 @@
 	// don't detect objects that are hidden behind the menu bars (ie. in
 	// the scrolled-off areas of the screen)
 
-	if (_input->_mouseY < 0 || _input->_mouseY > 399) {
+	if (_mouseY < 0 || _mouseY > 399) {
 		pointer_type = 0;
 		_mouseTouching = 0;
 	} else {
@@ -823,10 +822,10 @@
 			// mouse-detection-box
 
 			if (_mouseList[i].priority == priority &&
-			    _input->_mouseX + _thisScreen.scroll_offset_x >= _mouseList[i].x1 &&
-			    _input->_mouseX + _thisScreen.scroll_offset_x <= _mouseList[i].x2 &&
-			    _input->_mouseY + _thisScreen.scroll_offset_y >= _mouseList[i].y1 &&
-			    _input->_mouseY + _thisScreen.scroll_offset_y <= _mouseList[i].y2) {
+			    _mouseX + _thisScreen.scroll_offset_x >= _mouseList[i].x1 &&
+			    _mouseX + _thisScreen.scroll_offset_x <= _mouseList[i].x2 &&
+			    _mouseY + _thisScreen.scroll_offset_y >= _mouseList[i].y1 &&
+			    _mouseY + _thisScreen.scroll_offset_y <= _mouseList[i].y2) {
 				// Record id
 				_mouseTouching = _mouseList[i].id;
 
@@ -994,8 +993,8 @@
 	// line reference number
 
 	_pointerTextBlocNo = _fontRenderer->buildNewBloc(
-		text + 2, _input->_mouseX + xOffset,
-		_input->_mouseY + yOffset,
+		text + 2, _mouseX + xOffset,
+		_mouseY + yOffset,
 		POINTER_TEXT_WIDTH, POINTER_TEXT_PEN,
 		RDSPR_TRANS | RDSPR_DISPLAYALIGN,
 		_speechFontId, justification);
@@ -1066,7 +1065,7 @@
 
 void Sword2Engine::monitorPlayerActivity(void) {
 	// if there is at least one mouse event outstanding
-	if (_input->checkForMouseEvents()) {
+	if (checkForMouseEvents()) {
 		// reset activity delay counter
 		_playerActivityDelay = 0;
 	} else {
@@ -1133,7 +1132,7 @@
 	}
 
 	// if mouse is over menu area
-	if (_vm->_input->_mouseY > 399) {
+	if (_vm->_mouseY > 399) {
 		if (_vm->_mouseMode != MOUSE_holding) {
 			// VITAL - reset things & rebuild the menu
 			_vm->_mouseMode = MOUSE_normal;

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -d -r1.93 -r1.94
--- resman.cpp	9 May 2004 13:20:12 -0000	1.93
+++ resman.cpp	9 May 2004 13:32:03 -0000	1.94
@@ -860,14 +860,11 @@
 	// CD2: "RBSII2"
 
 	while (1) {
-		KeyboardEvent ke;
-		MouseEvent *me;
-
-		me = _vm->_input->mouseEvent();
+		MouseEvent *me = _vm->mouseEvent();
 		if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN)))
 			break;
 
-		if (_vm->_input->readKey(&ke) == RD_OK)
+		if (_vm->keyboardEvent())
 			break;
 
 		_vm->_graphics->updateDisplay();

Index: speech.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/speech.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- speech.cpp	5 May 2004 07:06:18 -0000	1.63
+++ speech.cpp	9 May 2004 13:32:03 -0000	1.64
@@ -135,11 +135,11 @@
 	}
 
 	// The menu is there - we're just waiting for a click. We only care
-	// about left clicks and ignore mouse releases.
+	// about left clicks.
 
-	MouseEvent *me = _vm->_input->mouseEvent();
+	MouseEvent *me = _vm->mouseEvent();
 
-	if (!me || !(me->buttons & RD_LEFTBUTTONDOWN) || _vm->_input->_mouseY < 400)
+	if (!me || !(me->buttons & RD_LEFTBUTTONDOWN) || _vm->_mouseY < 400)
 		return IR_REPEAT;
 
 	// Check for click on a menu.
@@ -200,7 +200,7 @@
 
 	_vm->_graphics->hideMenu(RDMENU_BOTTOM);
 
-	if (_vm->_input->_mouseY > 399) {
+	if (_vm->_mouseY > 399) {
 		// Will wait for cursor to move off the bottom menu
 		_vm->_mouseMode = MOUSE_holding;
 	}
@@ -995,8 +995,8 @@
 
 	// So that we can go to the options panel while text & speech is
 	// being tested
-	if (_scriptVars[SYSTEM_TESTING_TEXT] == 0 || _vm->_input->_mouseY > 0) {
-		MouseEvent *me = _vm->_input->mouseEvent();
+	if (_scriptVars[SYSTEM_TESTING_TEXT] == 0 || _vm->_mouseY > 0) {
+		MouseEvent *me = _vm->mouseEvent();
 
 		// Note that we now have TWO click-delays - one for LEFT
 		// button, one for RIGHT BUTTON
@@ -1004,7 +1004,7 @@
 		if ((!_leftClickDelay && me && (me->buttons & RD_LEFTBUTTONDOWN)) ||
 		    (!_rightClickDelay && me && (me->buttons & RD_RIGHTBUTTONDOWN))) {
 			// Mouse click, after click_delay has expired -> end
-			// the speech. We ignore mouse releases
+			// the speech.
 
 			// if testing text & speech
 			if (_scriptVars[SYSTEM_TESTING_TEXT]) {
@@ -1018,10 +1018,6 @@
 				}
 			}
 
-			// Trash anything that's buffered
-			while (_vm->_input->mouseEvent())
-				;
-
 			speechFinished = true;
 
 			// if speech sample playing, halt it prematurely

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- sword2.cpp	5 May 2004 07:06:18 -0000	1.111
+++ sword2.cpp	9 May 2004 13:32:03 -0000	1.112
@@ -120,6 +120,11 @@
 	_mixer->setVolume(256);
 	_mixer->setMusicVolume(256);
 
+	_keyboardEvent.pending = false;
+	_mouseEvent.pending = false;
+
+	_mouseX = _mouseY = 0;
+
 	// get some falling RAM and put it in your pocket, never let it slip
 	// away
 
@@ -137,7 +142,6 @@
 	_logic = new Logic(this);
 	_fontRenderer = new FontRenderer(this);
 	_gui = new Gui(this);
-	_input = new Input(this);
 	_sound = new Sound(this);
 
 	_lastPaletteRes = 0;
@@ -194,7 +198,6 @@
 	delete _debugger;
 	delete _graphics;
 	delete _sound;
-	delete _input;
 	delete _gui;
 	delete _fontRenderer;
 	delete _logic;
@@ -221,7 +224,9 @@
 }
 
 int32 Sword2Engine::initialiseGame(void) {
-	// init engine drivers
+	// During normal gameplay, we care neither about mouse button releases
+	// nor the scroll wheel.
+	setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
 
 	// initialise global script variables
 	// res 1 is the globals list
@@ -258,6 +263,101 @@
 	_quit = true;
 }
 
+bool Sword2Engine::checkForMouseEvents(void) {
+	return _mouseEvent.pending;
+}
+
+MouseEvent *Sword2Engine::mouseEvent(void) {
+	if (!_mouseEvent.pending)
+		return NULL;
+
+	_mouseEvent.pending = false;
+	return &_mouseEvent;
+}
+
+KeyboardEvent *Sword2Engine::keyboardEvent(void) {
+	if (!_keyboardEvent.pending)
+		return NULL;
+
+	_keyboardEvent.pending = false;
+	return &_keyboardEvent;
+}
+
+uint32 Sword2Engine::setEventFilter(uint32 filter) {
+	uint32 oldFilter = _eventFilter;
+
+	_eventFilter = filter;
+	return oldFilter;
+}
+
+/**
+ * OSystem Event Handler. Full of cross platform goodness and 99% fat free!
+ */
+
+void Sword2Engine::parseEvents(void) {
+	OSystem::Event event;
+	
+	while (_system->poll_event(&event)) {
+		switch (event.event_code) {
+		case OSystem::EVENT_KEYDOWN:
+			if (!(_eventFilter & RD_KEYDOWN)) {
+				_keyboardEvent.pending = true;
+				_keyboardEvent.ascii = event.kbd.ascii;
+				_keyboardEvent.keycode = event.kbd.keycode;
+				_keyboardEvent.modifiers = event.kbd.flags;
+			}
+			break;
+		case OSystem::EVENT_MOUSEMOVE:
+			if (!(_eventFilter & RD_KEYDOWN)) {
+				_mouseX = event.mouse.x;
+				_mouseY = event.mouse.y - RDMENU_MENUDEEP;
+			}
+			break;
+		case OSystem::EVENT_LBUTTONDOWN:
+			if (!(_eventFilter & RD_LEFTBUTTONDOWN)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_LEFTBUTTONDOWN;
+			}
+			break;
+		case OSystem::EVENT_RBUTTONDOWN:
+			if (!(_eventFilter & RD_RIGHTBUTTONDOWN)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_RIGHTBUTTONDOWN;
+			}
+			break;
+		case OSystem::EVENT_LBUTTONUP:
+			if (!(_eventFilter & RD_LEFTBUTTONUP)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_LEFTBUTTONUP;
+			}
+			break;
+		case OSystem::EVENT_RBUTTONUP:
+			if (!(_eventFilter & RD_RIGHTBUTTONUP)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_RIGHTBUTTONUP;
+			}
+			break;
+		case OSystem::EVENT_WHEELUP:
+			if (!(_eventFilter & RD_WHEELUP)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_WHEELUP;
+			}
+			break;
+		case OSystem::EVENT_WHEELDOWN:
+			if (!(_eventFilter & RD_WHEELDOWN)) {
+				_mouseEvent.pending = true;
+				_mouseEvent.buttons = RD_WHEELDOWN;
+			}
+			break;
+		case OSystem::EVENT_QUIT:
+			closeGame();
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 void Sword2Engine::gameCycle(void) {
 	// do one game cycle
 
@@ -290,8 +390,6 @@
 }
 
 void Sword2Engine::go() {
-	KeyboardEvent ke;
-
 	_quit = false;
 
 	debug(5, "CALLING: readOptionSettings");
@@ -354,13 +452,13 @@
 		}
 #endif
 
-		if (_input->keyWaiting()) {
-			_input->readKey(&ke);
+		KeyboardEvent *ke = keyboardEvent();
 
-			if ((ke.modifiers == OSystem::KBD_CTRL && ke.keycode == 'd') || ke.ascii == '#' || ke.ascii == '~') {
+		if (ke) {
+			if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
 				_debugger->attach();
-			} else if (ke.modifiers == 0 || ke.modifiers == OSystem::KBD_SHIFT) {
-				switch (ke.keycode) {
+			} else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
+				switch (ke->keycode) {
 				case 'p':
 					if (_gamePaused)
 						unpauseGame();

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- sword2.h	1 May 2004 10:42:22 -0000	1.61
+++ sword2.h	9 May 2004 13:32:04 -0000	1.62
@@ -50,8 +50,37 @@
 class Gui;
 class Debugger;
 
+enum {
+	RD_LEFTBUTTONDOWN		= 0x01,
+	RD_LEFTBUTTONUP			= 0x02,
+	RD_RIGHTBUTTONDOWN		= 0x04,
+	RD_RIGHTBUTTONUP		= 0x08,
+	RD_WHEELUP			= 0x10,
+	RD_WHEELDOWN			= 0x20,
+	RD_KEYDOWN			= 0x40,
+	RD_MOUSEMOVE			= 0x80
+};
+
+struct MouseEvent {
+	bool pending;
+	uint16 buttons;
+};
+
+struct KeyboardEvent {
+	bool pending;
+	uint16 ascii;
+	int keycode;
+	int modifiers;
+};
+
 class Sword2Engine : public Engine {
 private:
+	uint32 _eventFilter;
+
+	// The event "buffers"
+	MouseEvent _mouseEvent;
+	KeyboardEvent _keyboardEvent;
+
 	uint32 _bootParam;
 	int32 _saveSlot;
 
@@ -146,7 +175,6 @@
 
 	MemoryManager *_memory;
 	ResourceManager	*_resman;
-	Input *_input;
 	Sound *_sound;
 	Graphics *_graphics;
 	Logic *_logic;
@@ -161,6 +189,17 @@
 	uint32 _controlsFontId;
 	uint32 _redFontId;
 
+	int16 _mouseX;
+	int16 _mouseY;
+
+	uint32 setEventFilter(uint32 filter);
+
+	void parseEvents(void);
+
+	bool checkForMouseEvents(void);
+	MouseEvent *mouseEvent(void);
+	KeyboardEvent *keyboardEvent(void);
+
 	void resetRenderLists(void);
 	void buildDisplay(void);
 	void displayMsg(byte *text, int time);





More information about the Scummvm-git-logs mailing list