Skip to content

Commit

Permalink
Add initial sail implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Oct 5, 2024
1 parent da793a5 commit 796eda0
Show file tree
Hide file tree
Showing 12 changed files with 715 additions and 31 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
- name: Build 2Ship
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DBUILD_NETWORKING=1
cmake --build build-cmake --config Release --parallel 10
(cd build-cmake && cpack)
Expand Down Expand Up @@ -257,6 +257,7 @@ jobs:
SDL2-2.30.3
tinyxml2-10.0.0
libzip-1.10.1
SDL2_net-2.2.0
- name: Install latest SDL
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
Expand All @@ -283,6 +284,18 @@ jobs:
cmake ..
make
sudo make install
- name: Install latest SDL_net
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
if [ ! -d "SDL2_net-2.2.0" ]; then
wget https://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.2.0.tar.gz
tar -xzf SDL2_net-2.2.0.tar.gz
fi
cd SDL2_net-2.2.0
./configure
make -j 10
sudo make install
sudo cp -av /usr/local/lib/libSDL* /lib/x86_64-linux-gnu/
- name: Install libzip without crypto
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
Expand All @@ -305,7 +318,7 @@ jobs:
- name: Build 2Ship
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_REMOTE_CONTROL=1
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_NETWORKING=1
cmake --build build-cmake --config Release -j3
(cd build-cmake && cpack -G External)
Expand Down Expand Up @@ -365,7 +378,7 @@ jobs:
VCPKG_ROOT: ${{github.workspace}}/vcpkg
run: |
set $env:PATH="$env:USERPROFILE/.cargo/bin;$env:PATH"
cmake -S . -B build-windows -G Ninja -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
cmake -S . -B build-windows -G Ninja -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DBUILD_NETWORKING=1
cmake --build build-windows --config Release --parallel 10
(cd build-windows && cpack)
Expand Down
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()
endif()

if (CMAKE_SYSTEM_NAME MATCHES "Windows|Linux")
if(NOT DEFINED BUILD_CROWD_CONTROL)
set(BUILD_CROWD_CONTROL OFF)
endif()
endif()

# Enable the Gfx debugger in LUS to use libgfxd from ZAPDTR
set(GFX_DEBUG_DISASSEMBLER ON)

Expand Down
18 changes: 18 additions & 0 deletions mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "2s2h/Enhancements/Enhancements.h"
#include "2s2h/DeveloperTools/DeveloperTools.h"
#include "HudEditor.h"
#ifdef ENABLE_NETWORKING
#include "2s2h/Network/Sail.h"
#endif

extern "C" {
#include "z64.h"
Expand Down Expand Up @@ -876,6 +879,15 @@ void DrawDeveloperToolsMenu() {
}
}

#ifdef ENABLE_NETWORKING
void DrawRemoteControlMenu() {
if (UIWidgets::BeginMenu("Network")) {
Sail::Instance->DrawMenu();
ImGui::EndMenu();
}
}
#endif

void BenMenuBar::InitElement() {
UpdateWindowBackendObjects();
}
Expand Down Expand Up @@ -909,6 +921,12 @@ void BenMenuBar::DrawElement() {

ImGui::SetCursorPosY(0.0f);

#ifdef ENABLE_NETWORKING
DrawRemoteControlMenu();

ImGui::SetCursorPosY(0.0f);
#endif

ImGui::PopStyleVar(1);
ImGui::EndMenuBar();
}
Expand Down
128 changes: 126 additions & 2 deletions mm/2s2h/BenGui/SearchableMenuItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "variables.h"
#include <variant>
#include <tuple>
#include "ShipUtils.h"
#include "2s2h/Network/Sail.h"

