From 7b5a6b820d5acef36d402bd5a52d783ec68d33c7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 6 Apr 2008 14:13:36 +0000 Subject: mouse grabbing, Cvar and Func info --- src/Makefile.am | 7 ++++++- src/client/chat.cc | 6 +++++- src/client/client.cc | 14 +++++++++++--- src/client/console.cc | 8 +++++++- src/client/input.cc | 7 +++---- src/core/Makefile.am | 4 ++-- src/core/application.cc | 32 ++++++++++++++++++++++++++------ src/core/commandbuffer.cc | 18 +++++++++++++----- src/core/cvar.cc | 25 ++++++++++++++++++++----- src/core/cvar.h | 9 ++++++++- src/core/func.cc | 37 +++++++++++++++++++++++++++---------- src/core/func.h | 13 ++++++++++--- src/render/render.cc | 12 +++++++++--- 13 files changed, 147 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index e6595f6..5f9a33d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ osiriond_SOURCES = osiriond.cc EXTRA_osiriond_SOURCES = osiriond-res.rc osiriond_DEPENDENCIES = $(ICON_SERVER) osiriond_LDADD = $(top_builddir)/src/game/libgame.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \ $(top_builddir)/src/server/libserver.la $(HOST_LIBS) $(ICON_SERVER) # client @@ -21,5 +23,8 @@ EXTRA_osirion_SOURCES = osirion-res.rc osirion_DEPENDENCIES = $(ICON_CLIENT) osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) $(GLUT_CFLAGS) osirion_LDADD = $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/client/libclient.la $(GL_LIBS) $(HOST_LIBS) $(ICON_CLIENT) + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \ + $(top_builddir)/src/render/librender.la $(top_builddir)/src/client/libclient.la $(GL_LIBS) $(HOST_LIBS) \ + $(ICON_CLIENT) osirion_LDFLAGS = $(LIBSDL_LIBS) diff --git a/src/client/chat.cc b/src/client/chat.cc index 7f5c22c..8de2665 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -33,6 +33,8 @@ void func_con_chat(std::string const &args) if (i) chat_visible = true; else chat_visible = false; } else chat_visible = !chat_visible; + + } //--- public ------------------------------------------------------ @@ -40,7 +42,7 @@ void func_con_chat(std::string const &args) void init() { // add engine functions - //core::Func::add("con_chat", (core::FuncPtr) func_con_chat); + core::Func::add("con_chat", (core::FuncPtr) func_con_chat); history.clear(); history.push_back(""); @@ -97,6 +99,8 @@ void toggle() history_pos = history.rbegin(); (*history_pos).clear(); } + + setkeyboardmode(chat_visible); } void keypressed(int key) diff --git a/src/client/client.cc b/src/client/client.cc index b09618e..ab27d0f 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -90,9 +90,15 @@ void Client::init() core::Application::init(); // client variables - core::Cvar::get("cl_name", "Player", core::Cvar::Archive | core::Cvar::Info); - core::Cvar::get("cl_color", "1.0 1.0 1.0", core::Cvar::Archive | core::Cvar::Info); + core::Cvar *cvar = 0; + cvar = core::Cvar::get("cl_name", "Player", core::Cvar::Archive | core::Cvar::Info); + cvar->set_info("[str] client player name"); + + cvar = core::Cvar::get("cl_color", "1.0 1.0 1.0", core::Cvar::Archive | core::Cvar::Info); + cvar->set_info("[r g b] client player clor"); + cl_framerate = core::Cvar::get("cl_framerate", "120", core::Cvar::Archive); + cl_framerate->set_info("client framerate in frames/sec"); // initialize SDL, but do not initialize any subsystems SDL_Init(0); @@ -111,7 +117,9 @@ void Client::init() input::init(); // add engine functions - core::Func::add("r_restart", (core::FuncPtr) func_r_restart); + core::Func *func = 0; + func = core::Func::add("r_restart", (core::FuncPtr) func_r_restart); + func->set_info("restart render subsystem"); } void Client::run() diff --git a/src/client/console.cc b/src/client/console.cc index 2d667a8..ca84384 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -84,7 +84,7 @@ void init() console_visible = false; // add engine functions - //core::Func::add("con_toggle", (core::FuncPtr) func_con_toggle); + core::Func::add("con_toggle", (core::FuncPtr) func_con_toggle); text.clear(); console_scroll = 0; @@ -214,7 +214,13 @@ void toggle() history_pos = history.rbegin(); (*history_pos).clear(); + + SDL_WM_GrabInput(SDL_GRAB_OFF); + } else { + SDL_WM_GrabInput(SDL_GRAB_ON); } + + setkeyboardmode(console::visible()); } void keypressed(int key) diff --git a/src/client/input.cc b/src/client/input.cc index 88d1dd3..a7e67cc 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -35,7 +35,8 @@ int mouse_y = 0; void init() { con_print << "Initializing input..." << std::endl; - client::setkeyboardmode(console::visible()); + client::setkeyboardmode(false); + SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); } @@ -139,7 +140,7 @@ void frame(float seconds) if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { last_control = 0; console::toggle(); - setkeyboardmode(console::visible()); + if (console::visible() && chat::visible()) chat::toggle(); } else if (console::visible()) { @@ -149,7 +150,6 @@ void frame(float seconds) } else if (chat::visible()) { if(event.key.keysym.sym == SDLK_ESCAPE) { chat::toggle(); - setkeyboardmode(chat::visible()); } else { // send key events to the chatbox chat::keypressed(translate_keysym(event.key.keysym)); @@ -157,7 +157,6 @@ void frame(float seconds) } else if(core::application()->connected()) { if ((event.key.keysym.sym == 't') || (event.key.keysym.sym == 'T')) { chat::toggle(); - setkeyboardmode(chat::visible()); } else if (core::localcontrol()) { // send key events to the game world keypressed(event.key.keysym); diff --git a/src/core/Makefile.am b/src/core/Makefile.am index a73a8a7..e9091f2 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -5,8 +5,8 @@ libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \ func.cc gameconnection.cc gameinterface.cc gameserver.cc model.cc module.cc \ netclient.cc netconnection.cc netserver.cc player.cc libcore_la_LDFLAGS = -avoid-version -no-undefined -libcore_la_LIBADD = $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la +libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libcore.la noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \ diff --git a/src/core/application.cc b/src/core/application.cc index 2807d0e..ee0dd76 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -123,37 +123,57 @@ void Application::init() CommandBuffer::init(); // dedicated server has set this to 1 Cvar::sv_dedicated = Cvar::get("sv_dedicated", "0", Cvar::ReadOnly); + Cvar::sv_dedicated->set_info("[bool] indicates this is a dedicated server"); + // client can set this to 1 Cvar::sv_private = Cvar::get("sv_private", "0"); + Cvar::sv_private->set_info("[bool] indicates the client runs a networked server"); // load save cvars load_config(); // framerate settings Cvar::sv_framerate = Cvar::get("sv_framerate", "25"); + Cvar::sv_framerate->set_info("[int] server framerate in frames/sec"); // network settings Cvar::net_host = Cvar::get("net_host", "0.0.0.0", Cvar::Archive); + Cvar::net_host->set_info("[ip] IP address the network server binds to"); + Cvar::net_port = Cvar::get("net_port", "8042", Cvar::Archive); + Cvar::net_port->set_info("[int] default network port"); + Cvar::net_maxclients = Cvar::get("net_maxclients", "16", Cvar::Archive); + Cvar::net_maxclients->set_info("[int] maximum number of network clients"); + Cvar::net_timeout = Cvar::get("net_timeout", "20", Cvar::Archive); + Cvar::net_timeout->set_info("[int] network timeout in seconds"); #ifdef _WIN32 // Initialize win32 socket library WSADATA wsa_data; WORD wsa_version = MAKEWORD(2, 0); if (WSAStartup(wsa_version, &wsa_data) != 0 ) { - con_warn << "Could not initialize scoket library!" << std::endl; + con_warn << "Could not initialize socket library!" << std::endl; } #endif // register our engine functions - Func::add("print", func_print); - Func::add("help", func_help); - Func::add("quit", func_quit); + Func *func = 0; + func = Func::add("print", func_print); + func->set_info("[str] print a message on the console"); + + func = Func::add("help", func_help); + func->set_info("dummy help function"); + + func = Func::add("quit", func_quit); + func->set_info("exit the application"); - Func::add("connect", func_connect); - Func::add("disconnect", func_disconnect); + func = Func::add("connect", func_connect); + func->set_info("[ip] without ip, create a game"); + + func = Func::add("disconnect", func_disconnect); + func->set_info("leave the current game"); } void Application::shutdown() diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index a38d9d0..ead2a98 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -65,10 +65,18 @@ void CommandBuffer::init() { //con_debug << "Initializing command buffer...\n"; - Func::add("list_ent", (FuncPtr)func_list_ent); - Func::add("list_func", (FuncPtr)func_list_func); - Func::add("list_var", (FuncPtr)func_list_var); - Func::add("set", (FuncPtr)func_set); + Func *func = 0; + func = Func::add("list_ent", (FuncPtr)func_list_ent); + func->set_info("list entities"); + + func = Func::add("list_func", (FuncPtr)func_list_func); + func->set_info("list functions"); + + func = Func::add("list_var", (FuncPtr)func_list_var); + func->set_info("list variables"); + + func = Func::add("set", (FuncPtr)func_set); + func->set_info("[variable] [str] set variable value"); } void CommandBuffer::shutdown() @@ -130,7 +138,7 @@ void CommandBuffer::exec(std::string const &cmdline) } } - con_print << command << " " << cvar->str() << "\n"; + con_print << command << " " << cvar->str() << " " << cvar->info() << "\n"; return; } diff --git a/src/core/cvar.cc b/src/core/cvar.cc index 518ec5a..4571240 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -31,8 +31,19 @@ std::map Cvar::registry; Cvar::Cvar(const char *name, unsigned int flags) { cvar_flags = flags; + if (name) cvar_name.assign(name); + else + cvar_name.clear(); + + cvar_info.clear(); +} + +void Cvar::set_info(const char *info) +{ + if (info) + cvar_info.assign(info); } Cvar & Cvar::operator=(const std::string &other) @@ -148,6 +159,8 @@ Cvar *Cvar::find(const char *name) void Cvar::list() { + con_print << "Flags: A=Archive G=Game R=ReadOnly" << std::endl; + std::map::iterator it; for (it = registry.begin(); it != registry.end(); it++) { std::string typeindicator; @@ -155,17 +168,19 @@ void Cvar::list() typeindicator += 'A'; else typeindicator += ' '; - if (((*it).second->flags() & ReadOnly) == ReadOnly) - typeindicator += 'R'; - else - typeindicator += ' '; + if (((*it).second->flags() & Game) == Game) typeindicator += 'G'; else typeindicator += ' '; + if (((*it).second->flags() & ReadOnly) == ReadOnly) + typeindicator += 'R'; + else + typeindicator += ' '; + con_print << " " << typeindicator << - " " << (*it).first << " " << (*it).second->str() << std::endl; + " " << (*it).first << " " << (*it).second->str() << " " << (*it).second->info() << std::endl; } con_print << registry.size() << " registered variables" << std::endl; } diff --git a/src/core/cvar.h b/src/core/cvar.h index 8ced7a4..06b7f2a 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -27,13 +27,16 @@ public: enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8}; /// create a new variable - Cvar(const char *name = 0, unsigned int flags = 0); + Cvar(const char *name, unsigned int flags = 0); /*----- inspectors ------------------------------------------------ */ /// returns the name of the variable inline std::string const &name() { return cvar_name; } + /// returns the info of the variable + inline std::string const &info() { return cvar_info; } + /// returns the flags of the variable inline unsigned int flags() const { return cvar_flags; } @@ -45,6 +48,9 @@ public: /*----- mutators -------------------------------------------------- */ + /// set the info string + void set_info(const char *); + /// char * assignment operator Cvar &operator=(const char *other); @@ -110,6 +116,7 @@ public: static Cvar *net_timeout; // network timeout in seconds private: std::string cvar_name; + std::string cvar_info; std::string cvar_str; unsigned int cvar_flags; float cvar_value; diff --git a/src/core/func.cc b/src/core/func.cc index 4db8dcf..27c46a0 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -18,25 +18,34 @@ namespace core std::map Func::registry; -void Func::add(const char *name, FuncPtr functionptr, unsigned int flags) +Func * Func::add(const char *name, FuncPtr functionptr, unsigned int flags) { + Func *func = 0; std::map::iterator it = registry.find(name); if (it == registry.end()) { - registry[std::string(name)] = new Func(name, (void *)functionptr, flags & ~Func::Game); + func = new Func(name, (void *)functionptr, flags & ~Func::Game); + registry[std::string(name)] = func; + //con_debug << "Function '" << name << "' registered." << std::endl; } else { con_warn << "Function '" << name << "' already registered!" << std::endl; + func = (*it).second; } + return func; } -void Func::add(const char *name, GameFuncPtr gamefunctionptr, unsigned int flags) +Func *Func::add(const char *name, GameFuncPtr gamefunctionptr, unsigned int flags) { + Func *func = 0; std::map::iterator it = registry.find(name); if (it == registry.end()) { - registry[std::string(name)] = new Func(name, (void *)gamefunctionptr, flags | Func::Game); + func = new Func(name, (void *)gamefunctionptr, flags | Func::Game); + registry[std::string(name)] = func; //con_debug << "Function '" << name << "' registered." << std::endl; } else { con_warn << "Function '" << name << "' already registered!" << std::endl; + func = (*it).second; } + return func; } void Func::remove(const char *name) @@ -72,14 +81,15 @@ Func *Func::find(const std::string &name) void Func::list() { std::map::iterator it; + con_print << "Flags: G=Game" << std::endl; + for (it = registry.begin(); it != registry.end(); it++) { std::string typeindicator; if (((*it).second->flags() & Game) == Game) typeindicator += 'G'; else typeindicator += ' '; - con_print << " " << typeindicator << - " " << (*it).second->name() << std::endl; + con_print << " " << typeindicator << " " << (*it).second->name() << " " << (*it).second->info() << std::endl; } con_print << registry.size() << " registered functions" << std::endl; @@ -87,14 +97,16 @@ void Func::list() /* ---- Func ------------------------------------------------------ */ -Func::Func(char const * funcname, void *ptr, unsigned int funcflags) +Func::Func(char const * name, void *ptr, unsigned int flags) { - if (funcname) - func_name.assign(funcname); + if (name) + func_name.assign(name); else func_name.clear(); - func_flags = funcflags; + func_info.clear(); + + func_flags = flags; func_ptr = ptr; } @@ -105,6 +117,11 @@ Func::~Func() func_flags = 0; } +void Func::set_info(const char *info) +{ + if (info) + func_info.assign(info); +} void Func::exec(std::string const &args) { diff --git a/src/core/func.h b/src/core/func.h index e34e32d..2c02599 100644 --- a/src/core/func.h +++ b/src/core/func.h @@ -30,7 +30,7 @@ public: enum Flags {Game=1}; /// create a new function - Func(char const * funcname, void *ptr, unsigned int funcflags = 0); + Func(char const * name, void *ptr, unsigned int flags = 0); ~Func(); @@ -42,8 +42,14 @@ public: /// returns the name of the function inline std::string const &name() const { return func_name; } + /// returns the info of the function + inline std::string const &info() { return func_info; } + /*----- mutators -------------------------------------------------- */ + /// set the info string + void set_info(const char *); + /// execute the function if the Game flag is not set void exec(std::string const &args); @@ -53,10 +59,10 @@ public: /* ---- Static functions for the Func registry -------------------- */ /// add a function to the registry - static void add(const char *name, FuncPtr functionptr, unsigned int flags=0); + static Func *add(const char *name, FuncPtr functionptr, unsigned int flags=0); /// add a game function to the registry and set the Game flag - static void add(const char *name, GameFuncPtr functionptr, unsigned int flags=0); + static Func *add(const char *name, GameFuncPtr functionptr, unsigned int flags=0); /// remove a function from the registry static void remove(const char *name); @@ -75,6 +81,7 @@ public: private: std::string func_name; + std::string func_info; unsigned int func_flags; void *func_ptr; }; diff --git a/src/render/render.cc b/src/render/render.cc index 8311c16..7f79a85 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -75,17 +75,23 @@ void init() core::application()->shutdown(); } - r_arraysize = core::Cvar::get("r_arraysize", 4.0f * (float) sizeof(float) , core::Cvar::Archive); + // size of the vertex array in megabytes + r_arraysize = core::Cvar::get("r_arraysize", 0.0f , core::Cvar::Archive); + r_arraysize->set_info("[int] size of the vertex array in Mb"); + size_t mb = (size_t) r_arraysize->value(); - if (mb < 8) - mb = 8; + if (mb < 4 * sizeof(float)) + mb = 4 * sizeof(float); if (mb > 256) mb = 256; (*r_arraysize) = (float) mb; vertexarray = new core::VertexArray(mb); r_radius = core::Cvar::get("r_radius", "0", core::Cvar::Archive); + r_radius->set_info("[bool] render entity radius"); + r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive); + r_wireframe->set_info("[bool] render wireframe"); } void shutdown() -- cgit v1.2.3