Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse Support #4673

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0a16951
mouse
lilacLunatic Jul 2, 2023
5c4a3f7
(mouse) small fix
lilacLunatic Jul 2, 2023
cb576e5
"fix" implicit declaration
lilacLunatic Jul 7, 2023
3034179
LUS 1.2
lilacLunatic Jul 28, 2023
e6d450e
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Jul 28, 2023
a8a29a9
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Aug 11, 2023
1e2d660
Merge tag '8.0.3' of https://github.com/HarbourMasters/Shipwright int…
lilacLunatic Dec 17, 2023
3b6fca2
Merge tag '8.0.4' of https://github.com/HarbourMasters/Shipwright int…
lilacLunatic Dec 18, 2023
33609d0
empty commit to force CI re-run
lilacLunatic Apr 20, 2024
228a64c
Merge branch 'mouse' into HEAD
lilacLunatic Aug 15, 2024
734134e
include new mouse LUS
lilacLunatic Aug 15, 2024
1113f2f
deleted: soh/soh/Enhancements/controls/GameControlEditor.cpp
lilacLunatic Aug 21, 2024
a156632
[mouse]LUS
lilacLunatic Aug 22, 2024
d24981e
fix input viewer header
lilacLunatic Aug 22, 2024
4ef40b8
Merge branch 'mouse' into HEAD
lilacLunatic Oct 18, 2024
7a8d2a7
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Nov 18, 2024
02a259e
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Dec 10, 2024
d02668a
Bump LUS for mouse support
lilacLunatic Dec 10, 2024
df80c4c
Mouse Support
lilacLunatic Dec 12, 2024
addd23b
Comment cleanup
lilacLunatic Dec 12, 2024
31588b2
Adding the actual mouse enhancement files
lilacLunatic Dec 12, 2024
5bf27ca
Fix (?) Windows and Mac builds
lilacLunatic Dec 12, 2024
b67e4b6
Maybe fix MacOS now
lilacLunatic Dec 12, 2024
0ea05d1
Why was it compiling with this??
lilacLunatic Dec 12, 2024
cb8f4aa
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Dec 28, 2024
e8f5b70
Mouse input viewer handling
lilacLunatic Dec 30, 2024
7e797e2
[Mouse] LUS bump
lilacLunatic Dec 30, 2024
45bcb27
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Dec 30, 2024
e2cbd38
[mouse] LUS
lilacLunatic Jan 5, 2025
be0de6f
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Jan 5, 2025
2a443c4
(Mouse) bump LUS for dxgi fix
lilacLunatic Jan 5, 2025
9ef3dcc
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Jan 7, 2025
7405721
Merge branch 'develop' of https://github.com/HarbourMasters/Shipwrigh…
lilacLunatic Jan 9, 2025
78d1b35
F2 mouse notif
lilacLunatic Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions soh/include/z64player.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ typedef struct Player {
/* */ u8 ivanFloating;
/* */ u8 ivanDamageMultiplier;
// #endregion

} Player; // size = 0xA94

#endif
115 changes: 115 additions & 0 deletions soh/soh/Enhancements/controls/Mouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "Mouse.h"
#include <Window.h>

static Ship::Coords mouseCoord = {};
static Ship::Coords mouseCoordRel = {};

#define MOUSE_ENABLED (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0) && GetWindow()->IsMouseCaptured())

std::shared_ptr<Ship::Window> GetWindow() {
return OTRGlobals::Instance->context->GetWindow();
}

extern "C" {
void Mouse_UpdatePos() {
mouseCoord = GetWindow()->GetMousePos();
}

void Mouse_UpdatePosRel() {
mouseCoordRel = GetWindow()->GetMouseDelta();
}

void Mouse_UpdateAll() {
Mouse_UpdatePos();
Mouse_UpdatePosRel();
}

void Mouse_HandleThirdPerson(f32* newCamX, f32* newCamY) {
if (MOUSE_ENABLED) {
*newCamX -= mouseCoordRel.x * 40.0f;
*newCamY += mouseCoordRel.y * 40.0f;
}
}

void Mouse_HandleFirstPerson(Player* player, s8 invertXAxisMulti, s8 invertYAxisMulti) {
f32 xAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.X"), 1.0f);
f32 yAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.Y"), 1.0f);
if (MOUSE_ENABLED) {
player->actor.focus.rot.y -= mouseCoordRel.x * 6.0f * xAxisMulti * invertXAxisMulti;
player->actor.focus.rot.x += mouseCoordRel.y * 6.0f * yAxisMulti * invertYAxisMulti;
}
}

void Mouse_RecenterCursor() {
if (MOUSE_ENABLED) {
u32 width = GetWindow()->GetWidth();
u32 height = GetWindow()->GetHeight();
GetWindow()->SetMousePos({(s32) (width/2), (s32) (height/2)});
}
}

void Mouse_HandleShield(f32* sp50, f32* sp54) {
if (MOUSE_ENABLED) {
s32 width = GetWindow()->GetWidth();
s32 height = GetWindow()->GetHeight();
/*
* Y: -12800 ~ +12700
* X: -15360 ~ +15240
*/
f32 xBound = 15360 / ((f32)width / 2);
f32 yBound = 12800 / ((f32)height / 2);
*sp54 += (mouseCoord.y - (height / 2)) * yBound;
*sp50 += (mouseCoord.x - (width / 2)) * xBound * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? 1 : -1);
}
}

