mirror of https://github.com/AxioDL/boo.git
Merge branch 'master' of ssh://git.axiodl.com:6431/AxioDL/boo
This commit is contained in:
commit
922fcbb3c2
|
@ -10,7 +10,7 @@ struct IGraphicsDataFactory;
|
|||
class IGraphicsContext {
|
||||
friend class WindowCocoa;
|
||||
friend class WindowXCB;
|
||||
virtual void _setCallback(class IWindowCallback* cb) { (void)cb; }
|
||||
virtual void _setCallback([[maybe_unused]] class IWindowCallback* cb) {}
|
||||
|
||||
public:
|
||||
enum class EGraphicsAPI {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
#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 };
|
||||
|
||||
struct SWindowCoord {
|
||||
int pixel[2];
|
||||
int virtualPixel[2];
|
||||
float norm[2];
|
||||
std::array<int, 2> pixel;
|
||||
std::array<int, 2> virtualPixel;
|
||||
std::array<float, 2> norm;
|
||||
};
|
||||
|
||||
struct SWindowRect {
|
||||
int location[2];
|
||||
int size[2];
|
||||
std::array<int, 2> location{};
|
||||
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) {
|
||||
location[0] = x;
|
||||
location[1] = y;
|
||||
size[0] = w;
|
||||
size[1] = h;
|
||||
constexpr bool operator==(const SWindowRect& other) const noexcept {
|
||||
return location[0] == other.location[0] && location[1] == other.location[1] && size[0] == other.size[0] &&
|
||||
size[1] == other.size[1];
|
||||
}
|
||||
constexpr bool operator!=(const SWindowRect& other) const noexcept { return !operator==(other); }
|
||||
|
||||
bool operator!=(const SWindowRect& other) const {
|
||||
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 {
|
||||
constexpr bool coordInRect(const SWindowCoord& coord) const noexcept {
|
||||
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];
|
||||
}
|
||||
|
||||
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] &&
|
||||
location[1] < other.location[1] + other.size[1] && location[1] + size[1] > other.location[1]) {
|
||||
SWindowRect ret;
|
||||
|
@ -61,15 +55,15 @@ struct SWindowRect {
|
|||
};
|
||||
|
||||
struct STouchCoord {
|
||||
double coord[2];
|
||||
std::array<double, 2> coord;
|
||||
};
|
||||
|
||||
struct SScrollDelta {
|
||||
double delta[2] = {};
|
||||
std::array<double, 2> delta{};
|
||||
bool isFine = false; /* Use system-scale fine-scroll (for scrollable-trackpads) */
|
||||
bool isAccelerated = false; /* System performs acceleration computation */
|
||||
|
||||
SScrollDelta operator+(const SScrollDelta& other) const {
|
||||
constexpr SScrollDelta operator+(const SScrollDelta& other) const noexcept {
|
||||
SScrollDelta ret;
|
||||
ret.delta[0] = delta[0] + other.delta[0];
|
||||
ret.delta[1] = delta[1] + other.delta[1];
|
||||
|
@ -77,7 +71,7 @@ struct SScrollDelta {
|
|||
ret.isAccelerated = isAccelerated || other.isAccelerated;
|
||||
return ret;
|
||||
}
|
||||
SScrollDelta operator-(const SScrollDelta& other) const {
|
||||
constexpr SScrollDelta operator-(const SScrollDelta& other) const noexcept {
|
||||
SScrollDelta ret;
|
||||
ret.delta[0] = delta[0] - other.delta[0];
|
||||
ret.delta[1] = delta[1] - other.delta[1];
|
||||
|
@ -85,18 +79,15 @@ struct SScrollDelta {
|
|||
ret.isAccelerated = isAccelerated || other.isAccelerated;
|
||||
return ret;
|
||||
}
|
||||
SScrollDelta& operator+=(const SScrollDelta& other) {
|
||||
constexpr SScrollDelta& operator+=(const SScrollDelta& other) noexcept {
|
||||
delta[0] += other.delta[0];
|
||||
delta[1] += other.delta[1];
|
||||
isFine |= other.isFine;
|
||||
isAccelerated |= other.isAccelerated;
|
||||
return *this;
|
||||
}
|
||||
void zeroOut() {
|
||||
delta[0] = 0.0;
|
||||
delta[1] = 0.0;
|
||||
}
|
||||
bool isZero() const { return delta[0] == 0.0 && delta[1] == 0.0; }
|
||||
constexpr void zeroOut() noexcept { delta = {}; }
|
||||
constexpr bool isZero() const noexcept { return delta[0] == 0.0 && delta[1] == 0.0; }
|
||||
};
|
||||
|
||||
enum class ESpecialKey {
|
||||
|
@ -155,67 +146,34 @@ struct ITextInputCallback {
|
|||
|
||||
class IWindowCallback {
|
||||
public:
|
||||
virtual void resized(const SWindowRect& rect, bool sync) { (void)rect; }
|
||||
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 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 resized([[maybe_unused]] const SWindowRect& rect, [[maybe_unused]] bool sync) {}
|
||||
virtual void mouseDown([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button,
|
||||
[[maybe_unused]] EModifierKey mods) {}
|
||||
virtual void mouseUp([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button,
|
||||
[[maybe_unused]] EModifierKey mods) {}
|
||||
virtual void mouseMove([[maybe_unused]] const SWindowCoord& coord) {}
|
||||
virtual void mouseEnter([[maybe_unused]] const SWindowCoord& coord) {}
|
||||
virtual void mouseLeave([[maybe_unused]] const SWindowCoord& coord) {}
|
||||
virtual void scroll([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] const SScrollDelta& 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 touchDown([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) {}
|
||||
virtual void touchUp([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t tid) {}
|
||||
virtual void touchMove([[maybe_unused]] const STouchCoord& coord, [[maybe_unused]] uintptr_t 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; }
|
||||
virtual void charKeyDown([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods,
|
||||
[[maybe_unused]] bool isRepeat) {}
|
||||
virtual void charKeyUp([[maybe_unused]] unsigned long charCode, [[maybe_unused]] EModifierKey mods) {}
|
||||
virtual void specialKeyDown([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods,
|
||||
[[maybe_unused]] bool isRepeat) {}
|
||||
virtual void specialKeyUp([[maybe_unused]] ESpecialKey key, [[maybe_unused]] EModifierKey mods) {}
|
||||
virtual void modKeyDown([[maybe_unused]] EModifierKey mod, [[maybe_unused]] bool isRepeat) {}
|
||||
virtual void modKeyUp([[maybe_unused]] EModifierKey mod) {}
|
||||
|
||||
virtual ITextInputCallback* getTextInputCallback() { return nullptr; }
|
||||
|
||||
virtual void focusLost() {}
|
||||
virtual void focusGained() {}
|
||||
virtual void windowMoved(const SWindowRect& rect) { (void)rect; }
|
||||
virtual void windowMoved([[maybe_unused]] const SWindowRect& rect) {}
|
||||
|
||||
virtual void destroyed() {}
|
||||
};
|
||||
|
@ -278,10 +236,7 @@ public:
|
|||
virtual int waitForRetrace() = 0;
|
||||
|
||||
virtual uintptr_t getPlatformHandle() const = 0;
|
||||
virtual bool _incomingEvent(void* event) {
|
||||
(void)event;
|
||||
return false;
|
||||
}
|
||||
virtual bool _incomingEvent([[maybe_unused]] void* event) { return false; }
|
||||
virtual void _cleanup() {}
|
||||
|
||||
virtual ETouchType getTouchType() const = 0;
|
||||
|
@ -289,7 +244,7 @@ public:
|
|||
virtual void setStyle(EWindowStyle style) = 0;
|
||||
virtual EWindowStyle getStyle() const = 0;
|
||||
|
||||
virtual void setTouchBarProvider(void*) {}
|
||||
virtual void setTouchBarProvider([[maybe_unused]] void* provider) {}
|
||||
|
||||
virtual IGraphicsCommandQueue* getCommandQueue() = 0;
|
||||
virtual IGraphicsDataFactory* getDataFactory() = 0;
|
||||
|
|
|
@ -29,35 +29,34 @@ static inline ComPtr<T>* ReferenceComPtr(ComPtr<T>& ptr) {
|
|||
|
||||
#ifndef ENABLE_BITWISE_ENUM
|
||||
#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>; \
|
||||
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>; \
|
||||
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>; \
|
||||
a = type(static_cast<T>(a) | static_cast<T>(b)); \
|
||||
return a; \
|
||||
} \
|
||||
constexpr type& operator&=(type& a, type b) { \
|
||||
constexpr type& operator&=(type& a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
a = type(static_cast<T>(a) & static_cast<T>(b)); \
|
||||
return a; \
|
||||
} \
|
||||
constexpr type operator~(type key) { \
|
||||
constexpr type operator~(type key) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return type(~static_cast<T>(key)); \
|
||||
} \
|
||||
constexpr bool True(type key) { \
|
||||
constexpr bool True(type key) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<T>(key) != 0; \
|
||||
} \
|
||||
constexpr bool False(type key) { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<T>(key) == 0; \
|
||||
constexpr bool False(type key) noexcept { \
|
||||
return !True(key); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -85,8 +85,8 @@ struct VulkanContext {
|
|||
#if _WIN32
|
||||
HWND m_hwnd = 0;
|
||||
bool m_fs = false;
|
||||
LONG m_fsStyle;
|
||||
LONG m_fsExStyle;
|
||||
LONG_PTR m_fsStyle;
|
||||
LONG_PTR m_fsExStyle;
|
||||
RECT m_fsRect;
|
||||
int m_fsCountDown = 0;
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "boo/System.hpp"
|
||||
|
@ -31,42 +33,33 @@ enum class EDolphinControllerButtons {
|
|||
ENABLE_BITWISE_ENUM(EDolphinControllerButtons)
|
||||
|
||||
struct DolphinControllerState {
|
||||
int16_t m_leftStick[2] = {0};
|
||||
int16_t m_rightStick[2] = {0};
|
||||
int16_t m_analogTriggers[2] = {0};
|
||||
std::array<int16_t, 2> m_leftStick{};
|
||||
std::array<int16_t, 2> m_rightStick{};
|
||||
std::array<int16_t, 2> m_analogTriggers{};
|
||||
uint16_t m_btns = 0;
|
||||
void reset() {
|
||||
m_leftStick[0] = 0;
|
||||
m_leftStick[1] = 0;
|
||||
m_rightStick[0] = 0;
|
||||
m_rightStick[1] = 0;
|
||||
m_analogTriggers[0] = 0;
|
||||
m_analogTriggers[1] = 0;
|
||||
m_leftStick = {};
|
||||
m_rightStick = {};
|
||||
m_analogTriggers = {};
|
||||
m_btns = 0;
|
||||
}
|
||||
void clamp();
|
||||
};
|
||||
|
||||
struct IDolphinSmashAdapterCallback {
|
||||
virtual void controllerConnected(unsigned idx, EDolphinControllerType type) {
|
||||
(void)idx;
|
||||
(void)type;
|
||||
}
|
||||
virtual void controllerDisconnected(unsigned idx) { (void)idx; }
|
||||
virtual void controllerUpdate(unsigned idx, EDolphinControllerType type, const DolphinControllerState& state) {
|
||||
(void)idx;
|
||||
(void)type;
|
||||
(void)state;
|
||||
}
|
||||
virtual void controllerConnected([[maybe_unused]] unsigned idx, [[maybe_unused]] EDolphinControllerType type) {}
|
||||
virtual void controllerDisconnected([[maybe_unused]] unsigned idx) {}
|
||||
virtual void controllerUpdate([[maybe_unused]] unsigned idx, [[maybe_unused]] EDolphinControllerType type,
|
||||
[[maybe_unused]] const DolphinControllerState& state) {}
|
||||
};
|
||||
|
||||
class DolphinSmashAdapter final : public TDeviceBase<IDolphinSmashAdapterCallback> {
|
||||
int16_t m_leftStickCal[2] = {0x7f};
|
||||
int16_t m_rightStickCal[2] = {0x7f};
|
||||
int16_t m_triggersCal[2] = {0x0};
|
||||
std::array<int16_t, 2> m_leftStickCal{0x7f, 0};
|
||||
std::array<int16_t, 2> m_rightStickCal{0x7f, 0};
|
||||
std::array<int16_t, 2> m_triggersCal{};
|
||||
uint8_t m_knownControllers = 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 */
|
||||
void deviceDisconnected() override;
|
||||
void initialCycle() override;
|
||||
|
@ -81,15 +74,21 @@ public:
|
|||
TDeviceBase<IDolphinSmashAdapterCallback>::setCallback(cb);
|
||||
m_knownControllers = 0;
|
||||
}
|
||||
void startRumble(unsigned idx) {
|
||||
if (idx >= 4)
|
||||
|
||||
void startRumble(size_t idx) {
|
||||
if (idx >= m_hardStop.size()) {
|
||||
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;
|
||||
m_rumbleRequest &= ~(1 << idx);
|
||||
}
|
||||
|
||||
m_rumbleRequest &= ~(1U << idx);
|
||||
m_hardStop[idx] = hard;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ struct INintendoPowerACallback {
|
|||
};
|
||||
|
||||
class NintendoPowerA final : public TDeviceBase<INintendoPowerACallback> {
|
||||
NintendoPowerAState m_last;
|
||||
NintendoPowerAState m_last{};
|
||||
void deviceDisconnected() override;
|
||||
void initialCycle() 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;
|
||||
|
||||
public:
|
||||
NintendoPowerA(DeviceToken*);
|
||||
explicit NintendoPowerA(DeviceToken*);
|
||||
~NintendoPowerA() override;
|
||||
};
|
||||
} // namespace boo
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#include "boo/inputdev/DolphinSmashAdapter.hpp"
|
||||
#include "boo/inputdev/DeviceSignature.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace boo {
|
||||
/*
|
||||
* 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() {}
|
||||
|
||||
constexpr EDolphinControllerType parseType(unsigned char status) {
|
||||
EDolphinControllerType type =
|
||||
static constexpr EDolphinControllerType parseType(unsigned char status) {
|
||||
const auto type =
|
||||
EDolphinControllerType(status) & (EDolphinControllerType::Normal | EDolphinControllerType::Wavebird);
|
||||
|
||||
switch (type) {
|
||||
case EDolphinControllerType::Normal:
|
||||
case EDolphinControllerType::Wavebird:
|
||||
|
@ -26,13 +24,13 @@ constexpr EDolphinControllerType parseType(unsigned char status) {
|
|||
}
|
||||
}
|
||||
|
||||
static EDolphinControllerType parseState(DolphinControllerState* stateOut, uint8_t* payload, bool& rumble) {
|
||||
unsigned char status = payload[0];
|
||||
EDolphinControllerType type = parseType(status);
|
||||
static EDolphinControllerType parseState(DolphinControllerState* stateOut, const uint8_t* payload, bool& rumble) {
|
||||
const unsigned char status = payload[0];
|
||||
const EDolphinControllerType type = parseType(status);
|
||||
|
||||
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[1] = payload[4];
|
||||
|
@ -45,43 +43,44 @@ static EDolphinControllerType parseState(DolphinControllerState* stateOut, uint8
|
|||
}
|
||||
|
||||
void DolphinSmashAdapter::initialCycle() {
|
||||
uint8_t handshakePayload[] = {0x13};
|
||||
sendUSBInterruptTransfer(handshakePayload, sizeof(handshakePayload));
|
||||
constexpr std::array<uint8_t, 1> handshakePayload{0x13};
|
||||
sendUSBInterruptTransfer(handshakePayload.data(), handshakePayload.size());
|
||||
}
|
||||
|
||||
void DolphinSmashAdapter::transferCycle() {
|
||||
uint8_t payload[37];
|
||||
size_t recvSz = receiveUSBInterruptTransfer(payload, sizeof(payload));
|
||||
if (recvSz != 37 || payload[0] != 0x21)
|
||||
std::array<uint8_t, 37> payload;
|
||||
const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size());
|
||||
if (recvSz != payload.size() || payload[0] != 0x21) {
|
||||
return;
|
||||
}
|
||||
|
||||
// fmt::print("RECEIVED DATA {} {:02X}\n", recvSz, payload[0]);
|
||||
|
||||
std::lock_guard<std::mutex> lk(m_callbackLock);
|
||||
if (!m_callback)
|
||||
if (!m_callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Parse controller states */
|
||||
uint8_t* controller = &payload[1];
|
||||
const uint8_t* controller = &payload[1];
|
||||
uint8_t rumbleMask = 0;
|
||||
for (uint32_t i = 0; i < 4; i++, controller += 9) {
|
||||
DolphinControllerState state;
|
||||
bool rumble = false;
|
||||
EDolphinControllerType type = parseState(&state, controller, rumble);
|
||||
if (True(type) && !(m_knownControllers & 1 << i)) {
|
||||
m_leftStickCal[0] = state.m_leftStick[0];
|
||||
m_leftStickCal[1] = state.m_leftStick[1];
|
||||
m_rightStickCal[0] = state.m_rightStick[0];
|
||||
m_rightStickCal[1] = state.m_rightStick[1];
|
||||
m_triggersCal[0] = state.m_analogTriggers[0];
|
||||
m_triggersCal[1] = state.m_analogTriggers[1];
|
||||
m_knownControllers |= 1 << i;
|
||||
const EDolphinControllerType type = parseState(&state, controller, rumble);
|
||||
|
||||
if (True(type) && (m_knownControllers & (1U << i)) == 0) {
|
||||
m_leftStickCal = state.m_leftStick;
|
||||
m_rightStickCal = state.m_rightStick;
|
||||
m_triggersCal = state.m_analogTriggers;
|
||||
m_knownControllers |= 1U << i;
|
||||
m_callback->controllerConnected(i, type);
|
||||
} else if (False(type) && (m_knownControllers & 1 << i)) {
|
||||
m_knownControllers &= ~(1 << i);
|
||||
} else if (False(type) && (m_knownControllers & (1U << i)) != 0) {
|
||||
m_knownControllers &= ~(1U << 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[1] = state.m_leftStick[1] - m_leftStickCal[1];
|
||||
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];
|
||||
m_callback->controllerUpdate(i, type, state);
|
||||
}
|
||||
rumbleMask |= rumble ? 1 << i : 0;
|
||||
|
||||
rumbleMask |= rumble ? 1U << i : 0;
|
||||
}
|
||||
|
||||
/* Send rumble message (if needed) */
|
||||
uint8_t rumbleReq = m_rumbleRequest & rumbleMask;
|
||||
const uint8_t rumbleReq = m_rumbleRequest & rumbleMask;
|
||||
if (rumbleReq != m_rumbleState) {
|
||||
uint8_t rumbleMessage[5] = {0x11};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (rumbleReq & 1 << i)
|
||||
std::array<uint8_t, 5> rumbleMessage{0x11, 0, 0, 0, 0};
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
if ((rumbleReq & (1U << i)) != 0) {
|
||||
rumbleMessage[i + 1] = 1;
|
||||
else if (m_hardStop[i])
|
||||
} else if (m_hardStop[i]) {
|
||||
rumbleMessage[i + 1] = 2;
|
||||
else
|
||||
} else {
|
||||
rumbleMessage[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sendUSBInterruptTransfer(rumbleMessage, sizeof(rumbleMessage));
|
||||
sendUSBInterruptTransfer(rumbleMessage.data(), rumbleMessage.size());
|
||||
m_rumbleState = rumbleReq;
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinSmashAdapter::finalCycle() {
|
||||
uint8_t rumbleMessage[5] = {0x11, 0, 0, 0, 0};
|
||||
sendUSBInterruptTransfer(rumbleMessage, sizeof(rumbleMessage));
|
||||
constexpr std::array<uint8_t, 5> rumbleMessage{0x11, 0, 0, 0, 0};
|
||||
sendUSBInterruptTransfer(rumbleMessage.data(), sizeof(rumbleMessage));
|
||||
}
|
||||
|
||||
void DolphinSmashAdapter::deviceDisconnected() {
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
if (m_knownControllers & 1 << i) {
|
||||
m_knownControllers &= ~(1 << i);
|
||||
if ((m_knownControllers & (1U << i)) != 0) {
|
||||
m_knownControllers &= ~(1U << i);
|
||||
std::lock_guard<std::mutex> lk(m_callbackLock);
|
||||
if (m_callback)
|
||||
if (m_callback) {
|
||||
m_callback->controllerDisconnected(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,15 +153,15 @@ void DolphinSmashAdapter::deviceDisconnected() {
|
|||
* 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) {
|
||||
int x = px;
|
||||
int y = py;
|
||||
int signX;
|
||||
int signY;
|
||||
int d;
|
||||
|
||||
int signX;
|
||||
if (x > 0) {
|
||||
signX = 1;
|
||||
} else {
|
||||
|
@ -167,6 +169,7 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
|
|||
x = -x;
|
||||
}
|
||||
|
||||
int signY;
|
||||
if (y > 0) {
|
||||
signY = 1;
|
||||
} else {
|
||||
|
@ -174,10 +177,11 @@ static void pad_clampstick(int16_t& px, int16_t& py, int16_t max, int16_t xy, in
|
|||
y = -y;
|
||||
}
|
||||
|
||||
if (x <= min)
|
||||
if (x <= min) {
|
||||
x = 0;
|
||||
else
|
||||
} else {
|
||||
x -= min;
|
||||
}
|
||||
|
||||
if (y <= min) {
|
||||
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) {
|
||||
d = xy * x + (max - xy) * y;
|
||||
const int d = xy * x + (max - xy) * y;
|
||||
if (xy * max < d) {
|
||||
x = int16_t(xy * max * x / d);
|
||||
y = int16_t(xy * max * y / d);
|
||||
}
|
||||
} else {
|
||||
d = xy * y + (max - xy) * x;
|
||||
const int d = xy * y + (max - xy) * x;
|
||||
if (xy * max < d) {
|
||||
x = int16_t(xy * max * x / 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) {
|
||||
int16_t min, max;
|
||||
const int16_t min = pad_clampregion[0];
|
||||
const int16_t max = pad_clampregion[1];
|
||||
|
||||
min = pad_clampregion[0];
|
||||
max = pad_clampregion[1];
|
||||
if (min > trigger)
|
||||
if (min > trigger) {
|
||||
trigger = 0;
|
||||
else {
|
||||
if (max < trigger)
|
||||
} else {
|
||||
if (max < trigger) {
|
||||
trigger = max;
|
||||
}
|
||||
trigger -= min;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "boo/inputdev/NintendoPowerA.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
#include "boo/inputdev/DeviceSignature.hpp"
|
||||
|
@ -8,27 +9,31 @@ namespace boo {
|
|||
NintendoPowerA::NintendoPowerA(DeviceToken* token)
|
||||
: TDeviceBase<INintendoPowerACallback>(dev_typeid(NintendoPowerA), token) {}
|
||||
|
||||
NintendoPowerA::~NintendoPowerA() {}
|
||||
NintendoPowerA::~NintendoPowerA() = default;
|
||||
|
||||
void NintendoPowerA::deviceDisconnected() {
|
||||
std::lock_guard<std::mutex> lk(m_callbackLock);
|
||||
if (m_callback)
|
||||
std::lock_guard lk{m_callbackLock};
|
||||
if (m_callback != nullptr) {
|
||||
m_callback->controllerDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
void NintendoPowerA::initialCycle() {}
|
||||
|
||||
void NintendoPowerA::transferCycle() {
|
||||
uint8_t payload[8];
|
||||
size_t recvSz = receiveUSBInterruptTransfer(payload, sizeof(payload));
|
||||
if (recvSz != 8)
|
||||
std::array<uint8_t, 8> payload;
|
||||
const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size());
|
||||
if (recvSz != payload.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
NintendoPowerAState state = *reinterpret_cast<NintendoPowerAState*>(&payload);
|
||||
NintendoPowerAState state;
|
||||
std::memcpy(&state, payload.data(), sizeof(state));
|
||||
|
||||
std::lock_guard<std::mutex> lk(m_callbackLock);
|
||||
if (state != m_last && m_callback)
|
||||
std::lock_guard lk{m_callbackLock};
|
||||
if (state != m_last && m_callback != nullptr) {
|
||||
m_callback->controllerUpdate(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) {}
|
||||
|
||||
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); }
|
||||
|
|
|
@ -89,10 +89,7 @@ public:
|
|||
void waitForRetrace() override {}
|
||||
|
||||
uintptr_t getPlatformHandle() const override { return 0; }
|
||||
bool _incomingEvent(void* event) override {
|
||||
(void)event;
|
||||
return false;
|
||||
}
|
||||
bool _incomingEvent([[maybe_unused]] void* event) override { return false; }
|
||||
void _cleanup() override {}
|
||||
|
||||
ETouchType getTouchType() const override { return ETouchType::Display; }
|
||||
|
|
|
@ -339,9 +339,10 @@ public:
|
|||
win.m_fsExStyle = GetWindowLong(win.m_hwnd, GWL_EXSTYLE);
|
||||
GetWindowRect(win.m_hwnd, &win.m_fsRect);
|
||||
|
||||
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME));
|
||||
SetWindowLong(win.m_hwnd, GWL_EXSTYLE,
|
||||
win.m_fsExStyle & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
|
||||
SetWindowLongPtr(win.m_hwnd, GWL_STYLE, win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME));
|
||||
SetWindowLongPtr(win.m_hwnd, GWL_EXSTYLE,
|
||||
win.m_fsExStyle &
|
||||
~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
|
||||
|
||||
MONITORINFO monitor_info;
|
||||
monitor_info.cbSize = sizeof(monitor_info);
|
||||
|
@ -353,8 +354,8 @@ public:
|
|||
|
||||
win.m_fs = true;
|
||||
} else {
|
||||
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle);
|
||||
SetWindowLong(win.m_hwnd, GWL_EXSTYLE, win.m_fsExStyle);
|
||||
SetWindowLongPtr(win.m_hwnd, GWL_STYLE, win.m_fsStyle);
|
||||
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,
|
||||
win.m_fsRect.bottom - win.m_fsRect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
||||
|
|
|
@ -39,8 +39,8 @@ struct OGLContext {
|
|||
size_t width, height;
|
||||
|
||||
bool m_fs = false;
|
||||
LONG m_fsStyle;
|
||||
LONG m_fsExStyle;
|
||||
LONG_PTR m_fsStyle;
|
||||
LONG_PTR m_fsExStyle;
|
||||
RECT m_fsRect;
|
||||
int m_fsCountDown = 0;
|
||||
};
|
||||
|
|
|
@ -859,18 +859,17 @@ public:
|
|||
|
||||
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);
|
||||
HINSTANCE wndInstance = HINSTANCE(GetWindowLongPtr(m_hwnd, GWLP_HINSTANCE));
|
||||
m_imc = ImmGetContext(m_hwnd);
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
HINSTANCE wndInstance = HINSTANCE(GetWindowLongPtr(m_hwnd, GWLP_HINSTANCE));
|
||||
if (b3dCtx.m_vulkanDxFactory) {
|
||||
m_gfxCtx.reset(new GraphicsContextWin32Vulkan(this, wndInstance, m_hwnd, &g_VulkanContext, b3dCtx));
|
||||
if (m_gfxCtx->initializeContext(nullptr))
|
||||
return;
|
||||
}
|
||||
#else
|
||||
(void)wndInstance;
|
||||
#endif
|
||||
|
||||
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
|
||||
if (b3dCtx.m_ctxOgl.m_dxFactory) {
|
||||
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; }
|
||||
|
||||
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;
|
||||
else
|
||||
} else {
|
||||
sty &= ~WS_CAPTION;
|
||||
}
|
||||
|
||||
if ((style & EWindowStyle::Resize) != EWindowStyle::None)
|
||||
if ((style & EWindowStyle::Resize) != EWindowStyle::None) {
|
||||
sty |= WS_THICKFRAME;
|
||||
else
|
||||
} else {
|
||||
sty &= ~WS_THICKFRAME;
|
||||
}
|
||||
|
||||
if ((style & EWindowStyle::Close) != EWindowStyle::None)
|
||||
if ((style & EWindowStyle::Close) != EWindowStyle::None) {
|
||||
sty |= (WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
||||
else
|
||||
} else {
|
||||
sty &= ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
||||
}
|
||||
|
||||
SetWindowLong(m_hwnd, GWL_STYLE, sty);
|
||||
SetWindowLongPtr(m_hwnd, GWL_STYLE, sty);
|
||||
}
|
||||
|
||||
EWindowStyle getStyle() const override {
|
||||
LONG sty = GetWindowLong(m_hwnd, GWL_STYLE);
|
||||
const LONG_PTR sty = GetWindowLongPtr(m_hwnd, GWL_STYLE);
|
||||
|
||||
EWindowStyle retval = EWindowStyle::None;
|
||||
if ((sty & WS_CAPTION) != 0)
|
||||
if ((sty & WS_CAPTION) != 0) {
|
||||
retval |= EWindowStyle::Titlebar;
|
||||
if ((sty & WS_THICKFRAME) != 0)
|
||||
}
|
||||
if ((sty & WS_THICKFRAME) != 0) {
|
||||
retval |= EWindowStyle::Resize;
|
||||
if ((sty & WS_SYSMENU))
|
||||
}
|
||||
if ((sty & WS_SYSMENU)) {
|
||||
retval |= EWindowStyle::Close;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class ApplicationWayland final : public IApplication {
|
|||
const std::vector<std::string> m_args;
|
||||
bool m_singleInstance;
|
||||
|
||||
void _deletedWindow(IWindow* window) override { (void)window; }
|
||||
void _deletedWindow([[maybe_unused]] IWindow* window) override {}
|
||||
|
||||
public:
|
||||
ApplicationWayland(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
||||
|
|
Loading…
Reference in New Issue