mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-25 15:33:57 +00:00
wip, temp commit
This commit is contained in:
parent
4e37abd0f5
commit
d1778a97b8
7 changed files with 141 additions and 100 deletions
|
@ -116,8 +116,16 @@ void AquariaGuiElement::updateMovement(float dt)
|
||||||
if (guiMoveTimer==0)
|
if (guiMoveTimer==0)
|
||||||
{
|
{
|
||||||
Direction dir = DIR_NONE;
|
Direction dir = DIR_NONE;
|
||||||
Vector p = core->joystick.position;
|
Vector p;
|
||||||
if (!p.isLength2DIn(0.4))
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
|
if(Joystick *j = core->joysticks[i])
|
||||||
|
if(j->isEnabled())
|
||||||
|
{
|
||||||
|
p = core->joysticks[i]->position;
|
||||||
|
if(!p.isLength2DIn(0.4f))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!p.isLength2DIn(0.4f))
|
||||||
{
|
{
|
||||||
if (fabsf(p.x) > fabsf(p.y))
|
if (fabsf(p.x) > fabsf(p.y))
|
||||||
{
|
{
|
||||||
|
@ -346,10 +354,20 @@ bool AquariaSlider::doSliderInput(float dt)
|
||||||
|
|
||||||
float inputAmount; // How much to adjust by?
|
float inputAmount; // How much to adjust by?
|
||||||
|
|
||||||
|
Vector jpos;
|
||||||
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
|
if(Joystick *j = core->joysticks[i])
|
||||||
|
if(j->isEnabled())
|
||||||
|
{
|
||||||
|
jpos = core->joysticks[i]->position;
|
||||||
|
if(fabsf(jpos.x) > SLIDER_JOY_THRESHOLD)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
StateObject *obj = dsq->getTopStateObject();
|
StateObject *obj = dsq->getTopStateObject();
|
||||||
if (core->joystick.position.x <= -SLIDER_JOY_THRESHOLD)
|
if (jpos.x <= -SLIDER_JOY_THRESHOLD)
|
||||||
inputAmount = -0.1f;
|
inputAmount = -0.1f;
|
||||||
else if (core->joystick.position.x >= SLIDER_JOY_THRESHOLD)
|
else if (jpos.x >= SLIDER_JOY_THRESHOLD)
|
||||||
inputAmount = +0.1f;
|
inputAmount = +0.1f;
|
||||||
else if (obj && obj->isActing(ACTION_MENULEFT))
|
else if (obj && obj->isActing(ACTION_MENULEFT))
|
||||||
inputAmount = -0.1f;
|
inputAmount = -0.1f;
|
||||||
|
|
|
@ -187,16 +187,23 @@ Vector Avatar::getAim()
|
||||||
Vector d;
|
Vector d;
|
||||||
if (dsq->inputMode == INPUT_JOYSTICK)
|
if (dsq->inputMode == INPUT_JOYSTICK)
|
||||||
{
|
{
|
||||||
if (!core->joystick.rightStick.isZero())
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
{
|
if(Joystick *j = core->joysticks[i])
|
||||||
d = core->joystick.rightStick * 300;
|
if(j->isEnabled() && !j->rightStick.isZero())
|
||||||
d.z = 1;
|
{
|
||||||
}
|
d = j->rightStick * 300;
|
||||||
else
|
d.z = 1;
|
||||||
{
|
break;
|
||||||
d = core->joystick.position * 300;
|
}
|
||||||
d.z = 0;
|
|
||||||
}
|
if(d.isZero())
|
||||||
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
|
if(Joystick *j = core->joysticks[i])
|
||||||
|
if(j->isEnabled() && !j->position.isZero())
|
||||||
|
{
|
||||||
|
d = j->position * 300;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (dsq->inputMode == INPUT_KEYBOARD)
|
else if (dsq->inputMode == INPUT_KEYBOARD)
|
||||||
{
|
{
|
||||||
|
@ -1761,7 +1768,15 @@ void Avatar::updateSingingInterface(float dt)
|
||||||
{
|
{
|
||||||
if (dsq->inputMode == INPUT_JOYSTICK)
|
if (dsq->inputMode == INPUT_JOYSTICK)
|
||||||
{
|
{
|
||||||
Vector d = dsq->joystick.position;
|
Vector d;
|
||||||
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
|
if(Joystick *j = core->joysticks[i])
|
||||||
|
if(j->isEnabled())
|
||||||
|
{
|
||||||
|
d = j->position;
|
||||||
|
if(!d.isZero())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (d.isLength2DIn(JOYSTICK_NOTE_THRESHOLD))
|
if (d.isLength2DIn(JOYSTICK_NOTE_THRESHOLD))
|
||||||
{
|
{
|
||||||
|
|
|
@ -200,8 +200,10 @@ bool ActionMapper::getKeyState(int k)
|
||||||
int v = k - JOY_BUTTON_0;
|
int v = k - JOY_BUTTON_0;
|
||||||
|
|
||||||
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
for(size_t i = 0; i < core->joysticks.size(); ++i)
|
||||||
if( ((keyState = core->joysticks[i]->getButton(v))) )
|
if(Joystick *j = core->joysticks[i])
|
||||||
break;
|
if(j->isEnabled())
|
||||||
|
if( ((keyState = j->getButton(v))) )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyState;
|
return keyState;
|
||||||
|
|
|
@ -188,17 +188,6 @@ void Core::toggleScreenMode(int t)
|
||||||
sound->resume();
|
sound->resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::updateCursorFromJoystick(float dt, int spd)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
core->mouse.position += joystick.position*dt*spd;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doMouseConstraint();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Core::setWindowCaption(const std::string &caption, const std::string &icon)
|
void Core::setWindowCaption(const std::string &caption, const std::string &icon)
|
||||||
{
|
{
|
||||||
#ifndef BBGE_BUILD_SDL2
|
#ifndef BBGE_BUILD_SDL2
|
||||||
|
@ -712,7 +701,7 @@ bool Core::getKeyState(int k)
|
||||||
return k > 0 && k < KEY_MAXARRAY ? keys[k] : 0;
|
return k > 0 && k < KEY_MAXARRAY ? keys[k] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Core::initJoystickLibrary()
|
void Core::initJoystickLibrary()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_SDL2
|
#ifdef BBGE_BUILD_SDL2
|
||||||
|
@ -721,11 +710,35 @@ bool Core::initJoystickLibrary()
|
||||||
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
joystick.init(0);
|
detectJoysticks();
|
||||||
|
}
|
||||||
|
|
||||||
joystickEnabled = true;
|
void Core::clearJoysticks()
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < joysticks.size(); ++i)
|
||||||
|
delete joysticks[i];
|
||||||
|
joysticks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
void Core::detectJoysticks()
|
||||||
|
{
|
||||||
|
clearJoysticks();
|
||||||
|
|
||||||
|
std::ostringstream os;
|
||||||
|
const unsigned n = SDL_NumJoysticks();
|
||||||
|
os << "Found [" << n << "] joysticks";
|
||||||
|
debugLog(os.str());
|
||||||
|
|
||||||
|
for(unsigned i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
Joystick *j = new Joystick;
|
||||||
|
if(j->init(i))
|
||||||
|
joysticks.push_back(j);
|
||||||
|
else
|
||||||
|
delete j;
|
||||||
|
}
|
||||||
|
|
||||||
|
joystickEnabled = !joysticks.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Core::initInputLibrary()
|
bool Core::initInputLibrary()
|
||||||
|
@ -737,8 +750,6 @@ bool Core::initInputLibrary()
|
||||||
keys[i] = 0;
|
keys[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,7 +764,9 @@ void Core::onUpdate(float dt)
|
||||||
core->mouse.lastScrollWheel = core->mouse.scrollWheel;
|
core->mouse.lastScrollWheel = core->mouse.scrollWheel;
|
||||||
|
|
||||||
pollEvents();
|
pollEvents();
|
||||||
joystick.update(dt);
|
|
||||||
|
for(size_t i = 0; i < joysticks.size(); ++i)
|
||||||
|
joysticks[i]->update(dt);
|
||||||
|
|
||||||
onMouseInput();
|
onMouseInput();
|
||||||
|
|
||||||
|
@ -2350,7 +2363,7 @@ void Core::shutdownInputLibrary()
|
||||||
void Core::shutdownJoystickLibrary()
|
void Core::shutdownJoystickLibrary()
|
||||||
{
|
{
|
||||||
if (joystickEnabled) {
|
if (joystickEnabled) {
|
||||||
joystick.shutdown();
|
clearJoysticks();
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
joystickEnabled = false;
|
joystickEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,8 +293,6 @@ public:
|
||||||
int getWindowWidth() { return width; }
|
int getWindowWidth() { return width; }
|
||||||
int getWindowHeight() { return height; }
|
int getWindowHeight() { return height; }
|
||||||
|
|
||||||
void updateCursorFromJoystick(float dt, int spd);
|
|
||||||
|
|
||||||
unsigned getTicks();
|
unsigned getTicks();
|
||||||
|
|
||||||
void resetGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1);
|
void resetGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1);
|
||||||
|
@ -521,13 +519,15 @@ protected:
|
||||||
float baseCullRadius;
|
float baseCullRadius;
|
||||||
bool initSoundLibrary(const std::string &defaultDevice);
|
bool initSoundLibrary(const std::string &defaultDevice);
|
||||||
bool initInputLibrary();
|
bool initInputLibrary();
|
||||||
bool initJoystickLibrary();
|
void 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();
|
||||||
|
|
||||||
|
void detectJoysticks();
|
||||||
|
void clearJoysticks();
|
||||||
virtual void onJoystickAdded(int deviceID);
|
virtual void onJoystickAdded(int deviceID);
|
||||||
virtual void onJoystickRemoved(int instanceID);
|
virtual void onJoystickRemoved(int instanceID);
|
||||||
|
|
||||||
|
@ -565,8 +565,6 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Joystick*> joysticks;
|
std::vector<Joystick*> joysticks;
|
||||||
|
|
||||||
Joystick joystick; // TEMP: TO GET IT TO COMPILE
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Core *core;
|
extern Core *core;
|
||||||
|
|
|
@ -26,6 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "Joystick.h"
|
#include "Joystick.h"
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
|
||||||
|
unsigned Joystick::GetNumJoysticks()
|
||||||
|
{
|
||||||
|
return SDL_NumJoysticks();
|
||||||
|
}
|
||||||
|
|
||||||
Joystick::Joystick()
|
Joystick::Joystick()
|
||||||
{
|
{
|
||||||
|
@ -45,70 +49,61 @@ Joystick::Joystick()
|
||||||
s1ay = 1;
|
s1ay = 1;
|
||||||
s2ax = 4;
|
s2ax = 4;
|
||||||
s2ay = 3;
|
s2ay = 3;
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::init(int stick)
|
bool Joystick::init(int stick)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
|
||||||
|
|
||||||
stickIndex = stick;
|
stickIndex = stick;
|
||||||
const int numJoy = SDL_NumJoysticks();
|
|
||||||
os << "Found [" << numJoy << "] joysticks";
|
|
||||||
debugLog(os.str());
|
|
||||||
|
|
||||||
if (numJoy > stick)
|
#ifdef BBGE_BUILD_SDL2
|
||||||
|
if (SDL_IsGameController(stick))
|
||||||
|
{
|
||||||
|
sdl_controller = SDL_GameControllerOpen(stick);
|
||||||
|
if (sdl_controller)
|
||||||
|
sdl_joy = SDL_GameControllerGetJoystick(sdl_controller);
|
||||||
|
}
|
||||||
|
if (!sdl_joy)
|
||||||
|
sdl_joy = SDL_JoystickOpen(stick);
|
||||||
|
if (sdl_joy && SDL_JoystickIsHaptic(sdl_joy))
|
||||||
|
{
|
||||||
|
sdl_haptic = SDL_HapticOpenFromJoystick(sdl_joy);
|
||||||
|
bool rumbleok = false;
|
||||||
|
if (sdl_haptic && SDL_HapticRumbleSupported(sdl_haptic))
|
||||||
|
rumbleok = (SDL_HapticRumbleInit(sdl_haptic) == 0);
|
||||||
|
if (!rumbleok)
|
||||||
|
{
|
||||||
|
SDL_HapticClose(sdl_haptic);
|
||||||
|
sdl_haptic = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sdl_joy)
|
||||||
|
sdl_joy = SDL_JoystickOpen(stick);
|
||||||
|
|
||||||
|
if (sdl_joy)
|
||||||
{
|
{
|
||||||
#ifdef BBGE_BUILD_SDL2
|
#ifdef BBGE_BUILD_SDL2
|
||||||
if (SDL_IsGameController(stick))
|
debugLog(std::string("Initialized Joystick [") + SDL_JoystickName(sdl_joy) + "]");
|
||||||
{
|
if (sdl_controller)
|
||||||
sdl_controller = SDL_GameControllerOpen(stick);
|
debugLog("Joystick is a Game Controller");
|
||||||
if (sdl_controller)
|
if (sdl_haptic)
|
||||||
sdl_joy = SDL_GameControllerGetJoystick(sdl_controller);
|
debugLog("Joystick has force feedback support");
|
||||||
}
|
instanceID = SDL_JoystickInstanceID(sdl_joy);
|
||||||
if (!sdl_joy)
|
#else
|
||||||
sdl_joy = SDL_JoystickOpen(stick);
|
debugLog(std::string("Initialized Joystick [") + SDL_JoystickName(stick)) + std::string("]"));
|
||||||
if (sdl_joy && SDL_JoystickIsHaptic(sdl_joy))
|
instanceID = SDL_JoystickIndex(sdl_joy);
|
||||||
{
|
|
||||||
sdl_haptic = SDL_HapticOpenFromJoystick(sdl_joy);
|
|
||||||
bool rumbleok = false;
|
|
||||||
if (sdl_haptic && SDL_HapticRumbleSupported(sdl_haptic))
|
|
||||||
rumbleok = (SDL_HapticRumbleInit(sdl_haptic) == 0);
|
|
||||||
if (!rumbleok)
|
|
||||||
{
|
|
||||||
SDL_HapticClose(sdl_haptic);
|
|
||||||
sdl_haptic = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!sdl_joy)
|
return true;
|
||||||
sdl_joy = SDL_JoystickOpen(stick);
|
|
||||||
|
|
||||||
if (sdl_joy)
|
|
||||||
{
|
|
||||||
#ifdef BBGE_BUILD_SDL2
|
|
||||||
debugLog(std::string("Initialized Joystick [") + SDL_JoystickName(sdl_joy) + "]");
|
|
||||||
if (sdl_controller)
|
|
||||||
debugLog("Joystick is a Game Controller");
|
|
||||||
if (sdl_haptic)
|
|
||||||
debugLog("Joystick has force feedback support");
|
|
||||||
instanceID = SDL_JoystickInstanceID(sdl_joy);
|
|
||||||
#else
|
|
||||||
debugLog(std::string("Initialized Joystick [") + SDL_JoystickName(stick)) + std::string("]"));
|
|
||||||
instanceID = SDL_JoystickIndex(sdl_joy);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::ostringstream os;
|
|
||||||
os << "Failed to init Joystick [" << stick << "]";
|
|
||||||
debugLog(os.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
debugLog("Not enough Joystick(s) found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Failed to init Joystick [" << stick << "]";
|
||||||
|
debugLog(os.str());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::shutdown()
|
void Joystick::shutdown()
|
||||||
|
@ -241,13 +236,9 @@ void Joystick::update(float dt)
|
||||||
rightStick.y = yaxis2/32768.0f;
|
rightStick.y = yaxis2/32768.0f;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
calibrate(position, deadZone1);
|
calibrate(position, deadZone1);
|
||||||
|
|
||||||
calibrate(rightStick, deadZone2);
|
calibrate(rightStick, deadZone2);
|
||||||
|
|
||||||
|
|
||||||
buttonBitmask = 0;
|
buttonBitmask = 0;
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_SDL2
|
#ifdef BBGE_BUILD_SDL2
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
class Joystick
|
class Joystick
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static unsigned GetNumJoysticks();
|
||||||
|
|
||||||
Joystick();
|
Joystick();
|
||||||
void init(int stick=0);
|
bool init(int stick=0);
|
||||||
void shutdown();
|
void shutdown();
|
||||||
//Ranges from 0 to 1 (full speed).
|
//Ranges from 0 to 1 (full speed).
|
||||||
void rumble(float leftMotor, float rightMotor, float time);
|
void rumble(float leftMotor, float rightMotor, float time);
|
||||||
|
@ -32,12 +34,14 @@ public:
|
||||||
bool getButton(unsigned id) const { return !!(buttonBitmask & (1u << id)); }
|
bool getButton(unsigned id) const { return !!(buttonBitmask & (1u << id)); }
|
||||||
int getIndex() const { return stickIndex; }
|
int getIndex() const { return stickIndex; }
|
||||||
int getInstanceID() const { return instanceID; }
|
int getInstanceID() const { return instanceID; }
|
||||||
|
inline bool isEnabled() const { return enabled; }
|
||||||
|
|
||||||
Vector rightStick;
|
Vector rightStick;
|
||||||
|
|
||||||
int s1ax, s1ay, s2ax, s2ay;
|
int s1ax, s1ay, s2ax, s2ay;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool enabled;
|
||||||
int stickIndex;
|
int stickIndex;
|
||||||
int instanceID;
|
int instanceID;
|
||||||
unsigned buttonBitmask; // FIXME: this should go
|
unsigned buttonBitmask; // FIXME: this should go
|
||||||
|
|
Loading…
Add table
Reference in a new issue