Moves class member functions from headers to compilation units.

This commit is contained in:
Kenix3 2022-08-24 22:11:33 -04:00
parent c0b9171f98
commit 80863fc7f2
17 changed files with 266 additions and 87 deletions

View File

@ -87,6 +87,7 @@ set(Source_Files__Controller
"KeyboardController.cpp" "KeyboardController.cpp"
"KeyboardController.h" "KeyboardController.h"
"UltraController.h" "UltraController.h"
"DummyController.cpp"
"DummyController.h" "DummyController.h"
) )

View File

@ -389,4 +389,20 @@ namespace Ship {
Commands[command] = entry; Commands[command] = entry;
} }
} }
std::string Console::GetCurrentChannel() {
return currentChannel;
}
bool Console::IsOpened() {
return opened;
}
void Console::Close() {
opened = false;
}
void Console::Open() {
opened = true;
}
} }

View File

@ -93,10 +93,9 @@ namespace Ship {
void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...); void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...);
bool HasCommand(const std::string& command); bool HasCommand(const std::string& command);
void AddCommand(const std::string& command, CommandEntry entry); void AddCommand(const std::string& command, CommandEntry entry);
std::string GetCurrentChannel();
std::string GetCurrentChannel() { return currentChannel; } bool IsOpened();
bool IsOpened() { return opened; } void Close();
void Close() { opened = false; } void Open();
void Open() { opened = true; }
}; };
} }

View File

@ -21,7 +21,7 @@ namespace Ship {
size_t GetNumVirtualDevices(); size_t GetNumVirtualDevices();
uint8_t* GetControllerBits(); uint8_t* GetControllerBits();
private: private:
std::vector<int> virtualDevices = {}; std::vector<int32_t> virtualDevices = {};
std::vector<std::shared_ptr<Controller>> physicalDevices = {}; std::vector<std::shared_ptr<Controller>> physicalDevices = {};
uint8_t* controllerBits = nullptr; uint8_t* controllerBits = nullptr;
}; };

View File

@ -112,4 +112,16 @@ namespace Ship {
std::shared_ptr<DeviceProfile> Controller::getProfile(int32_t virtualSlot) { std::shared_ptr<DeviceProfile> Controller::getProfile(int32_t virtualSlot) {
return profiles[virtualSlot]; return profiles[virtualSlot];
} }
std::shared_ptr<ControllerAttachment> Controller::GetAttachment() {
return Attachment;
}
bool Controller::IsRumbling() {
return isRumbling;
}
std::string Controller::GetGuid() {
return GUID;
}
} }

View File

@ -40,7 +40,6 @@ namespace Ship {
public: public:
virtual ~Controller() = default; virtual ~Controller() = default;
Controller(); Controller();
void Read(OSContPad* pad, int32_t virtualSlot);
virtual void ReadFromSource(int32_t virtualSlot) = 0; virtual void ReadFromSource(int32_t virtualSlot) = 0;
virtual void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) = 0; virtual void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) = 0;
virtual bool Connected() const = 0; virtual bool Connected() const = 0;
@ -49,8 +48,12 @@ namespace Ship {
virtual void CreateDefaultBinding(int32_t virtualSlot) = 0; virtual void CreateDefaultBinding(int32_t virtualSlot) = 0;
virtual void ClearRawPress() = 0; virtual void ClearRawPress() = 0;
virtual int32_t ReadRawPress() = 0; virtual int32_t ReadRawPress() = 0;
virtual const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) = 0;
virtual const std::string GetControllerName() = 0;
void Read(OSContPad* pad, int32_t virtualSlot);
void SetButtonMapping(int32_t virtualSlot, int32_t n64Button, int32_t dwScancode); void SetButtonMapping(int32_t virtualSlot, int32_t n64Button, int32_t dwScancode);
std::shared_ptr<ControllerAttachment> GetAttachment() { return Attachment; } std::shared_ptr<ControllerAttachment> GetAttachment();
std::shared_ptr<DeviceProfile> getProfile(int32_t virtualSlot);
int8_t& getLeftStickX(int32_t virtualSlot); int8_t& getLeftStickX(int32_t virtualSlot);
int8_t& getLeftStickY(int32_t virtualSlot); int8_t& getLeftStickY(int32_t virtualSlot);
int8_t& getRightStickX(int32_t virtualSlot); int8_t& getRightStickX(int32_t virtualSlot);
@ -58,11 +61,8 @@ namespace Ship {
int32_t& getPressedButtons(int32_t virtualSlot); int32_t& getPressedButtons(int32_t virtualSlot);
float& getGyroX(int32_t virtualSlot); float& getGyroX(int32_t virtualSlot);
float& getGyroY(int32_t virtualSlot); float& getGyroY(int32_t virtualSlot);
std::shared_ptr<DeviceProfile> getProfile(int32_t virtualSlot); bool IsRumbling();
bool IsRumbling() { return isRumbling; } std::string GetGuid();
std::string GetGuid() { return GUID; }
virtual const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) = 0;
virtual const std::string GetControllerName() = 0;
protected: protected:
std::shared_ptr<ControllerAttachment> Attachment; std::shared_ptr<ControllerAttachment> Attachment;

