1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Begin joystick code refactor; some related cleanups and unused code removal

This commit is contained in:
fgenesis 2016-06-25 23:59:34 +02:00
parent 4534b68fc5
commit a7c2d054a2
14 changed files with 102 additions and 254 deletions

View file

@ -350,10 +350,6 @@ bool AquariaSlider::doSliderInput(float dt)
inputAmount = -0.1f; inputAmount = -0.1f;
else if (core->joystick.position.x >= SLIDER_JOY_THRESHOLD) else if (core->joystick.position.x >= SLIDER_JOY_THRESHOLD)
inputAmount = +0.1f; inputAmount = +0.1f;
else if (core->joystick.dpadLeft)
inputAmount = -0.1f;
else if (core->joystick.dpadRight)
inputAmount = +0.1f;
else if (obj && obj->isActing(ACTION_MENULEFT)) else if (obj && obj->isActing(ACTION_MENULEFT))
inputAmount = -0.1f; inputAmount = -0.1f;
else if (obj && obj->isActing(ACTION_MENURIGHT)) else if (obj && obj->isActing(ACTION_MENURIGHT))
@ -675,7 +671,7 @@ void AquariaKeyConfig::onUpdate(float dt)
} }
else else
{ {
for (int i = ActionMapper::JOY1_BUTTON_0; i <= ActionMapper::JOY1_BUTTON_16; i++) for (int i = ActionMapper::JOY1_BUTTON_0; i <= MAX_JOYSTICK_BTN; i++)
{ {
if (dsq->game->getKeyState(i)) if (dsq->game->getKeyState(i))
{ {

View file

@ -5170,38 +5170,6 @@ bool Avatar::canQuickSong()
return !isSinging() && !isEntityDead() && isInputEnabled() && quickSongCastDelay <= 0; return !isSinging() && !isEntityDead() && isInputEnabled() && quickSongCastDelay <= 0;
} }
void Avatar::updateJoystick(float dt)
{
if (canQuickSong())
{
if (core->joystick.dpadUp)
{
if (dsq->continuity.hasSong(SONG_ENERGYFORM) && dsq->continuity.form != FORM_ENERGY)
{
quickSongCastDelay = QUICK_SONG_CAST_DELAY;
dsq->continuity.castSong(SONG_ENERGYFORM);
}
}
else if (core->joystick.dpadDown && dsq->continuity.hasSong(SONG_BEASTFORM) && dsq->continuity.form != FORM_BEAST)
{
quickSongCastDelay = QUICK_SONG_CAST_DELAY;
dsq->continuity.castSong(SONG_BEASTFORM);
}
else if (core->joystick.dpadLeft && dsq->continuity.hasSong(SONG_SUNFORM) && dsq->continuity.form != FORM_SUN)
{
quickSongCastDelay = QUICK_SONG_CAST_DELAY;
dsq->continuity.castSong(SONG_SUNFORM);
}
else if (core->joystick.dpadRight && dsq->continuity.hasSong(SONG_NATUREFORM) && dsq->continuity.form != FORM_NATURE)
{
quickSongCastDelay = QUICK_SONG_CAST_DELAY;
dsq->continuity.castSong(SONG_NATUREFORM);
}
}
}
void Avatar::applyRidingPosition() void Avatar::applyRidingPosition()
{ {
if (riding) if (riding)
@ -5725,7 +5693,6 @@ void Avatar::onUpdate(float dt)
if (songInterfaceTimer < 1) if (songInterfaceTimer < 1)
songInterfaceTimer += dt; songInterfaceTimer += dt;
} }
updateJoystick(dt);
if (quickSongCastDelay>0) if (quickSongCastDelay>0)
{ {

View file

@ -180,7 +180,6 @@ public:
Vector getKeyDir(); Vector getKeyDir();
void startBurstCommon(); void startBurstCommon();
void updateJoystick(float dt);
void openSingingInterface(); void openSingingInterface();
void closeSingingInterface(); void closeSingingInterface();

View file

@ -1603,12 +1603,6 @@ void DSQ::toggleInputGrabPlat(bool on)
{ {
} }
void DSQ::instantQuit()
{
if (core->getCtrlState() && core->getAltState())
Core::instantQuit();
}
int DSQ::getEntityLayerToLayer(int lcode) int DSQ::getEntityLayerToLayer(int lcode)
{ {
if (lcode == -4) if (lcode == -4)
@ -3970,21 +3964,6 @@ void DSQ::onUpdate(float dt)
if (armb && ActionMapper::getKeyState(armb->joy[0])) if (armb && ActionMapper::getKeyState(armb->joy[0]))
mouse.buttons.right = DOWN; mouse.buttons.right = DOWN;
// not going to happen anymore!
// bye, bye xbox360 controller
if (!mouse.buttons.middle)
{
if (joystick.rightThumb)
mouse.buttons.middle = DOWN;
else if (joystick.leftThumb)
mouse.buttons.middle = DOWN;
}
} }
if (joystickEnabled) if (joystickEnabled)

View file

@ -1486,8 +1486,6 @@ public:
void loadFonts(); void loadFonts();
void instantQuit();
void centerText(const std::string &text); void centerText(const std::string &text);
void centerMessage(const std::string &text, float y=300, int type=0); void centerMessage(const std::string &text, float y=300, int type=0);

View file

@ -6981,28 +6981,6 @@ void Game::bindInput()
addAction(ACTION_TOGGLEGRID, KEY_F9); addAction(ACTION_TOGGLEGRID, KEY_F9);
} }
/*
addAction(ACTION_MENULEFT, KEY_LEFT);
addAction(ACTION_MENURIGHT, KEY_RIGHT);
addAction(ACTION_MENUUP, KEY_UP);
addAction(ACTION_MENUDOWN, KEY_DOWN);
dsq->user.control.actionSet.importAction(this, "SwimLeft", ACTION_MENULEFT);
dsq->user.control.actionSet.importAction(this, "SwimRight", ACTION_MENURIGHT);
dsq->user.control.actionSet.importAction(this, "SwimUp", ACTION_MENUUP);
dsq->user.control.actionSet.importAction(this, "SwimDown", ACTION_MENUDOWN);
addAction(ACTION_MENULEFT, JOY1_DPAD_LEFT);
addAction(ACTION_MENURIGHT, JOY1_DPAD_RIGHT);
addAction(ACTION_MENUUP, JOY1_DPAD_UP);
addAction(ACTION_MENUDOWN, JOY1_DPAD_DOWN);
*/
addAction(ACTION_MENULEFT, JOY1_STICK_LEFT);
addAction(ACTION_MENURIGHT, JOY1_STICK_RIGHT);
addAction(ACTION_MENUUP, JOY1_STICK_UP);
addAction(ACTION_MENUDOWN, JOY1_STICK_DOWN);
// To capture quick song keys via script // To capture quick song keys via script
dsq->user.control.actionSet.importAction(this, "SongSlot1", ACTION_SONGSLOT1); dsq->user.control.actionSet.importAction(this, "SongSlot1", ACTION_SONGSLOT1);
dsq->user.control.actionSet.importAction(this, "SongSlot2", ACTION_SONGSLOT2); dsq->user.control.actionSet.importAction(this, "SongSlot2", ACTION_SONGSLOT2);

View file

@ -20,14 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "UserSettings.h" #include "UserSettings.h"
#ifndef AQUARIA_USERSETTINGS_DATAONLY #include "DSQ.h"
#include "DSQ.h" #include "Game.h"
#include "Game.h" #include "Avatar.h"
#include "Avatar.h"
#else
#include "tinyxml2.h"
using namespace tinyxml2;
#endif
void UserSettings::save() void UserSettings::save()
@ -554,7 +549,6 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
void UserSettings::apply() void UserSettings::apply()
{ {
#ifndef AQUARIA_USERSETTINGS_DATAONLY
core->sound->setMusicVolume(audio.musvol); core->sound->setMusicVolume(audio.musvol);
core->sound->setSfxVolume(audio.sfxvol); core->sound->setSfxVolume(audio.sfxvol);
core->sound->setVoiceVolume(audio.voxvol); core->sound->setVoiceVolume(audio.voxvol);
@ -563,6 +557,7 @@ void UserSettings::apply()
dsq->loops.updateVolume(); dsq->loops.updateVolume();
// FIXME: This should be per-joystick
core->joystick.s1ax = control.s1ax; core->joystick.s1ax = control.s1ax;
core->joystick.s1ay = control.s1ay; core->joystick.s1ay = control.s1ay;
core->joystick.s2ax = control.s2ax; core->joystick.s2ax = control.s2ax;
@ -581,7 +576,5 @@ void UserSettings::apply()
dsq->bindInput(); dsq->bindInput();
core->settings.prebufferSounds = audio.prebuffer; core->settings.prebufferSounds = audio.prebuffer;
#endif
} }

View file

@ -211,52 +211,12 @@ bool ActionMapper::getKeyState(int k)
{ {
keyState = (core->mouse.buttons.middle == DOWN); keyState = (core->mouse.buttons.middle == DOWN);
} }
else if (k >= JOY1_BUTTON_0 && k <= JOY1_BUTTON_16) else if (k >= JOY1_BUTTON_0 && k < JOY1_BUTTON_END)
{ {
int v = k - JOY1_BUTTON_0; int v = k - JOY1_BUTTON_0;
if (core->joystickEnabled) if (core->joystickEnabled)
keyState = core->joystick.buttons[v]; keyState = core->joystick.getButton(v);
}
else if (k == JOY1_STICK_LEFT)
{
keyState = core->joystick.position.x < -0.6f;
}
else if (k == JOY1_STICK_RIGHT)
{
keyState = core->joystick.position.x > 0.6f;
}
else if (k == JOY1_STICK_UP)
{
keyState = core->joystick.position.y < -0.6f;
}
else if (k == JOY1_STICK_DOWN)
{
keyState = core->joystick.position.y > 0.6f;
}
else if (k == X360_BTN_START)
{
keyState = core->joystick.btnStart;
}
else if (k == X360_BTN_BACK)
{
keyState = core->joystick.btnSelect;
}
else if (k == JOY1_DPAD_LEFT)
{
keyState = core->joystick.dpadLeft;
}
else if (k == JOY1_DPAD_RIGHT)
{
keyState = core->joystick.dpadRight;
}
else if (k == JOY1_DPAD_UP)
{
keyState = core->joystick.dpadUp;
}
else if (k == JOY1_DPAD_DOWN)
{
keyState = core->joystick.dpadDown;
} }
return keyState; return keyState;

View file

@ -27,6 +27,7 @@ class Event;
class ActionMapper; class ActionMapper;
#include "ActionSet.h" #include "ActionSet.h"
#include "Joystick.h"
typedef std::vector<int> ButtonList; typedef std::vector<int> ButtonList;
@ -81,46 +82,12 @@ public:
MOUSE_BUTTON_MIDDLE = 1001, MOUSE_BUTTON_MIDDLE = 1001,
JOY1_BUTTON_0 = 2000, JOY1_BUTTON_0 = 2000,
JOY1_BUTTON_1 = 2001, JOY1_BUTTON_END = JOY1_BUTTON_0 + MAX_JOYSTICK_BTN, // one past end
JOY1_BUTTON_2 = 2002,
JOY1_BUTTON_3 = 2003,
JOY1_BUTTON_4 = 2004,
JOY1_BUTTON_5 = 2005,
JOY1_BUTTON_6 = 2006,
JOY1_BUTTON_7 = 2007,
JOY1_BUTTON_8 = 2008,
JOY1_BUTTON_9 = 2009,
JOY1_BUTTON_10 = 2010,
JOY1_BUTTON_11 = 2011,
JOY1_BUTTON_12 = 2012,
JOY1_BUTTON_13 = 2013,
JOY1_BUTTON_14 = 2014,
JOY1_BUTTON_15 = 2015,
JOY1_BUTTON_16 = 2016,
X360_BTN_START = 3016,
X360_BTN_BACK = 3017,
JOY1_DPAD_LEFT = 4000,
JOY1_DPAD_RIGHT = 4001,
JOY1_DPAD_DOWN = 4002,
JOY1_DPAD_UP = 4003,
JOY1_STICK_LEFT = 4010,
JOY1_STICK_RIGHT = 4011,
JOY1_STICK_DOWN = 4012,
JOY1_STICK_UP = 4013,
}; };
enum { DPAD_LEFT = 0, DPAD_RIGHT, DPAD_UP, DPAD_DOWN };
virtual void enableInput(); virtual void enableInput();
virtual void disableInput(); virtual void disableInput();
Event *addCreatedEvent(Event *event); Event *addCreatedEvent(Event *event);
void clearCreatedEvents(); void clearCreatedEvents();

View file

@ -807,7 +807,7 @@ void readKeyData()
bool Core::initJoystickLibrary(int numSticks) bool Core::initJoystickLibrary()
{ {
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
@ -816,13 +816,10 @@ bool Core::initJoystickLibrary(int numSticks)
SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_InitSubSystem(SDL_INIT_JOYSTICK);
#endif #endif
if (numSticks > 0)
joystick.init(0); joystick.init(0);
joystickEnabled = true; joystickEnabled = true;
return true; return true;
} }
@ -2124,8 +2121,6 @@ void Core::pollEvents()
{ {
SDL_Quit(); SDL_Quit();
_exit(0); _exit(0);
} }
} }
break; break;
@ -2141,6 +2136,15 @@ void Core::pollEvents()
} }
} }
break; break;
case SDL_JOYDEVICEADDED:
onJoystickAdded(event.jdevice.which);
break;
case SDL_JOYDEVICEREMOVED:
onJoystickRemoved(event.jdevice.which);
break;
#else #else
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
{ {
@ -3419,3 +3423,11 @@ void Core::initLocalization()
initCharTranslationTables(trans); initCharTranslationTables(trans);
} }
void Core::onJoystickAdded(int deviceID)
{
}
void Core::onJoystickRemoved(int instanceID)
{
}