static s8 iterMouse = 0;
static f32 mouseQuickspinX[5] = {};
static f32 mouseQuickspinY[5] = {};
static u8 quickspinCount = 0;

void Mouse_UpdateQuickspinCount() {
quickspinCount = (quickspinCount + 1) % 5;

if (MOUSE_ENABLED) {
mouseQuickspinX[quickspinCount] = mouseCoord.x;
mouseQuickspinY[quickspinCount] = mouseCoord.y;
}
}

bool Mouse_HandleQuickspin(s8* iter2, s8* sp3C) {
s8 temp1;
s8 temp2;
s32 i;
if (MOUSE_ENABLED) { //mouse quickspin
s32 willSpin = 1;
for (i = 0; i < 4; i++, iter2++) {
f32 relY = mouseQuickspinY[i + 1] - mouseQuickspinY[i];
f32 relX = mouseQuickspinX[i + 1] - mouseQuickspinX[i];
s16 aTan = Math_Atan2S(relY, -relX);
iterMouse = (u16)(aTan + 0x2000) >> 9;
if ((*iter2 = iterMouse) < 0) {
willSpin = 0;
break;
}
*iter2 *= 2;
}
temp1 = sp3C[0] - sp3C[1];
if (ABS(temp1) < 10) {
willSpin = 0;
}
iter2 = &sp3C[1];
for (i = 1; i < 3; i++, iter2++) {
temp2 = *iter2 - *(iter2 + 1);
if ((ABS(temp2) < 10) || (temp2 * temp1 < 0)) {
willSpin = 0;
break;
} }
if (willSpin) {
return true;
}
}

return false;
}
}; //extern "C"
29 changes: 29 additions & 0 deletions soh/soh/Enhancements/controls/Mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef MOUSE_H
#define MOUSE_H

#pragma once

#include "soh/OTRGlobals.h"
#include <libultraship/libultraship.h>
#include "z64player.h"
#include "global.h"

#ifdef __cplusplus
extern "C" {
#endif
void Mouse_UpdatePos();
void Mouse_UpdatePosRel();
void Mouse_UpdatePosWheel();
void Mouse_UpdateAll();
void Mouse_RecenterCursor();
void Mouse_HandleThirdPerson(f32* newCamX, f32* newCamY);
void Mouse_HandleFirstPerson(Player* player, s8 invertXAxisMulti, s8 invertYAxisMulti);
void Mouse_HandleShield(f32* sp50, f32* sp54);
bool Mouse_HandleQuickspin(s8* iter2, s8* sp3C);
void Mouse_UpdateQuickspinCount();
#ifdef __cplusplus
}; //extern "C"
#endif

