Don't initialize and manage joysticks in SDLmain
Two notable changes: 1. Eliminates the joystick setup from SDLmain, allowing the mapper's QueryJoysticks() function to be the sole setup and configuration point for both the SDL Joystick subsystem and DOSBox's internal configuration of the joysticks. 2. SDLmain's event loop previously perform some joystick- specific timing and always called the Mapper's UpdateJoysticks function; neither of which are needed if the user has disabled joystick support or if joysticks aren't physically present. This update now make this entire process conditional on both of the latter (which is set by the Mapper's QueryJoysticks).
This commit is contained in:
parent
5b587d490f
commit
5287559aee
3 changed files with 19 additions and 21 deletions
|
@ -36,7 +36,8 @@ void MAPPER_BindKeys();
|
|||
void MAPPER_StartUp(Section * sec);
|
||||
void MAPPER_Run(bool pressed);
|
||||
void MAPPER_DisplayUI();
|
||||
void MAPPER_LosingFocus(void);
|
||||
void MAPPER_LosingFocus();
|
||||
bool MAPPER_IsUsingJoysticks();
|
||||
std::vector<std::string> MAPPER_GetEventNames(const std::string &prefix);
|
||||
void MAPPER_AutoType(std::vector<std::string> &sequence,
|
||||
const uint32_t wait_ms,
|
||||
|
|
|
@ -2500,9 +2500,10 @@ void BIND_MappingEvents() {
|
|||
/**
|
||||
* Queries SDL's joysticks and sets joytype accordingly.
|
||||
* If no joysticks are valid then joytype is left at JOY_NONE.
|
||||
* Also resets mapper.sticks.num_groups to 0 and
|
||||
* mapper.sticks.num to the number of found SDL joysticks.
|
||||
*/
|
||||
* Also resets mapper.sticks.num_groups to 0, mapper.sticks.num
|
||||
* to the number of found SDL joysticks, and enables the boolean
|
||||
* joysticks_active if joystick support is enabled and are present.
|
||||
*/
|
||||
static void QueryJoysticks() {
|
||||
// Initialize SDL's Joystick and Event subsystems, if needed
|
||||
if (SDL_WasInit(SDL_INIT_JOYSTICK) != SDL_INIT_JOYSTICK)
|
||||
|
@ -2597,6 +2598,10 @@ static void CreateBindGroups() {
|
|||
}
|
||||
}
|
||||
|
||||
bool MAPPER_IsUsingJoysticks() {
|
||||
return (mapper.sticks.num > 0);
|
||||
}
|
||||
|
||||
#if defined (REDUCE_JOYSTICK_POLLING)
|
||||
void MAPPER_UpdateJoysticks() {
|
||||
for (Bitu i=0; i<mapper.sticks.num_groups; i++) {
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "cross.h"
|
||||
#include "video.h"
|
||||
#include "mouse.h"
|
||||
#include "joystick.h"
|
||||
#include "pic.h"
|
||||
#include "timer.h"
|
||||
#include "setup.h"
|
||||
|
@ -62,7 +63,6 @@
|
|||
#include "../libs/ppscale/ppscale.h"
|
||||
|
||||
#define MAPPERFILE "mapper-sdl2-" VERSION ".map"
|
||||
//#define DISABLE_JOYSTICK
|
||||
|
||||
#if C_OPENGL
|
||||
//Define to disable the usage of the pixel buffer object
|
||||
|
@ -344,7 +344,6 @@ struct SDL_Block {
|
|||
int ppscale_x, ppscale_y; /* x and y scales for pixel-perfect */
|
||||
bool double_h, double_w; /* double-height and double-width flags */
|
||||
SDL_Rect updateRects[1024];
|
||||
Bitu num_joysticks;
|
||||
#if defined (WIN32)
|
||||
// Time when sdl regains focus (alt-tab) in windowed mode
|
||||
Bit32u focus_ticks;
|
||||
|
@ -2457,12 +2456,14 @@ void GFX_Events() {
|
|||
|
||||
SDL_Event event;
|
||||
#if defined (REDUCE_JOYSTICK_POLLING)
|
||||
static int poll_delay = 0;
|
||||
int time = GetTicks();
|
||||
if (time - poll_delay > 20) {
|
||||
poll_delay = time;
|
||||
if (sdl.num_joysticks > 0) SDL_JoystickUpdate();
|
||||
MAPPER_UpdateJoysticks();
|
||||
if (MAPPER_IsUsingJoysticks()) {
|
||||
static int poll_delay = 0;
|
||||
int time = GetTicks();
|
||||
if (time - poll_delay > 20) {
|
||||
poll_delay = time;
|
||||
SDL_JoystickUpdate();
|
||||
MAPPER_UpdateJoysticks();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
@ -3151,18 +3152,9 @@ int main(int argc, char* argv[]) {
|
|||
// Once initialized, ensure we clean up SDL for all exit conditions
|
||||
atexit(SDL_Quit);
|
||||
|
||||
#ifndef DISABLE_JOYSTICK
|
||||
//Initialise Joystick separately. This way we can warn when it fails instead
|
||||
//of exiting the application
|
||||
if( SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0 )
|
||||
LOG_MSG("Failed to init joystick support");
|
||||
#endif
|
||||
|
||||
sdl.laltstate = SDL_KEYUP;
|
||||
sdl.raltstate = SDL_KEYUP;
|
||||
|
||||
sdl.num_joysticks=SDL_NumJoysticks();
|
||||
|
||||
CROSS_DetermineConfigPaths();
|
||||
|
||||
/* Parse configuration files */
|
||||
|
|
Loading…
Add table
Reference in a new issue