diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-05 22:23:15 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-05 22:23:15 +0000 |
commit | 1ed2e8eb1f1909a35f6fc8d5d6065bcac37c27ea (patch) | |
tree | bb1007c12c205b265c1e7515cdc7924496e19cf3 /src/client | |
parent | a51deebd87036ceb87c77a20117977d077b771e3 (diff) |
keyboard handling, cvar fixes
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Makefile.am | 6 | ||||
-rw-r--r-- | src/client/console.cc | 9 | ||||
-rw-r--r-- | src/client/console.h | 2 | ||||
-rw-r--r-- | src/client/input.cc | 40 | ||||
-rw-r--r-- | src/client/input.h | 9 |
5 files changed, 25 insertions, 41 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index a7ca17e..cd7a028 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,13 +1,13 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src -libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc \ +libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc keys.cc \ shipdrawer.cc stardrawer.cc video.cc view.cc libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_LTLIBRARIES = libclient.la -noinst_HEADERS = camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ - video.h view.h +noinst_HEADERS = camera.h client.h console.h input.h keys.h shipdrawer.h \ + stardrawer.h video.h view.h libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \ $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la diff --git a/src/client/console.cc b/src/client/console.cc index bf193e5..d10be50 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -6,6 +6,7 @@ #include "client/console.h" #include "client/video.h" +#include "client/keys.h" #include "core/core.h" #include "render/render.h" @@ -159,9 +160,9 @@ void toggle() console_visible = !console_visible; } -void handle_keypressed(SDL_keysym* keysym) +void keypressed(const SDL_keysym &keysym) { - switch( keysym->sym ) { + switch( keysym.sym ) { case SDLK_RETURN: if (input.size()) { core::cmd << input << std::endl; @@ -177,8 +178,8 @@ void handle_keypressed(SDL_keysym* keysym) break; } - if (keysym->sym >= 32 && keysym->sym <= 175) { - input += (char) keysym->sym; + if ((keysym.sym >= 32 ) && (keysym.sym <175)) { + input += keysym_to_char(keysym); } } diff --git a/src/client/console.h b/src/client/console.h index d185390..3ea064e 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -41,7 +41,7 @@ void draw(); void toggle(); /// handle keyboard input -void handle_keypressed(SDL_keysym* keysym); +void keypressed(const SDL_keysym &keysym); /// true of the console is visible bool visible(); diff --git a/src/client/input.cc b/src/client/input.cc index 9bcf4fe..b7c02af 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -32,26 +32,14 @@ void shutdown() con_print << "Shutting down input..." << std::endl; } -/* -see -http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html -*/ -// handle key_release events for the game world -void handle_keyreleased(SDL_keysym* keysym) + +// handle pressed keys for the game world +void keypressed(const SDL_keysym &keysym) { - switch( keysym->sym ) { + switch( keysym.sym) { case SDLK_SPACE: camera::nextmode(); break; - default: - break; - } -} - -// handle pressed keys for the game world -void handle_keypressed(SDL_keysym* keysym) -{ - switch( keysym->sym ) { case SDLK_LEFT: camera::rotate_left(); break; @@ -94,27 +82,21 @@ void frame(float seconds) switch( event.type ) { case SDL_KEYDOWN: - /* - if (event.key.keysym.sym == SDLK_ESCAPE) { + /*if (event.key.keysym.sym == SDLK_ESCAPE) { client::application.shutdown(); - } - */ - if (console::visible()) { + } else */ + if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { + console::toggle(); + } else if (console::visible()) { // send key events to the console - console::handle_keypressed( &event.key.keysym ); + console::keypressed(event.key.keysym ); } else if (core::connected()) { // send key events to the game world - handle_keypressed( &event.key.keysym ); + keypressed(event.key.keysym ); } break; case SDL_KEYUP: - if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { - console::toggle(); - } else if (!console::visible() && core::connected()) { - // send key events to the game world - handle_keyreleased( &event.key.keysym ); - } break; case SDL_QUIT: diff --git a/src/client/input.h b/src/client/input.h index 7b5f61a..8ab6c7d 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -1,10 +1,11 @@ -/* client/input.h +/* + client/input.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ -#ifndef __INCLUDED_INPUT_H__ -#define __INCLUDED_INPUT_H__ +#ifndef __INCLUDED_cLIENT_INPUT_H__ +#define __INCLUDED_cLIENT_INPUT_H__ namespace client { @@ -23,5 +24,5 @@ void frame(float seconds); } // namespace client -#endif // __INCLUDED_INPUT_H__ +#endif // __INCLUDED_cLIENT_INPUT_H__ |