extern "C" {
#include "functions.h"
Expand Down Expand Up @@ -43,7 +45,9 @@ typedef enum {
DISABLE_FOR_MOTION_BLUR_MODE,
DISABLE_FOR_MOTION_BLUR_OFF,
DISABLE_FOR_FRAME_ADVANCE_OFF,
DISABLE_FOR_WARP_POINT_NOT_SET
DISABLE_FOR_WARP_POINT_NOT_SET,
DISABLE_FOR_SAIL_FORM_INVALID,
DISABLE_FOR_SAIL_ENABLED,
} DisableOption;

struct widgetInfo;
Expand All @@ -67,6 +71,8 @@ typedef enum {
WIDGET_CVAR_COMBOBOX,
WIDGET_CVAR_SLIDER_INT,
WIDGET_CVAR_SLIDER_FLOAT,
WIDGET_CVAR_INPUT_TEXT,
WIDGET_CVAR_INPUT_INT,
WIDGET_BUTTON,
WIDGET_COLOR_24, // color picker without alpha
WIDGET_COLOR_32, // color picker with alpha
Expand Down Expand Up @@ -327,7 +333,16 @@ static std::map<DisableOption, disabledInfo> disabledMap = {
"Frame Advance is Disabled" } },
{ DISABLE_FOR_WARP_POINT_NOT_SET,
{ [](disabledInfo& info) -> bool { return !CVarGetInteger(WARP_POINT_CVAR "Saved", 0); },
"Warp Point Not Saved" } }
"Warp Point Not Saved" } },
{ DISABLE_FOR_SAIL_FORM_INVALID,
{ [](disabledInfo& info) -> bool {
return !(!isStringEmpty(CVarGetString("gNetwork.Sail.Host", "127.0.0.1")) &&
CVarGetInteger("gNetwork.Sail.Port", 43384) > 1024 &&
CVarGetInteger("gNetwork.Sail.Port", 43384) < 65535);
},
"Invalid Host/Port" } },
{ DISABLE_FOR_SAIL_ENABLED,
{ [](disabledInfo& info) -> bool { return Sail::Instance->isEnabled; }, "Sail is Enabled" } },
};

std::unordered_map<int32_t, const char*> menuThemeOptions = {
Expand Down Expand Up @@ -692,6 +707,78 @@ void AddSettings() {
WIDGET_WINDOW_BUTTON,
{ .size = UIWidgets::Sizes::Inline, .windowName = "2S2H Input Editor" } } } } });

#ifdef ENABLE_NETWORKING
// Network
settingsSidebar.push_back(
{ "Network",
3,
{ {
{ .widgetName = "Sail", .widgetType = WIDGET_SEPARATOR_TEXT },
{ "Host",
"gNetwork.Sail.Host",
"",
WIDGET_CVAR_INPUT_TEXT,
{ .defaultVariant = "127.0.0.1" },
{},
[](widgetInfo& info) {
if (disabledMap.at(DISABLE_FOR_SAIL_ENABLED).active) {
info.activeDisables.push_back(DISABLE_FOR_SAIL_ENABLED);
}
} },
{ "Port",
"gNetwork.Sail.Port",
"",
WIDGET_CVAR_INPUT_INT,
{ .defaultVariant = 43384 },
{},
[](widgetInfo& info) {
if (disabledMap.at(DISABLE_FOR_SAIL_ENABLED).active) {
info.activeDisables.push_back(DISABLE_FOR_SAIL_ENABLED);
}
} },
{ "Connect",
"",
"Connect/Disconnect to the Sail server.",
WIDGET_BUTTON,
{},
[](widgetInfo& info) {
if (Sail::Instance->isEnabled) {
CVarClear("gNetwork.Sail.Enabled");
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
Sail::Instance->Disable();
} else {
CVarSetInteger("gNetwork.Sail.Enabled", 1);
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
Sail::Instance->Enable();
}
},
[](widgetInfo& info) {
if (Sail::Instance->isEnabled) {
info.widgetName = "Disconnect";
} else {
info.widgetName = "Connect";
}
if (disabledMap.at(DISABLE_FOR_SAIL_FORM_INVALID).active)
info.activeDisables.push_back(DISABLE_FOR_SAIL_FORM_INVALID);
} },
{ "Connected",
"",
"Displays the current connection status.",
WIDGET_TEXT,
{},
{},
[](widgetInfo& info) {
if (Sail::Instance->isEnabled && Sail::Instance->isConnected) {
info.widgetName = "Connected";
} else if (Sail::Instance->isEnabled) {
info.widgetName = "Connecting...";
} else {
info.isHidden = true;
}
} },
} } });
#endif

