From 94ce3146c52b722356588d9e18401215224d9a05 Mon Sep 17 00:00:00 2001 From: Karutoh Date: Mon, 5 Feb 2024 21:06:48 -0800 Subject: [PATCH] Added vcpkg and fixed Windows build. --- .gitea/workflows/BuildRelease.yaml | 4 +-- CMakeLists.txt | 1 - CMakePresets.json | 12 +++++++++ include/ehs/io/hid/Keyboard.h | 6 ++--- include/ehs/io/socket/TCP_W32.h | 2 +- include/ehs/io/socket/UDP_W32.h | 16 ++++++------ src/io/COM.cpp | 2 +- src/io/FileMonitor_W32.cpp | 2 +- src/io/File_W32.cpp | 2 +- src/io/Window_W32.cpp | 42 ++++++++++++++++++------------ src/io/audio/AudioDevice_W32.cpp | 2 +- src/io/socket/TCP_W32.cpp | 6 ++--- src/io/socket/UDP_W32.cpp | 18 +++++++------ src/system/Mutex_W32.cpp | 2 +- src/system/Open_W32.cpp | 2 +- src/system/Semaphore_W32.cpp | 2 +- src/system/System_W32.cpp | 2 +- vcpkg-configuration.json | 14 ++++++++++ vcpkg.json | 6 +++++ 19 files changed, 93 insertions(+), 50 deletions(-) create mode 100644 CMakePresets.json create mode 100644 vcpkg-configuration.json create mode 100644 vcpkg.json diff --git a/.gitea/workflows/BuildRelease.yaml b/.gitea/workflows/BuildRelease.yaml index d2c15c5..a939fd7 100644 --- a/.gitea/workflows/BuildRelease.yaml +++ b/.gitea/workflows/BuildRelease.yaml @@ -23,7 +23,7 @@ jobs: - name: Building/Compiling/Installing Project run: | cd ${{ gitea.workspace }} - cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . + cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . cmake --build . --config Release cmake --install . @@ -65,7 +65,7 @@ jobs: - name: Building/Compiling/Installing Project run: | cd ${{ gitea.workspace }} - cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . + cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . cmake --build . --config Release cmake --install . diff --git a/CMakeLists.txt b/CMakeLists.txt index bba26d5..371ea15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,7 +171,6 @@ if (IS_OS_WINDOWS) src/system/Mutex_W32.cpp include/ehs/system/Mutex_W32.h src/system/Open_W32.cpp include/ehs/system/Open_W32.h src/io/audio/audioDevice_W32.cpp include/ehs/io/audio/audioDevice_W32.h - src/io/MsgBox.cpp include/ehs/io/MsgBox.h src/io/File_W32.cpp include/ehs/io/File_W32.h src/io/FileMonitor_W32.cpp include/ehs/io/FileMonitor_W32.h src/io/Window_W32.cpp include/ehs/io/Window_W32.h diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..afabfde --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,12 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + } + ] +} \ No newline at end of file diff --git a/include/ehs/io/hid/Keyboard.h b/include/ehs/io/hid/Keyboard.h index fb15cf8..7dc13c3 100644 --- a/include/ehs/io/hid/Keyboard.h +++ b/include/ehs/io/hid/Keyboard.h @@ -13,7 +13,7 @@ namespace ehs public: Keyboard(); - Keyboard(Str_8 name, const UInt_64 id); + Keyboard(Str_8 name, UInt_64 id); Keyboard(Keyboard&& hid) noexcept = default; @@ -114,8 +114,8 @@ namespace ehs static const Button Up; static const Button Down; - static Button TranslateScanCode(const UInt_32 code); + static Button TranslateScanCode(UInt_32 code); - static Char_8 TranslateToEnglish_8(const bool shifted, const Button& button); + static Char_8 TranslateToEnglish_8(bool shifted, const Button& button); }; } diff --git a/include/ehs/io/socket/TCP_W32.h b/include/ehs/io/socket/TCP_W32.h index b949158..edc9258 100644 --- a/include/ehs/io/socket/TCP_W32.h +++ b/include/ehs/io/socket/TCP_W32.h @@ -22,7 +22,7 @@ namespace ehs /// Default members initialization. TCP(); - TCP(const AddrType addrType); + TCP(AddrType addrType); TCP(TCP&& tcp) noexcept; diff --git a/include/ehs/io/socket/UDP_W32.h b/include/ehs/io/socket/UDP_W32.h index 992efc0..4475707 100644 --- a/include/ehs/io/socket/UDP_W32.h +++ b/include/ehs/io/socket/UDP_W32.h @@ -41,7 +41,7 @@ namespace ehs /// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. /// @param [in] port The port to bind to. /// @note Requires the port given to be forwarded if this is called. - void Bind(const Str_8& address, const UInt_16 port) override; + void Bind(AddrType type, const Str_8& address, UInt_16 port) override; /// Sends data using a C-style byte array. /// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. @@ -49,7 +49,7 @@ namespace ehs /// @param [in] data The C-style byte array to send. /// @param [in] size The size of the C-style byte array. /// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6". - UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) override; + UInt_64 Send(AddrType type, const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size) override; /// Receives data using the packet helper class. /// @param [out] addr The Ipv4 or Ipv6 address of the sender. @@ -58,11 +58,11 @@ namespace ehs /// @param [in] size The size of the pre-allocated C-style byte array. /// @returns The size of the data received. /// @warning The provided C-style byte array must be freed when finished using. - UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override; + UInt_64 Receive(AddrType* type, Str_8* addr, UInt_16* port, Byte* data, UInt_64 size) override; /// Sets whether or not receiving data blocks the next task. /// @param [in] blocking Whether or not to block. - void SetBlocking(const bool blocking) override; + void SetBlocking(bool blocking) override; /// Retrieves whether or not this socket will block when receiving data. /// @returns The result. @@ -71,12 +71,12 @@ namespace ehs bool IsValid() const override; private: - void Bind_v6(const Str_8& address, const UInt_16 port); + void Bind_v6(const Str_8& address, UInt_16 port); - void Bind_v4(const Str_8& address, const UInt_16 port); + void Bind_v4(const Str_8& address, UInt_16 port); - UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size); + UInt_64 Send_v6(const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size); - UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size); + UInt_64 Send_v4(const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size); }; } \ No newline at end of file diff --git a/src/io/COM.cpp b/src/io/COM.cpp index ec49844..c512ce9 100644 --- a/src/io/COM.cpp +++ b/src/io/COM.cpp @@ -1,4 +1,4 @@ -#include "io/COM.h" +#include "ehs/io/COM.h" #include "ehs/Str.h" #include "ehs/Log.h" diff --git a/src/io/FileMonitor_W32.cpp b/src/io/FileMonitor_W32.cpp index c3733a6..d3f6e1c 100644 --- a/src/io/FileMonitor_W32.cpp +++ b/src/io/FileMonitor_W32.cpp @@ -1,4 +1,4 @@ -#include "io/FileMonitor_W32.h" +#include "ehs/io/FileMonitor_W32.h" #include "ehs/Log.h" #include "ehs/UTF.h" diff --git a/src/io/File_W32.cpp b/src/io/File_W32.cpp index 275293d..c22c69a 100644 --- a/src/io/File_W32.cpp +++ b/src/io/File_W32.cpp @@ -1,4 +1,4 @@ -#include "io/File_W32.h" +#include "ehs/io/File_W32.h" namespace ehs { diff --git a/src/io/Window_W32.cpp b/src/io/Window_W32.cpp index e4838fb..3ed1165 100644 --- a/src/io/Window_W32.cpp +++ b/src/io/Window_W32.cpp @@ -1,7 +1,7 @@ -#include "io/Window_W32.h" -#include "io/hid/Keyboard.h" -#include "io/hid/Mouse.h" -#include "system/Thread.h" +#include "ehs/io/Window_W32.h" +#include "ehs/io/hid/Keyboard.h" +#include "ehs/io/hid/Mouse.h" +#include "ehs/system/Thread.h" #include @@ -108,16 +108,16 @@ namespace ehs if (!keyboard) { UInt_32 bufferSize; - GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, NULL, &bufferSize); + GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, NULL, &bufferSize); Char_16* deviceName = new Char_16[bufferSize]; - if (GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) + if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) { - EHS_LOG_INT("Error, 0, "Failed to retrieve device name."); - return; + EHS_LOG_INT("Error", 0, "Failed to retrieve device name."); + return 0; } - keyboard = new Keyboard(UTF::To_8(deviceName, bufferSize), (UInt_64)raw->header.hDevice); + keyboard = new Keyboard(UTF::To_8(deviceName, (UInt_64)bufferSize), (UInt_64)raw->header.hDevice); win->ih.AddDevice(keyboard); } @@ -134,16 +134,16 @@ namespace ehs if (!mouse) { UInt_32 bufferSize; - GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, NULL, &bufferSize); + GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, nullptr, &bufferSize); Char_16* deviceName = new Char_16[bufferSize]; - if (GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) + if (GetRawInputDeviceInfo(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &bufferSize) < 0) { - EHS_LOG_INT("Error, 1, "Failed to retrieve device name."); - return; + EHS_LOG_INT("Error", 1, "Failed to retrieve device name."); + return 0; } - mouse = new Mouse(UTF::To_8(deviceName, bufferSize), (UInt_64)raw->header.hDevice); + mouse = new Mouse(UTF::To_8(deviceName, (UInt_64)bufferSize), (UInt_64)raw->header.hDevice); win->ih.AddDevice(mouse); } @@ -172,9 +172,19 @@ namespace ehs else if (code == RI_MOUSE_BUTTON_5_UP) mouse->ButtonUp(Mouse::Five); else if (code == RI_MOUSE_WHEEL) - mouse->SetScroll({mouse->GetScroll().x, (SInt_8)raw->data.mouse.usButtonData}); + { + if (raw->data.mouse.usButtonData < 0) + mouse->ButtonDown(Mouse::ScrollDown); + else if (raw->data.mouse.usButtonData > 0) + mouse->ButtonDown(Mouse::ScrollUp); + } else if (code == RI_MOUSE_HWHEEL) - mouse->SetScroll({(SInt_8)raw->data.mouse.usButtonData, mouse->GetScroll().y}); + { + if (raw->data.mouse.usButtonData < 0) + mouse->ButtonDown(Mouse::ScrollLeft); + else if (raw->data.mouse.usButtonData > 0) + mouse->ButtonDown(Mouse::ScrollRight); + } } delete[] data; diff --git a/src/io/audio/AudioDevice_W32.cpp b/src/io/audio/AudioDevice_W32.cpp index 8c71ff2..2effd94 100644 --- a/src/io/audio/AudioDevice_W32.cpp +++ b/src/io/audio/AudioDevice_W32.cpp @@ -1,4 +1,4 @@ -#include "io/audio/AudioDevice_W32.h" +#include "ehs/io/audio/AudioDevice_W32.h" #include "ehs/Log.h" namespace ehs diff --git a/src/io/socket/TCP_W32.cpp b/src/io/socket/TCP_W32.cpp index 21062e7..1e7ae07 100644 --- a/src/io/socket/TCP_W32.cpp +++ b/src/io/socket/TCP_W32.cpp @@ -1,5 +1,5 @@ -#include "io/socket/TCP_W32.h" -#include "io/socket/DNS.h" +#include "ehs/io/socket/TCP_W32.h" +#include "ehs/io/socket/DNS.h" #include #include @@ -242,7 +242,7 @@ namespace ehs return; remoteHostName = address; - remoteAddr = DNS::Resolve(addrType, address); + remoteAddr = DNS::Resolve(address); remotePort = port; if (addrType == AddrType::IPV6) diff --git a/src/io/socket/UDP_W32.cpp b/src/io/socket/UDP_W32.cpp index 96d799a..3815b3d 100644 --- a/src/io/socket/UDP_W32.cpp +++ b/src/io/socket/UDP_W32.cpp @@ -1,4 +1,4 @@ -#include "io/socket/UDP_W32.h" +#include "ehs/io/socket/UDP_W32.h" #include "ehs/Log.h" #include @@ -110,14 +110,14 @@ namespace ehs bound = false; } - void UDP::Bind(const Str_8& address, const UInt_16 port) + void UDP::Bind(const AddrType type, const Str_8& address, const UInt_16 port) { if (!IsValid() || bound) return; - if (addrType == AddrType::IPV6) + if (type == AddrType::IPV6) Bind_v6(address, port); - else if (addrType == AddrType::IPV4) + else if (type == AddrType::IPV4) Bind_v4(address, port); this->address = address; @@ -126,17 +126,17 @@ namespace ehs bound = true; } - UInt_64 UDP::Send(const Str_8& address, const UInt_16 port, const Byte *const data, const UInt_64 size) + UInt_64 UDP::Send(const AddrType type, const Str_8& address, const UInt_16 port, const Byte *const data, const UInt_64 size) { - if (addrType == AddrType::IPV6) + if (type == AddrType::IPV6) return Send_v6(address, port, data, size); - else if (addrType == AddrType::IPV4) + else if (type == AddrType::IPV4) return Send_v4(address, port, data, size); return 0; } - UInt_64 UDP::Receive(Str_8* const address, UInt_16* const port, Byte* const data, const UInt_64 size) + UInt_64 UDP::Receive(AddrType* type, Str_8* const address, UInt_16* const port, Byte* const data, const UInt_64 size) { if (!IsValid()) { @@ -174,6 +174,7 @@ namespace ehs return received; } + *type = AddrType::IPV6; *address = tmpAddr; *port = ntohs(remote.sin6_port); } @@ -190,6 +191,7 @@ namespace ehs return received; } + *type = AddrType::IPV4; *address = tmpAddr; *port = ntohs(((sockaddr_in*)&remote)->sin_port); } diff --git a/src/system/Mutex_W32.cpp b/src/system/Mutex_W32.cpp index 2d28131..99579c6 100644 --- a/src/system/Mutex_W32.cpp +++ b/src/system/Mutex_W32.cpp @@ -1,4 +1,4 @@ -#include "system/Mutex_W32.h" +#include "ehs/system/Mutex_W32.h" #include "ehs/Str.h" #include "ehs/Log.h" diff --git a/src/system/Open_W32.cpp b/src/system/Open_W32.cpp index b2b579c..0170b2d 100644 --- a/src/system/Open_W32.cpp +++ b/src/system/Open_W32.cpp @@ -1,4 +1,4 @@ -#include "system/Open_W32.h" +#include "ehs/system/Open_W32.h" namespace ehs { diff --git a/src/system/Semaphore_W32.cpp b/src/system/Semaphore_W32.cpp index 5f001b2..c990ec6 100644 --- a/src/system/Semaphore_W32.cpp +++ b/src/system/Semaphore_W32.cpp @@ -1,4 +1,4 @@ -#include "system/Semaphore_W32.h" +#include "ehs/system/Semaphore_W32.h" #include "ehs/UTF.h" #include "ehs/Log.h" diff --git a/src/system/System_W32.cpp b/src/system/System_W32.cpp index 0cb4dd0..1029f1d 100644 --- a/src/system/System_W32.cpp +++ b/src/system/System_W32.cpp @@ -1,4 +1,4 @@ -#include "system/System_W32.h" +#include "ehs/system/System_W32.h" #include diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..427355d --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "42bb0d9e8d4cf33485afb9ee2229150f79f61a1f", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..e769101 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ + "openssl", + "zlib" + ] +}