View File

@ -0,0 +1,61 @@
#include "DummyController.h"
namespace Ship {
DummyController::DummyController(const std::string& CUID, const std::string& KeyName, bool Connected) {
GUID = CUID;
isConnected = Connected;
ButtonName = KeyName;
}
void DummyController::ReadFromSource(int32_t virtualSlot) {
}
const std::string DummyController::GetControllerName() {
return GUID;
}
const std::string DummyController::GetButtonName(int32_t virtualSlot, int32_t n64Button) {
return ButtonName;
}
void DummyController::WriteToSource(int32_t virtualSlot, ControllerCallback* controller){
}
bool DummyController::Connected() const {
return isConnected;
}
bool DummyController::CanRumble() const {
return false;
}
bool DummyController::CanGyro() const {
return false;
}
void DummyController::CreateDefaultBinding(int32_t slot) {
}
std::string DummyController::GetControllerType() {
return "Unk";
}
std::string DummyController::GetConfSection() {
return "Unk";
}
std::string DummyController::GetBindingConfSection() {
return "Unk";
}
void DummyController::ClearRawPress() {
}
int32_t DummyController::ReadRawPress() {
return -1;
}
}

View File

@ -7,31 +7,25 @@
namespace Ship { namespace Ship {
class DummyController final : public Controller { class DummyController final : public Controller {
public: public:
DummyController(const std::string& CUID, const std::string& KeyName, bool Connected) { DummyController(const std::string& CUID, const std::string& KeyName, bool Connected);
GUID = CUID;
isConnected = Connected;
ButtonName = KeyName;
}
std::map<std::vector<std::string>, int32_t> ReadButtonPress(); std::map<std::vector<std::string>, int32_t> ReadButtonPress();
void ReadFromSource(int32_t slot) override {} void ReadFromSource(int32_t virtualSlot) override;
const std::string GetControllerName() override { return GUID; } const std::string GetControllerName() override;
const std::string GetButtonName(int slot, int n64Button) override { return ButtonName; } const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override;
void WriteToSource(int32_t slot, ControllerCallback* controller) override { } void WriteToSource(int32_t slot, ControllerCallback* controller) override;
bool Connected() const override { return isConnected; } bool Connected() const override;
bool CanRumble() const override { return false; } bool CanRumble() const override;
bool CanGyro() const override { return false; } bool CanGyro() const override;
void ClearRawPress() override;
void ClearRawPress() override {} int32_t ReadRawPress() override;
int32_t ReadRawPress() override { return -1; } bool HasPadConf() const;
bool HasPadConf() const { return true; } std::optional<std::string> GetPadConfSection();
std::optional<std::string> GetPadConfSection() { return "Unk"; } void CreateDefaultBinding(int32_t virtualSlot) override;
void CreateDefaultBinding(int32_t slot) override {}
protected: protected:
std::string ButtonName; std::string ButtonName;
bool isConnected = false; bool isConnected = false;
std::string GetControllerType() { return "Unk"; } std::string GetControllerType();
std::string GetConfSection() { return "Unk"; } std::string GetConfSection();
std::string GetBindingConfSection() { return "Unk"; } std::string GetBindingConfSection();
}; };
} }

View File

@ -0,0 +1,5 @@
#include "Hooks.h"
namespace Ship {
}

View File

