Skip to content

Instantly share code, notes, and snippets.

@lukaspj
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaspj/6c92c6516b21c2e39cf3 to your computer and use it in GitHub Desktop.
Save lukaspj/6c92c6516b21c2e39cf3 to your computer and use it in GitHub Desktop.
#include "platform/input/xxx/xxxDevice.h"
#include "platform/platformInput.h"
#include "core/module.h"
#include "platform/threads/mutex.h"
#include "console/engineAPI.h"
#include "math/mAngAxis.h"
#include "math/mMatrix.h"
MODULE_BEGIN(xxxDevice)
MODULE_INIT_AFTER( InputEventManager )
MODULE_SHUTDOWN_BEFORE( InputEventManager )
MODULE_INIT
{
try{
ManagedSingleton< XxxDevice >::createSingleton();
} catch(std::runtime_error exception){
Con::errorf("Could not create the xxx device: %s", exception.what());
return;
}
XxxDevice::staticInit();
if (XxxDevice::smEnableDevice)
{
XXXDEV->enable();
}
// Register the device with the Input Event Manager
INPUTMGR->registerDevice(XXXDEV);
}
MODULE_SHUTDOWN
{
if(ManagedSingleton< XxxDevice >::instanceOrNull())
{
INPUTMGR->unregisterDevice(XXXDEV);
ManagedSingleton< XxxDevice >::deleteSingleton();
}
}
MODULE_END;
//-----------------------------------------------------------------------------
// XxxDevice
//-----------------------------------------------------------------------------
U32 XxxDevice::XXX_ORIENTATION = 0;
XxxDevice::XxxDevice()
{
// From IInputDevice
dStrcpy(mName, "xxx");
mDeviceType = INPUTMGR->getNextDeviceType();
mXxx = NULL;
mActiveMutex = Mutex::createMutex();
//
mEnabled = false;
mActive = false;
buildCodeTable();
}
XxxDevice::~XxxDevice()
{
disable();
Mutex::destroyMutex(mActiveMutex);
}
void XxxDevice::staticInit()
{
}
void XxxDevice::buildCodeTable()
{
// Obtain all of the device codes
XXX_ORIENTATION = INPUTMGR->getNextDeviceCode();
// Build out the virtual map
AddInputVirtualMap(orientation, SI_ROT, XXX_ORIENTATION);
}
bool XxxDevice::enable()
{
// Start off with disabling the device if it is already enabled
disable();
mXxx = MagicallyFetchXxxDevice();
// The device is now enabled but not yet ready to be used
mEnabled = true;
XXXDEV->setActive(true);
return false;
}
void XxxDevice::disable()
{
if(mXxx)
{
MagicallyDisableXxxDevice(mXxx);
}
setActive(false);
mEnabled = false;
}
bool XxxDevice::getActive()
{
Mutex::lockMutex(mActiveMutex);
bool active = mActive;
Mutex::unlockMutex(mActiveMutex);
return active;
}
void XxxDevice::setActive(bool state)
{
Mutex::lockMutex(mActiveMutex);
mActive = state;
Mutex::unlockMutex(mActiveMutex);
}
bool XxxDevice::process()
{
if(!mEnabled)
return false;
if(!getActive())
return false;
if (INPUTMGR)
mXxx->MagicallyFetchInputData();
INPUTMGR->buildInputEvent(mDeviceType, DEFAULT_MOTION_UNIT, SI_ROT, XXX_ORIENTATION, SI_MOVE, QuatF(mXxx->orientation));
return true;
}
#ifndef _XXXDEVICE_H_
#define _XXXDEVICE_H_
#include "platform/input/IInputDevice.h"
#include "platform/input/event.h"
#include "platformWin32/platformWin32.h"
#include "core/util/tSingleton.h"
#include "math/mQuat.h"
// The only file that needs to be included to use the XXX C++ SDK is xxx.hpp.
#include <xxx/xxx.hpp>
#define DEFAULT_MOTION_UNIT 0
class XxxDevice : public IInputDevice
{
protected:
/// The pointer to the Xxx device.
xxx::Xxx* mXxx;
/// Used with the LM listener object
void* mActiveMutex;
/// Is the Leap Motion active
bool mActive;
static U32 XXX_ORIENTATION; // SI_ROT
protected:
/// Build out the codes used for controller actions with the
/// Input Event Manager
void buildCodeTable();
public:
static bool smEnableDevice;
// Frame action codes
static U32 XXX_ORIENTATION; // SI_ROT
public:
XxxDevice();
~XxxDevice();
static void staticInit();
bool enable();
void disable();
bool getActive();
void setActive(bool state);
bool process();
public:
// For ManagedSingleton.
static const char* getSingletonName() { return "XxxDevice"; }
};
/// Returns the XxxDevice singleton.
#define XXXDEV ManagedSingleton<XxxDevice>::instance()
#endif // _XXXDEVICE_H_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment