@@ -229,88 +229,83 @@ void usb_device_guncon3::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint,
229229 GunCon3_data gc{};
230230 gc.stick_ax = gc.stick_ay = gc.stick_bx = gc.stick_by = 0x7f ;
231231
232- if (auto * wm = WiimoteManager::get_instance ())
233- {
234- auto states = wm->get_states ();
232+ auto * wm = wiimote_manager::get_instance ()
233+ auto states = wm->get_states ();
235234
236- // Determine which Wiimote to use based on our ordinal position among all GunCons
237- int my_wiimote_index = -1 ;
235+ // Determine which Wiimote to use based on our ordinal position among all GunCons
236+ int my_wiimote_index = -1 ;
237+ {
238+ std::lock_guard lock (s_instances_mutex);
239+ // Since we sort by pointer adress/controller_index in add, and search by this ptr
240+ // Actually lower_bound needs a value. std::find is safer for pointer identity.
241+ auto found = std::find (s_instances.begin (), s_instances.end (), this );
242+ if (found != s_instances.end ())
238243 {
239- std::lock_guard lock (s_instances_mutex);
240- auto it = std::lower_bound (s_instances.begin (), s_instances.end (), this , [](auto * a, auto * b) {
241- return a->m_controller_index < b->m_controller_index ;
242- });
243- // Since we sort by pointer adress/controller_index in add, and search by this ptr
244- // Actually lower_bound needs a value. std::find is safer for pointer identity.
245- auto found = std::find (s_instances.begin (), s_instances.end (), this );
246- if (found != s_instances.end ())
247- {
248- my_wiimote_index = std::distance (s_instances.begin (), found);
249- }
244+ my_wiimote_index = std::distance (s_instances.begin (), found);
250245 }
246+ }
251247
252- if (my_wiimote_index >= 0 && static_cast <size_t >(my_wiimote_index) < states.size ())
253- {
254- const auto & ws = states[my_wiimote_index];
255- const auto map = wm->get_mapping ();
248+ if (my_wiimote_index >= 0 && static_cast <size_t >(my_wiimote_index) < states.size ())
249+ {
250+ const auto & ws = states[my_wiimote_index];
251+ const auto map = wm->get_mapping ();
256252
257- auto is_pressed = [&](WiimoteButton btn) { return (ws.buttons & static_cast <u16 >(btn)) != 0 ; };
253+ auto is_pressed = [&](wiimote_button btn) { return (ws.buttons & static_cast <u16 >(btn)) != 0 ; };
258254
259- if (is_pressed (map.trigger )) gc.btn_trigger = 1 ;
255+ if (is_pressed (map.trigger )) gc.btn_trigger = 1 ;
260256
261- // Wiimote to GunCon3 Button Mapping
262- if (is_pressed (map.a1 )) gc.btn_a1 = 1 ;
263- if (is_pressed (map.a2 )) gc.btn_a2 = 1 ;
264- if (is_pressed (map.a3 )) gc.btn_a3 = 1 ;
265- if (is_pressed (map.b1 )) gc.btn_b1 = 1 ;
266- if (is_pressed (map.b2 )) gc.btn_b2 = 1 ;
267- if (is_pressed (map.b3 )) gc.btn_b3 = 1 ;
268- if (is_pressed (map.c1 )) gc.btn_c1 = 1 ;
269- if (is_pressed (map.c2 )) gc.btn_c2 = 1 ;
257+ // Wiimote to GunCon3 Button Mapping
258+ if (is_pressed (map.a1 )) gc.btn_a1 = 1 ;
259+ if (is_pressed (map.a2 )) gc.btn_a2 = 1 ;
260+ if (is_pressed (map.a3 )) gc.btn_a3 = 1 ;
261+ if (is_pressed (map.b1 )) gc.btn_b1 = 1 ;
262+ if (is_pressed (map.b2 )) gc.btn_b2 = 1 ;
263+ if (is_pressed (map.b3 )) gc.btn_b3 = 1 ;
264+ if (is_pressed (map.c1 )) gc.btn_c1 = 1 ;
265+ if (is_pressed (map.c2 )) gc.btn_c2 = 1 ;
270266
271- // Secondary / Hardcoded Alts (if kept in mapping struct)
272- if (is_pressed (map.b1_alt )) gc.btn_b1 = 1 ;
273- if (is_pressed (map.b2_alt )) gc.btn_b2 = 1 ;
267+ // Secondary / Hardcoded Alts (if kept in mapping struct)
268+ if (is_pressed (map.b1_alt )) gc.btn_b1 = 1 ;
269+ if (is_pressed (map.b2_alt )) gc.btn_b2 = 1 ;
274270
275- if (ws.ir [0 ].x < 1023 )
271+ if (ws.ir [0 ].x < 1023 )
272+ {
273+ // Only use the primary pointer to avoid jumping between multiple IR points
274+ s32 raw_x = ws.ir [0 ].x ;
275+ s32 raw_y = ws.ir [0 ].y ;
276+
277+ // Map to GunCon3 range (-32768..32767)
278+ // X calculation (Right = 32767, Left = -32768)
279+ s32 x_res = 32767 - (raw_x * 65535 / 1023 );
280+ // Y calculation (Top = 32767, Bottom = -32768)
281+ // Swapping to inverted mapping as per user feedback
282+ s32 y_res = 32767 - (raw_y * 65535 / 767 );
283+
284+ gc.gun_x = static_cast <int16_t >(std::clamp (x_res, -32768 , 32767 ));
285+ gc.gun_y = static_cast <int16_t >(std::clamp (y_res, -32768 , 32767 ));
286+
287+ // Draw the actual GunCon3 output to the overlay
288+ // Mapping GunCon3 range back to virtual_width/height
289+ s16 ax = static_cast <s16>((gc.gun_x + 32768 ) * rsx::overlays::overlay::virtual_width / 65535 );
290+ s16 ay = static_cast <s16>((32767 - gc.gun_y ) * rsx::overlays::overlay::virtual_height / 65535 );
291+
292+ if (g_cfg.io .show_move_cursor )
276293 {
277- // Only use the primary pointer to avoid jumping between multiple IR points
278- s32 raw_x = ws.ir [0 ].x ;
279- s32 raw_y = ws.ir [0 ].y ;
280-
281- // Map to GunCon3 range (-32768..32767)
282- // X calculation (Right = 32767, Left = -32768)
283- s32 x_res = 32767 - (raw_x * 65535 / 1023 );
284- // Y calculation (Top = 32767, Bottom = -32768)
285- // Swapping to inverted mapping as per user feedback
286- s32 y_res = 32767 - (raw_y * 65535 / 767 );
287-
288- gc.gun_x = static_cast <int16_t >(std::clamp (x_res, -32768 , 32767 ));
289- gc.gun_y = static_cast <int16_t >(std::clamp (y_res, -32768 , 32767 ));
290-
291- // Draw the actual GunCon3 output to the overlay
292- // Mapping GunCon3 range back to virtual_width/height
293- s16 ax = static_cast <s16>((gc.gun_x + 32768 ) * rsx::overlays::overlay::virtual_width / 65535 );
294- s16 ay = static_cast <s16>((32767 - gc.gun_y ) * rsx::overlays::overlay::virtual_height / 65535 );
295-
296- if (g_cfg.io .show_move_cursor )
297- {
298- // Use my_wiimote_index for color/cursor selection (0=Red, 1=Green...)
299- rsx::overlays::set_cursor (rsx::overlays::cursor_offset::cell_gem + my_wiimote_index, ax, ay, { 1 .0f , 1 .0f , 1 .0f , 1 .0f }, 100'000 , false );
300- }
301-
302- if (ws.ir [1 ].x < 1023 )
303- {
304- // Calculate "Z" (distance) based on spread of first two points to emulate depth sensor
305- s32 dx = static_cast <s32>(ws.ir [0 ].x ) - ws.ir [1 ].x ;
306- s32 dy = static_cast <s32>(ws.ir [0 ].y ) - ws.ir [1 ].y ;
307- gc.gun_z = static_cast <int16_t >(std::sqrt (dx * dx + dy * dy));
308- }
294+ // Use my_wiimote_index for color/cursor selection (0=Red, 1=Green...)
295+ rsx::overlays::set_cursor (rsx::overlays::cursor_offset::cell_gem + my_wiimote_index, ax, ay, { 1 .0f , 1 .0f , 1 .0f , 1 .0f }, 100'000 , false );
309296 }
310297
311- guncon3_encode (&gc, buf, m_key.data ());
312- return ;
298+ if (ws.ir [1 ].x < 1023 )
299+ {
300+ // Calculate "Z" (distance) based on spread of first two points to emulate depth sensor
301+ s32 dx = static_cast <s32>(ws.ir [0 ].x ) - ws.ir [1 ].x ;
302+ s32 dy = static_cast <s32>(ws.ir [0 ].y ) - ws.ir [1 ].y ;
303+ gc.gun_z = static_cast <int16_t >(std::sqrt (dx * dx + dy * dy));
304+ }
313305 }
306+
307+ guncon3_encode (&gc, buf, m_key.data ());
308+ return ;
314309 }
315310
316311 if (!is_input_allowed ())
0 commit comments