diff options
-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 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 7 | ||||
-rw-r--r-- | src/core/cvar.cc | 73 | ||||
-rw-r--r-- | src/core/cvar.h | 18 | ||||
-rw-r--r-- | src/core/func.cc | 21 |
9 files changed, 96 insertions, 89 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__ diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 67e90d9..adb3bac 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -23,7 +23,8 @@ void exec(const char *text) std::stringstream cmdstream(text); std::string cmdname; - cmdstream >> cmdname; + if (!(cmdstream >> cmdname)) + return; // is it a function Func f = func::find(cmdname); @@ -45,7 +46,9 @@ void exec(const char *text) args += c; (*cv) = args; } - con_print << cmdname << cv->text() << std::endl; + + con_print << cmdname << " " << cv->text() << std::endl; + return; } con_print << "unknown command '" << cmdname << "'" << std::endl; diff --git a/src/core/cvar.cc b/src/core/cvar.cc index f49438c..a1444ae 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -53,34 +53,49 @@ Cvar_t & Cvar_t::operator=(float other) return (*this); } +unsigned int Cvar_t::flags() const +{ + return(cvar_flags); +} + +float Cvar_t::value() const +{ + return(cvar_value); +} + +const std::string &Cvar_t::text() const +{ + return(cvar_text); +} + namespace cvar { -std::map<std::string, Cvar> cvarregistry; +std::map<std::string, Cvar> registry; Cvar get(const char *name, const char *value, int flags) { - Cvar c = cvarregistry[std::string(name)]; + Cvar c = find(name); if (c) { con_debug << "cvar::get " << name << " already exist with value " << value << std::endl; } else { con_debug << "cvar::get " << name << " " << value << std::endl; c = new Cvar_t(flags); - cvarregistry[std::string(name)] = c; + registry[std::string(name)] = c; (*c) = value; } return c; } -Cvar get(const char *name, int value, int flags) +Cvar get(const char *name, float value, int flags) { - Cvar c = cvarregistry[std::string(name)]; + Cvar c = find(name); if (c) { con_debug << "cvar::get " << name << " already exist with value " << value << std::endl; } else { con_debug << "cvar::get " << name << " " << value << std::endl; c = new Cvar_t(flags); - cvarregistry[std::string(name)] = c; + registry[std::string(name)] = c; (*c) = value; } return c; @@ -88,64 +103,64 @@ Cvar get(const char *name, int value, int flags) Cvar set(const char *name, const char *value, int flags) { - Cvar c = cvarregistry[std::string(name)]; + Cvar c = find(name); if (!c) { c = new Cvar_t(flags); - cvarregistry[std::string(name)] = c; + registry[std::string(name)] = c; } con_debug << "cvar::set " << name << " " << value << std::endl; (*c) = value; return c; } -Cvar set(const char *name, int value, int flags) +Cvar set(const char *name, float value, int flags) { - Cvar c = cvarregistry[std::string(name)]; + Cvar c = find(name); if (!c) { c = new Cvar_t(flags); - cvarregistry[std::string(name)] = c; + registry[std::string(name)] = c; } con_debug << "cvar::set " << name << " " << value << std::endl; (*c) = value; return c; } -void unset(const char *cvarname) +void unset(const std::string &name) { - Cvar c = cvarregistry[std::string(cvarname)]; + Cvar c = find(name); if (c) { - con_debug << "cvar::unset " << cvarname << std::endl; - cvarregistry.erase(std::string(cvarname)); + con_debug << "cvar::unset " << name << std::endl; + registry.erase(name); delete c; } } -void unset(const std::string &cvarname) +void unset(const char *name) { - Cvar c = cvarregistry[cvarname]; - if (c) { - con_debug << "cvar::unset " << cvarname << std::endl; - cvarregistry.erase(cvarname); - delete c; - } + unset(std::string(name)); } -Cvar find(const std::string &cvarname) +Cvar find(const std::string &name) { - return cvarregistry[cvarname]; + std::map<std::string, Cvar>::iterator it = registry.find(name); + if (it == registry.end()) + return 0; + else + return (*it).second; } -Cvar find(const char *cvarname) +Cvar find(const char *name) { - return cvarregistry[std::string(cvarname)]; + return(find(std::string(name))); } void list() { con_print << "-- listcvar -----------------" << std::endl; - std::map<std::string, Cvar>::iterator cvarregistryiterator; - for (cvarregistryiterator = cvarregistry.begin(); cvarregistryiterator != cvarregistry.end(); cvarregistryiterator++) { - con_print << " "<< (*cvarregistryiterator).first << " " << (*cvarregistryiterator).second->text() << std::endl; + + std::map<std::string, Cvar>::iterator it; + for (it = registry.begin(); it != registry.end(); it++) { + con_print << " "<< (*it).first << " " << (*it).second->text() << std::endl; } } diff --git a/src/core/cvar.h b/src/core/cvar.h index fa04c49..660f03e 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -21,9 +21,9 @@ public: Cvar_t &operator=(int other); Cvar_t &operator=(float other); - inline unsigned int flags() const { return cvar_flags; } - inline float value() const { return(cvar_value); } - const std::string &text() const { return(cvar_text); } + unsigned int flags() const; + float value() const; + const std::string &text() const; private: std::string cvar_text; @@ -49,7 +49,7 @@ Cvar get(const char *name, const char *value, int flags=0); * its value will not be changed. If the cvar does not exist, * it will be created */ -Cvar get(const char *name, int value, int flags=0); +Cvar get(const char *name, float value, int flags=0); /// set a cvar value /** If the a cvar with the given name already exists in the registry, @@ -60,19 +60,19 @@ Cvar set(const char *name, const char *value, int flags=0); /** If the a cvar with the given name already exists in the registry, * its value will be replaced */ -Cvar set(const char *name, int value, int flags=0); +Cvar set(const char *name, float value, int flags=0); /// delete a cvar from the registry -void unset(const char *cvarname); +void unset(const char *name); /// delete a cvar from the registry -void unset(const std::string &cvarname); +void unset(const std::string &name); /// search for a named cvar, returns 0 if not found -Cvar find(const std::string &cvarname); +Cvar find(const std::string &name); /// search for a named cvar, returns 0 if not found -Cvar find(const char *cvarname); +Cvar find(const char *name); /// list the cvar registry void list(); diff --git a/src/core/func.cc b/src/core/func.cc index c1ed826..c72faea 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -14,34 +14,39 @@ namespace core namespace func { -std::map<std::string, Func> funcregistry; +std::map<std::string, Func> registry; + void add(const char * functionname, Func functionptr) { - funcregistry[std::string(functionname)] = functionptr; + registry[std::string(functionname)] = functionptr; } void remove(const char *functionname) { - funcregistry.erase(std::string(functionname)); + registry.erase(std::string(functionname)); } void remove(const std::string &functionname) { - funcregistry.erase(functionname); + registry.erase(functionname); } Func find(const std::string &functionname) { - return funcregistry[functionname]; + std::map<std::string, Func>::iterator it = registry.find(functionname); + if (it == registry.end()) + return 0; + else + return (*it).second; } void list() { con_print << "-- listfunc -----------------" << std::endl; - std::map<std::string, Func>::iterator funcregistryiterator; - for (funcregistryiterator = funcregistry.begin(); funcregistryiterator != funcregistry.end(); funcregistryiterator++) { - con_print << " " << (*funcregistryiterator).first << std::endl; + std::map<std::string, Func>::iterator it; + for (it = registry.begin(); it != registry.end(); it++) { + con_print << " " << (*it).first << std::endl; } } |