Skip to content

Commit

Permalink
Merge pull request HarbourMasters#4290 from Archez/macready-golf-merge
Browse files Browse the repository at this point in the history
merge Macready Golf -> develop
  • Loading branch information
Archez authored Aug 14, 2024
2 parents 73be4e5 + 651348d commit 86580fc
Show file tree
Hide file tree
Showing 39 changed files with 338 additions and 161 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")

project(Ship VERSION 8.0.5 LANGUAGES C CXX)
project(Ship VERSION 8.0.6 LANGUAGES C CXX)
include(CMake/soh-cvars.cmake)
include(CMake/lus-cvars.cmake)
set(PROJECT_BUILD_NAME "MacReady Foxtrot" CACHE STRING "")
set(PROJECT_TEAM "github.com/harbourmasters" CACHE STRING "")
set(PROJECT_BUILD_NAME "MacReady Golf" CACHE STRING "" FORCE)
set(PROJECT_TEAM "github.com/harbourmasters" CACHE STRING "" FORCE)

set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT soh)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
Expand Down
4 changes: 4 additions & 0 deletions soh/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,8 @@ void SkelAnime_DrawFlexLod(PlayState* play, void** skeleton, Vec3s* jointTable,
s32 dListIndex);
void SkelAnime_DrawSkeletonOpa(PlayState* play, SkelAnime* skelAnime, OverrideLimbDrawOpa overrideLimbDraw,
PostLimbDrawOpa postLimbDraw, void* arg);
Gfx* SkelAnime_DrawSkeleton2(PlayState* play, SkelAnime* skelAnime, OverrideLimbDrawOpa overrideLimbDraw,
PostLimbDrawOpa postLimbDraw, void* arg, Gfx* gfx);
void SkelAnime_DrawOpa(PlayState* play, void** skeleton, Vec3s* jointTable,
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg);
void SkelAnime_DrawFlexOpa(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount,
Expand Down Expand Up @@ -2462,6 +2464,8 @@ void Message_DrawText(PlayState* play, Gfx** gfxP);

void Interface_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH);
void Interface_RandoRestoreSwordless(void);
s32 Ship_CalcShouldDrawAndUpdate(PlayState* play, Actor* actor, Vec3f* projectedPos, f32 projectedW, bool* shouldDraw,
bool* shouldUpdate);

//Pause Warp
void PauseWarp_HandleSelection();
Expand Down
2 changes: 2 additions & 0 deletions soh/include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,8 @@ typedef struct PlayState {
/* 0x1242B */ u8 unk_1242B;
/* 0x1242C */ SceneTableEntry* loadedScene;
/* 0x12430 */ char unk_12430[0xE8];
// SOH [Custom Models] MTX tracker for flex based skeletons
Mtx** flexLimbOverrideMTX;
} PlayState; // size = 0x12518

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/debugger/debugSaveEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ void DrawFlagTableArray16(const FlagTable& flagTable, uint16_t row, uint16_t& fl
ImGui::PopStyleColor();
if (ImGui::IsItemHovered() && hasDescription) {
ImGui::BeginTooltip();
ImGui::Text("%s", UIWidgets::WrappedText(flagTable.flagDescriptions.at(row * 16 + flagIndex), 60));
ImGui::Text("%s", UIWidgets::WrappedText(flagTable.flagDescriptions.at(row * 16 + flagIndex), 60).c_str());
ImGui::EndTooltip();
}
ImGui::PopID();
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/Enhancements/presets.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ const std::vector<const char*> enhancementsCvars = {
CVAR_ENHANCEMENT("DisableLOD"),
CVAR_ENHANCEMENT("DisableDrawDistance"),
CVAR_ENHANCEMENT("DisableKokiriDrawDistance"),
CVAR_ENHANCEMENT("WidescreenActorCulling"),
CVAR_ENHANCEMENT("ExtendedCullingExcludeGlitchActors"),
CVAR_LOW_RES_MODE,
CVAR_ENHANCEMENT("DrawLineupTick"),
CVAR_ENHANCEMENT("QuickBongoKill"),
Expand Down
22 changes: 4 additions & 18 deletions soh/soh/Enhancements/savestates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstdio> // std::sprintf

#include <spdlog/spdlog.h>
#include <spdlog/fmt/fmt.h>

#include <soh/OTRGlobals.h>
#include <soh/OTRAudio.h>
Expand All @@ -25,19 +24,6 @@

extern "C" PlayState* gPlayState;

template <> struct fmt::formatter<RequestType> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const RequestType& type, FormatContext& ctx) {
switch (type) {
case RequestType::SAVE: return fmt::format_to(ctx.out(), "Save");
case RequestType::LOAD: return fmt::format_to(ctx.out(), "Load");
default: return fmt::format_to(ctx.out(), "Unknown");
}
}
};