View file

@ -40,10 +40,10 @@ BUILD_LINUX
#include "DarkLayer.h" #include "DarkLayer.h"
#include "FrameBuffer.h" #include "FrameBuffer.h"
#include "Shader.h" #include "Shader.h"
#include "Joystick.h"
class ParticleEffect; class ParticleEffect;
@ -243,44 +243,6 @@ struct Mouse
int scrollWheel, scrollWheelChange, lastScrollWheel; int scrollWheel, scrollWheelChange, lastScrollWheel;
}; };
const int maxJoyBtns = 64;
class Joystick
{
public:
Joystick();
void init(int stick=0);
void shutdown();
//Ranges from 0 to 65535 (full speed).
void rumble(float leftMotor, float rightMotor, float time);
void update(float dt);
Vector position, lastPosition;
ButtonState buttons[maxJoyBtns];
float deadZone1, deadZone2;
float clearRumbleTime;
void callibrate(Vector &vec, float dead);
float leftTrigger, rightTrigger;
bool leftThumb, rightThumb, leftShoulder, rightShoulder, dpadLeft, dpadRight, dpadUp, dpadDown;
bool btnStart, btnSelect;
Vector rightStick;
bool inited, xinited;
bool anyButton();
# ifdef BBGE_BUILD_SDL2
SDL_GameController *sdl_controller;
SDL_Haptic *sdl_haptic;
# endif
SDL_Joystick *sdl_joy;
#if defined(__LINUX__) && !defined(BBGE_BUILD_SDL2)
int eventfd;
int16_t effectid;
#endif
int stickIndex;
int s1ax, s1ay, s2ax, s2ay;
};
enum FollowCameraLock enum FollowCameraLock
{ {
FCL_NONE = 0, FCL_NONE = 0,
@ -741,13 +703,16 @@ protected:
float baseCullRadius; float baseCullRadius;
bool initSoundLibrary(const std::string &defaultDevice); bool initSoundLibrary(const std::string &defaultDevice);
bool initInputLibrary(); bool initInputLibrary();
bool initJoystickLibrary(int numSticks=1); bool initJoystickLibrary();
bool initGraphicsLibrary(int w, int h, bool fullscreen, int vsync, int bpp, bool recreate=true); bool initGraphicsLibrary(int w, int h, bool fullscreen, int vsync, int bpp, bool recreate=true);
void shutdownInputLibrary(); void shutdownInputLibrary();
void shutdownJoystickLibrary(); void shutdownJoystickLibrary();
void shutdownGraphicsLibrary(bool kill=true); void shutdownGraphicsLibrary(bool kill=true);
void shutdownSoundLibrary(); void shutdownSoundLibrary();
virtual void onJoystickAdded(int deviceID);
virtual void onJoystickRemoved(int instanceID);
int afterEffectManagerLayer; int afterEffectManagerLayer;
Vector cameraOffset; Vector cameraOffset;
std::vector<float> avgFPS; std::vector<float> avgFPS;

View file

@ -42,7 +42,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Joystick::Joystick() Joystick::Joystick()
{ {
xinited = false;
stickIndex = -1; stickIndex = -1;
# ifdef BBGE_BUILD_SDL2 # ifdef BBGE_BUILD_SDL2
sdl_controller = NULL; sdl_controller = NULL;
@ -54,20 +53,11 @@ Joystick::Joystick()
effectid = -1; effectid = -1;
#endif #endif
inited = false; inited = false;
for (int i = 0; i < maxJoyBtns; i++) buttonBitmask = 0;
{
buttons[i] = UP;
}
deadZone1 = 0.3; deadZone1 = 0.3;
deadZone2 = 0.3; deadZone2 = 0.3;
clearRumbleTime= 0; clearRumbleTime= 0;
leftThumb = rightThumb = false;
leftTrigger = rightTrigger = 0;
rightShoulder = leftShoulder = false;
dpadRight = dpadLeft = dpadUp = dpadDown = false;
btnStart = false;
btnSelect = false;
s1ax = 0; s1ax = 0;
s1ay = 1; s1ay = 1;
@ -309,7 +299,11 @@ void Joystick::update(float dt)
if (!SDL_JoystickGetAttached(sdl_joy)) if (!SDL_JoystickGetAttached(sdl_joy))
{ {
debugLog("Lost Joystick"); debugLog("Lost Joystick");
if (sdl_haptic) { SDL_HapticClose(sdl_haptic); sdl_haptic = NULL; } if (sdl_haptic)
{
SDL_HapticClose(sdl_haptic);
sdl_haptic = NULL;
}
if (!sdl_controller) if (!sdl_controller)
SDL_JoystickClose(sdl_joy); SDL_JoystickClose(sdl_joy);
else else
@ -371,27 +365,20 @@ void Joystick::update(float dt)
callibrate(rightStick, deadZone2); callibrate(rightStick, deadZone2);
buttonBitmask = 0;
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
if (sdl_controller) if (sdl_controller)
{ {
for (int i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++) for (unsigned i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++)
buttons[i] = SDL_GameControllerGetButton(sdl_controller, (SDL_GameControllerButton)i)?DOWN:UP; buttonBitmask |= !!SDL_GameControllerGetButton(sdl_controller, (SDL_GameControllerButton)i) << i;
for (int i = SDL_CONTROLLER_BUTTON_MAX; i < maxJoyBtns; i++)
buttons[i] = UP;
} }
else else
{
for (int i = 0; i < maxJoyBtns; i++)
buttons[i] = SDL_JoystickGetButton(sdl_joy, i)?DOWN:UP;
}
#else
for (int i = 0; i < maxJoyBtns; i++)
buttons[i] = SDL_JoystickGetButton(sdl_joy, i)?DOWN:UP;
#endif #endif
{
for (unsigned i = 0; i < MAX_JOYSTICK_BTN; i++)
buttonBitmask |= !!SDL_JoystickGetButton(sdl_joy, i) << i;
}
} }
if (clearRumbleTime >= 0) if (clearRumbleTime >= 0)
@ -402,16 +389,9 @@ void Joystick::update(float dt)
rumble(0,0,0); rumble(0,0,0);
} }
} }
} }
bool Joystick::anyButton() bool Joystick::anyButton()
{ {
for (int i = 0; i < maxJoyBtns; i++) return !!buttonBitmask;;
{
if (buttons[i]) return true;
}
return false;
} }

