diff options
Diffstat (limited to 'src/core')
-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 |
4 files changed, 71 insertions, 48 deletions
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; } } |