Game Development Reference
With the base templated runtime_variable_type class in place, we can begin creating the
different specializations we may need, int, float, bool, string, vector and std::function
would provide the functionality for the vast majority of situations, though it's possible to
specialize types that are more specific to your games.
Runtime Variable Database
In order to be able to search for runtime variables when we type their name in the console
we will have to keep track of them somewhere. We will create a database and anytime we
create a runtime variable we will automatically register it to the database. We only need a
single database for all runtime variables, so we can make it a static member of the runtime
variable, this makes it straightforward to register runtime variables as they are constructed.
runtime_variable::runtime_variable(const std::string& name, const std::string description)
but this doesn't give us a lot of flexibility or performance if we want to implement some
nice features, like auto completion.
We can implement auto completion for runtime variables by creating a trie that holds all
the names of every runtime variable we create, the runtime variable database will keep this
trie and whenever we register a runtime variable we will add its name into it.
The auto completion feature is implemented within the Text Box control, we will then just
need to pass in our database's trie to the console's text box and it will magically work, for
reference, here is where the magic happens.
void textbox::AutoComplete(bool reset = false)
if ( reset || m_currentResult == nullptr )
m_currentResult = m_trie->find_prefix(m_text);
if ( m_currentResult != nullptr )