diff options
author | Stijn Buys <ingar@osirion.org> | 2008-04-06 14:13:36 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-04-06 14:13:36 +0000 |
commit | 7b5a6b820d5acef36d402bd5a52d783ec68d33c7 (patch) | |
tree | a1cb65e071441277865ca5f4e315611cdd51c0e5 /src/core | |
parent | 25d2c764443723eb7a3dd5f8bf0b76586c1ff10b (diff) |
mouse grabbing, Cvar and Func info
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 4 | ||||
-rw-r--r-- | src/core/application.cc | 32 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 18 | ||||
-rw-r--r-- | src/core/cvar.cc | 25 | ||||
-rw-r--r-- | src/core/cvar.h | 9 | ||||
-rw-r--r-- | src/core/func.cc | 37 | ||||
-rw-r--r-- | src/core/func.h | 13 |
7 files changed, 106 insertions, 32 deletions
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<std::string, Cvar*> 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<std::string, Cvar*>::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<std::string, Func*> 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<std::string, Func*>::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<std::string, Func*>::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<std::string, Func*>::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; }; |