mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 08:27:10 +00:00
Merge branch 'master' of https://github.com/RetroView/libBoo into ds3
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
#ifndef CINPUTDEFERREDRELAY_HPP
|
||||
#define CINPUTDEFERREDRELAY_HPP
|
||||
|
||||
#include "IInputWaiter.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif // CINPUTDEFERREDRELAY_HPP
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef CINPUTRELAY_HPP
|
||||
#define CINPUTRELAY_HPP
|
||||
|
||||
#include "IInputWaiter.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CInputRelay : IInputWaiter
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CINPUTRELAY_HPP
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef CQTOPENGLWINDOW_HPP
|
||||
#define CQTOPENGLWINDOW_HPP
|
||||
|
||||
#include <QWindow>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <ISurface.hpp>
|
||||
|
||||
class CQtOpenGLWindow : public QWindow, ISurface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CQtOpenGLWindow(QWindow *parent = 0);
|
||||
CQtOpenGLWindow();
|
||||
|
||||
virtual void render();
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
|
||||
public slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
bool m_update_pending;
|
||||
bool m_animating;
|
||||
|
||||
QOpenGLContext *m_context;
|
||||
};
|
||||
|
||||
#endif // CQTOPENGLWINDOW_HPP
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef CSURFACE_HPP
|
||||
#define CSURFACE_HPP
|
||||
|
||||
#include "ISurface.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
ISurface* CSurfaceNewWindow();
|
||||
ISurface* CSurfaceNewQWidget();
|
||||
|
||||
}
|
||||
|
||||
#endif // CSURFACE_HPP
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef IGRAPHICSCONTEXT_HPP
|
||||
#define IGRAPHICSCONTEXT_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IGraphicsContext
|
||||
{
|
||||
public:
|
||||
virtual ~IGraphicsContext() {}
|
||||
|
||||
virtual void setMinVersion (const int& min)=0;
|
||||
virtual void setMajorVersion(const int& maj)=0;
|
||||
virtual bool create()=0;
|
||||
virtual const std::string version() const=0;
|
||||
virtual const std::string name() const=0;
|
||||
virtual int depthSize() const=0;
|
||||
virtual int redDepth() const=0;
|
||||
virtual int greenDepth() const=0;
|
||||
virtual int blueDepth() const=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // IGRAPHICSCONTEXT_HPP
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef IINPUTWAITER_HPP
|
||||
#define IINPUTWAITER_HPP
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IInputWaiter
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // IINPUTWAITER_HPP
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef IRETRACEWAITER_HPP
|
||||
#define IRETRACEWAITER_HPP
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IRetraceWaiter
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // IRETRACEWAITER_HPP
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef ISURFACE_HPP
|
||||
#define ISURFACE_HPP
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class ISurface
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CSURFACE_HPP
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef BOO_HPP
|
||||
#define BOO_HPP
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "win/CWGLContext.hpp"
|
||||
namespace boo {typedef CWGLContext CGraphicsContext;}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#include "mac/CCGLContext.hpp"
|
||||
namespace boo {typedef CCGLContext CGraphicsContext;}
|
||||
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#include "x11/CGLXContext.hpp"
|
||||
namespace boo {typedef CGLXContext CGraphicsContext;}
|
||||
|
||||
#endif
|
||||
|
||||
#include "IGraphicsContext.hpp"
|
||||
#include "inputdev/CDeviceFinder.hpp"
|
||||
#include "inputdev/CDolphinSmashAdapter.hpp"
|
||||
#include "inputdev/CDualshockPad.hpp"
|
||||
|
||||
#endif // BOO_HPP
|
||||
87
include/boo/IApplication.hpp
Normal file
87
include/boo/IApplication.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef IRUNLOOP_HPP
|
||||
#define IRUNLOOP_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "IWindow.hpp"
|
||||
#include "inputdev/DeviceFinder.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
class IApplication;
|
||||
|
||||
struct IApplicationCallback
|
||||
{
|
||||
virtual void appLaunched(IApplication* app) {(void)app;}
|
||||
virtual void appQuitting(IApplication* app) {(void)app;}
|
||||
virtual void appFilesOpen(IApplication* app, const std::vector<std::string>& paths) {(void)app;(void)paths;}
|
||||
};
|
||||
|
||||
class IApplication
|
||||
{
|
||||
friend class WindowCocoa;
|
||||
friend class WindowWayland;
|
||||
friend class WindowXCB;
|
||||
friend class WindowWin32;
|
||||
virtual void _deletedWindow(IWindow* window)=0;
|
||||
public:
|
||||
virtual ~IApplication() {}
|
||||
|
||||
enum EPlatformType
|
||||
{
|
||||
PLAT_AUTO = 0,
|
||||
PLAT_WAYLAND = 1,
|
||||
PLAT_XCB = 2,
|
||||
PLAT_ANDROID = 3,
|
||||
PLAT_COCOA = 4,
|
||||
PLAT_COCOA_TOUCH = 5,
|
||||
PLAT_WIN32 = 6,
|
||||
PLAT_WINRT = 7,
|
||||
PLAT_REVOLUTION = 8,
|
||||
PLAT_CAFE = 9
|
||||
};
|
||||
virtual EPlatformType getPlatformType() const=0;
|
||||
|
||||
virtual void run()=0;
|
||||
virtual void quit()=0;
|
||||
virtual const std::string& getUniqueName() const=0;
|
||||
virtual const std::string& getFriendlyName() const=0;
|
||||
virtual const std::string& getProcessName() const=0;
|
||||
virtual const std::vector<std::string>& getArgs() const=0;
|
||||
|
||||
/* Constructors/initializers for sub-objects */
|
||||
virtual IWindow* newWindow(const std::string& title)=0;
|
||||
|
||||
};
|
||||
|
||||
std::unique_ptr<IApplication>
|
||||
ApplicationBootstrap(IApplication::EPlatformType platform,
|
||||
IApplicationCallback& cb,
|
||||
const std::string& uniqueName,
|
||||
const std::string& friendlyName,
|
||||
const std::string& pname,
|
||||
const std::vector<std::string>& args,
|
||||
bool singleInstance=true);
|
||||
extern IApplication* APP;
|
||||
|
||||
static inline std::unique_ptr<IApplication>
|
||||
ApplicationBootstrap(IApplication::EPlatformType platform,
|
||||
IApplicationCallback& cb,
|
||||
const std::string& uniqueName,
|
||||
const std::string& friendlyName,
|
||||
int argc, const char** argv,
|
||||
bool singleInstance=true)
|
||||
{
|
||||
if (APP)
|
||||
return std::unique_ptr<IApplication>();
|
||||
std::vector<std::string> args;
|
||||
for (int i=1 ; i<argc ; ++i)
|
||||
args.push_back(argv[i]);
|
||||
return ApplicationBootstrap(platform, cb, uniqueName, friendlyName, argv[0], args, singleInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // IRUNLOOP_HPP
|
||||
48
include/boo/IGraphicsContext.hpp
Normal file
48
include/boo/IGraphicsContext.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef IGFXCONTEXT_HPP
|
||||
#define IGFXCONTEXT_HPP
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IGraphicsContext
|
||||
{
|
||||
friend class CWindowCocoa;
|
||||
friend class CWindowXCB;
|
||||
virtual void _setCallback(class IWindowCallback* cb) {(void)cb;}
|
||||
|
||||
public:
|
||||
|
||||
enum EGraphicsAPI
|
||||
{
|
||||
API_NONE = 0,
|
||||
API_OPENGL_3_3 = 1,
|
||||
API_OPENGL_4_2 = 2,
|
||||
API_OPENGLES_3 = 3,
|
||||
API_VULKAN = 4,
|
||||
API_D3D11 = 5,
|
||||
API_METAL = 6,
|
||||
API_GX = 7,
|
||||
API_GX2 = 8
|
||||
};
|
||||
|
||||
enum EPixelFormat
|
||||
{
|
||||
PF_NONE = 0,
|
||||
PF_RGBA8 = 1, /* Default */
|
||||
PF_RGBA8_Z24 = 2,
|
||||
PF_RGBAF32 = 3,
|
||||
PF_RGBAF32_Z24 = 4
|
||||
};
|
||||
|
||||
virtual ~IGraphicsContext() {}
|
||||
|
||||
virtual EGraphicsAPI getAPI() const=0;
|
||||
virtual EPixelFormat getPixelFormat() const=0;
|
||||
virtual void setPixelFormat(EPixelFormat pf)=0;
|
||||
virtual void initializeContext()=0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // IGFXCONTEXT_HPP
|
||||
146
include/boo/IWindow.hpp
Normal file
146
include/boo/IWindow.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#ifndef IWINDOW_HPP
|
||||
#define IWINDOW_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IWindowCallback
|
||||
{
|
||||
public:
|
||||
enum EMouseButton
|
||||
{
|
||||
BUTTON_NONE = 0,
|
||||
BUTTON_PRIMARY = 1,
|
||||
BUTTON_SECONDARY = 2,
|
||||
BUTTON_MIDDLE = 3,
|
||||
BUTTON_AUX1 = 4,
|
||||
BUTTON_AUX2 = 5
|
||||
};
|
||||
|
||||
struct SWindowCoord
|
||||
{
|
||||
unsigned pixel[2];
|
||||
unsigned virtualPixel[2];
|
||||
float norm[2];
|
||||
};
|
||||
|
||||
struct STouchCoord
|
||||
{
|
||||
double coord[2];
|
||||
};
|
||||
|
||||
struct SScrollDelta
|
||||
{
|
||||
double delta[2];
|
||||
bool isFine; /* Use system-scale fine-scroll (for scrollable-trackpads) */
|
||||
};
|
||||
|
||||
enum ESpecialKey
|
||||
{
|
||||
KEY_NONE = 0,
|
||||
KEY_F1 = 1,
|
||||
KEY_F2 = 2,
|
||||
KEY_F3 = 3,
|
||||
KEY_F4 = 4,
|
||||
KEY_F5 = 5,
|
||||
KEY_F6 = 6,
|
||||
KEY_F7 = 7,
|
||||
KEY_F8 = 8,
|
||||
KEY_F9 = 9,
|
||||
KEY_F10 = 10,
|
||||
KEY_F11 = 11,
|
||||
KEY_F12 = 12,
|
||||
KEY_ESC = 13,
|
||||
KEY_ENTER = 14,
|
||||
KEY_BACKSPACE = 15,
|
||||
KEY_INSERT = 16,
|
||||
KEY_DELETE = 17,
|
||||
KEY_HOME = 18,
|
||||
KEY_END = 19,
|
||||
KEY_PGUP = 20,
|
||||
KEY_PGDOWN = 21,
|
||||
KEY_LEFT = 22,
|
||||
KEY_RIGHT = 23,
|
||||
KEY_UP = 24,
|
||||
KEY_DOWN = 25
|
||||
};
|
||||
|
||||
enum EModifierKey
|
||||
{
|
||||
MKEY_NONE = 0,
|
||||
MKEY_CTRL = 1<<0,
|
||||
MKEY_ALT = 1<<2,
|
||||
MKEY_SHIFT = 1<<3,
|
||||
MKEY_COMMAND = 1<<4
|
||||
};
|
||||
|
||||
virtual void mouseDown(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
||||
{(void)coord;(void)button;(void)mods;}
|
||||
virtual void mouseUp(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
||||
{(void)coord;(void)button;(void)mods;}
|
||||
virtual void mouseMove(const SWindowCoord& coord)
|
||||
{(void)coord;}
|
||||
virtual void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
||||
{(void)coord;(void)scroll;}
|
||||
|
||||
virtual void touchDown(const STouchCoord& coord, uintptr_t tid)
|
||||
{(void)coord;(void)tid;}
|
||||
virtual void touchUp(const STouchCoord& coord, uintptr_t tid)
|
||||
{(void)coord;(void)tid;}
|
||||
virtual void touchMove(const STouchCoord& coord, uintptr_t tid)
|
||||
{(void)coord;(void)tid;}
|
||||
|
||||
virtual void charKeyDown(unsigned long charCode, EModifierKey mods, bool isRepeat)
|
||||
{(void)charCode;(void)mods;(void)isRepeat;}
|
||||
virtual void charKeyUp(unsigned long charCode, EModifierKey mods)
|
||||
{(void)charCode;(void)mods;}
|
||||
virtual void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat)
|
||||
{(void)key;(void)mods;(void)isRepeat;}
|
||||
virtual void specialKeyUp(ESpecialKey key, EModifierKey mods)
|
||||
{(void)key;(void)mods;}
|
||||
virtual void modKeyDown(EModifierKey mod, bool isRepeat)
|
||||
{(void)mod;(void)isRepeat;}
|
||||
virtual void modKeyUp(EModifierKey mod) {(void)mod;}
|
||||
|
||||
};
|
||||
|
||||
class IWindow
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~IWindow() {}
|
||||
|
||||
virtual void setCallback(IWindowCallback* cb)=0;
|
||||
|
||||
virtual void showWindow()=0;
|
||||
virtual void hideWindow()=0;
|
||||
|
||||
virtual std::string getTitle()=0;
|
||||
virtual void setTitle(const std::string& title)=0;
|
||||
|
||||
virtual void setWindowFrameDefault()=0;
|
||||
virtual void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const=0;
|
||||
virtual void setWindowFrame(float x, float y, float w, float h)=0;
|
||||
virtual float getVirtualPixelFactor() const=0;
|
||||
|
||||
virtual bool isFullscreen() const=0;
|
||||
virtual void setFullscreen(bool fs)=0;
|
||||
|
||||
virtual uintptr_t getPlatformHandle() const=0;
|
||||
virtual void _incomingEvent(void* event) {(void)event;}
|
||||
|
||||
enum ETouchType
|
||||
{
|
||||
TOUCH_NONE = 0,
|
||||
TOUCH_DISPLAY = 1,
|
||||
TOUCH_TRACKPAD = 2
|
||||
};
|
||||
virtual ETouchType getTouchType() const=0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // IWINDOW_HPP
|
||||
10
include/boo/boo.hpp
Normal file
10
include/boo/boo.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef BOO_HPP
|
||||
#define BOO_HPP
|
||||
|
||||
#include "IApplication.hpp"
|
||||
#include "IWindow.hpp"
|
||||
#include "inputdev/DeviceFinder.hpp"
|
||||
#include "inputdev/DolphinSmashAdapter.hpp"
|
||||
#include "inputdev/DualshockPad.hpp"
|
||||
|
||||
#endif // BOO_HPP
|
||||
@@ -8,27 +8,27 @@
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CDeviceBase
|
||||
class DeviceBase
|
||||
{
|
||||
friend class CDeviceToken;
|
||||
friend class CHIDDeviceIOKit;
|
||||
friend class CHIDDeviceUdev;
|
||||
friend class CHIDDeviceWinUSB;
|
||||
friend class DeviceToken;
|
||||
friend class HIDDeviceIOKit;
|
||||
friend class HIDDeviceUdev;
|
||||
friend class HIDDeviceWinUSB;
|
||||
|
||||
class CDeviceToken* m_token;
|
||||
class DeviceToken* m_token;
|
||||
class IHIDDevice* m_hidDev;
|
||||
void _deviceDisconnected();
|
||||
|
||||
public:
|
||||
CDeviceBase(CDeviceToken* token);
|
||||
virtual ~CDeviceBase();
|
||||
DeviceBase(DeviceToken* token);
|
||||
virtual ~DeviceBase();
|
||||
void closeDevice();
|
||||
virtual void deviceDisconnected()=0;
|
||||
virtual void deviceError(const char* error, ...);
|
||||
|
||||
/* Low-Level API */
|
||||
bool sendUSBInterruptTransfer(uint8_t pipe, const uint8_t* data, size_t length);
|
||||
size_t receiveUSBInterruptTransfer(uint8_t pipe, uint8_t* data, size_t length);
|
||||
bool sendUSBInterruptTransfer(const uint8_t* data, size_t length);
|
||||
size_t receiveUSBInterruptTransfer(uint8_t* data, size_t length);
|
||||
virtual void initialCycle() {}
|
||||
virtual void transferCycle() {}
|
||||
virtual void finalCycle() {}
|
||||
@@ -1,13 +1,14 @@
|
||||
#ifndef CDEVICEFINDER_HPP
|
||||
#define CDEVICEFINDER_HPP
|
||||
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <typeindex>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include "CDeviceToken.hpp"
|
||||
#include "DeviceToken.hpp"
|
||||
#include "IHIDListener.hpp"
|
||||
#include "SDeviceSignature.hpp"
|
||||
#include "DeviceSignature.hpp"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_LEAN_AND_MEAN 1
|
||||
@@ -18,20 +19,20 @@
|
||||
namespace boo
|
||||
{
|
||||
|
||||
static class CDeviceFinder* skDevFinder = NULL;
|
||||
static class DeviceFinder* skDevFinder = NULL;
|
||||
|
||||
class CDeviceFinder
|
||||
class DeviceFinder
|
||||
{
|
||||
public:
|
||||
friend class CHIDListenerIOKit;
|
||||
friend class CHIDListenerUdev;
|
||||
friend class CHIDListenerWinUSB;
|
||||
static inline CDeviceFinder* instance() {return skDevFinder;}
|
||||
friend class HIDListenerIOKit;
|
||||
friend class HIDListenerUdev;
|
||||
friend class HIDListenerWinUSB;
|
||||
static inline DeviceFinder* instance() {return skDevFinder;}
|
||||
|
||||
private:
|
||||
|
||||
/* Types this finder is interested in (immutable) */
|
||||
SDeviceSignature::TDeviceSignatureSet m_types;
|
||||
DeviceSignature::TDeviceSignatureSet m_types;
|
||||
|
||||
/* Platform-specific USB event registration
|
||||
* (for auto-scanning, NULL if not registered) */
|
||||
@@ -50,9 +51,9 @@ private:
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
inline bool _insertToken(CDeviceToken&& token)
|
||||
inline bool _insertToken(DeviceToken&& token)
|
||||
{
|
||||
if (SDeviceSignature::DeviceMatchToken(token, m_types)) {
|
||||
if (DeviceSignature::DeviceMatchToken(token, m_types)) {
|
||||
m_tokensLock.lock();
|
||||
TInsertedDeviceToken inseredTok =
|
||||
m_tokens.insert(std::make_pair(token.getDevicePath(), std::move(token)));
|
||||
@@ -67,8 +68,8 @@ private:
|
||||
auto preCheck = m_tokens.find(path);
|
||||
if (preCheck != m_tokens.end())
|
||||
{
|
||||
CDeviceToken& tok = preCheck->second;
|
||||
CDeviceBase* dev = tok.m_connectedDev;
|
||||
DeviceToken& tok = preCheck->second;
|
||||
DeviceBase* dev = tok.m_connectedDev;
|
||||
tok._deviceClose();
|
||||
deviceDisconnected(tok, dev);
|
||||
m_tokensLock.lock();
|
||||
@@ -81,9 +82,9 @@ public:
|
||||
|
||||
class CDeviceTokensHandle
|
||||
{
|
||||
CDeviceFinder& m_finder;
|
||||
DeviceFinder& m_finder;
|
||||
public:
|
||||
inline CDeviceTokensHandle(CDeviceFinder& finder) : m_finder(finder)
|
||||
inline CDeviceTokensHandle(DeviceFinder& finder) : m_finder(finder)
|
||||
{m_finder.m_tokensLock.lock();}
|
||||
inline ~CDeviceTokensHandle() {m_finder.m_tokensLock.unlock();}
|
||||
inline TDeviceTokens::iterator begin() {return m_finder.m_tokens.begin();}
|
||||
@@ -91,24 +92,27 @@ public:
|
||||
};
|
||||
|
||||
/* Application must specify its interested device-types */
|
||||
CDeviceFinder(std::vector<const char*> types)
|
||||
DeviceFinder(std::unordered_set<std::type_index> types)
|
||||
: m_listener(NULL)
|
||||
{
|
||||
if (skDevFinder)
|
||||
throw std::runtime_error("only one instance of CDeviceFinder may be constructed");
|
||||
skDevFinder = this;
|
||||
for (const char* typeName : types)
|
||||
{
|
||||
const SDeviceSignature* sigIter = BOO_DEVICE_SIGS;
|
||||
fprintf(stderr, "only one instance of CDeviceFinder may be constructed");
|
||||
abort();
|
||||
}
|
||||
skDevFinder = this;
|
||||
for (const std::type_index& typeIdx : types)
|
||||
{
|
||||
const DeviceSignature* sigIter = BOO_DEVICE_SIGS;
|
||||
while (sigIter->m_name)
|
||||
{
|
||||
if (!strcmp(sigIter->m_name, typeName))
|
||||
if (sigIter->m_typeIdx == typeIdx)
|
||||
m_types.push_back(sigIter);
|
||||
++sigIter;
|
||||
}
|
||||
}
|
||||
}
|
||||
~CDeviceFinder()
|
||||
~DeviceFinder()
|
||||
{
|
||||
if (m_listener)
|
||||
m_listener->stopScanning();
|
||||
@@ -117,7 +121,7 @@ public:
|
||||
}
|
||||
|
||||
/* Get interested device-type mask */
|
||||
inline const SDeviceSignature::TDeviceSignatureSet& getTypes() const {return m_types;}
|
||||
inline const DeviceSignature::TDeviceSignatureSet& getTypes() const {return m_types;}
|
||||
|
||||
/* Iterable set of tokens */
|
||||
inline CDeviceTokensHandle getTokens() {return CDeviceTokensHandle(*this);}
|
||||
@@ -150,8 +154,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void deviceConnected(CDeviceToken&) {}
|
||||
virtual void deviceDisconnected(CDeviceToken&, CDeviceBase*) {}
|
||||
virtual void deviceConnected(DeviceToken&) {}
|
||||
virtual void deviceDisconnected(DeviceToken&, DeviceBase*) {}
|
||||
|
||||
#if _WIN32
|
||||
/* Windows-specific WM_DEVICECHANGED handler */
|
||||
38
include/boo/inputdev/DeviceSignature.hpp
Normal file
38
include/boo/inputdev/DeviceSignature.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef SDeviceSignature_HPP
|
||||
#define SDeviceSignature_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <typeindex>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class DeviceToken;
|
||||
class DeviceBase;
|
||||
|
||||
struct DeviceSignature
|
||||
{
|
||||
typedef std::vector<const DeviceSignature*> TDeviceSignatureSet;
|
||||
typedef std::function<DeviceBase*(DeviceToken*)> TFactoryLambda;
|
||||
const char* m_name;
|
||||
std::type_index m_typeIdx;
|
||||
unsigned m_vid, m_pid;
|
||||
TFactoryLambda m_factory;
|
||||
DeviceSignature() : m_name(NULL), m_typeIdx(typeid(DeviceSignature)) {} /* Sentinel constructor */
|
||||
DeviceSignature(const char* name, std::type_index&& typeIdx, unsigned vid, unsigned pid, TFactoryLambda&& factory)
|
||||
: m_name(name), m_typeIdx(typeIdx), m_vid(vid), m_pid(pid), m_factory(factory) {}
|
||||
static bool DeviceMatchToken(const DeviceToken& token, const TDeviceSignatureSet& sigSet);
|
||||
static DeviceBase* DeviceNew(DeviceToken& token);
|
||||
};
|
||||
|
||||
#define DEVICE_SIG(name, vid, pid) \
|
||||
DeviceSignature(#name, typeid(name), vid, pid, [](DeviceToken* tok) -> DeviceBase* {return new name(tok);})
|
||||
#define DEVICE_SIG_SENTINEL() DeviceSignature()
|
||||
|
||||
extern const DeviceSignature BOO_DEVICE_SIGS[];
|
||||
|
||||
}
|
||||
|
||||
#endif // SDeviceSignature_HPP
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#define CDEVICETOKEN
|
||||
|
||||
#include <string>
|
||||
#include "CDeviceBase.hpp"
|
||||
#include "SDeviceSignature.hpp"
|
||||
#include "DeviceBase.hpp"
|
||||
#include "DeviceSignature.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CDeviceToken
|
||||
class DeviceToken
|
||||
{
|
||||
public:
|
||||
enum TDeviceType
|
||||
@@ -27,10 +27,10 @@ private:
|
||||
std::string m_productName;
|
||||
std::string m_devPath;
|
||||
|
||||
friend class CDeviceBase;
|
||||
CDeviceBase* m_connectedDev;
|
||||
friend class DeviceBase;
|
||||
DeviceBase* m_connectedDev;
|
||||
|
||||
friend class CDeviceFinder;
|
||||
friend class DeviceFinder;
|
||||
inline void _deviceClose()
|
||||
{
|
||||
if (m_connectedDev)
|
||||
@@ -40,8 +40,8 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
CDeviceToken(const CDeviceToken&) = delete;
|
||||
CDeviceToken(const CDeviceToken&& other)
|
||||
DeviceToken(const DeviceToken&) = delete;
|
||||
DeviceToken(const DeviceToken&& other)
|
||||
: m_devType(other.m_devType),
|
||||
m_vendorId(other.m_vendorId),
|
||||
m_productId(other.m_productId),
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
m_devPath(other.m_devPath),
|
||||
m_connectedDev(other.m_connectedDev)
|
||||
{}
|
||||
inline CDeviceToken(enum TDeviceType devType, unsigned vid, unsigned pid, const char* vname, const char* pname, const char* path)
|
||||
inline DeviceToken(enum TDeviceType devType, unsigned vid, unsigned pid, const char* vname, const char* pname, const char* path)
|
||||
: m_devType(devType),
|
||||
m_vendorId(vid),
|
||||
m_productId(pid),
|
||||
@@ -70,16 +70,16 @@ public:
|
||||
inline const std::string& getProductName() const {return m_productName;}
|
||||
inline const std::string& getDevicePath() const {return m_devPath;}
|
||||
inline bool isDeviceOpen() const {return (m_connectedDev != NULL);}
|
||||
inline CDeviceBase* openAndGetDevice()
|
||||
inline DeviceBase* openAndGetDevice()
|
||||
{
|
||||
if (!m_connectedDev)
|
||||
m_connectedDev = SDeviceSignature::DeviceNew(*this);
|
||||
m_connectedDev = DeviceSignature::DeviceNew(*this);
|
||||
return m_connectedDev;
|
||||
}
|
||||
|
||||
inline bool operator ==(const CDeviceToken& rhs) const
|
||||
inline bool operator ==(const DeviceToken& rhs) const
|
||||
{return m_devPath == rhs.m_devPath;}
|
||||
inline bool operator <(const CDeviceToken& rhs) const
|
||||
inline bool operator <(const DeviceToken& rhs) const
|
||||
{return m_devPath < rhs.m_devPath;}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CDOLPHINSMASHADAPTER_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include "CDeviceBase.hpp"
|
||||
#include "DeviceBase.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
@@ -29,7 +29,8 @@ enum EDolphinControllerButtons
|
||||
DOL_DOWN = 1<<14,
|
||||
DOL_UP = 1<<15
|
||||
};
|
||||
struct SDolphinControllerState
|
||||
|
||||
struct DolphinControllerState
|
||||
{
|
||||
uint8_t m_leftStick[2];
|
||||
uint8_t m_rightStick[2];
|
||||
@@ -39,13 +40,13 @@ struct SDolphinControllerState
|
||||
|
||||
struct IDolphinSmashAdapterCallback
|
||||
{
|
||||
virtual void controllerConnected(unsigned idx, EDolphinControllerType type) {}
|
||||
virtual void controllerDisconnected(unsigned idx, EDolphinControllerType type) {}
|
||||
virtual void controllerConnected(unsigned idx, EDolphinControllerType type) {(void)idx;(void)type;}
|
||||
virtual void controllerDisconnected(unsigned idx, EDolphinControllerType type) {(void)idx;(void)type;}
|
||||
virtual void controllerUpdate(unsigned idx, EDolphinControllerType type,
|
||||
const SDolphinControllerState& state) {}
|
||||
const DolphinControllerState& state) {(void)idx;(void)type;(void)state;}
|
||||
};
|
||||
|
||||
class CDolphinSmashAdapter final : public CDeviceBase
|
||||
class DolphinSmashAdapter final : public DeviceBase
|
||||
{
|
||||
IDolphinSmashAdapterCallback* m_callback;
|
||||
uint8_t m_knownControllers;
|
||||
@@ -56,8 +57,8 @@ class CDolphinSmashAdapter final : public CDeviceBase
|
||||
void transferCycle();
|
||||
void finalCycle();
|
||||
public:
|
||||
CDolphinSmashAdapter(CDeviceToken* token);
|
||||
~CDolphinSmashAdapter();
|
||||
DolphinSmashAdapter(DeviceToken* token);
|
||||
~DolphinSmashAdapter();
|
||||
|
||||
inline void setCallback(IDolphinSmashAdapterCallback* cb)
|
||||
{m_callback = cb; m_knownControllers = 0;}
|
||||
@@ -1,13 +1,12 @@
|
||||
#ifndef CDUALSHOCKPAD_HPP
|
||||
#define CDUALSHOCKPAD_HPP
|
||||
#include <stdint.h>
|
||||
#include "CDeviceBase.hpp"
|
||||
#include "DeviceBase.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
|
||||
struct SDualshockLED
|
||||
struct DualshockLED
|
||||
{
|
||||
uint8_t timeEnabled;
|
||||
uint8_t dutyLength;
|
||||
@@ -16,7 +15,7 @@ struct SDualshockLED
|
||||
uint8_t dutyOn;
|
||||
};
|
||||
|
||||
struct SDualshockRumble
|
||||
struct DualshockRumble
|
||||
{
|
||||
uint8_t rightDuration;
|
||||
bool rightOn;
|
||||
@@ -24,23 +23,23 @@ struct SDualshockRumble
|
||||
uint8_t leftForce;
|
||||
};
|
||||
|
||||
union SDualshockOutReport
|
||||
union DualshockOutReport
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t reportId;
|
||||
SDualshockRumble rumble;
|
||||
DualshockRumble rumble;
|
||||
uint8_t gyro1;
|
||||
uint8_t gyro2;
|
||||
uint8_t padding[2];
|
||||
uint8_t leds;
|
||||
SDualshockLED led[4];
|
||||
SDualshockLED reserved;
|
||||
DualshockLED led[4];
|
||||
DualshockLED reserved;
|
||||
};
|
||||
uint8_t buf[36];
|
||||
};
|
||||
|
||||
enum EDualshockControllerButtons
|
||||
enum EDualshockPadButtons
|
||||
{
|
||||
DS3_SELECT = 1<< 0,
|
||||
DS3_L3 = 1<< 1,
|
||||
@@ -75,7 +74,7 @@ enum EDualshockLED
|
||||
DS3_LED_4 = 1<<4
|
||||
};
|
||||
|
||||
struct SDualshockControllerState
|
||||
struct DualshockPadState
|
||||
{
|
||||
uint8_t m_reportType;
|
||||
uint8_t m_reserved1;
|
||||
@@ -110,33 +109,33 @@ struct SDualshockControllerState
|
||||
float gyroZ;
|
||||
};
|
||||
|
||||
class CDualshockController;
|
||||
struct IDualshockControllerCallback
|
||||
class DualshockPad;
|
||||
struct IDualshockPadCallback
|
||||
{
|
||||
CDualshockController* ctrl = nullptr;
|
||||
DualshockPad* ctrl = nullptr;
|
||||
virtual void controllerDisconnected() {}
|
||||
virtual void controllerUpdate(const SDualshockControllerState&) {}
|
||||
virtual void controllerUpdate(const DualshockPadState&) {}
|
||||
};
|
||||
|
||||
class CDualshockController final : public CDeviceBase
|
||||
class DualshockPad final : public DeviceBase
|
||||
{
|
||||
IDualshockControllerCallback* m_callback;
|
||||
IDualshockPadCallback* m_callback;
|
||||
uint8_t m_rumbleRequest;
|
||||
uint8_t m_rumbleState;
|
||||
uint8_t m_rumbleDuration[2];
|
||||
uint8_t m_rumbleIntensity[2];
|
||||
uint8_t m_led;
|
||||
SDualshockOutReport m_report;
|
||||
DualshockOutReport m_report;
|
||||
uint8_t m_btAddress[6];
|
||||
void deviceDisconnected();
|
||||
void initialCycle();
|
||||
void transferCycle();
|
||||
void finalCycle();
|
||||
public:
|
||||
CDualshockController(CDeviceToken* token);
|
||||
~CDualshockController();
|
||||
DualshockPad(DeviceToken* token);
|
||||
~DualshockPad();
|
||||
|
||||
inline void setCallback(IDualshockControllerCallback* cb)
|
||||
inline void setCallback(IDualshockPadCallback* cb)
|
||||
{ m_callback = cb; if (m_callback) m_callback->ctrl = this; }
|
||||
|
||||
inline void startRumble(int motor, uint8_t duration = 254, uint8_t intensity=255)
|
||||
@@ -1,16 +1,16 @@
|
||||
#ifndef CGENERICPAD_HPP
|
||||
#define CGENERICPAD_HPP
|
||||
|
||||
#include "CDeviceBase.hpp"
|
||||
#include "DeviceBase.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CGenericPad final : public CDeviceBase
|
||||
class GenericPad final : public DeviceBase
|
||||
{
|
||||
public:
|
||||
CGenericPad(CDeviceToken* token);
|
||||
~CGenericPad();
|
||||
GenericPad(DeviceToken* token);
|
||||
~GenericPad();
|
||||
|
||||
void deviceDisconnected();
|
||||
};
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include "CDeviceToken.hpp"
|
||||
#include "DeviceToken.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
typedef std::unordered_map<std::string, CDeviceToken> TDeviceTokens;
|
||||
typedef std::unordered_map<std::string, DeviceToken> TDeviceTokens;
|
||||
typedef std::pair<TDeviceTokens::iterator, bool> TInsertedDeviceToken;
|
||||
class CDeviceFinder;
|
||||
class DeviceFinder;
|
||||
|
||||
class IHIDListener
|
||||
{
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
};
|
||||
|
||||
/* Platform-specific constructor */
|
||||
IHIDListener* IHIDListenerNew(CDeviceFinder& finder);
|
||||
IHIDListener* IHIDListenerNew(DeviceFinder& finder);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef SDeviceSignature_HPP
|
||||
#define SDeviceSignature_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CDeviceToken;
|
||||
class CDeviceBase;
|
||||
|
||||
struct SDeviceSignature
|
||||
{
|
||||
typedef std::vector<const SDeviceSignature*> TDeviceSignatureSet;
|
||||
typedef std::function<CDeviceBase*(CDeviceToken*)> TFactoryLambda;
|
||||
const char* m_name;
|
||||
unsigned m_vid, m_pid;
|
||||
TFactoryLambda m_factory;
|
||||
SDeviceSignature() : m_name(NULL) {} /* Sentinel constructor */
|
||||
SDeviceSignature(const char* name, unsigned vid, unsigned pid, TFactoryLambda&& factory)
|
||||
: m_name(name), m_vid(vid), m_pid(pid), m_factory(factory) {}
|
||||
static bool DeviceMatchToken(const CDeviceToken& token, const TDeviceSignatureSet& sigSet);
|
||||
static CDeviceBase* DeviceNew(CDeviceToken& token);
|
||||
};
|
||||
|
||||
#define DEVICE_SIG(name, vid, pid) \
|
||||
SDeviceSignature(#name, vid, pid, [](CDeviceToken* tok) -> CDeviceBase* {return new name(tok);})
|
||||
#define DEVICE_SIG_SENTINEL() SDeviceSignature()
|
||||
|
||||
extern const SDeviceSignature BOO_DEVICE_SIGS[];
|
||||
|
||||
}
|
||||
|
||||
#endif // SDeviceSignature_HPP
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef CCGLCONTEXT_HPP
|
||||
#define CCGLCONTEXT_HPP
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "IGraphicsContext.hpp"
|
||||
#include <OpenGL/OpenGL.h>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CCGLContext final : public IGraphicsContext
|
||||
{
|
||||
public:
|
||||
CCGLContext();
|
||||
virtual ~CCGLContext();
|
||||
|
||||
bool create();
|
||||
void setMinVersion (const int& min) override;
|
||||
void setMajorVersion(const int& maj) override;
|
||||
const std::string version() const override;
|
||||
const std::string name() const override;
|
||||
int depthSize() const override;
|
||||
int redDepth() const override;
|
||||
int greenDepth() const override;
|
||||
int blueDepth() const override;
|
||||
private:
|
||||
int m_minVersion;
|
||||
int m_majVersion;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __APPLE__
|
||||
#endif // CCGLCONTEXT_HPP
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef CWGLCONTEXT_HPP
|
||||
#define CWGLCONTEXT_HPP
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "IGraphicsContext.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CWGLContext : public IGraphicsContext
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // CWGLCONTEXT_HPP
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef CGLXCONTEXT_HPP
|
||||
#define CGLXCONTEXT_HPP
|
||||
|
||||
#if !defined(__APPLE__) && (defined(__linux__) || defined(BSD))
|
||||
#include <GL/glx.h>
|
||||
#include "IGraphicsContext.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CGLXContext final : public IGraphicsContext
|
||||
{
|
||||
public:
|
||||
CGLXContext();
|
||||
virtual ~CGLXContext() {}
|
||||
|
||||
bool create();
|
||||
void setMajorVersion(const int& maj) override;
|
||||
void setMinVersion(const int& min) override;
|
||||
const std::string version() const override;
|
||||
const std::string name() const override;
|
||||
int depthSize() const override;
|
||||
int redDepth() const override;
|
||||
int greenDepth() const override;
|
||||
int blueDepth() const override;
|
||||
private:
|
||||
int m_majVersion;
|
||||
int m_minVersion;
|
||||
|
||||
Display* m_display;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // !defined(__APPLE__) && (defined(__linux__) || defined(BSD))
|
||||
#endif // CGLXCONTEXT_HPP
|
||||
Reference in New Issue
Block a user