//MOUSE_H
#endif
56 changes: 55 additions & 1 deletion soh/soh/Enhancements/controls/SohInputEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void SohInputEditorWindow::InitElement() {
mDeviceIndexVisiblity.clear();
mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Keyboard] = true;
mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Blue] = true;
mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse] = true;
for (auto index = 1; index < Ship::ShipDeviceIndex::Max; index++) {
mDeviceIndexVisiblity[static_cast<Ship::ShipDeviceIndex>(index)] = false;
}
Expand Down Expand Up @@ -176,6 +177,9 @@ void SohInputEditorWindow::DrawAnalogPreview(const char* label, ImVec2 stick, fl
#define BUTTON_COLOR_KEYBOARD_BEIGE ImVec4(0.651f, 0.482f, 0.357f, 0.5f)
#define BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED ImVec4(0.651f, 0.482f, 0.357f, 1.0f)

#define BUTTON_COLOR_MOUSE_BEIGE ImVec4(0.5f, 0.5f, 0.5f, 0.5f)
#define BUTTON_COLOR_MOUSE_BEIGE_HOVERED ImVec4(0.5f, 0.5f, 0.5f, 1.0f)

#define BUTTON_COLOR_GAMEPAD_BLUE ImVec4(0.0f, 0.255f, 0.976f, 0.5f)
#define BUTTON_COLOR_GAMEPAD_BLUE_HOVERED ImVec4(0.0f, 0.255f, 0.976f, 1.0f)

Expand All @@ -198,6 +202,10 @@ void SohInputEditorWindow::GetButtonColorsForLUSDeviceIndex(Ship::ShipDeviceInde
buttonColor = BUTTON_COLOR_KEYBOARD_BEIGE;
buttonHoveredColor = BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED;
break;
case Ship::ShipDeviceIndex::Mouse:
buttonColor = BUTTON_COLOR_MOUSE_BEIGE;
buttonHoveredColor = BUTTON_COLOR_MOUSE_BEIGE_HOVERED;
break;
case Ship::ShipDeviceIndex::Blue:
buttonColor = BUTTON_COLOR_GAMEPAD_BLUE;
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_BLUE_HOVERED;
Expand Down Expand Up @@ -277,6 +285,7 @@ void SohInputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, N64Butt
icon = ICON_FA_GAMEPAD;
break;
case MAPPING_TYPE_KEYBOARD:
case MAPPING_TYPE_MOUSE:
icon = ICON_FA_KEYBOARD_O;
break;
case MAPPING_TYPE_UNKNOWN:
Expand Down Expand Up @@ -1259,6 +1268,7 @@ void SohInputEditorWindow::DrawGyroSection(uint8_t port) {
void SohInputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set<N64ButtonMask> bitmasks) {
std::set<Ship::ShipDeviceIndex> allLusDeviceIndices;
allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Keyboard);
allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Mouse);
for (auto [lusIndex, mapping] : Ship::Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
Expand Down Expand Up @@ -1307,6 +1317,7 @@ void SohInputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set<N64
void SohInputEditorWindow::DrawAnalogStickDeviceIcons(uint8_t portIndex, Ship::StickIndex stickIndex) {
std::set<Ship::ShipDeviceIndex> allLusDeviceIndices;
allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Keyboard);
allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Mouse);
for (auto [lusIndex, mapping] : Ship::Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
Expand Down Expand Up @@ -1345,7 +1356,7 @@ void SohInputEditorWindow::DrawAnalogStickDeviceIcons(uint8_t portIndex, Ship::S
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor);
ImGui::SameLine();
if (lusIndex == Ship::ShipDeviceIndex::Keyboard) {
if (lusIndex == Ship::ShipDeviceIndex::Keyboard || lusIndex == Ship::ShipDeviceIndex::Mouse) {
ImGui::SmallButton(ICON_FA_KEYBOARD_O);
} else {
ImGui::SmallButton(connected ? ICON_FA_GAMEPAD : ICON_FA_CHAIN_BROKEN);
Expand Down Expand Up @@ -1570,6 +1581,7 @@ void SohInputEditorWindow::DrawOcarinaControlPanel() {
void SohInputEditorWindow::DrawCameraControlPanel() {
ImVec2 cursor = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(cursor.x + 5, cursor.y + 5));
UIWidgets::PaddedEnhancementCheckbox("Enable Mouse", CVAR_SETTING("EnableMouse"));
Ship::GuiWindow::BeginGroupPanel("Aiming/First-Person Camera", ImGui::GetContentRegionAvail());
UIWidgets::PaddedEnhancementCheckbox("Right Stick Aiming", CVAR_SETTING("Controls.RightStickAim"));
UIWidgets::Tooltip("Allows for aiming with the right stick in:\n-First-Person/C-Up view\n-Weapon Aiming");
Expand Down Expand Up @@ -1691,6 +1703,19 @@ void SohInputEditorWindow::DrawDeviceVisibilityButtons() {
ImGui::PopStyleColor();
ImGui::PopStyleColor();

auto mouseButtonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button);
auto mouseButtonHoveredColor = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered);
GetButtonColorsForLUSDeviceIndex(Ship::ShipDeviceIndex::Mouse, mouseButtonColor, mouseButtonHoveredColor);
ImGui::PushStyleColor(ImGuiCol_Button, mouseButtonColor);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, mouseButtonHoveredColor);
bool mouseVisible = mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse];
if (ImGui::Button(StringHelper::Sprintf("%s %s Mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH,
ICON_FA_KEYBOARD_O)
.c_str())) {
mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse] = !mouseVisible;
}
ImGui::PopStyleColor();
ImGui::PopStyleColor();

for (auto [lusIndex, info] : indexMappings) {
auto [name, sdlIndex] = info;
Expand Down Expand Up @@ -1823,6 +1848,8 @@ void SohInputEditorWindow::DrawLinkTab() {
UIWidgets::PaddedEnhancementSliderFloat("Swim Modifier 2: %.0f %%", "##SwimMod2",
CVAR_SETTING("WalkModifier.SwimMapping2"), 0.0f, 5.0f, "", 1.0f,
true, true, false, true);


Ship::GuiWindow::EndGroupPanel(0);
Ship::GuiWindow::EndGroupPanel(0);
}
Expand Down Expand Up @@ -2049,6 +2076,33 @@ void SohInputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) {
}
ImGui::EndPopup();
}
ImGui::PushStyleColor(ImGuiCol_Button, BUTTON_COLOR_MOUSE_BEIGE);

