Skip to content
Permalink
Browse files

Add cgame->engine calls for get/set console keys

  • Loading branch information
slipher committed Nov 28, 2019
1 parent f306070 commit 520a832806a9db681760ba1d3e782d65cb2afb08
Showing with 33 additions and 0 deletions.
  1. +2 −0 src/engine/client/cg_api.h
  2. +7 −0 src/engine/client/cg_msgdef.h
  3. +12 −0 src/engine/client/cl_cgame.cpp
  4. +12 −0 src/shared/client/cg_api.cpp
@@ -197,6 +197,8 @@ void trap_SetUserCmdValue( int stateValue, int flags, float sensitivi
int trap_Key_GetCatcher();
void trap_Key_SetCatcher( int catcher );
void trap_Key_SetBinding( Keyboard::Key key, int team, const char *cmd );
std::vector<Keyboard::Key> trap_Key_GetConsoleKeys();
void trap_Key_SetConsoleKeys(const std::vector<Keyboard::Key>& keys);
void trap_Key_ClearCmdButtons();
void trap_Key_ClearStates();
std::vector<bool> trap_Key_KeysDown( const std::vector<Keyboard::Key>& keys );
@@ -202,6 +202,8 @@ enum cgameImport_t
CG_KEY_GETCATCHER,
CG_KEY_SETCATCHER,
CG_KEY_GETKEYSFORBINDS,
CG_KEY_GETCONSOLEKEYS,
CG_KEY_SETCONSOLEKEYS,
CG_KEY_GETCHARFORSCANCODE,
CG_KEY_SETBINDING,
CG_KEY_CLEARSTATES,
@@ -437,6 +439,11 @@ namespace Keyboard {
IPC::Message<IPC::Id<VM::QVM, CG_KEY_GETKEYSFORBINDS>, int, std::vector<std::string>>,
IPC::Reply<std::vector<std::vector<Key>>>
>;
using GetConsoleKeysMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_KEY_GETCONSOLEKEYS>>,
IPC::Reply<std::vector<Key>>
>;
using SetConsoleKeysMsg = IPC::Message<IPC::Id<VM::QVM, CG_KEY_SETCONSOLEKEYS>, std::vector<Key>>;
using GetCharForScancodeMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_KEY_GETCHARFORSCANCODE>, int>,
IPC::Reply<int>
@@ -1411,6 +1411,18 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
});
break;

case CG_KEY_GETCONSOLEKEYS:
IPC::HandleMsg<Keyboard::GetConsoleKeysMsg>(channel, std::move(reader), [this] (std::vector<Keyboard::Key>& keys) {
keys = Keyboard::GetConsoleKeys();
});
break;

case CG_KEY_SETCONSOLEKEYS:
IPC::HandleMsg<Keyboard::SetConsoleKeysMsg>(channel, std::move(reader), [this] (const std::vector<Keyboard::Key>& keys) {
Keyboard::SetConsoleKeys(keys);
});
break;

case CG_KEY_CLEARCMDBUTTONS:
IPC::HandleMsg<Keyboard::ClearCmdButtonsMsg>(channel, std::move(reader), [this] {
CL_ClearCmdButtons();
@@ -584,6 +584,18 @@ void trap_Key_SetBinding( Keyboard::Key key, int team, const char *cmd )
VM::SendMsg<Keyboard::SetBindingMsg>(key, team, cmd);
}

std::vector<Keyboard::Key> trap_Key_GetConsoleKeys()
{
std::vector<Keyboard::Key> result;
VM::SendMsg<Keyboard::GetConsoleKeysMsg>(result);
return result;
}

void trap_Key_SetConsoleKeys(const std::vector<Keyboard::Key>& keys)
{
VM::SendMsg<Keyboard::SetConsoleKeysMsg>(keys);
}

void trap_Key_ClearCmdButtons()
{
VM::SendMsg<Keyboard::ClearCmdButtonsMsg>();

0 comments on commit 520a832

Please sign in to comment.
You can’t perform that action at this time.