Skip to content

Commit

Permalink
InputSystem|Bindings|Client: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 4, 2014
1 parent 2d7c218 commit d552ba6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/dd_main.h
Expand Up @@ -61,7 +61,9 @@ extern GETGAMEAPI GetGameAPI;

extern int gameDataFormat;

#ifdef __CLIENT__
extern int symbolicEchoMode;
#endif

int DD_EarlyInit(void);
void DD_FinishInitializationAfterWindowReady(void);
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/ui/b_util.h
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions doomsday/client/src/ui/b_main.cpp
Expand Up @@ -39,8 +39,6 @@

using namespace de;

int symbolicEchoMode = false;

/**
* Binding context fallback for the "global" context.
*
Expand Down Expand Up @@ -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]);
}
52 changes: 27 additions & 25 deletions doomsday/client/src/ui/bindcontext.cpp
Expand Up @@ -22,17 +22,21 @@

#include <cstring>
#include <de/memory.h>
#include <QSet>
#include <de/Log>
#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;

Expand All @@ -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<int> DeviceIds;
DeviceIds acquireDevices;
bool acquireAllDevices = false; ///< @c true= will ignore @var acquireDevices.

cbinding_t commandBinds;
controlbinding_t controlBinds;

DDFallbackResponderFunc ddFallbackResponder = nullptr;
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions doomsday/client/src/ui/inputsystem.cpp
Expand Up @@ -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();

/*
Expand Down Expand Up @@ -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) =
{
Expand Down

0 comments on commit d552ba6

Please sign in to comment.