Skip to content

Commit

Permalink
InputSystem|Client: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 10, 2014
1 parent 92bcf16 commit 0499a75
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 242 deletions.
4 changes: 0 additions & 4 deletions doomsday/client/include/ui/b_main.h
Expand Up @@ -22,8 +22,4 @@

void B_Init();

void B_BindDefaults();

void B_BindGameDefaults();

#endif // CLIENT_INPUTSYSTEM_BINDINGS_H
11 changes: 2 additions & 9 deletions doomsday/client/include/ui/b_util.h
Expand Up @@ -28,7 +28,7 @@ class BindContext;
class InputDevice;
struct ImpulseBinding;

// Event Binding Toggle State
// Event Binding State
enum ebstate_t
{
EBTOG_UNDEFINED,
Expand Down Expand Up @@ -81,7 +81,7 @@ bool B_ParseStateCondition(statecondition_t *cond, char const *desc);

// ---------------------------------------------------------------------------------

de::String B_ControlDescToString(InputDevice const &device, ddeventtype_t type, int id);
de::String B_ControlDescToString(int deviceId, ddeventtype_t type, int id);

de::String B_ToggleStateToString(ebstate_t state);

Expand Down Expand Up @@ -115,12 +115,5 @@ char const *B_ShortNameForKey(int ddKey, bool forceLowercase = true);

int B_KeyForShortName(char const *key);

/**
* @return Never returns zero, as that is reserved for list roots.
*/
int B_NewIdentifier();

void B_ResetIdentifiers();

#endif // CLIENT_INPUTSYSTEM_BINDING_UTILITIES_H

32 changes: 23 additions & 9 deletions doomsday/client/include/ui/inputsystem.h
Expand Up @@ -68,7 +68,12 @@ class InputSystem : public de::System
// System.
void timeChanged(de::Clock const &);

/**
public: // Input devices -----------------------------------------------------

/// Required/referenced input device is missing. @ingroup errors
DENG2_ERROR(MissingDeviceError);

/*
* Lookup an InputDevice by it's unique @a id.
*/
InputDevice &device(int id) const;
Expand Down Expand Up @@ -144,7 +149,7 @@ class InputSystem : public de::System
public:

static bool convertEvent(ddevent_t const &from, event_t &to);
static void convertEvent(de::Event const &from, ddevent_t &to);
static bool convertEvent(de::Event const &from, ddevent_t &to);

/**
* Updates virtual input device state.
Expand All @@ -169,6 +174,10 @@ class InputSystem : public de::System
/// Required/referenced binding context is missing. @ingroup errors
DENG2_ERROR(MissingContextError);

void bindDefaults();

void bindGameDefaults();

/**
* Try to make a new (console) command binding.
*
Expand Down Expand Up @@ -201,6 +210,11 @@ class InputSystem : public de::System
*/
bool removeBinding(int id);

/**
* Remove all bindings in all contexts.
*/
void removeAllBindings();

// ---

/**
Expand Down Expand Up @@ -257,17 +271,17 @@ class InputSystem : public de::System
*
* eventparams{+cond}*
*
* @param binding Command binding to configure.
* @param eventDesc Descriptor for event information and any additional conditions.
* @param command Console command to execute when triggered, if any.
* @param newId @c true= assign a new unique identifier.
* @param binding Command binding to configure.
* @param eventDesc Descriptor for event information and any additional conditions.
* @param command Console command to execute when triggered, if any.
* @param assignNewId @c true= assign a new unique identifier.
*
* @throws ConfigureError on failure. At which point @a binding should be considered
* to be in an undefined state. The caller may choose to clear and then reconfigure
* it using another descriptor.
*/
void configure(CommandBinding &binding, char const *eventDesc,
char const *command = nullptr, bool newId = false);
char const *command = nullptr, bool assignNewId = true);

/**
* Parse a device-control => player impulse trigger descriptor and configure the given
Expand All @@ -277,14 +291,14 @@ class InputSystem : public de::System
* @param ctrlDesc Descriptor for control information and any additional conditions.
* @param impulseId Identifier of the player impulse to execute when triggered, if any.
* @param localPlayer Local player number to execute the impulse for when triggered.
* @param newId @c true= assign a new unique identifier.
* @param assignNewId @c true= assign a new unique identifier.
*
* @throws ConfigureError on failure. At which point @a binding should be considered
* to be in an undefined state. The caller may choose to clear and then reconfigure
* it using another descriptor.
*/
void configure(ImpulseBinding &binding, char const *ctrlDesc,
int impulseId, int localPlayer, bool newId = false);
int impulseId, int localPlayer, bool assignNewId = true);

/**
* Does the opposite of the B_Parse* methods for event descriptor, including the
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -1230,7 +1230,7 @@ static int DD_ActivateGameWorker(void *context)

#ifdef __CLIENT__
// Apply default control bindings for this game.
B_BindGameDefaults();
ClientApp::inputSystem().bindGameDefaults();

// Read bindings for this game and merge with the working set.
Con_ParseCommands(App_CurrentGame().bindingConfig(), CPCF_ALLOW_SAVE_BINDINGS);
Expand Down Expand Up @@ -1516,7 +1516,7 @@ bool App_ChangeGame(Game &game, bool allowReload)
P_ImpulseShutdown();

Con_Execute(CMDS_DDAY, "clearbindings", true, false);
B_BindDefaults();
ClientApp::inputSystem().bindDefaults();
ClientApp::inputSystem().initialContextActivations();
#endif
// Reset the world back to it's initial state (unload the map, reset players, etc...).
Expand Down
26 changes: 1 addition & 25 deletions doomsday/client/src/ui/b_main.cpp
Expand Up @@ -21,9 +21,6 @@

#include "ui/b_main.h"

#include <doomsday/console/exec.h>
#include <doomsday/console/cmd.h>
#include <doomsday/console/var.h>
#include "dd_main.h" // App_GameLoaded
#include "dd_def.h"
#include "clientapp.h"
Expand Down Expand Up @@ -125,28 +122,7 @@ void B_Init()
*/

// Bind all the defaults for the engine only.
B_BindDefaults();
isys.bindDefaults();

isys.initialContextActivations();
}

void B_BindDefaults()
{
InputSystem &isys = ClientApp::inputSystem();

// Engine's highest priority context: opening control panel, opening the console.
isys.bindCommand("global:key-f11-down + key-alt-down", "releasemouse");
isys.bindCommand("global:key-f11-down", "togglefullscreen");
isys.bindCommand("global:key-tilde-down + key-shift-up", "taskbar");

// Console bindings (when open).
isys.bindCommand("console:key-tilde-down + key-shift-up", "taskbar"); // without this, key would be entered into command line

// Bias editor.
}

void B_BindGameDefaults()
{
if(!App_GameLoaded()) return;
Con_Executef(CMDS_DDAY, false, "defaultgamebindings");
}

0 comments on commit 0499a75

Please sign in to comment.