Commit b408932f authored by Ben Hymers's avatar Ben Hymers
Browse files

Add .gitattributes to control line endings, and normalise all existing files

parent c50bad3f
//{{NO_DEPENDENCIES}} //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file. // Microsoft Visual C++ generated include file.
// Used by OIS.rc // Used by OIS.rc
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif
#include "OIS.h" #include "OIS.h"
#include <math.h> #include <math.h>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <ios> #include <ios>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
using namespace std; using namespace std;
////////////////////////////////////Needed Windows Headers//////////// ////////////////////////////////////Needed Windows Headers////////////
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include "windows.h" # include "windows.h"
# include "resource.h" # include "resource.h"
////////////////////////////////////Needed Linux Headers////////////// ////////////////////////////////////Needed Linux Headers//////////////
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
# include <X11/Xlib.h> # include <X11/Xlib.h>
#else #else
# error Sorry, not yet implemented on this platform. # error Sorry, not yet implemented on this platform.
#endif #endif
using namespace OIS; using namespace OIS;
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
// The dialog proc we have to give to CreateDialog // The dialog proc we have to give to CreateDialog
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{ {
return FALSE; return FALSE;
} }
#endif #endif
//////////// Event handler class declaration //////////////////////////////////////////////// //////////// Event handler class declaration ////////////////////////////////////////////////
class Application; class Application;
class JoystickManager; class JoystickManager;
class EffectManager; class EffectManager;
class EventHandler : public KeyListener, public JoyStickListener class EventHandler : public KeyListener, public JoyStickListener
{ {
protected: protected:
Application* _pApplication; Application* _pApplication;
JoystickManager* _pJoystickMgr; JoystickManager* _pJoystickMgr;
EffectManager* _pEffectMgr; EffectManager* _pEffectMgr;
public: public:
EventHandler(Application* pApp); EventHandler(Application* pApp);
void initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr); void initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr);
bool keyPressed( const KeyEvent &arg ); bool keyPressed( const KeyEvent &arg );
bool keyReleased( const KeyEvent &arg ); bool keyReleased( const KeyEvent &arg );
bool buttonPressed( const JoyStickEvent &arg, int button ); bool buttonPressed( const JoyStickEvent &arg, int button );
bool buttonReleased( const JoyStickEvent &arg, int button ); bool buttonReleased( const JoyStickEvent &arg, int button );
bool axisMoved( const JoyStickEvent &arg, int axis ); bool axisMoved( const JoyStickEvent &arg, int axis );
bool povMoved( const JoyStickEvent &arg, int pov ); bool povMoved( const JoyStickEvent &arg, int pov );
}; };
//////////// Variable classes //////////////////////////////////////////////////////// //////////// Variable classes ////////////////////////////////////////////////////////
class Variable class Variable
{ {
protected: protected:
double _dInitValue; double _dInitValue;
double _dValue; double _dValue;
public: public:
Variable(double dInitValue) : _dInitValue(dInitValue) { reset(); } Variable(double dInitValue) : _dInitValue(dInitValue) { reset(); }
double getValue() const { return _dValue; } double getValue() const { return _dValue; }
void reset() { _dValue = _dInitValue; } void reset() { _dValue = _dInitValue; }
virtual void setValue(double dValue) { _dValue = dValue; } virtual void setValue(double dValue) { _dValue = dValue; }
virtual string toString() const virtual string toString() const
{ {
ostringstream oss; ostringstream oss;
oss << _dValue; oss << _dValue;
return oss.str(); return oss.str();
} }
virtual void update() {}; virtual void update() {};
}; };
class Constant : public Variable class Constant : public Variable
{ {
public: public:
Constant(double dInitValue) : Variable(dInitValue) {} Constant(double dInitValue) : Variable(dInitValue) {}
virtual void setValue(double dValue) { } virtual void setValue(double dValue) { }
}; };
class LimitedVariable : public Variable class LimitedVariable : public Variable
{ {
protected: protected:
double _dMinValue; double _dMinValue;
double _dMaxValue; double _dMaxValue;
public: public:
LimitedVariable(double dInitValue, double dMinValue, double dMaxValue) LimitedVariable(double dInitValue, double dMinValue, double dMaxValue)
: _dMinValue(dMinValue), _dMaxValue(dMaxValue), Variable(dInitValue) : _dMinValue(dMinValue), _dMaxValue(dMaxValue), Variable(dInitValue)
{} {}
virtual void setValue(double dValue) virtual void setValue(double dValue)
{ {
_dValue = dValue; _dValue = dValue;
if (_dValue > _dMaxValue) if (_dValue > _dMaxValue)
_dValue = _dMaxValue; _dValue = _dMaxValue;
else if (_dValue < _dMinValue) else if (_dValue < _dMinValue)
_dValue = _dMinValue; _dValue = _dMinValue;
} }
/* virtual string toString() const /* virtual string toString() const
{ {
ostringstream oss; ostringstream oss;
oss << setiosflags(ios_base::right) << setw(4) oss << setiosflags(ios_base::right) << setw(4)
<< (int)(200.0 * getValue()/(_dMaxValue - _dMinValue)); // [-100%, +100%] << (int)(200.0 * getValue()/(_dMaxValue - _dMinValue)); // [-100%, +100%]
return oss.str(); return oss.str();
}*/ }*/
}; };
class TriangleVariable : public LimitedVariable class TriangleVariable : public LimitedVariable
{ {
protected: protected:
double _dDeltaValue; double _dDeltaValue;
public: public:
TriangleVariable(double dInitValue, double dDeltaValue, double dMinValue, double dMaxValue) TriangleVariable(double dInitValue, double dDeltaValue, double dMinValue, double dMaxValue)
: LimitedVariable(dInitValue, dMinValue, dMaxValue), _dDeltaValue(dDeltaValue) {}; : LimitedVariable(dInitValue, dMinValue, dMaxValue), _dDeltaValue(dDeltaValue) {};
virtual void update() virtual void update()
{ {
double dValue = getValue() + _dDeltaValue; double dValue = getValue() + _dDeltaValue;
if (dValue > _dMaxValue) if (dValue > _dMaxValue)
{ {
dValue = _dMaxValue; dValue = _dMaxValue;
_dDeltaValue = -_dDeltaValue; _dDeltaValue = -_dDeltaValue;
//cout << "Decreasing variable towards " << _dMinValue << endl; //cout << "Decreasing variable towards " << _dMinValue << endl;
} }
else if (dValue < _dMinValue) else if (dValue < _dMinValue)
{ {
dValue = _dMinValue; dValue = _dMinValue;
_dDeltaValue = -_dDeltaValue; _dDeltaValue = -_dDeltaValue;
//cout << "Increasing variable towards " << _dMaxValue << endl; //cout << "Increasing variable towards " << _dMaxValue << endl;
} }
setValue(dValue); setValue(dValue);
//cout << "TriangleVariable::update : delta=" << _dDeltaValue << ", value=" << dValue << endl; //cout << "TriangleVariable::update : delta=" << _dDeltaValue << ", value=" << dValue << endl;
} }
}; };
//////////// Variable effect class ////////////////////////////////////////////////////////// //////////// Variable effect class //////////////////////////////////////////////////////////
typedef map<string, Variable*> MapVariables; typedef map<string, Variable*> MapVariables;
typedef void (*EffectVariablesApplier)(MapVariables& mapVars, Effect* pEffect); typedef void (*EffectVariablesApplier)(MapVariables& mapVars, Effect* pEffect);
class VariableEffect class VariableEffect
{ {
protected: protected:
// Effect description // Effect description
const char* _pszDesc; const char* _pszDesc;
// The associate OIS effect // The associate OIS effect
Effect* _pEffect; Effect* _pEffect;
// The effect variables. // The effect variables.
MapVariables _mapVariables; MapVariables _mapVariables;
// The effect variables applier function. // The effect variables applier function.
EffectVariablesApplier _pfApplyVariables; EffectVariablesApplier _pfApplyVariables;
// True if the effect is currently being played. // True if the effect is currently being played.
bool _bActive; bool _bActive;
public: public:
VariableEffect(const char* pszDesc, Effect* pEffect, VariableEffect(const char* pszDesc, Effect* pEffect,
const MapVariables& mapVars, const EffectVariablesApplier pfApplyVars) const MapVariables& mapVars, const EffectVariablesApplier pfApplyVars)
: _pszDesc(pszDesc), _pEffect(pEffect), : _pszDesc(pszDesc), _pEffect(pEffect),
_mapVariables(mapVars), _pfApplyVariables(pfApplyVars), _bActive(false) _mapVariables(mapVars), _pfApplyVariables(pfApplyVars), _bActive(false)
{} {}
~VariableEffect() ~VariableEffect()
{ {
if (_pEffect) if (_pEffect)
delete _pEffect; delete _pEffect;
MapVariables::iterator iterVars; MapVariables::iterator iterVars;
for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++)
if (iterVars->second) if (iterVars->second)
delete iterVars->second; delete iterVars->second;
} }
void setActive(bool bActive = true) void setActive(bool bActive = true)
{ {
reset(); reset();
_bActive = bActive; _bActive = bActive;
} }
bool isActive() bool isActive()
{ {
return _bActive; return _bActive;
} }
Effect* getFFEffect() Effect* getFFEffect()
{ {
return _pEffect; return _pEffect;
} }
const char* getDescription() const const char* getDescription() const
{ {
return _pszDesc; return _pszDesc;
} }
void update() void update()
{ {
if (isActive()) if (isActive())
{ {
// Update the variables. // Update the variables.
MapVariables::iterator iterVars; MapVariables::iterator iterVars;
for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++)
iterVars->second->update(); iterVars->second->update();
// Apply the updated variable values to the effect. // Apply the updated variable values to the effect.
_pfApplyVariables(_mapVariables, _pEffect); _pfApplyVariables(_mapVariables, _pEffect);
} }
} }
void reset() void reset()
{ {
MapVariables::iterator iterVars; MapVariables::iterator iterVars;
for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++)
iterVars->second->reset(); iterVars->second->reset();
_pfApplyVariables(_mapVariables, _pEffect); _pfApplyVariables(_mapVariables, _pEffect);
} }
string toString() const string toString() const
{ {
string str; string str;
MapVariables::const_iterator iterVars; MapVariables::const_iterator iterVars;
for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++)
str += iterVars->first + ":" + iterVars->second->toString() + " "; str += iterVars->first + ":" + iterVars->second->toString() + " ";
return str; return str;
} }
}; };
//////////// Joystick manager class //////////////////////////////////////////////////////// //////////// Joystick manager class ////////////////////////////////////////////////////////
class JoystickManager class JoystickManager
{ {
protected: protected:
// Input manager. // Input manager.
InputManager* _pInputMgr; InputManager* _pInputMgr;
// Vectors to hold joysticks and associated force feedback devices // Vectors to hold joysticks and associated force feedback devices
vector<JoyStick*> _vecJoys; vector<JoyStick*> _vecJoys;
vector<ForceFeedback*> _vecFFDev; vector<ForceFeedback*> _vecFFDev;
// Selected joystick // Selected joystick
int _nCurrJoyInd; int _nCurrJoyInd;
// Force feedback detected ? // Force feedback detected ?
bool _bFFFound; bool _bFFFound;
// Selected joystick master gain. // Selected joystick master gain.
float _dMasterGain; float _dMasterGain;
// Selected joystick auto-center mode. // Selected joystick auto-center mode.
bool _bAutoCenter; bool _bAutoCenter;
public: public:
JoystickManager(InputManager* pInputMgr, EventHandler* pEventHdlr) JoystickManager(InputManager* pInputMgr, EventHandler* pEventHdlr)
: _pInputMgr(pInputMgr), _nCurrJoyInd(-1), _dMasterGain(0.5), _bAutoCenter(true) : _pInputMgr(pInputMgr), _nCurrJoyInd(-1), _dMasterGain(0.5), _bAutoCenter(true)
{ {
_bFFFound = false; _bFFFound = false;
for( int nJoyInd = 0; nJoyInd < pInputMgr->getNumberOfDevices(OISJoyStick); ++nJoyInd ) for( int nJoyInd = 0; nJoyInd < pInputMgr->getNumberOfDevices(OISJoyStick); ++nJoyInd )
{ {
//Create the stick //Create the stick
JoyStick* pJoy = (JoyStick*)pInputMgr->createInputObject( OISJoyStick, true ); JoyStick* pJoy = (JoyStick*)pInputMgr->createInputObject( OISJoyStick, true );
cout << endl << "Created buffered joystick #" << nJoyInd << " '" << pJoy->vendor() cout << endl << "Created buffered joystick #" << nJoyInd << " '" << pJoy->vendor()
<< "' (Id=" << pJoy->getID() << ")"; << "' (Id=" << pJoy->getID() << ")";
// Check for FF, and if so, keep the joy and dump FF info // Check for FF, and if so, keep the joy and dump FF info
ForceFeedback* pFFDev = (ForceFeedback*)pJoy->queryInterface(Interface::ForceFeedback ); ForceFeedback* pFFDev = (ForceFeedback*)pJoy->queryInterface(Interface::ForceFeedback );
if( pFFDev ) if( pFFDev )
{ {
_bFFFound = true; _bFFFound = true;
// Keep the joy to play with it. // Keep the joy to play with it.
pJoy->setEventCallback(pEventHdlr); pJoy->setEventCallback(pEventHdlr);
_vecJoys.push_back(pJoy); _vecJoys.push_back(pJoy);
// Keep also the associated FF device // Keep also the associated FF device
_vecFFDev.push_back(pFFDev); _vecFFDev.push_back(pFFDev);
// Dump FF supported effects and other info. // Dump FF supported effects and other info.
cout << endl << " * Number of force feedback axes : " cout << endl << " * Number of force feedback axes : "
<< pFFDev->getFFAxesNumber() << endl; << pFFDev->getFFAxesNumber() << endl;
const ForceFeedback::SupportedEffectList &lstFFEffects = const ForceFeedback::SupportedEffectList &lstFFEffects =
pFFDev->getSupportedEffects(); pFFDev->getSupportedEffects();
if (lstFFEffects.size() > 0) if (lstFFEffects.size() > 0)
{ {
cout << " * Supported effects :"; cout << " * Supported effects :";
ForceFeedback::SupportedEffectList::const_iterator itFFEff; ForceFeedback::SupportedEffectList::const_iterator itFFEff;
for(itFFEff = lstFFEffects.begin(); itFFEff != lstFFEffects.end(); ++itFFEff) for(itFFEff = lstFFEffects.begin(); itFFEff != lstFFEffects.end(); ++itFFEff)
cout << " " << Effect::getEffectTypeName(itFFEff->second); cout << " " << Effect::getEffectTypeName(itFFEff->second);
cout << endl << endl; cout << endl << endl;
} }
else else
cout << "Warning: no supported effect found !" << endl; cout << "Warning: no supported effect found !" << endl;
} }
else else
{ {
cout << " (no force feedback support detected) => ignored." << endl << endl; cout << " (no force feedback support detected) => ignored." << endl << endl;
_pInputMgr->destroyInputObject(pJoy); _pInputMgr->destroyInputObject(pJoy);
} }
} }
} }
~JoystickManager() ~JoystickManager()
{ {
for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd) for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd)
_pInputMgr->destroyInputObject( _vecJoys[nJoyInd] ); _pInputMgr->destroyInputObject( _vecJoys[nJoyInd] );
} }
size_t getNumberOfJoysticks() const size_t getNumberOfJoysticks() const
{ {
return _vecJoys.size(); return _vecJoys.size();
} }
bool wasFFDetected() const bool wasFFDetected() const
{ {
return _bFFFound; return _bFFFound;
} }
enum EWhichJoystick { ePrevious=-1, eNext=+1 }; enum EWhichJoystick { ePrevious=-1, eNext=+1 };
void selectJoystick(EWhichJoystick eWhich) void selectJoystick(EWhichJoystick eWhich)
{ {
// Note: Reset the master gain to half the maximum and autocenter mode to Off, // Note: Reset the master gain to half the maximum and autocenter mode to Off,
// when really selecting a new joystick. // when really selecting a new joystick.
if (_nCurrJoyInd < 0) if (_nCurrJoyInd < 0)
{ {
_nCurrJoyInd = 0; _nCurrJoyInd = 0;
_dMasterGain = 0.5; // Half the maximum. _dMasterGain = 0.5; // Half the maximum.
changeMasterGain(0.0); changeMasterGain(0.0);
} }
else else
{ {
_nCurrJoyInd += eWhich; _nCurrJoyInd += eWhich;
if (_nCurrJoyInd < -1 || _nCurrJoyInd >= (int)_vecJoys.size()) if (_nCurrJoyInd < -1 || _nCurrJoyInd >= (int)_vecJoys.size())
_nCurrJoyInd = -1; _nCurrJoyInd = -1;
if (_vecJoys.size() > 1 && _nCurrJoyInd >= 0) if (_vecJoys.size() > 1 && _nCurrJoyInd >= 0)
{ {
_dMasterGain = 0.5; // Half the maximum. _dMasterGain = 0.5; // Half the maximum.
changeMasterGain(0.0); changeMasterGain(0.0);
} }
} }
} }
ForceFeedback* getCurrentFFDevice() ForceFeedback* getCurrentFFDevice()
{ {
return (_nCurrJoyInd >= 0) ? _vecFFDev[_nCurrJoyInd] : 0; return (_nCurrJoyInd >= 0) ? _vecFFDev[_nCurrJoyInd] : 0;
} }
void changeMasterGain(float dDeltaPercent) void changeMasterGain(float dDeltaPercent)
{ {
if (_nCurrJoyInd >= 0) if (_nCurrJoyInd >= 0)
{ {
_dMasterGain += dDeltaPercent / 100; _dMasterGain += dDeltaPercent / 100;
if (_dMasterGain > 1.0) if (_dMasterGain > 1.0)
_dMasterGain = 1.0; _dMasterGain = 1.0;
else if (_dMasterGain < 0.0) else if (_dMasterGain < 0.0)
_dMasterGain = 0.0; _dMasterGain = 0.0;
_vecFFDev[_nCurrJoyInd]->setMasterGain(_dMasterGain); _vecFFDev[_nCurrJoyInd]->setMasterGain(_dMasterGain);
} }
} }
enum EAutoCenterHow { eOff, eOn, eToggle }; enum EAutoCenterHow { eOff, eOn, eToggle };
void changeAutoCenter(EAutoCenterHow eHow = eToggle) void changeAutoCenter(EAutoCenterHow eHow = eToggle)
{ {
if (_nCurrJoyInd >= 0) if (_nCurrJoyInd >= 0)
{ {
if (eHow == eToggle) if (eHow == eToggle)
_bAutoCenter = !_bAutoCenter; _bAutoCenter = !_bAutoCenter;
else else
_bAutoCenter = (eHow == eOn ? true : false); _bAutoCenter = (eHow == eOn ? true : false);
_vecFFDev[_nCurrJoyInd]->setAutoCenterMode(_bAutoCenter); _vecFFDev[_nCurrJoyInd]->setAutoCenterMode(_bAutoCenter);
} }
} }
void captureEvents() void captureEvents()
{ {
// This fires off buffered events for each joystick we have // This fires off buffered events for each joystick we have
for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd) for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd)
if( _vecJoys[nJoyInd] ) if( _vecJoys[nJoyInd] )
_vecJoys[nJoyInd]->capture(); _vecJoys[nJoyInd]->capture();
} }
string toString() const string toString() const
{ {
// Warning: Wrong result if more than 10 joysticks ... // Warning: Wrong result if more than 10 joysticks ...
ostringstream oss; ostringstream oss;
oss << "Joy:" << (_nCurrJoyInd >= 0 ? (char)('0' + _nCurrJoyInd) : '-'); oss << "Joy:" << (_nCurrJoyInd >= 0 ? (char)('0' + _nCurrJoyInd) : '-');
oss << " Gain:" << setiosflags(ios_base::right) << setw(3) << (int)(_dMasterGain*100); oss << " Gain:" << setiosflags(ios_base::right) << setw(3) << (int)(_dMasterGain*100);
oss << "% Center:" << (_bAutoCenter ? " On " : "Off"); oss << "% Center:" << (_bAutoCenter ? " On " : "Off");
return oss.str(); return oss.str();
} }
}; };
//////////// Effect variables applier functions ///////////////////////////////////////////// //////////// Effect variables applier functions /////////////////////////////////////////////
// These functions apply the given Variables to the given OIS::Effect // These functions apply the given Variables to the given OIS::Effect
// Variable force "Force" + optional "AttackFactor" constant, on a OIS::ConstantEffect // Variable force "Force" + optional "AttackFactor" constant, on a OIS::ConstantEffect
void forceVariableApplier(MapVariables& mapVars, Effect* pEffect) void forceVariableApplier(MapVariables& mapVars, Effect* pEffect)
{ {
double dForce = mapVars["Force"]->getValue(); double dForce = mapVars["Force"]->getValue();
double dAttackFactor = 1.0; double dAttackFactor = 1.0;
if (mapVars.find("AttackFactor") != mapVars.end()) if (mapVars.find("AttackFactor") != mapVars.end())
dAttackFactor = mapVars["AttackFactor"]->getValue(); dAttackFactor = mapVars["AttackFactor"]->getValue();
ConstantEffect* pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect()); ConstantEffect* pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect());
pConstForce->level = (int)dForce; pConstForce->level = (int)dForce;
pConstForce->envelope.attackLevel = (unsigned short)fabs(dForce*dAttackFactor); pConstForce->envelope.attackLevel = (unsigned short)fabs(dForce*dAttackFactor);
pConstForce->envelope.fadeLevel = (unsigned short)fabs(dForce); // Fade never reached, in fact. pConstForce->envelope.fadeLevel = (unsigned short)fabs(dForce); // Fade never reached, in fact.
} }
// Variable "Period" on an OIS::PeriodicEffect // Variable "Period" on an OIS::PeriodicEffect
void periodVariableApplier(MapVariables& mapVars, Effect* pEffect) void periodVariableApplier(MapVariables& mapVars, Effect* pEffect)
{ {
double dPeriod = mapVars["Period"]->getValue(); double dPeriod = mapVars["Period"]->getValue();
PeriodicEffect* pPeriodForce = dynamic_cast<PeriodicEffect*>(pEffect->getForceEffect()); PeriodicEffect* pPeriodForce = dynamic_cast<PeriodicEffect*>(pEffect->getForceEffect());
pPeriodForce->period = (unsigned int)dPeriod; pPeriodForce->period = (unsigned int)dPeriod;
} }
//////////// Effect manager class ////////////////////////////////////////////////////////// //////////// Effect manager class //////////////////////////////////////////////////////////
class EffectManager class EffectManager
{ {
protected: protected:
// The joystick manager // The joystick manager
JoystickManager* _pJoystickMgr; JoystickManager* _pJoystickMgr;
// Vector to hold variable effects // Vector to hold variable effects
vector<VariableEffect*> _vecEffects; vector<VariableEffect*> _vecEffects;
// Selected effect // Selected effect
int _nCurrEffectInd; int _nCurrEffectInd;
// Update frequency (Hz) // Update frequency (Hz)
unsigned int _nUpdateFreq; unsigned int _nUpdateFreq;
// Indexes (in _vecEffects) of the variable effects that are playable by the selected joystick. // Indexes (in _vecEffects) of the variable effects that are playable by the selected joystick.
vector<size_t> _vecPlayableEffectInd; vector<size_t> _vecPlayableEffectInd;
public: public:
EffectManager(JoystickManager* pJoystickMgr, unsigned int nUpdateFreq) EffectManager(JoystickManager* pJoystickMgr, unsigned int nUpdateFreq)
: _pJoystickMgr(pJoystickMgr), _nUpdateFreq(nUpdateFreq), _nCurrEffectInd(-1) : _pJoystickMgr(pJoystickMgr), _nUpdateFreq(nUpdateFreq), _nCurrEffectInd(-1)
{ {
Effect* pEffect; Effect* pEffect;
MapVariables mapVars; MapVariables mapVars;
ConstantEffect* pConstForce; ConstantEffect* pConstForce;
PeriodicEffect* pPeriodForce; PeriodicEffect* pPeriodForce;
// Please don't modify or remove effects (unless there is some bug ...) : // Please don't modify or remove effects (unless there is some bug ...) :
// add new ones to enhance the test repository. // add new ones to enhance the test repository.
// And feel free to add any tested device, even when the test failed ! // And feel free to add any tested device, even when the test failed !
// Tested devices capabilities : // Tested devices capabilities :
// - Logitech G25 Racing wheel : // - Logitech G25 Racing wheel :
// * Only 1 axis => no directional 2D effect (only left and right) // * Only 1 axis => no directional 2D effect (only left and right)
// * Full support for constant force under WinXPSP2DX9 and Linux 2.6.22.9 // * Full support for constant force under WinXPSP2DX9 and Linux 2.6.22.9
// * Full support for periodic forces under WinXPSP2DX9 // * Full support for periodic forces under WinXPSP2DX9
// (but poor rendering under 20ms period), and no support under Linux 2.6.22.9 // (but poor rendering under 20ms period), and no support under Linux 2.6.22.9
// * Full support reported (not tested) for all other forces under WinXPSP2DX9, // * Full support reported (not tested) for all other forces under WinXPSP2DX9,
// and no support under Linux 2.6.22.9 // and no support under Linux 2.6.22.9
// - Logitech Rumble pad 2 : // - Logitech Rumble pad 2 :
// * Only 1 axis => no directional 2D effect (only left and right) // * Only 1 axis => no directional 2D effect (only left and right)
// * Forces amplitude is rendered through the inertia motors rotation frequency // * Forces amplitude is rendered through the inertia motors rotation frequency
// (stronger force => quicker rotation) // (stronger force => quicker rotation)
// * 2 inertia motors : 1 with small inertia, 1 with "heavy" one. // * 2 inertia motors : 1 with small inertia, 1 with "heavy" one.
// => poor force feedback rendering ... // => poor force feedback rendering ...
// * Support (poor) for all OIS forces under WinXPSP2DX9, // * Support (poor) for all OIS forces under WinXPSP2DX9,
// and only for Triangle, Square and Sine periodic forces under Linux 2.6.22.9 // and only for Triangle, Square and Sine periodic forces under Linux 2.6.22.9
// (reported by enumeration, but does not seem to work actually) // (reported by enumeration, but does not seem to work actually)
// Master gain setting tests: // Master gain setting tests:
// - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK.
// - Logitech Rumble pad 2 : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // - Logitech Rumble pad 2 : WinXPSP2DX9=OK, Linux2.6.22.9=OK.
// Auto-center mode setting tests: // Auto-center mode setting tests:
// - Logitech G25 Racing wheel : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported. // - Logitech G25 Racing wheel : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported.
// - Logitech Rumble pad 2 : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported. // - Logitech Rumble pad 2 : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported.
// 1) Constant force on 1 axis with 20s-period triangle oscillations in [-10K, +10K]. // 1) Constant force on 1 axis with 20s-period triangle oscillations in [-10K, +10K].
// Notes: Linux: replay_length: no way to get it to work if not 0 or Effect::OIS_INFINITE // Notes: Linux: replay_length: no way to get it to work if not 0 or Effect::OIS_INFINITE
// Tested devices : // Tested devices :
// - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK.
// - Logitech Rumble pad 2 : WinXPSP2DX9=OK (but only light motor involved), // - Logitech Rumble pad 2 : WinXPSP2DX9=OK (but only light motor involved),
// Linux2.6.22.9=Not supported // Linux2.6.22.9=Not supported
pEffect = new Effect(Effect::ConstantForce, Effect::Constant); pEffect = new Effect(Effect::ConstantForce, Effect::Constant);
pEffect->direction = Effect::North; pEffect->direction = Effect::North;
pEffect->trigger_button = 0; pEffect->trigger_button = 0;
pEffect->trigger_interval = 0; pEffect->trigger_interval = 0;
pEffect->replay_length = Effect::OIS_INFINITE; // Linux/Win32: Same behaviour as 0. pEffect->replay_length = Effect::OIS_INFINITE; // Linux/Win32: Same behaviour as 0.
pEffect->replay_delay = 0; pEffect->replay_delay = 0;
pEffect->setNumAxes(1); pEffect->setNumAxes(1);
pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect()); pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect());
pConstForce->level = 5000; //-10K to +10k pConstForce->level = 5000; //-10K to +10k
pConstForce->envelope.attackLength = 0; pConstForce->envelope.attackLength = 0;
pConstForce->envelope.attackLevel = (unsigned short)pConstForce->level; pConstForce->envelope.attackLevel = (unsigned short)pConstForce->level;
pConstForce->envelope.fadeLength = 0; pConstForce->envelope.fadeLength = 0;
pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level; pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level;
mapVars.clear(); mapVars.clear();
mapVars["Force"] = mapVars["Force"] =
new TriangleVariable(0.0, // F0 new TriangleVariable(0.0, // F0
4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle 4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle
-10000.0, // Fmin -10000.0, // Fmin
10000.0); // Fmax 10000.0); // Fmax
mapVars["AttackFactor"] = new Constant(1.0); mapVars["AttackFactor"] = new Constant(1.0);
_vecEffects.push_back _vecEffects.push_back
(new VariableEffect (new VariableEffect
("Constant force on 1 axis with 20s-period triangle oscillations " ("Constant force on 1 axis with 20s-period triangle oscillations "
"of its signed amplitude in [-10K, +10K]", "of its signed amplitude in [-10K, +10K]",
pEffect, mapVars, forceVariableApplier)); pEffect, mapVars, forceVariableApplier));
// 2) Constant force on 1 axis with noticeable attack // 2) Constant force on 1 axis with noticeable attack
// with 20s-period triangle oscillations in [-10K, +10K]. // with 20s-period triangle oscillations in [-10K, +10K].
// Tested devices : // Tested devices :
// - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK. // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK.
// - Logitech Rumble pad 2 : WinXPSP2DX9=OK (including attack, but only light motor involved), // - Logitech Rumble pad 2 : WinXPSP2DX9=OK (including attack, but only light motor involved),
// Linux2.6.22.9=Not supported. // Linux2.6.22.9=Not supported.
pEffect = new Effect(Effect::ConstantForce, Effect::Constant); pEffect = new Effect(Effect::ConstantForce, Effect::Constant);
pEffect->direction = Effect::North; pEffect->direction = Effect::North;
pEffect->trigger_button = 0; pEffect->trigger_button = 0;
pEffect->trigger_interval = 0; pEffect->trigger_interval = 0;
pEffect->replay_length = Effect::OIS_INFINITE; //(unsigned int)(1000000.0/_nUpdateFreq); // Linux: Does not work. pEffect->replay_length = Effect::OIS_INFINITE; //(unsigned int)(1000000.0/_nUpdateFreq); // Linux: Does not work.
pEffect->replay_delay = 0; pEffect->replay_delay = 0;
pEffect->setNumAxes(1); pEffect->setNumAxes(1);
pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect()); pConstForce = dynamic_cast<ConstantEffect*>(pEffect->getForceEffect());
pConstForce->level = 5000; //-10K to +10k pConstForce->level = 5000; //-10K to +10k
pConstForce->envelope.attackLength = (unsigned int)(1000000.0/_nUpdateFreq/2); pConstForce->envelope.attackLength = (unsigned int)(1000000.0/_nUpdateFreq/2);
pConstForce->envelope.attackLevel = (unsigned short)(pConstForce->level*0.1); pConstForce->envelope.attackLevel = (unsigned short)(pConstForce->level*0.1);
pConstForce->envelope.fadeLength = 0; // Never reached, actually. pConstForce->envelope.fadeLength = 0; // Never reached, actually.
pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level; // Idem pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level; // Idem
mapVars.clear(); mapVars.clear();
mapVars["Force"] = mapVars["Force"] =
new TriangleVariable(0.0, // F0 new TriangleVariable(0.0, // F0
4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle 4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle
-10000.0, // Fmin -10000.0, // Fmin
10000.0); // Fmax 10000.0); // Fmax
mapVars["AttackFactor"] = new Constant(0.1); mapVars["AttackFactor"] = new Constant(0.1);
_vecEffects.push_back _vecEffects.push_back
(new VariableEffect (new VariableEffect
("Constant force on 1 axis with noticeable attack (app update period / 2)" ("Constant force on 1 axis with noticeable attack (app update period / 2)"
"and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]", "and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]",
pEffect, mapVars, forceVariableApplier)); pEffect, mapVars, forceVariableApplier));
// 3) Triangle periodic force on 1 axis with 40s-period triangle oscillations // 3) Triangle periodic force on 1 axis with 40s-period triangle oscillations
// of its period in [10, 400] ms, and constant amplitude // of its period in [10, 400] ms, and constant amplitude
// Tested devices : // Tested devices :
// - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK. // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK.
// - Logitech Rumble pad 2 : WinXPSP2DX9=OK but only light motor involved, // - Logitech Rumble pad 2 : WinXPSP2DX9=OK but only light motor involved,
// Linux2.6.22.9=Failed. // Linux2.6.22.9=Failed.
pEffect = new Effect(Effect::PeriodicForce, Effect::Triangle); pEffect = new Effect(Effect::PeriodicForce, Effect::Triangle);
pEffect->direction = Effect::North; pEffect->direction = Effect::North;
pEffect->trigger_button = 0; pEffect->trigger_button = 0;
pEffect->trigger_interval = 0; pEffect->trigger_interval = 0;
pEffect->replay_length = Effect::OIS_INFINITE; pEffect->replay_length = Effect::OIS_INFINITE;
pEffect->replay_delay = 0; pEffect->replay_delay = 0;
pEffect->setNumAxes(1); pEffect->setNumAxes(1);
pPeriodForce = dynamic_cast<PeriodicEffect*>(pEffect->getForceEffect()); pPeriodForce = dynamic_cast<PeriodicEffect*>(pEffect->getForceEffect());
pPeriodForce->magnitude = 10000; // 0 to +10k pPeriodForce->magnitude = 10000; // 0 to +10k
pPeriodForce->offset = 0; pPeriodForce->offset = 0;
pPeriodForce->phase = 0; // 0 to 35599 pPeriodForce->phase = 0; // 0 to 35599
pPeriodForce->period = 10000; // Micro-seconds pPeriodForce->period = 10000; // Micro-seconds
pPeriodForce->envelope.attackLength = 0; pPeriodForce->envelope.attackLength = 0;
pPeriodForce->envelope.attackLevel = (unsigned short)pPeriodForce->magnitude; pPeriodForce->envelope.attackLevel = (unsigned short)pPeriodForce->magnitude;
pPeriodForce->envelope.fadeLength = 0; pPeriodForce->envelope.fadeLength = 0;
pPeriodForce->envelope.fadeLevel = (unsigned short)pPeriodForce->magnitude; pPeriodForce->envelope.fadeLevel = (unsigned short)pPeriodForce->magnitude;
mapVars.clear(); mapVars.clear();
mapVars["Period"] = mapVars["Period"] =
new TriangleVariable(1*1000.0, // P0 new TriangleVariable(1*1000.0, // P0
4*(400-10)*1000.0/_nUpdateFreq / 40.0, // dP for a 40s-period triangle 4*(400-10)*1000.0/_nUpdateFreq / 40.0, // dP for a 40s-period triangle
10*1000.0, // Pmin 10*1000.0, // Pmin
400*1000.0); // Pmax 400*1000.0); // Pmax
_vecEffects.push_back _vecEffects.push_back
(new VariableEffect (new VariableEffect
("Periodic force on 1 axis with 40s-period triangle oscillations " ("Periodic force on 1 axis with 40s-period triangle oscillations "
"of its period in [10, 400] ms, and constant amplitude", "of its period in [10, 400] ms, and constant amplitude",
pEffect, mapVars, periodVariableApplier)); pEffect, mapVars, periodVariableApplier));
} }
~EffectManager() ~EffectManager()
{ {
vector<VariableEffect*>::iterator iterEffs; vector<VariableEffect*>::iterator iterEffs;
for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++) for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++)
delete *iterEffs; delete *iterEffs;
} }
void updateActiveEffects() void updateActiveEffects()
{ {
vector<VariableEffect*>::iterator iterEffs; vector<VariableEffect*>::iterator iterEffs;
for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++) for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++)
if ((*iterEffs)->isActive()) if ((*iterEffs)->isActive())
{ {
(*iterEffs)->update(); (*iterEffs)->update();
_pJoystickMgr->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect()); _pJoystickMgr->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect());
} }
} }
void checkPlayableEffects() void checkPlayableEffects()
{ {
// Nothing to do if no joystick currently selected // Nothing to do if no joystick currently selected
if (!_pJoystickMgr->getCurrentFFDevice()) if (!_pJoystickMgr->getCurrentFFDevice())
return; return;
// Get the list of indexes of effects that the selected device can play // Get the list of indexes of effects that the selected device can play
_vecPlayableEffectInd.clear(); _vecPlayableEffectInd.clear();
for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++) for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++)
{ {
const Effect::EForce eForce = _vecEffects[nEffInd]->getFFEffect()->force; const Effect::EForce eForce = _vecEffects[nEffInd]->getFFEffect()->force;
const Effect::EType eType = _vecEffects[nEffInd]->getFFEffect()->type; const Effect::EType eType = _vecEffects[nEffInd]->getFFEffect()->type;
if (_pJoystickMgr->getCurrentFFDevice()->supportsEffect(eForce, eType)) if (_pJoystickMgr->getCurrentFFDevice()->supportsEffect(eForce, eType))
{ {
_vecPlayableEffectInd.push_back(nEffInd); _vecPlayableEffectInd.push_back(nEffInd);
} }
} }
// Print details about playable effects // Print details about playable effects
if (_vecPlayableEffectInd.empty()) if (_vecPlayableEffectInd.empty())
{ {
cout << endl << endl << "The device can't play any effect of the test set" << endl; cout << endl << endl << "The device can't play any effect of the test set" << endl;
} }
else else
{ {
cout << endl << endl << "Selected device can play the following effects :" << endl; cout << endl << endl << "Selected device can play the following effects :" << endl;
for (size_t nEffIndInd = 0; nEffIndInd < _vecPlayableEffectInd.size(); nEffIndInd++) for (size_t nEffIndInd = 0; nEffIndInd < _vecPlayableEffectInd.size(); nEffIndInd++)
printEffect(_vecPlayableEffectInd[nEffIndInd]); printEffect(_vecPlayableEffectInd[nEffIndInd]);
cout << endl; cout << endl;
} }
} }
enum EWhichEffect { ePrevious=-1, eNone=0, eNext=+1 }; enum EWhichEffect { ePrevious=-1, eNone=0, eNext=+1 };
void selectEffect(EWhichEffect eWhich) void selectEffect(EWhichEffect eWhich)
{ {
// Nothing to do if no joystick currently selected // Nothing to do if no joystick currently selected
if (!_pJoystickMgr->getCurrentFFDevice()) if (!_pJoystickMgr->getCurrentFFDevice())
{ {
cout << "\nNo Joystick selected.\n"; cout << "\nNo Joystick selected.\n";
return; return;
} }
// Nothing to do if joystick cannot play any effect // Nothing to do if joystick cannot play any effect
if (_vecPlayableEffectInd.empty()) if (_vecPlayableEffectInd.empty())
{ {
cout << "\nNo playable effects.\n"; cout << "\nNo playable effects.\n";
return; return;
} }
// If no effect selected, and next or previous requested, select the first one. // If no effect selected, and next or previous requested, select the first one.
if (eWhich != eNone && _nCurrEffectInd < 0) if (eWhich != eNone && _nCurrEffectInd < 0)
_nCurrEffectInd = 0; _nCurrEffectInd = 0;
// Otherwise, remove the current one from the device, // Otherwise, remove the current one from the device,
// and then select the requested one if any. // and then select the requested one if any.
else if (_nCurrEffectInd >= 0) else if (_nCurrEffectInd >= 0)
{ {
_pJoystickMgr->getCurrentFFDevice() _pJoystickMgr->getCurrentFFDevice()
->remove(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect()); ->remove(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(false); _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(false);
_nCurrEffectInd += eWhich; _nCurrEffectInd += eWhich;
if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (int)_vecPlayableEffectInd.size()) if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (int)_vecPlayableEffectInd.size())
_nCurrEffectInd = -1; _nCurrEffectInd = -1;
} }
// If no effect must be selected, reset the selection index // If no effect must be selected, reset the selection index
if (eWhich == eNone) if (eWhich == eNone)
{ {
_nCurrEffectInd = -1; _nCurrEffectInd = -1;
} }
// Otherwise, upload the new selected effect to the device if any. // Otherwise, upload the new selected effect to the device if any.
else if (_nCurrEffectInd >= 0) else if (_nCurrEffectInd >= 0)
{ {
_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(true); _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(true);
_pJoystickMgr->getCurrentFFDevice() _pJoystickMgr->getCurrentFFDevice()
->upload(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect()); ->upload(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
} }
} }
void printEffect(size_t nEffInd) void printEffect(size_t nEffInd)
{ {
cout << "* #" << nEffInd << " : " << _vecEffects[nEffInd]->getDescription() << endl; cout << "* #" << nEffInd << " : " << _vecEffects[nEffInd]->getDescription() << endl;
} }
void printEffects() void printEffects()
{ {
for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++) for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++)
printEffect(nEffInd); printEffect(nEffInd);
} }
string toString() const string toString() const
{ {
ostringstream oss; ostringstream oss;
oss << "DevMem: " << setiosflags(ios_base::right) << setw(3); oss << "DevMem: " << setiosflags(ios_base::right) << setw(3);
//This causes constant exceptions with my device. Not needed for anything other than debugging //This causes constant exceptions with my device. Not needed for anything other than debugging
//if (_pJoystickMgr->getCurrentFFDevice()) //if (_pJoystickMgr->getCurrentFFDevice())
// oss << _pJoystickMgr->getCurrentFFDevice()->getFFMemoryLoad() << "%"; // oss << _pJoystickMgr->getCurrentFFDevice()->getFFMemoryLoad() << "%";
//else //else
// oss << "----"; // oss << "----";
oss << " Effect:" << setw(2); oss << " Effect:" << setw(2);
if (_nCurrEffectInd >= 0) if (_nCurrEffectInd >= 0)
oss << _vecPlayableEffectInd[_nCurrEffectInd] oss << _vecPlayableEffectInd[_nCurrEffectInd]
<< " " << _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->toString(); << " " << _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->toString();
else else
oss << "--"; oss << "--";
return oss.str(); return oss.str();
} }
}; };
//////////// Application class //////////////////////////////////////////////////////// //////////// Application class ////////////////////////////////////////////////////////
class Application class Application
{ {
protected: protected:
InputManager* _pInputMgr; InputManager* _pInputMgr;
EventHandler* _pEventHdlr; EventHandler* _pEventHdlr;
Keyboard* _pKeyboard; Keyboard* _pKeyboard;
JoystickManager* _pJoystickMgr; JoystickManager* _pJoystickMgr;
EffectManager* _pEffectMgr; EffectManager* _pEffectMgr;
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
HWND _hWnd; HWND _hWnd;
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
Display* _pXDisp; Display* _pXDisp;
Window _xWin; Window _xWin;
#endif #endif
bool _bMustStop; bool _bMustStop;
bool _bIsInitialized; bool _bIsInitialized;
int _nStatus; int _nStatus;
// App. hart beat frequency. // App. hart beat frequency.
static const unsigned int _nHartBeatFreq = 20; // Hz static const unsigned int _nHartBeatFreq = 20; // Hz
// Effects update frequency (Hz) : Needs to be quite lower than app. hart beat frequency, // Effects update frequency (Hz) : Needs to be quite lower than app. hart beat frequency,
// if we want to be able to calmly study effect changes ... // if we want to be able to calmly study effect changes ...
static const unsigned int _nEffectUpdateFreq = 1; // Hz static const unsigned int _nEffectUpdateFreq = 1; // Hz
public: public:
Application(int argc, const char* argv[]) Application(int argc, const char* argv[])
{ {
_pInputMgr = 0; _pInputMgr = 0;
_pEventHdlr = 0; _pEventHdlr = 0;
_pKeyboard = 0; _pKeyboard = 0;
_pJoystickMgr = 0; _pJoystickMgr = 0;
_pEffectMgr = 0; _pEffectMgr = 0;
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
_hWnd = 0; _hWnd = 0;
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
_pXDisp = 0; _pXDisp = 0;
_xWin = 0; _xWin = 0;
#endif #endif
_bMustStop = false; _bMustStop = false;
_bIsInitialized = false; _bIsInitialized = false;
_nStatus = 0; _nStatus = 0;
} }
int initialize() int initialize()
{ {
ostringstream wnd; ostringstream wnd;
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
//Create a capture window for Input Grabbing //Create a capture window for Input Grabbing
_hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc); _hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc);
if( _hWnd == NULL ) if( _hWnd == NULL )
OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!"); OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!");
ShowWindow(_hWnd, SW_SHOW); ShowWindow(_hWnd, SW_SHOW);
wnd << (size_t)_hWnd; wnd << (size_t)_hWnd;
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
//Connects to default X window //Connects to default X window
if( !(_pXDisp = XOpenDisplay(0)) ) if( !(_pXDisp = XOpenDisplay(0)) )
OIS_EXCEPT(E_General, "Error opening X!"); OIS_EXCEPT(E_General, "Error opening X!");
//Create a window //Create a window
_xWin = XCreateSimpleWindow(_pXDisp,DefaultRootWindow(_pXDisp), 0,0, 100,100, 0, 0, 0); _xWin = XCreateSimpleWindow(_pXDisp,DefaultRootWindow(_pXDisp), 0,0, 100,100, 0, 0, 0);
//bind our connection to that window //bind our connection to that window
XMapWindow(_pXDisp, _xWin); XMapWindow(_pXDisp, _xWin);
//Select what events we want to listen to locally //Select what events we want to listen to locally
XSelectInput(_pXDisp, _xWin, StructureNotifyMask); XSelectInput(_pXDisp, _xWin, StructureNotifyMask);
//Wait for Window to show up //Wait for Window to show up
XEvent event; XEvent event;
do { XNextEvent(_pXDisp, &event); } while(event.type != MapNotify); do { XNextEvent(_pXDisp, &event); } while(event.type != MapNotify);
wnd << _xWin; wnd << _xWin;
#endif #endif
// Create OIS input manager // Create OIS input manager
ParamList pl; ParamList pl;
pl.insert(make_pair(string("WINDOW"), wnd.str())); pl.insert(make_pair(string("WINDOW"), wnd.str()));
_pInputMgr = InputManager::createInputSystem(pl); _pInputMgr = InputManager::createInputSystem(pl);
cout << _pInputMgr->inputSystemName() << " created." << endl; cout << _pInputMgr->inputSystemName() << " created." << endl;
// Create the event handler. // Create the event handler.
_pEventHdlr = new EventHandler(this); _pEventHdlr = new EventHandler(this);
// Create a simple keyboard // Create a simple keyboard
_pKeyboard = (Keyboard*)_pInputMgr->createInputObject( OISKeyboard, true ); _pKeyboard = (Keyboard*)_pInputMgr->createInputObject( OISKeyboard, true );
_pKeyboard->setEventCallback( _pEventHdlr ); _pKeyboard->setEventCallback( _pEventHdlr );
// Create the joystick manager. // Create the joystick manager.
_pJoystickMgr = new JoystickManager(_pInputMgr, _pEventHdlr); _pJoystickMgr = new JoystickManager(_pInputMgr, _pEventHdlr);
if( !_pJoystickMgr->wasFFDetected() ) if( !_pJoystickMgr->wasFFDetected() )
{ {
cout << "No Force Feedback device detected." << endl; cout << "No Force Feedback device detected." << endl;
_nStatus = 1; _nStatus = 1;
return _nStatus; return _nStatus;
} }
// Create force feedback effect manager. // Create force feedback effect manager.
_pEffectMgr = new EffectManager(_pJoystickMgr, _nEffectUpdateFreq); _pEffectMgr = new EffectManager(_pJoystickMgr, _nEffectUpdateFreq);
// Initialize the event handler. // Initialize the event handler.
_pEventHdlr->initialize(_pJoystickMgr, _pEffectMgr); _pEventHdlr->initialize(_pJoystickMgr, _pEffectMgr);
_bIsInitialized = true; _bIsInitialized = true;
return _nStatus; return _nStatus;
} }
#if defined OIS_LINUX_PLATFORM #if defined OIS_LINUX_PLATFORM
// This is just here to show that you still receive x11 events, // This is just here to show that you still receive x11 events,
// as the lib only needs mouse/key events // as the lib only needs mouse/key events
void checkX11Events() void checkX11Events()
{ {
XEvent event; XEvent event;
//Poll x11 for events //Poll x11 for events
while( XPending(_pXDisp) > 0 ) while( XPending(_pXDisp) > 0 )
{ {
XNextEvent(_pXDisp, &event); XNextEvent(_pXDisp, &event);
} }
} }
#endif #endif
int run() int run()
{ {
const unsigned int nMaxEffectUpdateCnt = _nHartBeatFreq / _nEffectUpdateFreq; const unsigned int nMaxEffectUpdateCnt = _nHartBeatFreq / _nEffectUpdateFreq;
unsigned int nEffectUpdateCnt = 0; unsigned int nEffectUpdateCnt = 0;
// Initailize app. if not already done, and exit if something went wrong. // Initailize app. if not already done, and exit if something went wrong.
if (!_bIsInitialized) if (!_bIsInitialized)
initialize(); initialize();
if (!_bIsInitialized) if (!_bIsInitialized)
return _nStatus; return _nStatus;
try try
{ {
//Main polling loop //Main polling loop
while(!_bMustStop) while(!_bMustStop)
{ {
// This fires off buffered events for keyboards // This fires off buffered events for keyboards
_pKeyboard->capture(); _pKeyboard->capture();
// This fires off buffered events for each joystick we have // This fires off buffered events for each joystick we have
_pJoystickMgr->captureEvents(); _pJoystickMgr->captureEvents();
// Update currently selected effects if time has come to. // Update currently selected effects if time has come to.
if (!nEffectUpdateCnt) if (!nEffectUpdateCnt)
{ {
_pEffectMgr->updateActiveEffects(); _pEffectMgr->updateActiveEffects();
nEffectUpdateCnt = nMaxEffectUpdateCnt; nEffectUpdateCnt = nMaxEffectUpdateCnt;
} }
else else
nEffectUpdateCnt--; nEffectUpdateCnt--;
// Update state line. // Update state line.
cout << "\r" << _pJoystickMgr->toString() << " " << _pEffectMgr->toString() cout << "\r" << _pJoystickMgr->toString() << " " << _pEffectMgr->toString()
<< " "; << " ";
//Throttle down CPU usage & handle OS events //Throttle down CPU usage & handle OS events
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
Sleep( (DWORD)(1000.0/_nHartBeatFreq) ); Sleep( (DWORD)(1000.0/_nHartBeatFreq) );
MSG msg; MSG msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{ {
TranslateMessage( &msg ); TranslateMessage( &msg );
DispatchMessage( &msg ); DispatchMessage( &msg );
} }
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
checkX11Events(); checkX11Events();
usleep(1000000.0/_nHartBeatFreq); usleep(1000000.0/_nHartBeatFreq);
#endif #endif
} }
} }
catch( const Exception &ex ) catch( const Exception &ex )
{ {
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
MessageBox(0, ex.eText, "Exception Raised!", MB_OK); MessageBox(0, ex.eText, "Exception Raised!", MB_OK);
#else #else
cout << endl << "OIS Exception Caught!" << endl cout << endl << "OIS Exception Caught!" << endl
<< "\t" << ex.eText << "[Line " << ex.eLine << " in " << ex.eFile << "]" << endl; << "\t" << ex.eText << "[Line " << ex.eLine << " in " << ex.eFile << "]" << endl;
#endif #endif
} }
terminate(); terminate();
return _nStatus; return _nStatus;
} }
void stop() void stop()
{ {
_bMustStop = true; _bMustStop = true;
} }
void terminate() void terminate()
{ {
if (_pInputMgr) if (_pInputMgr)
{ {
_pInputMgr->destroyInputObject( _pKeyboard ); _pInputMgr->destroyInputObject( _pKeyboard );
_pKeyboard = 0; _pKeyboard = 0;
if (_pJoystickMgr) if (_pJoystickMgr)
{ {
delete _pJoystickMgr; delete _pJoystickMgr;
_pJoystickMgr = 0; _pJoystickMgr = 0;
} }
InputManager::destroyInputSystem(_pInputMgr); InputManager::destroyInputSystem(_pInputMgr);
_pInputMgr = 0; _pInputMgr = 0;
} }
if (_pEffectMgr) if (_pEffectMgr)
{ {
delete _pEffectMgr; delete _pEffectMgr;
_pEffectMgr = 0; _pEffectMgr = 0;
} }
if (_pEventHdlr) if (_pEventHdlr)
{ {
delete _pEventHdlr; delete _pEventHdlr;
_pEventHdlr = 0; _pEventHdlr = 0;
} }
#if defined OIS_LINUX_PLATFORM #if defined OIS_LINUX_PLATFORM
// Be nice to X and clean up the x window // Be nice to X and clean up the x window
XDestroyWindow(_pXDisp, _xWin); XDestroyWindow(_pXDisp, _xWin);
XCloseDisplay(_pXDisp); XCloseDisplay(_pXDisp);
#endif #endif
} }
JoystickManager* getJoystickManager() JoystickManager* getJoystickManager()
{ {
return _pJoystickMgr; return _pJoystickMgr;
} }
EffectManager* getEffectManager() EffectManager* getEffectManager()
{ {
return _pEffectMgr; return _pEffectMgr;
} }
void printHelp() void printHelp()
{ {
cout << endl cout << endl
<< "Keyboard actions :" << endl << "Keyboard actions :" << endl
<< "* Escape : Exit App" << endl << "* Escape : Exit App" << endl
<< "* H : This help menu" << endl << "* H : This help menu" << endl
<< "* Right/Left : Select next/previous joystick among the FF capable detected ones" << endl << "* Right/Left : Select next/previous joystick among the FF capable detected ones" << endl
<< "* Up/Down : Select next/previous effect for the selected joystick" << endl << "* Up/Down : Select next/previous effect for the selected joystick" << endl
<< "* PgUp/PgDn : Increase/decrease from 5% the master gain " << "* PgUp/PgDn : Increase/decrease from 5% the master gain "
<< "for all the joysticks" << endl << "for all the joysticks" << endl
<< "* Space : Toggle auto-centering on all the joysticks" << endl; << "* Space : Toggle auto-centering on all the joysticks" << endl;
if (_bIsInitialized) if (_bIsInitialized)
{ {
cout << endl << "Implemented effects :" << endl << endl; cout << endl << "Implemented effects :" << endl << endl;
_pEffectMgr->printEffects(); _pEffectMgr->printEffects();
cout << endl; cout << endl;
} }
} }
}; };
//////////// Event handler class definition //////////////////////////////////////////////// //////////// Event handler class definition ////////////////////////////////////////////////
EventHandler::EventHandler(Application* pApp) EventHandler::EventHandler(Application* pApp)
: _pApplication(pApp) : _pApplication(pApp)
{} {}
void EventHandler::initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr) void EventHandler::initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr)
{ {
_pJoystickMgr = pJoystickMgr; _pJoystickMgr = pJoystickMgr;
_pEffectMgr = pEffectMgr; _pEffectMgr = pEffectMgr;
} }
bool EventHandler::keyPressed( const KeyEvent &arg ) bool EventHandler::keyPressed( const KeyEvent &arg )
{ {
switch (arg.key) switch (arg.key)
{ {
// Quit. // Quit.
case KC_ESCAPE: case KC_ESCAPE:
_pApplication->stop(); _pApplication->stop();
break; break;
// Help. // Help.
case KC_H: case KC_H:
_pApplication->printHelp(); _pApplication->printHelp();
break; break;
// Change current joystick. // Change current joystick.
case KC_RIGHT: case KC_RIGHT:
_pEffectMgr->selectEffect(EffectManager::eNone); _pEffectMgr->selectEffect(EffectManager::eNone);
_pJoystickMgr->selectJoystick(JoystickManager::eNext); _pJoystickMgr->selectJoystick(JoystickManager::eNext);
_pEffectMgr->checkPlayableEffects(); _pEffectMgr->checkPlayableEffects();
break; break;
case KC_LEFT: case KC_LEFT:
_pEffectMgr->selectEffect(EffectManager::eNone); _pEffectMgr->selectEffect(EffectManager::eNone);
_pJoystickMgr->selectJoystick(JoystickManager::ePrevious); _pJoystickMgr->selectJoystick(JoystickManager::ePrevious);
_pEffectMgr->checkPlayableEffects(); _pEffectMgr->checkPlayableEffects();
break; break;
// Change current effect. // Change current effect.
case KC_UP: case KC_UP:
_pEffectMgr->selectEffect(EffectManager::eNext); _pEffectMgr->selectEffect(EffectManager::eNext);
break; break;
case KC_DOWN: case KC_DOWN:
_pEffectMgr->selectEffect(EffectManager::ePrevious); _pEffectMgr->selectEffect(EffectManager::ePrevious);
break; break;
// Change current master gain. // Change current master gain.
case KC_PGUP: case KC_PGUP:
_pJoystickMgr->changeMasterGain(5.0); // Percent _pJoystickMgr->changeMasterGain(5.0); // Percent
break; break;
case KC_PGDOWN: case KC_PGDOWN:
_pJoystickMgr->changeMasterGain(-5.0); // Percent _pJoystickMgr->changeMasterGain(-5.0); // Percent
break; break;
// Toggle auto-center mode. // Toggle auto-center mode.
case KC_SPACE: case KC_SPACE:
_pJoystickMgr->changeAutoCenter(); _pJoystickMgr->changeAutoCenter();
break; break;
default: default:
cout << "Non mapped key: " << arg.key << endl; cout << "Non mapped key: " << arg.key << endl;
} }
return true; return true;
} }
bool EventHandler::keyReleased( const KeyEvent &arg ) bool EventHandler::keyReleased( const KeyEvent &arg )
{ {
return true; return true;
} }
bool EventHandler::buttonPressed( const JoyStickEvent &arg, int button ) bool EventHandler::buttonPressed( const JoyStickEvent &arg, int button )
{ {
return true; return true;
} }
bool EventHandler::buttonReleased( const JoyStickEvent &arg, int button ) bool EventHandler::buttonReleased( const JoyStickEvent &arg, int button )
{ {
return true; return true;
} }
bool EventHandler::axisMoved( const JoyStickEvent &arg, int axis ) bool EventHandler::axisMoved( const JoyStickEvent &arg, int axis )
{ {
return true; return true;
} }
bool EventHandler::povMoved( const JoyStickEvent &arg, int pov ) bool EventHandler::povMoved( const JoyStickEvent &arg, int pov )
{ {
return true; return true;
} }
//========================================================================================== //==========================================================================================
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
cout << endl cout << endl
<< "This is a simple command line Force Feedback testing demo ..." << endl << "This is a simple command line Force Feedback testing demo ..." << endl
<< "All connected joystick devices will be created and if FF Support is found," << endl << "All connected joystick devices will be created and if FF Support is found," << endl
<< "you'll be able to play some predefined variable effects on them." << endl << endl << "you'll be able to play some predefined variable effects on them." << endl << endl
<< "Note: 1 effect can be played on 1 joystick at a time for the moment." << endl << endl; << "Note: 1 effect can be played on 1 joystick at a time for the moment." << endl << endl;
Application app(argc, argv); Application app(argc, argv);
int status = app.initialize(); int status = app.initialize();
if (!status) if (!status)
{ {
app.printHelp(); app.printHelp();
status = app.run(); status = app.run();
} }
cout << endl << endl << "Exiting ..." << endl << endl; cout << endl << endl << "Exiting ..." << endl << endl;
#if defined OIS_WIN32_PLATFORM && _DEBUG #if defined OIS_WIN32_PLATFORM && _DEBUG
cout << "Click on this window and ..." << endl; cout << "Click on this window and ..." << endl;
system("pause"); system("pause");
#endif #endif
exit(status); exit(status);
} }
INCLUDES = $(STLPORT_CFLAGS) -I$(top_srcdir)/includes $(CFLAGS) -I/usr/X11R6/include INCLUDES = $(STLPORT_CFLAGS) -I$(top_srcdir)/includes $(CFLAGS) -I/usr/X11R6/include
noinst_PROGRAMS = ConsoleApp FFConsoleTest noinst_PROGRAMS = ConsoleApp FFConsoleTest
ConsoleApp_SOURCES = OISConsole.cpp ConsoleApp_SOURCES = OISConsole.cpp
ConsoleApp_LDFLAGS = -L$(top_builddir)/src ConsoleApp_LDFLAGS = -L$(top_builddir)/src
ConsoleApp_LDADD = -lOIS ConsoleApp_LDADD = -lOIS
FFConsoleTest_SOURCES = FFConsoleDemo.cpp FFConsoleTest_SOURCES = FFConsoleDemo.cpp
FFConsoleTest_LDFLAGS = -L$(top_builddir)/src FFConsoleTest_LDFLAGS = -L$(top_builddir)/src
FFConsoleTest_LDADD = -lOIS FFConsoleTest_LDADD = -lOIS
//////////////////////////////// OS Nuetral Headers //////////////// //////////////////////////////// OS Nuetral Headers ////////////////
#include "OISInputManager.h" #include "OISInputManager.h"
#include "OISException.h" #include "OISException.h"
#include "OISKeyboard.h" #include "OISKeyboard.h"
#include "OISMouse.h" #include "OISMouse.h"
#include "OISJoyStick.h" #include "OISJoyStick.h"
#include "OISEvents.h" #include "OISEvents.h"
//Advanced Usage //Advanced Usage
#include "OISForceFeedback.h" #include "OISForceFeedback.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
////////////////////////////////////Needed Windows Headers//////////// ////////////////////////////////////Needed Windows Headers////////////
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include "windows.h" #include "windows.h"
#ifdef min #ifdef min
#undef min #undef min
#endif #endif
#include "resource.h" #include "resource.h"
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Linux Headers////////////// ////////////////////////////////////Needed Linux Headers//////////////
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
void checkX11Events(); void checkX11Events();
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Mac Headers////////////// ////////////////////////////////////Needed Mac Headers//////////////
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
void checkMacEvents(); void checkMacEvents();
#endif #endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
using namespace OIS; using namespace OIS;
//-- Some local prototypes --// //-- Some local prototypes --//
void doStartup(); void doStartup();
void handleNonBufferedKeys(); void handleNonBufferedKeys();
void handleNonBufferedMouse(); void handleNonBufferedMouse();
void handleNonBufferedJoy( JoyStick* js ); void handleNonBufferedJoy( JoyStick* js );
//-- Easy access globals --// //-- Easy access globals --//
bool appRunning = true; //Global Exit Flag bool appRunning = true; //Global Exit Flag
const char *g_DeviceType[6] = {"OISUnknown", "OISKeyboard", "OISMouse", "OISJoyStick", const char *g_DeviceType[6] = {"OISUnknown", "OISKeyboard", "OISMouse", "OISJoyStick",
"OISTablet", "OISOther"}; "OISTablet", "OISOther"};
InputManager *g_InputManager = 0; //Our Input System InputManager *g_InputManager = 0; //Our Input System
Keyboard *g_kb = 0; //Keyboard Device Keyboard *g_kb = 0; //Keyboard Device
Mouse *g_m = 0; //Mouse Device Mouse *g_m = 0; //Mouse Device
JoyStick* g_joys[4] = {0,0,0,0}; //This demo supports up to 4 controllers JoyStick* g_joys[4] = {0,0,0,0}; //This demo supports up to 4 controllers
//-- OS Specific Globals --// //-- OS Specific Globals --//
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
HWND hWnd = 0; HWND hWnd = 0;
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
Display *xDisp = 0; Display *xDisp = 0;
Window xWin = 0; Window xWin = 0;
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
WindowRef mWin = 0; WindowRef mWin = 0;
#endif #endif
//////////// Common Event handler class //////// //////////// Common Event handler class ////////
class EventHandler : public KeyListener, public MouseListener, public JoyStickListener class EventHandler : public KeyListener, public MouseListener, public JoyStickListener
{ {
public: public:
EventHandler() {} EventHandler() {}
~EventHandler() {} ~EventHandler() {}
bool keyPressed( const KeyEvent &arg ) { bool keyPressed( const KeyEvent &arg ) {
std::cout << " KeyPressed {" << arg.key std::cout << " KeyPressed {" << arg.key
<< ", " << ((Keyboard*)(arg.device))->getAsString(arg.key) << ", " << ((Keyboard*)(arg.device))->getAsString(arg.key)
<< "} || Character (" << (char)arg.text << ")" << std::endl; << "} || Character (" << (char)arg.text << ")" << std::endl;
return true; return true;
} }
bool keyReleased( const KeyEvent &arg ) { bool keyReleased( const KeyEvent &arg ) {
if( arg.key == KC_ESCAPE || arg.key == KC_Q ) if( arg.key == KC_ESCAPE || arg.key == KC_Q )
appRunning = false; appRunning = false;
std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n"; std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n";
return true; return true;
} }
bool mouseMoved( const MouseEvent &arg ) { bool mouseMoved( const MouseEvent &arg ) {
const OIS::MouseState& s = arg.state; const OIS::MouseState& s = arg.state;
std::cout << "\nMouseMoved: Abs(" std::cout << "\nMouseMoved: Abs("
<< s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel("
<< s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")";
return true; return true;
} }
bool mousePressed( const MouseEvent &arg, MouseButtonID id ) { bool mousePressed( const MouseEvent &arg, MouseButtonID id ) {
const OIS::MouseState& s = arg.state; const OIS::MouseState& s = arg.state;
std::cout << "\nMouse button #" << id << " pressed. Abs(" std::cout << "\nMouse button #" << id << " pressed. Abs("
<< s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel("
<< s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")";
return true; return true;
} }
bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) { bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) {
const OIS::MouseState& s = arg.state; const OIS::MouseState& s = arg.state;
std::cout << "\nMouse button #" << id << " released. Abs(" std::cout << "\nMouse button #" << id << " released. Abs("
<< s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel("
<< s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")";
return true; return true;
} }
bool buttonPressed( const JoyStickEvent &arg, int button ) { bool buttonPressed( const JoyStickEvent &arg, int button ) {
std::cout << std::endl << arg.device->vendor() << ". Button Pressed # " << button; std::cout << std::endl << arg.device->vendor() << ". Button Pressed # " << button;
return true; return true;
} }
bool buttonReleased( const JoyStickEvent &arg, int button ) { bool buttonReleased( const JoyStickEvent &arg, int button ) {
std::cout << std::endl << arg.device->vendor() << ". Button Released # " << button; std::cout << std::endl << arg.device->vendor() << ". Button Released # " << button;
return true; return true;
} }
bool axisMoved( const JoyStickEvent &arg, int axis ) bool axisMoved( const JoyStickEvent &arg, int axis )
{ {
//Provide a little dead zone //Provide a little dead zone
if( arg.state.mAxes[axis].abs > 2500 || arg.state.mAxes[axis].abs < -2500 ) if( arg.state.mAxes[axis].abs > 2500 || arg.state.mAxes[axis].abs < -2500 )
std::cout << std::endl << arg.device->vendor() << ". Axis # " << axis << " Value: " << arg.state.mAxes[axis].abs; std::cout << std::endl << arg.device->vendor() << ". Axis # " << axis << " Value: " << arg.state.mAxes[axis].abs;
return true; return true;
} }
bool povMoved( const JoyStickEvent &arg, int pov ) bool povMoved( const JoyStickEvent &arg, int pov )
{ {
std::cout << std::endl << arg.device->vendor() << ". POV" << pov << " "; std::cout << std::endl << arg.device->vendor() << ". POV" << pov << " ";
if( arg.state.mPOV[pov].direction & Pov::North ) //Going up if( arg.state.mPOV[pov].direction & Pov::North ) //Going up
std::cout << "North"; std::cout << "North";
else if( arg.state.mPOV[pov].direction & Pov::South ) //Going down else if( arg.state.mPOV[pov].direction & Pov::South ) //Going down
std::cout << "South"; std::cout << "South";
if( arg.state.mPOV[pov].direction & Pov::East ) //Going right if( arg.state.mPOV[pov].direction & Pov::East ) //Going right
std::cout << "East"; std::cout << "East";
else if( arg.state.mPOV[pov].direction & Pov::West ) //Going left else if( arg.state.mPOV[pov].direction & Pov::West ) //Going left
std::cout << "West"; std::cout << "West";
if( arg.state.mPOV[pov].direction == Pov::Centered ) //stopped/centered out if( arg.state.mPOV[pov].direction == Pov::Centered ) //stopped/centered out
std::cout << "Centered"; std::cout << "Centered";
return true; return true;
} }
bool vector3Moved( const JoyStickEvent &arg, int index) bool vector3Moved( const JoyStickEvent &arg, int index)
{ {
std::cout.precision(2); std::cout.precision(2);
std::cout.flags(std::ios::fixed | std::ios::right); std::cout.flags(std::ios::fixed | std::ios::right);
std::cout << std::endl << arg.device->vendor() << ". Orientation # " << index std::cout << std::endl << arg.device->vendor() << ". Orientation # " << index
<< " X Value: " << arg.state.mVectors[index].x << " X Value: " << arg.state.mVectors[index].x
<< " Y Value: " << arg.state.mVectors[index].y << " Y Value: " << arg.state.mVectors[index].y
<< " Z Value: " << arg.state.mVectors[index].z; << " Z Value: " << arg.state.mVectors[index].z;
std::cout.precision(); std::cout.precision();
std::cout.flags(); std::cout.flags();
return true; return true;
} }
}; };
//Create a global instance //Create a global instance
EventHandler handler; EventHandler handler;
int main() int main()
{ {
std::cout << "\n\n*** OIS Console Demo App is starting up... *** \n"; std::cout << "\n\n*** OIS Console Demo App is starting up... *** \n";
try try
{ {
doStartup(); doStartup();
std::cout << "\nStartup done... Hit 'q' or ESC to exit.\n\n"; std::cout << "\nStartup done... Hit 'q' or ESC to exit.\n\n";
while(appRunning) while(appRunning)
{ {
//Throttle down CPU usage //Throttle down CPU usage
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
Sleep(90); Sleep(90);
MSG msg; MSG msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{ {
TranslateMessage( &msg ); TranslateMessage( &msg );
DispatchMessage( &msg ); DispatchMessage( &msg );
} }
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
checkX11Events(); checkX11Events();
usleep( 500 ); usleep( 500 );
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
checkMacEvents(); checkMacEvents();
usleep( 500 ); usleep( 500 );
#endif #endif
if( g_kb ) if( g_kb )
{ {
g_kb->capture(); g_kb->capture();
if( !g_kb->buffered() ) if( !g_kb->buffered() )
handleNonBufferedKeys(); handleNonBufferedKeys();
} }
if( g_m ) if( g_m )
{ {
g_m->capture(); g_m->capture();
if( !g_m->buffered() ) if( !g_m->buffered() )
handleNonBufferedMouse(); handleNonBufferedMouse();
} }
for( int i = 0; i < 4 ; ++i ) for( int i = 0; i < 4 ; ++i )
{ {
if( g_joys[i] ) if( g_joys[i] )
{ {
g_joys[i]->capture(); g_joys[i]->capture();
if( !g_joys[i]->buffered() ) if( !g_joys[i]->buffered() )
handleNonBufferedJoy( g_joys[i] ); handleNonBufferedJoy( g_joys[i] );
} }
} }
} }
} }
catch( const Exception &ex ) catch( const Exception &ex )
{ {
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
MessageBox( NULL, ex.eText, "An exception has occurred!", MB_OK | MessageBox( NULL, ex.eText, "An exception has occurred!", MB_OK |
MB_ICONERROR | MB_TASKMODAL); MB_ICONERROR | MB_TASKMODAL);
#else #else
std::cout << "\nOIS Exception Caught!\n" << "\t" << ex.eText << "[Line " std::cout << "\nOIS Exception Caught!\n" << "\t" << ex.eText << "[Line "
<< ex.eLine << " in " << ex.eFile << "]\nExiting App"; << ex.eLine << " in " << ex.eFile << "]\nExiting App";
#endif #endif
} }
catch(std::exception &ex) catch(std::exception &ex)
{ {
std::cout << "Caught std::exception: what = " << ex.what() << std::endl; std::cout << "Caught std::exception: what = " << ex.what() << std::endl;
} }
//Destroying the manager will cleanup unfreed devices //Destroying the manager will cleanup unfreed devices
std::cout << "Cleaning up...\n"; std::cout << "Cleaning up...\n";
if( g_InputManager ) if( g_InputManager )
InputManager::destroyInputSystem(g_InputManager); InputManager::destroyInputSystem(g_InputManager);
#if defined OIS_LINUX_PLATFORM #if defined OIS_LINUX_PLATFORM
// Be nice to X and clean up the x window // Be nice to X and clean up the x window
XDestroyWindow(xDisp, xWin); XDestroyWindow(xDisp, xWin);
XCloseDisplay(xDisp); XCloseDisplay(xDisp);
#endif #endif
std::cout << "\nGoodbye!\n"; std::cout << "\nGoodbye!\n";
return 0; return 0;
} }
void doStartup() void doStartup()
{ {
ParamList pl; ParamList pl;
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
//Create a capture window for Input Grabbing //Create a capture window for Input Grabbing
hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc); hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc);
if( hWnd == NULL ) if( hWnd == NULL )
OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!"); OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!");
ShowWindow(hWnd, SW_SHOW); ShowWindow(hWnd, SW_SHOW);
std::ostringstream wnd; std::ostringstream wnd;
wnd << (size_t)hWnd; wnd << (size_t)hWnd;
pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() )); pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() ));
//Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive //Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive
// pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); // pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
// pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); // pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
//Connects to default X window //Connects to default X window
if( !(xDisp = XOpenDisplay(0)) ) if( !(xDisp = XOpenDisplay(0)) )
OIS_EXCEPT(E_General, "Error opening X!"); OIS_EXCEPT(E_General, "Error opening X!");
//Create a window //Create a window
xWin = XCreateSimpleWindow(xDisp, DefaultRootWindow(xDisp), 0, 0, 100, 100, 0, 0, 0); xWin = XCreateSimpleWindow(xDisp, DefaultRootWindow(xDisp), 0, 0, 100, 100, 0, 0, 0);
//bind our connection to that window //bind our connection to that window
XMapWindow(xDisp, xWin); XMapWindow(xDisp, xWin);
// XInternAtom // XInternAtom
//Select what events we want to listen to locally //Select what events we want to listen to locally
XSelectInput(xDisp, xWin, StructureNotifyMask | SubstructureNotifyMask); XSelectInput(xDisp, xWin, StructureNotifyMask | SubstructureNotifyMask);
Atom wmProto = XInternAtom(xDisp, "WM_PROTOCOLS", False); Atom wmProto = XInternAtom(xDisp, "WM_PROTOCOLS", False);
Atom wmDelete = XInternAtom(xDisp, "WM_DELETE_WINDOW", False); Atom wmDelete = XInternAtom(xDisp, "WM_DELETE_WINDOW", False);
XChangeProperty(xDisp, xWin, wmProto, XA_ATOM, 32, 0, (const unsigned char*)&wmDelete, 1); XChangeProperty(xDisp, xWin, wmProto, XA_ATOM, 32, 0, (const unsigned char*)&wmDelete, 1);
XEvent evtent; XEvent evtent;
do do
{ {
XNextEvent(xDisp, &evtent); XNextEvent(xDisp, &evtent);
} while(evtent.type != MapNotify); } while(evtent.type != MapNotify);
std::ostringstream wnd; std::ostringstream wnd;
wnd << xWin; wnd << xWin;
pl.insert(std::make_pair(std::string("WINDOW"), wnd.str())); pl.insert(std::make_pair(std::string("WINDOW"), wnd.str()));
//For this demo, show mouse and do not grab (confine to window) //For this demo, show mouse and do not grab (confine to window)
// pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false"))); // pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false")));
// pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false"))); // pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false")));
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
// create the window rect in global coords // create the window rect in global coords
::Rect windowRect; ::Rect windowRect;
windowRect.left = 0; windowRect.left = 0;
windowRect.top = 0; windowRect.top = 0;
windowRect.right = 300; windowRect.right = 300;
windowRect.bottom = 300; windowRect.bottom = 300;
// set the default attributes for the window // set the default attributes for the window
WindowAttributes windowAttrs = kWindowStandardDocumentAttributes WindowAttributes windowAttrs = kWindowStandardDocumentAttributes
| kWindowStandardHandlerAttribute | kWindowStandardHandlerAttribute
| kWindowInWindowMenuAttribute | kWindowInWindowMenuAttribute
| kWindowHideOnFullScreenAttribute; | kWindowHideOnFullScreenAttribute;
// Create the window // Create the window
CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWin); CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWin);
// Color the window background black // Color the window background black
SetThemeWindowBackground (mWin, kThemeBrushBlack, true); SetThemeWindowBackground (mWin, kThemeBrushBlack, true);
// Set the title of our window // Set the title of our window
CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, "OIS Input", kCFStringEncodingASCII ); CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, "OIS Input", kCFStringEncodingASCII );
SetWindowTitleWithCFString( mWin, titleRef ); SetWindowTitleWithCFString( mWin, titleRef );
// Center our window on the screen // Center our window on the screen
RepositionWindow( mWin, NULL, kWindowCenterOnMainScreen ); RepositionWindow( mWin, NULL, kWindowCenterOnMainScreen );
// Install the event handler for the window // Install the event handler for the window
InstallStandardEventHandler(GetWindowEventTarget(mWin)); InstallStandardEventHandler(GetWindowEventTarget(mWin));
// This will give our window focus, and not lock it to the terminal // This will give our window focus, and not lock it to the terminal
ProcessSerialNumber psn = { 0, kCurrentProcess }; ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType( &psn, kProcessTransformToForegroundApplication ); TransformProcessType( &psn, kProcessTransformToForegroundApplication );
SetFrontProcess(&psn); SetFrontProcess(&psn);
// Display and select our window // Display and select our window
ShowWindow(mWin); ShowWindow(mWin);
SelectWindow(mWin); SelectWindow(mWin);
std::ostringstream wnd; std::ostringstream wnd;
wnd << (unsigned int)mWin; //cast to int so it gets encoded correctly (else it gets stored as a hex string) wnd << (unsigned int)mWin; //cast to int so it gets encoded correctly (else it gets stored as a hex string)
std::cout << "WindowRef: " << mWin << " WindowRef as int: " << wnd.str() << "\n"; std::cout << "WindowRef: " << mWin << " WindowRef as int: " << wnd.str() << "\n";
pl.insert(std::make_pair(std::string("WINDOW"), wnd.str())); pl.insert(std::make_pair(std::string("WINDOW"), wnd.str()));
#endif #endif
//This never returns null.. it will raise an exception on errors //This never returns null.. it will raise an exception on errors
g_InputManager = InputManager::createInputSystem(pl); g_InputManager = InputManager::createInputSystem(pl);
//Lets enable all addons that were compiled in: //Lets enable all addons that were compiled in:
g_InputManager->enableAddOnFactory(InputManager::AddOn_All); g_InputManager->enableAddOnFactory(InputManager::AddOn_All);
//Print debugging information //Print debugging information
unsigned int v = g_InputManager->getVersionNumber(); unsigned int v = g_InputManager->getVersionNumber();
std::cout << "OIS Version: " << (v>>16 ) << "." << ((v>>8) & 0x000000FF) << "." << (v & 0x000000FF) std::cout << "OIS Version: " << (v>>16 ) << "." << ((v>>8) & 0x000000FF) << "." << (v & 0x000000FF)
<< "\nRelease Name: " << g_InputManager->getVersionName() << "\nRelease Name: " << g_InputManager->getVersionName()
<< "\nManager: " << g_InputManager->inputSystemName() << "\nManager: " << g_InputManager->inputSystemName()
<< "\nTotal Keyboards: " << g_InputManager->getNumberOfDevices(OISKeyboard) << "\nTotal Keyboards: " << g_InputManager->getNumberOfDevices(OISKeyboard)
<< "\nTotal Mice: " << g_InputManager->getNumberOfDevices(OISMouse) << "\nTotal Mice: " << g_InputManager->getNumberOfDevices(OISMouse)
<< "\nTotal JoySticks: " << g_InputManager->getNumberOfDevices(OISJoyStick); << "\nTotal JoySticks: " << g_InputManager->getNumberOfDevices(OISJoyStick);
//List all devices //List all devices
DeviceList list = g_InputManager->listFreeDevices(); DeviceList list = g_InputManager->listFreeDevices();
for( DeviceList::iterator i = list.begin(); i != list.end(); ++i ) for( DeviceList::iterator i = list.begin(); i != list.end(); ++i )
std::cout << "\n\tDevice: " << g_DeviceType[i->first] << " Vendor: " << i->second; std::cout << "\n\tDevice: " << g_DeviceType[i->first] << " Vendor: " << i->second;
g_kb = (Keyboard*)g_InputManager->createInputObject( OISKeyboard, true ); g_kb = (Keyboard*)g_InputManager->createInputObject( OISKeyboard, true );
g_kb->setEventCallback( &handler ); g_kb->setEventCallback( &handler );
g_m = (Mouse*)g_InputManager->createInputObject( OISMouse, true ); g_m = (Mouse*)g_InputManager->createInputObject( OISMouse, true );
g_m->setEventCallback( &handler ); g_m->setEventCallback( &handler );
const MouseState &ms = g_m->getMouseState(); const MouseState &ms = g_m->getMouseState();
ms.width = 100; ms.width = 100;
ms.height = 100; ms.height = 100;
try try
{ {
//This demo uses at most 4 joysticks - use old way to create (i.e. disregard vendor) //This demo uses at most 4 joysticks - use old way to create (i.e. disregard vendor)
int numSticks = std::min(g_InputManager->getNumberOfDevices(OISJoyStick), 4); int numSticks = std::min(g_InputManager->getNumberOfDevices(OISJoyStick), 4);
for( int i = 0; i < numSticks; ++i ) for( int i = 0; i < numSticks; ++i )
{ {
g_joys[i] = (JoyStick*)g_InputManager->createInputObject( OISJoyStick, true ); g_joys[i] = (JoyStick*)g_InputManager->createInputObject( OISJoyStick, true );
g_joys[i]->setEventCallback( &handler ); g_joys[i]->setEventCallback( &handler );
std::cout << "\n\nCreating Joystick " << (i + 1) std::cout << "\n\nCreating Joystick " << (i + 1)
<< "\n\tAxes: " << g_joys[i]->getNumberOfComponents(OIS_Axis) << "\n\tAxes: " << g_joys[i]->getNumberOfComponents(OIS_Axis)
<< "\n\tSliders: " << g_joys[i]->getNumberOfComponents(OIS_Slider) << "\n\tSliders: " << g_joys[i]->getNumberOfComponents(OIS_Slider)
<< "\n\tPOV/HATs: " << g_joys[i]->getNumberOfComponents(OIS_POV) << "\n\tPOV/HATs: " << g_joys[i]->getNumberOfComponents(OIS_POV)
<< "\n\tButtons: " << g_joys[i]->getNumberOfComponents(OIS_Button) << "\n\tButtons: " << g_joys[i]->getNumberOfComponents(OIS_Button)
<< "\n\tVector3: " << g_joys[i]->getNumberOfComponents(OIS_Vector3); << "\n\tVector3: " << g_joys[i]->getNumberOfComponents(OIS_Vector3);
} }
} }
catch(OIS::Exception &ex) catch(OIS::Exception &ex)
{ {
std::cout << "\nException raised on joystick creation: " << ex.eText << std::endl; std::cout << "\nException raised on joystick creation: " << ex.eText << std::endl;
} }
} }
void handleNonBufferedKeys() void handleNonBufferedKeys()
{ {
if( g_kb->isKeyDown( KC_ESCAPE ) || g_kb->isKeyDown( KC_Q ) ) if( g_kb->isKeyDown( KC_ESCAPE ) || g_kb->isKeyDown( KC_Q ) )
appRunning = false; appRunning = false;
if( g_kb->isModifierDown(Keyboard::Shift) ) if( g_kb->isModifierDown(Keyboard::Shift) )
std::cout << "Shift is down..\n"; std::cout << "Shift is down..\n";
if( g_kb->isModifierDown(Keyboard::Alt) ) if( g_kb->isModifierDown(Keyboard::Alt) )
std::cout << "Alt is down..\n"; std::cout << "Alt is down..\n";
if( g_kb->isModifierDown(Keyboard::Ctrl) ) if( g_kb->isModifierDown(Keyboard::Ctrl) )
std::cout << "Ctrl is down..\n"; std::cout << "Ctrl is down..\n";
} }
void handleNonBufferedMouse() void handleNonBufferedMouse()
{ {
//Just dump the current mouse state //Just dump the current mouse state
const MouseState &ms = g_m->getMouseState(); const MouseState &ms = g_m->getMouseState();
std::cout << "\nMouse: Abs(" << ms.X.abs << " " << ms.Y.abs << " " << ms.Z.abs std::cout << "\nMouse: Abs(" << ms.X.abs << " " << ms.Y.abs << " " << ms.Z.abs
<< ") B: " << ms.buttons << " Rel(" << ms.X.rel << " " << ms.Y.rel << " " << ms.Z.rel << ")"; << ") B: " << ms.buttons << " Rel(" << ms.X.rel << " " << ms.Y.rel << " " << ms.Z.rel << ")";
} }
void handleNonBufferedJoy( JoyStick* js ) void handleNonBufferedJoy( JoyStick* js )
{ {
//Just dump the current joy state //Just dump the current joy state
const JoyStickState &joy = js->getJoyStickState(); const JoyStickState &joy = js->getJoyStickState();
for( unsigned int i = 0; i < joy.mAxes.size(); ++i ) for( unsigned int i = 0; i < joy.mAxes.size(); ++i )
std::cout << "\nAxis " << i << " X: " << joy.mAxes[i].abs; std::cout << "\nAxis " << i << " X: " << joy.mAxes[i].abs;
} }
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{ {
return FALSE; return FALSE;
} }
#endif #endif
#if defined OIS_LINUX_PLATFORM #if defined OIS_LINUX_PLATFORM
//This is just here to show that you still recieve x11 events, as the lib only needs mouse/key events //This is just here to show that you still recieve x11 events, as the lib only needs mouse/key events
void checkX11Events() void checkX11Events()
{ {
if(!appRunning) if(!appRunning)
return; return;
XEvent event; XEvent event;
while(XPending(xDisp) > 0) while(XPending(xDisp) > 0)
{ {
XNextEvent(xDisp, &event); XNextEvent(xDisp, &event);
//Handle Resize events //Handle Resize events
if(event.type == ConfigureNotify) if(event.type == ConfigureNotify)
{ {
if(g_m) if(g_m)
{ {
const MouseState &ms = g_m->getMouseState(); const MouseState &ms = g_m->getMouseState();
ms.width = event.xconfigure.width; ms.width = event.xconfigure.width;
ms.height = event.xconfigure.height; ms.height = event.xconfigure.height;
} }
} }
else if(event.type == ClientMessage || event.type == DestroyNotify) else if(event.type == ClientMessage || event.type == DestroyNotify)
{ // We only get DestroyNotify for child windows. However, we regeistered earlier to receive WM_DELETE_MESSAGEs { // We only get DestroyNotify for child windows. However, we regeistered earlier to receive WM_DELETE_MESSAGEs
std::cout << "Exiting...\n"; std::cout << "Exiting...\n";
appRunning = false; appRunning = false;
return; return;
} }
else else
{ {
std::cout << "\nUnknown X Event: " << event.type << std::endl; std::cout << "\nUnknown X Event: " << event.type << std::endl;
} }
} }
} }
#endif #endif
#if defined OIS_APPLE_PLATFORM #if defined OIS_APPLE_PLATFORM
void checkMacEvents() void checkMacEvents()
{ {
//TODO - Check for window resize events, and then adjust the members of mousestate //TODO - Check for window resize events, and then adjust the members of mousestate
EventRef event = NULL; EventRef event = NULL;
EventTargetRef targetWindow = GetEventDispatcherTarget(); EventTargetRef targetWindow = GetEventDispatcherTarget();
if( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr ) if( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr )
{ {
SendEventToEventTarget(event, targetWindow); SendEventToEventTarget(event, targetWindow);
std::cout << "Event : " << GetEventKind(event) << "\n"; std::cout << "Event : " << GetEventKind(event) << "\n";
ReleaseEvent(event); ReleaseEvent(event);
} }
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_OISALL_H #ifndef OIS_OISALL_H
#define OIS_OISALL_H #define OIS_OISALL_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
#include "OISObject.h" #include "OISObject.h"
#include "OISMouse.h" #include "OISMouse.h"
#include "OISKeyboard.h" #include "OISKeyboard.h"
#include "OISJoyStick.h" #include "OISJoyStick.h"
#include "OISMultiTouch.h" #include "OISMultiTouch.h"
#include "OISInputManager.h" #include "OISInputManager.h"
#include "OISFactoryCreator.h" #include "OISFactoryCreator.h"
#include "OISException.h" #include "OISException.h"
#include "OISEvents.h" #include "OISEvents.h"
#include "OISEffect.h" #include "OISEffect.h"
#include "OISInterface.h" #include "OISInterface.h"
#include "OISForceFeedback.h" #include "OISForceFeedback.h"
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_CONFIG_HEADER #ifndef OIS_CONFIG_HEADER
#define OIS_CONFIG_HEADER #define OIS_CONFIG_HEADER
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
//* This file contains defines for building certain parts of this Lib //* This file contains defines for building certain parts of this Lib
//* This file is not meant for External inclusion. However, you can edit this //* This file is not meant for External inclusion. However, you can edit this
//* file before a build to effect what features are used internally //* file before a build to effect what features are used internally
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
/** /**
@remarks @remarks
These lines have no bearing on internal build of OIS. This is here for These lines have no bearing on internal build of OIS. This is here for
external build settings. Meaning, changing this does not require a external build settings. Meaning, changing this does not require a
rebuild of OIS. This just affects VC dll import settings, as the DLL rebuild of OIS. This just affects VC dll import settings, as the DLL
build already defines this during its build for setting dll exports. build already defines this during its build for setting dll exports.
The undefine here is here just incase you decide to only use The undefine here is here just incase you decide to only use
DLL, and want to set it permently and recompile OIS too.. Avoid redefinition DLL, and want to set it permently and recompile OIS too.. Avoid redefinition
from DLL build of OIS. from DLL build of OIS.
So, if wanting to link against DLL version, just uncomment these lines. So, if wanting to link against DLL version, just uncomment these lines.
*/ */
//#ifdef OIS_DYNAMIC_LIB //#ifdef OIS_DYNAMIC_LIB
//# undef OIS_DYNAMIC_LIB //# undef OIS_DYNAMIC_LIB
//#endif //#endif
//#define OIS_DYNAMIC_LIB //#define OIS_DYNAMIC_LIB
/** /**
@remarks @remarks
Build in support for LIRC / WinLIRC - remote control support. Build in support for LIRC / WinLIRC - remote control support.
Requires Boost::asio Requires Boost::asio
@notes @notes
Experimental - Supports connecting and enumerating. Control does not Experimental - Supports connecting and enumerating. Control does not
yet return state or events yet return state or events
*/ */
//#define OIS_LIRC_SUPPORT //#define OIS_LIRC_SUPPORT
/** /**
@remarks @remarks
Build in support for PC Nintendo WiiMote Win32 HID interface. Build in support for PC Nintendo WiiMote Win32 HID interface.
Requires Boost::threads Requires Boost::threads
@notes @notes
Useable, but not quite finished - supports rumble, all buttons, & main orientation axis. Useable, but not quite finished - supports rumble, all buttons, & main orientation axis.
Still needs Nunchuck, IR, and LED/Battery support. Still needs Nunchuck, IR, and LED/Battery support.
*/ */
//#define OIS_WIN32_WIIMOTE_SUPPORT //#define OIS_WIN32_WIIMOTE_SUPPORT
/** /**
@remarks @remarks
Build in support for Win32 XInput (Xbox 360 Controller) Build in support for Win32 XInput (Xbox 360 Controller)
*/ */
//#define OIS_WIN32_XINPUT_SUPPORT //#define OIS_WIN32_XINPUT_SUPPORT
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Effect_H #ifndef OIS_Effect_H
#define OIS_Effect_H #define OIS_Effect_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
namespace OIS namespace OIS
{ {
//Predeclare some Effect Property structs //Predeclare some Effect Property structs
class ForceEffect; class ForceEffect;
class ConstantEffect; class ConstantEffect;
class RampEffect; class RampEffect;
class PeriodicEffect; class PeriodicEffect;
class ConditionalEffect; class ConditionalEffect;
/** /**
Force Feedback is a relatively complex set of properties to upload to a device. Force Feedback is a relatively complex set of properties to upload to a device.
The best place for information on the different properties, effects, etc is in The best place for information on the different properties, effects, etc is in
the DX Documentation and MSDN - there are even pretty graphs ther =) the DX Documentation and MSDN - there are even pretty graphs ther =)
As this class is modeled on the the DX interface you can apply that same As this class is modeled on the the DX interface you can apply that same
knowledge to creating effects via this class on any OS supported by OIS. knowledge to creating effects via this class on any OS supported by OIS.
In anycase, this is the main class you will be using. There is *absolutely* no In anycase, this is the main class you will be using. There is *absolutely* no
need to instance any of the supporting ForceEffect classes yourself. need to instance any of the supporting ForceEffect classes yourself.
*/ */
class _OISExport Effect class _OISExport Effect
{ {
public: public:
//! Type of force //! Type of force
enum EForce enum EForce
{ {
UnknownForce = 0, UnknownForce = 0,
ConstantForce, ConstantForce,
RampForce, RampForce,
PeriodicForce, PeriodicForce,
ConditionalForce, ConditionalForce,
CustomForce, CustomForce,
_ForcesNumber // Always keep in last position. _ForcesNumber // Always keep in last position.
}; };
static const char* getForceTypeName(EForce eValue); static const char* getForceTypeName(EForce eValue);
//! Type of effect //! Type of effect
enum EType enum EType
{ {
//Type ----- Pairs with force: //Type ----- Pairs with force:
Unknown = 0, //UnknownForce Unknown = 0, //UnknownForce
Constant, //ConstantForce Constant, //ConstantForce
Ramp, //RampForce Ramp, //RampForce
Square, //PeriodicForce Square, //PeriodicForce
Triangle, //PeriodicForce Triangle, //PeriodicForce
Sine, //PeriodicForce Sine, //PeriodicForce
SawToothUp, //PeriodicForce SawToothUp, //PeriodicForce
SawToothDown,//PeriodicForce SawToothDown,//PeriodicForce
Friction, //ConditionalForce Friction, //ConditionalForce
Damper, //ConditionalForce Damper, //ConditionalForce
Inertia, //ConditionalForce Inertia, //ConditionalForce
Spring, //ConditionalForce Spring, //ConditionalForce
Custom, //CustomForce Custom, //CustomForce
_TypesNumber // Always keep in last position. _TypesNumber // Always keep in last position.
}; };
static const char* getEffectTypeName(EType eValue); static const char* getEffectTypeName(EType eValue);
//! Direction of the Force //! Direction of the Force
enum EDirection enum EDirection
{ {
NorthWest, NorthWest,
North, North,
NorthEast, NorthEast,
East, East,
SouthEast, SouthEast,
South, South,
SouthWest, SouthWest,
West, West,
_DirectionsNumber // Always keep in last position. _DirectionsNumber // Always keep in last position.
}; };
static const char* getDirectionName(EDirection eValue); static const char* getDirectionName(EDirection eValue);
/** /**
This constructor allows you to set the force type and effect. This constructor allows you to set the force type and effect.
*/ */
Effect(EForce ef, EType et); Effect(EForce ef, EType et);
virtual ~Effect(); virtual ~Effect();
const EForce force; const EForce force;
const EType type; const EType type;
//Infinite Time //Infinite Time
static const unsigned int OIS_INFINITE = 0xFFFFFFFF; static const unsigned int OIS_INFINITE = 0xFFFFFFFF;
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
//--- Set these variables before uploading or modifying an effect ---// //--- Set these variables before uploading or modifying an effect ---//
//Direction to apply to the force - affects two axes+ effects //Direction to apply to the force - affects two axes+ effects
EDirection direction; EDirection direction;
//Number of button triggering an effect (-1 means no trigger) //Number of button triggering an effect (-1 means no trigger)
short trigger_button; short trigger_button;
//Time to wait before an effect can be re-triggered (microseconds) //Time to wait before an effect can be re-triggered (microseconds)
unsigned int trigger_interval; unsigned int trigger_interval;
//Duration of an effect (microseconds) //Duration of an effect (microseconds)
unsigned int replay_length; unsigned int replay_length;
//Time to wait before to start playing an effect (microseconds) //Time to wait before to start playing an effect (microseconds)
unsigned int replay_delay; unsigned int replay_delay;
//Get the specific Force Effect. This should be cast depending on the EForce //Get the specific Force Effect. This should be cast depending on the EForce
ForceEffect* getForceEffect() const; ForceEffect* getForceEffect() const;
/** /**
@remarks @remarks
Set the number of Axes to use before the initial creation of the effect. Set the number of Axes to use before the initial creation of the effect.
Can only be done prior to creation! Use the FF interface to determine Can only be done prior to creation! Use the FF interface to determine
how many axes can be used (are availiable) how many axes can be used (are availiable)
*/ */
void setNumAxes(short nAxes); void setNumAxes(short nAxes);
/** /**
@remarks @remarks
Returns the number of axes used in this effect Returns the number of axes used in this effect
*/ */
short getNumAxes() const; short getNumAxes() const;
//------------- Library Internal -------------------------------------// //------------- Library Internal -------------------------------------//
/** /**
set internally.. do not change or you will not be able to upload/stop set internally.. do not change or you will not be able to upload/stop
this effect any more. It will become lost. It is mutable so even this effect any more. It will become lost. It is mutable so even
with const reference it can/will be changed by this lib with const reference it can/will be changed by this lib
*/ */
mutable int _handle; mutable int _handle;
protected: protected:
// Prevent copying. // Prevent copying.
Effect(const Effect&); Effect(const Effect&);
Effect& operator=(Effect); Effect& operator=(Effect);
ForceEffect* effect; //Properties depend on EForce ForceEffect* effect; //Properties depend on EForce
short axes; //Number of axes to use in effect short axes; //Number of axes to use in effect
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
Base class of all effect property classes Base class of all effect property classes
*/ */
class _OISExport ForceEffect class _OISExport ForceEffect
{ {
public: public:
virtual ~ForceEffect() {} virtual ~ForceEffect() {}
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
An optional envelope to be applied to the start/end of an effect. If any of An optional envelope to be applied to the start/end of an effect. If any of
these values are nonzero, then the envelope will be used in setting up the these values are nonzero, then the envelope will be used in setting up the
effect. effect.
*/ */
class _OISExport Envelope : public ForceEffect class _OISExport Envelope : public ForceEffect
{ {
public: public:
Envelope() : attackLength(0), attackLevel(0), fadeLength(0), fadeLevel(0) {} Envelope() : attackLength(0), attackLevel(0), fadeLength(0), fadeLevel(0) {}
#if defined(OIS_MSVC_COMPILER) #if defined(OIS_MSVC_COMPILER)
#pragma warning (push) #pragma warning (push)
#pragma warning (disable : 4800) #pragma warning (disable : 4800)
#endif #endif
bool isUsed() const { return attackLength | attackLevel | fadeLength | fadeLevel; } bool isUsed() const { return attackLength | attackLevel | fadeLength | fadeLevel; }
#if defined(OIS_MSVC_COMPILER) #if defined(OIS_MSVC_COMPILER)
#pragma warning (pop) #pragma warning (pop)
#endif #endif
// Duration of the attack (microseconds) // Duration of the attack (microseconds)
unsigned int attackLength; unsigned int attackLength;
// Absolute level at the beginning of the attack (0 to 10K) // Absolute level at the beginning of the attack (0 to 10K)
// (automatically signed when necessary by FF core according to effect level sign) // (automatically signed when necessary by FF core according to effect level sign)
unsigned short attackLevel; unsigned short attackLevel;
// Duration of fade (microseconds) // Duration of fade (microseconds)
unsigned int fadeLength; unsigned int fadeLength;
// Absolute level at the end of fade (0 to 10K) // Absolute level at the end of fade (0 to 10K)
// (automatically signed when necessary by FF core according to effect level sign) // (automatically signed when necessary by FF core according to effect level sign)
unsigned short fadeLevel; unsigned short fadeLevel;
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
Use this class when dealing with Force type of Constant Use this class when dealing with Force type of Constant
*/ */
class _OISExport ConstantEffect : public ForceEffect class _OISExport ConstantEffect : public ForceEffect
{ {
public: public:
ConstantEffect() : level(5000) {} ConstantEffect() : level(5000) {}
Envelope envelope; //Optional envolope Envelope envelope; //Optional envolope
signed short level; //-10K to +10k signed short level; //-10K to +10k
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
Use this class when dealing with Force type of Ramp Use this class when dealing with Force type of Ramp
*/ */
class _OISExport RampEffect : public ForceEffect class _OISExport RampEffect : public ForceEffect
{ {
public: public:
RampEffect() : startLevel(0), endLevel(0) {} RampEffect() : startLevel(0), endLevel(0) {}
Envelope envelope; //Optional envelope Envelope envelope; //Optional envelope
signed short startLevel; //-10K to +10k signed short startLevel; //-10K to +10k
signed short endLevel; //-10K to +10k signed short endLevel; //-10K to +10k
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
Use this class when dealing with Force type of Periodic Use this class when dealing with Force type of Periodic
*/ */
class _OISExport PeriodicEffect : public ForceEffect class _OISExport PeriodicEffect : public ForceEffect
{ {
public: public:
PeriodicEffect() : magnitude(0), offset(0), phase(0), period(0) {} PeriodicEffect() : magnitude(0), offset(0), phase(0), period(0) {}
Envelope envelope; //Optional Envelope Envelope envelope; //Optional Envelope
unsigned short magnitude; //0 to 10,0000 unsigned short magnitude; //0 to 10,0000
signed short offset; signed short offset;
unsigned short phase; //Position at which playback begins 0 to 35,999 unsigned short phase; //Position at which playback begins 0 to 35,999
unsigned int period; //Period of effect (microseconds) unsigned int period; //Period of effect (microseconds)
}; };
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
/** /**
Use this class when dealing with Force type of Condional Use this class when dealing with Force type of Condional
*/ */
class _OISExport ConditionalEffect : public ForceEffect class _OISExport ConditionalEffect : public ForceEffect
{ {
public: public:
ConditionalEffect() : ConditionalEffect() :
rightCoeff(0), leftCoeff(0), rightSaturation(0), leftSaturation(0), rightCoeff(0), leftCoeff(0), rightSaturation(0), leftSaturation(0),
deadband(0), center(0) {} deadband(0), center(0) {}
signed short rightCoeff; //-10k to +10k (Positive Coeff) signed short rightCoeff; //-10k to +10k (Positive Coeff)
signed short leftCoeff; //-10k to +10k (Negative Coeff) signed short leftCoeff; //-10k to +10k (Negative Coeff)
unsigned short rightSaturation; //0 to 10k (Pos Saturation) unsigned short rightSaturation; //0 to 10k (Pos Saturation)
unsigned short leftSaturation; //0 to 10k (Neg Saturation) unsigned short leftSaturation; //0 to 10k (Neg Saturation)
//Region around center in which the condition is not active, in the range //Region around center in which the condition is not active, in the range
//from 0 through 10,000 //from 0 through 10,000
unsigned short deadband; unsigned short deadband;
//(Offset in DX) -10k and 10k //(Offset in DX) -10k and 10k
signed short center; signed short center;
}; };
} }
#endif //OIS_Effect_H #endif //OIS_Effect_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _OIS_EVENTHEADERS_ #ifndef _OIS_EVENTHEADERS_
#define _OIS_EVENTHEADERS_ #define _OIS_EVENTHEADERS_
#include "OISPrereqs.h" #include "OISPrereqs.h"
namespace OIS namespace OIS
{ {
/** /**
Base class of all events Base class of all events
*/ */
class _OISExport EventArg class _OISExport EventArg
{ {
public: public:
explicit EventArg( Object* obj ) : device(obj) {} explicit EventArg( Object* obj ) : device(obj) {}
virtual ~EventArg() {} virtual ~EventArg() {}
//! Pointer to the Input Device //! Pointer to the Input Device
const Object* device; const Object* device;
}; };
} }
#endif //_OIS_EVENTHEADERS_ #endif //_OIS_EVENTHEADERS_
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _OIS_EXCEPTION_HEADER_ #ifndef _OIS_EXCEPTION_HEADER_
#define _OIS_EXCEPTION_HEADER_ #define _OIS_EXCEPTION_HEADER_
#include "OISPrereqs.h" #include "OISPrereqs.h"
#include <exception> #include <exception>
namespace OIS namespace OIS
{ {
//! Simple enum's for dealing with exceptions //! Simple enum's for dealing with exceptions
enum OIS_ERROR enum OIS_ERROR
{ {
E_InputDisconnected, E_InputDisconnected,
E_InputDeviceNonExistant, E_InputDeviceNonExistant,
E_InputDeviceNotSupported, E_InputDeviceNotSupported,
E_DeviceFull, E_DeviceFull,
E_NotSupported, E_NotSupported,
E_NotImplemented, E_NotImplemented,
E_Duplicate, E_Duplicate,
E_InvalidParam, E_InvalidParam,
E_General E_General
}; };
/** /**
@remarks @remarks
Class for handling OIS exceptions. Much cleaner than checking every method for reurn value. Class for handling OIS exceptions. Much cleaner than checking every method for reurn value.
Inherits from std::exception so you can simply log those messages if you want to be generic. Inherits from std::exception so you can simply log those messages if you want to be generic.
Also note that this has a source file now since OSX was not finding the OIS::Exception symbol Also note that this has a source file now since OSX was not finding the OIS::Exception symbol
which would cause program abortion with now correponding exception type. which would cause program abortion with now correponding exception type.
*/ */
class _OISExport Exception : public std::exception class _OISExport Exception : public std::exception
{ {
public: public:
//! Creates exception object //! Creates exception object
Exception( OIS_ERROR err, const char* str, int line, const char *file ) Exception( OIS_ERROR err, const char* str, int line, const char *file )
: eType(err), eLine(line), eFile(file), eText(str) {} : eType(err), eLine(line), eFile(file), eText(str) {}
Exception(const Exception& other) Exception(const Exception& other)
: eType(other.eType), eLine(other.eLine), eFile(other.eFile), eText(other.eText) {} : eType(other.eType), eLine(other.eLine), eFile(other.eFile), eText(other.eText) {}
~Exception() throw() {} ~Exception() throw() {}
virtual const char* what() const throw(); virtual const char* what() const throw();
//! The type of exception raised //! The type of exception raised
const OIS_ERROR eType; const OIS_ERROR eType;
//! The line number it occurred on //! The line number it occurred on
const int eLine; const int eLine;
//! The source file //! The source file
const char* eFile; const char* eFile;
//! A message passed along when the exception was raised //! A message passed along when the exception was raised
const char* eText; const char* eText;
private: private:
// Unimplemented and unaccessible due to const members. // Unimplemented and unaccessible due to const members.
Exception& operator=(Exception); Exception& operator=(Exception);
}; };
} }
//! Use this macro to handle exceptions easily //! Use this macro to handle exceptions easily
#define OIS_EXCEPT( err, str ) throw( OIS::Exception(err, str, __LINE__, __FILE__) ) #define OIS_EXCEPT( err, str ) throw( OIS::Exception(err, str, __LINE__, __FILE__) )
#endif //_OIS_EXCEPTION_HEADER_ #endif //_OIS_EXCEPTION_HEADER_
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_FactoryCreator_H #ifndef OIS_FactoryCreator_H
#define OIS_FactoryCreator_H #define OIS_FactoryCreator_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
namespace OIS namespace OIS
{ {
/** /**
Interface for creating devices - all devices ultimately get enumerated/created via a factory. Interface for creating devices - all devices ultimately get enumerated/created via a factory.
A factory can create multiple types of objects. A factory can create multiple types of objects.
*/ */
class _OISExport FactoryCreator class _OISExport FactoryCreator
{ {
public: public:
/** /**
@remarks Virtual Destructor @remarks Virtual Destructor
*/ */
virtual ~FactoryCreator() {}; virtual ~FactoryCreator() {};
/** /**
@remarks Return a list of all unused devices the factory maintains @remarks Return a list of all unused devices the factory maintains
*/ */
virtual DeviceList freeDeviceList() = 0; virtual DeviceList freeDeviceList() = 0;
/** /**
@remarks Number of total devices of requested type @remarks Number of total devices of requested type
@param iType Type of devices to check @param iType Type of devices to check
*/ */
virtual int totalDevices(Type iType) = 0; virtual int totalDevices(Type iType) = 0;
/** /**
@remarks Number of free devices of requested type @remarks Number of free devices of requested type
@param iType Type of devices to check @param iType Type of devices to check
*/ */
virtual int freeDevices(Type iType) = 0; virtual int freeDevices(Type iType) = 0;
/** /**
@remarks Does a Type exist with the given vendor name @remarks Does a Type exist with the given vendor name
@param iType Type to check @param iType Type to check
@param vendor Vendor name to test @param vendor Vendor name to test
*/ */
virtual bool vendorExist(Type iType, const std::string & vendor) = 0; virtual bool vendorExist(Type iType, const std::string & vendor) = 0;
/** /**
@remarks Creates the object @remarks Creates the object
@param iType Type to create @param iType Type to create
@param bufferMode True to setup for buffered events @param bufferMode True to setup for buffered events
@param vendor Create a device with the vendor name, "" means vendor name is unimportant @param vendor Create a device with the vendor name, "" means vendor name is unimportant
*/ */
virtual Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "") = 0; virtual Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "") = 0;
/** /**
@remarks Destroys object @remarks Destroys object
@param obj Object to destroy @param obj Object to destroy
*/ */
virtual void destroyObject(Object* obj) = 0; virtual void destroyObject(Object* obj) = 0;
}; };
} }
#endif //OIS_FactoryCreator_H #endif //OIS_FactoryCreator_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_ForceFeedBack_H #ifndef OIS_ForceFeedBack_H
#define OIS_ForceFeedBack_H #define OIS_ForceFeedBack_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
#include "OISInterface.h" #include "OISInterface.h"
#include "OISEffect.h" #include "OISEffect.h"
namespace OIS namespace OIS
{ {
/** /**
Interface class for dealing with Force Feedback devices Interface class for dealing with Force Feedback devices
*/ */
class _OISExport ForceFeedback : public Interface class _OISExport ForceFeedback : public Interface
{ {
public: public:
ForceFeedback(); ForceFeedback();
virtual ~ForceFeedback() {} virtual ~ForceFeedback() {}
/** /**
@remarks @remarks
This is like setting the master volume of an audio device. This is like setting the master volume of an audio device.
Individual effects have gain levels; however, this affects all Individual effects have gain levels; however, this affects all
effects at once. effects at once.
Note: If the device does not support master gain setting, nothing is done Note: If the device does not support master gain setting, nothing is done
@param level @param level
A value between 0.0 and 1.0 represent the percentage of gain. 1.0 A value between 0.0 and 1.0 represent the percentage of gain. 1.0
being the highest possible force level (means no scaling). being the highest possible force level (means no scaling).
*/ */
virtual void setMasterGain( float level ) = 0; virtual void setMasterGain( float level ) = 0;
/** /**
@remarks @remarks
If using Force Feedback effects, this should be turned off If using Force Feedback effects, this should be turned off
before uploading any effects. Auto centering is the motor moving before uploading any effects. Auto centering is the motor moving
the joystick back to center. DirectInput only has an on/off setting, the joystick back to center. DirectInput only has an on/off setting,
whereas linux has levels.. Though, we go with DI's on/off mode only whereas linux has levels.. Though, we go with DI's on/off mode only
Note: If the device does not support auto-centering, nothing is done Note: If the device does not support auto-centering, nothing is done
@param auto_on @param auto_on
true to turn auto centering on, false to turn off. true to turn auto centering on, false to turn off.
*/ */
virtual void setAutoCenterMode( bool auto_on ) = 0; virtual void setAutoCenterMode( bool auto_on ) = 0;
/** /**
@remarks @remarks
Creates and Plays the effect immediately. If the device is full Creates and Plays the effect immediately. If the device is full
of effects, it will fail to be uploaded. You will know this by of effects, it will fail to be uploaded. You will know this by
an invalid Effect Handle an invalid Effect Handle
*/ */
virtual void upload( const Effect* effect ) = 0; virtual void upload( const Effect* effect ) = 0;
/** /**
@remarks @remarks
Modifies an effect that is currently playing Modifies an effect that is currently playing
*/ */
virtual void modify( const Effect* effect ) = 0; virtual void modify( const Effect* effect ) = 0;
/** /**
@remarks @remarks
Remove the effect from the device Remove the effect from the device
*/ */
virtual void remove( const Effect* effect ) = 0; virtual void remove( const Effect* effect ) = 0;
/** /**
@remarks @remarks
Get the number of supported Axes for FF usage Get the number of supported Axes for FF usage
*/ */
virtual short getFFAxesNumber() = 0; virtual short getFFAxesNumber() = 0;
/** /**
@remarks @remarks
Get the current load (%, in [0, 100] of the FF device memory Get the current load (%, in [0, 100] of the FF device memory
*/ */
virtual unsigned short getFFMemoryLoad() = 0; virtual unsigned short getFFMemoryLoad() = 0;
typedef std::multimap<Effect::EForce, Effect::EType> SupportedEffectList; typedef std::multimap<Effect::EForce, Effect::EType> SupportedEffectList;
/** /**
@remarks @remarks
Get a list of all supported effects Get a list of all supported effects
*/ */
const SupportedEffectList& getSupportedEffects() const; const SupportedEffectList& getSupportedEffects() const;
/** /**
@remarks @remarks
Tell if a given force / effect type pair is supported Tell if a given force / effect type pair is supported
*/ */
bool supportsEffect(Effect::EForce force, Effect::EType type) const; bool supportsEffect(Effect::EForce force, Effect::EType type) const;
void _addEffectTypes( Effect::EForce force, Effect::EType type ); void _addEffectTypes( Effect::EForce force, Effect::EType type );
void _setGainSupport( bool on ); void _setGainSupport( bool on );
void _setAutoCenterSupport( bool on ); void _setAutoCenterSupport( bool on );
protected: protected:
SupportedEffectList mSupportedEffects; SupportedEffectList mSupportedEffects;
bool mSetGainSupport; bool mSetGainSupport;
bool mSetAutoCenterSupport; bool mSetAutoCenterSupport;
}; };
} }
#endif //OIS_ForceFeedBack_H #endif //OIS_ForceFeedBack_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_InputManager_H #ifndef OIS_InputManager_H
#define OIS_InputManager_H #define OIS_InputManager_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
namespace OIS namespace OIS
{ {
//Forward declare a couple of classes we might use later //Forward declare a couple of classes we might use later
class LIRCFactoryCreator; class LIRCFactoryCreator;
class WiiMoteFactoryCreator; class WiiMoteFactoryCreator;
/** /**
Base Manager class. No longer a Singleton; so feel free to create as many InputManager's as you have Base Manager class. No longer a Singleton; so feel free to create as many InputManager's as you have
windows. windows.
*/ */
class _OISExport InputManager class _OISExport InputManager
{ {
public: public:
/** /**
@remarks @remarks
Returns version number (useful in DLL/SO libs) Returns version number (useful in DLL/SO libs)
@returns @returns
Bits: 1-8 Patch number, 9-16 Minor version, 17-32 Major version Bits: 1-8 Patch number, 9-16 Minor version, 17-32 Major version
*/ */
static unsigned int getVersionNumber(); static unsigned int getVersionNumber();
/** /**
@remarks @remarks
Returns version string (useful in DLL/SO libs) Returns version string (useful in DLL/SO libs)
@returns @returns
Version name Version name
*/ */
const std::string &getVersionName(); const std::string &getVersionName();
/** /**
@remarks @remarks
Creates appropriate input system dependent on platform. Creates appropriate input system dependent on platform.
@param winHandle @param winHandle
Contains OS specific window handle (such as HWND or X11 Window) Contains OS specific window handle (such as HWND or X11 Window)
@returns @returns
A pointer to the created manager, or raises Exception A pointer to the created manager, or raises Exception
*/ */
static InputManager* createInputSystem( std::size_t winHandle ); static InputManager* createInputSystem( std::size_t winHandle );
/** /**
@remarks @remarks
Creates appropriate input system dependent on platform. Creates appropriate input system dependent on platform.
@param paramList @param paramList
ParamList contains OS specific info (such as HWND and HINSTANCE for window apps), ParamList contains OS specific info (such as HWND and HINSTANCE for window apps),
and access mode. and access mode.
@returns @returns
A pointer to the created manager, or raises Exception A pointer to the created manager, or raises Exception
*/ */
static InputManager* createInputSystem( ParamList &paramList ); static InputManager* createInputSystem( ParamList &paramList );
/** /**
@remarks @remarks
Destroys the InputManager Destroys the InputManager
@param manager @param manager
Manager to destroy Manager to destroy
*/ */
static void destroyInputSystem(InputManager* manager); static void destroyInputSystem(InputManager* manager);
/** /**
@remarks Gets the name of the current platform input system @remarks Gets the name of the current platform input system
*/ */
const std::string& inputSystemName(); const std::string& inputSystemName();
/** /**
@remarks @remarks
Returns the number of the specified OIS::Type devices discovered by OIS Returns the number of the specified OIS::Type devices discovered by OIS
@param iType @param iType
Type that you are interested in Type that you are interested in
*/ */
int getNumberOfDevices( Type iType ); int getNumberOfDevices( Type iType );
/** /**
@remarks @remarks
Lists all unused devices Lists all unused devices
@returns @returns
DeviceList which contains Type and vendor of device DeviceList which contains Type and vendor of device
*/ */
DeviceList listFreeDevices(); DeviceList listFreeDevices();
/** /**
@remarks @remarks
Tries to create an object with the specified vendor. If you have no Tries to create an object with the specified vendor. If you have no
preference of vendor, leave vender as default (""). Raises exception on failure preference of vendor, leave vender as default (""). Raises exception on failure
*/ */
Object* createInputObject( Type iType, bool bufferMode, const std::string &vendor = ""); Object* createInputObject( Type iType, bool bufferMode, const std::string &vendor = "");
/** /**
@remarks Destroys Input Object @remarks Destroys Input Object
*/ */
void destroyInputObject( Object* obj ); void destroyInputObject( Object* obj );
/** /**
@remarks @remarks
Add a custom object factory to allow for user controls. Add a custom object factory to allow for user controls.
@param factory @param factory
Factory instance to add Factory instance to add
@notes @notes
Make sure you do not delete the factory before devices created from Make sure you do not delete the factory before devices created from
the factory are destroyed (either by calling RemoveFactoryCreator, or shutting down the factory are destroyed (either by calling RemoveFactoryCreator, or shutting down
the input system). Order should be something like the following: the input system). Order should be something like the following:
* Create Input System * Create Input System
* Create Factory Instance * Create Factory Instance
* AddFactoryCreator(factory) * AddFactoryCreator(factory)
* Create a device from the InputManager (device created by factory) * Create a device from the InputManager (device created by factory)
* One of the follwoing: * One of the follwoing:
* removeFactoryCreator(factory) * removeFactoryCreator(factory)
* inputManager->destroyInputObject(obj) * inputManager->destroyInputObject(obj)
* destroyInputSystem(inputManager) * destroyInputSystem(inputManager)
* destroy Factory Instance * destroy Factory Instance
You can safely delete the factory instance once you have removed it or shut down the You can safely delete the factory instance once you have removed it or shut down the
input manager. input manager.
*/ */
void addFactoryCreator( FactoryCreator* factory ); void addFactoryCreator( FactoryCreator* factory );
/** /**
@remarks @remarks
Remove a previously added object factory Remove a previously added object factory
@param factory @param factory
Factory object to remove. Factory object to remove.
@notes @notes
Removing a factory will automatically destroy any Objects created from the factory Removing a factory will automatically destroy any Objects created from the factory
*/ */
void removeFactoryCreator( FactoryCreator* factory ); void removeFactoryCreator( FactoryCreator* factory );
//! All generic devices OIS supports internally (if they are compiled in) //! All generic devices OIS supports internally (if they are compiled in)
enum AddOnFactories enum AddOnFactories
{ {
AddOn_All = 0, //All Devices AddOn_All = 0, //All Devices
AddOn_LIRC = 1, //PC Linux Infrared Remote Control AddOn_LIRC = 1, //PC Linux Infrared Remote Control
AddOn_WiiMote = 2 //PC WiiMote Support AddOn_WiiMote = 2 //PC WiiMote Support
}; };
/** /**
@remarks @remarks
Enable an addon FactoryCreator extension. By default, none are activated. Enable an addon FactoryCreator extension. By default, none are activated.
If the desired support was not compiled in, this has no effect. Calling If the desired support was not compiled in, this has no effect. Calling
multiple times has no effect. Once activated, there is no way to deactivate - multiple times has no effect. Once activated, there is no way to deactivate -
simply destroy and recreate input manager. simply destroy and recreate input manager.
*/ */
void enableAddOnFactory(AddOnFactories factory); void enableAddOnFactory(AddOnFactories factory);
protected: protected:
/** /**
@remarks @remarks
Called from createInputSystem, gives derived input class a chance to setup after it is created Called from createInputSystem, gives derived input class a chance to setup after it is created
*/ */
virtual void _initialize(ParamList &paramList) = 0; virtual void _initialize(ParamList &paramList) = 0;
/** /**
@remarks @remarks
Derived classes must provide input system name Derived classes must provide input system name
*/ */
explicit InputManager(const std::string& name); explicit InputManager(const std::string& name);
/** /**
@remarks @remarks
Virtual Destructor - this base class will clean up all devices still opened in mFactoryObjects list Virtual Destructor - this base class will clean up all devices still opened in mFactoryObjects list
*/ */
virtual ~InputManager(); virtual ~InputManager();
//! OIS Version name //! OIS Version name
const std::string m_VersionName; const std::string m_VersionName;
//! FactoryCreator list //! FactoryCreator list
FactoryList mFactories; FactoryList mFactories;
//! Factory created objects - useful so we can find creator to send destruction request to //! Factory created objects - useful so we can find creator to send destruction request to
FactoryCreatedObject mFactoryObjects; FactoryCreatedObject mFactoryObjects;
//! Name of the input system //! Name of the input system
const std::string mInputSystemName; const std::string mInputSystemName;
//! Extra factory (not enabled by default) //! Extra factory (not enabled by default)
LIRCFactoryCreator *m_lircSupport; LIRCFactoryCreator *m_lircSupport;
WiiMoteFactoryCreator *m_wiiMoteSupport; WiiMoteFactoryCreator *m_wiiMoteSupport;
private: private:
// Prevent copying. // Prevent copying.
InputManager(const InputManager&); InputManager(const InputManager&);
InputManager& operator=(InputManager); InputManager& operator=(InputManager);
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Interface_H #ifndef OIS_Interface_H
#define OIS_Interface_H #define OIS_Interface_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
namespace OIS namespace OIS
{ {
/** /**
An Object's interface is a way to gain write access to devices which support An Object's interface is a way to gain write access to devices which support
it. For example, force feedack. it. For example, force feedack.
*/ */
class _OISExport Interface class _OISExport Interface
{ {
public: public:
virtual ~Interface() {}; virtual ~Interface() {};
//! Type of Interface //! Type of Interface
enum IType enum IType
{ {
ForceFeedback, ForceFeedback,
Reserved Reserved
}; };
}; };
} }
#endif //OIS_Interface_H #endif //OIS_Interface_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Joystick_H #ifndef OIS_Joystick_H
#define OIS_Joystick_H #define OIS_Joystick_H
#include "OISObject.h" #include "OISObject.h"
#include "OISEvents.h" #include "OISEvents.h"
namespace OIS namespace OIS
{ {
/** @remarks default sensitivity for vector3 component of joystick */ /** @remarks default sensitivity for vector3 component of joystick */
#define OIS_JOYSTICK_VECTOR3_DEFAULT 2.28f #define OIS_JOYSTICK_VECTOR3_DEFAULT 2.28f
//! POV / HAT Joystick component //! POV / HAT Joystick component
class _OISExport Pov : public Component class _OISExport Pov : public Component
{ {
public: public:
Pov() : Component(OIS_POV), direction(0) {} Pov() : Component(OIS_POV), direction(0) {}
static const int Centered = 0x00000000; static const int Centered = 0x00000000;
static const int North = 0x00000001; static const int North = 0x00000001;
static const int South = 0x00000010; static const int South = 0x00000010;
static const int East = 0x00000100; static const int East = 0x00000100;
static const int West = 0x00001000; static const int West = 0x00001000;
static const int NorthEast = 0x00000101; static const int NorthEast = 0x00000101;
static const int SouthEast = 0x00000110; static const int SouthEast = 0x00000110;
static const int NorthWest = 0x00001001; static const int NorthWest = 0x00001001;
static const int SouthWest = 0x00001010; static const int SouthWest = 0x00001010;
int direction; int direction;
}; };
//! A sliding axis - only used in Win32 Right Now //! A sliding axis - only used in Win32 Right Now
class _OISExport Slider : public Component class _OISExport Slider : public Component
{ {
public: public:
Slider() : Component(OIS_Slider), abX(0), abY(0) {}; Slider() : Component(OIS_Slider), abX(0), abY(0) {};
//! true if pushed, false otherwise //! true if pushed, false otherwise
int abX, abY; int abX, abY;
}; };
/** /**
Represents the state of the joystick Represents the state of the joystick
All members are valid for both buffered and non buffered mode All members are valid for both buffered and non buffered mode
Sticks with zero values are not present on the device Sticks with zero values are not present on the device
*/ */
class _OISExport JoyStickState class _OISExport JoyStickState
{ {
public: public:
//! Constructor //! Constructor
JoyStickState() { clear(); } JoyStickState() { clear(); }
//! Represents all the buttons (uses a bitset) //! Represents all the buttons (uses a bitset)
std::vector<bool> mButtons; std::vector<bool> mButtons;
//! Represents all the single axes on the device //! Represents all the single axes on the device
std::vector<Axis> mAxes; std::vector<Axis> mAxes;
//! Represents the value of a POV. Maximum of 4 //! Represents the value of a POV. Maximum of 4
Pov mPOV[4]; Pov mPOV[4];
//! Represent the max sliders //! Represent the max sliders
Slider mSliders[4]; Slider mSliders[4];
//! Represents all Vector type controls the device exports //! Represents all Vector type controls the device exports
std::vector<Vector3> mVectors; std::vector<Vector3> mVectors;
//! internal method to reset all variables to initial values //! internal method to reset all variables to initial values
void clear() void clear()
{ {
for( std::vector<bool>::iterator i = mButtons.begin(), e = mButtons.end(); i != e; ++i ) for( std::vector<bool>::iterator i = mButtons.begin(), e = mButtons.end(); i != e; ++i )
{ {
(*i) = false; (*i) = false;
} }
for( std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i ) for( std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i )
{ {
i->absOnly = true; //Currently, joysticks only report Absolute values i->absOnly = true; //Currently, joysticks only report Absolute values
i->clear(); i->clear();
} }
for( std::vector<Vector3>::iterator i = mVectors.begin(), e = mVectors.end(); i != e; ++i ) for( std::vector<Vector3>::iterator i = mVectors.begin(), e = mVectors.end(); i != e; ++i )
{ {
i->clear(); i->clear();
} }
for( int i = 0; i < 4; ++i ) for( int i = 0; i < 4; ++i )
{ {
mPOV[i].direction = Pov::Centered; mPOV[i].direction = Pov::Centered;
mSliders[i].abX = mSliders[i].abY = 0; mSliders[i].abX = mSliders[i].abY = 0;
} }
} }
}; };
/** Specialised for joystick events */ /** Specialised for joystick events */
class _OISExport JoyStickEvent : public EventArg class _OISExport JoyStickEvent : public EventArg
{ {
public: public:
JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {} JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {}
virtual ~JoyStickEvent() {} virtual ~JoyStickEvent() {}
const JoyStickState &state; const JoyStickState &state;
private: private:
// Prevent copying. // Prevent copying.
JoyStickEvent(const JoyStickEvent&); JoyStickEvent(const JoyStickEvent&);
JoyStickEvent& operator=(JoyStickEvent); JoyStickEvent& operator=(JoyStickEvent);
}; };
/** /**
To recieve buffered joystick input, derive a class from this, and implement the To recieve buffered joystick input, derive a class from this, and implement the
methods here. Then set the call back to your JoyStick instance with JoyStick::setEventCallback methods here. Then set the call back to your JoyStick instance with JoyStick::setEventCallback
Each JoyStick instance can use the same callback class, as a devID number will be provided Each JoyStick instance can use the same callback class, as a devID number will be provided
to differentiate between connected joysticks. Of course, each can have a seperate to differentiate between connected joysticks. Of course, each can have a seperate
callback instead. callback instead.
*/ */
class _OISExport JoyStickListener class _OISExport JoyStickListener
{ {
public: public:
virtual ~JoyStickListener() {} virtual ~JoyStickListener() {}
/** @remarks Joystick button down event */ /** @remarks Joystick button down event */
virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0; virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0;
/** @remarks Joystick button up event */ /** @remarks Joystick button up event */
virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0; virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0;
/** @remarks Joystick axis moved event */ /** @remarks Joystick axis moved event */
virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0; virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0;
//-- Not so common control events, so are not required --// //-- Not so common control events, so are not required --//
//! Joystick Event, and sliderID //! Joystick Event, and sliderID
virtual bool sliderMoved( const JoyStickEvent &, int index) {return true;} virtual bool sliderMoved( const JoyStickEvent &, int index) {return true;}
//! Joystick Event, and povID //! Joystick Event, and povID
virtual bool povMoved( const JoyStickEvent &arg, int index) {return true;} virtual bool povMoved( const JoyStickEvent &arg, int index) {return true;}
//! Joystick Event, and Vector3ID //! Joystick Event, and Vector3ID
virtual bool vector3Moved( const JoyStickEvent &arg, int index) {return true;} virtual bool vector3Moved( const JoyStickEvent &arg, int index) {return true;}
}; };
/** /**
Joystick base class. To be implemented by specific system (ie. DirectX joystick) Joystick base class. To be implemented by specific system (ie. DirectX joystick)
This class is useful as you remain OS independent using this common interface. This class is useful as you remain OS independent using this common interface.
*/ */
class _OISExport JoyStick : public Object class _OISExport JoyStick : public Object
{ {
public: public:
virtual ~JoyStick() {} virtual ~JoyStick() {}
/** /**
@remarks @remarks
Returns the number of requested components Returns the number of requested components
@param cType @param cType
The ComponentType you are interested in knowing about The ComponentType you are interested in knowing about
*/ */
int getNumberOfComponents(ComponentType cType) const; int getNumberOfComponents(ComponentType cType) const;
/** /**
@remarks @remarks
Sets a cutoff limit for changes in the Vector3 component for movement to Sets a cutoff limit for changes in the Vector3 component for movement to
be ignored. Helps reduce much event traffic for frequent small/sensitive be ignored. Helps reduce much event traffic for frequent small/sensitive
changes changes
@param degrees @param degrees
The degree under which Vector3 events should be discarded The degree under which Vector3 events should be discarded
*/ */
void setVector3Sensitivity(float degrees = OIS_JOYSTICK_VECTOR3_DEFAULT); void setVector3Sensitivity(float degrees = OIS_JOYSTICK_VECTOR3_DEFAULT);
/** /**
@remarks @remarks
Returns the sensitivity cutoff for Vector3 Component Returns the sensitivity cutoff for Vector3 Component
*/ */
float getVector3Sensitivity() const; float getVector3Sensitivity() const;
/** /**
@remarks @remarks
Register/unregister a JoyStick Listener - Only one allowed for simplicity. If broadcasting Register/unregister a JoyStick Listener - Only one allowed for simplicity. If broadcasting
is neccessary, just broadcast from the callback you registered. is neccessary, just broadcast from the callback you registered.
@param joyListener @param joyListener
Send a pointer to a class derived from JoyStickListener or 0 to clear the callback Send a pointer to a class derived from JoyStickListener or 0 to clear the callback
*/ */
virtual void setEventCallback( JoyStickListener *joyListener ); virtual void setEventCallback( JoyStickListener *joyListener );
/** @remarks Returns currently set callback.. or null */ /** @remarks Returns currently set callback.. or null */
JoyStickListener* getEventCallback() const; JoyStickListener* getEventCallback() const;
/** @remarks Returns the state of the joystick - is valid for both buffered and non buffered mode */ /** @remarks Returns the state of the joystick - is valid for both buffered and non buffered mode */
const JoyStickState& getJoyStickState() const { return mState; } const JoyStickState& getJoyStickState() const { return mState; }
//! The minimal axis value //! The minimal axis value
static const int MIN_AXIS = -32768; static const int MIN_AXIS = -32768;
//! The maximum axis value //! The maximum axis value
static const int MAX_AXIS = 32767; static const int MAX_AXIS = 32767;
protected: protected:
JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator); JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator);
//! Number of sliders //! Number of sliders
int mSliders; int mSliders;
//! Number of POVs //! Number of POVs
int mPOVs; int mPOVs;
//! The JoyStickState structure (contains all component values) //! The JoyStickState structure (contains all component values)
JoyStickState mState; JoyStickState mState;
//! The callback listener //! The callback listener
JoyStickListener *mListener; JoyStickListener *mListener;
//! Adjustment factor for orientation vector accuracy //! Adjustment factor for orientation vector accuracy
float mVector3Sensitivity; float mVector3Sensitivity;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Keyboard_H #ifndef OIS_Keyboard_H
#define OIS_Keyboard_H #define OIS_Keyboard_H
#include "OISObject.h" #include "OISObject.h"
#include "OISEvents.h" #include "OISEvents.h"
namespace OIS namespace OIS
{ {
//! Keyboard scan codes //! Keyboard scan codes
enum KeyCode enum KeyCode
{ {
KC_UNASSIGNED = 0x00, KC_UNASSIGNED = 0x00,
KC_ESCAPE = 0x01, KC_ESCAPE = 0x01,
KC_1 = 0x02, KC_1 = 0x02,
KC_2 = 0x03, KC_2 = 0x03,
KC_3 = 0x04, KC_3 = 0x04,
KC_4 = 0x05, KC_4 = 0x05,
KC_5 = 0x06, KC_5 = 0x06,
KC_6 = 0x07, KC_6 = 0x07,
KC_7 = 0x08, KC_7 = 0x08,
KC_8 = 0x09, KC_8 = 0x09,
KC_9 = 0x0A, KC_9 = 0x0A,
KC_0 = 0x0B, KC_0 = 0x0B,
KC_MINUS = 0x0C, // - on main keyboard KC_MINUS = 0x0C, // - on main keyboard
KC_EQUALS = 0x0D, KC_EQUALS = 0x0D,
KC_BACK = 0x0E, // backspace KC_BACK = 0x0E, // backspace
KC_TAB = 0x0F, KC_TAB = 0x0F,
KC_Q = 0x10, KC_Q = 0x10,
KC_W = 0x11, KC_W = 0x11,
KC_E = 0x12, KC_E = 0x12,
KC_R = 0x13, KC_R = 0x13,
KC_T = 0x14, KC_T = 0x14,
KC_Y = 0x15, KC_Y = 0x15,
KC_U = 0x16, KC_U = 0x16,
KC_I = 0x17, KC_I = 0x17,
KC_O = 0x18, KC_O = 0x18,
KC_P = 0x19, KC_P = 0x19,
KC_LBRACKET = 0x1A, KC_LBRACKET = 0x1A,
KC_RBRACKET = 0x1B, KC_RBRACKET = 0x1B,
KC_RETURN = 0x1C, // Enter on main keyboard KC_RETURN = 0x1C, // Enter on main keyboard
KC_LCONTROL = 0x1D, KC_LCONTROL = 0x1D,
KC_A = 0x1E, KC_A = 0x1E,
KC_S = 0x1F, KC_S = 0x1F,
KC_D = 0x20, KC_D = 0x20,
KC_F = 0x21, KC_F = 0x21,
KC_G = 0x22, KC_G = 0x22,
KC_H = 0x23, KC_H = 0x23,
KC_J = 0x24, KC_J = 0x24,
KC_K = 0x25, KC_K = 0x25,
KC_L = 0x26, KC_L = 0x26,
KC_SEMICOLON = 0x27, KC_SEMICOLON = 0x27,
KC_APOSTROPHE = 0x28, KC_APOSTROPHE = 0x28,
KC_GRAVE = 0x29, // accent KC_GRAVE = 0x29, // accent
KC_LSHIFT = 0x2A, KC_LSHIFT = 0x2A,
KC_BACKSLASH = 0x2B, KC_BACKSLASH = 0x2B,
KC_Z = 0x2C, KC_Z = 0x2C,
KC_X = 0x2D, KC_X = 0x2D,
KC_C = 0x2E, KC_C = 0x2E,
KC_V = 0x2F, KC_V = 0x2F,
KC_B = 0x30, KC_B = 0x30,
KC_N = 0x31, KC_N = 0x31,
KC_M = 0x32, KC_M = 0x32,
KC_COMMA = 0x33, KC_COMMA = 0x33,
KC_PERIOD = 0x34, // . on main keyboard KC_PERIOD = 0x34, // . on main keyboard
KC_SLASH = 0x35, // / on main keyboard KC_SLASH = 0x35, // / on main keyboard
KC_RSHIFT = 0x36, KC_RSHIFT = 0x36,
KC_MULTIPLY = 0x37, // * on numeric keypad KC_MULTIPLY = 0x37, // * on numeric keypad
KC_LMENU = 0x38, // left Alt KC_LMENU = 0x38, // left Alt
KC_SPACE = 0x39, KC_SPACE = 0x39,
KC_CAPITAL = 0x3A, KC_CAPITAL = 0x3A,
KC_F1 = 0x3B, KC_F1 = 0x3B,
KC_F2 = 0x3C, KC_F2 = 0x3C,
KC_F3 = 0x3D, KC_F3 = 0x3D,
KC_F4 = 0x3E, KC_F4 = 0x3E,
KC_F5 = 0x3F, KC_F5 = 0x3F,
KC_F6 = 0x40, KC_F6 = 0x40,
KC_F7 = 0x41, KC_F7 = 0x41,
KC_F8 = 0x42, KC_F8 = 0x42,
KC_F9 = 0x43, KC_F9 = 0x43,
KC_F10 = 0x44, KC_F10 = 0x44,
KC_NUMLOCK = 0x45, KC_NUMLOCK = 0x45,
KC_SCROLL = 0x46, // Scroll Lock KC_SCROLL = 0x46, // Scroll Lock
KC_NUMPAD7 = 0x47, KC_NUMPAD7 = 0x47,
KC_NUMPAD8 = 0x48, KC_NUMPAD8 = 0x48,
KC_NUMPAD9 = 0x49, KC_NUMPAD9 = 0x49,
KC_SUBTRACT = 0x4A, // - on numeric keypad KC_SUBTRACT = 0x4A, // - on numeric keypad
KC_NUMPAD4 = 0x4B, KC_NUMPAD4 = 0x4B,
KC_NUMPAD5 = 0x4C, KC_NUMPAD5 = 0x4C,
KC_NUMPAD6 = 0x4D, KC_NUMPAD6 = 0x4D,
KC_ADD = 0x4E, // + on numeric keypad KC_ADD = 0x4E, // + on numeric keypad
KC_NUMPAD1 = 0x4F, KC_NUMPAD1 = 0x4F,
KC_NUMPAD2 = 0x50, KC_NUMPAD2 = 0x50,
KC_NUMPAD3 = 0x51, KC_NUMPAD3 = 0x51,
KC_NUMPAD0 = 0x52, KC_NUMPAD0 = 0x52,
KC_DECIMAL = 0x53, // . on numeric keypad KC_DECIMAL = 0x53, // . on numeric keypad
KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards
KC_F11 = 0x57, KC_F11 = 0x57,
KC_F12 = 0x58, KC_F12 = 0x58,
KC_F13 = 0x64, // (NEC PC98) KC_F13 = 0x64, // (NEC PC98)
KC_F14 = 0x65, // (NEC PC98) KC_F14 = 0x65, // (NEC PC98)
KC_F15 = 0x66, // (NEC PC98) KC_F15 = 0x66, // (NEC PC98)
KC_KANA = 0x70, // (Japanese keyboard) KC_KANA = 0x70, // (Japanese keyboard)
KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards
KC_CONVERT = 0x79, // (Japanese keyboard) KC_CONVERT = 0x79, // (Japanese keyboard)
KC_NOCONVERT = 0x7B, // (Japanese keyboard) KC_NOCONVERT = 0x7B, // (Japanese keyboard)
KC_YEN = 0x7D, // (Japanese keyboard) KC_YEN = 0x7D, // (Japanese keyboard)
KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards
KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98) KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98)
KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
KC_AT = 0x91, // (NEC PC98) KC_AT = 0x91, // (NEC PC98)
KC_COLON = 0x92, // (NEC PC98) KC_COLON = 0x92, // (NEC PC98)
KC_UNDERLINE = 0x93, // (NEC PC98) KC_UNDERLINE = 0x93, // (NEC PC98)
KC_KANJI = 0x94, // (Japanese keyboard) KC_KANJI = 0x94, // (Japanese keyboard)
KC_STOP = 0x95, // (NEC PC98) KC_STOP = 0x95, // (NEC PC98)
KC_AX = 0x96, // (Japan AX) KC_AX = 0x96, // (Japan AX)
KC_UNLABELED = 0x97, // (J3100) KC_UNLABELED = 0x97, // (J3100)
KC_NEXTTRACK = 0x99, // Next Track KC_NEXTTRACK = 0x99, // Next Track
KC_NUMPADENTER = 0x9C, // Enter on numeric keypad KC_NUMPADENTER = 0x9C, // Enter on numeric keypad
KC_RCONTROL = 0x9D, KC_RCONTROL = 0x9D,
KC_MUTE = 0xA0, // Mute KC_MUTE = 0xA0, // Mute
KC_CALCULATOR = 0xA1, // Calculator KC_CALCULATOR = 0xA1, // Calculator
KC_PLAYPAUSE = 0xA2, // Play / Pause KC_PLAYPAUSE = 0xA2, // Play / Pause
KC_MEDIASTOP = 0xA4, // Media Stop KC_MEDIASTOP = 0xA4, // Media Stop
KC_VOLUMEDOWN = 0xAE, // Volume - KC_VOLUMEDOWN = 0xAE, // Volume -
KC_VOLUMEUP = 0xB0, // Volume + KC_VOLUMEUP = 0xB0, // Volume +
KC_WEBHOME = 0xB2, // Web home KC_WEBHOME = 0xB2, // Web home
KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98) KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98)
KC_DIVIDE = 0xB5, // / on numeric keypad KC_DIVIDE = 0xB5, // / on numeric keypad
KC_SYSRQ = 0xB7, KC_SYSRQ = 0xB7,
KC_RMENU = 0xB8, // right Alt KC_RMENU = 0xB8, // right Alt
KC_PAUSE = 0xC5, // Pause KC_PAUSE = 0xC5, // Pause
KC_HOME = 0xC7, // Home on arrow keypad KC_HOME = 0xC7, // Home on arrow keypad
KC_UP = 0xC8, // UpArrow on arrow keypad KC_UP = 0xC8, // UpArrow on arrow keypad
KC_PGUP = 0xC9, // PgUp on arrow keypad KC_PGUP = 0xC9, // PgUp on arrow keypad
KC_LEFT = 0xCB, // LeftArrow on arrow keypad KC_LEFT = 0xCB, // LeftArrow on arrow keypad
KC_RIGHT = 0xCD, // RightArrow on arrow keypad KC_RIGHT = 0xCD, // RightArrow on arrow keypad
KC_END = 0xCF, // End on arrow keypad KC_END = 0xCF, // End on arrow keypad
KC_DOWN = 0xD0, // DownArrow on arrow keypad KC_DOWN = 0xD0, // DownArrow on arrow keypad
KC_PGDOWN = 0xD1, // PgDn on arrow keypad KC_PGDOWN = 0xD1, // PgDn on arrow keypad
KC_INSERT = 0xD2, // Insert on arrow keypad KC_INSERT = 0xD2, // Insert on arrow keypad
KC_DELETE = 0xD3, // Delete on arrow keypad KC_DELETE = 0xD3, // Delete on arrow keypad
KC_LWIN = 0xDB, // Left Windows key KC_LWIN = 0xDB, // Left Windows key
KC_RWIN = 0xDC, // Right Windows key KC_RWIN = 0xDC, // Right Windows key
KC_APPS = 0xDD, // AppMenu key KC_APPS = 0xDD, // AppMenu key
KC_POWER = 0xDE, // System Power KC_POWER = 0xDE, // System Power
KC_SLEEP = 0xDF, // System Sleep KC_SLEEP = 0xDF, // System Sleep
KC_WAKE = 0xE3, // System Wake KC_WAKE = 0xE3, // System Wake
KC_WEBSEARCH = 0xE5, // Web Search KC_WEBSEARCH = 0xE5, // Web Search
KC_WEBFAVORITES= 0xE6, // Web Favorites KC_WEBFAVORITES= 0xE6, // Web Favorites
KC_WEBREFRESH = 0xE7, // Web Refresh KC_WEBREFRESH = 0xE7, // Web Refresh
KC_WEBSTOP = 0xE8, // Web Stop KC_WEBSTOP = 0xE8, // Web Stop
KC_WEBFORWARD = 0xE9, // Web Forward KC_WEBFORWARD = 0xE9, // Web Forward
KC_WEBBACK = 0xEA, // Web Back KC_WEBBACK = 0xEA, // Web Back
KC_MYCOMPUTER = 0xEB, // My Computer KC_MYCOMPUTER = 0xEB, // My Computer
KC_MAIL = 0xEC, // Mail KC_MAIL = 0xEC, // Mail
KC_MEDIASELECT = 0xED // Media Select KC_MEDIASELECT = 0xED // Media Select
}; };
/** /**
Specialised for key events Specialised for key events
*/ */
class _OISExport KeyEvent : public EventArg class _OISExport KeyEvent : public EventArg
{ {
public: public:
KeyEvent(Object* obj, KeyCode kc, unsigned int txt) : EventArg(obj), key(kc), text(txt) {} KeyEvent(Object* obj, KeyCode kc, unsigned int txt) : EventArg(obj), key(kc), text(txt) {}
virtual ~KeyEvent() {} virtual ~KeyEvent() {}
//! KeyCode of event //! KeyCode of event
KeyCode key; KeyCode key;
//! Text character, depends on current TextTranslationMode //! Text character, depends on current TextTranslationMode
unsigned int text; unsigned int text;
}; };
/** /**
To recieve buffered keyboard input, derive a class from this, and implement the To recieve buffered keyboard input, derive a class from this, and implement the
methods here. Then set the call back to your Keyboard instance with Keyboard::setEventCallback methods here. Then set the call back to your Keyboard instance with Keyboard::setEventCallback
*/ */
class _OISExport KeyListener class _OISExport KeyListener
{ {
public: public:
virtual ~KeyListener() {} virtual ~KeyListener() {}
virtual bool keyPressed(const KeyEvent &arg) = 0; virtual bool keyPressed(const KeyEvent &arg) = 0;
virtual bool keyReleased(const KeyEvent &arg) = 0; virtual bool keyReleased(const KeyEvent &arg) = 0;
}; };
/** /**
Keyboard base class. To be implemented by specific system (ie. DirectX Keyboard) Keyboard base class. To be implemented by specific system (ie. DirectX Keyboard)
This class is useful as you remain OS independent using this common interface. This class is useful as you remain OS independent using this common interface.
*/ */
class _OISExport Keyboard : public Object class _OISExport Keyboard : public Object
{ {
public: public:
virtual ~Keyboard() {}; virtual ~Keyboard() {};
/** /**
@remarks @remarks
Returns true if key is donwn Returns true if key is donwn
@param key @param key
A KeyCode to check A KeyCode to check
*/ */
virtual bool isKeyDown(KeyCode key) const = 0; virtual bool isKeyDown(KeyCode key) const = 0;
/** /**
@remarks @remarks
Register/unregister a Keyboard Listener - Only one allowed for simplicity. If broadcasting Register/unregister a Keyboard Listener - Only one allowed for simplicity. If broadcasting
is neccessary, just broadcast from the callback you registered. is neccessary, just broadcast from the callback you registered.
@param keyListener @param keyListener
Send a pointer to a class derived from KeyListener or 0 to clear the callback Send a pointer to a class derived from KeyListener or 0 to clear the callback
*/ */
virtual void setEventCallback(KeyListener *keyListener) { mListener = keyListener;} virtual void setEventCallback(KeyListener *keyListener) { mListener = keyListener;}
/** /**
@remarks @remarks
Returns currently set callback.. or 0 Returns currently set callback.. or 0
*/ */
KeyListener* getEventCallback() const {return mListener;} KeyListener* getEventCallback() const {return mListener;}
//! TextTranslation Mode //! TextTranslation Mode
enum TextTranslationMode enum TextTranslationMode
{ {
Off, Off,
Unicode, Unicode,
Ascii Ascii
}; };
/** /**
@remarks @remarks
Enable extra processing to translate KC_*** to an Enable extra processing to translate KC_*** to an
actual text character based off of locale. Different actual text character based off of locale. Different
managers may implement none or all. Check the managers may implement none or all. Check the
translation mode after setting to be sure translation mode after setting to be sure
@param mode @param mode
Off, Unicode, Ascii Off, Unicode, Ascii
*/ */
virtual void setTextTranslation(TextTranslationMode mode); virtual void setTextTranslation(TextTranslationMode mode);
/** /**
@remarks @remarks
Returns current translation mode Returns current translation mode
*/ */
TextTranslationMode getTextTranslation() const {return mTextMode;} TextTranslationMode getTextTranslation() const {return mTextMode;}
/** /**
@remarks @remarks
Translates KeyCode to string representation. Translates KeyCode to string representation.
For example, KC_ENTER will be "Enter" - Locale For example, KC_ENTER will be "Enter" - Locale
specific of course. specific of course.
@param kc @param kc
KeyCode to convert KeyCode to convert
@returns @returns
The string as determined from the current locale The string as determined from the current locale
*/ */
virtual const std::string& getAsString(KeyCode kc) = 0; virtual const std::string& getAsString(KeyCode kc) = 0;
//! Enum of bit position of modifer //! Enum of bit position of modifer
enum Modifier enum Modifier
{ {
Shift = 0x0000001, Shift = 0x0000001,
Ctrl = 0x0000010, Ctrl = 0x0000010,
Alt = 0x0000100 Alt = 0x0000100
}; };
/** /**
@remarks @remarks
Check modifier status Check modifier status
*/ */
bool isModifierDown(Modifier mod) const; bool isModifierDown(Modifier mod) const;
/** /**
@remarks @remarks
Copies the state of the keys into the sent buffer Copies the state of the keys into the sent buffer
(in the form of 1 is down and 0 is up) (in the form of 1 is down and 0 is up)
*/ */
virtual void copyKeyStates(char keys[256]) const = 0; virtual void copyKeyStates(char keys[256]) const = 0;
protected: protected:
Keyboard(const std::string &vendor, bool buffered, int devID, InputManager* creator) Keyboard(const std::string &vendor, bool buffered, int devID, InputManager* creator)
: Object(vendor, OISKeyboard, buffered, devID, creator), : Object(vendor, OISKeyboard, buffered, devID, creator),
mModifiers(0), mListener(0), mTextMode(Unicode) {} mModifiers(0), mListener(0), mTextMode(Unicode) {}
//! Bit field that holds status of Alt, Ctrl, Shift //! Bit field that holds status of Alt, Ctrl, Shift
unsigned int mModifiers; unsigned int mModifiers;
//! Used for buffered/actionmapping callback //! Used for buffered/actionmapping callback
KeyListener *mListener; KeyListener *mListener;
//! The current translation mode //! The current translation mode
TextTranslationMode mTextMode; TextTranslationMode mTextMode;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Mouse_H #ifndef OIS_Mouse_H
#define OIS_Mouse_H #define OIS_Mouse_H
#include "OISObject.h" #include "OISObject.h"
#include "OISEvents.h" #include "OISEvents.h"
namespace OIS namespace OIS
{ {
//! Button ID for mouse devices //! Button ID for mouse devices
enum MouseButtonID enum MouseButtonID
{ {
MB_Left = 0, MB_Right, MB_Middle, MB_Left = 0, MB_Right, MB_Middle,
MB_Button3, MB_Button4, MB_Button5, MB_Button6, MB_Button7 MB_Button3, MB_Button4, MB_Button5, MB_Button6, MB_Button7
}; };
/** /**
Represents the state of the mouse Represents the state of the mouse
All members are valid for both buffered and non buffered mode All members are valid for both buffered and non buffered mode
*/ */
class _OISExport MouseState class _OISExport MouseState
{ {
public: public:
MouseState() : width(50), height(50), buttons(0) {}; MouseState() : width(50), height(50), buttons(0) {};
/** Represents the height/width of your display area.. used if mouse clipping /** Represents the height/width of your display area.. used if mouse clipping
or mouse grabbed in case of X11 - defaults to 50.. Make sure to set this or mouse grabbed in case of X11 - defaults to 50.. Make sure to set this
and change when your size changes.. */ and change when your size changes.. */
mutable int width, height; mutable int width, height;
//! X Axis component //! X Axis component
Axis X; Axis X;
//! Y Axis Component //! Y Axis Component
Axis Y; Axis Y;
//! Z Axis Component //! Z Axis Component
Axis Z; Axis Z;
//! represents all buttons - bit position indicates button down //! represents all buttons - bit position indicates button down
int buttons; int buttons;
//! Button down test //! Button down test
inline bool buttonDown( MouseButtonID button ) const inline bool buttonDown( MouseButtonID button ) const
{ {
return ((buttons & ( 1L << button )) == 0) ? false : true; return ((buttons & ( 1L << button )) == 0) ? false : true;
} }
//! Clear all the values //! Clear all the values
void clear() void clear()
{ {
X.clear(); X.clear();
Y.clear(); Y.clear();
Z.clear(); Z.clear();
buttons = 0; buttons = 0;
} }
}; };
/** Specialised for mouse events */ /** Specialised for mouse events */
class _OISExport MouseEvent : public EventArg class _OISExport MouseEvent : public EventArg
{ {
public: public:
MouseEvent( Object *obj, const MouseState &ms ) : EventArg(obj), state(ms) {} MouseEvent( Object *obj, const MouseState &ms ) : EventArg(obj), state(ms) {}
virtual ~MouseEvent() {} virtual ~MouseEvent() {}
//! The state of the mouse - including buttons and axes //! The state of the mouse - including buttons and axes
const MouseState &state; const MouseState &state;
private: private:
// Prevent copying. // Prevent copying.
MouseEvent(const MouseEvent&); MouseEvent(const MouseEvent&);
MouseEvent& operator=(MouseEvent); MouseEvent& operator=(MouseEvent);
}; };
/** /**
To recieve buffered mouse input, derive a class from this, and implement the To recieve buffered mouse input, derive a class from this, and implement the
methods here. Then set the call back to your Mouse instance with Mouse::setEventCallback methods here. Then set the call back to your Mouse instance with Mouse::setEventCallback
*/ */
class _OISExport MouseListener class _OISExport MouseListener
{ {
public: public:
virtual ~MouseListener() {} virtual ~MouseListener() {}
virtual bool mouseMoved( const MouseEvent &arg ) = 0; virtual bool mouseMoved( const MouseEvent &arg ) = 0;
virtual bool mousePressed( const MouseEvent &arg, MouseButtonID id ) = 0; virtual bool mousePressed( const MouseEvent &arg, MouseButtonID id ) = 0;
virtual bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) = 0; virtual bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) = 0;
}; };
/** /**
Mouse base class. To be implemented by specific system (ie. DirectX Mouse) Mouse base class. To be implemented by specific system (ie. DirectX Mouse)
This class is useful as you remain OS independent using this common interface. This class is useful as you remain OS independent using this common interface.
*/ */
class _OISExport Mouse : public Object class _OISExport Mouse : public Object
{ {
public: public:
virtual ~Mouse() {} virtual ~Mouse() {}
/** /**
@remarks @remarks
Register/unregister a Mouse Listener - Only one allowed for simplicity. If broadcasting Register/unregister a Mouse Listener - Only one allowed for simplicity. If broadcasting
is neccessary, just broadcast from the callback you registered. is neccessary, just broadcast from the callback you registered.
@param mouseListener @param mouseListener
Send a pointer to a class derived from MouseListener or 0 to clear the callback Send a pointer to a class derived from MouseListener or 0 to clear the callback
*/ */
virtual void setEventCallback( MouseListener *mouseListener ) {mListener = mouseListener;} virtual void setEventCallback( MouseListener *mouseListener ) {mListener = mouseListener;}
/** @remarks Returns currently set callback.. or 0 */ /** @remarks Returns currently set callback.. or 0 */
MouseListener* getEventCallback() const {return mListener;} MouseListener* getEventCallback() const {return mListener;}
/** @remarks Returns the state of the mouse - is valid for both buffered and non buffered mode */ /** @remarks Returns the state of the mouse - is valid for both buffered and non buffered mode */
const MouseState& getMouseState() const { return mState; } const MouseState& getMouseState() const { return mState; }
protected: protected:
Mouse(const std::string &vendor, bool buffered, int devID, InputManager* creator) Mouse(const std::string &vendor, bool buffered, int devID, InputManager* creator)
: Object(vendor, OISMouse, buffered, devID, creator), mListener(0) {} : Object(vendor, OISMouse, buffered, devID, creator), mListener(0) {}
//! The state of the mouse //! The state of the mouse
MouseState mState; MouseState mState;
//! Used for buffered/actionmapping callback //! Used for buffered/actionmapping callback
MouseListener *mListener; MouseListener *mListener;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_MultiTouch_H #ifndef OIS_MultiTouch_H
#define OIS_MultiTouch_H #define OIS_MultiTouch_H
#include "OISObject.h" #include "OISObject.h"
#include "OISEvents.h" #include "OISEvents.h"
#include <set> #include <set>
#include <vector> #include <vector>
#define OIS_MAX_NUM_TOUCHES 4 // 4 finger touches are probably the highest we'll ever get #define OIS_MAX_NUM_TOUCHES 4 // 4 finger touches are probably the highest we'll ever get
namespace OIS namespace OIS
{ {
/** /**
Represents the state of the multi-touch device Represents the state of the multi-touch device
All members are valid for both buffered and non buffered mode All members are valid for both buffered and non buffered mode
*/ */
//! Touch Event type //! Touch Event type
enum MultiTypeEventTypeID enum MultiTypeEventTypeID
{ {
MT_None = 0, MT_Pressed, MT_Released, MT_Moved, MT_Cancelled MT_None = 0, MT_Pressed, MT_Released, MT_Moved, MT_Cancelled
}; };
class _OISExport MultiTouchState class _OISExport MultiTouchState
{ {
public: public:
MultiTouchState() : width(50), height(50), touchType(MT_None) {}; MultiTouchState() : width(50), height(50), touchType(MT_None) {};
/** Represents the height/width of your display area.. used if touch clipping /** Represents the height/width of your display area.. used if touch clipping
or touch grabbed in case of X11 - defaults to 50.. Make sure to set this or touch grabbed in case of X11 - defaults to 50.. Make sure to set this
and change when your size changes.. */ and change when your size changes.. */
mutable int width, height; mutable int width, height;
//! X Axis component //! X Axis component
Axis X; Axis X;
//! Y Axis Component //! Y Axis Component
Axis Y; Axis Y;
//! Z Axis Component //! Z Axis Component
Axis Z; Axis Z;
int touchType; int touchType;
inline bool touchIsType( MultiTypeEventTypeID touch ) const inline bool touchIsType( MultiTypeEventTypeID touch ) const
{ {
return ((touchType & ( 1L << touch )) == 0) ? false : true; return ((touchType & ( 1L << touch )) == 0) ? false : true;
} }
//! Clear all the values //! Clear all the values
void clear() void clear()
{ {
X.clear(); X.clear();
Y.clear(); Y.clear();
Z.clear(); Z.clear();
touchType = MT_None; touchType = MT_None;
} }
}; };
/** Specialised for multi-touch events */ /** Specialised for multi-touch events */
class _OISExport MultiTouchEvent : public EventArg class _OISExport MultiTouchEvent : public EventArg
{ {
public: public:
MultiTouchEvent( Object *obj, const MultiTouchState &ms ) : EventArg(obj), state(ms) {} MultiTouchEvent( Object *obj, const MultiTouchState &ms ) : EventArg(obj), state(ms) {}
virtual ~MultiTouchEvent() {} virtual ~MultiTouchEvent() {}
//! The state of the touch - including axes //! The state of the touch - including axes
const MultiTouchState &state; const MultiTouchState &state;
}; };
/** /**
To receive buffered touch input, derive a class from this, and implement the To receive buffered touch input, derive a class from this, and implement the
methods here. Then set the call back to your MultiTouch instance with MultiTouch::setEventCallback methods here. Then set the call back to your MultiTouch instance with MultiTouch::setEventCallback
*/ */
class _OISExport MultiTouchListener class _OISExport MultiTouchListener
{ {
public: public:
virtual ~MultiTouchListener() {} virtual ~MultiTouchListener() {}
virtual bool touchMoved( const MultiTouchEvent &arg ) = 0; virtual bool touchMoved( const MultiTouchEvent &arg ) = 0;
virtual bool touchPressed( const MultiTouchEvent &arg ) = 0; virtual bool touchPressed( const MultiTouchEvent &arg ) = 0;
virtual bool touchReleased( const MultiTouchEvent &arg ) = 0; virtual bool touchReleased( const MultiTouchEvent &arg ) = 0;
virtual bool touchCancelled( const MultiTouchEvent &arg ) = 0; virtual bool touchCancelled( const MultiTouchEvent &arg ) = 0;
}; };
/** /**
MultiTouch base class. To be implemented by specific system (ie. iPhone UITouch) MultiTouch base class. To be implemented by specific system (ie. iPhone UITouch)
This class is useful as you remain OS independent using this common interface. This class is useful as you remain OS independent using this common interface.
*/ */
class _OISExport MultiTouch : public Object class _OISExport MultiTouch : public Object
{ {
public: public:
virtual ~MultiTouch() {} virtual ~MultiTouch() {}
/** /**
@remarks @remarks
Register/unregister a MultiTouch Listener - Only one allowed for simplicity. If broadcasting Register/unregister a MultiTouch Listener - Only one allowed for simplicity. If broadcasting
is necessary, just broadcast from the callback you registered. is necessary, just broadcast from the callback you registered.
@param touchListener @param touchListener
Send a pointer to a class derived from MultiTouchListener or 0 to clear the callback Send a pointer to a class derived from MultiTouchListener or 0 to clear the callback
*/ */
virtual void setEventCallback( MultiTouchListener *touchListener ) {mListener = touchListener;} virtual void setEventCallback( MultiTouchListener *touchListener ) {mListener = touchListener;}
/** @remarks Returns currently set callback.. or 0 */ /** @remarks Returns currently set callback.. or 0 */
MultiTouchListener* getEventCallback() {return mListener;} MultiTouchListener* getEventCallback() {return mListener;}
/** @remarks Clear out the set of input states. Should be called after input has been processed by the application */ /** @remarks Clear out the set of input states. Should be called after input has been processed by the application */
void clearStates(void) { mStates.clear(); } void clearStates(void) { mStates.clear(); }
/** @remarks Returns the state of the touch - is valid for both buffered and non buffered mode */ /** @remarks Returns the state of the touch - is valid for both buffered and non buffered mode */
std::vector<MultiTouchState> getMultiTouchStates() const { return mStates; } std::vector<MultiTouchState> getMultiTouchStates() const { return mStates; }
/** @remarks Returns the first n touch states. Useful if you know your app only needs to /** @remarks Returns the first n touch states. Useful if you know your app only needs to
process n touches. The return value is a vector to allow random access */ process n touches. The return value is a vector to allow random access */
const std::vector<MultiTouchState> getFirstNTouchStates(int n) { const std::vector<MultiTouchState> getFirstNTouchStates(int n) {
std::vector<MultiTouchState> states; std::vector<MultiTouchState> states;
for( unsigned int i = 0; i < mStates.size(); i++ ) { for( unsigned int i = 0; i < mStates.size(); i++ ) {
if(!(mStates[i].touchIsType(MT_None))) { if(!(mStates[i].touchIsType(MT_None))) {
states.push_back(mStates[i]); states.push_back(mStates[i]);
} }
} }
return states; return states;
} }
/** @remarks Returns the first n touch states. Useful if you know your app only needs to /** @remarks Returns the first n touch states. Useful if you know your app only needs to
process n touches. The return value is a vector to allow random access */ process n touches. The return value is a vector to allow random access */
const std::vector<MultiTouchState> getMultiTouchStatesOfType(MultiTypeEventTypeID type) { const std::vector<MultiTouchState> getMultiTouchStatesOfType(MultiTypeEventTypeID type) {
std::vector<MultiTouchState> states; std::vector<MultiTouchState> states;
for( unsigned int i = 0; i < mStates.size(); i++ ) { for( unsigned int i = 0; i < mStates.size(); i++ ) {
if(mStates[i].touchIsType(type)) { if(mStates[i].touchIsType(type)) {
states.push_back(mStates[i]); states.push_back(mStates[i]);
} }
} }
return states; return states;
} }
protected: protected:
MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager* creator) MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager* creator)
: Object(vendor, OISMultiTouch, buffered, devID, creator), mListener(0) {} : Object(vendor, OISMultiTouch, buffered, devID, creator), mListener(0) {}
//! The state of the touch device, implemented in a vector to store the state from each finger touch //! The state of the touch device, implemented in a vector to store the state from each finger touch
std::vector<MultiTouchState> mStates; std::vector<MultiTouchState> mStates;
//! Used for buffered/actionmapping callback //! Used for buffered/actionmapping callback
MultiTouchListener *mListener; MultiTouchListener *mListener;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Object_H #ifndef OIS_Object_H
#define OIS_Object_H #define OIS_Object_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
#include "OISInterface.h" #include "OISInterface.h"
namespace OIS namespace OIS
{ {
/** The base class of all input types. */ /** The base class of all input types. */
class _OISExport Object class _OISExport Object
{ {
public: public:
virtual ~Object() {} virtual ~Object() {}
/** @remarks Get the type of device */ /** @remarks Get the type of device */
Type type() const { return mType; } Type type() const { return mType; }
/** @remarks Get the vender string name */ /** @remarks Get the vender string name */
const std::string& vendor() const { return mVendor; } const std::string& vendor() const { return mVendor; }
/** @remarks Get buffered mode - true is buffered, false otherwise */ /** @remarks Get buffered mode - true is buffered, false otherwise */
virtual bool buffered() const { return mBuffered; } virtual bool buffered() const { return mBuffered; }
/** @remarks Returns this input object's creator */ /** @remarks Returns this input object's creator */
InputManager* getCreator() const { return mCreator; } InputManager* getCreator() const { return mCreator; }
/** @remarks Sets buffered mode */ /** @remarks Sets buffered mode */
virtual void setBuffered(bool buffered) = 0; virtual void setBuffered(bool buffered) = 0;
/** @remarks Used for updating call once per frame before checking state or to update events */ /** @remarks Used for updating call once per frame before checking state or to update events */
virtual void capture() = 0; virtual void capture() = 0;
/** @remarks This may/may not) differentiate the different controllers based on (for instance) a port number (useful for console InputManagers) */ /** @remarks This may/may not) differentiate the different controllers based on (for instance) a port number (useful for console InputManagers) */
virtual int getID() const {return mDevID;} virtual int getID() const {return mDevID;}
/** /**
@remarks @remarks
If available, get an interface to write to some devices. If available, get an interface to write to some devices.
Examples include, turning on and off LEDs, ForceFeedback, etc Examples include, turning on and off LEDs, ForceFeedback, etc
@param type @param type
The type of interface you are looking for The type of interface you are looking for
*/ */
virtual Interface* queryInterface(Interface::IType type) = 0; virtual Interface* queryInterface(Interface::IType type) = 0;
/** @remarks Internal... Do not call this directly. */ /** @remarks Internal... Do not call this directly. */
virtual void _initialize() = 0; virtual void _initialize() = 0;
protected: protected:
Object(const std::string &vendor, Type iType, bool buffered, Object(const std::string &vendor, Type iType, bool buffered,
int devID, InputManager* creator) : int devID, InputManager* creator) :
mVendor(vendor), mVendor(vendor),
mType(iType), mType(iType),
mBuffered(buffered), mBuffered(buffered),
mDevID(devID), mDevID(devID),
mCreator(creator) {} mCreator(creator) {}
//! Vendor name if applicable/known //! Vendor name if applicable/known
std::string mVendor; std::string mVendor;
//! Type of controller object //! Type of controller object
Type mType; Type mType;
//! Buffered flag //! Buffered flag
bool mBuffered; bool mBuffered;
//! Not fully implemented yet //! Not fully implemented yet
int mDevID; int mDevID;
//! The creator who created this object //! The creator who created this object
InputManager* mCreator; InputManager* mCreator;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Prereqs_H #ifndef OIS_Prereqs_H
#define OIS_Prereqs_H #define OIS_Prereqs_H
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// This Header File contains: forward declared classes // This Header File contains: forward declared classes
// * Forward Declarations of all public API classes // * Forward Declarations of all public API classes
// * Several typedef's used around the library // * Several typedef's used around the library
// * Base class component types // * Base class component types
// * Preprocessor definitons // * Preprocessor definitons
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
//-------------- Common STL Containers ---------------------------------------// //-------------- Common STL Containers ---------------------------------------//
#include <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include "OISConfig.h" #include "OISConfig.h"
// Default is blank for most OS's // Default is blank for most OS's
#define _OISExport #define _OISExport
//-------------- Determine Compiler --------------------------------- //-------------- Determine Compiler ---------------------------------
#if defined( _MSC_VER ) #if defined( _MSC_VER )
# define OIS_MSVC_COMPILER # define OIS_MSVC_COMPILER
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if defined( __WIN32__ ) || defined( _WIN32 ) # if defined( __WIN32__ ) || defined( _WIN32 )
# define OIS_MINGW_COMPILER # define OIS_MINGW_COMPILER
# else # else
# define OIS_GCC_COMPILER # define OIS_GCC_COMPILER
# endif # endif
#elif defined( __BORLANDC__ ) #elif defined( __BORLANDC__ )
# define OIS_BORLAND_COMPILER # define OIS_BORLAND_COMPILER
#else #else
# error No Recognized Compiler! # error No Recognized Compiler!
#endif #endif
// --------------- Determine Operating System Platform --------------- // --------------- Determine Operating System Platform ---------------
#if defined( __WIN32__ ) || defined( _WIN32 ) // Windows 2000, XP, ETC #if defined( __WIN32__ ) || defined( _WIN32 ) // Windows 2000, XP, ETC
# if defined ( _XBOX ) # if defined ( _XBOX )
# define OIS_XBOX_PLATFORM # define OIS_XBOX_PLATFORM
# else # else
# define OIS_WIN32_PLATFORM # define OIS_WIN32_PLATFORM
# if defined( OIS_DYNAMIC_LIB ) # if defined( OIS_DYNAMIC_LIB )
# undef _OISExport # undef _OISExport
//Ignorable Dll interface warning... //Ignorable Dll interface warning...
# if !defined(OIS_MINGW_COMPILER) # if !defined(OIS_MINGW_COMPILER)
# pragma warning (disable : 4251) # pragma warning (disable : 4251)
# endif # endif
# if defined( OIS_NONCLIENT_BUILD ) # if defined( OIS_NONCLIENT_BUILD )
# define _OISExport __declspec( dllexport ) # define _OISExport __declspec( dllexport )
# else # else
# if defined(OIS_MINGW_COMPILER) # if defined(OIS_MINGW_COMPILER)
# define _OISExport # define _OISExport
# else # else
# define _OISExport __declspec( dllimport ) # define _OISExport __declspec( dllimport )
# endif # endif
# endif # endif
# endif # endif
# endif # endif
#elif defined( __APPLE_CC__ ) // Apple OS X #elif defined( __APPLE_CC__ ) // Apple OS X
// Device Simulator // Device Simulator
# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20201 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000 # if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20201 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000
//# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 //# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
# define OIS_IPHONE_PLATFORM # define OIS_IPHONE_PLATFORM
# else # else
# define OIS_APPLE_PLATFORM # define OIS_APPLE_PLATFORM
# endif # endif
# undef _OISExport # undef _OISExport
# define _OISExport __attribute__((visibility("default"))) # define _OISExport __attribute__((visibility("default")))
#else //Probably Linux #else //Probably Linux
# define OIS_LINUX_PLATFORM # define OIS_LINUX_PLATFORM
# include <unistd.h> # include <unistd.h>
#endif #endif
//Is Processor 32 or 64 bits... //Is Processor 32 or 64 bits...
#if defined(__x86_64__) #if defined(__x86_64__)
# define OIS_ARCH_64 # define OIS_ARCH_64
#else #else
# define OIS_ARCH_32 # define OIS_ARCH_32
#endif #endif
//-------------- Common Classes, Enums, and Typdef's -------------------------// //-------------- Common Classes, Enums, and Typdef's -------------------------//
#define OIS_VERSION_MAJOR 1 #define OIS_VERSION_MAJOR 1
#define OIS_VERSION_MINOR 4 #define OIS_VERSION_MINOR 4
#define OIS_VERSION_PATCH 0 #define OIS_VERSION_PATCH 0
#define OIS_VERSION_NAME "1.4.0" #define OIS_VERSION_NAME "1.4.0"
#define OIS_VERSION ((OIS_VERSION_MAJOR << 16) | (OIS_VERSION_MINOR << 8) | OIS_VERSION_PATCH) #define OIS_VERSION ((OIS_VERSION_MAJOR << 16) | (OIS_VERSION_MINOR << 8) | OIS_VERSION_PATCH)
namespace OIS namespace OIS
{ {
//Forward Declarations //Forward Declarations
class InputManager; class InputManager;
class FactoryCreator; class FactoryCreator;
class Object; class Object;
class Keyboard; class Keyboard;
class Mouse; class Mouse;
class JoyStick; class JoyStick;
class MultiTouch; class MultiTouch;
class KeyListener; class KeyListener;
class MouseListener; class MouseListener;
class MultiTouchListener; class MultiTouchListener;
class JoyStickListener; class JoyStickListener;
class Interface; class Interface;
class ForceFeedback; class ForceFeedback;
class Effect; class Effect;
class Exception; class Exception;
//! Way to send OS nuetral parameters.. ie OS Window handles, modes, flags //! Way to send OS nuetral parameters.. ie OS Window handles, modes, flags
typedef std::multimap<std::string, std::string> ParamList; typedef std::multimap<std::string, std::string> ParamList;
//! List of FactoryCreator's //! List of FactoryCreator's
typedef std::vector<FactoryCreator*> FactoryList; typedef std::vector<FactoryCreator*> FactoryList;
//! Map of FactoryCreator created Objects //! Map of FactoryCreator created Objects
typedef std::map<Object*, FactoryCreator*> FactoryCreatedObject; typedef std::map<Object*, FactoryCreator*> FactoryCreatedObject;
//! Each Input class has a General Type variable, a form of RTTI //! Each Input class has a General Type variable, a form of RTTI
enum Type enum Type
{ {
OISUnknown = 0, OISUnknown = 0,
OISKeyboard = 1, OISKeyboard = 1,
OISMouse = 2, OISMouse = 2,
OISJoyStick = 3, OISJoyStick = 3,
OISTablet = 4, OISTablet = 4,
OISMultiTouch = 5 OISMultiTouch = 5
}; };
//! Map of device objects connected and their respective vendors //! Map of device objects connected and their respective vendors
typedef std::multimap<Type, std::string> DeviceList; typedef std::multimap<Type, std::string> DeviceList;
//-------- Shared common components ------------------------// //-------- Shared common components ------------------------//
//! Base type for all device components (button, axis, etc) //! Base type for all device components (button, axis, etc)
enum ComponentType enum ComponentType
{ {
OIS_Unknown = 0, OIS_Unknown = 0,
OIS_Button = 1, //ie. Key, mouse button, joy button, etc OIS_Button = 1, //ie. Key, mouse button, joy button, etc
OIS_Axis = 2, //ie. A joystick or mouse axis OIS_Axis = 2, //ie. A joystick or mouse axis
OIS_Slider = 3, // OIS_Slider = 3, //
OIS_POV = 4, //ie. Arrow direction keys OIS_POV = 4, //ie. Arrow direction keys
OIS_Vector3 = 5 //ie. WiiMote orientation OIS_Vector3 = 5 //ie. WiiMote orientation
}; };
//! Base of all device components (button, axis, etc) //! Base of all device components (button, axis, etc)
class _OISExport Component class _OISExport Component
{ {
public: public:
Component() : cType(OIS_Unknown) {}; Component() : cType(OIS_Unknown) {};
explicit Component(ComponentType type) : cType(type) {}; explicit Component(ComponentType type) : cType(type) {};
//! Indicates what type of coponent this is //! Indicates what type of coponent this is
ComponentType cType; ComponentType cType;
}; };
//! Button can be a keyboard key, mouse button, etc //! Button can be a keyboard key, mouse button, etc
class _OISExport Button : public Component class _OISExport Button : public Component
{ {
public: public:
Button() : Component(OIS_Button), pushed(false) {} Button() : Component(OIS_Button), pushed(false) {}
explicit Button(bool bPushed) : Component(OIS_Button), pushed(bPushed) {} explicit Button(bool bPushed) : Component(OIS_Button), pushed(bPushed) {}
//! true if pushed, false otherwise //! true if pushed, false otherwise
bool pushed; bool pushed;
}; };
//! Axis component //! Axis component
class _OISExport Axis : public Component class _OISExport Axis : public Component
{ {
public: public:
Axis() : Component(OIS_Axis), abs(0), rel(0), absOnly(false) {}; Axis() : Component(OIS_Axis), abs(0), rel(0), absOnly(false) {};
//! Absoulte and Relative value components //! Absoulte and Relative value components
int abs, rel; int abs, rel;
//! Indicates if this Axis only supports Absoulte (ie JoyStick) //! Indicates if this Axis only supports Absoulte (ie JoyStick)
bool absOnly; bool absOnly;
//! Used internally by OIS //! Used internally by OIS
void clear() void clear()
{ {
abs = rel = 0; abs = rel = 0;
} }
}; };
//! A 3D Vector component (perhaps an orientation, as in the WiiMote) //! A 3D Vector component (perhaps an orientation, as in the WiiMote)
class _OISExport Vector3 : public Component class _OISExport Vector3 : public Component
{ {
public: public:
Vector3() {} Vector3() {}
Vector3(float _x, float _y, float _z) : Component(OIS_Vector3), x(_x), y(_y), z(_z) {}; Vector3(float _x, float _y, float _z) : Component(OIS_Vector3), x(_x), y(_y), z(_z) {};
//! X component of vector //! X component of vector
float x; float x;
//! Y component of vector //! Y component of vector
float y; float y;
//! Z component of vector //! Z component of vector
float z; float z;
void clear() void clear()
{ {
x = y = z = 0.0f; x = y = z = 0.0f;
} }
}; };
} }
#endif //end if prereq header defined #endif //end if prereq header defined
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software. the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_SDLInputManager_H #ifndef OIS_SDLInputManager_H
#define OIS_SDLInputManager_H #define OIS_SDLInputManager_H
#include "OISInputManager.h" #include "OISInputManager.h"
#include "SDL/SDLPrereqs.h" #include "SDL/SDLPrereqs.h"
namespace OIS namespace OIS
{ {
/** /**
SDL Input Manager wrapper SDL Input Manager wrapper
*/ */
class SDLInputManager : public InputManager class SDLInputManager : public InputManager
{ {
public: public:
SDLInputManager(); SDLInputManager();
virtual ~SDLInputManager(); virtual ~SDLInputManager();
/** @copydoc InputManager::inputSystemName */ /** @copydoc InputManager::inputSystemName */
virtual const std::string& inputSystemName() { return iName; } virtual const std::string& inputSystemName() { return iName; }
/** @copydoc InputManager::numJoysticks */ /** @copydoc InputManager::numJoysticks */
virtual int numJoySticks(); virtual int numJoySticks();
/** @copydoc InputManager::numMice */ /** @copydoc InputManager::numMice */
virtual int numMice(); virtual int numMice();
/** @copydoc InputManager::numKeyBoards */ /** @copydoc InputManager::numKeyBoards */
virtual int numKeyboards(); virtual int numKeyboards();
/** @copydoc InputManager::createInputObject */ /** @copydoc InputManager::createInputObject */
Object* createInputObject( Type iType, bool bufferMode ); Object* createInputObject( Type iType, bool bufferMode );
/** @copydoc InputManager::destroyInputObject */ /** @copydoc InputManager::destroyInputObject */
void destroyInputObject( Object* obj ); void destroyInputObject( Object* obj );
/** @copydoc InputManager::_initialize */ /** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList ); void _initialize( ParamList &paramList );
//Utility methods to coordinate between mouse and keyboard grabbing //Utility methods to coordinate between mouse and keyboard grabbing
bool _getGrabMode() {return mGrabbed;}; bool _getGrabMode() {return mGrabbed;};
void _setGrabMode(bool grabbed) {mGrabbed = grabbed;} void _setGrabMode(bool grabbed) {mGrabbed = grabbed;}
protected: protected:
//! internal class method for dealing with param list //! internal class method for dealing with param list
void _parseConfigSettings( ParamList &paramList ); void _parseConfigSettings( ParamList &paramList );
//! internal class method for finding attached devices //! internal class method for finding attached devices
void _enumerateDevices(); void _enumerateDevices();
static const std::string iName; static const std::string iName;
bool mGrabbed; bool mGrabbed;
}; };
} }
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment