Game Development Reference
In-Depth Information
it exists, we need to find the variable in the database, once we find it we will call Parse
on it, passing in only the parameters; no need to pass the variable's own name. Parse is a
pure virtual function of the class runtime_variable , it's required that any deriving classes
provide their own implementation, it will return true if parsing was successful and false if
the parameters did not meet the expectations of the variable.
If the Parse function returns true, we can add the text into the console as-is, otherwise we
display the name of the variable and the current value, we can also display the description
of the variable providing users with some built-in documentation. Finally, any text entered
into the console needs to be added to the input history, this allows us to recall previously
typed entries by pressing the up or down keys.
Runtime Commands
Oneofthe specializations that weprovided was for std::function ,unlike runtime variables,
is useful when you want to provide certain code that may execute regardless of the game
state, for example one such command would be take_screenshot , when you type this com-
(save the current frame buffer to file) and restore the console, other useful commands may
or teleport to a new location.
As an example, let's see at how to implement a runtime_variable_function that will clear
the console. The first part is to declare a runtime variable function as a member of the con-
sole class:
class console
. . .
runtime_variable_function m_clear;
We need to initialize our variable during the console's construction:
console::console(std::shared_ptr<core> core)
: m_core(core)
, m_clear(L"clear", L"Clears the console.", [&](std::vector<std::wstring>) -> bool { Clear(); return true; })
Search WWH ::

Custom Search