From 80863fc7f287af134334cc8d2edbc9a4ed8494af Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Wed, 24 Aug 2022 22:11:33 -0400 Subject: [PATCH] Moves class member functions from headers to compilation units. --- libultraship/libultraship/CMakeLists.txt | 1 + libultraship/libultraship/Console.cpp | 16 +++++ libultraship/libultraship/Console.h | 9 ++- libultraship/libultraship/ControlDeck.h | 2 +- libultraship/libultraship/Controller.cpp | 12 ++++ libultraship/libultraship/Controller.h | 14 ++--- libultraship/libultraship/DummyController.cpp | 61 +++++++++++++++++++ libultraship/libultraship/DummyController.h | 38 +++++------- libultraship/libultraship/Hooks.cpp | 5 ++ .../libultraship/KeyboardController.cpp | 26 +++++++- .../libultraship/KeyboardController.h | 20 ++---- libultraship/libultraship/ResourceMgr.cpp | 13 ++++ libultraship/libultraship/ResourceMgr.h | 9 +-- libultraship/libultraship/SDLController.cpp | 23 +++++++ libultraship/libultraship/SDLController.h | 32 ++++------ libultraship/libultraship/Window.cpp | 48 +++++++++++++++ libultraship/libultraship/Window.h | 24 ++++---- 17 files changed, 266 insertions(+), 87 deletions(-) create mode 100644 libultraship/libultraship/DummyController.cpp create mode 100644 libultraship/libultraship/Hooks.cpp diff --git a/libultraship/libultraship/CMakeLists.txt b/libultraship/libultraship/CMakeLists.txt index 8f365162d..b59993660 100644 --- a/libultraship/libultraship/CMakeLists.txt +++ b/libultraship/libultraship/CMakeLists.txt @@ -87,6 +87,7 @@ set(Source_Files__Controller "KeyboardController.cpp" "KeyboardController.h" "UltraController.h" + "DummyController.cpp" "DummyController.h" ) diff --git a/libultraship/libultraship/Console.cpp b/libultraship/libultraship/Console.cpp index 846e6e0a0..65ec3ea81 100644 --- a/libultraship/libultraship/Console.cpp +++ b/libultraship/libultraship/Console.cpp @@ -389,4 +389,20 @@ namespace Ship { Commands[command] = entry; } } + + std::string Console::GetCurrentChannel() { + return currentChannel; + } + + bool Console::IsOpened() { + return opened; + } + + void Console::Close() { + opened = false; + } + + void Console::Open() { + opened = true; + } } \ No newline at end of file diff --git a/libultraship/libultraship/Console.h b/libultraship/libultraship/Console.h index 4f846a2c5..91aebb907 100644 --- a/libultraship/libultraship/Console.h +++ b/libultraship/libultraship/Console.h @@ -93,10 +93,9 @@ namespace Ship { void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...); bool HasCommand(const std::string& command); void AddCommand(const std::string& command, CommandEntry entry); - - std::string GetCurrentChannel() { return currentChannel; } - bool IsOpened() { return opened; } - void Close() { opened = false; } - void Open() { opened = true; } + std::string GetCurrentChannel(); + bool IsOpened(); + void Close(); + void Open(); }; } \ No newline at end of file diff --git a/libultraship/libultraship/ControlDeck.h b/libultraship/libultraship/ControlDeck.h index d925020c4..e0e85f27a 100644 --- a/libultraship/libultraship/ControlDeck.h +++ b/libultraship/libultraship/ControlDeck.h @@ -21,7 +21,7 @@ namespace Ship { size_t GetNumVirtualDevices(); uint8_t* GetControllerBits(); private: - std::vector virtualDevices = {}; + std::vector virtualDevices = {}; std::vector> physicalDevices = {}; uint8_t* controllerBits = nullptr; }; diff --git a/libultraship/libultraship/Controller.cpp b/libultraship/libultraship/Controller.cpp index c1d32c2a9..ef2ebe943 100644 --- a/libultraship/libultraship/Controller.cpp +++ b/libultraship/libultraship/Controller.cpp @@ -112,4 +112,16 @@ namespace Ship { std::shared_ptr Controller::getProfile(int32_t virtualSlot) { return profiles[virtualSlot]; } + + std::shared_ptr Controller::GetAttachment() { + return Attachment; + } + + bool Controller::IsRumbling() { + return isRumbling; + } + + std::string Controller::GetGuid() { + return GUID; + } } diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index 76d1c46af..5cd5b8654 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -40,7 +40,6 @@ namespace Ship { public: virtual ~Controller() = default; Controller(); - void Read(OSContPad* pad, int32_t virtualSlot); virtual void ReadFromSource(int32_t virtualSlot) = 0; virtual void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) = 0; virtual bool Connected() const = 0; @@ -49,8 +48,12 @@ namespace Ship { virtual void CreateDefaultBinding(int32_t virtualSlot) = 0; virtual void ClearRawPress() = 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); - std::shared_ptr GetAttachment() { return Attachment; } + std::shared_ptr GetAttachment(); + std::shared_ptr getProfile(int32_t virtualSlot); int8_t& getLeftStickX(int32_t virtualSlot); int8_t& getLeftStickY(int32_t virtualSlot); int8_t& getRightStickX(int32_t virtualSlot); @@ -58,11 +61,8 @@ namespace Ship { int32_t& getPressedButtons(int32_t virtualSlot); float& getGyroX(int32_t virtualSlot); float& getGyroY(int32_t virtualSlot); - std::shared_ptr getProfile(int32_t virtualSlot); - bool IsRumbling() { return isRumbling; } - std::string GetGuid() { return GUID; } - virtual const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) = 0; - virtual const std::string GetControllerName() = 0; + bool IsRumbling(); + std::string GetGuid(); protected: std::shared_ptr Attachment; diff --git a/libultraship/libultraship/DummyController.cpp b/libultraship/libultraship/DummyController.cpp new file mode 100644 index 000000000..fba77edb1 --- /dev/null +++ b/libultraship/libultraship/DummyController.cpp @@ -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; + } +} diff --git a/libultraship/libultraship/DummyController.h b/libultraship/libultraship/DummyController.h index 7e71b7033..c66d83c3d 100644 --- a/libultraship/libultraship/DummyController.h +++ b/libultraship/libultraship/DummyController.h @@ -7,31 +7,25 @@ namespace Ship { class DummyController final : public Controller { public: - DummyController(const std::string& CUID, const std::string& KeyName, bool Connected) { - GUID = CUID; - isConnected = Connected; - ButtonName = KeyName; - } - + DummyController(const std::string& CUID, const std::string& KeyName, bool Connected); std::map, int32_t> ReadButtonPress(); - void ReadFromSource(int32_t slot) override {} - const std::string GetControllerName() override { return GUID; } - const std::string GetButtonName(int slot, int n64Button) override { return ButtonName; } - void WriteToSource(int32_t slot, ControllerCallback* controller) override { } - bool Connected() const override { return isConnected; } - bool CanRumble() const override { return false; } - bool CanGyro() const override { return false; } - - void ClearRawPress() override {} - int32_t ReadRawPress() override { return -1; } - bool HasPadConf() const { return true; } - std::optional GetPadConfSection() { return "Unk"; } - void CreateDefaultBinding(int32_t slot) override {} + 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 slot, ControllerCallback* controller) override; + bool Connected() const override; + bool CanRumble() const override; + bool CanGyro() const override; + void ClearRawPress() override; + int32_t ReadRawPress() override; + bool HasPadConf() const; + std::optional GetPadConfSection(); + void CreateDefaultBinding(int32_t virtualSlot) override; protected: std::string ButtonName; bool isConnected = false; - std::string GetControllerType() { return "Unk"; } - std::string GetConfSection() { return "Unk"; } - std::string GetBindingConfSection() { return "Unk"; } + std::string GetControllerType(); + std::string GetConfSection(); + std::string GetBindingConfSection(); }; } \ No newline at end of file diff --git a/libultraship/libultraship/Hooks.cpp b/libultraship/libultraship/Hooks.cpp new file mode 100644 index 000000000..577801743 --- /dev/null +++ b/libultraship/libultraship/Hooks.cpp @@ -0,0 +1,5 @@ +#include "Hooks.h" + +namespace Ship { + +} diff --git a/libultraship/libultraship/KeyboardController.cpp b/libultraship/libultraship/KeyboardController.cpp index ff0b72b70..88fb0f897 100644 --- a/libultraship/libultraship/KeyboardController.cpp +++ b/libultraship/libultraship/KeyboardController.cpp @@ -7,7 +7,7 @@ #endif #include "Hooks.h" - + #include "Window.h" namespace Ship { @@ -100,4 +100,28 @@ namespace Ship { const std::string KeyboardController::GetControllerName() { 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; + } } diff --git a/libultraship/libultraship/KeyboardController.h b/libultraship/libultraship/KeyboardController.h index 345e34718..6e2a9f5f5 100644 --- a/libultraship/libultraship/KeyboardController.h +++ b/libultraship/libultraship/KeyboardController.h @@ -9,26 +9,18 @@ namespace Ship { void ReadFromSource(int32_t virtualSlot) 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 GetButtonName(int32_t virtualSlot, int32_t n64Button) override; bool PressButton(int32_t dwScancode); bool ReleaseButton(int32_t dwScancode); - - void ClearRawPress() override { - lastKey = -1; - } - + bool Connected() const override; + bool CanRumble() const override; + bool CanGyro() const override; + void ClearRawPress() override; int32_t ReadRawPress() override; void ReleaseAllButtons(); - - void SetLastScancode(int32_t key) { - lastScancode = key; - } - - int32_t GetLastScancode() { return lastScancode; } + void SetLastScancode(int32_t key); + int32_t GetLastScancode(); void CreateDefaultBinding(int32_t virtualSlot) override; protected: diff --git a/libultraship/libultraship/ResourceMgr.cpp b/libultraship/libultraship/ResourceMgr.cpp index 4ca77708a..0bf34ffe8 100644 --- a/libultraship/libultraship/ResourceMgr.cpp +++ b/libultraship/libultraship/ResourceMgr.cpp @@ -333,4 +333,17 @@ namespace Ship { const std::string* ResourceMgr::HashToString(uint64_t Hash) const { return OTR->HashToString(Hash); } + + std::shared_ptr ResourceMgr::GetArchive() { + return OTR; + } + + std::shared_ptr ResourceMgr::GetContext() { + return Context; + } + + std::shared_ptr ResourceMgr::LoadResource(const std::string& FilePath) { + return LoadResource(FilePath.c_str()); + } + } diff --git a/libultraship/libultraship/ResourceMgr.h b/libultraship/libultraship/ResourceMgr.h index e0b0c07cf..f98b8cb8b 100644 --- a/libultraship/libultraship/ResourceMgr.h +++ b/libultraship/libultraship/ResourceMgr.h @@ -23,20 +23,17 @@ namespace Ship { bool IsRunning(); bool DidLoadSuccessfully(); - std::shared_ptr GetArchive() { return OTR; } - std::shared_ptr GetContext() { return Context; } - + std::shared_ptr GetArchive(); + std::shared_ptr GetContext(); const std::string* HashToString(uint64_t Hash) const; - void InvalidateResourceCache(); - uint32_t GetGameVersion(); void SetGameVersion(uint32_t newGameVersion); std::shared_ptr LoadFileAsync(const std::string& FilePath); std::shared_ptr LoadFile(const std::string& FilePath); std::shared_ptr GetCachedFile(const char* FilePath) const; std::shared_ptr LoadResource(const char* FilePath); - std::shared_ptr LoadResource(const std::string& FilePath) { return LoadResource(FilePath.c_str()); } + std::shared_ptr LoadResource(const std::string& FilePath); std::variant, std::shared_ptr> LoadResourceAsync(const char* FilePath); std::shared_ptr>> CacheDirectory(const std::string& SearchMask); std::shared_ptr>> CacheDirectoryAsync(const std::string& SearchMask); diff --git a/libultraship/libultraship/SDLController.cpp b/libultraship/libultraship/SDLController.cpp index d0bb8e1f7..8811b94cb 100644 --- a/libultraship/libultraship/SDLController.cpp +++ b/libultraship/libultraship/SDLController.cpp @@ -12,6 +12,10 @@ extern "C" uint8_t __osMaxControllers; namespace Ship { + SDLController::SDLController(int32_t physicalSlot) : Controller(), Cont(nullptr), physicalSlot(physicalSlot) { + + } + bool SDLController::Open() { const auto NewCont = SDL_GameControllerOpen(physicalSlot); @@ -450,4 +454,23 @@ namespace Ship { profile->GyroData[DRIFT_Y] = 0.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() { + + } } diff --git a/libultraship/libultraship/SDLController.h b/libultraship/libultraship/SDLController.h index e9c696dac..111070843 100644 --- a/libultraship/libultraship/SDLController.h +++ b/libultraship/libultraship/SDLController.h @@ -5,6 +5,19 @@ namespace Ship { class SDLController : public Controller { 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[] = { "Left Stick X", "Left Stick Y", @@ -15,25 +28,6 @@ namespace Ship { "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; private: diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 666c1e0c0..b9e84fd60 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -581,4 +581,52 @@ namespace Ship { 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 Window::GetControlDeck() { + return ControllerApi; + } + + std::shared_ptr Window::GetAudioPlayer() { + return APlayer; + } + + std::shared_ptr Window::GetResourceManager() { + return ResMan; + } + + std::shared_ptr Window::GetConfig() { + return Config; + } + + std::shared_ptr 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; + } } diff --git a/libultraship/libultraship/Window.h b/libultraship/libultraship/Window.h index 6a0e68899..b70587bf5 100644 --- a/libultraship/libultraship/Window.h +++ b/libultraship/libultraship/Window.h @@ -36,20 +36,20 @@ namespace Ship { void ToggleFullscreen(); void SetFullscreen(bool bIsFullscreen); void ShowCursor(bool hide); - bool IsFullscreen() { return bIsFullscreen; } uint32_t GetCurrentWidth(); uint32_t GetCurrentHeight(); - uint32_t GetMenuBar() { return dwMenubar; } - void SetMenuBar(uint32_t dwMenuBar) { this->dwMenubar = dwMenuBar; } - std::string GetName() { return Name; } - std::shared_ptr GetControlDeck() { return ControllerApi; }; - std::shared_ptr GetAudioPlayer() { return APlayer; } - std::shared_ptr GetResourceManager() { return ResMan; } - std::shared_ptr GetConfig() { return Config; } - std::shared_ptr GetLogger() { return Logger; } - const char* GetKeyName(int32_t scancode) { return WmApi->get_key_name(scancode); } - int32_t GetLastScancode() { return lastScancode; } - void SetLastScancode(int32_t scanCode) { lastScancode = scanCode; } + bool IsFullscreen(); + uint32_t GetMenuBar(); + void SetMenuBar(uint32_t dwMenuBar); + std::string GetName(); + std::shared_ptr GetControlDeck(); + std::shared_ptr GetAudioPlayer(); + std::shared_ptr GetResourceManager(); + std::shared_ptr GetConfig(); + std::shared_ptr GetLogger(); + const char* GetKeyName(int32_t scancode); + int32_t GetLastScancode(); + void SetLastScancode(int32_t scanCode); protected: Window() = default;