Fix inconsistent EOL

This commit is contained in:
2025-01-08 22:27:37 +01:00
parent 57671ac79d
commit 1f7141c517
184 changed files with 13686 additions and 13685 deletions

View File

@@ -1,107 +1,107 @@
#pragma once
#include "../GPU/gpu_types.hpp"
#include "raw_controller.hpp"
namespace JabyEngine {
namespace Periphery {
class GenericController : public RawController {
public:
struct Rumble {
static constexpr uint8_t LargeMotorThreshold = 0x60;
};
enum struct Button : uint16_t {
L2 = static_cast<uint16_t>(GenericButton::D0),
R2 = static_cast<uint16_t>(GenericButton::D1),
L1 = static_cast<uint16_t>(GenericButton::D2),
R1 = static_cast<uint16_t>(GenericButton::D3),
Triangle = static_cast<uint16_t>(GenericButton::D4),
Circle = static_cast<uint16_t>(GenericButton::D5),
Cross = static_cast<uint16_t>(GenericButton::D6),
Square = static_cast<uint16_t>(GenericButton::D7),
SEL = static_cast<uint16_t>(GenericButton::D8),
ST = static_cast<uint16_t>(GenericButton::D11),
Up = static_cast<uint16_t>(GenericButton::D12),
Right = static_cast<uint16_t>(GenericButton::D13),
Down = static_cast<uint16_t>(GenericButton::D14),
Left = static_cast<uint16_t>(GenericButton::D15)
};
void set_digital_rumble() {
RawController::header.rumble0 = 0x1;
RawController::header.rumble1 = 0x7F;
}
void set_analog_rumble(uint8_t largeMotor, bool smallMotor) {
RawController::header.rumble0 = smallMotor ? 0x1 : 0x0;
RawController::header.rumble1 = largeMotor;
}
void stopRumble() {
RawController::header.rumble0 = 0x0;
RawController::header.rumble1 = 0x0;
}
bool is_small_rumble() const {
return static_cast<bool>(RawController::header.rumble0);
}
uint8_t get_large_rumble() const {
return RawController::header.rumble1;
}
bool is_connected() const {
return RawController::header.state != RawController::State::Disconnected;
}
bool is_useable() const {
const auto type = RawController::get_type();
return ((RawController::header.state == RawController::State::Stable) && (type == ControllerType::Controller || type == ControllerType::DualShock));
}
};
class AnalogeController : public GenericController {
public:
enum struct Button : uint16_t {
L2 = static_cast<uint16_t>(GenericButton::D0),
R2 = static_cast<uint16_t>(GenericButton::D1),
L1 = static_cast<uint16_t>(GenericButton::D2),
R1 = static_cast<uint16_t>(GenericButton::D3),
Triangle = static_cast<uint16_t>(GenericButton::D4),
Circle = static_cast<uint16_t>(GenericButton::D5),
Cross = static_cast<uint16_t>(GenericButton::D6),
Square = static_cast<uint16_t>(GenericButton::D7),
SEL = static_cast<uint16_t>(GenericButton::D8),
L3 = static_cast<uint16_t>(GenericButton::D9),
R3 = static_cast<uint16_t>(GenericButton::D10),
ST = static_cast<uint16_t>(GenericButton::D11),
Up = static_cast<uint16_t>(GenericButton::D12),
Right = static_cast<uint16_t>(GenericButton::D13),
Down = static_cast<uint16_t>(GenericButton::D14),
Left = static_cast<uint16_t>(GenericButton::D15)
};
private:
uint8_t read_special_byte(size_t idx) const {
return reinterpret_cast<const uint8_t(&)[4]>(this->special)[idx];
}
public:
GPU::PositionI16 get_right_stick_pos() const {
const uint8_t joy_x = AnalogeController::read_special_byte(0);
const uint8_t joy_y = AnalogeController::read_special_byte(1);
return GPU::PositionI16::create(joy_x - 0x80, joy_y - 0x80);
}
GPU::PositionI16 get_left_stick_pos() const {
const uint8_t joy_x = AnalogeController::read_special_byte(2);
const uint8_t joy_y = AnalogeController::read_special_byte(3);
return GPU::PositionI16::create(joy_x - 0x80, joy_y - 0x80);
}
};
using GenericButtonState = GenericController::ButtonState;
}
#pragma once
#include "../GPU/gpu_types.hpp"
#include "raw_controller.hpp"
namespace JabyEngine {
namespace Periphery {
class GenericController : public RawController {
public:
struct Rumble {
static constexpr uint8_t LargeMotorThreshold = 0x60;
};
enum struct Button : uint16_t {
L2 = static_cast<uint16_t>(GenericButton::D0),
R2 = static_cast<uint16_t>(GenericButton::D1),
L1 = static_cast<uint16_t>(GenericButton::D2),
R1 = static_cast<uint16_t>(GenericButton::D3),
Triangle = static_cast<uint16_t>(GenericButton::D4),
Circle = static_cast<uint16_t>(GenericButton::D5),
Cross = static_cast<uint16_t>(GenericButton::D6),
Square = static_cast<uint16_t>(GenericButton::D7),
SEL = static_cast<uint16_t>(GenericButton::D8),
ST = static_cast<uint16_t>(GenericButton::D11),
Up = static_cast<uint16_t>(GenericButton::D12),
Right = static_cast<uint16_t>(GenericButton::D13),
Down = static_cast<uint16_t>(GenericButton::D14),
Left = static_cast<uint16_t>(GenericButton::D15)
};
void set_digital_rumble() {
RawController::header.rumble0 = 0x1;
RawController::header.rumble1 = 0x7F;
}
void set_analog_rumble(uint8_t largeMotor, bool smallMotor) {
RawController::header.rumble0 = smallMotor ? 0x1 : 0x0;
RawController::header.rumble1 = largeMotor;
}
void stopRumble() {
RawController::header.rumble0 = 0x0;
RawController::header.rumble1 = 0x0;
}
bool is_small_rumble() const {
return static_cast<bool>(RawController::header.rumble0);
}
uint8_t get_large_rumble() const {
return RawController::header.rumble1;
}
bool is_connected() const {
return RawController::header.state != RawController::State::Disconnected;
}
bool is_useable() const {
const auto type = RawController::get_type();
return ((RawController::header.state == RawController::State::Stable) && (type == ControllerType::Controller || type == ControllerType::DualShock));
}
};
class AnalogeController : public GenericController {
public:
enum struct Button : uint16_t {
L2 = static_cast<uint16_t>(GenericButton::D0),
R2 = static_cast<uint16_t>(GenericButton::D1),
L1 = static_cast<uint16_t>(GenericButton::D2),
R1 = static_cast<uint16_t>(GenericButton::D3),
Triangle = static_cast<uint16_t>(GenericButton::D4),
Circle = static_cast<uint16_t>(GenericButton::D5),
Cross = static_cast<uint16_t>(GenericButton::D6),
Square = static_cast<uint16_t>(GenericButton::D7),
SEL = static_cast<uint16_t>(GenericButton::D8),
L3 = static_cast<uint16_t>(GenericButton::D9),
R3 = static_cast<uint16_t>(GenericButton::D10),
ST = static_cast<uint16_t>(GenericButton::D11),
Up = static_cast<uint16_t>(GenericButton::D12),
Right = static_cast<uint16_t>(GenericButton::D13),
Down = static_cast<uint16_t>(GenericButton::D14),
Left = static_cast<uint16_t>(GenericButton::D15)
};
private:
uint8_t read_special_byte(size_t idx) const {
return reinterpret_cast<const uint8_t(&)[4]>(this->special)[idx];
}
public:
GPU::PositionI16 get_right_stick_pos() const {
const uint8_t joy_x = AnalogeController::read_special_byte(0);
const uint8_t joy_y = AnalogeController::read_special_byte(1);
return GPU::PositionI16::create(joy_x - 0x80, joy_y - 0x80);
}
GPU::PositionI16 get_left_stick_pos() const {
const uint8_t joy_x = AnalogeController::read_special_byte(2);
const uint8_t joy_y = AnalogeController::read_special_byte(3);
return GPU::PositionI16::create(joy_x - 0x80, joy_y - 0x80);
}
};
using GenericButtonState = GenericController::ButtonState;
}
}

View File

@@ -1,24 +1,24 @@
#pragma once
#include "../jabyengine_config.hpp"
#include "controller.hpp"
namespace JabyEngine {
namespace Periphery {
static constexpr uint32_t PortCount = Configuration::Periphery::include_portB() ? 2 : 1;
static constexpr uint32_t DeviceCount = Configuration::Periphery::use_multi_tap() ? 4 : 1;
extern RawController controller[PortCount][DeviceCount];
void query_controller();
template<typename T>
inline T& get_controller_as(size_t port, size_t device) {
return *reinterpret_cast<T*>(&controller[port][device]);
}
template<typename T>
inline T& get_primary_controller_as() {
return get_controller_as<T>(0, 0);
}
}
#pragma once
#include "../jabyengine_config.hpp"
#include "controller.hpp"
namespace JabyEngine {
namespace Periphery {
static constexpr uint32_t PortCount = Configuration::Periphery::include_portB() ? 2 : 1;
static constexpr uint32_t DeviceCount = Configuration::Periphery::use_multi_tap() ? 4 : 1;
extern RawController controller[PortCount][DeviceCount];
void query_controller();
template<typename T>
inline T& get_controller_as(size_t port, size_t device) {
return *reinterpret_cast<T*>(&controller[port][device]);
}
template<typename T>
inline T& get_primary_controller_as() {
return get_controller_as<T>(0, 0);
}
}
}

View File

@@ -1,137 +1,137 @@
#pragma once
#include "../jabyengine_defines.hpp"
namespace JabyEngine {
namespace Periphery {
enum struct ControllerType : uint8_t {
Unkown = 0x0,
Mouse = 0x1,
NegCon = 0x2,
HyperBlaster = 0x3, // Konami Lightgun
Controller = 0x4,
ArcadeFlightStick = 0x5,
GCon = 0x6,
DualShock = 0x7,
MultiTap = 0x8
};
enum struct GenericButton : uint16_t {
D8 = (1 << 0),
D9 = (1 << 1),
D10 = (1 << 2),
D11 = (1 << 3),
D12 = (1 << 4),
D13 = (1 << 5),
D14 = (1 << 6),
D15 = (1 << 7),
D0 = (1 << 8),
D1 = (1 << 9),
D2 = (1 << 10),
D3 = (1 << 11),
D4 = (1 << 12),
D5 = (1 << 13),
D6 = (1 << 14),
D7 = (1 << 15)
};
struct LED {
enum struct State : uint8_t {
Off = 0x0,
On = 0x1
};
enum struct Lock {
Off = 0x2,
On = 0x3
};
};
class RawController {
public:
enum struct State : uint8_t
{
Disconnected = 0,
EnterConfigMode = (1 << 0),
LockAnalog = (1 << 1),
UnlockRumble = (1 << 2),
ExitConfigMode = (1 << 3),
Stable = (1 << 4)
};
protected:
struct Header {
uint8_t type;
State state;
uint8_t rumble0;
uint8_t rumble1;
void clear() {
this->type = 0;
this->state = State::Disconnected;
}
};
public:
class ButtonState {
private:
uint16_t oldState;
uint16_t currentState;
static bool is_down(uint16_t data, uint16_t button) {
return ((data & button) == 0);
}
void exchange_state() {
this->oldState = this->currentState;
}
public:
template<typename T>
bool is_down(T button) const {
return ButtonState::is_down(this->currentState, static_cast<uint16_t>(button));
}
template<typename T>
bool was_down(T button) const {
return ButtonState::is_down(this->oldState, static_cast<uint16_t>(button));
}
template<typename T>
bool went_down(T button) const {
return (!ButtonState::was_down(button) && ButtonState::is_down(button));
}
template<typename T>
bool went_up(T button) const {
return (ButtonState::was_down(button) && !ButtonState::is_down(button));
}
friend class RawController;
friend struct ControllerHelper;
friend void query_controller();
};
Header header;
ButtonState button;
uint32_t special;
public:
ControllerType get_type() const {
return static_cast<ControllerType>((this->header.type >> 4));
}
ButtonState get_button_state() const {
return this->button;
}
//For debugging only
uint8_t get_raw_type() const {
return this->header.type;
}
uint16_t get_raw_button_state() const {
return this->button.currentState;
}
};
}
#pragma once
#include "../jabyengine_defines.hpp"
namespace JabyEngine {
namespace Periphery {
enum struct ControllerType : uint8_t {
Unkown = 0x0,
Mouse = 0x1,
NegCon = 0x2,
HyperBlaster = 0x3, // Konami Lightgun
Controller = 0x4,
ArcadeFlightStick = 0x5,
GCon = 0x6,
DualShock = 0x7,
MultiTap = 0x8
};
enum struct GenericButton : uint16_t {
D8 = (1 << 0),
D9 = (1 << 1),
D10 = (1 << 2),
D11 = (1 << 3),
D12 = (1 << 4),
D13 = (1 << 5),
D14 = (1 << 6),
D15 = (1 << 7),
D0 = (1 << 8),
D1 = (1 << 9),
D2 = (1 << 10),
D3 = (1 << 11),
D4 = (1 << 12),
D5 = (1 << 13),
D6 = (1 << 14),
D7 = (1 << 15)
};
struct LED {
enum struct State : uint8_t {
Off = 0x0,
On = 0x1
};
enum struct Lock {
Off = 0x2,
On = 0x3
};
};
class RawController {
public:
enum struct State : uint8_t
{
Disconnected = 0,
EnterConfigMode = (1 << 0),
LockAnalog = (1 << 1),
UnlockRumble = (1 << 2),
ExitConfigMode = (1 << 3),
Stable = (1 << 4)
};
protected:
struct Header {
uint8_t type;
State state;
uint8_t rumble0;
uint8_t rumble1;
void clear() {
this->type = 0;
this->state = State::Disconnected;
}
};
public:
class ButtonState {
private:
uint16_t oldState;
uint16_t currentState;
static bool is_down(uint16_t data, uint16_t button) {
return ((data & button) == 0);
}
void exchange_state() {
this->oldState = this->currentState;
}
public:
template<typename T>
bool is_down(T button) const {
return ButtonState::is_down(this->currentState, static_cast<uint16_t>(button));
}
template<typename T>
bool was_down(T button) const {
return ButtonState::is_down(this->oldState, static_cast<uint16_t>(button));
}
template<typename T>
bool went_down(T button) const {
return (!ButtonState::was_down(button) && ButtonState::is_down(button));
}
template<typename T>
bool went_up(T button) const {
return (ButtonState::was_down(button) && !ButtonState::is_down(button));
}
friend class RawController;
friend struct ControllerHelper;
friend void query_controller();
};
Header header;
ButtonState button;
uint32_t special;
public:
ControllerType get_type() const {
return static_cast<ControllerType>((this->header.type >> 4));
}
ButtonState get_button_state() const {
return this->button;
}
//For debugging only
uint8_t get_raw_type() const {
return this->header.type;
}
uint16_t get_raw_button_state() const {
return this->button.currentState;
}
};
}
}