ImGui::PushStyleColor(ImGuiCol_ButtonHovered, BUTTON_COLOR_MOUSE_BEIGE_HOVERED);
if (ImGui::Button(StringHelper::Sprintf("%s Mouse", ICON_FA_KEYBOARD_O).c_str())) {
ImGui::OpenPopup("Set Defaults for Mouse");
}
ImGui::PopStyleColor();
ImGui::PopStyleColor();
if (ImGui::BeginPopupModal("Set Defaults for Mouse", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("This will clear all existing mappings for\nMouse on port %d.\n\nContinue?", portIndex + 1);
if (ImGui::Button("Cancel")) {
shouldClose = true;
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Set defaults")) {
Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(portIndex)
->ClearAllMappingsForDevice(Ship::ShipDeviceIndex::Mouse);
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings(
Ship::ShipDeviceIndex::Mouse);
shouldClose = true;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}

for (auto [lusIndex, info] : indexMappings) {
auto [name, sdlIndex] = info;

Expand Down
1 change: 1 addition & 0 deletions soh/soh/SohGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ namespace SohGui {
Notification::Emit({ .message = "Press - to access enhancements menu", .remainingTime = 10.0f });
#else
Notification::Emit({ .message = "Press F1 to access enhancements menu", .remainingTime = 10.0f });
Notification::Emit({ .message = "Press F2 to enable mouse controls", .remainingTime = 10.0f });
#endif
}

Expand Down
5 changes: 5 additions & 0 deletions soh/src/code/padmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>

#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/controls/Mouse.h"
#include "soh/OTRGlobals.h"
#include "soh/ResourceManagerHelpers.h"

Expand Down Expand Up @@ -270,6 +271,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
input->cur.button = 0;
input->cur.stick_x = 0;
input->cur.stick_y = 0;

input->cur.err_no = padnow1->err_no;
if (padMgr->ctrlrIsConnected[i]) {
padMgr->ctrlrIsConnected[i] = false;
Expand Down Expand Up @@ -304,6 +306,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
input->press.right_stick_x += (s8)(input->cur.right_stick_x - input->prev.right_stick_x);
input->press.right_stick_y += (s8)(input->cur.right_stick_y - input->prev.right_stick_y);
// #endregion

}

uint8_t rumble = (padMgr->rumbleEnable[0] > 0);
Expand All @@ -324,6 +327,8 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) {
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
osContGetReadData(padMgr->pads);

Mouse_UpdateAll();

for (i = 0; i < __osMaxControllers; i++) {
padMgr->padStatus[i].status = Controller_ShouldRumble(i);
}
Expand Down
16 changes: 14 additions & 2 deletions soh/src/code/z_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "overlays/actors/ovl_En_Horse/z_en_horse.h"

#include "soh/frame_interpolation.h"
#include "soh/Enhancements/controls/Mouse.h"

s16 Camera_ChangeSettingFlags(Camera* camera, s16 setting, s16 flags);
s32 Camera_ChangeModeFlags(Camera* camera, s16 mode, u8 flags);
Expand Down Expand Up @@ -1422,6 +1423,8 @@ s32 SetCameraManual(Camera* camera) {
f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f;
f32 newCamY = D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f;

Mouse_HandleThirdPerson(&newCamX, &newCamY);

if ((fabsf(newCamX) >= 15.0f || fabsf(newCamY) >= 15.0f) && camera->play->manualCamera == false) {
camera->play->manualCamera = true;

Expand Down Expand Up @@ -1485,8 +1488,17 @@ s32 Camera_Free(Camera* camera) {

camera->animState = 0;

f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f * (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.X"), 1.0f));
f32 newCamY = D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f * (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.Y"), 1.0f));
f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f;
f32 newCamY = +D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f;

/* Disable mouse movement when holding down the shield */
if (!(camera->player->stateFlags1 & 0x400000)) {
Mouse_HandleThirdPerson(&newCamX, &newCamY);
}

newCamX *= (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.X"), 1.0f));
newCamY *= (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.Y"), 1.0f));

bool invertXAxis = (CVarGetInteger(CVAR_SETTING("FreeLook.InvertXAxis"), 0) && !CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0)) || (!CVarGetInteger(CVAR_SETTING("FreeLook.InvertXAxis"), 0) && CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0));

camera->play->camX += newCamX * (invertXAxis ? -1 : 1);
Expand Down
Loading