Major refactor for better modularity

This commit is contained in:
Jack Andersen
2015-08-18 09:40:26 -10:00
parent 3007714b5a
commit e56b8539bf
62 changed files with 275 additions and 791 deletions

View File

@@ -4,8 +4,8 @@
#include <string>
#include <vector>
#include "windowsys/IWindow.hpp"
#include "inputdev/CDeviceFinder.hpp"
#include "IWindow.hpp"
#include "inputdev/DeviceFinder.hpp"
namespace boo
{
@@ -15,15 +15,15 @@ struct IApplicationCallback
{
virtual void appLaunched(IApplication* app) {(void)app;}
virtual void appQuitting(IApplication* app) {(void)app;}
virtual void appFilesOpen(IApplication* app, const std::vector<const std::string>& paths) {(void)app;(void)paths;}
virtual void appFilesOpen(IApplication* app, const std::vector<std::string>& paths) {(void)app;(void)paths;}
};
class IApplication
{
friend class CWindowCocoa;
friend class CWindowWayland;
friend class CWindowXCB;
friend class CWindowWin32;
friend class WindowCocoa;
friend class WindowWayland;
friend class WindowXCB;
friend class WindowWin32;
virtual void _deletedWindow(IWindow* window)=0;
public:
virtual ~IApplication() {}
@@ -63,7 +63,6 @@ IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
const std::vector<std::string>& args,
bool singleInstance=true);
extern IApplication* APP;
#define IApplicationInstance() APP
static inline IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,

View File

@@ -4,7 +4,7 @@
namespace boo
{
class IGFXContext
class IGraphicsContext
{
friend class CWindowCocoa;
friend class CWindowXCB;
@@ -34,7 +34,7 @@ public:
PF_RGBAF32_Z24 = 4
};
virtual ~IGFXContext() {}
virtual ~IGraphicsContext() {}
virtual EGraphicsAPI getAPI() const=0;
virtual EPixelFormat getPixelFormat() const=0;

View File

@@ -1,11 +0,0 @@
#ifndef CINPUTDEFERREDRELAY_HPP
#define CINPUTDEFERREDRELAY_HPP
#include "IInputWaiter.hpp"
namespace boo
{
}
#endif // CINPUTDEFERREDRELAY_HPP

View File

@@ -1,16 +0,0 @@
#ifndef CINPUTRELAY_HPP
#define CINPUTRELAY_HPP
#include "IInputWaiter.hpp"
namespace boo
{
class CInputRelay : IInputWaiter
{
};
}
#endif // CINPUTRELAY_HPP

View File

@@ -1,14 +0,0 @@
#ifndef CSURFACE_HPP
#define CSURFACE_HPP
#include "ISurface.hpp"
namespace boo
{
ISurface* CSurfaceNewWindow();
ISurface* CSurfaceNewQWidget();
}
#endif // CSURFACE_HPP

View File

@@ -2,8 +2,8 @@
#define BOO_HPP
#include "IApplication.hpp"
#include "windowsys/IWindow.hpp"
#include "inputdev/CDeviceFinder.hpp"
#include "inputdev/CDolphinSmashAdapter.hpp"
#include "IWindow.hpp"
#include "inputdev/DeviceFinder.hpp"
#include "inputdev/DolphinSmashAdapter.hpp"
#endif // BOO_HPP

View File

@@ -1,20 +0,0 @@
#ifndef CGFXVERTEXLAYOUTBASE_HPP
#define CGFXVERTEXLAYOUTBASE_HPP
class CGFXVertexLayoutBase
{
unsigned m_uvCount;
unsigned m_weightCount;
public:
CGFXVertexLayoutBase(unsigned uvCount=0, unsigned weightCount=0)
: m_uvCount(uvCount),
m_weightCount(weightCount) {}
virtual ~CGFXVertexLayoutBase() {}
inline unsigned uvCount() {return m_uvCount;}
inline unsigned weightCount() {return m_weightCount;}
inline bool isSkinned() {return m_weightCount > 0;}
};
#endif // CGFXVERTEXLAYOUTBASE_HPP

View File

@@ -1,5 +0,0 @@
#ifndef IGFXCOMMANDBUFFER_HPP
#define IGFXCOMMANDBUFFER_HPP
#endif // IGFXCOMMANDBUFFER_HPP

View File

@@ -1,5 +0,0 @@
#ifndef IGFXPIPELINESTATE_HPP
#define IGFXPIPELINESTATE_HPP
#endif // IGFXPIPELINESTATE_HPP

View File

@@ -1,5 +0,0 @@
#ifndef IGFXTRANSFORMSET_HPP
#define IGFXTRANSFORMSET_HPP
#endif // IGFXTRANSFORMSET_HPP

View File

@@ -1,20 +0,0 @@
#ifndef CHECLLEXER_HPP
#define CHECLLEXER_HPP
#include <string>
#include "graphicsys/CGFXVertexLayoutBase.hpp"
class CHECLLexer
{
const CGFXVertexLayoutBase& m_vertLayout;
public:
CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL);
CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL,
const std::string& alphaHECL);
inline const CGFXVertexLayoutBase& getVertLayout() const {return m_vertLayout;}
};
#endif // CHECLLEXER_HPP

