OSDN Git Service

[Qt][OSD][MOUSE] Lock values via accessing.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 21 May 2020 13:33:47 +0000 (22:33 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 21 May 2020 13:33:47 +0000 (22:33 +0900)
source/src/qt/osd_base.cpp
source/src/qt/osd_base.h
source/src/qt/osd_input.cpp
source/src/vm/fmtowns/joystick.cpp

index 43e6c96..38e45a7 100644 (file)
@@ -49,6 +49,8 @@ OSD_BASE::OSD_BASE(USING_FLAGS *p, CSP_Logger *logger) : QThread(0)
        vm_mutex = new QMutex(QMutex::Recursive);
        locked_vm = false;
        screen_mutex = new QMutex(QMutex::Recursive);
+       mouse_mutex = new QMutex(QMutex::Recursive);
+       
        device_node_list.clear();
        max_vm_nodes = 0;
        p_logger = logger;
@@ -67,6 +69,7 @@ OSD_BASE::OSD_BASE(USING_FLAGS *p, CSP_Logger *logger) : QThread(0)
 
 OSD_BASE::~OSD_BASE()
 {
+       delete mouse_mutex;
        delete vm_mutex;
        delete screen_mutex;
 }
index 6a15686..a96eded 100644 (file)
@@ -363,6 +363,7 @@ public:
        QMutex *screen_mutex;
        QMutex *vm_mutex;
        QMutex *debug_mutex;
+       QMutex *mouse_mutex;
        
        int host_cpus;
        bool now_auto_key;
index 0d99eff..5d55154 100644 (file)
@@ -10,6 +10,8 @@
 #include <Qt>
 #include <QApplication>
 #include <SDL.h>
+#include <QMutex>
+#include <QMutexLocker>
 
 //#include "../emu.h"
 #include "../fifo.h"
@@ -257,9 +259,12 @@ void OSD_BASE::update_input()
        memset(mouse_status, 0, sizeof(mouse_status));
        //bool hid = false;
        if(mouse_enabled) {
+               QMutexLocker n(mouse_mutex);
                mouse_status[0] = delta_x;
                mouse_status[1] = delta_y; 
                mouse_status[2] = mouse_button;
+               mouse_oldx = mouse_ptrx;
+               mouse_oldy = mouse_ptry;
                //printf("Mouse delta(%d, %d)\n", delta_x, delta_y);
                delta_x = delta_y = 0;
        }
@@ -766,6 +771,7 @@ uint32_t* OSD_BASE::get_joy_buffer()
 
 int32_t* OSD_BASE::get_mouse_buffer()
 {
+       QMutexLocker n(mouse_mutex);
        return mouse_status;
 }
 
@@ -789,6 +795,7 @@ void OSD_BASE::enable_mouse()
 {
        // enable mouse emulation
        if(!mouse_enabled) {
+               QMutexLocker n(mouse_mutex);
                mouse_oldx = mouse_ptrx = get_screen_width() / 2;
                mouse_oldy = mouse_ptry = get_screen_height() / 2;
                delta_x = 0;
@@ -828,24 +835,25 @@ bool OSD_BASE::is_mouse_enabled()
 void OSD_BASE::set_mouse_pointer(int x, int y)
 {
        if(mouse_enabled) {
-               int32_t dw = get_screen_width();
-               int32_t dh = get_screen_height();
+               QMutexLocker n(mouse_mutex);
+//             int32_t dw = get_screen_width();
+//             int32_t dh = get_screen_height();
                mouse_ptrx = x;
                mouse_ptry = y;
-               //delta_x = x - (dw / 2);
-               //delta_y = y - (dh / 2);
+//             delta_x = x - (dw / 2);
+//             delta_y = y - (dh / 2);
                delta_x += (mouse_ptrx - mouse_oldx);
                delta_y += (mouse_ptry - mouse_oldy);
-/*             if(delta_x > (dw / 2)) {
-                       delta_x = dw / 2;
-               } else if(delta_x < -(dw / 2)) {
-                       delta_x = -dw / 2;
-               }
-               if(delta_y > (dh / 2)) {
-                       delta_y = dh / 2;
-               } else if(delta_y < -(dh / 2)) {
-                       delta_y = -dh / 2;
-                       }*/
+//             if(delta_x > (dw / 2)) {
+//                     delta_x = dw / 2;
+//             } else if(delta_x < -(dw / 2)) {
+//                     delta_x = -dw / 2;
+//             }
+//             if(delta_y > (dh / 2)) {
+//                     delta_y = dh / 2;
+//             } else if(delta_y < -(dh / 2)) {
+//                     delta_y = -dh / 2;
+//             }
                mouse_oldx = mouse_ptrx;
                mouse_oldy = mouse_ptry;
                //printf("Mouse Moved: (%d, %d) -> delta(%d, %d)\n", mouse_ptrx, mouse_ptry, delta_x, delta_y);
@@ -854,11 +862,13 @@ void OSD_BASE::set_mouse_pointer(int x, int y)
 
 void OSD_BASE::set_mouse_button(int button) 
 {
+       QMutexLocker n(mouse_mutex);
        mouse_button = button;
 }
 
 int OSD_BASE::get_mouse_button() 
 {
+       QMutexLocker n(mouse_mutex);
        return mouse_button;
 }
 
index 2c025ff..3dc4455 100644 (file)
@@ -34,7 +34,7 @@ void JOYSTICK::reset()
        if(mouse_sampling_event >= 0) {
                cancel_event(this, mouse_sampling_event);
        }
-//     register_event(this, EVENT_MOUSE_SAMPLING, 16.0e3, true, &mouse_sampling_event);
+//     register_event(this, EVENT_MOUSE_SAMPLING, 8.0e3, true, &mouse_sampling_event);
 }
 
 void JOYSTICK::initialize()
@@ -50,7 +50,6 @@ void JOYSTICK::initialize()
        set_emulate_mouse();
        mouse_type = config.mouse_type;
        register_frame_event(this);
-       
 }
 
 void JOYSTICK::release()