// FROM z_lights.c
// I didn't feel like moving it into a header file.
#define LIGHTS_BUFFER_SIZE 32
Expand Down Expand Up @@ -862,11 +848,11 @@ void SaveStateMgr::ProcessSaveStateRequests(void) {
this->states[request.slot]->Load();
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->TextDrawNotification(1.0f, true, "loaded state %u", request.slot);
} else {
SPDLOG_ERROR("Invalid SaveState slot: {}", request.type);
SPDLOG_ERROR("Invalid SaveState slot: {}", request.slot);
}
break;
[[unlikely]] default:
SPDLOG_ERROR("Invalid SaveState request type: {}", request.type);
SPDLOG_ERROR("Invalid SaveState request type: Unknown ({})", static_cast<int>(request.type));
break;
}
this->requests.pop();
Expand All @@ -889,12 +875,12 @@ SaveStateReturn SaveStateMgr::AddRequest(const SaveStateRequest request) {
requests.push(request);
return SaveStateReturn::SUCCESS;
} else {
SPDLOG_ERROR("Invalid SaveState slot: {}", request.type);
SPDLOG_ERROR("Invalid SaveState slot: {}", request.slot);
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->TextDrawNotification(1.0f, true, "state slot %u empty", request.slot);
return SaveStateReturn::FAIL_INVALID_SLOT;
}
[[unlikely]] default:
SPDLOG_ERROR("Invalid SaveState request type: {}", request.type);
SPDLOG_ERROR("Invalid SaveState request type: Unknown ({})", static_cast<int>(request.type));
return SaveStateReturn::FAIL_BAD_REQUEST;
}
}
Expand Down
1 change: 1 addition & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ extern "C" char* ResourceMgr_LoadArrayByName(const char* path)
return (char*)res->Scalars.data();
}

