Skip to content

Commit

Permalink
Added the "console" class, which gets activated upon opening of the c…
Browse files Browse the repository at this point in the history
…onsole.

Binding classes can be marked for acquisition of the entire keyboard device. The "console" class uses this to prevent lower classes from reacting to the device states.
  • Loading branch information
skyjake committed Jul 30, 2007
1 parent 4252cef commit ed8570a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/b_class.h
Expand Up @@ -43,6 +43,8 @@ typedef struct controlbinding_s {
typedef struct bclass_s {
char *name; // Name of the binding class.
boolean active; // The class is only used when it is active.
boolean acquireKeyboard; // Class has acquired all keyboard states, unless
// higher-priority classes override it.
evbinding_t commandBinds; // List of command bindings.
controlbinding_t controlBinds;
} bclass_t;
Expand All @@ -51,6 +53,7 @@ void B_UpdateDeviceStateAssociations(void);
bclass_t* B_NewClass(const char* name);
void B_DestroyAllClasses(void);
void B_ActivateClass(bclass_t* bc, boolean doActivate);
void B_AcquireKeyboard(bclass_t* bc, boolean doAcquire);
bclass_t* B_ClassByPos(int pos);
bclass_t* B_ClassByName(const char* name);
int B_ClassCount(void);
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/b_main.h
Expand Up @@ -28,6 +28,9 @@
#ifndef __DOOMSDAY_BIND_MAIN_H__
#define __DOOMSDAY_BIND_MAIN_H__

#define DEFAULT_BINDING_CLASS_NAME "game"
#define CONSOLE_BINDING_CLASS_NAME "console"

void B_Register(void);
void B_Init(void);
void B_Shutdown(void);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/de_console.h
Expand Up @@ -36,5 +36,6 @@
#include "con_busy.h"
#include "con_bar.h"
#include "b_main.h"
#include "b_class.h"

#endif
24 changes: 20 additions & 4 deletions doomsday/engine/portable/src/b_class.c
Expand Up @@ -89,7 +89,7 @@ void B_UpdateDeviceStateAssociations(void)
evbinding_t* eb;
controlbinding_t* conBin;
dbinding_t* db;
int i;
int i, k;

I_ClearDeviceClassAssociations();

Expand Down Expand Up @@ -128,10 +128,10 @@ void B_UpdateDeviceStateAssociations(void)
for(conBin = bc->controlBinds.next; conBin != &bc->controlBinds;
conBin = conBin->next)
{
for(i = 0; i < DDMAXPLAYERS; ++i)
for(k = 0; k < DDMAXPLAYERS; ++k)
{
// Associate all the device bindings.
for(db = conBin->deviceBinds[i].next; db != &conBin->deviceBinds[i];
for(db = conBin->deviceBinds[k].next; db != &conBin->deviceBinds[k];
db = db->next)
{
inputdev_t* dev = I_GetDevice(db->device, false);
Expand All @@ -155,6 +155,17 @@ void B_UpdateDeviceStateAssociations(void)
}
}
}

// If the class have made a broad device acquisition, mark all relevant states.
if(bc->acquireKeyboard)
{
inputdev_t* dev = I_GetDevice(IDEV_KEYBOARD, false);
for(k = 0; k < dev->numKeys; ++k)
{
if(!dev->keys[k].bClass)
dev->keys[k].bClass = bc;
}
}
}
}

Expand Down Expand Up @@ -192,7 +203,6 @@ bclass_t* B_NewClass(const char* name)
bclass_t* bc = M_Calloc(sizeof(bclass_t));

bc->name = strdup(name);
bc->active = false;
B_InitCommandBindingList(&bc->commandBinds);
B_InitControlBindingList(&bc->controlBinds);
B_InsertClass(bc, 0);
Expand All @@ -219,6 +229,12 @@ void B_ActivateClass(bclass_t* bc, boolean doActivate)
B_UpdateDeviceStateAssociations();
}

void B_AcquireKeyboard(bclass_t* bc, boolean doAcquire)
{
bc->acquireKeyboard = doAcquire;
B_UpdateDeviceStateAssociations();
}

bclass_t* B_ClassByName(const char* name)
{
int i;
Expand Down
11 changes: 6 additions & 5 deletions doomsday/engine/portable/src/b_main.c
Expand Up @@ -34,17 +34,13 @@
#include "de_misc.h"
#include "de_play.h"

#include "b_class.h"
#include "b_command.h"
#include "p_control.h"

#include <ctype.h>

// MACROS ------------------------------------------------------------------

#define DEFAULT_BINDING_CLASS_NAME "game"
#define CONSOLE_BINDING_CLASS_NAME "console"

// TYPES -------------------------------------------------------------------

typedef struct {
Expand Down Expand Up @@ -259,8 +255,13 @@ void B_Register(void)
*/
void B_Init(void)
{
bclass_t* bc;

B_NewClass(DEFAULT_BINDING_CLASS_NAME);
B_NewClass(CONSOLE_BINDING_CLASS_NAME);

// Binding class for the console.
bc = B_NewClass(CONSOLE_BINDING_CLASS_NAME);
B_AcquireKeyboard(bc, true); // Console takes over all keyboard events.
/*
B_BindCommand("joy-hat-angle3", "print {angle 3}");
B_BindCommand("joy-hat-center", "print center");
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/portable/src/con_main.c
Expand Up @@ -1248,12 +1248,16 @@ void Con_Open(int yes)
{
ConsoleActive = true;
ConsoleTime = 0;

B_ActivateClass(B_ClassByName(CONSOLE_BINDING_CLASS_NAME), true);
}
else
{
memset(cmdLine, 0, sizeof(cmdLine));
cmdCursor = 0;
ConsoleActive = false;

B_ActivateClass(B_ClassByName(CONSOLE_BINDING_CLASS_NAME), false);
}
}

Expand Down

0 comments on commit ed8570a

Please sign in to comment.