Skip to content

Commit

Permalink
InputSystem|Client: Re-initialize InputDevices during a game change
Browse files Browse the repository at this point in the history
Todo: Could observe App::GameChange?
  • Loading branch information
danij-deng committed Nov 2, 2014
1 parent 3cc8fae commit a4132cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/inputsystem.h
Expand Up @@ -60,6 +60,8 @@ class InputSystem : public de::System
*/
de::LoopResult forAllDevices(std::function<de::LoopResult (InputDevice &)> func) const;

void initAllDevices();

/**
* Returns @c true if the shift key of the keyboard is thought to be down.
* @todo: Refactor away
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -1551,6 +1551,10 @@ bool App_ChangeGame(Game &game, bool allowReload)

R_InitSvgs();

#ifdef __CLIENT__
ClientApp::inputSystem().initAllDevices();
#endif

#ifdef __CLIENT__
R_InitViewWindow();
#endif
Expand Down
51 changes: 32 additions & 19 deletions doomsday/client/src/ui/inputsystem.cpp
Expand Up @@ -307,31 +307,20 @@ DENG2_PIMPL(InputSystem)

// Initialize system APIs.
I_InitInterfaces();

// Initialize devices.
addDevice(makeKeyboard("key", "Keyboard"))->activate(); // A keyboard is assumed to always be present.

addDevice(makeMouse("mouse", "Mouse"))->activate(Mouse_IsPresent()); // A mouse may not be present.

addDevice(makeJoystick("joy", "Joystick"))->activate(Joystick_IsPresent()); // A joystick may not be present.

/// @todo: Add support for multiple joysticks (just some generics, for now).
addDevice(new InputDevice("joy2"));
addDevice(new InputDevice("joy3"));
addDevice(new InputDevice("joy4"));

addDevice(makeHeadTracker("head", "Head Tracker")); // Head trackers are activated later.

// Register console variables for the controls of all devices.
for(InputDevice *device : devices) device->consoleRegister();
}

~Instance()
{
qDeleteAll(devices);
clearAllDevices();
I_ShutdownInterfaces();
}

void clearAllDevices()
{
qDeleteAll(devices);
devices.clear();
}

/**
* @param device InputDevice to add.
* @return Same as @a device for caller convenience.
Expand Down Expand Up @@ -705,7 +694,9 @@ DENG2_PIMPL(InputSystem)
};

InputSystem::InputSystem() : d(new Instance(this))
{}
{
initAllDevices();
}

void InputSystem::timeChanged(Clock const &)
{}
Expand Down Expand Up @@ -742,6 +733,28 @@ LoopResult InputSystem::forAllDevices(std::function<LoopResult (InputDevice &)>
return LoopContinue;
}

void InputSystem::initAllDevices()
{
d->clearAllDevices();

// Initialize devices.
d->addDevice(makeKeyboard("key", "Keyboard"))->activate(); // A keyboard is assumed to always be present.

d->addDevice(makeMouse("mouse", "Mouse"))->activate(Mouse_IsPresent()); // A mouse may not be present.

d->addDevice(makeJoystick("joy", "Joystick"))->activate(Joystick_IsPresent()); // A joystick may not be present.

/// @todo: Add support for multiple joysticks (just some generics, for now).
d->addDevice(new InputDevice("joy2"));
d->addDevice(new InputDevice("joy3"));
d->addDevice(new InputDevice("joy4"));

d->addDevice(makeHeadTracker("head", "Head Tracker")); // Head trackers are activated later.

// Register console variables for the controls of all devices.
for(InputDevice *device : d->devices) device->consoleRegister();
}

void InputSystem::trackEvent(ddevent_t *ev)
{
DENG2_ASSERT(ev);
Expand Down

0 comments on commit a4132cf

Please sign in to comment.