@ -7,7 +7,7 @@
#endif #endif
#include "Hooks.h" #include "Hooks.h"
#include "Window.h" #include "Window.h"
namespace Ship { namespace Ship {
@ -100,4 +100,28 @@ namespace Ship {
const std::string KeyboardController::GetControllerName() { const std::string KeyboardController::GetControllerName() {
return "Keyboard"; return "Keyboard";
} }
bool KeyboardController::Connected() const {
return true;
}
bool KeyboardController::CanRumble() const {
return false;
}
bool KeyboardController::CanGyro() const {
return false;
}
void KeyboardController::ClearRawPress() {
lastKey = -1;
}
void KeyboardController::SetLastScancode(int32_t key) {
lastScancode = key;
}
int32_t KeyboardController::GetLastScancode() {
return lastScancode;
}
} }

View File

@ -9,26 +9,18 @@ namespace Ship {
void ReadFromSource(int32_t virtualSlot) override; void ReadFromSource(int32_t virtualSlot) override;
void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) override; void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) override;
bool Connected() const override { return true; }
bool CanRumble() const override { return false; }
bool CanGyro() const override { return false; }
const std::string GetControllerName() override; const std::string GetControllerName() override;
const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override; const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override;
bool PressButton(int32_t dwScancode); bool PressButton(int32_t dwScancode);
bool ReleaseButton(int32_t dwScancode); bool ReleaseButton(int32_t dwScancode);
bool Connected() const override;
void ClearRawPress() override { bool CanRumble() const override;
lastKey = -1; bool CanGyro() const override;
} void ClearRawPress() override;
int32_t ReadRawPress() override; int32_t ReadRawPress() override;
void ReleaseAllButtons(); void ReleaseAllButtons();
void SetLastScancode(int32_t key);
void SetLastScancode(int32_t key) { int32_t GetLastScancode();
lastScancode = key;
}
int32_t GetLastScancode() { return lastScancode; }
void CreateDefaultBinding(int32_t virtualSlot) override; void CreateDefaultBinding(int32_t virtualSlot) override;
protected: protected:

View File

@ -333,4 +333,17 @@ namespace Ship {
const std::string* ResourceMgr::HashToString(uint64_t Hash) const { const std::string* ResourceMgr::HashToString(uint64_t Hash) const {
return OTR->HashToString(Hash); return OTR->HashToString(Hash);
} }
std::shared_ptr<Archive> ResourceMgr::GetArchive() {
return OTR;
}
std::shared_ptr<Window> ResourceMgr::GetContext() {
return Context;
}
std::shared_ptr<Resource> ResourceMgr::LoadResource(const std::string& FilePath) {
return LoadResource(FilePath.c_str());
}
} }

View File