if (CVarGetInteger("gSettings.SidebarSearch", 0)) {
settingsSidebar.insert(settingsSidebar.begin() + searchSidebarIndex, searchSidebarEntry);
}
Expand Down Expand Up @@ -1575,6 +1662,43 @@ void SearchMenuGetItem(widgetInfo& widget) {
}
}
break;
case WIDGET_CVAR_INPUT_TEXT: {
ImGui::BeginDisabled(disabledValue);
UIWidgets::PushStyleSlider(menuTheme[menuThemeIndex]);
ImGui::PushItemWidth(ImGui::GetWindowWidth());
ImGui::Text(widget.widgetName.c_str());
std::string cvarValue =
CVarGetString(widget.widgetCVar, std::get<const char*>(widget.widgetOptions.defaultVariant));
if (ImGui::InputText(("##" + widget.widgetName).c_str(), (char*)cvarValue.c_str(),
cvarValue.capacity() + 1, 0)) {
CVarSetString(widget.widgetCVar, cvarValue.c_str());
if (widget.widgetCallback != nullptr) {
widget.widgetCallback(widget);
}
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
}
ImGui::PopItemWidth();
UIWidgets::PopStyleSlider();
ImGui::EndDisabled();
} break;
case WIDGET_CVAR_INPUT_INT: {
ImGui::BeginDisabled(disabledValue);
UIWidgets::PushStyleSlider(menuTheme[menuThemeIndex]);
ImGui::PushItemWidth(ImGui::GetWindowWidth());
ImGui::Text(widget.widgetName.c_str());
int32_t cvarValue =
CVarGetInteger(widget.widgetCVar, std::get<int32_t>(widget.widgetOptions.defaultVariant));
if (ImGui::InputInt(("##" + widget.widgetName).c_str(), &cvarValue, NULL, NULL)) {
CVarSetInteger(widget.widgetCVar, cvarValue);
if (widget.widgetCallback != nullptr) {
widget.widgetCallback(widget);
}
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
}
ImGui::PopItemWidth();
UIWidgets::PopStyleSlider();
ImGui::EndDisabled();
} break;
case WIDGET_SLIDER_INT: {
int32_t* pointer = std::get<int32_t*>(widget.widgetOptions.valuePointer);
if (pointer == nullptr) {
Expand Down
29 changes: 16 additions & 13 deletions mm/2s2h/BenPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
//#include <functions.h>
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"

#ifdef ENABLE_CROWD_CONTROL
#include "Enhancements/crowd-control/CrowdControl.h"
CrowdControl* CrowdControl::Instance;
#ifdef ENABLE_NETWORKING
#include "2s2h/Network/Sail.h"
Sail* Sail::Instance;
#endif

#include <libultraship/libultraship.h>
Expand Down Expand Up @@ -512,6 +512,10 @@ extern "C" void InitOTR() {

OTRGlobals::Instance = new OTRGlobals();
GameInteractor::Instance = new GameInteractor();
#ifdef ENABLE_NETWORKING
Sail::Instance = new Sail();
#endif

BenGui::SetupGuiElements();
InitEnhancements();
InitDeveloperTools();
Expand All @@ -533,13 +537,10 @@ extern "C" void InitOTR() {
}

srand(now);
#ifdef ENABLE_CROWD_CONTROL
CrowdControl::Instance = new CrowdControl();
CrowdControl::Instance->Init();
if (CVarGetInteger("gCrowdControl", 0)) {
CrowdControl::Instance->Enable();
} else {
CrowdControl::Instance->Disable();
#ifdef ENABLE_NETWORKING
SDLNet_Init();
if (CVarGetInteger("gNetwork.Sail.Enabled", 0)) {
Sail::Instance->Enable();
}
#endif

Expand All @@ -553,9 +554,11 @@ extern "C" void SaveManager_ThreadPoolWait() {
extern "C" void DeinitOTR() {
SaveManager_ThreadPoolWait();
OTRAudio_Exit();
#ifdef ENABLE_CROWD_CONTROL
CrowdControl::Instance->Disable();
CrowdControl::Instance->Shutdown();
#ifdef ENABLE_NETWORKING
if (CVarGetInteger("gNetwork.Sail.Enabled", 0)) {
Sail::Instance->Disable();
}
SDLNet_Quit();
#endif

// Destroying gui here because we have shared ptrs to LUS objects which output to SPDLOG which is destroyed before
Expand Down
Loading

0 comments on commit 796eda0

Please sign in to comment.