Skip to content

Commit

Permalink
Added: "global" context for bindings that are globally active
Browse files Browse the repository at this point in the history
Bindings in the "global" context are always in effect. Moved the fullscreen
toggle and releasemouse bindings to the engine's default bindings.

Todo for later: Remove/relocate the special case handlers in dispatchEvents()
so that the bindings system actually gets all the events first.
  • Loading branch information
skyjake committed Apr 30, 2012
1 parent 8ac6fc4 commit f4d4dc3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
6 changes: 6 additions & 0 deletions doomsday/engine/portable/include/b_main.h
Expand Up @@ -32,6 +32,7 @@
#define DEFAULT_BINDING_CONTEXT_NAME "game"
#define CONSOLE_BINDING_CONTEXT_NAME "console"
#define UI_BINDING_CONTEXT_NAME "deui"
#define GLOBAL_BINDING_CONTEXT_NAME "global"

void B_Register(void);
void B_Init(void);
Expand All @@ -40,6 +41,11 @@ boolean B_Delete(int bid);
boolean B_Responder(ddevent_t* ev);
void B_WriteToFile(FILE* file);

/**
* Enable the contexts for the initial state.
*/
void B_InitialContextActivations(void);

void B_BindDefaults(void);
void B_BindGameDefaults(void);

Expand Down
30 changes: 29 additions & 1 deletion doomsday/engine/portable/src/b_main.c
Expand Up @@ -215,6 +215,13 @@ void B_Init(void)

// UI doesn't let anything past it.
B_AcquireAll(B_NewContext(UI_BINDING_CONTEXT_NAME), true);

// Top-level context that is always active and overrides every other context.
// To be used only for system-level functionality.
bc = B_NewContext(GLOBAL_BINDING_CONTEXT_NAME);
bc->flags |= BCF_PROTECTED;
B_ActivateContext(bc, true);

/*
B_BindCommand("joy-hat-angle3", "print {angle 3}");
B_BindCommand("joy-hat-center", "print center");
Expand Down Expand Up @@ -244,13 +251,34 @@ void B_Init(void)
// Bind all the defaults for the engine only.
B_BindDefaults();

// Enable the contexts for the initial state.
B_InitialContextActivations();
}

void B_InitialContextActivations(void)
{
int i;

// Disable all contexts.
for(i = 0; i < B_ContextCount(); ++i)
{
B_ActivateContext(B_ContextByPos(i), false);
}

// These are the contexts active by default.
B_ActivateContext(B_ContextByName(GLOBAL_BINDING_CONTEXT_NAME), true);
B_ActivateContext(B_ContextByName(DEFAULT_BINDING_CONTEXT_NAME), true);

if(Con_IsActive())
{
B_ActivateContext(B_ContextByName(CONSOLE_BINDING_CONTEXT_NAME), true);
}
}

void B_BindDefaults(void)
{
// Engine's highest priority context: opening control panel, opening the console.
B_BindCommand("global:key-f11-down + key-alt-down", "releasemouse");
B_BindCommand("global:key-f11-down", "togglefullscreen");

// Console bindings (when open).

Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/dd_input.c
Expand Up @@ -1054,10 +1054,10 @@ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength)
continue;
}

if(UI_Responder(ddev)) continue;
if(Con_Responder(ddev)) continue;
if(UI_Responder(ddev)) continue; /// @todo: use the bindings system (deui context fallback)
if(Con_Responder(ddev)) continue; /// @todo refactor: use the bindings system

if(callGameResponders)
if(callGameResponders) /// @todo refactor: use the bindings system (chat context fallback)
{
// The game's normal responder only returns true if the bindings can't
// be used (like when chatting).
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1109,6 +1109,8 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)

P_ControlShutdown();
Con_Execute(CMDS_DDAY, "clearbindings", true, false);
B_BindDefaults();
B_InitialContextActivations();

for(i = 0; i < DDMAXPLAYERS; ++i)
{
Expand Down
2 changes: 0 additions & 2 deletions doomsday/plugins/common/src/g_controls.c
Expand Up @@ -397,8 +397,6 @@ D_CMD(DefaultGameBinds)
"bindevent shortcut:key-f9 quickload",
"bindevent shortcut:key-f10 quit",
//"bindevent shortcut:key-f11 togglegamma",
"bindevent shortcut:key-f11+key-alt-down releasemouse",
"bindevent shortcut:key-f11 togglefullscreen",
"bindevent shortcut:key-print screenshot",
"bindevent shortcut:key-f12 screenshot",

Expand Down

0 comments on commit f4d4dc3

Please sign in to comment.