View File

@@ -1,46 +0,0 @@
#ifndef HECLEXPRESSIONS_HPP
#define HECLEXPRESSIONS_HPP
#include <string>
#include "IHECLBackend.hpp"
class IHECLExpression
{
/* Traverse expression tree and assemble
* backend-specific stage objects */
virtual IHECLBackendStage* recursiveStages(IHECLBackend& backend) const=0;
};
class CHECLNumberLiteral final : IHECLExpression
{
};
class CHECLVector final : IHECLExpression
{
};
class CHECLTextureSample final : IHECLExpression
{
};
class CHECLTextureGatherSample final : IHECLExpression
{
};
class CHECLMulOperation final : IHECLExpression
{
};
class CHECLAddOperation final : IHECLExpression
{
};
class CHECLSubOperation final : IHECLExpression
{
};
class CHECLRoot final : IHECLExpression
{
};
#endif // HECLEXPRESSIONS_HPP

View File

@@ -1,76 +0,0 @@
#ifndef IHECLBACKEND_HPP
#define IHECLBACKEND_HPP
#include <string>
#include "CHECLLexer.hpp"
class IHECLBackend;
IHECLBackend* NewHECLBackendOutline(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendGLSL(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendHLSL(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendMetal(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendTEV(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendGLSLCafe(const CHECLLexer& lexer);
class IHECLBackend
{
public:
enum Type
{
AUTO = 0,
OUTLINE = 1,
GLSL = 2,
HLSL = 3,
METAL = 4,
TEV = 5,
GLSL_CAFE = 6
};
virtual Type getType() const=0;
virtual bool hasVertexSourceForm() const {return false;}
virtual bool hasFragmentSourceForm() const {return false;}
virtual bool hasVertexBinaryForm() const {return false;}
virtual bool hasFragmentBinaryForm() const {return false;}
virtual bool hasBinaryForm() const {return false;}
virtual std::string* emitNewVertexSource() {return NULL;}
virtual std::string* emitNewFragmentSource() {return NULL;}
virtual void* emitNewVertexBinary(size_t& szOut) {szOut = 0;return NULL;}
virtual void* emitNewFragmentBinary(size_t& szOut) {szOut = 0;return NULL;}
virtual void* emitNewBinary(size_t& szOut) {szOut = 0;return NULL;}
static inline IHECLBackend* NewHECLBackend(Type backendType, const CHECLLexer& lexer)
{
switch (backendType)
{
case AUTO:
#if HW_RVL
return NewHECLBackendTEV(lexer);
#elif HW_CAFE
return NewHECLBackendGLSLCafe(lexer);
#elif _WIN32
return NewHECLBackendHLSL(lexer);
#else
return NewHECLBackendGLSL(lexer);
#endif
case OUTLINE:
return NewHECLBackendOutline(lexer);
case GLSL:
return NewHECLBackendGLSL(lexer);
case HLSL:
return NewHECLBackendHLSL(lexer);
case METAL:
return NewHECLBackendMetal(lexer);
case TEV:
return NewHECLBackendTEV(lexer);
case GLSL_CAFE:
return NewHECLBackendGLSLCafe(lexer);
}
return NULL;
}
};
#endif // IHECLBACKEND_HPP

View File

@@ -8,20 +8,20 @@
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) {fprintf(stderr, "%s\n", error);}

View File

@@ -19,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) */
@@ -51,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)));
@@ -68,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();
@@ -82,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();}
@@ -92,7 +92,7 @@ public:
};
/* Application must specify its interested device-types */
CDeviceFinder(std::unordered_set<std::type_index> types)
DeviceFinder(std::unordered_set<std::type_index> types)
: m_listener(NULL)
{
if (skDevFinder)
@@ -103,7 +103,7 @@ public:
skDevFinder = this;
for (const std::type_index& typeIdx : types)
{
const SDeviceSignature* sigIter = BOO_DEVICE_SIGS;
const DeviceSignature* sigIter = BOO_DEVICE_SIGS;
while (sigIter->m_name)
{
if (sigIter->m_typeIdx == typeIdx)
@@ -112,7 +112,7 @@ public:
}
}
}
~CDeviceFinder()
~DeviceFinder()
{
if (m_listener)
m_listener->stopScanning();
@@ -121,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);}
@@ -154,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 */