50
BBGE/Joystick.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef BBGE_JOYSTICK_H
#define BBGE_JOYSTICK_H
#include <SDL_joystick.h>
#include "Vector.h"
#define MAX_JOYSTICK_BTN 32
class Joystick
{
public:
Joystick();
void init(int stick=0);
void shutdown();
//Ranges from 0 to 65535 (full speed).
void rumble(float leftMotor, float rightMotor, float time);
void update(float dt);
Vector position, lastPosition;
float deadZone1, deadZone2;
float clearRumbleTime;
void callibrate(Vector &vec, float dead);
bool anyButton();
bool getButton(unsigned id) const { return buttonBitmask & (1u << id); }
Vector rightStick;
int stickIndex;
int s1ax, s1ay, s2ax, s2ay;
private:
bool inited;
unsigned buttonBitmask; // FIXME: this should go
# ifdef BBGE_BUILD_SDL2
SDL_GameController *sdl_controller;
SDL_Haptic *sdl_haptic;
# endif
SDL_Joystick *sdl_joy;
#if defined(__LINUX__) && !defined(BBGE_BUILD_SDL2)
int eventfd;
short effectid;
#endif
};
#endif

View file

@ -296,6 +296,10 @@
RelativePath="..\..\BBGE\Joystick.cpp" RelativePath="..\..\BBGE\Joystick.cpp"
> >
</File> </File>
<File
RelativePath="..\..\BBGE\Joystick.h"
>
</File>
<File <File
RelativePath="..\..\BBGE\LensFlare.cpp" RelativePath="..\..\BBGE\LensFlare.cpp"
> >