Added cmdRemove.

This commit is contained in:
Бранимир Караџић
2021-10-26 18:20:35 -07:00
parent 89c8e61abd
commit 53772163f4
4 changed files with 40 additions and 9 deletions

View File

@@ -29,12 +29,24 @@ struct CmdContext
void add(const char* _name, ConsoleFn _fn, void* _userData)
{
uint32_t cmd = bx::hash<bx::HashMurmur2A>(_name, (uint32_t)bx::strLen(_name) );
const uint32_t cmd = bx::hash<bx::HashMurmur2A>(_name, (uint32_t)bx::strLen(_name) );
BX_ASSERT(m_lookup.end() == m_lookup.find(cmd), "Command \"%s\" already exist.", _name);
Func fn = { _fn, _userData };
m_lookup.insert(stl::make_pair(cmd, fn) );
}
void remove(const char* _name)
{
const uint32_t cmd = bx::hash<bx::HashMurmur2A>(_name, (uint32_t)bx::strLen(_name) );
CmdLookup::iterator it = m_lookup.find(cmd);
if (it != m_lookup.end() )
{
m_lookup.erase(it);
}
}
void exec(const char* _cmd)
{
for (bx::StringView next(_cmd); !next.isEmpty(); _cmd = next.getPtr() )
@@ -105,6 +117,11 @@ void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData)
s_cmdContext->add(_name, _fn, _userData);
}
void cmdRemove(const char* _name)
{
s_cmdContext->remove(_name);
}
void cmdExec(const char* _format, ...)
{
char tmp[2048];