|
From: knittl <kn...@us...> - 2009-08-03 08:41:27
|
Module: performous
Branch: master
Commit: 03cfbe49f9f5618f025cf292b846f2a02d7ce371
Author: Vincent Le Ligeour <yo...@us...>
Date: Sun Aug 2 23:58:22 2009 +0200
Added keyboard guitar
---
game/joystick.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
game/joystick.hh | 12 +++++++-
2 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index bee8bdb..cfdd816 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -65,7 +65,8 @@ input::SDL_devices input::sdl_devices;
void input::init_devices() {
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;
+ if(it->second.assigned()) continue;
+ if(input::sdl_devices[id] == NULL) continue; // Keyboard
unsigned int num_buttons = SDL_JoystickNumButtons(input::sdl_devices[id]);
for( unsigned int i = 0 ; i < num_buttons ; ++i ) {
SDL_Event event;
@@ -116,6 +117,11 @@ void input::init() {
}
// Here we should send an event to have correct state buttons
init_devices();
+ // Adding keyboard instrument
+ std::cout << "Id: " << UINT_MAX << std::endl;
+ std::cout << " Name: Keyboard (emulated guitar)" << std::endl;
+ input::sdl_devices[UINT_MAX] = NULL;
+ input::Private::devices[UINT_MAX] = input::Private::InputDevPrivate(input::Private::GUITAR_GH);
}
bool input::pushEvent(SDL_Event _e) {
@@ -125,6 +131,69 @@ bool input::pushEvent(SDL_Event _e) {
Event event;
switch(_e.type) {
+ case SDL_KEYDOWN: {
+ int button = 0;
+ joy_id = UINT_MAX;
+ if(!devices[joy_id].assigned()) return false;
+ switch(_e.key.keysym.sym) {
+ case SDLK_RETURN:
+ event.type = input::Event::PICK;
+ button = 0;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ devices[joy_id].addEvent(event);
+ return true;
+ case SDLK_F5:
+ button++;
+ case SDLK_F4:
+ button++;
+ case SDLK_F3:
+ button++;
+ case SDLK_F2:
+ button++;
+ case SDLK_F1:
+ event.type = input::Event::PRESS;
+ break;
+ default:
+ return false;
+ }
+ if(devices[joy_id].pressed(button)) return true; // repeating
+ event.button = button;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ event.pressed[button] = true;
+ devices[joy_id].addEvent(event);
+ break;
+ }
+ case SDL_KEYUP: {
+ int button = 0;
+ joy_id = UINT_MAX;
+ if(!devices[joy_id].assigned()) return false;
+ switch(_e.key.keysym.sym) {
+ case SDLK_F5:
+ button++;
+ case SDLK_F4:
+ button++;
+ case SDLK_F3:
+ button++;
+ case SDLK_F2:
+ button++;
+ case SDLK_F1:
+ event.type = input::Event::RELEASE;
+ break;
+ default:
+ return false;
+ }
+ event.button = button;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ event.pressed[button] = false;
+ devices[joy_id].addEvent(event);
+ break;
+ }
case SDL_JOYAXISMOTION:
joy_id = _e.jaxis.which;
diff --git a/game/joystick.hh b/game/joystick.hh
index fd0d791..98ddebf 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -25,8 +25,16 @@ namespace input {
enum Type {GUITAR_RB, DRUMS_RB, GUITAR_GH, DRUMS_GH};
class InputDevPrivate {
public:
- InputDevPrivate() : m_assigned(false), m_type(input::Private::DRUMS_GH) {};
- InputDevPrivate(input::Private::Type _type) : m_assigned(false), m_type(_type) {};
+ InputDevPrivate() : m_assigned(false), m_type(input::Private::DRUMS_GH) {
+ for(unsigned int i = 0 ; i < BUTTONS ; i++) {
+ m_pressed[i] = false;
+ }
+ };
+ InputDevPrivate(input::Private::Type _type) : m_assigned(false), m_type(_type) {
+ for(unsigned int i = 0 ; i < BUTTONS ; i++) {
+ m_pressed[i] = false;
+ }
+ };
bool tryPoll(Event& _event) {
if( m_events.empty() ) return false;
_event = m_events.front();
|