Commit Graph

29 Commits

Author SHA1 Message Date
Jean Raby
65d41e7b37 joynums.fill(false); 2022-02-18 16:12:19 -05:00
Jean Raby
38b1e495ea Move joystick + related functions under JoyDevices 2022-02-18 15:43:52 -05:00
Jean Raby
e1685b05eb range-based for loops + simplify joynum assignment 2022-02-18 11:08:20 -05:00
Jean Raby
cdbf783fc4 gtk: Support adding/removing joysticks at runtime
Reworked how/where SDL events are polled:
  - poll_joystick_events is now a static member of JoyDevice so it can be
    called from outside when needed (preference window for config and
    caliration).
  - S9xProcessEvents calls JoyDevice::poll_joystick_events directly so
    events are polled when no joysticks are attached.
  - JoyDevice::poll_joystick_events handles SDL_JOYDEVICE{ADDED,REMOVED}
    events.
  - Individual JoyDevice no longer call poll_joystick_events from
    get_events.

Reworked how attached joysticks are maintained in Snes9xConfig:
  - Use a map for joysticks keyed on SDL JoystickID (instance id in sdl
    parlance), which is stable while a joystick is attached instead of
    an array keyed on device_index.
    The instance id is what poll_joystick_events gets with every
    event (except for SDL_JOYDEVICEADDED which gets a device_index...)
    Instance id is an incrementing int starting from 0, they are never reused.
    i.e. each attach/dettach/attach cycle yields a new id.
    Whereas device index are reused and can "move".
  - On SDL_JOYDEVICEADDED the joystick is handed a "joynum", that is, an
    int from 0 to NUM_JOYPADS-1. A new joystick always get the lowest
    available joynum.
    (joynum was already a member of JoyDevice but wasn't initialized,
    this seemed like a proper way to use it.)
  - On SDL_JOYDEVICEREMOVED, the joystick associated with the instance
    id is simply removed from the map.

All this allows for the following behaviors.
It is possible to start without any joystick, add one joystick and it works.
(disconnect/reconnect cycles with a single joystick also work)

Joystick numbers are "stable" while they remain connected. For example:
 - Start with joystick0 and joystick1 connected
 - if joystick0 is disconnected, joystick1 keeps its number and keeps
   working
 - if joystick0 (or any new joystick) is connected at this time,
   it gets to become joystick0

If all joysticks are disconnected while snes9x is running, the order of
the "reconnections" will determine the joystick number of each joystick.

I think there is room for improvement still, with regards to code
organization. For instance, there could be a "JoyDevices" class which
would handle all the attached JoyDevice. This would allow moving all the
"joystick_*" methods from Snes9xConfig to that new class, and
poll_joystick_events could also be moved there.
The functionality wouldn't change, but the intent/ownership would probably be clearer.
2022-02-17 11:02:53 -05:00
Brandon Wright
e17ff69533 Gtk: Switch codebase to gtkmm.
GTK: Remove support for GTK+ 2.0.

GTK 3 is stable and widespread enough now.

GTK: Rearrange headers to eliminate gtk_s9xcore.h

Gtk: Initial gtkmm conversion work.

Gtk: More gtkmm conversion and bug fixing.

Gtk: More gtkmm fixes.

Gtk: More Fixes

OpenGL no longer creates a second window.
Accelerators are fixed.

Gtk: More fixes

Removed GLX context dependency on Gtk.

Gtk: Fix formatting.

Gtk: Remove a #pragma once
2020-07-17 14:48:34 -05:00
Brandon Wright
c3388602bb gtk: Undef vector and bool after SDL.h 2019-07-16 11:16:10 -05:00
Brandon Wright
f8a0fadfa1 GTK: Use C++ memory allocation. 2019-05-14 15:34:25 -05:00
Brandon Wright
92f2a9510f GTK: In mouse-grab mode, accumulate partial pixels. 2019-03-02 16:10:00 -06:00
Brandon Wright
fcdead0028 GTK+: Use lowercase true/false, bool in more places. 2018-12-28 17:07:32 -06:00
Brandon Wright
c21539d269 GTK+: Mandate Netplay, Joystick, JMA. 2018-12-03 17:32:12 -06:00
Brandon Wright
f0ddb097f9 Mark all of GTK+ with header stub, and a couple others. 2018-11-15 17:42:29 -06:00
Brandon Wright
54a3d41d61 GTK+: Implement a different overlay font.
It's the same font, but with kerning added and the black outline
replaced with a translucent background.
2018-11-15 17:03:49 -06:00
Brandon Wright
8c7b326254 GTK+: Add hotkey to capture the mouse. 2018-11-08 14:23:37 -06:00
Brandon Wright
cadffa0073 GTK+: Relative save slots. 2018-11-06 16:39:23 -06:00
Brandon Wright
c5038bc9fe GTK+/style: Remove explicit returns in void funcs. 2018-11-02 16:48:20 -05:00
Brandon Wright
61d691a523 GTK+: Clean up control stuff a bit. 2018-11-02 15:27:12 -05:00
Brandon Wright
602919d522 GTK+: Don't override command-line port choice. 2018-10-03 16:58:40 -05:00
Brandon Wright
95ee47ac06 Use port commands for quickload to allow undo. 2018-06-21 14:23:43 -05:00
Brandon Wright
c555b07846 Translate mouse coordinates correctly in hidpi modes. Hide cursor when SuperScope enabled. 2018-05-23 15:50:57 -05:00
Brandon Wright
a42498b161 Fix a bunch of warnings. 2018-05-13 20:19:21 -05:00
Brandon Wright
7411df6c73 Make rewinding and bilinear filtering global Snes9x settings. 2018-05-13 17:31:25 -05:00
Brandon Wright
b7a2486ace List enumerated joysticks in terminal output. 2017-11-30 18:38:09 -06:00
Brandon Wright
2eaac353ba Bump SDL requirement to SDL 2.0. 2017-11-23 18:57:47 -06:00
Yamashita Ren
5519a00241 GTK: Add a 10th save slot (Slot 9).
Reorganizing save slots section of snes9x.ui while I'm at it.
2017-04-25 21:45:30 +02:00
Brandon Wright
5dd5d9ba74 Fix tabulation glitch with rewind shortcut box. 2016-10-08 21:19:04 -05:00
Juha Laukkanen
118544e8ac Use of rewind feature (stateman) with GTK. 2014-06-27 08:36:36 +00:00
Brandon Wright
7c39cc34ba Fix some compiler warnings. 2014-02-05 03:22:07 -06:00
Brandon Wright
31f45619a5 Import of GTK port changes. 2010-09-26 04:19:15 -05:00
OV2
d1666860e0 Initial 1.52 import 2010-09-25 17:46:12 +02:00