@ -23,20 +23,17 @@ namespace Ship {
bool IsRunning(); bool IsRunning();
bool DidLoadSuccessfully(); bool DidLoadSuccessfully();
std::shared_ptr<Archive> GetArchive() { return OTR; } std::shared_ptr<Archive> GetArchive();
std::shared_ptr<Window> GetContext() { return Context; } std::shared_ptr<Window> GetContext();
const std::string* HashToString(uint64_t Hash) const; const std::string* HashToString(uint64_t Hash) const;
void InvalidateResourceCache(); void InvalidateResourceCache();
uint32_t GetGameVersion(); uint32_t GetGameVersion();
void SetGameVersion(uint32_t newGameVersion); void SetGameVersion(uint32_t newGameVersion);
std::shared_ptr<File> LoadFileAsync(const std::string& FilePath); std::shared_ptr<File> LoadFileAsync(const std::string& FilePath);
std::shared_ptr<File> LoadFile(const std::string& FilePath); std::shared_ptr<File> LoadFile(const std::string& FilePath);
std::shared_ptr<Resource> GetCachedFile(const char* FilePath) const; std::shared_ptr<Resource> GetCachedFile(const char* FilePath) const;
std::shared_ptr<Resource> LoadResource(const char* FilePath); std::shared_ptr<Resource> LoadResource(const char* FilePath);
std::shared_ptr<Resource> LoadResource(const std::string& FilePath) { return LoadResource(FilePath.c_str()); } std::shared_ptr<Resource> LoadResource(const std::string& FilePath);
std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> LoadResourceAsync(const char* FilePath); std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> LoadResourceAsync(const char* FilePath);
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(const std::string& SearchMask); std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(const std::string& SearchMask);
std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> CacheDirectoryAsync(const std::string& SearchMask); std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> CacheDirectoryAsync(const std::string& SearchMask);

View File

@ -12,6 +12,10 @@ extern "C" uint8_t __osMaxControllers;
namespace Ship { namespace Ship {
SDLController::SDLController(int32_t physicalSlot) : Controller(), Cont(nullptr), physicalSlot(physicalSlot) {
}
bool SDLController::Open() { bool SDLController::Open() {
const auto NewCont = SDL_GameControllerOpen(physicalSlot); const auto NewCont = SDL_GameControllerOpen(physicalSlot);
@ -450,4 +454,23 @@ namespace Ship {
profile->GyroData[DRIFT_Y] = 0.0f; profile->GyroData[DRIFT_Y] = 0.0f;
profile->GyroData[GYRO_SENSITIVITY] = 1.0f; profile->GyroData[GYRO_SENSITIVITY] = 1.0f;
} }
bool SDLController::Connected() const {
return Cont != nullptr;
}
bool SDLController::CanGyro() const {
return supportsGyro;
}
bool SDLController::CanRumble() const {
#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(2,0,18)
return SDL_GameControllerHasRumble(Cont);
#endif
return false;
}
void SDLController::ClearRawPress() {
}
} }

View File

@ -5,6 +5,19 @@
namespace Ship { namespace Ship {
class SDLController : public Controller { class SDLController : public Controller {
public: public:
SDLController(int32_t physicalSlot);
void ReadFromSource(int32_t virtualSlot) override;
const std::string GetControllerName() override;
const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override;
void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) override;
bool Connected() const override;
bool CanGyro() const override;
bool CanRumble() const override;
bool Open();
void ClearRawPress() override;
int32_t ReadRawPress() override;
protected:
inline static const char* AxisNames[] = { inline static const char* AxisNames[] = {
"Left Stick X", "Left Stick X",
"Left Stick Y", "Left Stick Y",
@ -15,25 +28,6 @@ namespace Ship {
"Start Button" "Start Button"
}; };
SDLController(int32_t physicalSlot) : Controller(), Cont(nullptr), physicalSlot(physicalSlot) { }
void ReadFromSource(int32_t virtualSlot) override;
const std::string GetControllerName() override;
const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override;
void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) override;
bool Connected() const override { return Cont != nullptr; }
bool CanGyro() const override { return supportsGyro; }
bool CanRumble() const override {
#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(2,0,18)
return SDL_GameControllerHasRumble(Cont);
#endif
return false;
}
bool Open();
void ClearRawPress() override {}
int32_t ReadRawPress() override;
protected:
void CreateDefaultBinding(int32_t virtualSlot) override; void CreateDefaultBinding(int32_t virtualSlot) override;
private: private:

View File

@ -581,4 +581,52 @@ namespace Ship {
saveFile.close(); saveFile.close();
} }
bool Window::IsFullscreen() {
return bIsFullscreen;
}
uint32_t Window::GetMenuBar() {
return dwMenubar;
}
void Window::SetMenuBar(uint32_t dwMenuBar) {
this->dwMenubar = dwMenuBar;
}
std::string Window::GetName() {
return Name;
}
std::shared_ptr<ControlDeck> Window::GetControlDeck() {
return ControllerApi;
}
std::shared_ptr<AudioPlayer> Window::GetAudioPlayer() {
return APlayer;
}
std::shared_ptr<ResourceMgr> Window::GetResourceManager() {
return ResMan;
}
std::shared_ptr<Mercury> Window::GetConfig() {
return Config;
}
std::shared_ptr<spdlog::logger> Window::GetLogger() {
return Logger;
}
const char* Window::GetKeyName(int32_t scancode) {
return WmApi->get_key_name(scancode);
}
int32_t Window::GetLastScancode() {
return lastScancode;
}
void Window::SetLastScancode(int32_t scanCode) {
lastScancode = scanCode;
}
} }

View File

@ -36,20 +36,20 @@ namespace Ship {
void ToggleFullscreen(); void ToggleFullscreen();
void SetFullscreen(bool bIsFullscreen); void SetFullscreen(bool bIsFullscreen);
void ShowCursor(bool hide); void ShowCursor(bool hide);
bool IsFullscreen() { return bIsFullscreen; }
uint32_t GetCurrentWidth(); uint32_t GetCurrentWidth();
uint32_t GetCurrentHeight(); uint32_t GetCurrentHeight();
uint32_t GetMenuBar() { return dwMenubar; } bool IsFullscreen();
void SetMenuBar(uint32_t dwMenuBar) { this->dwMenubar = dwMenuBar; } uint32_t GetMenuBar();
std::string GetName() { return Name; } void SetMenuBar(uint32_t dwMenuBar);
std::shared_ptr<ControlDeck> GetControlDeck() { return ControllerApi; }; std::string GetName();
std::shared_ptr<AudioPlayer> GetAudioPlayer() { return APlayer; } std::shared_ptr<ControlDeck> GetControlDeck();
std::shared_ptr<ResourceMgr> GetResourceManager() { return ResMan; } std::shared_ptr<AudioPlayer> GetAudioPlayer();
std::shared_ptr<Mercury> GetConfig() { return Config; } std::shared_ptr<ResourceMgr> GetResourceManager();
std::shared_ptr<spdlog::logger> GetLogger() { return Logger; } std::shared_ptr<Mercury> GetConfig();
const char* GetKeyName(int32_t scancode) { return WmApi->get_key_name(scancode); } std::shared_ptr<spdlog::logger> GetLogger();
int32_t GetLastScancode() { return lastScancode; } const char* GetKeyName(int32_t scancode);
void SetLastScancode(int32_t scanCode) { lastScancode = scanCode; } int32_t GetLastScancode();
void SetLastScancode(int32_t scanCode);
protected: protected:
Window() = default; Window() = default;