// Return of LoadArrayByNameAsVec3s must be freed by the caller
extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) {
auto res = std::static_pointer_cast<SOH::Array>(GetResourceByNameHandlingMQ(path));

Expand Down
109 changes: 69 additions & 40 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ std::string GetWindowButtonText(const char* text, bool menuOpen) {
return buttonText;
}

static std::unordered_map<Ship::WindowBackend, const char*> windowBackendNames = {
{ Ship::WindowBackend::FAST3D_DXGI_DX11, "DirectX" },
{ Ship::WindowBackend::FAST3D_SDL_OPENGL, "OpenGL" },
{ Ship::WindowBackend::FAST3D_SDL_METAL, "Metal" },
};

static const char* imguiScaleOptions[4] = { "Small", "Normal", "Large", "X-Large" };

static const char* filters[3] = {
Expand Down Expand Up @@ -103,6 +109,24 @@ extern "C" SaveContext gSaveContext;

namespace SohGui {

std::unordered_map<Ship::WindowBackend, const char*> availableWindowBackendsMap;
Ship::WindowBackend configWindowBackend;

void UpdateWindowBackendObjects() {
Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend();
int32_t configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) {
configWindowBackend = static_cast<Ship::WindowBackend>(configWindowBackendId);
} else {
configWindowBackend = runningWindowBackend;
}

auto availableWindowBackends = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends();
for (auto& backend : *availableWindowBackends) {
availableWindowBackendsMap[backend] = windowBackendNames[backend];
}
}

void DrawMenuBarIcon() {
static bool gameIconLoaded = false;
if (!gameIconLoaded) {
Expand Down Expand Up @@ -441,39 +465,24 @@ void DrawSettingsMenu() {
UIWidgets::Tooltip("Changes the scaling of the ImGui menu elements.");

UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f);

static std::unordered_map<Ship::WindowBackend, const char*> windowBackendNames = {
{ Ship::WindowBackend::FAST3D_DXGI_DX11, "DirectX" },
{ Ship::WindowBackend::FAST3D_SDL_OPENGL, "OpenGL"},
{ Ship::WindowBackend::FAST3D_SDL_METAL, "Metal" }
};

ImGui::Text("Renderer API (Needs reload)");
Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend();
Ship::WindowBackend configWindowBackend;
int configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) {
configWindowBackend = static_cast<Ship::WindowBackend>(configWindowBackendId);
} else {
configWindowBackend = runningWindowBackend;
}

if (Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) {
if (availableWindowBackendsMap.size() <= 1) {
UIWidgets::DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
}
if (ImGui::BeginCombo("##RApi", windowBackendNames[configWindowBackend])) {
for (size_t i = 0; i < Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size(); i++) {
auto backend = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->data()[i];
if (ImGui::Selectable(windowBackendNames[backend], backend == configWindowBackend)) {
Ship::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend));
Ship::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name",
windowBackendNames[backend]);
if (ImGui::BeginCombo("##RApi", availableWindowBackendsMap[configWindowBackend])) {
for (auto backend : availableWindowBackendsMap) {
if (ImGui::Selectable(backend.second, backend.first == configWindowBackend)) {
Ship::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend.first));
Ship::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name", backend.second);
Ship::Context::GetInstance()->GetConfig()->Save();
UpdateWindowBackendObjects();
}
}
ImGui::EndCombo();
}
if (Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) {
if (availableWindowBackendsMap.size() <= 1) {
UIWidgets::ReEnableComponent("");
}

Expand Down Expand Up @@ -1147,26 +1156,42 @@ void DrawEnhancementsMenu() {
UIWidgets::Spacer(0);

UIWidgets::PaddedEnhancementCheckbox("Disable LOD", CVAR_ENHANCEMENT("DisableLOD"), true, false);
UIWidgets::Tooltip("Turns off the Level of Detail setting, making models use their higher-poly variants at any distance");
if (UIWidgets::PaddedEnhancementCheckbox("Disable Draw Distance", CVAR_ENHANCEMENT("DisableDrawDistance"), true, false)) {
if (CVarGetInteger(CVAR_ENHANCEMENT("DisableDrawDistance"), 0) == 0) {
UIWidgets::Tooltip(
"Turns off the Level of Detail setting, making models use their higher-poly variants at any distance");
if (UIWidgets::EnhancementSliderInt("Increase Actor Draw Distance: %dx", "##IncreaseActorDrawDistance",
CVAR_ENHANCEMENT("DisableDrawDistance"), 1, 5, "", 1, true, false)) {
if (CVarGetInteger(CVAR_ENHANCEMENT("DisableDrawDistance"), 1) <= 1) {
CVarSetInteger(CVAR_ENHANCEMENT("DisableKokiriDrawDistance"), 0);
}
}
UIWidgets::Tooltip("Turns off the objects draw distance, making objects being visible from a longer range");
if (CVarGetInteger(CVAR_ENHANCEMENT("DisableDrawDistance"), 0) == 1) {
UIWidgets::PaddedEnhancementCheckbox("Kokiri Draw Distance", CVAR_ENHANCEMENT("DisableKokiriDrawDistance"), true, false);
UIWidgets::Tooltip("The Kokiri are mystical beings that fade into view when approached\nEnabling this will remove their draw distance");
}
if (UIWidgets::PaddedEnhancementCheckbox("Show Age-Dependent Equipment", CVAR_ENHANCEMENT("EquimentAlwaysVisible"), true,
false)) {
UpdatePatchHand();
}
UIWidgets::Tooltip("Makes all equipment visible, regardless of Age.");
if (CVarGetInteger(CVAR_ENHANCEMENT("EquimentAlwaysVisible"), 0) == 1) {
UIWidgets::PaddedEnhancementCheckbox("Scale Adult Equipment as Child", CVAR_ENHANCEMENT("ScaleAdultEquimentAsChild"), true, false);
UIWidgets::Tooltip("Scales all of the Adult Equipment, as well and moving some a bit, to fit on Child Link Better. May not work properly with some mods.");
}
UIWidgets::Tooltip("Increases the range in which actors/objects are drawn");
if (CVarGetInteger(CVAR_ENHANCEMENT("DisableDrawDistance"), 1) > 1) {
UIWidgets::PaddedEnhancementCheckbox("Kokiri Draw Distance",
CVAR_ENHANCEMENT("DisableKokiriDrawDistance"), true, false);
UIWidgets::Tooltip("The Kokiri are mystical beings that fade into view when approached\nEnabling this "
"will remove their draw distance");
}
UIWidgets::PaddedEnhancementCheckbox("Widescreen Actor Culling", CVAR_ENHANCEMENT("WidescreenActorCulling"),
true, false);
UIWidgets::Tooltip("Adjusts the horizontal culling plane to account for widescreen resolutions");
UIWidgets::PaddedEnhancementCheckbox(
"Cull Glitch Useful Actors", CVAR_ENHANCEMENT("ExtendedCullingExcludeGlitchActors"), true, false,
!CVarGetInteger(CVAR_ENHANCEMENT("WidescreenActorCulling"), 0) &&
CVarGetInteger(CVAR_ENHANCEMENT("DisableDrawDistance"), 1) <= 1,
"Requires Actor Draw Distance to be increased or Widescreen Actor Culling enabled");
UIWidgets::Tooltip(
"Exclude actors that are useful for glitches from the extended culling ranges.\n"
"Some actors may still draw in the extended ranges, but will not \"update\" so that certain "
"glitches that leverage the original culling requirements will still work.\n"
"\n"
"The following actors are excluded:\n"
"- White clothed Gerudos\n"
"- King Zora\n"
"- Gossip Stones\n"
"- Boulders\n"
"- Blue Warps\n"
"- Darunia\n"
"- Gold Skulltulas");
UIWidgets::PaddedEnhancementCheckbox("N64 Mode", CVAR_LOW_RES_MODE, true, false);
UIWidgets::Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution");
UIWidgets::PaddedEnhancementCheckbox("Glitch line-up tick", CVAR_ENHANCEMENT("DrawLineupTick"), true, false);
Expand Down Expand Up @@ -2004,6 +2029,10 @@ void DrawRandomizerMenu() {
}
}

void SohMenuBar::InitElement() {
UpdateWindowBackendObjects();
}

void SohMenuBar::DrawElement() {
if (ImGui::BeginMenuBar()) {
DrawMenuBarIcon();
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/SohMenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SohMenuBar : public Ship::GuiMenuBar {
using Ship::GuiMenuBar::GuiMenuBar;
protected:
void DrawElement() override;
void InitElement() override {};
void InitElement() override;
void UpdateElement() override {};
};
} // namespace SohGui
16 changes: 8 additions & 8 deletions soh/soh/UIWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace UIWidgets {
// Automatically adds newlines to break up text longer than a specified number of characters
// Manually included newlines will still be respected and reset the line length
// If line is midword when it hits the limit, text should break at the last encountered space
char* WrappedText(const char* text, unsigned int charactersPerLine) {
std::string WrappedText(const char* text, unsigned int charactersPerLine) {
std::string newText(text);
const size_t tipLength = newText.length();
int lastSpace = -1;
Expand All @@ -46,25 +46,25 @@ namespace UIWidgets {
currentLineLength++;
}

return strdup(newText.c_str());
return newText;
}

char* WrappedText(const std::string& text, unsigned int charactersPerLine) {
std::string WrappedText(const std::string& text, unsigned int charactersPerLine) {
return WrappedText(text.c_str(), charactersPerLine);
}

void SetLastItemHoverText(const std::string& text) {
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
ImGui::Text("%s", WrappedText(text, 60).c_str());
ImGui::EndTooltip();
}
}

void SetLastItemHoverText(const char* text) {
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
ImGui::Text("%s", WrappedText(text, 60).c_str());
ImGui::EndTooltip();
}
}
Expand All @@ -75,7 +75,7 @@ namespace UIWidgets {
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
ImGui::Text("%s", WrappedText(text, 60).c_str());
ImGui::EndTooltip();
}
}
Expand All @@ -85,7 +85,7 @@ namespace UIWidgets {
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
ImGui::Text("%s", WrappedText(text, 60).c_str());
ImGui::EndTooltip();
}
}
Expand All @@ -95,7 +95,7 @@ namespace UIWidgets {

void Tooltip(const char* text) {
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("%s", WrappedText(text));
ImGui::SetTooltip("%s", WrappedText(text).c_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions soh/soh/UIWidgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace UIWidgets {
constexpr float sliderButtonWidth = 30.0f;
#endif

char* WrappedText(const char* text, unsigned int charactersPerLine = 60);
char* WrappedText(const std::string& text, unsigned int charactersPerLine);
std::string WrappedText(const char* text, unsigned int charactersPerLine = 60);
std::string WrappedText(const std::string& text, unsigned int charactersPerLine);

void SetLastItemHoverText(const std::string& text);
void SetLastItemHoverText(const char* text);
Expand Down
8 changes: 7 additions & 1 deletion soh/soh/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ void aClearBufferImpl(uint16_t addr, int nbytes) {
memset(BUF_U8(addr), 0, nbytes);
}

void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes) {
void aLoadBufferImpl(const void* source_addr, uint16_t dest_addr, uint16_t nbytes) {
#if __SANITIZE_ADDRESS__
for (size_t i = 0; i < ROUND_DOWN_16(nbytes); i++) {
BUF_U8(dest_addr)[i] = ((const unsigned char*)source_addr)[i];
}
#else
memcpy(BUF_U8(dest_addr), source_addr, ROUND_DOWN_16(nbytes));
#endif
}

void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes) {
Expand Down
Loading

0 comments on commit 86580fc

Please sign in to comment.