|
From: Tapio V. <aa...@us...> - 2010-03-15 10:12:02
|
Module: performous
Branch: holdesc
Commit: 303584a5e0d9d3e4db9c3d261f0839b169296416
Author: Tapio Vierros <tap...@gm...>
Date: Sun Jan 10 01:28:46 2010 +0200
WIP
---
game/joystick.cc | 12 ++++++++++--
game/joystick.hh | 3 +++
game/main.cc | 13 +++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 1a6cdfd..ada967a 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -68,6 +68,7 @@ int input::buttonFromSDL(input::Private::Type _type, unsigned int _sdl_button) {
input::Private::InputDevs input::Private::devices;
input::SDL::SDL_devices input::SDL::sdl_devices;
+//input::cancel_hold = AnimValue(0.0, 1.0);
/// Abstract navigation actions for different input devices, including keyboard
input::NavButton input::getNav(SDL_Event const &e) {
@@ -80,7 +81,7 @@ input::NavButton input::getNav(SDL_Event const &e) {
else if (k == SDLK_LEFT) return input::LEFT;
else if (k == SDLK_RIGHT) return input::RIGHT;
else if (k == SDLK_RETURN) return input::START;
- else if (k == SDLK_ESCAPE) return input::CANCEL;
+ else if (k == SDLK_ESCAPE) { input::cancel_hold.setTarget(1.0); return input::CANCEL; }
else if (k == SDLK_PAGEUP) return input::MOREUP;
else if (k == SDLK_PAGEDOWN) return input::MOREDOWN;
else if (k == SDLK_PAUSE || (k == SDLK_p && mod & KMOD_CTRL)) return input::PAUSE;
@@ -92,7 +93,7 @@ input::NavButton input::getNav(SDL_Event const &e) {
input::Private::InputDevPrivate devt = input::Private::devices[joy_id];
int b = buttonFromSDL(devt.type(), e.jbutton.button);
if (b == -1) return input::NONE;
- else if (b == 8) return input::CANCEL;
+ else if (b == 8) { input::cancel_hold.setTarget(1.0); return input::CANCEL; }
else if (b == 9) return input::START;
// Totally different device types need their own custom mappings
if (devt.type_match(input::DANCEPAD)) {
@@ -139,11 +140,18 @@ input::NavButton input::getNav(SDL_Event const &e) {
else if (dir == SDL_HAT_LEFT) return input::LEFT;
else if (dir == SDL_HAT_RIGHT) return input::RIGHT;
}
+ // Reset cancel holding counter
+ } else if (e.type == SDL_KEYUP) {
+ if (e.key.keysym.sym == SDLK_ESCAPE) input::cancel_hold.setTarget(0.0, true);
+ } else if (e.type == SDL_JOYBUTTONUP) {
+ if (buttonFromSDL(input::Private::devices[e.jbutton.which].type(), e.jbutton.button) == 8)
+ input::cancel_hold.setTarget(0.0, true);
}
return input::NONE;
}
void input::SDL::init_devices() {
+ input::cancel_hold = AnimValue(0.0, 1.0);
for (input::Private::InputDevs::iterator it = input::Private::devices.begin() ; it != input::Private::devices.end() ; ++it) {
unsigned int id = it->first;
if(it->second.assigned()) continue;
diff --git a/game/joystick.hh b/game/joystick.hh
index a7ddb7f..39cc56c 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -10,6 +10,7 @@
#include "xtime.hh"
#include "configuration.hh"
+#include "animvalue.hh"
#ifdef USE_PORTMIDI
#include "portmidi.hh"
@@ -22,6 +23,8 @@ namespace input {
static const std::size_t BUTTONS = 10;
static const int STARPOWER_BUTTON = 5;
+ static AnimValue cancel_hold(0.0, 1.0);
+
struct Event {
enum Type { PRESS, RELEASE, PICK, WHAMMY };
Type type;
diff --git a/game/main.cc b/game/main.cc
index 05b36cd..7deade6 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -85,6 +85,19 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
case GL_OUT_OF_MEMORY: std::cerr << "OpenGL error: invalid enum" << std::endl; break;
}
}
+ // If cancel button is held down, generate a "start" event
+ // which confirms exit
+ if (input::cancel_hold.get() == 1.0) {
+ SDL_Event newe;
+ newe.type = SDL_KEYDOWN;
+ SDL_keysym newk;
+ newk.sym = SDLK_RETURN;
+ newe.key.keysym = newk;
+ //newe.key.keysym.sym = SDLK_RETURN;
+ input::SDL::pushEvent(newe);
+ std::cout << "HOLDED" << std::endl;
+ }
+ // Switch fullscreen/windowed mode
if( config["graphic/fullscreen"].b() != window.getFullscreen() )
window.setFullscreen(config["graphic/fullscreen"].b());
}
|