From 02fdde376870639b2f492f4f481dacde9f466437 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 14 Jun 2026 22:41:33 -0600 Subject: [PATCH] Scale map rendering with IR (#2056) * Scale map rendering with IR + scale config * Remove config option --- include/d/d_map.h | 3 ++ src/d/d_map.cpp | 22 ++++++++++++ src/d/d_map_path.cpp | 79 +++++++++++++++++++++++++------------------ src/d/d_meter_map.cpp | 6 ++++ 4 files changed, 77 insertions(+), 33 deletions(-) diff --git a/include/d/d_map.h b/include/d/d_map.h index 1acc7e4519..1cddbf3944 100644 --- a/include/d/d_map.h +++ b/include/d/d_map.h @@ -157,6 +157,9 @@ public: int getDispType() const; void _move(f32, f32, int, f32); void _draw(); +#if TARGET_PC + bool refreshTextureSize(); +#endif virtual ~dMap_c() { #if DEBUG diff --git a/src/d/d_map.cpp b/src/d/d_map.cpp index 8cecead15a..765facc335 100644 --- a/src/d/d_map.cpp +++ b/src/d/d_map.cpp @@ -1213,6 +1213,10 @@ void dMap_c::changeTextureSize(int param_1, int param_2, int param_3) { JUT_ASSERT(2672, mImage_p != NULL); JUT_ASSERT(2673, mResTIMG != NULL); +#if TARGET_PC + GXDestroyCopyTex(mImage_p); +#endif + mTexSizeX = param_1 >> param_3; mTexSizeY = param_2 >> param_3; @@ -1226,6 +1230,24 @@ void dMap_c::changeTextureSize(int param_1, int param_2, int param_3) { } #endif +#if TARGET_PC +bool dMap_c::refreshTextureSize() { + JUT_ASSERT(2688, mImage_p != NULL); + JUT_ASSERT(2689, mResTIMG != NULL); + + const u16 oldWidth = mResTIMG->width; + const u16 oldHeight = mResTIMG->height; + makeResTIMG(mResTIMG, mTexSizeX, mTexSizeY, mImage_p, (u8*)m_res, 0x33); + + if (mResTIMG->width == oldWidth && mResTIMG->height == oldHeight) { + return false; + } + + GXDestroyCopyTex(mImage_p); + return true; +} +#endif + void dMap_c::_remove() { if (mImage_p != NULL) { #if TARGET_PC diff --git a/src/d/d_map_path.cpp b/src/d/d_map_path.cpp index a7579ee92d..cafbb93e38 100644 --- a/src/d/d_map_path.cpp +++ b/src/d/d_map_path.cpp @@ -15,32 +15,49 @@ #include #ifdef TARGET_PC -#include -#include -#include +#include "dusk/settings.h" +#include "m_Do/m_Do_graphic.h" +#include +#include -constexpr u16 kPreferredMapResolutionMultiplier = 4; -constexpr u32 kMaxMapRenderPixels = 4096 * 4096; -constexpr u16 kMapImageSide = 16 * kPreferredMapResolutionMultiplier; +#include +#include +#include +#include +#include +#include +#include + +constexpr u16 kMapIconResolutionMultiplier = 4; +constexpr u16 kMapImageSide = 16 * kMapIconResolutionMultiplier; constexpr u32 kMapImageTotalPixels = kMapImageSide * kMapImageSide; typedef std::function PaintI8Fn; -u16 map_resolution_multiplier(u16 width, u16 height) { - const u32 basePixels = static_cast(width) * height; - if (basePixels == 0) { - return 1; +u16 scaled_map_axis(u16 value, f32 scale) { + const auto scaledValue = + static_cast(std::max(1.0f, std::round(static_cast(value) * scale))); + return static_cast(std::min(scaledValue, std::numeric_limits::max())); +} + +aurora::Vec2 map_render_size_for(u16 width, u16 height) { + if (width == 0 || height == 0) { + return {width, height}; } - u16 scale = kPreferredMapResolutionMultiplier; - while (scale > 1) { - const u32 scalePixels = static_cast(scale) * scale; - if (basePixels <= kMaxMapRenderPixels / scalePixels) { - break; - } - scale--; - } - return scale; + u32 renderWidth = 0; + u32 renderHeight = 0; + AuroraGetRenderSize(&renderWidth, &renderHeight); + + const f32 logicalWidth = std::max(mDoGph_gInf_c::getWidthF(), 1.0f); + const f32 logicalHeight = std::max(mDoGph_gInf_c::getHeightF(), 1.0f); + const f32 irScaleX = renderWidth > 0 ? static_cast(renderWidth) / logicalWidth : 1.0f; + const f32 irScaleY = renderHeight > 0 ? static_cast(renderHeight) / logicalHeight : 1.0f; + const f32 hudScale = std::clamp(dusk::getSettings().game.hudScale.getValue(), 0.5f, 2.0f); + return { + scaled_map_axis(width, irScaleX * hudScale), + scaled_map_axis(height, irScaleY * hudScale), + }; } void paint_i8(std::span dst, size_t width, PaintI8Fn paint) { @@ -496,9 +513,9 @@ void dRenderingMap_c::makeResTIMG(ResTIMG* p_image, u16 width, u16 height, u8* p p_image->format = GX_TF_C8; p_image->alphaEnabled = 2; #ifdef TARGET_PC - const u16 scale = map_resolution_multiplier(width, height); - p_image->width = width * scale; - p_image->height = height * scale; + const auto [rw, rh] = map_render_size_for(width, height); + p_image->width = rw; + p_image->height = rh; #else p_image->width = width; p_image->height = height; @@ -581,16 +598,14 @@ void dRenderingFDAmap_c::drawBack() const { void dRenderingFDAmap_c::preRenderingMap() { #ifdef TARGET_PC - const u16 scale = map_resolution_multiplier(mTexWidth, mTexHeight); - const u16 w = mTexWidth * scale; - const u16 h = mTexHeight * scale; - GXCreateFrameBuffer(w, h); + const auto [rw, rh] = map_render_size_for(mTexWidth, mTexHeight); + GXCreateFrameBuffer(rw, rh); // Set logical viewport dimensions GXSetViewport(0.0f, 0.0f, mTexWidth, mTexHeight, 0.0f, 1.0f); GXSetScissor(0, 0, mTexWidth, mTexHeight); // Set render viewport dimensions - GXSetViewportRender(0.0f, 0.0f, w, h, 0.0f, 1.0f); - GXSetScissorRender(0, 0, w, h); + GXSetViewportRender(0.0f, 0.0f, rw, rh, 0.0f, 1.0f); + GXSetScissorRender(0, 0, rw, rh); #else GXSetViewport(0.0f, 0.0f, mTexWidth, mTexHeight, 0.0f, 1.0f); GXSetScissor(0, 0, mTexWidth, mTexHeight); @@ -628,11 +643,9 @@ void dRenderingFDAmap_c::preRenderingMap() { void dRenderingFDAmap_c::postRenderingMap() { GXSetCopyFilter(GX_FALSE, NULL, GX_FALSE, NULL); #ifdef TARGET_PC - const u16 scale = map_resolution_multiplier(mTexWidth, mTexHeight); - const u16 w = mTexWidth * scale; - const u16 h = mTexHeight * scale; - GXSetTexCopySrc(0, 0, w, h); - GXSetTexCopyDst(w, h, GX_CTF_R8, GX_FALSE); + const auto [rw, rh] = map_render_size_for(mTexWidth, mTexHeight); + GXSetTexCopySrc(0, 0, rw, rh); + GXSetTexCopyDst(rw, rh, GX_CTF_R8, GX_FALSE); GXCopyTex(field_0x4, GX_TRUE); GXRestoreFrameBuffer(); #else diff --git a/src/d/d_meter_map.cpp b/src/d/d_meter_map.cpp index c03214b963..95cd82cd53 100644 --- a/src/d/d_meter_map.cpp +++ b/src/d/d_meter_map.cpp @@ -539,6 +539,12 @@ void dMeterMap_c::_move(u32 param_0) { } #endif +#if TARGET_PC + if (mMap->refreshTextureSize()) { + mMapJ2DPicture->changeTexture(mMap->getResTIMGPointer(), 0); + } +#endif + int stayNo = dComIfGp_roomControl_getStayNo(); field_0x14 = param_0;