Skip to content

Commit

Permalink
Refactor|InputSystem|Bindings|Client: Continued splitting up b_main.h…
Browse files Browse the repository at this point in the history
…/cpp
  • Loading branch information
danij-deng committed Nov 4, 2014
1 parent 5b79ff5 commit 2d7c218
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 575 deletions.
4 changes: 3 additions & 1 deletion doomsday/client/include/dd_main.h
Expand Up @@ -49,7 +49,7 @@ struct game_s;
extern int verbose;
//extern FILE* outFile; // Output file for console messages.

extern char* startupFiles; // A list of names of files to be autoloaded during startup, whitespace in between (in .cfg).
extern char *startupFiles; // A list of names of files to be autoloaded during startup, whitespace in between (in .cfg).

extern int isDedicated;

Expand All @@ -61,6 +61,8 @@ extern GETGAMEAPI GetGameAPI;

extern int gameDataFormat;

extern int symbolicEchoMode;

int DD_EarlyInit(void);
void DD_FinishInitializationAfterWindowReady(void);
dd_bool DD_Init(void);
Expand Down
49 changes: 0 additions & 49 deletions doomsday/client/include/ui/b_main.h
Expand Up @@ -25,16 +25,6 @@

class BindContext;
struct dbinding_t;
struct cbinding_t;

#define DEFAULT_BINDING_CONTEXT_NAME "game"
#define CONSOLE_BINDING_CONTEXT_NAME "console"
#define UI_BINDING_CONTEXT_NAME "deui"
#define GLOBAL_BINDING_CONTEXT_NAME "global"

extern int symbolicEchoMode;

void B_ConsoleRegister();

void B_Init();

Expand All @@ -43,49 +33,10 @@ void B_Init();
*/
void B_Shutdown();

dd_bool B_Delete(int bid);

/**
* Checks to see if we need to respond to the given input event in some way
* and then if so executes the action associated to the event.
*
* @param ev ddevent_t we may need to respond to.
*
* @return @c true if an action was executed.
*/
dd_bool B_Responder(ddevent_t *ev);

/**
* Dump all the bindings to a text (cfg) file. Outputs console commands.
*/
void B_WriteToFile(FILE *file);

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

void B_BindDefaults();

void B_BindGameDefaults();

cbinding_t *B_BindCommand(char const *eventDesc, char const *command);

dbinding_t *B_BindControl(char const *controlDesc, char const *device);

dbinding_t *B_GetControlBindings(int localNum, int control, BindContext **context);

bool B_UnbindCommand(char const *command);

/// Utils: @todo move to b_util.h ----------------------------------------------

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

char const *B_ShortNameForKey(int ddKey, dd_bool forceLowercase = true);

int B_KeyForShortName(char const *key);

#endif // CLIENT_INPUTSYSTEM_BINDINGS_H
13 changes: 13 additions & 0 deletions doomsday/client/include/ui/b_util.h
Expand Up @@ -63,6 +63,8 @@ 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 Expand Up @@ -110,5 +112,16 @@ void B_AppendConditionToString(statecondition_t const *cond, ddstring_t *str);
*/
void B_AppendEventToString(ddevent_t const *ev, ddstring_t *str);

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

void B_ResetIdentifiers();

char const *B_ShortNameForKey(int ddKey, dd_bool forceLowercase = true);

int B_KeyForShortName(char const *key);

#endif // CLIENT_INPUTSYSTEM_BINDING_UTILITIES_H

53 changes: 52 additions & 1 deletion doomsday/client/include/ui/inputsystem.h
Expand Up @@ -30,6 +30,13 @@

class BindContext;
class InputDevice;
struct cbinding_t;
struct dbinding_t;

#define DEFAULT_BINDING_CONTEXT_NAME "game"
#define CONSOLE_BINDING_CONTEXT_NAME "console"
#define UI_BINDING_CONTEXT_NAME "deui"
#define GLOBAL_BINDING_CONTEXT_NAME "global"

/**
* Input devices and events. @ingroup ui
Expand Down Expand Up @@ -63,6 +70,10 @@ class InputSystem : public de::System
*/
de::LoopResult forAllDevices(std::function<de::LoopResult (InputDevice &)> func) const;

/**
* (Re)initialize the input device models, returning all controls to their
* default states.
*/
void initAllDevices();

/**
Expand Down Expand Up @@ -111,11 +122,46 @@ class InputSystem : public de::System
*/
static void convertEvent(de::Event const &event, ddevent_t *ddEvent);

public: // Bindings ----------------------------------------------------------
public: // Binding (context) management --------------------------------------

/**
* Try to make a new command binding.
*
* @param eventDesc Textual descriptor for the event.
* @param command Console command(s) which the binding will execute when
* triggered, if a binding is created.
*
* @return Resultant command binding.
*/
cbinding_t *bindCommand(char const *eventDesc, char const *command);

bool unbindCommand(char const *command);

/**
* Try to make a new (player) control binding.
*
* @param controlDesc ?
* @param deviceDesc ?
*/
dbinding_t *bindControl(char const *controlDesc, char const *deviceDesc);

/**
* Try to remove the one unique binding associated with @a id.
*
* @return @c true if that binding was removed.
*/
bool removeBinding(int id);

// ---

/// Required/referenced binding context is missing. @ingroup errors
DENG2_ERROR(MissingContextError);

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

/**
* Destroy all binding contexts and the bindings within the contexts.
*/
Expand Down Expand Up @@ -180,6 +226,11 @@ class InputSystem : public de::System
*/
void updateAllDeviceStateAssociations();

/**
* Write all bindings in all contexts to a text (cfg) file. Outputs console commands.
*/
void writeAllBindingsTo(FILE *file);

public:
/**
* Register the console commands and variables of this module.
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/con_config.cpp
Expand Up @@ -35,6 +35,7 @@
#include <doomsday/filesys/fs_util.h>

#ifdef __CLIENT__
# include "clientapp.h"
# include "ui/b_main.h"
#endif

Expand Down Expand Up @@ -197,7 +198,7 @@ static bool writeBindingsState(Path const &filePath)
<< NativePath(filePath).pretty();

writeHeaderComment(file);
B_WriteToFile(file);
ClientApp::inputSystem().writeAllBindingsTo(file);
fclose(file);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Expand Up @@ -1513,7 +1513,7 @@ bool App_ChangeGame(Game &game, bool allowReload)

Con_Execute(CMDS_DDAY, "clearbindings", true, false);
B_BindDefaults();
B_InitialContextActivations();
ClientApp::inputSystem().initialContextActivations();
#endif
// Reset the world back to it's initial state (unload the map, reset players, etc...).
App_WorldSystem().reset();
Expand Down

0 comments on commit 2d7c218

Please sign in to comment.