[Orxonox-commit 760] r3288 - branches/core4/src/core/input
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Jul 13 22:43:59 CEST 2009
Author: rgrieder
Date: 2009-07-13 22:43:59 +0200 (Mon, 13 Jul 2009)
New Revision: 3288
Modified:
branches/core4/src/core/input/InputManager.cc
branches/core4/src/core/input/InputState.cc
branches/core4/src/core/input/InputState.h
branches/core4/src/core/input/JoyStickQuantityListener.cc
branches/core4/src/core/input/JoyStickQuantityListener.h
branches/core4/src/core/input/KeyBinder.cc
branches/core4/src/core/input/KeyBinder.h
branches/core4/src/core/input/KeyDetector.cc
branches/core4/src/core/input/KeyDetector.h
Log:
Finally found a satisfying way to deal with interfaces that deliver information, but only upon virtual call.
The solution involves a static variable but any other (and uglier/hackier) solution will do so too.
I applied the method the the JoyStickQuantityListener so that the KeyBinder is now independent on the InputManager.
Modified: branches/core4/src/core/input/InputManager.cc
===================================================================
--- branches/core4/src/core/input/InputManager.cc 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/InputManager.cc 2009-07-13 20:43:59 UTC (rev 3288)
@@ -259,8 +259,10 @@
}
// inform all JoyStick Device Number Listeners
- for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it)
- it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
+ std::vector<JoyStick*> joyStickList;
+ for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
+ joyStickList.push_back(static_cast<JoyStick*>(devices_[i]));
+ JoyStickQuantityListener::changeJoyStickQuantity(joyStickList);
}
void InputManager::setKeyDetectorCallback(const std::string& command)
@@ -571,7 +573,6 @@
return 0;
if (statesByName_.find(name) == statesByName_.end())
{
- InputState* state = new InputState;
if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
{
// Make sure we don't add two high priority states with the same priority
@@ -582,17 +583,12 @@
{
COUT(2) << "Warning: Could not add an InputState with the same priority '"
<< static_cast<int>(priority) << "' != 0." << std::endl;
- return false;
+ return 0;
}
}
}
+ InputState* state = new InputState(name, bAlwaysGetsInput, bTransparent, priority);
statesByName_[name] = state;
- state->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
- state->setName(name);
- state->bAlwaysGetsInput_ = bAlwaysGetsInput;
- state->bTransparent_ = bTransparent;
- if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
- state->setPriority(priority);
return state;
}
Modified: branches/core4/src/core/input/InputState.cc
===================================================================
--- branches/core4/src/core/input/InputState.cc 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/InputState.cc 2009-07-13 20:43:59 UTC (rev 3288)
@@ -31,16 +31,22 @@
namespace orxonox
{
- InputState::InputState()
- : priority_(0)
- , bAlwaysGetsInput_(false)
- , bTransparent_(false)
+ InputState::InputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
+ : name_(name)
+ , bAlwaysGetsInput_(bAlwaysGetsInput)
+ , bTransparent_(bTransparent)
, bExpired_(true)
, handlers_(2)
, joyStickHandlerAll_(0)
, enterFunctor_(0)
, leaveFunctor_(0)
{
+ if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
+ priority_ = priority;
+ else
+ priority_ = 0;
+
+ handlers_.resize(InputDeviceEnumerator::FirstJoyStick + JoyStickQuantityListener::getJoyStickList().size(), NULL);
}
bool InputState::isInputDeviceEnabled(unsigned int device)
@@ -51,10 +57,10 @@
return false;
}
- void InputState::JoyStickQuantityChanged(unsigned int n)
+ void InputState::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
{
unsigned int oldSize = handlers_.size();
- handlers_.resize(InputDeviceEnumerator::FirstJoyStick + n, NULL);
+ handlers_.resize(InputDeviceEnumerator::FirstJoyStick + joyStickList.size(), NULL);
for (unsigned int i = oldSize; i < handlers_.size(); ++i)
handlers_[i] = joyStickHandlerAll_;
Modified: branches/core4/src/core/input/InputState.h
===================================================================
--- branches/core4/src/core/input/InputState.h 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/InputState.h 2009-07-13 20:43:59 UTC (rev 3288)
@@ -96,18 +96,17 @@
void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; }
private:
- InputState();
+ InputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority);
~InputState() { }
- void JoyStickQuantityChanged(unsigned int n);
+ void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
- void setName(const std::string& name) { name_ = name; }
- void setPriority(int priority) { priority_ = priority; }
+ void setPriority(int priority) { priority_ = priority; }
- std::string name_;
+ const std::string name_;
+ const bool bAlwaysGetsInput_;
+ const bool bTransparent_;
int priority_;
- bool bAlwaysGetsInput_;
- bool bTransparent_;
bool bExpired_;
std::vector<InputHandler*> handlers_;
InputHandler* joyStickHandlerAll_;
Modified: branches/core4/src/core/input/JoyStickQuantityListener.cc
===================================================================
--- branches/core4/src/core/input/JoyStickQuantityListener.cc 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/JoyStickQuantityListener.cc 2009-07-13 20:43:59 UTC (rev 3288)
@@ -27,12 +27,24 @@
*/
#include "JoyStickQuantityListener.h"
+
#include "core/CoreIncludes.h"
+#include "core/ObjectList.h"
namespace orxonox
{
+ std::vector<JoyStick*> JoyStickQuantityListener::joyStickList_s;
+
JoyStickQuantityListener::JoyStickQuantityListener()
{
RegisterObject(JoyStickQuantityListener);
}
+
+ //! Calls all registered objects and sets the static variable
+ /*static*/ void JoyStickQuantityListener::changeJoyStickQuantity(const std::vector<JoyStick*>& joyStickList)
+ {
+ joyStickList_s = joyStickList;
+ for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it)
+ it->JoyStickQuantityChanged(joyStickList);
+ }
}
Modified: branches/core4/src/core/input/JoyStickQuantityListener.h
===================================================================
--- branches/core4/src/core/input/JoyStickQuantityListener.h 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/JoyStickQuantityListener.h 2009-07-13 20:43:59 UTC (rev 3288)
@@ -42,12 +42,22 @@
//! Derive from this class to get informed when joy sticks get added/removed
class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass
{
+ friend InputManager;
public:
JoyStickQuantityListener();
virtual ~JoyStickQuantityListener() { }
- //! Called when joy sticks get added/removed
- virtual void JoyStickQuantityChanged(unsigned int value) = 0;
+ //! Returns a list with all JoySticks currently loaded
+ const std::vector<JoyStick*>& getJoyStickList() const { return joyStickList_s; }
+
+ private:
+ //! Called whenever joy sticks get added/removed
+ virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList) = 0;
+
+ static void changeJoyStickQuantity(const std::vector<JoyStick*>& joyStickList);
+
+ //! Static variable that holds the latest distributed information
+ static std::vector<JoyStick*> joyStickList_s;
};
}
Modified: branches/core4/src/core/input/KeyBinder.cc
===================================================================
--- branches/core4/src/core/input/KeyBinder.cc 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/KeyBinder.cc 2009-07-13 20:43:59 UTC (rev 3288)
@@ -39,7 +39,6 @@
#include "core/CoreIncludes.h"
#include "core/ConfigFileManager.h"
#include "InputCommands.h"
-#include "InputManager.h"
namespace orxonox
{
@@ -102,7 +101,7 @@
this->configFile_ = ConfigFileType::NoType;
// initialise joy sticks separatly to allow for reloading
- numberOfJoySticks_ = InputManager::getInstance().getJoyStickQuantity();
+ numberOfJoySticks_ = this->getJoyStickList().size();
initialiseJoyStickBindings();
// collect all Buttons and HalfAxes
@@ -154,10 +153,10 @@
allHalfAxes_[i]->buttonThreshold_ = this->buttonThreshold_;
}
- void KeyBinder::JoyStickQuantityChanged(unsigned int value)
+ void KeyBinder::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
{
unsigned int oldValue = numberOfJoySticks_;
- numberOfJoySticks_ = value;
+ numberOfJoySticks_ = joyStickList.size();
// initialise joy stick bindings
initialiseJoyStickBindings();
Modified: branches/core4/src/core/input/KeyBinder.h
===================================================================
--- branches/core4/src/core/input/KeyBinder.h 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/KeyBinder.h 2009-07-13 20:43:59 UTC (rev 3288)
@@ -75,7 +75,7 @@
void buttonThresholdChanged();
// from JoyStickQuantityListener interface
- virtual void JoyStickQuantityChanged(unsigned int value);
+ virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
void initialiseJoyStickBindings();
void compilePointerLists();
Modified: branches/core4/src/core/input/KeyDetector.cc
===================================================================
--- branches/core4/src/core/input/KeyDetector.cc 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/KeyDetector.cc 2009-07-13 20:43:59 UTC (rev 3288)
@@ -72,9 +72,9 @@
}
}
- void KeyDetector::JoyStickQuantityChanged(unsigned int value)
+ void KeyDetector::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
{
- KeyBinder::JoyStickQuantityChanged(value);
+ KeyBinder::JoyStickQuantityChanged(joyStickList);
setCallbackCommand(callbackCommand_);
}
}
Modified: branches/core4/src/core/input/KeyDetector.h
===================================================================
--- branches/core4/src/core/input/KeyDetector.h 2009-07-13 19:30:36 UTC (rev 3287)
+++ branches/core4/src/core/input/KeyDetector.h 2009-07-13 20:43:59 UTC (rev 3288)
@@ -48,7 +48,7 @@
KeyDetector();
~KeyDetector();
void setCallbackCommand(const std::string& command);
- void JoyStickQuantityChanged(unsigned int value);
+ void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
private:
std::string callbackCommand_;
More information about the Orxonox-commit
mailing list