|
From: knittl <kn...@us...> - 2009-08-03 08:39:58
|
Module: performous
Branch: master
Commit: a194165a0895eac4a2b99f9486ea47331621e207
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 12:40:57 2009 +0200
Started new input device implementation (keeping joystick api compatibility)
Fixed manpage section
---
docs/CMakeLists.txt | 6 ++--
game/joystick.cc | 71 +++++++++++++++++++++++++++++++++-----------------
game/joystick.hh | 13 ++++-----
game/main.cc | 70 ++++++++++++++++++++-----------------------------
game/video_driver.cc | 6 +---
5 files changed, 87 insertions(+), 79 deletions(-)
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index 4b99915..0a4269d 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -5,19 +5,19 @@ if(UNIX)
mark_as_advanced(HELP2MAN)
mark_as_advanced(GZIP)
if(HELP2MAN AND GZIP)
- set(MANFILE ${CMAKE_CURRENT_BINARY_DIR}/performous.1.gz)
+ set(MANFILE ${CMAKE_CURRENT_BINARY_DIR}/performous.6.gz)
set(H2MFILE ${CMAKE_CURRENT_SOURCE_DIR}/performous.h2m)
set(PERFORMOUS_EXEC ${CMAKE_BINARY_DIR}/game/performous)
add_custom_command(
OUTPUT ${MANFILE}
- COMMAND ${HELP2MAN} ${PERFORMOUS_EXEC} -i ${H2MFILE} -N | ${GZIP} > ${MANFILE}
+ COMMAND ${HELP2MAN} ${PERFORMOUS_EXEC} -s 6 -i ${H2MFILE} -N | ${GZIP} > ${MANFILE}
MAIN_DEPENDENCY ${H2MFILE}
DEPENDENCY ${PERFORMOUS_EXEC}
COMMENT "Building Performous man page"
VERBATIM
)
add_custom_target(manpage ALL DEPENDS ${MANFILE})
- install(FILES ${MANFILE} DESTINATION share/man/man1)
+ install(FILES ${MANFILE} DESTINATION share/man/man6)
else(HELP2MAN AND GZIP)
message("WARNING: Can't locate help2man or gzip; man pages will not be generated")
endif(HELP2MAN AND GZIP)
diff --git a/game/joystick.cc b/game/joystick.cc
index c030705..213284d 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -6,7 +6,6 @@
Joysticks joysticks;
Joystick::Joystick(unsigned int _id): m_id(_id) {
- m_joystick = SDL_JoystickOpen(m_id);
if( getName().find("Guitar Hero") != std::string::npos ) {
m_type = Joystick::GUITARHERO;
} else if( getName().find("Harmonix") != std::string::npos ) {
@@ -25,18 +24,6 @@ std::string Joystick::getName() const {
Joystick::Type Joystick::getType() const {
return m_type;
}
-std::string Joystick::getDescription() const {
- std::string desc;
- desc += "axes: ";
- desc += boost::lexical_cast<std::string>(SDL_JoystickNumAxes(m_joystick));
- desc += ", buttons: ";
- desc += boost::lexical_cast<std::string>(SDL_JoystickNumButtons(m_joystick));
- desc += ", balls: ";
- desc += boost::lexical_cast<std::string>(SDL_JoystickNumBalls(m_joystick));
- desc += ", hats: ";
- desc += boost::lexical_cast<std::string>(SDL_JoystickNumHats(m_joystick));
- return desc;
-};
bool Joystick::buttonState(unsigned char _button_id) const {
return (SDL_JoystickGetButton(m_joystick, _button_id) != 0);
};
@@ -149,21 +136,57 @@ void Joystick::clearEvents() {
m_events.clear();
}
-void joysticks_init() {
+/**
+ * New input management, superseed all joysticks stuffs
+ */
+input::Private::InputDevs input::Private::devices;
+
+void input::init() {
+ // new stuffs
unsigned int nbjoysticks = SDL_NumJoysticks();
std::cout << "Detecting " << nbjoysticks << " joysticks..." << std::endl;
for (unsigned int i = 0 ; i < nbjoysticks ; i++) {
- joysticks[i] = Joystick(i);
+ SDL_JoystickOpen(i);
+ input::Private::devices[i] = input::Private::InputDevPrivate();
std::cout << "Id: " << i << std::endl;
- std::cout << " Name: " << joysticks[i].getName() << std::endl;
- std::cout << " Description: " << joysticks[i].getDescription() << std::endl;
+ std::cout << " Name: " << SDL_JoystickName(i) << std::endl;
+ }
+ // compatibility with old joystick stuffs
+ for (input::Private::InputDevs::iterator it = input::Private::devices.begin() ; it != input::Private::devices.end() ; ++it) {
+ joysticks[it->first] = Joystick(it->first);
}
}
-
-/**
- * New input management, superseed all joysticks stuffs
- */
-void input::init() {}
-input::InputDev& input::assign(input::Type) {}
-bool input::pushEvent(SDL_Event) {return false;}
+void input::clear() {
+ // new stuffs
+ for (input::Private::InputDevs::iterator it = input::Private::devices.begin() ; it != input::Private::devices.end() ; ++it) {
+ it->second.clearEvents();
+ }
+ // compatibility with old joystick stuffs
+ for(Joysticks::iterator it = joysticks.begin() ; it != joysticks.end() ; ++it ) {
+ it->second.clearEvents();
+ }
+}
+bool input::pushEvent(SDL_Event _e) {
+ // new stuffs
+ // TODO
+ // compatibility with old joystick stuffs
+ switch(_e.type) {
+ case SDL_JOYAXISMOTION:
+ joysticks[_e.jaxis.which].addEvent(_e.jaxis);
+ break;
+ case SDL_JOYBALLMOTION:
+ joysticks[_e.jball.which].addEvent(_e.jball);
+ break;
+ case SDL_JOYHATMOTION:
+ joysticks[_e.jhat.which].addEvent(_e.jhat);
+ break;
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ joysticks[_e.jbutton.which].addEvent(_e.jbutton);
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
diff --git a/game/joystick.hh b/game/joystick.hh
index 1cbfa55..3e75435 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -11,8 +11,6 @@
#define PS3_DRUM_CONTROLLER_XXX 4
#define PS3_DRUM_CONTROLLER_ORANGE 5
-void joysticks_init();
-
class JoystickEvent {
public:
enum Type {BUTTON_DOWN, BUTTON_UP, HAT_MOTION, AXIS_MOTION, BALL_MOTION};
@@ -51,8 +49,6 @@ class Joystick {
Joystick::Type getType() const;
/// get name of joystick
std::string getName() const;
- /// get longer description of joystick
- std::string getDescription() const;
/// add an even from an SDL_JoyAxisEvent
void addEvent(SDL_JoyAxisEvent event);
/// add an even from an SDL_JoyBallEvent
@@ -102,15 +98,17 @@ namespace input {
namespace Private {
class InputDevPrivate {
public:
- InputDevPrivate() : m_assigned(false) {};
+ InputDevPrivate() : m_assigned(false), m_type(input::UNKNOWN) {};
bool tryPoll(InputDevEvent&) {return true;};
void addEvent(InputDevEvent) {};
+ void clearEvents() {m_events.clear();};
bool status(InputDevEvent::Type) {return false;}; // for buttons
short value(InputDevEvent::Type) {return 0;}; // for axis
void assign() {m_assigned = true;};
void unassign() {m_assigned = false;};
bool assigned() {return m_assigned;};
private:
+ std::deque<InputDevEvent> m_events;
bool m_assigned;
input::Type m_type;
};
@@ -121,6 +119,7 @@ namespace input {
class InputDev {
public:
+ // Throw an exception if none is available
InputDev(input::Type) : m_device_id() {input::Private::devices[m_device_id].assign();};
~InputDev() {input::Private::devices[m_device_id].unassign();};
bool tryPoll(InputDevEvent& _e) {return input::Private::devices[m_device_id].tryPoll(_e);};
@@ -134,8 +133,8 @@ namespace input {
// Initialize all event stuffs
void init();
- // Throw an exception if none is available
- InputDev& assign(input::Type);
+ // clear all event stuffs
+ void clear();
// Returns true if event is taken, feed an InputDev by transforming SDL_Event into InputDevEvent
bool pushEvent(SDL_Event);
};
diff --git a/game/main.cc b/game/main.cc
index cd05a20..e5578f5 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -40,46 +40,36 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
static bool esc = false;
SDL_Event event;
while(SDL_PollEvent(&event) == 1) {
- switch(event.type) {
- case SDL_QUIT:
- sm.finished();
- break;
- case SDL_VIDEORESIZE:
- window.resize(event.resize.w, event.resize.h);
- break;
- case SDL_JOYAXISMOTION:
- joysticks[event.jaxis.which].addEvent(event.jaxis);
- break;
- case SDL_JOYBALLMOTION:
- joysticks[event.jball.which].addEvent(event.jball);
- break;
- case SDL_JOYHATMOTION:
- joysticks[event.jhat.which].addEvent(event.jhat);
- break;
- case SDL_JOYBUTTONDOWN:
- case SDL_JOYBUTTONUP:
- joysticks[event.jbutton.which].addEvent(event.jbutton);
- break;
- case SDL_KEYUP:
- if (event.key.keysym.sym == SDLK_ESCAPE) esc = false;
- break;
- case SDL_KEYDOWN:
- int keypressed = event.key.keysym.sym;
- SDLMod modifier = event.key.keysym.mod;
- // Workaround for key repeat on escape
- if (keypressed == SDLK_ESCAPE) {
- if (esc) return;
- esc = true;
- }
- if (keypressed == SDLK_RETURN && modifier & KMOD_ALT ) {
- config["graphic/fullscreen"].b() = !config["graphic/fullscreen"].b();
- continue; // Already handled here...
- }
- if (keypressed == SDLK_F4 && modifier & KMOD_ALT) {
+ // catch input event first
+ if(!input::pushEvent(event)) {
+ switch(event.type) {
+ case SDL_QUIT:
sm.finished();
- continue; // Already handled here...
+ break;
+ case SDL_VIDEORESIZE:
+ window.resize(event.resize.w, event.resize.h);
+ break;
+ case SDL_KEYUP:
+ if (event.key.keysym.sym == SDLK_ESCAPE) esc = false;
+ break;
+ case SDL_KEYDOWN:
+ int keypressed = event.key.keysym.sym;
+ SDLMod modifier = event.key.keysym.mod;
+ // Workaround for key repeat on escape
+ if (keypressed == SDLK_ESCAPE) {
+ if (esc) return;
+ esc = true;
+ }
+ if (keypressed == SDLK_RETURN && modifier & KMOD_ALT ) {
+ config["graphic/fullscreen"].b() = !config["graphic/fullscreen"].b();
+ continue; // Already handled here...
+ }
+ if (keypressed == SDLK_F4 && modifier & KMOD_ALT) {
+ sm.finished();
+ continue; // Already handled here...
+ }
+ break;
}
- break;
}
sm.getCurrentScreen()->manageEvent(event);
switch(glGetError()) {
@@ -91,9 +81,7 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
case GL_OUT_OF_MEMORY: std::cerr << "OpenGL error: invalid enum" << std::endl; break;
}
}
- for(Joysticks::iterator it = joysticks.begin() ; it != joysticks.end() ; ++it ) {
- it->second.clearEvents();
- }
+ input::clear();
if( config["graphic/fullscreen"].b() != window.getFullscreen() )
window.setFullscreen(config["graphic/fullscreen"].b());
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index c93b955..b1edfe2 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -29,12 +29,10 @@ Window::Window(unsigned int width, unsigned int height, int fs, unsigned int fs_
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableUNICODE(SDL_ENABLE);
SDL_EnableKeyRepeat(80, 80);
- joysticks_init();
+ input::init();
}
-Window::~Window() {
- joysticks.clear();
-}
+Window::~Window() { }
void Window::blank() {
glClear(GL_COLOR_BUFFER_BIT);
|