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

Implement Alt Assets Variable LUS #619

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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: 0 additions & 1 deletion CMake/lus-cvars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(CVAR_STATS_WINDOW_OPEN "${CVAR_PREFIX_WINDOW}.Stats" CACHE STRING "")
set(CVAR_ENABLE_MULTI_VIEWPORTS "${CVAR_PREFIX_SETTING}.EnableMultiViewports" CACHE STRING "")
set(CVAR_LOW_RES_MODE "${CVAR_PREFIX_SETTING}.LowResMode" CACHE STRING "")
set(CVAR_SIMULATED_INPUT_LAG "${CVAR_PREFIX_SETTING}.SimulatedInputLag" CACHE STRING "")
set(CVAR_ALT_ASSETS "${CVAR_PREFIX_ENHANCEMENT}.AltAssets" CACHE STRING "")
set(CVAR_GAME_OVERLAY_FONT "${CVAR_PREFIX_SETTING}.OverlayFont" CACHE STRING "")
set(CVAR_MENU_BAR_OPEN "${CVAR_PREFIX_SETTING}.OpenMenuBar" CACHE STRING "")
set(CVAR_PREFIX_CONTROLLERS "${CVAR_PREFIX_SETTING}.Controllers" CACHE STRING "")
Expand Down
2 changes: 1 addition & 1 deletion libultraship
2 changes: 0 additions & 2 deletions mm/2s2h/BenGui/BenGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "include/global.h"
#include "include/z64audio.h"

bool ShouldClearTextureCacheAtEndOfFrame = false;

namespace BenGui {
// MARK: - Delegates

Expand Down
2 changes: 0 additions & 2 deletions mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "2s2h/DeveloperTools/WarpPoint.h"
#include "HudEditor.h"

extern bool ShouldClearTextureCacheAtEndOfFrame;

extern "C" {
#include "z64.h"
#include "functions.h"
Expand Down
28 changes: 18 additions & 10 deletions mm/2s2h/BenPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ OTRGlobals* OTRGlobals::Instance;
GameInteractor* GameInteractor::Instance;

extern "C" char** cameraStrings;
bool prevAltAssets = false;
std::vector<std::shared_ptr<std::string>> cameraStdStrings;

Color_RGB8 kokiriColor = { 0x1E, 0x69, 0x1B };
Expand Down Expand Up @@ -148,6 +149,7 @@ OTRGlobals::OTRGlobals() {
// tell LUS to reserve 3 SoH specific threads (Game, Audio, Save)
context =
Ship::Context::CreateInstance("2 Ship 2 Harkinian", appShortName, "2ship2harkinian.json", archiveFiles, {}, 3);
prevAltAssets = CVarGetInteger("gAltAssets", 0);
Malkierian marked this conversation as resolved.
Show resolved Hide resolved

// Override LUS defaults
Ship::Context::GetInstance()->GetLogger()->set_level(
Expand Down Expand Up @@ -565,8 +567,6 @@ extern "C" uint64_t GetUnixTimestamp() {
return now;
}

extern bool ShouldClearTextureCacheAtEndOfFrame;

extern "C" void Graph_StartFrame() {
#ifndef __WIIU__
using Ship::KbScancode;
Expand Down Expand Up @@ -649,7 +649,7 @@ extern "C" void Graph_StartFrame() {
#endif
case KbScancode::LUS_KB_TAB: {
// Toggle HD Assets
CVarSetInteger(CVAR_ALT_ASSETS, !CVarGetInteger(CVAR_ALT_ASSETS, 0));
CVarSetInteger("gAltAssets", !CVarGetInteger("gAltAssets", 0));
// ShouldClearTextureCacheAtEndOfFrame = true;
break;
}
Expand Down Expand Up @@ -738,12 +738,16 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
audio.cv_from_thread.wait(Lock);
}
}
//
// if (ShouldClearTextureCacheAtEndOfFrame) {
// gfx_texture_cache_clear();
// Ship::SkeletonPatcher::UpdateSkeletons();
// ShouldClearTextureCacheAtEndOfFrame = false;
//}

bool curAltAssets = CVarGetInteger("gAltAssets", 0);
if (prevAltAssets != curAltAssets) {
prevAltAssets = curAltAssets;
Ship::Context::GetInstance()->GetResourceManager()->SetAltAssetsEnabled(curAltAssets);
gfx_texture_cache_clear();
// TODO: skeleton patch, hooks
// SOH::SkeletonPatcher::UpdateSkeletons();
// GameInteractor::Instance->ExecuteHooks<GameInteractor::OnAssetAltChange>();
}

// OTRTODO: FIGURE OUT END FRAME POINT
/* if (OTRGlobals::Instance->context->GetWindow()->lastScancode != -1)
Expand Down Expand Up @@ -777,6 +781,10 @@ extern "C" uint16_t OTRGetPixelDepth(float x, float y) {
return wnd->GetPixelDepth(x, adjustedY);
}

extern "C" bool ResourceMgr_IsAltAssetsEnabled() {
return Ship::Context::GetInstance()->GetResourceManager()->IsAltAssetsEnabled();
}

extern "C" uint32_t ResourceMgr_GetNumGameVersions() {
return Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions().size();
}
Expand Down Expand Up @@ -1218,7 +1226,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path, Skel
pathStr = pathStr.substr(sOtr.length());
}

bool isAlt = CVarGetInteger(CVAR_ALT_ASSETS, 0);
bool isAlt = ResourceMgr_IsAltAssetsEnabled();

if (isAlt) {
pathStr = Ship::IResource::gAltAssetPrefix + pathStr;
Expand Down
6 changes: 3 additions & 3 deletions mm/2s2h/resource/type/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void SkeletonPatcher::ClearSkeletons() {
}

void SkeletonPatcher::UpdateSkeletons() {
bool isHD = CVarGetInteger(CVAR_ALT_ASSETS, 0);
auto resourceMgr = Ship::Context::GetInstance()->GetResourceManager();
bool isHD = resourceMgr->IsAltAssetsEnabled();
for (auto skel : skeletons) {
Skeleton* newSkel =
(Skeleton*)Ship::Context::GetInstance()
->GetResourceManager()
(Skeleton*)resourceMgr
->LoadResource((isHD ? Ship::IResource::gAltAssetPrefix : "") + skel.vanillaSkeletonPath, true)
.get();

Expand Down