Navigation Menu

Skip to content

Commit

Permalink
Added virtual input device state visuals for debugging controls
Browse files Browse the repository at this point in the history
Presently these visuals are only available in _DEBUG builds. Enable
them using the following cvars:

rend-dev-input-joy-state
rend-dev-input-key-state
rend-dev-input-mouse-state

The keyboard visual employs the standard American English key layout
to match the engine's assumed key layout on Windows.

The other visuals simply list the controls in a logical order.

Todo for later: Extend these visuals so they can be used by users in
an interactive control setup UI within the engine.

Todo for later: Implement a drawer for axis and hat controls.
  • Loading branch information
danij-deng committed Feb 14, 2012
1 parent 8315b37 commit 04e3cae
Show file tree
Hide file tree
Showing 5 changed files with 837 additions and 81 deletions.
8 changes: 6 additions & 2 deletions doomsday/engine/portable/include/b_main.h
Expand Up @@ -48,9 +48,13 @@ struct dbinding_s* B_BindControl(const char* controlDesc, const char* device);
struct dbinding_s* B_GetControlDeviceBindings(int localNum, int control, struct bcontext_s** bContext);

// Utils
/// \todo: move to b_util.h
/// @todo: move to b_util.h
int B_NewIdentifier(void);

const char* B_ShortNameForKey2(int ddKey, boolean forceLowercase);
const char* B_ShortNameForKey(int ddkey);

int B_KeyForShortName(const char* key);

int DD_GetKeyCode(const char* key);
#endif /* LIBDENG_BIND_MAIN_H */
#endif /// LIBDENG_BIND_MAIN_H
99 changes: 91 additions & 8 deletions doomsday/engine/portable/include/dd_input.h
Expand Up @@ -31,6 +31,10 @@

#define NUMKKEYS 256

#if _DEBUG
# include "point.h" // For the debug visual.
#endif

// Input devices.
enum
{
Expand All @@ -43,6 +47,14 @@ enum
NUM_INPUT_DEVICES // Theoretical maximum.
};

// Input device control types
typedef enum {
IDC_KEY,
IDC_AXIS,
IDC_HAT,
NUM_INPUT_DEVICE_CONTROL_TYPES
} inputdev_controltype_t;

