Revamp: Transition HarmonyLink to C++ with DLL support

This transformative commit marks the evolution of HarmonyLink from a Rust-based server-side application to a C++ implemented, C-compatible dynamic link library (DLL). We've restructured the codebase to streamline integration into games, eliminating the need for a server setup by end-users.

Key Changes:
- Introduced .gitattributes and .gitmodules to manage new dependencies and collaborations.
- Replaced the GitHub workflow files with CMake configurations to support the new C++ build system.
- Introduced a comprehensive set of header and implementation files defining the core functionality, platform-specific utilities, and cross-platform compatibility layers.
- Removed all Rust-specific files (Cargo.toml, Cargo.lock, etc.) and references to ensure a clean transition to the C++ environment.
- Implemented new testing mechanisms within HarmonyLinkTest to ensure robustness and reliability of the DLL.
- Excised previous server-side components and models to focus on the DLL's direct integration into consumer applications.

This update is a direct response to community feedback, showcasing our commitment to adaptability and innovation. HarmonyLink 2.0 is now more accessible, efficient, and tailored for diverse gaming environments, providing developers with an unparalleled level of hardware-software harmony.

Please refer to the updated README for more details on the new structure and how to integrate HarmonyLink 2.0 into your projects.
This commit is contained in:
Jordon Brooks 2024-01-07 20:29:47 +00:00
parent d13fc728df
commit 6bf68eb298
No known key found for this signature in database
GPG key ID: 83964894E5D98D57
60 changed files with 1629 additions and 2389 deletions

View file

@ -0,0 +1,143 @@
// Copyright (C) 2023 Jordon Brooks
#include <iostream>
#include <chrono>
#include <thread>
#include <atomic>
#include "HarmonyLinkLib.h"
// Include necessary headers for platform-specific functionality
#ifdef BUILD_WINDOWS
#include <conio.h> // For _kbhit() and _getch()
#include <windows.h> // For system("cls")
#else
#include <unistd.h> // For read()
#include <termios.h> // For termios
#include <stdio.h> // For getchar()
#include <fcntl.h> // For F_GETFL, F_SETFL and O_NONBLOCK
#endif
std::atomic<bool> quitFlag(false);
// Function to clear the screen cross-platform
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
std::cout << "\x1B[2J\x1B[H";
#endif
}
// Function to check if 'q' or 'Q' is pressed in Windows
void checkForQuit() {
while (!quitFlag) {
#ifdef BUILD_WINDOWS
if (_kbhit()) {
const char c = static_cast<char>(_getch());
if (c == 'q' || c == 'Q') {
quitFlag = true;
break;
}
}
#else
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if (ch != EOF) {
ungetc(ch, stdin);
if (ch == 'q' || ch == 'Q') {
quitFlag = true;
break;
}
}
#endif
// Checks for input every roughly 60 frames
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
}
int main()
{
std::cout << "Hello, World!" << '\n';
std::thread inputThread(checkForQuit);
const bool isWine = HarmonyLinkLib::get_is_wine();
const char* test = isWine ? "is" : "isn't";
const HarmonyLinkLib::FOSVerInfo* os_info = HarmonyLinkLib::get_os_version();
const HarmonyLinkLib::FDevice* device_info = HarmonyLinkLib::get_device_info();
const HarmonyLinkLib::FCPUInfo* cpu_info = HarmonyLinkLib::get_cpu_info();
// This loop is to test how stable & expensive these functions are
while (!quitFlag)
{
// Clear the screen
clearScreen();
std::wcout << "This program " << test << " running under wine.\n";
if (cpu_info)
{
cpu_info->print();
}
if (os_info)
{
os_info->print();
}
if (device_info)
{
wprintf(L"Is SteamDeck: %s\n", device_info->device == HarmonyLinkLib::EDevice::STEAM_DECK ? L"true" : L"false");
}
// we can't do this before the loop because we need updated values
if (const HarmonyLinkLib::FBattery* battery = HarmonyLinkLib::get_battery_status())
{
battery->to_string();
battery->free();
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (inputThread.joinable())
{
inputThread.join();
}
if (os_info)
{
os_info->free();
}
if (device_info)
{
device_info->free();
}
if (cpu_info)
{
cpu_info->free();
}
return 0;
}