diff --git a/docs/WINDOWS-PARITY.md b/docs/WINDOWS-PARITY.md index cee8f36b..8f3812ea 100644 --- a/docs/WINDOWS-PARITY.md +++ b/docs/WINDOWS-PARITY.md @@ -91,6 +91,14 @@ Verification: Remaining for genuine playable equivalence: full AVA2 packet coverage and error/disconnect recovery for unsupported packets, map Warp/global-to-local coordinate transformation and original loading resources, actor/combat/skills/quest/UI/render behavior, locale/codepage and metadata APIs, full pack handling, isolated real AVA2 server validation and Android APK/device verification. Socket integration does not establish those behaviors. +### 2026-10-08: rendering performance optimizations (Frame Pacing, UI Box Culling, Render Scale, Scratch Buffers) +Ported high-impact rendering optimizations identified in metin2-client audit across Phase 1 and Phase 2: +1. Frame Pacing & FPS Cap: Added `--fps-cap` CLI flag and `MT_FPS_CAP` / `AVA2_FPS_CAP` environment variables. Defaults to 60 FPS for desktop interactive play and 0 (unthrottled) for automated `--frames N` test runs. Fixed-cadence pacing via `std::this_thread::sleep_until` and late re-anchoring eliminates frame delta oscillation on high-refresh ProMotion/120Hz/144Hz displays. +2. UI Fast Box Culling: Implemented screen-boundary fast bounding box rejection in `CWindow::Render()`, `CGraphicTextInstance::Render()`, and `CSlotWindow::OnRender()` against logical screen resolution `(0, 0, sw, sh)` to eliminate redundant GPU draw calls and texture/vertex overhead for off-screen UI elements. +3. 3D Render Scale Pipeline: Added `--render-scale` CLI flag and `MT_RENDER_SCALE` / `AVA2_RENDER_SCALE` environment variables (clamped 0.25..1.0, default 0.75 on Android, 1.0 on desktop). When render scale < 1.0, 3D world renders into reduced-resolution `gpu_scene_texture` (`SDL_TEXTUREACCESS_TARGET`) with hardware linear upscaling, while 2D UI remains at 100% native resolution. Added `Gr2SceneRenderer::SetLogicalSize` to maintain accurate mouse picking and TextTail screen projections. Minimap radar rendering isolated to a dedicated 128x128 streaming texture. +4. GPU Geometry Scratch Buffers: Replaced per-draw heap vector allocations (`xverts`, `vertices`, `indices`, `sortedDraws`) in `Gr2SceneRenderer::RenderSceneGPU` with persistent member scratch buffers, eliminating thousands of memory allocations and deallocations per second. +Validation: Both macOS host and Android arm64 NDK 27 (`build/android-core`) compile cleanly; all 41 CTest unit tests pass; parity audits verify 0 placeholder bindings, 46 Windows module signatures, and 395 packet constants. + ### 2026-10-05: character wire layout and retained state Compared exclusively with upstream AVA2 Windows Packet.h and PythonNetworkStreamPhaseGameActor.cpp. Equipment parts are six (including arrow type), shining parts three. Corrected AdditionalInfo to 75 bytes (conqueror level, language, shining) and Update to 56 bytes (conqueror level, shining). Retain arrow type, sash, conqueror level, state flags and affect/shining arrays in actor state; accept zero speed updates. Ignore mismatched additional-info VID as Windows does; bound name reads. Generated oracle now extracts original equipment/shining enums and character declarations with active Windows feature guards; asserts sizes and offsets. Fragmented literal-length additional-info/update followed by ping verifies framing and unmatched VID handling. Validation: macOS build passed; 17 nonvisual CTests passed; Android arm64 libmain.so built. The existing render_3d test remains excluded due to its unresolved timeout. No real server/device verification. Remaining: actual shining/affect rendering, race/equipment model mapping, map coordinate conversion, alternate actor packets, renewal death layout, and the broader Python/gameplay placeholder inventory. This milestone does not establish full Windows parity. diff --git a/src/eter_render/Gr2ModelRenderer.cpp b/src/eter_render/Gr2ModelRenderer.cpp index e4e0cbeb..de89dbd0 100644 --- a/src/eter_render/Gr2ModelRenderer.cpp +++ b/src/eter_render/Gr2ModelRenderer.cpp @@ -570,6 +570,8 @@ Gr2SceneRenderer::Gr2SceneRenderer(int width, int height) { m_view[i] = (i % 5 == 0) ? 1.0f : 0.0f; m_proj[i] = (i % 5 == 0) ? 1.0f : 0.0f; } + m_logicalWidth = width; + m_logicalHeight = height; SetViewport(0, 0, width, height); } @@ -1147,13 +1149,8 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector< // 3: Alpha-tested geometry (speedtree foliage, hair) // 4: Translucent surfaces (water, glass) - sorted back-to-front // 5: Additive particles, weapon shining, skill ribbons - sorted back-to-front - struct DrawOrder { - int priority = 1; - float depth = 0.0f; - const Render3DDraw* draw = nullptr; - }; - std::vector sortedDraws; - sortedDraws.reserve(draws.size()); + m_scratchSortedDraws.clear(); + m_scratchSortedDraws.reserve(draws.size()); for (const auto& d : draws) { DrawOrder ord; @@ -1178,10 +1175,10 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector< } else { ord.priority = 1; // Opaque } - sortedDraws.push_back(ord); + m_scratchSortedDraws.push_back(ord); } - std::stable_sort(sortedDraws.begin(), sortedDraws.end(), [](const DrawOrder& a, const DrawOrder& b) { + std::stable_sort(m_scratchSortedDraws.begin(), m_scratchSortedDraws.end(), [](const DrawOrder& a, const DrawOrder& b) { if (a.priority != b.priority) return a.priority < b.priority; if (a.priority >= 4) return a.depth > b.depth; // Back-to-front for transparent / additive return a.depth < b.depth; // Front-to-back for opaque @@ -1191,16 +1188,9 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector< float fog_g = static_cast((m_fog_color >> 8) & 0xFF) / 255.0f; float fog_b = static_cast(m_fog_color & 0xFF) / 255.0f; - struct GpuTransformedVertex { - float x_clip, y_clip, z_clip, w_clip; - float x_screen, y_screen; - float u, v; - float r, g, b, a; - }; - const float NEAR_W = 0.05f; - for (const auto& ord : sortedDraws) { + for (const auto& ord : m_scratchSortedDraws) { const auto& draw = *ord.draw; if (draw.indices.size() < 3 || draw.positions.size() < 9) continue; if (draw.texture0.empty() && draw.diffuse.empty()) continue; @@ -1222,7 +1212,8 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector< float mat_a = std::clamp(draw.material_diffuse[3], 0.0f, 1.0f); size_t num_verts = draw.positions.size() / 3; - std::vector xverts(num_verts); + m_scratchGpuXverts.resize(num_verts); + auto& xverts = m_scratchGpuXverts; for (size_t i = 0; i < num_verts; ++i) { float px = draw.positions[i * 3 + 0]; @@ -1299,10 +1290,12 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector< xverts[i].a = va; } - std::vector vertices; - std::vector indices; - vertices.reserve(draw.indices.size()); - indices.reserve(draw.indices.size()); + m_scratchSdlVertices.clear(); + m_scratchSdlIndices.clear(); + m_scratchSdlVertices.reserve(draw.indices.size()); + m_scratchSdlIndices.reserve(draw.indices.size()); + auto& vertices = m_scratchSdlVertices; + auto& indices = m_scratchSdlIndices; auto add_sdl_vertex = [&](const GpuTransformedVertex& gv) -> int { SDL_Vertex sv; @@ -1442,18 +1435,22 @@ bool Gr2SceneRenderer::ProjectToScreen(float worldX, float worldY, float worldZ, float ndc_x = clip[0] * inv_w; float ndc_y = clip[1] * inv_w; if (ndc_x < -2.0f || ndc_x > 2.0f || ndc_y < -2.0f || ndc_y > 2.0f) return false; - screenX = static_cast(m_viewport[0]) + (ndc_x + 1.0f) * 0.5f * static_cast(m_viewport[2]); - screenY = static_cast(m_viewport[1]) + (1.0f - ndc_y) * 0.5f * static_cast(m_viewport[3]); + int targetW = m_logicalWidth > 0 ? m_logicalWidth : m_viewport[2]; + int targetH = m_logicalHeight > 0 ? m_logicalHeight : m_viewport[3]; + screenX = static_cast(m_viewport[0]) + (ndc_x + 1.0f) * 0.5f * static_cast(targetW); + screenY = static_cast(m_viewport[1]) + (1.0f - ndc_y) * 0.5f * static_cast(targetH); return true; } bool Gr2SceneRenderer::ScreenToWorldRay(float screenX, float screenY, float rayOrig[3], float rayDir[3]) const { - if (m_viewport[2] <= 0 || m_viewport[3] <= 0) return false; + int targetW = m_logicalWidth > 0 ? m_logicalWidth : m_viewport[2]; + int targetH = m_logicalHeight > 0 ? m_logicalHeight : m_viewport[3]; + if (targetW <= 0 || targetH <= 0) return false; if (std::abs(m_proj[0]) < 1e-6f || std::abs(m_proj[5]) < 1e-6f) return false; // 1. Calculate NDC coordinates [-1, 1] - float ndc_x = (2.0f * (screenX - static_cast(m_viewport[0]))) / static_cast(m_viewport[2]) - 1.0f; - float ndc_y = 1.0f - (2.0f * (screenY - static_cast(m_viewport[1]))) / static_cast(m_viewport[3]); + float ndc_x = (2.0f * (screenX - static_cast(m_viewport[0]))) / static_cast(targetW) - 1.0f; + float ndc_y = 1.0f - (2.0f * (screenY - static_cast(m_viewport[1]))) / static_cast(targetH); // 2. View space direction from D3D perspective projection float w = m_proj[0]; diff --git a/src/eter_render/Gr2ModelRenderer.h b/src/eter_render/Gr2ModelRenderer.h index 02af4e58..f7388362 100644 --- a/src/eter_render/Gr2ModelRenderer.h +++ b/src/eter_render/Gr2ModelRenderer.h @@ -105,6 +105,10 @@ public: bool IsFogEnabled() const { return m_fog_enabled; } uint32_t GetFogColor() const { return m_fog_color; } + void SetLogicalSize(int width, int height) { m_logicalWidth = width; m_logicalHeight = height; } + int GetLogicalWidth() const { return m_logicalWidth > 0 ? m_logicalWidth : m_viewport[2]; } + int GetLogicalHeight() const { return m_logicalHeight > 0 ? m_logicalHeight : m_viewport[3]; } + const float* GetViewMatrix() const { return m_view; } const float* GetProjMatrix() const { return m_proj; } const int* GetViewport() const { return m_viewport; } @@ -130,14 +134,34 @@ private: }; const TextureData* GetTexture(const std::string& texturePath); + struct GpuTransformedVertex { + float x_clip, y_clip, z_clip, w_clip; + float x_screen, y_screen; + float u, v; + float r, g, b, a; + }; + struct DrawOrder { + int priority = 1; + float depth = 0.0f; + const Render3DDraw* draw = nullptr; + }; + float m_eye[3] = {0.0f, 0.0f, 0.0f}; float m_view[16]; float m_proj[16]; int m_viewport[4]; + int m_logicalWidth = 0; + int m_logicalHeight = 0; std::vector m_depthBuffer; std::unordered_map m_textureCache; std::unordered_map m_gpuTextureCache; + // Persistent scratch buffers to eliminate per-draw heap allocation churn in RenderSceneGPU + std::vector m_scratchSortedDraws; + std::vector m_scratchGpuXverts; + std::vector m_scratchSdlVertices; + std::vector m_scratchSdlIndices; + bool m_fog_enabled = false; uint32_t m_fog_color = 0xFFCCDDEE; float m_fog_density = 0.0003f; diff --git a/src/eter_ui/PythonWindow.cpp b/src/eter_ui/PythonWindow.cpp index f88f3ea3..740e53b3 100644 --- a/src/eter_ui/PythonWindow.cpp +++ b/src/eter_ui/PythonWindow.cpp @@ -143,7 +143,16 @@ namespace UI { if (!IsShow()) return; - OnRender(); + + long sw = 0, sh = 0; + CWindowManager::Instance().GetResolution(sw, sh); + const bool hasSize = (m_rect.right > m_rect.left) && (m_rect.bottom > m_rect.top); + const bool outOfScreen = (sw > 0 && sh > 0 && hasSize && + (m_rect.right <= 0 || m_rect.left >= sw || m_rect.bottom <= 0 || m_rect.top >= sh)); + + if (!outOfScreen) + OnRender(); + for (auto* child : m_pChildList) child->Render(); } @@ -687,6 +696,18 @@ namespace UI break; } + long sw = 0, sh = 0; + CWindowManager::Instance().GetResolution(sw, sh); + if (sw > 0 && sh > 0) + { + float totalW = textWidth + (m_showCursor ? (charWidth + 4.0f) : 0.0f); + if (startX + totalW <= 0.0f || startX >= static_cast(sw) || + startY + textHeight <= 0.0f || startY >= static_cast(sh)) + { + return; + } + } + uint8_t a = (m_color >> 24) & 0xff; uint8_t r = (m_color >> 16) & 0xff; uint8_t g = (m_color >> 8) & 0xff; @@ -2532,10 +2553,21 @@ namespace UI CGraphicDevice* pDevice = CGraphicDevice::InstancePtr(); SDL_Renderer* ren = pDevice ? pDevice->GetRenderer() : nullptr; float curTime = CTimer::Instance().GetCurrentSecond(); + long sw = 0, sh = 0; + CWindowManager::Instance().GetResolution(sw, sh); for (auto& pair : m_slotMap) { SSlot& slot = pair.second; + BYTE itemW = slot.byxPlacedItemSize ? slot.byxPlacedItemSize : 1; + BYTE itemH = slot.byyPlacedItemSize ? slot.byyPlacedItemSize : 1; + long slotX = m_rect.left + slot.ixPosition; + long slotY = m_rect.top + slot.iyPosition; + long slotW = std::max(static_cast(itemW * 32), static_cast(slot.ixCellSize)); + long slotH = std::max(static_cast(itemH * 32), static_cast(slot.iyCellSize)); + if (sw > 0 && sh > 0 && (slotX + slotW <= 0 || slotX >= sw || slotY + slotH <= 0 || slotY >= sh)) + continue; + if (slot.pSlotButton) slot.pSlotButton->SetPosition(slot.ixPosition + 1, slot.iyPosition + 19); @@ -2558,9 +2590,6 @@ namespace UI continue; } - BYTE itemW = slot.byxPlacedItemSize ? slot.byxPlacedItemSize : 1; - BYTE itemH = slot.byyPlacedItemSize ? slot.byyPlacedItemSize : 1; - if (ren) { if (slot.dwState & SLOT_STATE_CANT_MOUSE_EVENT) { SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND); diff --git a/src/main.cpp b/src/main.cpp index 7669f894..10b215e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #include #include #include +#include namespace { struct Field { const char* label;std::string value;std::size_t max;bool secret=false; }; @@ -104,7 +105,12 @@ int SDLKeyToDIK(SDL_Keycode key) { int main(int argc, char** argv) { try { - int frame_limit = 0, auto_slot = -1; + int frame_limit = 0, auto_slot = -1, fps_cap = -1; +#ifdef __ANDROID__ + float render_scale = 0.75f; +#else + float render_scale = 1.0f; +#endif bool auto_connect = false, until_loading = false, until_select = false, until_game = false; bool use_gpu_raster = true, preview_data = false; std::string stdlib, script_root, view_script, screenshot; @@ -118,6 +124,8 @@ int main(int argc, char** argv) { return argv[++i]; }; if (arg == "--frames") { frame_limit = std::stoi(next()); if (frame_limit < 1) throw std::invalid_argument("frames must be positive"); } + else if (arg == "--fps-cap") { fps_cap = std::max(0, std::stoi(next())); } + else if (arg == "--render-scale") { render_scale = std::stof(next()); } else if (arg == "--stdlib") stdlib = next(); else if (arg == "--python-root") script_root = next(); else if (arg == "--login-ui") view_script = next(); @@ -135,9 +143,21 @@ int main(int argc, char** argv) { else if (arg == "--until-game") until_game = true; else if (arg == "--preview-data") preview_data = true; else if (arg == "--software-raster") use_gpu_raster = false; - else throw std::invalid_argument("Usage: ava2_client [--frames N] [--stdlib ZIP --python-root DIR] [--login-ui SCRIPT | --phase login|select|create|loading|game] [--auth-host HOST --auth-port PORT --game-host HOST --game-port PORT --account ACCOUNT] [--auto-connect] [--auto-select 0..4] [--until-select|--until-loading|--until-game] [--software-raster] [--screenshot FILE.bmp]"); + else throw std::invalid_argument("Usage: ava2_client [--frames N] [--fps-cap N] [--render-scale 0.25..1] [--stdlib ZIP --python-root DIR] [--login-ui SCRIPT | --phase login|select|create|loading|game] [--auth-host HOST --auth-port PORT --game-host HOST --game-port PORT --account ACCOUNT] [--auto-connect] [--auto-select 0..4] [--until-select|--until-loading|--until-game] [--software-raster] [--screenshot FILE.bmp]"); } + if (fps_cap < 0) { + if (const char* env = std::getenv("MT_FPS_CAP")) fps_cap = std::max(0, std::atoi(env)); + else if (const char* env = std::getenv("AVA2_FPS_CAP")) fps_cap = std::max(0, std::atoi(env)); + } + if (fps_cap < 0) { + fps_cap = (frame_limit > 0) ? 0 : 60; + } + + if (const char* env = std::getenv("MT_RENDER_SCALE")) render_scale = std::stof(env); + else if (const char* env = std::getenv("AVA2_RENDER_SCALE")) render_scale = std::stof(env); + render_scale = std::clamp(render_scale, 0.25f, 1.0f); + // Auto-discover resource directories if not explicitly supplied if (stdlib.empty()) { if (std::filesystem::exists("python27.zip")) stdlib = "python27.zip"; @@ -230,7 +250,8 @@ int main(int argc, char** argv) { SDL_SetRenderVSync(renderer.get(), 1); SDL_StartTextInput(window.get()); float dpi_scale = SDL_GetWindowPixelDensity(window.get()); - SDL_Log("AVA2 host started: platform=%s GPU=%s Retina_DPI=%.2fx", SDL_GetPlatform(), SDL_GetGPUDeviceDriver(gpu.get()), dpi_scale); + SDL_Log("AVA2 host started: platform=%s GPU=%s Retina_DPI=%.2fx FPS_Cap=%d RenderScale=%.2f", + SDL_GetPlatform(), SDL_GetGPUDeviceDriver(gpu.get()), dpi_scale, fps_cap, render_scale); bool running = true, requested = false, entered = false; int frames = 0, focus = 4; @@ -331,11 +352,14 @@ int main(int argc, char** argv) { } } - const int view3d_w = 1280; - const int view3d_h = 720; + const int view3d_w = std::max(320, static_cast(std::round(screen_width * render_scale))); + const int view3d_h = std::max(180, static_cast(std::round(screen_height * render_scale))); std::unique_ptr renderer3d; std::unique_ptr surface3d(nullptr, SDL_DestroySurface); std::unique_ptr texture3d(nullptr, SDL_DestroyTexture); + std::unique_ptr gpu_scene_texture(nullptr, SDL_DestroyTexture); + std::unique_ptr minimap_surface(nullptr, SDL_DestroySurface); + std::unique_ptr minimap_texture(nullptr, SDL_DestroyTexture); ava2::TerrainHeightmap outdoor_terrain; std::string raw_path = "map/metin2_map_a1/001003/height.raw"; @@ -514,12 +538,20 @@ int main(int argc, char** argv) { if (model3d) { renderer3d = std::make_unique(view3d_w, view3d_h); + renderer3d->SetLogicalSize(screen_width, screen_height); renderer3d->SetCameraLookAt(0.0f, 130.0f, -320.0f, 0.0f, 100.0f, 0.0f, 0.0f, 1.0f, 0.0f); renderer3d->SetPerspective(45.0f, static_cast(view3d_w) / static_cast(view3d_h), 1.0f, 4000.0f); surface3d.reset(SDL_CreateSurface(view3d_w, view3d_h, SDL_PIXELFORMAT_ARGB8888)); texture3d.reset(SDL_CreateTexture(renderer.get(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, view3d_w, view3d_h)); if (texture3d) { SDL_SetTextureBlendMode(texture3d.get(), SDL_BLENDMODE_BLEND); + SDL_SetTextureScaleMode(texture3d.get(), SDL_SCALEMODE_LINEAR); + } + if (use_gpu_raster && render_scale < 0.999f) { + gpu_scene_texture.reset(SDL_CreateTexture(renderer.get(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, view3d_w, view3d_h)); + if (gpu_scene_texture) { + SDL_SetTextureScaleMode(gpu_scene_texture.get(), SDL_SCALEMODE_LINEAR); + } } ava2::TextTailManager::Instance().SetCurrentRenderer(renderer.get()); ava2::TextTailManager::Instance().SetCurrentSceneRenderer(renderer3d.get()); @@ -981,7 +1013,20 @@ int main(int argc, char** argv) { std::string chat_input_buffer; auto prev_frame_time = std::chrono::steady_clock::now(); + auto cap_period = fps_cap > 0 ? std::chrono::nanoseconds(1'000'000'000LL / fps_cap) + : std::chrono::nanoseconds(0); + auto next_frame_at = std::chrono::steady_clock::now(); + while (running && (!frame_limit || frames < frame_limit)) { + if (cap_period.count() > 0) { + const auto now = std::chrono::steady_clock::now(); + if (next_frame_at > now) { + std::this_thread::sleep_until(next_frame_at); + } else if (now - next_frame_at > cap_period) { + next_frame_at = now; + } + next_frame_at += cap_period; + } #ifdef AVA2_HAS_PYTHON ava2::LoginViewSnapshot snapshot; if (python && !view_script.empty()) { @@ -1010,7 +1055,7 @@ int main(int argc, char** argv) { wm->RunMouseLeftButtonDown(static_cast(bx), static_cast(by)); if (last_phase == "game" && renderer3d) { // Ignore clicks on the minimap radar at top-right - bool is_minimap_area = (bx >= static_cast(view3d_w) - 135.0f && by <= 140.0f); + bool is_minimap_area = (bx >= static_cast(screen_width) - 135.0f && by <= 140.0f); if (!is_minimap_area) { // 1. Mouse picking on dropped items via TextTail auto& ttm = ava2::TextTailManager::Instance(); @@ -1709,27 +1754,18 @@ int main(int argc, char** argv) { uint32_t clear_col = (last_phase == "game") ? current_env.fog.GetColorUint() : 0x00000000; if (use_gpu_raster) { // High Performance Hardware-Accelerated GPU Pipeline (Metal / Vulkan via SDL_RenderGeometry) + if (gpu_scene_texture) { + SDL_SetRenderTarget(renderer.get(), gpu_scene_texture.get()); + SDL_SetRenderDrawColor(renderer.get(), (clear_col >> 16) & 0xFF, (clear_col >> 8) & 0xFF, clear_col & 0xFF, (clear_col >> 24) & 0xFF); + SDL_RenderClear(renderer.get()); + } + renderer3d->RenderSceneGPU(renderer.get(), draws); - // Render Minimap Radar HUD in game phase (modeled after 40250 CPythonMiniMap) - if (last_phase == "game") { - minimap_mgr.ClearBlips(); - if (preview_data) { - if (!mob_dog.IsDead()) { - minimap_mgr.AddBlip(mob_dog.GetX(), mob_dog.GetZ(), ava2::MinimapBlipType::Monster); - } - if (!mob_metin.IsDead()) { - minimap_mgr.AddBlip(mob_metin.GetX(), mob_metin.GetZ(), ava2::MinimapBlipType::Monster); - } - } - minimap_mgr.AddBlip(60.0f, 140.0f, ava2::MinimapBlipType::NPC); // NPC - - SDL_FillSurfaceRect(surface3d.get(), nullptr, 0x00000000); - minimap_mgr.RenderRadar(surface3d.get(), view3d_w - 132, 5, 128, player_world_x, player_world_z, player_world_yaw); - SDL_UpdateTexture(texture3d.get(), nullptr, surface3d->pixels, surface3d->pitch); - SDL_SetTextureBlendMode(texture3d.get(), SDL_BLENDMODE_BLEND); - SDL_FRect dst = { 0.0f, 0.0f, static_cast(view3d_w), static_cast(view3d_h) }; - SDL_RenderTexture(renderer.get(), texture3d.get(), nullptr, &dst); + if (gpu_scene_texture) { + SDL_SetRenderTarget(renderer.get(), nullptr); + SDL_FRect dst = { 0.0f, 0.0f, static_cast(screen_width), static_cast(screen_height) }; + SDL_RenderTexture(renderer.get(), gpu_scene_texture.get(), nullptr, &dst); } } else { // CPU Software Rasterizer (Fallback & Headless verification) @@ -1737,25 +1773,39 @@ int main(int argc, char** argv) { renderer3d->Clear(clear_col, 1.0f); renderer3d->RenderScene(surface3d.get(), draws); - // Render Minimap Radar HUD in game phase (modeled after 40250 CPythonMiniMap) - if (last_phase == "game") { - minimap_mgr.ClearBlips(); - if (preview_data) { - if (!mob_dog.IsDead()) { - minimap_mgr.AddBlip(mob_dog.GetX(), mob_dog.GetZ(), ava2::MinimapBlipType::Monster); - } - if (!mob_metin.IsDead()) { - minimap_mgr.AddBlip(mob_metin.GetX(), mob_metin.GetZ(), ava2::MinimapBlipType::Monster); - } - } - minimap_mgr.AddBlip(60.0f, 140.0f, ava2::MinimapBlipType::NPC); // NPC - minimap_mgr.RenderRadar(surface3d.get(), view3d_w - 132, 5, 128, player_world_x, player_world_z, player_world_yaw); - } - SDL_UpdateTexture(texture3d.get(), nullptr, surface3d->pixels, surface3d->pitch); - SDL_FRect dst = { 0.0f, 0.0f, static_cast(view3d_w), static_cast(view3d_h) }; + SDL_FRect dst = { 0.0f, 0.0f, static_cast(screen_width), static_cast(screen_height) }; SDL_RenderTexture(renderer.get(), texture3d.get(), nullptr, &dst); } + + // Render Minimap Radar HUD in game phase (modeled after 40250 CPythonMiniMap) + if (last_phase == "game") { + minimap_mgr.ClearBlips(); + if (preview_data) { + if (!mob_dog.IsDead()) { + minimap_mgr.AddBlip(mob_dog.GetX(), mob_dog.GetZ(), ava2::MinimapBlipType::Monster); + } + if (!mob_metin.IsDead()) { + minimap_mgr.AddBlip(mob_metin.GetX(), mob_metin.GetZ(), ava2::MinimapBlipType::Monster); + } + } + minimap_mgr.AddBlip(60.0f, 140.0f, ava2::MinimapBlipType::NPC); // NPC + + if (!minimap_surface) { + minimap_surface.reset(SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_ARGB8888)); + minimap_texture.reset(SDL_CreateTexture(renderer.get(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 128, 128)); + if (minimap_texture) { + SDL_SetTextureBlendMode(minimap_texture.get(), SDL_BLENDMODE_BLEND); + } + } + if (minimap_surface && minimap_texture) { + SDL_FillSurfaceRect(minimap_surface.get(), nullptr, 0x00000000); + minimap_mgr.RenderRadar(minimap_surface.get(), 0, 0, 128, player_world_x, player_world_z, player_world_yaw); + SDL_UpdateTexture(minimap_texture.get(), nullptr, minimap_surface->pixels, minimap_surface->pitch); + SDL_FRect dst = { static_cast(screen_width - 132), 5.0f, 128.0f, 128.0f }; + SDL_RenderTexture(renderer.get(), minimap_texture.get(), nullptr, &dst); + } + } } }