2011-09-14 19:08:43 +00:00
|
|
|
/**
|
|
|
|
** Supermodel
|
|
|
|
** A Sega Model 3 Arcade Emulator.
|
|
|
|
** Copyright 2011 Bart Trzynadlowski, Nik Henson
|
|
|
|
**
|
|
|
|
** This file is part of Supermodel.
|
|
|
|
**
|
|
|
|
** Supermodel is free software: you can redistribute it and/or modify it under
|
2020-07-27 10:28:48 +00:00
|
|
|
** the terms of the GNU General Public License as published by the Free
|
2011-09-14 19:08:43 +00:00
|
|
|
** Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
** any later version.
|
|
|
|
**
|
|
|
|
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
** more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License along
|
|
|
|
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**/
|
2020-07-27 10:28:48 +00:00
|
|
|
|
2011-09-14 19:08:43 +00:00
|
|
|
/*
|
|
|
|
* SDLInputSystem.h
|
2020-07-27 10:28:48 +00:00
|
|
|
*
|
2011-09-14 19:08:43 +00:00
|
|
|
* Header file for SDL input system.
|
|
|
|
*/
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
#ifndef INCLUDED_SDLINPUTSYSTEM_H
|
|
|
|
#define INCLUDED_SDLINPUTSYSTEM_H
|
|
|
|
|
|
|
|
#include "Types.h"
|
|
|
|
#include "Inputs/InputSource.h"
|
|
|
|
#include "Inputs/InputSystem.h"
|
2020-07-27 10:28:48 +00:00
|
|
|
#include "SDLIncludes.h"
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define NUM_SDL_KEYS (sizeof(s_keyMap) / sizeof(SDLKeyMapStruct))
|
|
|
|
|
|
|
|
struct SDLKeyMapStruct
|
|
|
|
{
|
|
|
|
const char *keyName;
|
2020-04-19 08:34:58 +00:00
|
|
|
SDL_Scancode sdlKey;
|
2011-04-24 01:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Input system that uses SDL.
|
|
|
|
*/
|
|
|
|
class CSDLInputSystem : public CInputSystem
|
|
|
|
{
|
|
|
|
private:
|
2020-10-21 08:19:51 +00:00
|
|
|
const Util::Config::Node& m_config;
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
// Lookup table to map key names to SDLKeys
|
|
|
|
static SDLKeyMapStruct s_keyMap[];
|
|
|
|
|
|
|
|
// Vector to keep track of attached joysticks
|
2020-09-16 07:03:03 +00:00
|
|
|
std::vector<SDL_Joystick*> m_joysticks;
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2011-06-05 20:53:39 +00:00
|
|
|
// Vector of joystick details
|
2020-09-16 07:03:03 +00:00
|
|
|
std::vector<JoyDetails> m_joyDetails;
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
// Current key state obtained from SDL
|
2020-04-19 08:34:58 +00:00
|
|
|
const Uint8 *m_keyState;
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
// Current mouse state obtained from SDL
|
|
|
|
int m_mouseX;
|
|
|
|
int m_mouseY;
|
|
|
|
int m_mouseZ;
|
|
|
|
short m_mouseWheelDir;
|
|
|
|
Uint8 m_mouseButtons;
|
|
|
|
|
2020-10-21 08:19:51 +00:00
|
|
|
// SDL2 ffb
|
|
|
|
SDL_HapticEffect eff;
|
|
|
|
unsigned sdlConstForceMax;
|
|
|
|
unsigned sdlSelfCenterMax;
|
|
|
|
unsigned sdlFrictionMax;
|
|
|
|
unsigned sdlVibrateMax;
|
|
|
|
struct hapticInfo
|
|
|
|
{
|
|
|
|
SDL_Haptic* SDLhaptic = NULL;
|
|
|
|
int effectConstantForceID = -1;
|
|
|
|
int effectVibrationID = -1;
|
|
|
|
int effectSpringForceID = -1;
|
|
|
|
int effectFrictionForceID = -1;
|
|
|
|
};
|
|
|
|
std::vector<hapticInfo> m_SDLHapticDatas;
|
|
|
|
|
2020-07-27 10:28:48 +00:00
|
|
|
/*
|
2011-04-24 01:14:00 +00:00
|
|
|
* Opens all attached joysticks.
|
|
|
|
*/
|
|
|
|
void OpenJoysticks();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Closes all attached joysticks.
|
|
|
|
*/
|
|
|
|
void CloseJoysticks();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/*
|
|
|
|
* Initializes the SDL input system.
|
|
|
|
*/
|
|
|
|
bool InitializeSystem();
|
|
|
|
|
|
|
|
int GetKeyIndex(const char *keyName);
|
|
|
|
|
|
|
|
const char *GetKeyName(int keyIndex);
|
|
|
|
|
|
|
|
bool IsKeyPressed(int kbdNum, int keyIndex);
|
|
|
|
|
|
|
|
int GetMouseAxisValue(int mseNum, int axisNum);
|
2020-07-27 10:28:48 +00:00
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
int GetMouseWheelDir(int mseNum);
|
|
|
|
|
|
|
|
bool IsMouseButPressed(int mseNum, int butNum);
|
|
|
|
|
|
|
|
int GetJoyAxisValue(int joyNum, int axisNum);
|
|
|
|
|
|
|
|
bool IsJoyPOVInDir(int joyNum, int povNum, int povDir);
|
|
|
|
|
|
|
|
bool IsJoyButPressed(int joyNum, int butNum);
|
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
bool ProcessForceFeedbackCmd(int joyNum, int axisNum, ForceFeedbackCmd ffCmd);
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2020-10-21 08:19:51 +00:00
|
|
|
void StopAllEffect(int joyNum);
|
|
|
|
|
|
|
|
void StopConstanteforce(int joyNum);
|
|
|
|
|
|
|
|
void StopVibrationforce(int joyNum);
|
|
|
|
|
|
|
|
void StopSpringforce(int joyNum);
|
|
|
|
|
|
|
|
void StopFrictionforce(int joyNum);
|
|
|
|
|
|
|
|
void VibrationEffect(float strength, int joyNum);
|
|
|
|
|
|
|
|
void ConstantForceEffect(float force, int dir, int length, int joyNum);
|
|
|
|
|
|
|
|
void SpringForceEffect(float force, int joyNum);
|
|
|
|
|
|
|
|
void FrictionForceEffect(float force, int joyNum);
|
|
|
|
|
|
|
|
bool HasBasicForce(SDL_Haptic* hap);
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Constructs an SDL input system.
|
|
|
|
*/
|
2020-10-21 08:19:51 +00:00
|
|
|
CSDLInputSystem(const Util::Config::Node& config);
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
~CSDLInputSystem();
|
|
|
|
|
2020-07-27 10:28:48 +00:00
|
|
|
int GetNumKeyboards();
|
2011-06-05 20:53:39 +00:00
|
|
|
|
|
|
|
int GetNumMice();
|
2020-07-27 10:28:48 +00:00
|
|
|
|
2011-06-05 20:53:39 +00:00
|
|
|
int GetNumJoysticks();
|
|
|
|
|
|
|
|
const KeyDetails *GetKeyDetails(int kbdNum);
|
|
|
|
|
|
|
|
const MouseDetails *GetMouseDetails(int mseNum);
|
|
|
|
|
|
|
|
const JoyDetails *GetJoyDetails(int joyNum);
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
bool Poll();
|
2011-06-05 20:53:39 +00:00
|
|
|
|
|
|
|
void SetMouseVisibility(bool visible);
|
2011-04-24 01:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_SDLINPUTSYSTEM_H
|