Merge branch 'master' of ssh://git.axiodl.com:6431/AxioDL/boo

This commit is contained in:
Jack Andersen 2019-09-30 21:22:52 -10:00
commit 922fcbb3c2
13 changed files with 191 additions and 224 deletions

View File

@ -10,7 +10,7 @@ struct IGraphicsDataFactory;
class IGraphicsContext { class IGraphicsContext {
friend class WindowCocoa; friend class WindowCocoa;
friend class WindowXCB; friend class WindowXCB;
virtual void _setCallback(class IWindowCallback* cb) { (void)cb; } virtual void _setCallback([[maybe_unused]] class IWindowCallback* cb) {}
public: public:
enum class EGraphicsAPI { enum class EGraphicsAPI {

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <array>
#include <memory> #include <memory>
#include <cstring>
#include "boo/System.hpp" #include "boo/System.hpp"
@ -17,36 +17,30 @@ struct IAudioVoiceEngine;
enum class EMouseButton { None = 0, Primary = 1, Secondary = 2, Middle = 3, Aux1 = 4, Aux2 = 5 }; enum class EMouseButton { None = 0, Primary = 1, Secondary = 2, Middle = 3, Aux1 = 4, Aux2 = 5 };
struct SWindowCoord { struct SWindowCoord {
int pixel[2]; std::array<int, 2> pixel;
int virtualPixel[2]; std::array<int, 2> virtualPixel;
float norm[2]; std::array<float, 2> norm;
}; };
struct SWindowRect { struct SWindowRect {
int location[2]; std::array<int, 2> location{};
int size[2]; std::array<int, 2> size{};
SWindowRect() { std::memset(this, 0, sizeof(SWindowRect)); } constexpr SWindowRect() noexcept = default;
constexpr SWindowRect(int x, int y, int w, int h) noexcept : location{x, y}, size{w, h} {}
SWindowRect(int x, int y, int w, int h) { constexpr bool operator==(const SWindowRect& other) const noexcept {
location[0] = x; return location[0] == other.location[0] && location[1] == other.location[1] && size[0] == other.size[0] &&
location[1] = y; size[1] == other.size[1];
size[0] = w;
size[1] = h;
} }
constexpr bool operator!=(const SWindowRect& other) const noexcept { return !operator==(other); }
bool operator!=(const SWindowRect& other) const { constexpr bool coordInRect(const SWindowCoord& coord) const noexcept {
return location[0] != other.location[0] || location[1] != other.location[1] || size[0] != other.size[0] ||
size[1] != other.size[1];
}
bool operator==(const SWindowRect& other) const { return !(*this != other); }
bool coordInRect(const SWindowCoord& coord) const {
return coord.pixel[0] >= location[0] && coord.pixel[0] < location[0] + size[0] && coord.pixel[1] >= location[1] && return coord.pixel[0] >= location[0] && coord.pixel[0] < location[0] + size[0] && coord.pixel[1] >= location[1] &&
coord.pixel[1] < location[1] + size[1]; coord.pixel[1] < location[1] + size[1];
} }
SWindowRect intersect(const SWindowRect& other) const { constexpr SWindowRect intersect(const SWindowRect& other) const noexcept {
if (location[0] < other.location[0] + other.size[0] && location[0] + size[0] > other.location[0] && if (location[0] < other.location[0] + other.size[0] && location[0] + size[0] > other.location[0] &&
location[1] < other.location[1] + other.size[1] && location[1] + size[1] > other.location[1]) { location[1] < other.location[1] + other.size[1] && location[1] + size[1] > other.location[1]) {
SWindowRect ret; SWindowRect ret;
@ -61,15 +55,15 @@ struct SWindowRect {
}; };
struct STouchCoord { struct STouchCoord {
double coord[2]; std::array<double, 2> coord;
}; };
struct SScrollDelta { struct SScrollDelta {
double delta[2] = {}; std::array<double, 2> delta{};
bool isFine = false; /* Use system-scale fine-scroll (for scrollable-trackpads) */ bool isFine = false; /* Use system-scale fine-scroll (for scrollable-trackpads) */
bool isAccelerated = false; /* System performs acceleration computation */ bool isAccelerated = false; /* System performs acceleration computation */
SScrollDelta operator+(const SScrollDelta& other) const { constexpr SScrollDelta operator+(const SScrollDelta& other) const noexcept {
SScrollDelta ret; SScrollDelta ret;
ret.delta[0] = delta[0] + other.delta[0]; ret.delta[0] = delta[0] + other.delta[0];
ret.delta[1] = delta[1] + other.delta[1]; ret.delta[1] = delta[1] + other.delta[1];
@ -77,7 +71,7 @@ struct SScrollDelta {
ret.isAccelerated = isAccelerated || other.isAccelerated; ret.isAccelerated = isAccelerated || other.isAccelerated;
return ret; return ret;
} }
SScrollDelta operator-(const SScrollDelta& other) const { constexpr SScrollDelta operator-(const SScrollDelta& other) const noexcept {
SScrollDelta ret; SScrollDelta ret;
ret.delta[0] = delta[0] - other.delta[0]; ret.delta[0] = delta[0] - other.delta[0];
ret.delta[1] = delta[1] - other.delta[1]; ret.delta[1] = delta[1] - other.delta[1];
@ -85,18 +79,15 @@ struct SScrollDelta {
ret.isAccelerated = isAccelerated || other.isAccelerated; ret.isAccelerated = isAccelerated || other.isAccelerated;
return ret; return ret;
} }
SScrollDelta& operator+=(const SScrollDelta& other) { constexpr SScrollDelta& operator+=(const SScrollDelta& other) noexcept {
delta[0] += other.delta[0]; delta[0] += other.delta[0];
delta[1] += other.delta[1]; delta[1] += other.delta[1];
isFine |= other.isFine; isFine |= other.isFine;
isAccelerated |= other.isAccelerated; isAccelerated |= other.isAccelerated;
return *this; return *this;
} }
void zeroOut() { constexpr void zeroOut() noexcept { delta = {}; }
delta[0] = 0.0; constexpr bool isZero() const noexcept { return delta[0] == 0.0 && delta[1] == 0.0; }
delta[1] = 0.0;
}
bool isZero() const { return delta[0] == 0.0 && delta[1] == 0.0; }
}; };
enum class ESpecialKey { enum class ESpecialKey {
@ -155,67 +146,34 @@ struct ITextInputCallback {
class IWindowCallback { class IWindowCallback {
public: public:
virtual void resized(const SWindowRect& rect, bool sync) { (void)rect; } virtual void resized([[maybe_unused]] const SWindowRect& rect, [[maybe_unused]] bool sync) {}
virtual void mouseDown(const SWindowCoord& coord, EMouseButton button, EModifierKey mods) { virtual void mouseDown([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button,
(void)coord; [[maybe_unused]] EModifierKey mods) {}
(void)button; virtual void mouseUp([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button,
(void)mods; [[maybe_unused]] EModifierKey mods) {}
} virtual void mouseMove([[maybe_unused]] const SWindowCoord& coord) {}
virtual void mouseUp(const SWindowCoord& coord, EMouseButton button, EModifierKey mods) { virtual void mouseEnter([[maybe_unused]] const SWindowCoord& coord) {}
(void)coord; virtual void mouseLeave([[maybe_unused]] const SWindowCoord& coord) {}
(void)button; virtual void scroll([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] const SScrollDelta& scroll) {}
(void)mods;
}
virtual void mouseMove(const SWindowCoord& coord) { (void)coord; }
virtual void mouseEnter(const SWindowCoord& coord) { (void)coord; }
virtual void mouseLeave(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) { virtual void touchDown([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) {}
(void)coord; virtual void touchUp([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) {}
(void)tid; virtual void touchMove([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t 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) { virtual void charKeyDown([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods,
(void)charCode; [[maybe_unused]] bool isRepeat) {}
(void)mods; virtual void charKeyUp([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods) {}
(void)isRepeat; virtual void specialKeyDown([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods,
} [[maybe_unused]] bool isRepeat) {}
virtual void charKeyUp(unsigned long charCode, EModifierKey mods) { virtual void specialKeyUp([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods) {}
(void)charCode; virtual void modKeyDown([[maybe_unused]] EModifierKey mod, [[maybe_unused]] bool isRepeat) {}
(void)mods; virtual void modKeyUp([[maybe_unused]] EModifierKey mod) {}
}
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; }
virtual ITextInputCallback* getTextInputCallback() { return nullptr; } virtual ITextInputCallback* getTextInputCallback() { return nullptr; }
virtual void focusLost() {} virtual void focusLost() {}
virtual void focusGained() {} virtual void focusGained() {}
virtual void windowMoved(const SWindowRect& rect) { (void)rect; } virtual void windowMoved([[maybe_unused]] const SWindowRect& rect) {}
virtual void destroyed() {} virtual void destroyed() {}
}; };
@ -278,10 +236,7 @@ public:
virtual int waitForRetrace() = 0; virtual int waitForRetrace() = 0;
virtual uintptr_t getPlatformHandle() const = 0; virtual uintptr_t getPlatformHandle() const = 0;
virtual bool _incomingEvent(void* event) { virtual bool _incomingEvent([[maybe_unused]] void* event) { return false; }
(void)event;
return false;
}
virtual void _cleanup() {} virtual void _cleanup() {}
virtual ETouchType getTouchType() const = 0; virtual ETouchType getTouchType() const = 0;
@ -289,7 +244,7 @@ public:
virtual void setStyle(EWindowStyle style) = 0; virtual void setStyle(EWindowStyle style) = 0;
virtual EWindowStyle getStyle() const = 0; virtual EWindowStyle getStyle() const = 0;
virtual void setTouchBarProvider(void*) {} virtual void setTouchBarProvider([[maybe_unused]] void* provider) {}
virtual IGraphicsCommandQueue* getCommandQueue() = 0; virtual IGraphicsCommandQueue* getCommandQueue() = 0;
virtual IGraphicsDataFactory* getDataFactory() = 0; virtual IGraphicsDataFactory* getDataFactory() = 0;

View File

@ -29,35 +29,34 @@ static inline ComPtr<T>* ReferenceComPtr(ComPtr<T>& ptr) {
#ifndef ENABLE_BITWISE_ENUM #ifndef ENABLE_BITWISE_ENUM
#define ENABLE_BITWISE_ENUM(type) \ #define ENABLE_BITWISE_ENUM(type) \
constexpr type operator|(type a, type b) { \ constexpr type operator|(type a, type b) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) | static_cast<T>(b)); \ return type(static_cast<T>(a) | static_cast<T>(b)); \
} \ } \
constexpr type operator&(type a, type b) { \ constexpr type operator&(type a, type b) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) & static_cast<T>(b)); \ return type(static_cast<T>(a) & static_cast<T>(b)); \
} \ } \
constexpr type& operator|=(type& a, type b) { \ constexpr type& operator|=(type& a, type b) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) | static_cast<T>(b)); \ a = type(static_cast<T>(a) | static_cast<T>(b)); \
return a; \ return a; \
} \ } \
constexpr type& operator&=(type& a, type b) { \ constexpr type& operator&=(type& a, type b) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) & static_cast<T>(b)); \ a = type(static_cast<T>(a) & static_cast<T>(b)); \
return a; \ return a; \
} \ } \
constexpr type operator~(type key) { \ constexpr type operator~(type key) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
return type(~static_cast<T>(key)); \ return type(~static_cast<T>(key)); \
} \ } \
constexpr bool True(type key) { \ constexpr bool True(type key) noexcept { \
using T = std::underlying_type_t<type>; \ using T = std::underlying_type_t<type>; \
return static_cast<T>(key) != 0; \ return static_cast<T>(key) != 0; \
} \ } \
constexpr bool False(type key) { \ constexpr bool False(type key) noexcept { \
using T = std::underlying_type_t<type>; \ return !True(key); \
return static_cast<T>(key) == 0; \
} }
#endif #endif

View File

@ -85,8 +85,8 @@ struct VulkanContext {
#if _WIN32 #if _WIN32
HWND m_hwnd = 0; HWND m_hwnd = 0;
bool m_fs = false; bool m_fs = false;
LONG m_fsStyle; LONG_PTR m_fsStyle;
LONG m_fsExStyle; LONG_PTR m_fsExStyle;
RECT m_fsRect; RECT m_fsRect;
int m_fsCountDown = 0; int m_fsCountDown = 0;
#endif #endif

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <array>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include "boo/System.hpp" #include "boo/System.hpp"
@ -31,42 +33,33 @@ enum class EDolphinControllerButtons {
ENABLE_BITWISE_ENUM(EDolphinControllerButtons) ENABLE_BITWISE_ENUM(EDolphinControllerButtons)
struct DolphinControllerState { struct DolphinControllerState {
int16_t m_leftStick[2] = {0}; std::array<int16_t, 2> m_leftStick{};
int16_t m_rightStick[2] = {0}; std::array<int16_t, 2> m_rightStick{};
int16_t m_analogTriggers[2] = {0}; std::array<int16_t, 2> m_analogTriggers{};
uint16_t m_btns = 0; uint16_t m_btns = 0;
void reset() { void reset() {
m_leftStick[0] = 0; m_leftStick = {};
m_leftStick[1] = 0; m_rightStick = {};
m_rightStick[0] = 0; m_analogTriggers = {};
m_rightStick[1] = 0;
m_analogTriggers[0] = 0;
m_analogTriggers[1] = 0;
m_btns = 0; m_btns = 0;
} }
void clamp(); void clamp();
}; };
struct IDolphinSmashAdapterCallback { struct IDolphinSmashAdapterCallback {
virtual void controllerConnected(unsigned idx, EDolphinControllerType type) { virtual void controllerConnected([[maybe_unused]] unsigned idx, [[maybe_unused]] EDolphinControllerType type) {}
(void)idx; virtual void controllerDisconnected([[maybe_unused]] unsigned idx) {}
(void)type; virtual void controllerUpdate([[maybe_unused]] unsigned idx, [[maybe_unused]] EDolphinControllerType type,
} [[maybe_unused]] const DolphinControllerState& state) {}
virtual void controllerDisconnected(unsigned idx) { (void)idx; }
virtual void controllerUpdate(unsigned idx, EDolphinControllerType type, const DolphinControllerState& state) {
(void)idx;
(void)type;
(void)state;
}
}; };
class DolphinSmashAdapter final : public TDeviceBase<IDolphinSmashAdapterCallback> { class DolphinSmashAdapter final : public TDeviceBase<IDolphinSmashAdapterCallback> {
int16_t m_leftStickCal[2] = {0x7f}; std::array<int16_t, 2> m_leftStickCal{0x7f, 0};
int16_t m_rightStickCal[2] = {0x7f}; std::array<int16_t, 2> m_rightStickCal{0x7f, 0};
int16_t m_triggersCal[2] = {0x0}; std::array<int16_t, 2> m_triggersCal{};
uint8_t m_knownControllers = 0; uint8_t m_knownControllers = 0;
uint8_t m_rumbleRequest = 0; uint8_t m_rumbleRequest = 0;
bool m_hardStop[4] = {false}; std::array<bool, 4> m_hardStop{};
uint8_t m_rumbleState = 0xf; /* Force initial send of stop-rumble command */ uint8_t m_rumbleState = 0xf; /* Force initial send of stop-rumble command */
void deviceDisconnected() override; void deviceDisconnected() override;
void initialCycle() override; void initialCycle() override;
@ -81,15 +74,21 @@ public:
TDeviceBase<IDolphinSmashAdapterCallback>::setCallback(cb); TDeviceBase<IDolphinSmashAdapterCallback>::setCallback(cb);
m_knownControllers = 0; m_knownControllers = 0;
} }
void startRumble(unsigned idx) {
if (idx >= 4) void startRumble(size_t idx) {
if (idx >= m_hardStop.size()) {
return; return;
m_rumbleRequest |= 1 << idx; }
m_rumbleRequest |= 1U << idx;
} }
void stopRumble(unsigned idx, bool hard = false) {
if (idx >= 4) void stopRumble(size_t idx, bool hard = false) {
if (idx >= m_hardStop.size()) {
return; return;
m_rumbleRequest &= ~(1 << idx); }
m_rumbleRequest &= ~(1U << idx);
m_hardStop[idx] = hard; m_hardStop[idx] = hard;
} }
}; };

View File

@ -34,7 +34,7 @@ struct INintendoPowerACallback {
}; };
class NintendoPowerA final : public TDeviceBase<INintendoPowerACallback> { class NintendoPowerA final : public TDeviceBase<INintendoPowerACallback> {
NintendoPowerAState m_last; NintendoPowerAState m_last{};
void deviceDisconnected() override; void deviceDisconnected() override;
void initialCycle() override; void initialCycle() override;
void transferCycle() override; void transferCycle() override;
@ -42,7 +42,7 @@ class NintendoPowerA final : public TDeviceBase<INintendoPowerACallback> {
void receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) override; void receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) override;
public: public:
NintendoPowerA(DeviceToken*); explicit NintendoPowerA(DeviceToken*);
~NintendoPowerA() override; ~NintendoPowerA() override;
}; };
} // namespace boo } // namespace boo

View File

@ -1,9 +1,6 @@
#include "boo/inputdev/DolphinSmashAdapter.hpp" #include "boo/inputdev/DolphinSmashAdapter.hpp"
#include "boo/inputdev/DeviceSignature.hpp" #include "boo/inputdev/DeviceSignature.hpp"
#include <cstdio>
#include <cstring>
namespace boo { namespace boo {
/* /*
* Reference: https://github.com/ToadKing/wii-u-gc-adapter/blob/master/wii-u-gc-adapter.c * Reference: https://github.com/ToadKing/wii-u-gc-adapter/blob/master/wii-u-gc-adapter.c
@ -14,9 +11,10 @@ DolphinSmashAdapter::DolphinSmashAdapter(DeviceToken* token)
DolphinSmashAdapter::~DolphinSmashAdapter() {} DolphinSmashAdapter::~DolphinSmashAdapter() {}
constexpr EDolphinControllerType parseType(unsigned char status) { static constexpr EDolphinControllerType parseType(unsigned char status) {
EDolphinControllerType type = const auto type =
EDolphinControllerType(status) & (EDolphinControllerType::Normal | EDolphinControllerType::Wavebird); EDolphinControllerType(status) & (EDolphinControllerType::Normal | EDolphinControllerType::Wavebird);
switch (type) { switch (type) {
case EDolphinControllerType::Normal: case EDolphinControllerType::Normal:
case EDolphinControllerType::Wavebird: case EDolphinControllerType::Wavebird:
@ -26,13 +24,13 @@ constexpr EDolphinControllerType parseType(unsigned char status) {
} }
} }
static EDolphinControllerType parseState(DolphinControllerState* stateOut, uint8_t* payload, bool& rumble) { static EDolphinControllerType parseState(DolphinControllerState* stateOut, const uint8_t* payload, bool& rumble) {
unsigned char status = payload[0]; const unsigned char status = payload[0];
EDolphinControllerType type = parseType(status); const EDolphinControllerType type = parseType(status);
rumble = ((status & 0x04) != 0) ? true : false; rumble = ((status & 0x04) != 0) ? true : false;
stateOut->m_btns = (uint16_t)payload[1] << 8 | (uint16_t)payload[2]; stateOut->m_btns = static_cast<uint16_t>(payload[1]) << 8 | static_cast<uint16_t>(payload[2]);
stateOut->m_leftStick[0] = payload[3]; stateOut->m_leftStick[0] = payload[3];
stateOut->m_leftStick[1] = payload[4]; stateOut->m_leftStick[1] = payload[4];
@ -45,43 +43,44 @@ static EDolphinControllerType parseState(DolphinControllerState* stateOut, uint8
} }
void DolphinSmashAdapter::initialCycle() { void DolphinSmashAdapter::initialCycle() {
uint8_t handshakePayload[] = {0x13}; constexpr std::array<uint8_t, 1> handshakePayload{0x13};
sendUSBInterruptTransfer(handshakePayload, sizeof(handshakePayload)); sendUSBInterruptTransfer(handshakePayload.data(), handshakePayload.size());
} }
void DolphinSmashAdapter::transferCycle() { void DolphinSmashAdapter::transferCycle() {
uint8_t payload[37]; std::array<uint8_t, 37> payload;
size_t recvSz = receiveUSBInterruptTransfer(payload, sizeof(payload)); const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size());
if (recvSz != 37 || payload[0] != 0x21) if (recvSz != payload.size() || payload[0] != 0x21) {
return; return;
}
// fmt::print("RECEIVED DATA {} {:02X}\n", recvSz, payload[0]); // fmt::print("RECEIVED DATA {} {:02X}\n", recvSz, payload[0]);
std::lock_guard<std::mutex> lk(m_callbackLock); std::lock_guard<std::mutex> lk(m_callbackLock);
if (!m_callback) if (!m_callback) {
return; return;
}
/* Parse controller states */ /* Parse controller states */
uint8_t* controller = &payload[1]; const uint8_t* controller = &payload[1];
uint8_t rumbleMask = 0; uint8_t rumbleMask = 0;
for (uint32_t i = 0; i < 4; i++, controller += 9) { for (uint32_t i = 0; i < 4; i++, controller += 9) {
DolphinControllerState state; DolphinControllerState state;
bool rumble = false; bool rumble = false;
EDolphinControllerType type = parseState(&state, controller, rumble); const EDolphinControllerType type = parseState(&state, controller, rumble);
if (True(type) && !(m_knownControllers & 1 << i)) {
m_leftStickCal[0] = state.m_leftStick[0]; if (True(type) && (m_knownControllers & (1U << i)) == 0) {
m_leftStickCal[1] = state.m_leftStick[1]; m_leftStickCal = state.m_leftStick;
m_rightStickCal[0] = state.m_rightStick[0]; m_rightStickCal = state.m_rightStick;
m_rightStickCal[1] = state.m_rightStick[1]; m_triggersCal = state.m_analogTriggers;
m_triggersCal[0] = state.m_analogTriggers[0]; m_knownControllers |= 1U << i;
m_triggersCal[1] = state.m_analogTriggers[1];
m_knownControllers |= 1 << i;
m_callback->controllerConnected(i, type); m_callback->controllerConnected(i, type);
} else if (False(type) && (m_knownControllers & 1 << i)) { } else if (False(type) && (m_knownControllers & (1U << i)) != 0) {
m_knownControllers &= ~(1 << i); m_knownControllers &= ~(1U << i);
m_callback->controllerDisconnected(i); m_callback->controllerDisconnected(i);
} }
if (m_knownControllers & 1 << i) {
if ((m_knownControllers & (1U << i)) != 0) {
state.m_leftStick[0] = state.m_leftStick[0] - m_leftStickCal[0]; state.m_leftStick[0] = state.m_leftStick[0] - m_leftStickCal[0];
state.m_leftStick[1] = state.m_leftStick[1] - m_leftStickCal[1]; state.m_leftStick[1] = state.m_leftStick[1] - m_leftStickCal[1];
state.m_rightStick[0] = state.m_rightStick[0] - m_rightStickCal[0]; state.m_rightStick[0] = state.m_rightStick[0] - m_rightStickCal[0];
@ -90,39 +89,42 @@ void DolphinSmashAdapter::transferCycle() {
state.m_analogTriggers[1] = state.m_analogTriggers[1] - m_triggersCal[1]; state.m_analogTriggers[1] = state.m_analogTriggers[1] - m_triggersCal[1];
m_callback->controllerUpdate(i, type, state); m_callback->controllerUpdate(i, type, state);
} }
rumbleMask |= rumble ? 1 << i : 0;
rumbleMask |= rumble ? 1U << i : 0;
} }
/* Send rumble message (if needed) */ /* Send rumble message (if needed) */
uint8_t rumbleReq = m_rumbleRequest & rumbleMask; const uint8_t rumbleReq = m_rumbleRequest & rumbleMask;
if (rumbleReq != m_rumbleState) { if (rumbleReq != m_rumbleState) {
uint8_t rumbleMessage[5] = {0x11}; std::array<uint8_t, 5> rumbleMessage{0x11, 0, 0, 0, 0};
for (int i = 0; i < 4; ++i) { for (size_t i = 0; i < 4; ++i) {
if (rumbleReq & 1 << i) if ((rumbleReq & (1U << i)) != 0) {
rumbleMessage[i + 1] = 1; rumbleMessage[i + 1] = 1;
else if (m_hardStop[i]) } else if (m_hardStop[i]) {
rumbleMessage[i + 1] = 2; rumbleMessage[i + 1] = 2;
else } else {
rumbleMessage[i + 1] = 0; rumbleMessage[i + 1] = 0;
}
} }
sendUSBInterruptTransfer(rumbleMessage, sizeof(rumbleMessage)); sendUSBInterruptTransfer(rumbleMessage.data(), rumbleMessage.size());
m_rumbleState = rumbleReq; m_rumbleState = rumbleReq;
} }
} }
void DolphinSmashAdapter::finalCycle() { void DolphinSmashAdapter::finalCycle() {
uint8_t rumbleMessage[5] = {0x11, 0, 0, 0, 0}; constexpr std::array<uint8_t, 5> rumbleMessage{0x11, 0, 0, 0, 0};
sendUSBInterruptTransfer(rumbleMessage, sizeof(rumbleMessage)); sendUSBInterruptTransfer(rumbleMessage.data(), sizeof(rumbleMessage));
} }
void DolphinSmashAdapter::deviceDisconnected() { void DolphinSmashAdapter::deviceDisconnected() {
for (uint32_t i = 0; i < 4; i++) { for (uint32_t i = 0; i < 4; i++) {
if (m_knownControllers & 1 << i) { if ((m_knownControllers & (1U << i)) != 0) {
m_knownControllers &= ~(1 << i); m_knownControllers &= ~(1U << i);
std::lock_guard<std::mutex> lk(m_callbackLock); std::lock_guard<std::mutex> lk(m_callbackLock);
if (m_callback) if (m_callback) {
m_callback->controllerDisconnected(i); m_callback->controllerDisconnected(i);
}
} }
} }
} }
@ -151,15 +153,15 @@ void DolphinSmashAdapter::deviceDisconnected() {
* distribution. * distribution.
*/ */
static int16_t pad_clampregion[8] = {30, 180, 15, 72, 40, 15, 59, 31}; constexpr std::array<int16_t, 8> pad_clampregion{
30, 180, 15, 72, 40, 15, 59, 31,
};
static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, int16_t min) { static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, int16_t min) {
int x = px; int x = px;
int y = py; int y = py;
int signX;
int signY;
int d;
int signX;
if (x > 0) { if (x > 0) {
signX = 1; signX = 1;
} else { } else {
@ -167,6 +169,7 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
x = -x; x = -x;
} }
int signY;
if (y > 0) { if (y > 0) {
signY = 1; signY = 1;
} else { } else {
@ -174,10 +177,11 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
y = -y; y = -y;
} }
if (x <= min) if (x <= min) {
x = 0; x = 0;
else } else {
x -= min; x -= min;
}
if (y <= min) { if (y <= min) {
y = 0; y = 0;
@ -191,13 +195,13 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
} }
if (xy * y <= xy * x) { if (xy * y <= xy * x) {
d = xy * x + (max - xy) * y; const int d = xy * x + (max - xy) * y;
if (xy * max < d) { if (xy * max < d) {
x = int16_t(xy * max * x / d); x = int16_t(xy * max * x / d);
y = int16_t(xy * max * y / d); y = int16_t(xy * max * y / d);
} }
} else { } else {
d = xy * y + (max - xy) * x; const int d = xy * y + (max - xy) * x;
if (xy * max < d) { if (xy * max < d) {
x = int16_t(xy * max * x / d); x = int16_t(xy * max * x / d);
y = int16_t(xy * max * y / d); y = int16_t(xy * max * y / d);
@ -209,15 +213,15 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
} }
static void pad_clamptrigger(int16_t& trigger) { static void pad_clamptrigger(int16_t& trigger) {
int16_t min, max; const int16_t min = pad_clampregion[0];
const int16_t max = pad_clampregion[1];
min = pad_clampregion[0]; if (min > trigger) {
max = pad_clampregion[1];
if (min > trigger)
trigger = 0; trigger = 0;
else { } else {
if (max < trigger) if (max < trigger) {
trigger = max; trigger = max;
}
trigger -= min; trigger -= min;
} }
} }

View File

@ -1,5 +1,6 @@
#include "boo/inputdev/NintendoPowerA.hpp" #include "boo/inputdev/NintendoPowerA.hpp"
#include <array>
#include <cstring> #include <cstring>
#include "boo/inputdev/DeviceSignature.hpp" #include "boo/inputdev/DeviceSignature.hpp"
@ -8,27 +9,31 @@ namespace boo {
NintendoPowerA::NintendoPowerA(DeviceToken* token) NintendoPowerA::NintendoPowerA(DeviceToken* token)
: TDeviceBase<INintendoPowerACallback>(dev_typeid(NintendoPowerA), token) {} : TDeviceBase<INintendoPowerACallback>(dev_typeid(NintendoPowerA), token) {}
NintendoPowerA::~NintendoPowerA() {} NintendoPowerA::~NintendoPowerA() = default;
void NintendoPowerA::deviceDisconnected() { void NintendoPowerA::deviceDisconnected() {
std::lock_guard<std::mutex> lk(m_callbackLock); std::lock_guard lk{m_callbackLock};
if (m_callback) if (m_callback != nullptr) {
m_callback->controllerDisconnected(); m_callback->controllerDisconnected();
}
} }
void NintendoPowerA::initialCycle() {} void NintendoPowerA::initialCycle() {}
void NintendoPowerA::transferCycle() { void NintendoPowerA::transferCycle() {
uint8_t payload[8]; std::array<uint8_t, 8> payload;
size_t recvSz = receiveUSBInterruptTransfer(payload, sizeof(payload)); const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size());
if (recvSz != 8) if (recvSz != payload.size()) {
return; return;
}
NintendoPowerAState state = *reinterpret_cast<NintendoPowerAState*>(&payload); NintendoPowerAState state;
std::memcpy(&state, payload.data(), sizeof(state));
std::lock_guard<std::mutex> lk(m_callbackLock); std::lock_guard lk{m_callbackLock};
if (state != m_last && m_callback) if (state != m_last && m_callback != nullptr) {
m_callback->controllerUpdate(state); m_callback->controllerUpdate(state);
}
m_last = state; m_last = state;
} }
@ -37,7 +42,7 @@ void NintendoPowerA::finalCycle() {}
void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {} void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {}
bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const { bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const {
return memcmp(this, &other, sizeof(NintendoPowerAState)) == 0; return std::memcmp(this, &other, sizeof(NintendoPowerAState)) == 0;
} }
bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); } bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); }

View File

@ -89,10 +89,7 @@ public:
void waitForRetrace() override {} void waitForRetrace() override {}
uintptr_t getPlatformHandle() const override { return 0; } uintptr_t getPlatformHandle() const override { return 0; }
bool _incomingEvent(void* event) override { bool _incomingEvent([[maybe_unused]] void* event) override { return false; }
(void)event;
return false;
}
void _cleanup() override {} void _cleanup() override {}
ETouchType getTouchType() const override { return ETouchType::Display; } ETouchType getTouchType() const override { return ETouchType::Display; }

View File

@ -339,9 +339,10 @@ public:
win.m_fsExStyle = GetWindowLong(win.m_hwnd, GWL_EXSTYLE); win.m_fsExStyle = GetWindowLong(win.m_hwnd, GWL_EXSTYLE);
GetWindowRect(win.m_hwnd, &win.m_fsRect); GetWindowRect(win.m_hwnd, &win.m_fsRect);
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME)); SetWindowLongPtr(win.m_hwnd, GWL_STYLE, win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME));
SetWindowLong(win.m_hwnd, GWL_EXSTYLE, SetWindowLongPtr(win.m_hwnd, GWL_EXSTYLE,
win.m_fsExStyle & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); win.m_fsExStyle &
~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
MONITORINFO monitor_info; MONITORINFO monitor_info;
monitor_info.cbSize = sizeof(monitor_info); monitor_info.cbSize = sizeof(monitor_info);
@ -353,8 +354,8 @@ public:
win.m_fs = true; win.m_fs = true;
} else { } else {
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle); SetWindowLongPtr(win.m_hwnd, GWL_STYLE, win.m_fsStyle);
SetWindowLong(win.m_hwnd, GWL_EXSTYLE, win.m_fsExStyle); SetWindowLongPtr(win.m_hwnd, GWL_EXSTYLE, win.m_fsExStyle);
SetWindowPos(win.m_hwnd, nullptr, win.m_fsRect.left, win.m_fsRect.top, win.m_fsRect.right - win.m_fsRect.left, SetWindowPos(win.m_hwnd, nullptr, win.m_fsRect.left, win.m_fsRect.top, win.m_fsRect.right - win.m_fsRect.left,
win.m_fsRect.bottom - win.m_fsRect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); win.m_fsRect.bottom - win.m_fsRect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);

View File

@ -39,8 +39,8 @@ struct OGLContext {
size_t width, height; size_t width, height;
bool m_fs = false; bool m_fs = false;
LONG m_fsStyle; LONG_PTR m_fsStyle;
LONG m_fsExStyle; LONG_PTR m_fsExStyle;
RECT m_fsRect; RECT m_fsRect;
int m_fsCountDown = 0; int m_fsCountDown = 0;
}; };

View File

@ -859,18 +859,17 @@ public:
m_hwnd = CreateWindowW(L"BooWindow", title.data(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left, m_hwnd = CreateWindowW(L"BooWindow", title.data(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left,
r.bottom - r.top, nullptr, nullptr, nullptr, nullptr); r.bottom - r.top, nullptr, nullptr, nullptr, nullptr);
HINSTANCE wndInstance = HINSTANCE(GetWindowLongPtr(m_hwnd, GWLP_HINSTANCE));
m_imc = ImmGetContext(m_hwnd); m_imc = ImmGetContext(m_hwnd);
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
HINSTANCE wndInstance = HINSTANCE(GetWindowLongPtr(m_hwnd, GWLP_HINSTANCE));
if (b3dCtx.m_vulkanDxFactory) { if (b3dCtx.m_vulkanDxFactory) {
m_gfxCtx.reset(new GraphicsContextWin32Vulkan(this, wndInstance, m_hwnd, &g_VulkanContext, b3dCtx)); m_gfxCtx.reset(new GraphicsContextWin32Vulkan(this, wndInstance, m_hwnd, &g_VulkanContext, b3dCtx));
if (m_gfxCtx->initializeContext(nullptr)) if (m_gfxCtx->initializeContext(nullptr))
return; return;
} }
#else
(void)wndInstance;
#endif #endif
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11; IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
if (b3dCtx.m_ctxOgl.m_dxFactory) { if (b3dCtx.m_ctxOgl.m_dxFactory) {
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx)); m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx));
@ -1300,35 +1299,43 @@ public:
ETouchType getTouchType() const override { return ETouchType::None; } ETouchType getTouchType() const override { return ETouchType::None; }
void setStyle(EWindowStyle style) override { void setStyle(EWindowStyle style) override {
LONG sty = GetWindowLong(m_hwnd, GWL_STYLE); LONG_PTR sty = GetWindowLongPtr(m_hwnd, GWL_STYLE);
if ((style & EWindowStyle::Titlebar) != EWindowStyle::None) if ((style & EWindowStyle::Titlebar) != EWindowStyle::None) {
sty |= WS_CAPTION; sty |= WS_CAPTION;
else } else {
sty &= ~WS_CAPTION; sty &= ~WS_CAPTION;
}
if ((style & EWindowStyle::Resize) != EWindowStyle::None) if ((style & EWindowStyle::Resize) != EWindowStyle::None) {
sty |= WS_THICKFRAME; sty |= WS_THICKFRAME;
else } else {
sty &= ~WS_THICKFRAME; sty &= ~WS_THICKFRAME;
}
if ((style & EWindowStyle::Close) != EWindowStyle::None) if ((style & EWindowStyle::Close) != EWindowStyle::None) {
sty |= (WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); sty |= (WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
else } else {
sty &= ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); sty &= ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
}
SetWindowLong(m_hwnd, GWL_STYLE, sty); SetWindowLongPtr(m_hwnd, GWL_STYLE, sty);
} }
EWindowStyle getStyle() const override { EWindowStyle getStyle() const override {
LONG sty = GetWindowLong(m_hwnd, GWL_STYLE); const LONG_PTR sty = GetWindowLongPtr(m_hwnd, GWL_STYLE);
EWindowStyle retval = EWindowStyle::None; EWindowStyle retval = EWindowStyle::None;
if ((sty & WS_CAPTION) != 0) if ((sty & WS_CAPTION) != 0) {
retval |= EWindowStyle::Titlebar; retval |= EWindowStyle::Titlebar;
if ((sty & WS_THICKFRAME) != 0) }
if ((sty & WS_THICKFRAME) != 0) {
retval |= EWindowStyle::Resize; retval |= EWindowStyle::Resize;
if ((sty & WS_SYSMENU)) }
if ((sty & WS_SYSMENU)) {
retval |= EWindowStyle::Close; retval |= EWindowStyle::Close;
}
return retval; return retval;
} }

View File

@ -19,7 +19,7 @@ class ApplicationWayland final : public IApplication {
const std::vector<std::string> m_args; const std::vector<std::string> m_args;
bool m_singleInstance; bool m_singleInstance;
void _deletedWindow(IWindow* window) override { (void)window; } void _deletedWindow([[maybe_unused]] IWindow* window) override {}
public: public:
ApplicationWayland(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName, ApplicationWayland(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,