mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-16 05:55:37 -04:00
Scale map rendering with IR (#2056)
* Scale map rendering with IR + scale config * Remove config option
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+46
-33
@@ -15,32 +15,49 @@
|
||||
#include <cstring>
|
||||
|
||||
#ifdef TARGET_PC
|
||||
#include <span>
|
||||
#include <numbers>
|
||||
#include <array>
|
||||
#include "dusk/settings.h"
|
||||
#include "m_Do/m_Do_graphic.h"
|
||||
#include <dolphin/gx/GXAurora.h>
|
||||
#include <aurora/math.hpp>
|
||||
|
||||
constexpr u16 kPreferredMapResolutionMultiplier = 4;
|
||||
constexpr u32 kMaxMapRenderPixels = 4096 * 4096;
|
||||
constexpr u16 kMapImageSide = 16 * kPreferredMapResolutionMultiplier;
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <span>
|
||||
|
||||
constexpr u16 kMapIconResolutionMultiplier = 4;
|
||||
constexpr u16 kMapImageSide = 16 * kMapIconResolutionMultiplier;
|
||||
constexpr u32 kMapImageTotalPixels = kMapImageSide * kMapImageSide;
|
||||
|
||||
typedef std::function<u8(size_t, size_t)> PaintI8Fn;
|
||||
|
||||
u16 map_resolution_multiplier(u16 width, u16 height) {
|
||||
const u32 basePixels = static_cast<u32>(width) * height;
|
||||
if (basePixels == 0) {
|
||||
return 1;
|
||||
u16 scaled_map_axis(u16 value, f32 scale) {
|
||||
const auto scaledValue =
|
||||
static_cast<u32>(std::max(1.0f, std::round(static_cast<f32>(value) * scale)));
|
||||
return static_cast<u16>(std::min<u32>(scaledValue, std::numeric_limits<u16>::max()));
|
||||
}
|
||||
|
||||
aurora::Vec2<u16> 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<u32>(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<f32>(renderWidth) / logicalWidth : 1.0f;
|
||||
const f32 irScaleY = renderHeight > 0 ? static_cast<f32>(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<u8> 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user