typedef enum ddeventtype_e {
E_TOGGLE, // Two-state device
E_AXIS, // Axis position
Expand Down Expand Up @@ -153,6 +165,7 @@ typedef struct inputdevhat_s {
#define ID_ACTIVE 0x1 // The input device is active.

typedef struct inputdev_s {
char niceName[40]; // Human-friendly name of the device.
char name[20]; // Symbolic name of the device.
int flags;
uint numAxes; // Number of axes in this input device.
Expand Down Expand Up @@ -196,15 +209,85 @@ void I_InitVirtualInputDevices(void);
void I_ShutdownInputDevices(void);
void I_ClearDeviceContextAssociations(void);
void I_DeviceReset(uint ident);
inputdev_t *I_GetDevice(uint ident, boolean ifactive);
inputdev_t *I_GetDeviceByName(const char *name, boolean ifactive);
boolean I_ParseDeviceAxis(const char* str, uint* deviceID, uint* axis);
inputdevaxis_t *I_GetAxisByID(inputdev_t *device, uint id);
int I_GetAxisByName(inputdev_t *device, const char *name);
int I_GetKeyByName(inputdev_t* device, const char* name);
float I_TransformAxis(inputdev_t* dev, uint axis, float rawPos);
boolean I_IsDeviceKeyDown(uint ident, uint code);

inputdev_t* I_GetDevice(uint ident, boolean ifactive);
inputdev_t* I_GetDeviceByName(const char* name, boolean ifactive);

float I_TransformAxis(inputdev_t* dev, uint axis, float rawPos);

/**
* Check through the axes registered for the given device, see if there is
* one identified by the given name.
*
* @return @c false, if the string is invalid.
*/
boolean I_ParseDeviceAxis(const char* str, uint* deviceID, uint* axis);

/**
* Retrieve the index of a device's axis by name.
*
* @param device Ptr to input device info, to get the axis index from.
* @param name Ptr to string containing the name to be searched for.
*
* @return Index of the device axis named; or -1, if not found.
*/
int I_GetAxisByName(inputdev_t* device, const char* name);

/**
* Retrieve a ptr to the device axis specified by id.
*
* @param device Ptr to input device info, to get the axis ptr from.
* @param id Axis index, to search for.
*
* @return Ptr to the device axis OR @c NULL, if not found.
*/
inputdevaxis_t* I_GetAxisByID(inputdev_t* device, uint id);

/**
* Retrieve the index of a device's key by name.
*
* @param device Ptr to input device info, to get the key index from.
* @param name Ptr to string containing the name to be searched for.
*
* @return Index of the device key named; or -1, if not found.
*/
int I_GetKeyByName(inputdev_t* device, const char* name);

/**
* Retrieve a ptr to the device key specified by id.
*
* @param device Ptr to input device info, to get the key ptr from.
* @param id Key index, to search for.
*
* @return Ptr to the device key OR @c NULL, if not found.
*/
inputdevkey_t* I_GetKeyByID(inputdev_t* device, uint id);

/**
* @return The key state from the downKeys array.
*/
boolean I_IsKeyDown(inputdev_t* device, uint id);

/**
* Retrieve a ptr to the device hat specified by id.
*
* @param device Ptr to input device info, to get the hat ptr from.
* @param id Hat index, to search for.
*
* @return Ptr to the device hat OR @c NULL, if not found.
*/
inputdevhat_t* I_GetHatByID(inputdev_t* device, uint id);

void I_SetUIMouseMode(boolean on);
void I_TrackInput(ddevent_t *ev, timespan_t ticLength);

#if _DEBUG
/**
* Render a visual representation of the current state of all input devices.
*/
void Rend_AllInputDeviceStateVisuals(void);
#else
# define Rend_AllInputDeviceStateVisuals
#endif

#endif /* LIBDENG_CORE_INPUT_H */
17 changes: 11 additions & 6 deletions doomsday/engine/portable/src/b_main.c
Expand Up @@ -1091,28 +1091,33 @@ binding_t *B_Bind(ddevent_t *ev, char *command, int control, uint bindContext)
}
#endif

const char *B_ShortNameForKey(int ddkey)
const char* B_ShortNameForKey2(int ddKey, boolean forceLowercase)
{
uint idx;
static char nameBuffer[40];
uint idx;

for(idx = 0; keyNames[idx].key; ++idx)
{
if(ddkey == keyNames[idx].key)
if(ddKey == keyNames[idx].key)
return keyNames[idx].name;
}

if(isalnum(ddkey))
if(isalnum(ddKey))
{
// Printable character, fabricate a single-character name.
nameBuffer[0] = tolower(ddkey);
nameBuffer[0] = forceLowercase? tolower(ddKey) : ddKey;
nameBuffer[1] = 0;
return nameBuffer;
}

return NULL;
}

const char* B_ShortNameForKey(int ddKey)
{
return B_ShortNameForKey2(ddKey, true/*force lowercase*/);
}

int B_KeyForShortName(const char *key)
{
uint idx;
Expand Down Expand Up @@ -1449,7 +1454,7 @@ static void queEventsForHeldControls(uint deviceID, uint classID)
// being pressed that have a binding in the context being
// enabled/disabled (classID)
if(!(com->command[EVS_DOWN] != NULL && bind->controlID >= 0 &&
I_IsDeviceKeyDown(deviceID, (uint) bind->controlID)))
I_IsKeyDown(dev, (uint) bind->controlID)))
continue;
break;
Expand Down

0 comments on commit 04e3cae

Please sign in to comment.