/* core/cvar.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_CVAR_H__ #define __INCLUDED_CORE_CVAR_H__ #include #include namespace core { /** * @brief a client variable encapsulation class * values f client variables can be set through the command console interface */ class Cvar { public: /** * @brief Cvar flags * * Archive a cvar with this flag will be saved to the configuration file * ReadOnly the value of cvar with this flag can not be altered from the commandline * Game a cvar with this flag is only valid when a game is loaded * Info a cvar that updates player info */ enum Flags {Archive = 1, ReadOnly = 2, Game = 4, Info = 8}; /// create a new variable Cvar(const char* name, const unsigned int flags = 0); /*----- inspectors ------------------------------------------------ */ /// returns the name of the variable inline const std::string& name() const { return cvar_name; } /// returns the info of the variable inline const std::string& info() const { return cvar_info; } /// returns the flags of the variable inline const unsigned int flags() const { return cvar_flags; } /// returns the float value of the variable inline const float value() const { return cvar_value; } /// returns the string value of the variable inline const std::string& str() const { return cvar_str; } /*----- mutators -------------------------------------------------- */ /// set the info string void set_info(const char* info); /// std::string assignment void assign(const std::string& other); /// char * assignment void assign(const char* other); /// float assignment void assign(const float other); /// std::string assignment operator inline Cvar & operator=(const std::string& other) { assign(other); return (*this); } /// char * assignment operator inline Cvar & operator=(const char* other) { assign(other); return (*this); } /// float assignment operator inline Cvar & operator=(const float other) { assign(other); return (*this); } /* ---- Static functions for the Cvar registry -------------------- */ /// type definition for the Cvar registry typedef std::map Registry; /** * @brief get a cvar value from the registry * If the a cvar with the given name already exists in the registry, * its value will not be changed. If the cvar does not exist, * it will be created */ static Cvar* get(const char* name, const char* value, const unsigned int flags = 0); /** * @brief get a cvar value from the registry * If the a cvar with the given name already exists in the registry, * its value will not be changed. If the cvar does not exist, * it will be created */ static Cvar* get(const char* name, const float value, const unsigned int flags = 0); /** * @brief set a cvar value * If the a cvar with the given name already exists in the registry, * its value will be replaced */ static Cvar* set(const char* name, const char* value, const unsigned int flags = 0); /** * @brief set a cvar value * If the a cvar with the given name already exists in the registry, * its value will be replaced */ static Cvar* set(const char* name, const float value, const unsigned int flags = 0); /// search for a named cvar, returns 0 if not found static Cvar* find(const std::string& name); /// search for a named cvar, returns 0 if not found static Cvar* find(const char* name); /// delete a cvar from the registry static void unset(const char* name); /// delete a cvar from the registry static void unset(const std::string& name); /// list the cvar registry static void list(); /// the cvar registry static inline Registry & registry() { return cvar_registry; } static Cvar *sv_dedicated; // dedicated server static Cvar *sv_private; // client with private server static Cvar *sv_framerate; // server framerate static Cvar *sv_name; // server name static Cvar *sv_description; // server description static Cvar *sv_password; // server rcon password static Cvar *sv_keepalive; // entity keepalive timeout static Cvar *sv_collisionmargin; // bullet collision margin static Cvar *con_ansi; // console ANSI colors static Cvar *con_timestamps;// console timestamps static Cvar *net_host; // network server ip (default binds to all interfaces) static Cvar *net_port; // network port static Cvar *net_maxclients;// maximum number of connected clients static Cvar *net_timeout; // network timeout in seconds static Cvar *net_framerate; // client network send framerate static Cvar *net_selecttimeout; // timeout for select() call, in microseconds static Cvar *mem_vertex; // amount of video memory reserved for model geometry, in megabytes private: std::string cvar_name; std::string cvar_info; std::string cvar_str; unsigned int cvar_flags; float cvar_value; static Registry cvar_registry; }; } #endif // __INCLUDED_CORE_CVAR_H__