Game Development Reference
In-Depth Information
Optimization hint: The description string is only useful for documentation, such as provid-
ing a “help” command that displays, for systems with strict memory requirements this
could be stripped out using a preprocessor directive (e.g. #if BUILD_SHIPPING),
however, if the game design allows the player to use the in-game console, then we would
want to keep the description as it's useful documentation for players or modders to access.
The Parse function needs to be implemented by the specialized classes, this function will
receive a string and from it, it must be able to recognize the value and apply it on itself.
This is the function that will translate what the player typed in the console into the value
we apply on the runtime variable itself.
We will define a templated base class that will be the foundation for any runtime variable
type we chose to implement.
template <typename T, runtime_variable::eType type = Undefined>
class runtime_variable_type : public runtime_variable
{
protected:
T m_value;
T m_minValue;
T m_maxValue;
T m_defaultValue;
runtime_variable::eType m_type;
};
ThefirsttemplateargumentTwilldeterminetheinternaltypetheruntimevariablewillrep-
resent, the simplest kind to implement will be the fundamental data types, int, float, bool
or any other basic type, however we will also implement a specialization that supports an
std::function in this sense, some runtime variables will in fact behave like runtime func-
tions or commands that we can invoke from a console, or remotely.
The second template argument is not strictly required, the system could exist without it; at
thecostofanincrease incodemaintenance, wegettheability tofilterruntimevariables by
type, as well as create a self-documenting system which would allow us to dump a listing
of all runtime variables, including their type.
The goal of the runtime variable type base class is to simplify as much as possible the
implementation of the specialized runtime variable types, for this reason we provide the
ability to set limits on a variable type, though the m_minValue and m_maxValue members.
Giventhatonlynumerictypeswillneedtotakeadvantageofthisfeaturewecancreatetwo
specializations of the Set function.
template <typename T>
Search WWH ::




Custom Search