[Orxonox-commit 121] r2814 - in branches/gui/src: core/input orxonox/gamestates orxonox/gui orxonox/overlays/console
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Mar 21 17:30:16 CET 2009
Author: rgrieder
Date: 2009-03-21 16:30:16 +0000 (Sat, 21 Mar 2009)
New Revision: 2814
Modified:
branches/gui/src/core/input/InputManager.cc
branches/gui/src/core/input/InputManager.h
branches/gui/src/orxonox/gamestates/GSLevel.cc
branches/gui/src/orxonox/gui/GUIManager.cc
branches/gui/src/orxonox/overlays/console/InGameConsole.cc
Log:
InputManager upgrade number one: InputState priorities are managed automatically. However you can still use the enum in InputManager.h and get yourself a high priority.
High priorities are only to be used for special cases like calibrator, console or detector.
All other states are simply pushed onto the normal stack.
Modified: branches/gui/src/core/input/InputManager.cc
===================================================================
--- branches/gui/src/core/input/InputManager.cc 2009-03-21 14:28:07 UTC (rev 2813)
+++ branches/gui/src/core/input/InputManager.cc 2009-03-21 16:30:16 UTC (rev 2814)
@@ -173,7 +173,7 @@
paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
//paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
//paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
-#if defined OIS_LINUX_PLATFORM
+#if defined ORXONOX_PLATFORM_LINUX
paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
paramList.insert(std::make_pair(std::string("x11_mouse_hide"), "true"));
@@ -218,7 +218,7 @@
CCOUT(4) << "Initialising InputStates components..." << std::endl;
// Lowest priority empty InputState
- stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
+ stateEmpty_ = createInputState<SimpleInputState>("empty", InputStatePriority::Empty);
stateEmpty_->setHandler(&EMPTY_HANDLER);
activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
@@ -228,12 +228,12 @@
stateMaster_->setNumOfJoySticks(joySticksSize_);
// KeyDetector to evaluate a pressed key's name
- SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
+ SimpleInputState* detector = createInputState<SimpleInputState>("detector", InputStatePriority::Detector);
keyDetector_ = new KeyDetector();
detector->setHandler(keyDetector_);
// Joy stick calibration helper callback
- SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);
+ SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", InputStatePriority::Calibrator);
calibrator->setHandler(&EMPTY_HANDLER);
calibratorCallbackBuffer_ = new InputBuffer();
calibratorCallbackBuffer_->registerListener(this, &InputManager::_completeCalibration, '\r', true);
@@ -427,8 +427,8 @@
activeStatesTop_.resize(devicesNum_);
// inform all states
- for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
- it != inputStatesByPriority_.end(); ++it)
+ for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin();
+ it != inputStatesByName_.end(); ++it)
{
it->second->setNumOfJoySticks(joySticksSize_);
}
@@ -554,8 +554,8 @@
delete stateMaster_;
// destroy all user InputStates
- while (inputStatesByPriority_.size() > 0)
- _destroyState((*inputStatesByPriority_.rbegin()).second);
+ while (inputStatesByName_.size() > 0)
+ _destroyState((*inputStatesByName_.rbegin()).second);
// destroy the devices
_destroyKeyboard();
@@ -639,7 +639,6 @@
this->activeStates_.erase(it);
_updateActiveStates();
}
- inputStatesByPriority_.erase(state->getPriority());
inputStatesByName_.erase(state->getName());
delete state;
}
@@ -767,6 +766,8 @@
assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
activeStates_.erase((*rit)->getPriority());
+ if ((*rit)->getPriority() < InputStatePriority::HighPriority)
+ (*rit)->setPriority(0);
_updateActiveStates();
}
stateLeaveRequests_.clear();
@@ -781,6 +782,22 @@
// just to be sure that the state actually is registered
assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
+ if ((*rit)->getPriority() == 0)
+ {
+ // Get smallest possible priority between 1 and maxStateStackSize_s
+ for(std::map<int, InputState*>::const_reverse_iterator rit2 = activeStates_.rbegin();
+ rit2 != activeStates_.rend(); ++rit2)
+ {
+ if (rit2->first < InputStatePriority::HighPriority)
+ {
+ (*rit)->setPriority(rit2->first + 1);
+ break;
+ }
+ }
+ // In case no normal handler was on the stack
+ if ((*rit)->getPriority() == 0)
+ (*rit)->setPriority(1);
+ }
activeStates_[(*rit)->getPriority()] = (*rit);
_updateActiveStates();
(*rit)->onEnter();
@@ -812,7 +829,7 @@
if (bUpdateRequired)
_updateActiveStates();
- // mark that we capture and distribute input
+ // mark that we now start capturing and distributing input
internalState_ |= Ticking;
// Capture all the input. This calls the event handlers in InputManager.
@@ -1245,7 +1262,9 @@
@param name
Unique name of the handler.
@param priority
- Unique integer number. Higher means more prioritised.
+ Determines which InputState gets the input. Higher is better.
+ Use 0 to handle it implicitely by the order of activation.
+ Otherwise numbers larger than maxStateStackSize_s have to be used!
@return
True if added, false if name or priority already existed.
*/
@@ -1257,22 +1276,26 @@
return false;
if (inputStatesByName_.find(name) == inputStatesByName_.end())
{
- if (inputStatesByPriority_.find(priority)
- == inputStatesByPriority_.end())
+ if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
{
- inputStatesByName_[name] = state;
- inputStatesByPriority_[priority] = state;
- state->setNumOfJoySticks(numberOfJoySticks());
- state->setName(name);
+ // Make sure we don't add two high priority states with the same priority
+ for (std::map<std::string, InputState*>::const_iterator it = this->inputStatesByName_.begin();
+ it != this->inputStatesByName_.end(); ++it)
+ {
+ if (it->second->getPriority() == priority)
+ {
+ COUT(2) << "Warning: Could not add an InputState with the same priority '"
+ << priority << "' != 0." << std::endl;
+ return false;
+ }
+ }
+ }
+ inputStatesByName_[name] = state;
+ state->setNumOfJoySticks(numberOfJoySticks());
+ state->setName(name);
+ if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
state->setPriority(priority);
- return true;
- }
- else
- {
- COUT(2) << "Warning: Could not add an InputState with the same priority '"
- << priority << "'." << std::endl;
- return false;
- }
+ return true;
}
else
{
@@ -1371,7 +1394,7 @@
if (stateDestroyRequests_.find(it->second) == stateDestroyRequests_.end())
{
// not scheduled for destruction
- // set prevents a state being added multiple times
+ // prevents a state being added multiple times
stateEnterRequests_.insert(it->second);
return true;
}
@@ -1390,6 +1413,11 @@
*/
bool InputManager::requestLeaveState(const std::string& name)
{
+ if (name == "empty")
+ {
+ COUT(2) << "InputManager: Leaving the empty state is not allowed!" << std::endl;
+ return false;
+ }
// get pointer from the map with all stored handlers
std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
if (it != inputStatesByName_.end())
Modified: branches/gui/src/core/input/InputManager.h
===================================================================
--- branches/gui/src/core/input/InputManager.h 2009-03-21 14:28:07 UTC (rev 2813)
+++ branches/gui/src/core/input/InputManager.h 2009-03-21 16:30:16 UTC (rev 2814)
@@ -42,6 +42,7 @@
#include <vector>
#include <stack>
#include "util/Math.h"
+#include "util/OrxEnum.h"
#include "core/OrxonoxClass.h"
#include "InputInterfaces.h"
@@ -75,6 +76,19 @@
float negativeCoeff[24];
};
+ struct InputStatePriority : OrxEnum<InputStatePriority>
+ {
+ OrxEnumConstructors(InputStatePriority);
+
+ static const int Empty = -1;
+ static const int Dynamic = 0;
+
+ static const int HighPriority = 1000;
+ static const int Console = HighPriority + 0;
+ static const int Calibrator = HighPriority + 1;
+ static const int Detector = HighPriority + 2;
+ };
+
/**
@brief
Captures and distributes mouse and keyboard input.
@@ -115,7 +129,7 @@
void setKeyDetectorCallback(const std::string& command);
template <class T>
- T* createInputState(const std::string& name, int priority);
+ T* createInputState(const std::string& name, InputStatePriority priority = InputStatePriority::Dynamic);
InputState* getState (const std::string& name);
InputState* getCurrentState();
@@ -201,7 +215,6 @@
InputBuffer* calibratorCallbackBuffer_;
std::map<std::string, InputState*> inputStatesByName_;
- std::map<int, InputState*> inputStatesByPriority_;
std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state
std::set<InputState*> stateLeaveRequests_; //!< Request to leave a running state
@@ -248,7 +261,7 @@
number, but 1 - 99 is preferred (99 means high).
*/
template <class T>
- T* InputManager::createInputState(const std::string& name, int priority)
+ T* InputManager::createInputState(const std::string& name, InputStatePriority priority)
{
T* state = new T;
if (_configureInputState(state, name, priority))
Modified: branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-21 14:28:07 UTC (rev 2813)
+++ branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-21 16:30:16 UTC (rev 2814)
@@ -81,7 +81,7 @@
{
if (Core::showsGraphics())
{
- inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
+ inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
keyBinder_ = new KeyBinder();
keyBinder_->loadBindings("keybindings.ini");
inputState_->setHandler(keyBinder_);
Modified: branches/gui/src/orxonox/gui/GUIManager.cc
===================================================================
--- branches/gui/src/orxonox/gui/GUIManager.cc 2009-03-21 14:28:07 UTC (rev 2813)
+++ branches/gui/src/orxonox/gui/GUIManager.cc 2009-03-21 16:30:16 UTC (rev 2814)
@@ -166,7 +166,7 @@
tolua_Orxonox_open(this->scriptModule_->getLuaState());
// register us as input handler
- SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui", 30);
+ SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui");
state->setHandler(this);
state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
Modified: branches/gui/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- branches/gui/src/orxonox/overlays/console/InGameConsole.cc 2009-03-21 14:28:07 UTC (rev 2813)
+++ branches/gui/src/orxonox/overlays/console/InGameConsole.cc 2009-03-21 16:30:16 UTC (rev 2814)
@@ -172,7 +172,7 @@
void InGameConsole::initialise(int windowWidth, int windowHeight)
{
// create the corresponding input state
- inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40);
+ inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", InputStatePriority::Console);
inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
bHidesAllInputChanged();
More information about the Orxonox-commit
mailing list