From d552ba68c8b876f83fa604485b6cdfd82ae8efcb Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 4 Nov 2014 16:15:18 +0000 Subject: [PATCH] InputSystem|Bindings|Client: Cleanup --- doomsday/client/include/dd_main.h | 2 + doomsday/client/include/ui/b_util.h | 2 - doomsday/client/src/dd_main.cpp | 4 ++ doomsday/client/src/ui/b_main.cpp | 10 ----- doomsday/client/src/ui/bindcontext.cpp | 52 +++++++++++++------------- doomsday/client/src/ui/inputsystem.cpp | 15 ++++---- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/doomsday/client/include/dd_main.h b/doomsday/client/include/dd_main.h index 16a21cb7ac..4679318294 100644 --- a/doomsday/client/include/dd_main.h +++ b/doomsday/client/include/dd_main.h @@ -61,7 +61,9 @@ extern GETGAMEAPI GetGameAPI; extern int gameDataFormat; +#ifdef __CLIENT__ extern int symbolicEchoMode; +#endif int DD_EarlyInit(void); void DD_FinishInitializationAfterWindowReady(void); diff --git a/doomsday/client/include/ui/b_util.h b/doomsday/client/include/ui/b_util.h index 7879c7e776..a084633ba1 100644 --- a/doomsday/client/include/ui/b_util.h +++ b/doomsday/client/include/ui/b_util.h @@ -63,8 +63,6 @@ struct statecondition_t } flags; }; -char const *B_ParseContext(char const *desc, BindContext **bc); - dd_bool B_ParseToggleState(char const *toggleName, ebstate_t *state); dd_bool B_ParseAxisPosition(char const *desc, ebstate_t *state, float *pos); diff --git a/doomsday/client/src/dd_main.cpp b/doomsday/client/src/dd_main.cpp index 0393007790..08d98a655b 100644 --- a/doomsday/client/src/dd_main.cpp +++ b/doomsday/client/src/dd_main.cpp @@ -177,6 +177,10 @@ finaleid_t titleFinale; int gameDataFormat; // Use a game-specifc data format where applicable. +#ifdef __CLIENT__ +int symbolicEchoMode = false; // Mutable via public API. +#endif + static void registerResourceFileTypes() { FileType *ftype; diff --git a/doomsday/client/src/ui/b_main.cpp b/doomsday/client/src/ui/b_main.cpp index 2038577968..87db8c1ad8 100644 --- a/doomsday/client/src/ui/b_main.cpp +++ b/doomsday/client/src/ui/b_main.cpp @@ -39,8 +39,6 @@ using namespace de; -int symbolicEchoMode = false; - /** * Binding context fallback for the "global" context. * @@ -178,11 +176,3 @@ dbinding_t *B_GetControlBindings(int localNum, int control, BindContext **bConte return nullptr; } - -#undef DD_GetKeyCode -DENG_EXTERN_C int DD_GetKeyCode(char const *key) -{ - DENG2_ASSERT(key); - int code = B_KeyForShortName(key); - return (code ? code : key[0]); -} diff --git a/doomsday/client/src/ui/bindcontext.cpp b/doomsday/client/src/ui/bindcontext.cpp index 7c5a9daeee..363480cc67 100644 --- a/doomsday/client/src/ui/bindcontext.cpp +++ b/doomsday/client/src/ui/bindcontext.cpp @@ -22,17 +22,21 @@ #include #include +#include #include #include "clientapp.h" -#include "dd_main.h" -#include "m_misc.h" +#include "m_misc.h" // M_WriteTextEsc + #include "ui/b_main.h" #include "ui/b_command.h" #include "ui/p_control.h" #include "ui/inputdevice.h" + +/// @todo: remove #include "ui/inputdeviceaxiscontrol.h" #include "ui/inputdevicebuttoncontrol.h" #include "ui/inputdevicehatcontrol.h" +// todo ends using namespace de; @@ -41,18 +45,18 @@ static inline InputSystem &inputSys() return ClientApp::inputSystem(); } -// Binding Context Flags: -#define BCF_ACTIVE 0x01 ///< Context is only used when it is active. -#define BCF_PROTECTED 0x02 ///< Context cannot be (de)activated by plugins. -#define BCF_ACQUIRE_KEYBOARD 0x04 /** Context has acquired all keyboard states, unless - higher-priority contexts override it. */ -#define BCF_ACQUIRE_ALL 0x08 ///< Context will acquire all unacquired states. - DENG2_PIMPL(BindContext) { - byte flags = 0; - String name; ///< Symbolic. - cbinding_t commandBinds; ///< List of command bindings. + bool active = false; ///< @c true= Bindings are active. + bool protect = false; ///< @c true= Prevent explicit end user (de)activation. + String name; ///< Symbolic. + + // Acquired device states, unless higher-priority contexts override. + typedef QSet DeviceIds; + DeviceIds acquireDevices; + bool acquireAllDevices = false; ///< @c true= will ignore @var acquireDevices. + + cbinding_t commandBinds; controlbinding_t controlBinds; DDFallbackResponderFunc ddFallbackResponder = nullptr; @@ -130,18 +134,17 @@ BindContext::~BindContext() bool BindContext::isActive() const { - return (d->flags & BCF_ACTIVE) != 0; + return d->active; } bool BindContext::isProtected() const { - return (d->flags & BCF_PROTECTED) != 0; + return d->protect; } void BindContext::protect(bool yes) { - if(yes) d->flags |= BCF_PROTECTED; - else d->flags &= ~BCF_PROTECTED; + d->protect = yes; } String BindContext::name() const @@ -160,12 +163,11 @@ void BindContext::activate(bool yes) << (yes? "Activating" : "Deactivating") << d->name; - d->flags &= ~BCF_ACTIVE; - if(yes) d->flags |= BCF_ACTIVE; + d->active = yes; inputSys().updateAllDeviceStateAssociations(); - if(d->flags & BCF_ACQUIRE_ALL) + if(d->acquireAllDevices) { inputSys().forAllDevices([] (InputDevice &device) { @@ -177,28 +179,28 @@ void BindContext::activate(bool yes) void BindContext::acquireKeyboard(bool yes) { - d->flags &= ~BCF_ACQUIRE_KEYBOARD; - if(yes) d->flags |= BCF_ACQUIRE_KEYBOARD; + if(yes) d->acquireDevices.insert(IDEV_KEYBOARD); + else d->acquireDevices.remove(IDEV_KEYBOARD); inputSys().updateAllDeviceStateAssociations(); } void BindContext::acquireAll(bool yes) { - d->flags &= ~BCF_ACQUIRE_ALL; - if(yes) d->flags |= BCF_ACQUIRE_ALL; + d->acquireAllDevices = yes; inputSys().updateAllDeviceStateAssociations(); } bool BindContext::willAcquireAll() const { - return (d->flags & BCF_ACQUIRE_ALL) != 0; + return d->acquireAllDevices; } bool BindContext::willAcquireKeyboard() const { - return (d->flags & BCF_ACQUIRE_KEYBOARD) != 0; + /// @todo: What about acquireAllDevices? (Ambiguous naming/usage). + return d->acquireDevices.contains(IDEV_KEYBOARD); } void BindContext::setDDFallbackResponder(DDFallbackResponderFunc newResponderFunc) diff --git a/doomsday/client/src/ui/inputsystem.cpp b/doomsday/client/src/ui/inputsystem.cpp index 5b8bd98ef4..a14374efd2 100644 --- a/doomsday/client/src/ui/inputsystem.cpp +++ b/doomsday/client/src/ui/inputsystem.cpp @@ -1068,13 +1068,10 @@ bool InputSystem::shiftDown() const void InputSystem::initialContextActivations() { // Deactivate all contexts. - for(BindContext *bc : d->contexts) - { - bc->deactivate(); - }; + for(BindContext *bc : d->contexts) bc->deactivate(); // These are the contexts active by default. - context(GLOBAL_BINDING_CONTEXT_NAME).activate(); + context(GLOBAL_BINDING_CONTEXT_NAME ).activate(); context(DEFAULT_BINDING_CONTEXT_NAME).activate(); /* @@ -1755,8 +1752,12 @@ void InputSystem::consoleRegister() // static #undef PROTECTED_FLAGS } -// b_main.c -DENG_EXTERN_C int DD_GetKeyCode(char const *key); +DENG_EXTERN_C int DD_GetKeyCode(char const *key) +{ + DENG2_ASSERT(key); + int code = B_KeyForShortName(key); + return (code ? code : key[0]); +} DENG_DECLARE_API(B) = {