View File

@@ -8,29 +8,29 @@
namespace boo
{
class CDeviceToken;
class CDeviceBase;
class DeviceToken;
class DeviceBase;
struct SDeviceSignature
struct DeviceSignature
{
typedef std::vector<const SDeviceSignature*> TDeviceSignatureSet;
typedef std::function<CDeviceBase*(CDeviceToken*)> TFactoryLambda;
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;
SDeviceSignature() : m_name(NULL), m_typeIdx(typeid(SDeviceSignature)) {} /* Sentinel constructor */
SDeviceSignature(const char* name, std::type_index&& typeIdx, unsigned vid, unsigned pid, TFactoryLambda&& 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 CDeviceToken& token, const TDeviceSignatureSet& sigSet);
static CDeviceBase* DeviceNew(CDeviceToken& token);
static bool DeviceMatchToken(const DeviceToken& token, const TDeviceSignatureSet& sigSet);
static DeviceBase* DeviceNew(DeviceToken& token);
};
#define DEVICE_SIG(name, vid, pid) \
SDeviceSignature(#name, typeid(name), vid, pid, [](CDeviceToken* tok) -> CDeviceBase* {return new name(tok);})
#define DEVICE_SIG_SENTINEL() SDeviceSignature()
DeviceSignature(#name, typeid(name), vid, pid, [](DeviceToken* tok) -> DeviceBase* {return new name(tok);})
#define DEVICE_SIG_SENTINEL() DeviceSignature()
extern const SDeviceSignature BOO_DEVICE_SIGS[];
extern const DeviceSignature BOO_DEVICE_SIGS[];
}

View File

@@ -8,7 +8,7 @@
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;}
};

View File

@@ -30,7 +30,7 @@ enum EDolphinControllerButtons
DOL_UP = 1<<15
};
struct SDolphinControllerState
struct DolphinControllerState
{
uint8_t m_leftStick[2];
uint8_t m_rightStick[2];
@@ -43,10 +43,10 @@ struct IDolphinSmashAdapterCallback
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) {(void)idx;(void)type;(void)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;
@@ -57,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;}

View File

@@ -6,11 +6,11 @@
namespace boo
{
class CGenericPad final : public CDeviceBase
class GenericPad final : public DeviceBase
{
public:
CGenericPad(CDeviceToken* token);
~CGenericPad();
GenericPad(DeviceToken* token);
~GenericPad();
void deviceDisconnected();
};

View File

@@ -8,9 +8,9 @@
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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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