Path: blob/master/libsnes/lsnes_patches/0004-Fix-mouse-polling.patch
2 views
From 160dedf35571478781737ee35307b9321cfb41bb Mon Sep 17 00:00:00 20011From: Ilari Liusvaara <[email protected]>2Date: Wed, 7 Mar 2012 16:57:18 +02003Subject: [PATCH 4/4] Fix mouse polling45Don't poll for mouse motion excessive number of times (no need to poll it for6each bit!)7---8snes/controller/mouse/mouse.cpp | 12 ++++++++++--9snes/controller/mouse/mouse.hpp | 2 ++102 files changed, 12 insertions(+), 2 deletions(-)1112diff --git a/snes/controller/mouse/mouse.cpp b/snes/controller/mouse/mouse.cpp13index 6b26fae..824ecd3 10075514--- snes/controller/mouse/mouse.cpp15+++ snes/controller/mouse/mouse.cpp16@@ -3,8 +3,10 @@17uint2 Mouse::data() {18if(counter >= 32) return 1;1920- int position_x = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::X); //-n = left, 0 = center, +n = right21- int position_y = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::Y); //-n = up, 0 = center, +n = down22+ if(counter == 0) {23+ position_x = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::X); //-n = left, 0 = center, +n = right24+ position_y = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::Y); //-n = up, 0 = center, +n = down25+ }2627bool direction_x = position_x < 0; //0 = right, 1 = left28bool direction_y = position_y < 0; //0 = down, 1 = up29@@ -67,10 +69,16 @@ void Mouse::serialize(serializer& s) {30unsigned char block[Controller::SaveSize] = {0};31block[0] = latched ? 1 : 0;32block[1] = counter;33+ block[2] = (unsigned short)position_x >> 8;34+ block[3] = (unsigned short)position_x;35+ block[4] = (unsigned short)position_y >> 8;36+ block[5] = (unsigned short)position_y;37s.array(block, Controller::SaveSize);38if(s.mode() == nall::serializer::Load) {39latched = (block[0] != 0);40counter = block[1];41+ position_x = (short)(((unsigned short)block[2] << 8) | (unsigned short)block[3]);42+ position_y = (short)(((unsigned short)block[4] << 8) | (unsigned short)block[5]);43}44}4546diff --git a/snes/controller/mouse/mouse.hpp b/snes/controller/mouse/mouse.hpp47index b66ea51..6074f34 10075548--- snes/controller/mouse/mouse.hpp49+++ snes/controller/mouse/mouse.hpp50@@ -6,4 +6,6 @@ struct Mouse : Controller {51private:52bool latched;53unsigned counter;54+ int position_x;55+ int position_y;56};57--581.7.9.48.g85da4d59606162