Cafu Engine
ConVarT Class Reference

This class implements Console Variables ("convars"). More...

#include "ConVar.hpp"

Public Types

enum  TypeT { String, Integer, Bool, Double }
 
enum  FlagT {
  FLAG_ALL = -1, FLAG_MAIN_EXE = 0x0001, FLAG_MATSYS = 0x0002, FLAG_SOUNDSYS = 0x0004,
  FLAG_GAMEDLL = 0x0008, FLAG_USERINFO = 0x0010, FLAG_SERVERINFO = 0x0020, FLAG_NETWORK_SYNC = 0x0040,
  FLAG_CHEAT = 0x0080, FLAG_FOR_INIT = 0x0100, FLAG_READ_ONLY = 0x0200, FLAG_BY_CODE = 0x0400,
  FLAG_PERSISTENT = 0x0800
}
 

Public Member Functions

 ConVarT (const std::string &Name_, const std::string &Value_, const int Flags_, const std::string &Description_, const char **AllowedValues_=NULL)
 
 ConVarT (const std::string &Name_, const char *Value_, const int Flags_, const std::string &Description_, const char **AllowedValues_=NULL)
 
 ConVarT (const std::string &Name_, const int Value_, const int Flags_, const std::string &Description_, const int MinValue_=1, const int MaxValue_=-1)
 
 ConVarT (const std::string &Name_, const bool Value_, const int Flags_, const std::string &Description_)
 
 ConVarT (const std::string &Name_, const double Value_, const int Flags_, const std::string &Description_, const double MinValue_=1.0, const double MaxValue_=-1.0)
 
const std::string & GetName () const
 
const std::string & GetDescription () const
 
int GetFlags () const
 
TypeT GetType () const
 
const std::string & GetValueString () const
 
int GetValueInt () const
 
bool GetValueBool () const
 
double GetValueDouble () const
 
void SetValue (const std::string &Value_)
 
void SetValue (const char *Value_)
 
void SetValue (const int Value_)
 
void SetValue (const bool Value_)
 
void SetValue (const double Value_)
 
void operator= (const std::string &Value_)
 
void operator= (const char *Value_)
 
void operator= (const int Value_)
 
void operator= (const bool Value_)
 
void operator= (const double Value_)
 
bool HasBeenModified () const
 
void ClearModified ()
 

Static Public Member Functions

static void RegisterStaticList ()
 Registers all convars in the StaticList with the ConsoleInterpreter and invalidates the StaticList. More...
 

Friends

class ConsoleInterpreterImplT
 Give the implementation of the console interpreter full access. More...
 

Detailed Description

This class implements Console Variables ("convars").

A convar is a special variable that can be modified by the user at the game console and is globally accessible in the entire application.

In user code, a convar can be declared as a global variable or as a local, static variable. Use as a non-static local variable or on the heap (with new and delete) is also possible, but comes at a performance cost and is against the (gobal) nature of convars. Such a local variable would also never be visible at the console, and thus it makes no sense to have it.

a) Before ConVarT::RegisterStaticList() is called, all instantiated convars register themselves in a list that is global to the module, that is, the exe and each dll has its own list. b) Then, the ConsoleInterpreter pointer is set to point to the implementation of the ConsoleInterpreterI in the exe. (There is only exactly one "global" singleton ConsoleInterpreterI instance for the entire application.) c) Calling ConVarT::RegisterStaticList() then iterates over all (pointers to) convars in the per-module list, and for each tries to find a convar with the same name in the unique, application-global list inside the ConsoleInterpreter. d) Convars that are instantiated after the call to ConVarT::RegisterStaticList(), e.g. local static variables that are reached by the control-flow for the first time, automatically register themselves with the ConsoleInterpreter directly, rather than attempting to add themselves to the obsolete list from step a).

Member Enumeration Documentation

Enumerator
FLAG_USERINFO 

Sent from clients to the server.

FLAG_SERVERINFO 

Sent from servers to the clients.

FLAG_NETWORK_SYNC 

Value of this variable is sync'ed from the server to the clients.

FLAG_CHEAT 

Use of this variable is considered a cheat.

FLAG_FOR_INIT 

This variable is used during initialization, and can thus only be changed at the command-line, not at the console.

FLAG_READ_ONLY 

This variable is read-only, i.e. it cannot be modified by the user (neither in console nor at command-line).

FLAG_BY_CODE 

This variable has been statically declared by code, not by a user via the "set var xy" command.

FLAG_PERSISTENT 

This variable (and its value) is archived in a config file.

Member Function Documentation

void ConVarT::RegisterStaticList ( )
static

Registers all convars in the StaticList with the ConsoleInterpreter and invalidates the StaticList.

This has to be called after the ConsoleInterpreter pointer is set when the dll is first initialized! The ctors of all convars that are instantiated after this call (those that are declared as local (static) variables) then automatically register themselves with the ConsoleInterpreter rather than with the StaticList.

Friends And Related Function Documentation

friend class ConsoleInterpreterImplT
friend

Give the implementation of the console interpreter full access.


The documentation for this class was generated from the following files: