diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index c2239ee9..6c5befdf 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -275,7 +275,7 @@ if(DMC_NATIVE_READER_BUILD_TESTS) enable_testing() set(DMC_NATIVE_READER_TESTS black_widow_state composite_builder composite_mod_scene composite_placement core_model_pipeline cxx23_profile dds_ptx_v1 - em028_corpus_contract gdata_legacy mod_spatial_adapter module_registry + em028_corpus_contract effect_visualization gdata_legacy mod_spatial_adapter module_registry png_export_session ptx_model_texture ptx_runtime_compat ptx_transaction render_scene scm_authority spider_event_execution spider_model_execution uv_gallery session_inspection tm2_legacy workspace_graph motion_playback pac_assembly player_coat diff --git a/app/src/main/cpp/app_native.cpp b/app/src/main/cpp/app_native.cpp index f459290b..d075f115 100644 --- a/app/src/main/cpp/app_native.cpp +++ b/app/src/main/cpp/app_native.cpp @@ -300,12 +300,13 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_imagePreviewWidth( JNIEnv*, jclass, jlong handle) { const SessionLock jni_lock{session_mutex()}; const Session* session = from_handle(handle); - if (session == nullptr || !session->image_preview.available() || - session->image_preview.width > static_cast( + const auto* preview = dmcresource::session_active_preview(session); + if (preview == nullptr || !preview->available() || + preview->width > static_cast( std::numeric_limits::max())) { return 0; } - return static_cast(session->image_preview.width); + return static_cast(preview->width); } extern "C" JNIEXPORT jint JNICALL @@ -313,12 +314,13 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_imagePreviewHeight( JNIEnv*, jclass, jlong handle) { const SessionLock jni_lock{session_mutex()}; const Session* session = from_handle(handle); - if (session == nullptr || !session->image_preview.available() || - session->image_preview.height > static_cast( + const auto* preview = dmcresource::session_active_preview(session); + if (preview == nullptr || !preview->available() || + preview->height > static_cast( std::numeric_limits::max())) { return 0; } - return static_cast(session->image_preview.height); + return static_cast(preview->height); } extern "C" JNIEXPORT jboolean JNICALL @@ -326,8 +328,34 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_imagePreview( JNIEnv* env, jclass, jlong handle, jobject target) { const SessionLock jni_lock{session_mutex()}; const Session* session = from_handle(handle); - if (session == nullptr) return JNI_FALSE; - return preview_to_bitmap(env, target, session->image_preview) + const auto* preview = dmcresource::session_active_preview(session); + if (preview == nullptr) return JNI_FALSE; + return preview_to_bitmap(env, target, *preview) + ? JNI_TRUE : JNI_FALSE; +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_hasDualPreview( + JNIEnv*, jclass, jlong handle) { + const SessionLock jni_lock{session_mutex()}; + return dmcresource::session_has_dual_preview(from_handle(handle)) + ? JNI_TRUE : JNI_FALSE; +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_infoPreviewActive( + JNIEnv*, jclass, jlong handle) { + const SessionLock jni_lock{session_mutex()}; + return dmcresource::session_info_preview_active(from_handle(handle)) + ? JNI_TRUE : JNI_FALSE; +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_setInfoPreviewActive( + JNIEnv*, jclass, jlong handle, jboolean active) { + const SessionLock jni_lock{session_mutex()}; + return dmcresource::session_set_info_preview( + from_handle(handle), active == JNI_TRUE) ? JNI_TRUE : JNI_FALSE; } diff --git a/app/src/main/cpp/include/dmcresource/child_resource.h b/app/src/main/cpp/include/dmcresource/child_resource.h index 7e931858..7a7484dd 100644 --- a/app/src/main/cpp/include/dmcresource/child_resource.h +++ b/app/src/main/cpp/include/dmcresource/child_resource.h @@ -25,7 +25,12 @@ struct ChildResource { ResourceCapabilities capabilities{}; InspectionDocument inspection; RenderScene scene; + // Primary visual representation used by the normal viewer/gallery. ImagePreview image_preview; + // Optional evidence/diagnostic representation of the same logical child. + // FXBANK records use this for the EXE-backed Info mode while image_preview + // remains the Visual/Playback-facing surface. + ImagePreview info_preview; std::vector children; // Optional bounded source payload for lazy child materialization. Containers diff --git a/app/src/main/cpp/include/dmcresource/effect_bank.h b/app/src/main/cpp/include/dmcresource/effect_bank.h index 3b8efb5a..3d9d4d26 100644 --- a/app/src/main/cpp/include/dmcresource/effect_bank.h +++ b/app/src/main/cpp/include/dmcresource/effect_bank.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -40,7 +41,8 @@ struct Bank final { // Registrar address of a kind (0 when the loader ignores it). [[nodiscard]] std::uint64_t registrar(char kind) noexcept; -// Short description of a kind; tentative except T (texture) and M (model). +// Neutral runtime-kind description. It does not claim an original filename +// or file extension; T/M mention only byte-confirmed payload families. [[nodiscard]] std::string_view kind_name(char kind) noexcept; // Structural identity: PNST, slot 0 a manifest whose first token is one @@ -67,4 +69,68 @@ struct SpriteAnimation final { }; [[nodiscard]] std::optional sprite_animation(const Record& record); +// Runtime-facing views recovered from the canonical dmc3.exe consumers. These +// structs intentionally expose only fields whose access pattern is proven by +// the executable; unknown bytes remain outside the typed view. + +// V: fixed 0x2C-byte entries. 0x140324680 builds a local transform from +// translation, degree rotation (converted to radians), and scale, then +// dispatches the referenced child: +// 0=P, 1=E, 2=G, 3=V. +struct VEntry final { + std::uint8_t dispatch{}; + std::uint16_t id{}; + std::array translation{}; + std::array rotation_degrees{}; + std::array scale{}; +}; +struct VRuntimeView final { + std::int16_t count{}; + std::vector entries; +}; +[[nodiscard]] std::optional v_runtime_view(const Record& record); + +// E: 0x1402E3AA0 resolves +0x04 through the T texture manager. When +0x06 is +// one and +0x08 != 0xFFFF, 0x1402E494F binds that id through the A manager. +// Otherwise +0x0C..+0x12 are copied directly into the runtime rectangle. +struct ERuntimeView final { + std::uint8_t mode{}; + std::uint16_t texture_id{0xFFFFU}; + bool uses_animation{}; + std::uint16_t animation_id{0xFFFFU}; + SpriteFrame rectangle{}; +}; +[[nodiscard]] std::optional e_runtime_view(const Record& record); + +// G: the generator consumer 0x1402EBC10 reads these offsets directly. Exact +// gameplay labels for several scalar fields are still intentionally withheld; +// the view keeps their source offsets explicit instead of guessing semantics. +struct GRuntimeView final { + std::uint8_t mode{}; + std::uint16_t c_id{}; + std::int32_t value_18{}; + std::int32_t value_20{}; + std::uint8_t mode_30{}; + float value_38{}; + float value_3c{}; + std::uint16_t steps_40{}; + float value_50{}; + float value_54{}; + std::uint8_t value_59{}; +}; +[[nodiscard]] std::optional g_runtime_view(const Record& record); + +// P: 0x140312DC0 validates version 2, rebases the relative pointers stored +// from +0x10, and returns the root object. 0x140312840 dispatches on root+1 +// with runtime subtype 0..5. The optional child target list is described by +// root+0xC0 and the relative offsets beginning at raw+0x18. +struct PRuntimeView final { + std::uint32_t version{}; + std::uint8_t subtype{}; + std::uint32_t root_offset{}; + std::uint32_t list_offset{}; + std::vector target_offsets; +}; +[[nodiscard]] std::optional p_runtime_view(const Record& record); + } // namespace dmcresource::effect_bank diff --git a/app/src/main/cpp/include/dmcresource/format_views.h b/app/src/main/cpp/include/dmcresource/format_views.h index d9c5f45f..e45a0852 100644 --- a/app/src/main/cpp/include/dmcresource/format_views.h +++ b/app/src/main/cpp/include/dmcresource/format_views.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -45,6 +46,33 @@ inline constexpr int kViewHeight = 1440; [[nodiscard]] ImagePreview render_sprite_view(const effect_bank::SpriteAnimation& animation, std::uint32_t record_id, const ImagePreview* texture); +// FXBANK effect-record views recovered from the runtime consumers. T keeps its +// decoded DDS view, A keeps render_sprite_view, and M uses the ordinary model +// renderer. This view covers the remaining registered effect kinds so a PNST +// gallery never has to represent them as empty black tiles. E may receive its +// resolved T texture and optional A animation from the owning bank. +[[nodiscard]] ImagePreview render_effect_record_view( + const effect_bank::Record& record, + const ImagePreview* texture = nullptr, + const effect_bank::SpriteAnimation* animation = nullptr); + +// Cleaner Visual-mode projection. It intentionally uses only confirmed runtime +// links/fields; missing linked previews stay explicit instead of being guessed. +struct EffectLinkedVisual final { + char kind{}; + std::uint32_t id{}; + std::array translation{}; + std::array rotation_degrees{}; + std::array scale{1.0F, 1.0F, 1.0F}; + const ImagePreview* preview{}; +}; + +[[nodiscard]] ImagePreview render_effect_visual_view( + const effect_bank::Record& record, + const ImagePreview* texture = nullptr, + const effect_bank::SpriteAnimation* animation = nullptr, + std::span linked = {}); + // Attack index: every entry (id, target mask, bone, shape). [[nodiscard]] ImagePreview render_attack_index_view(const std::vector& entries); diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index f24fd937..a456391e 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -35,7 +35,11 @@ struct Session { dmcresource::ResourceCapabilities capabilities{}; dmcresource::InspectionDocument inspection; dmcresource::RenderScene scene; + // Primary visual/playback-facing preview. dmcresource::ImagePreview image_preview; + // Optional evidence/diagnostic view of the same logical effect/resource. + dmcresource::ImagePreview info_preview; + bool info_preview_active{}; std::vector children; dmcresource::Mesh render_mesh; @@ -189,6 +193,13 @@ struct Session { [[nodiscard]] const ImagePreview* session_child_preview( const Session* session, int index, ImagePreview* scratch); [[nodiscard]] std::unique_ptr open_session_child(const Session* session, int index); + +// Dual Visual / Info surface. The active preview is the image exposed to +// platform shells; sessions without info_preview behave exactly as before. +[[nodiscard]] bool session_has_dual_preview(const Session* session) noexcept; +[[nodiscard]] bool session_info_preview_active(const Session* session) noexcept; +[[nodiscard]] bool session_set_info_preview(Session* session, bool info) noexcept; +[[nodiscard]] const ImagePreview* session_active_preview(const Session* session) noexcept; [[nodiscard]] std::string describe_session(const Session* session); [[nodiscard]] spider::black_widow::StateBits black_widow_state(const Session* session) noexcept; diff --git a/app/src/main/cpp/modules/effect_bank.cpp b/app/src/main/cpp/modules/effect_bank.cpp index 83c86c0a..43c68c5a 100644 --- a/app/src/main/cpp/modules/effect_bank.cpp +++ b/app/src/main/cpp/modules/effect_bank.cpp @@ -5,12 +5,39 @@ namespace dmcresource::effect_bank { namespace { +[[nodiscard]] std::uint16_t u16(std::span b, std::size_t o) noexcept { + if (o + 2U > b.size()) return 0U; + return static_cast( + static_cast(b[o]) | + (static_cast(b[o + 1U]) << 8U)); +} + [[nodiscard]] std::uint32_t u32(std::span b, std::size_t o) noexcept { if (o + 4U > b.size()) return 0U; return static_cast(b[o]) | (static_cast(b[o + 1U]) << 8U) | (static_cast(b[o + 2U]) << 16U) | (static_cast(b[o + 3U]) << 24U); } +[[nodiscard]] std::int32_t i32(std::span b, std::size_t o) noexcept { + return static_cast(u32(b, o)); +} + +[[nodiscard]] float f32(std::span b, std::size_t o) noexcept { + const auto bits = u32(b, o); + float value = 0.0F; + std::memcpy(&value, &bits, sizeof(value)); + return value; +} + +[[nodiscard]] bool add_relative(std::size_t base, std::int32_t relative, + std::size_t size, std::size_t* out) noexcept { + if (out == nullptr) return false; + const auto absolute = static_cast(base) + static_cast(relative); + if (absolute < 0 || static_cast(absolute) >= size) return false; + *out = static_cast(absolute); + return true; +} + // Relative-slot container (PNST): magic, u32 count, u32 offsets from the // container start; a slot ends at the next larger offset. struct Slots final { @@ -104,16 +131,19 @@ std::uint64_t registrar(char kind) noexcept { } std::string_view kind_name(char kind) noexcept { + // Keep the UI neutral: letters are the canonical manifest/runtime kinds. + // Do not turn nearby class names or tool-side interpretations into file + // format names. Only T/M carry a byte-backed payload description here. switch (kind) { - case 'T': return "texture (descriptor + DDS)"; - case 'M': return "model (MOD / EFM) + companion"; - case 'G': return "generator (registrar near CGenerator)"; - case 'E': return "effect (registrar near CEffectClip)"; - case 'P': return "P record (registrar 0x140314B80)"; - case 'V': return "V record (clip / value registrar)"; - case 'A': return "A record (clip registrar)"; - case 'C': return "C record (registrar 0x1402D3BE0)"; - default: return "not registered by the loader"; + case 'T': return "T record (descriptor + DDS payload)"; + case 'M': return "M record (MOD / EFM payload + companion)"; + case 'V': return "V record (P/E/G/V composite dispatch)"; + case 'G': return "G record"; + case 'E': return "E record"; + case 'P': return "P record"; + case 'A': return "A record"; + case 'C': return "C record"; + default: return "unregistered manifest kind"; } } @@ -195,4 +225,116 @@ std::span texture_dds(const Record& record) noexcept { return b.subspan(kTextureDescriptorSize); } +std::optional v_runtime_view(const Record& record) { + if (record.kind != 'V' || record.bytes.size() < 0x30U) return std::nullopt; + const auto b = record.bytes; + const auto signed_count = static_cast(u16(b, 0U)); + if (signed_count < 0 || signed_count > 64) return std::nullopt; + + VRuntimeView out; + out.count = signed_count; + out.entries.reserve(static_cast(signed_count)); + for (std::int16_t index = 0; index < signed_count; ++index) { + const std::size_t base = static_cast(index) * 0x2CU; + if (base + 0x30U > b.size()) return std::nullopt; + + VEntry entry; + entry.dispatch = b[base + 0x04U]; + entry.id = u16(b, base + 0x06U); + entry.translation = { + f32(b, base + 0x0CU), + f32(b, base + 0x10U), + f32(b, base + 0x14U), + }; + entry.rotation_degrees = { + f32(b, base + 0x18U), + f32(b, base + 0x1CU), + f32(b, base + 0x20U), + }; + entry.scale = { + f32(b, base + 0x24U), + f32(b, base + 0x28U), + f32(b, base + 0x2CU), + }; + out.entries.push_back(entry); + } + return out; +} + +std::optional e_runtime_view(const Record& record) { + if (record.kind != 'E' || record.bytes.size() < 0x14U) return std::nullopt; + const auto b = record.bytes; + + ERuntimeView out; + out.mode = b[0x01U]; + out.texture_id = u16(b, 0x04U); + out.uses_animation = b[0x06U] == 1U && u16(b, 0x08U) != 0xFFFFU; + out.animation_id = u16(b, 0x08U); + out.rectangle = { + u16(b, 0x0CU), + u16(b, 0x0EU), + u16(b, 0x10U), + u16(b, 0x12U), + }; + return out; +} + +std::optional g_runtime_view(const Record& record) { + if (record.kind != 'G' || record.bytes.size() < 0x5AU) return std::nullopt; + const auto b = record.bytes; + + GRuntimeView out; + out.mode = b[0x01U]; + out.c_id = u16(b, 0x02U); + out.value_18 = i32(b, 0x18U); + out.value_20 = i32(b, 0x20U); + out.mode_30 = b[0x30U]; + out.value_38 = f32(b, 0x38U); + out.value_3c = f32(b, 0x3CU); + out.steps_40 = u16(b, 0x40U); + out.value_50 = f32(b, 0x50U); + out.value_54 = f32(b, 0x54U); + out.value_59 = b[0x59U]; + return out; +} + +std::optional p_runtime_view(const Record& record) { + if (record.kind != 'P' || record.bytes.size() < 0x20U) return std::nullopt; + const auto b = record.bytes; + const auto version = u32(b, 0U); + if (version != 2U) return std::nullopt; + + constexpr std::size_t kRelativeBase = 0x10U; + std::size_t root = 0U; + std::size_t list = 0U; + if (!add_relative(kRelativeBase, i32(b, 0x10U), b.size(), &root) || + !add_relative(kRelativeBase, i32(b, 0x14U), b.size(), &list) || + root + 0xCAU > b.size()) { + return std::nullopt; + } + + const auto count = u16(b, root + 0xC0U); + // 0x140312DC0 stages the relative target table from raw+0x18 in a + // bounded 0xD0-byte local block, leaving at most 50 entries. + if (count > 50U || 0x18U + static_cast(count) * 4U > b.size()) { + return std::nullopt; + } + + PRuntimeView out; + out.version = version; + out.subtype = b[root + 0x01U]; + out.root_offset = static_cast(root); + out.list_offset = static_cast(list); + out.target_offsets.reserve(count); + for (std::uint16_t index = 0U; index < count; ++index) { + std::size_t target = 0U; + if (!add_relative(kRelativeBase, i32(b, 0x18U + static_cast(index) * 4U), + b.size(), &target)) { + return std::nullopt; + } + out.target_offsets.push_back(static_cast(target)); + } + return out; +} + } // namespace dmcresource::effect_bank diff --git a/app/src/main/cpp/modules/format_views.cpp b/app/src/main/cpp/modules/format_views.cpp index 603d056a..7be4a260 100644 --- a/app/src/main/cpp/modules/format_views.cpp +++ b/app/src/main/cpp/modules/format_views.cpp @@ -642,6 +642,678 @@ ImagePreview render_sprite_view(const effect_bank::SpriteAnimation& a, std::uint return canvas.take(); } + +namespace { + +struct TextureFit final { + int x{}; + int y{}; + int width{}; + int height{}; + float scale{}; +}; + +[[nodiscard]] TextureFit draw_texture_fit(Canvas& canvas, const ImagePreview& texture, + int left, int top, int right, int bottom) { + if (!texture.available() || right <= left || bottom <= top) return {}; + const int box_w = right - left; + const int box_h = bottom - top; + const float scale = std::min( + static_cast(box_w) / static_cast(texture.width), + static_cast(box_h) / static_cast(texture.height)); + const int width = std::max(1, static_cast(texture.width * scale)); + const int height = std::max(1, static_cast(texture.height * scale)); + const int x0 = left + (box_w - width) / 2; + const int y0 = top + (box_h - height) / 2; + canvas.fill(left, top, right, bottom, raster::kPanel); + for (int y = 0; y < height; ++y) { + const auto sy = std::min( + texture.height - 1U, + static_cast( + static_cast(y) * texture.height / + static_cast(height))); + for (int x = 0; x < width; ++x) { + const auto sx = std::min( + texture.width - 1U, + static_cast( + static_cast(x) * texture.width / + static_cast(width))); + const auto offset = + (static_cast(sy) * texture.width + sx) * 4U; + const auto alpha = texture.rgba8[offset + 3U]; + const auto mix = [alpha](std::uint8_t value, std::uint8_t bg) { + return static_cast( + (static_cast(value) * alpha + + static_cast(bg) * (255U - alpha)) / 255U); + }; + canvas.put( + x0 + x, y0 + y, + {mix(texture.rgba8[offset + 0U], raster::kPanel.r), + mix(texture.rgba8[offset + 1U], raster::kPanel.g), + mix(texture.rgba8[offset + 2U], raster::kPanel.b)}); + } + } + return {x0, y0, width, height, scale}; +} + +void outline(Canvas& canvas, int x0, int y0, int x1, int y1, Rgb color) { + if (x1 < x0 || y1 < y0) return; + canvas.line(x0, y0, x1, y0, color); + canvas.line(x1, y0, x1, y1, color); + canvas.line(x1, y1, x0, y1, color); + canvas.line(x0, y1, x0, y0, color); +} + +void draw_texture_rect(Canvas& canvas, const TextureFit& fit, + const effect_bank::SpriteFrame& frame, Rgb color) { + if (fit.width <= 0 || fit.height <= 0 || fit.scale <= 0.0F) return; + const int x0 = fit.x + static_cast(frame.x * fit.scale); + const int y0 = fit.y + static_cast(frame.y * fit.scale); + const int x1 = fit.x + static_cast((frame.x + frame.w) * fit.scale) - 1; + const int y1 = fit.y + static_cast((frame.y + frame.h) * fit.scale) - 1; + outline(canvas, x0, y0, x1, y1, color); +} + +void draw_texture_crop(Canvas& canvas, const ImagePreview& texture, + const effect_bank::SpriteFrame& frame, + int left, int top, int size) { + canvas.fill(left, top, left + size, top + size, raster::kPanel); + if (!texture.available() || frame.w == 0U || frame.h == 0U) return; + const float scale = std::min( + static_cast(size) / static_cast(frame.w), + static_cast(size) / static_cast(frame.h)); + const int width = std::max(1, static_cast(frame.w * scale)); + const int height = std::max(1, static_cast(frame.h * scale)); + const int x0 = left + (size - width) / 2; + const int y0 = top + (size - height) / 2; + for (int y = 0; y < height; ++y) { + const auto sy = std::min( + texture.height - 1U, + static_cast(frame.y) + + static_cast( + static_cast(y) * frame.h / + static_cast(height))); + for (int x = 0; x < width; ++x) { + const auto sx = std::min( + texture.width - 1U, + static_cast(frame.x) + + static_cast( + static_cast(x) * frame.w / + static_cast(width))); + const auto offset = + (static_cast(sy) * texture.width + sx) * 4U; + const auto alpha = texture.rgba8[offset + 3U]; + if (alpha == 0U) continue; + canvas.put(x0 + x, y0 + y, + {texture.rgba8[offset + 0U], + texture.rgba8[offset + 1U], + texture.rgba8[offset + 2U]}); + } + } + outline(canvas, left, top, left + size - 1, top + size - 1, raster::kGrid); +} + +[[nodiscard]] const char* v_dispatch_name(std::uint8_t dispatch) noexcept { + switch (dispatch) { + case 0U: return "P"; + case 1U: return "E"; + case 2U: return "G"; + case 3U: return "V"; + default: return "?"; + } +} + +[[nodiscard]] std::string vec3_text(const std::array& value) { + char buffer[128]; + std::snprintf(buffer, sizeof(buffer), "%.3g %.3g %.3g", + static_cast(value[0]), + static_cast(value[1]), + static_cast(value[2])); + return buffer; +} + +[[nodiscard]] ImagePreview render_e_record(const effect_bank::Record& record, + const effect_bank::ERuntimeView& view, + const ImagePreview* texture, + const effect_bank::SpriteAnimation* animation) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + const int small = std::max(1, scale - 1); + std::string header = "E " + std::to_string(record.id) + + " MODE " + std::to_string(view.mode); + if (view.texture_id != 0xFFFFU) header += " T " + std::to_string(view.texture_id); + if (view.uses_animation) header += " A " + std::to_string(view.animation_id); + canvas.text(10, 8, header, raster::kAccent, scale); + canvas.text(10, 8 + 9 * scale, + "EXE: T LINK +04; A LINK +08 WHEN +06=1; DIRECT RECT +0C..+12", + raster::kDim, small); + + const int top = 8 + 9 * scale + 9 * small + 14; + const int atlas_bottom = top + 760; + TextureFit fit{}; + if (texture != nullptr && texture->available()) { + fit = draw_texture_fit(canvas, *texture, 20, top, kViewWidth - 20, atlas_bottom); + if (animation != nullptr && !animation->frames.empty()) { + for (const auto& frame : animation->frames) { + draw_texture_rect(canvas, fit, frame, raster::kAccent); + } + } else { + draw_texture_rect(canvas, fit, view.rectangle, kGood); + } + } else { + canvas.fill(20, top, kViewWidth - 20, atlas_bottom, raster::kPanel); + canvas.text(40, top + 40, "NO T TEXTURE IN THIS BANK", raster::kDim, scale); + if (view.mode == 5U) { + canvas.text(40, top + 40 + 12 * scale, + "MODE 5 BYPASSES THE NORMAL TEXTURE PATH", + raster::kLabel, small); + } + } + + char rect[128]; + std::snprintf(rect, sizeof(rect), "RECT +0C: X %u Y %u W %u H %u", + view.rectangle.x, view.rectangle.y, + view.rectangle.w, view.rectangle.h); + int y = atlas_bottom + 18; + canvas.text(20, y, rect, raster::kLabel, small); + y += 11 * small; + + if (texture != nullptr && texture->available()) { + if (animation != nullptr && !animation->frames.empty()) { + const int cell = 150; + int x = 20; + std::size_t shown = 0U; + for (const auto& frame : animation->frames) { + if (shown == 6U || y + cell + 20 >= kViewHeight) break; + draw_texture_crop(canvas, *texture, frame, x, y + 12, cell); + canvas.text(x, y, std::to_string(shown), raster::kLabel, 1); + x += cell + 18; + ++shown; + } + } else if (view.rectangle.w != 0U && view.rectangle.h != 0U) { + draw_texture_crop(canvas, *texture, view.rectangle, 20, y + 14, 220); + } + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_v_record(const effect_bank::Record& record, + const effect_bank::VRuntimeView& view) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + const int small = std::max(1, scale - 1); + canvas.text(10, 8, + "V " + std::to_string(record.id) + " COMPOSITE " + + std::to_string(view.entries.size()) + " ENTRIES", + raster::kAccent, scale); + canvas.text(10, 8 + 9 * scale, + "0=P 1=E 2=G 3=V T=TRANSLATION R=DEGREES S=SCALE", + raster::kDim, small); + + float max_xy = 1.0F; + for (const auto& entry : view.entries) { + max_xy = std::max(max_xy, std::fabs(entry.translation[0])); + max_xy = std::max(max_xy, std::fabs(entry.translation[1])); + } + + const int top0 = 8 + 9 * scale + 9 * small + 14; + const int count = std::max(1, static_cast(view.entries.size())); + const int panel_h = std::min(180, (kViewHeight - top0 - 10) / count - 6); + int top = top0; + for (std::size_t index = 0U; index < view.entries.size(); ++index) { + const auto& entry = view.entries[index]; + const int bottom = top + std::max(110, panel_h); + canvas.fill(10, top, kViewWidth - 10, bottom, raster::kPanel); + + std::string child = std::to_string(index) + " " + + v_dispatch_name(entry.dispatch) + " " + + std::to_string(entry.id); + canvas.text(18, top + 8, child, raster::kAccent, scale); + + const int cx = 110; + const int cy = top + (bottom - top) / 2 + 12; + const int radius = std::max(25, (bottom - top) / 2 - 24); + canvas.line(cx - radius, cy, cx + radius, cy, raster::kGrid); + canvas.line(cx, cy - radius, cx, cy + radius, raster::kGrid); + const int tx = cx + static_cast( + entry.translation[0] / max_xy * static_cast(radius)); + const int ty = cy - static_cast( + entry.translation[1] / max_xy * static_cast(radius)); + arrow(canvas, cx, cy, tx, ty, kGood); + + canvas.text(210, top + 12, + "T " + vec3_text(entry.translation), kGood, small); + canvas.text(210, top + 12 + 10 * small, + "R " + vec3_text(entry.rotation_degrees), kV, small); + canvas.text(210, top + 12 + 20 * small, + "S " + vec3_text(entry.scale), kU, small); + top = bottom + 6; + if (top >= kViewHeight - 20) break; + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_g_record(const effect_bank::Record& record, + const effect_bank::GRuntimeView& view) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + const int small = std::max(1, scale - 1); + canvas.text(10, 8, + "G " + std::to_string(record.id) + " RUNTIME GENERATOR VIEW", + raster::kAccent, scale); + canvas.text(10, 8 + 9 * scale, + "ONLY EXE-READ FIELDS ARE DRAWN; UNKNOWN SEMANTICS KEEP OFFSET LABELS", + raster::kDim, small); + + int y = 8 + 9 * scale + 9 * small + 18; + canvas.fill(14, y, kViewWidth - 14, y + 150, raster::kPanel); + std::string mode = "MODE +01 = " + std::to_string(view.mode); + if (view.mode == 1U) mode += " C " + std::to_string(view.c_id); + canvas.text(24, y + 12, mode, raster::kLabel, scale); + canvas.text(24, y + 12 + 12 * scale, + "+18 " + std::to_string(view.value_18) + + " +20 " + std::to_string(view.value_20) + + " +30 " + std::to_string(view.mode_30), + raster::kDim, small); + y += 170; + + const auto envelope = [&](const char* name, float a, float b, + int top, Rgb color) { + const int left = 90; + const int right = kViewWidth - 60; + const int height = 180; + canvas.fill(20, top, kViewWidth - 20, top + height, raster::kPanel); + canvas.text(30, top + 10, name, raster::kLabel, small); + const float lo = std::min({a, b, 0.0F}); + const float hi = std::max({a, b, 1.0F}); + const float span = std::max(1.0e-6F, hi - lo); + const auto to_y = [&](float value) { + return top + height - 24 - + static_cast((value - lo) / span * (height - 54)); + }; + canvas.line(left, top + height - 24, right, top + height - 24, raster::kGrid); + canvas.line(left, to_y(a), right, to_y(b), color); + canvas.circle(left, to_y(a), 5, color); + canvas.circle(right, to_y(b), 5, color); + char values[96]; + std::snprintf(values, sizeof(values), "%.5g -> %.5g", + static_cast(a), static_cast(b)); + canvas.text(30, top + height - 20, values, color, small); + }; + + envelope("+38 -> +3C (INTERPOLATED WHEN +40 != 0)", + view.value_38, view.value_3c, y, kGood); + y += 200; + canvas.text(30, y, "+40 STEPS = " + std::to_string(view.steps_40), + raster::kLabel, small); + y += 28; + envelope("+50 -> +54 (RUNTIME RANGE)", view.value_50, view.value_54, y, kU); + y += 210; + canvas.text(30, y, "+59 = " + std::to_string(view.value_59), + raster::kLabel, small); + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_p_record(const effect_bank::Record& record, + const effect_bank::PRuntimeView& view) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + const int small = std::max(1, scale - 1); + canvas.text(10, 8, + "P " + std::to_string(record.id) + " RELATIVE GRAPH", + raster::kAccent, scale); + canvas.text(10, 8 + 9 * scale, + "0x140312DC0 REBASE; 0x140312840 SUBTYPE DISPATCH 0..5", + raster::kDim, small); + + int y = 8 + 9 * scale + 9 * small + 18; + canvas.text(18, y, + "VERSION " + std::to_string(view.version) + + " SUBTYPE " + std::to_string(view.subtype) + + " ROOT +" + std::to_string(view.root_offset) + + " LIST +" + std::to_string(view.list_offset), + raster::kLabel, small); + y += 38; + + const int left = 40; + const int right = kViewWidth - 40; + const int axis_y = y + 120; + canvas.fill(20, y, kViewWidth - 20, y + 260, raster::kPanel); + canvas.line(left, axis_y, right, axis_y, raster::kGrid); + const auto to_x = [&](std::uint32_t offset) { + if (record.bytes.size() <= 1U) return left; + return left + static_cast( + static_cast(offset) * (right - left) / + static_cast(record.bytes.size() - 1U)); + }; + + const int root_x = to_x(view.root_offset); + const int list_x = to_x(view.list_offset); + canvas.line(root_x, axis_y - 55, root_x, axis_y + 55, raster::kAccent); + canvas.text(std::max(20, root_x - 30), axis_y - 75, "ROOT", raster::kAccent, 1); + canvas.line(list_x, axis_y - 45, list_x, axis_y + 45, kU); + canvas.text(std::max(20, list_x - 30), axis_y + 52, "LIST", kU, 1); + + for (std::size_t i = 0U; i < view.target_offsets.size(); ++i) { + const int x = to_x(view.target_offsets[i]); + canvas.line(list_x, axis_y + 30, x, axis_y - 28, kGood); + canvas.circle(x, axis_y - 28, 5, kGood); + canvas.text(std::max(20, x - 12), axis_y - 48, + std::to_string(i), kGood, 1); + } + + char span[96]; + std::snprintf(span, sizeof(span), "0 %zu BYTES", + record.bytes.size()); + canvas.text(left, y + 225, span, raster::kDim, small); + y += 285; + + canvas.text(20, y, + "TARGETS " + std::to_string(view.target_offsets.size()), + raster::kLabel, scale); + y += 12 * scale; + for (std::size_t i = 0U; i < view.target_offsets.size(); ++i) { + if (y + 10 * small >= kViewHeight) break; + char line[96]; + std::snprintf(line, sizeof(line), "%02zu -> +0x%04X", + i, view.target_offsets[i]); + canvas.text(30, y, line, kGood, small); + y += 10 * small; + } + + y += 20; + canvas.text(20, y, "RUNTIME SUBTYPE SELECTOR", raster::kLabel, small); + y += 18; + const int cell_w = (kViewWidth - 50) / 6; + for (int subtype = 0; subtype < 6; ++subtype) { + const int x0 = 20 + subtype * cell_w; + const int x1 = x0 + cell_w - 6; + canvas.fill(x0, y, x1, y + 80, + subtype == view.subtype ? raster::kGrid : raster::kPanel); + outline(canvas, x0, y, x1, y + 80, + subtype == view.subtype ? raster::kAccent : raster::kGrid); + canvas.text(x0 + cell_w / 2 - 3, y + 28, + std::to_string(subtype), + subtype == view.subtype ? raster::kAccent : raster::kDim, + scale); + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_registered_fallback(const effect_bank::Record& record) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + const int small = std::max(1, scale - 1); + std::string header = "FX " + std::string(1U, record.kind) + " " + + std::to_string(record.id) + " " + + std::to_string(record.bytes.size()) + " B"; + canvas.text(10, 8, header, raster::kAccent, scale); + canvas.text(10, 8 + 9 * scale, + "REGISTERED RECORD; SEMANTIC VIEW NOT YET TYPED", + raster::kDim, small); + + const int cols = 32; + const int cell = std::max(4, (kViewWidth - 40) / cols); + int top = 8 + 9 * scale + 9 * small + 24; + const std::size_t max_cells = + static_cast((kViewHeight - top - 20) / cell) * cols; + const auto count = std::min(max_cells, record.bytes.size()); + for (std::size_t i = 0U; i < count; ++i) { + const int x = 20 + static_cast(i % cols) * cell; + const int y = top + static_cast(i / cols) * cell; + const auto value = record.bytes[i]; + const Rgb color{ + static_cast(40U + value * 3U / 4U), + static_cast(50U + value / 2U), + static_cast(70U + value * 2U / 3U)}; + canvas.fill(x, y, x + cell - 1, y + cell - 1, color); + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_e_visual( + const effect_bank::Record& record, + const effect_bank::ERuntimeView& view, + const ImagePreview* texture, + const effect_bank::SpriteAnimation* animation) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + canvas.text(18, 14, + "E " + std::to_string(record.id) + " VISUAL", + raster::kAccent, scale); + + const int top = 58; + const int bottom = kViewHeight - 40; + if (texture == nullptr || !texture->available()) { + canvas.fill(20, top, kViewWidth - 20, bottom, raster::kPanel); + canvas.text(54, top + 54, + view.mode == 5U + ? "NO DIRECT TEXTURE PATH FOR THIS MODE" + : "LINKED T TEXTURE NOT AVAILABLE IN THIS BANK", + raster::kDim, std::max(1, scale - 1)); + return canvas.take(); + } + + const auto fit = draw_texture_fit( + canvas, *texture, 20, top, kViewWidth - 20, bottom); + if (animation != nullptr && !animation->frames.empty()) { + for (const auto& frame : animation->frames) { + draw_texture_rect(canvas, fit, frame, raster::kAccent); + } + const auto& frame = animation->frames.front(); + draw_texture_crop(canvas, *texture, frame, + kViewWidth - 300, bottom - 280, 240); + } else { + draw_texture_rect(canvas, fit, view.rectangle, kGood); + if (view.rectangle.w != 0U && view.rectangle.h != 0U) { + draw_texture_crop(canvas, *texture, view.rectangle, + kViewWidth - 300, bottom - 280, 240); + } + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_v_visual( + const effect_bank::Record& record, + const effect_bank::VRuntimeView& view, + std::span linked) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + canvas.text(18, 14, + "V " + std::to_string(record.id) + " COMPOSITE VISUAL", + raster::kAccent, scale); + canvas.text(18, 14 + 10 * scale, + "CONFIRMED XY TRANSLATION / SCALE PROJECTION; CHILD PIXELS WHEN RESOLVED", + raster::kDim, std::max(1, scale - 1)); + + const int left = 40; + const int right = kViewWidth - 40; + const int top = 100; + const int bottom = kViewHeight - 50; + const int cx = (left + right) / 2; + const int cy = (top + bottom) / 2; + canvas.fill(left, top, right, bottom, raster::kPanel); + canvas.line(left, cy, right, cy, raster::kGrid); + canvas.line(cx, top, cx, bottom, raster::kGrid); + + float max_xy = 1.0F; + for (const auto& entry : view.entries) { + max_xy = std::max(max_xy, std::fabs(entry.translation[0])); + max_xy = std::max(max_xy, std::fabs(entry.translation[1])); + } + + const auto find_link = [&linked](char kind, std::uint32_t id) + -> const EffectLinkedVisual* { + for (const auto& item : linked) { + if (item.kind == kind && item.id == id) return &item; + } + return nullptr; + }; + + for (std::size_t i = 0U; i < view.entries.size(); ++i) { + const auto& entry = view.entries[i]; + const char kind = v_dispatch_name(entry.dispatch)[0]; + const int x = cx + static_cast( + entry.translation[0] / max_xy * static_cast((right - left) / 2 - 100)); + const int y = cy - static_cast( + entry.translation[1] / max_xy * static_cast((bottom - top) / 2 - 100)); + const float raw_scale = (std::fabs(entry.scale[0]) + std::fabs(entry.scale[1])) * 0.5F; + const float bounded_scale = std::clamp(raw_scale, 0.5F, 2.0F); + const int half = static_cast(70.0F * bounded_scale); + + const auto* linked_item = find_link(kind, entry.id); + if (linked_item != nullptr && linked_item->preview != nullptr && + linked_item->preview->available()) { + draw_texture_fit(canvas, *linked_item->preview, + x - half, y - half, x + half, y + half); + outline(canvas, x - half, y - half, x + half, y + half, + raster::kAccent); + } else { + canvas.circle(x, y, std::max(8, half / 3), kGood); + } + + std::string label; + label.push_back(kind); + label += " " + std::to_string(entry.id); + canvas.text(std::max(left, x - half), std::max(top, y - half - 22), + label, raster::kLabel, 1); + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_g_visual( + const effect_bank::Record& record, + const effect_bank::GRuntimeView& view) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + canvas.text(18, 14, + "G " + std::to_string(record.id) + " PARAMETER VISUAL", + raster::kAccent, scale); + canvas.text(18, 14 + 10 * scale, + "NOT WORLD-SPACE PARTICLES: ONLY CONFIRMED INTERPOLATION/RANGE FIELDS", + raster::kDim, std::max(1, scale - 1)); + + const int left = 80; + const int right = kViewWidth - 80; + const int top = 180; + const int bottom = kViewHeight - 180; + canvas.fill(30, 120, kViewWidth - 30, kViewHeight - 80, raster::kPanel); + canvas.line(left, bottom, right, bottom, raster::kGrid); + + const std::uint32_t steps = std::clamp( + view.steps_40 == 0U ? 2U : view.steps_40, 2U, 64U); + const float lo = std::min({view.value_38, view.value_3c, 0.0F}); + const float hi = std::max({view.value_38, view.value_3c, 1.0F}); + const float span = std::max(1.0e-6F, hi - lo); + for (std::uint32_t i = 0U; i < steps; ++i) { + const float t = steps <= 1U ? 0.0F : + static_cast(i) / static_cast(steps - 1U); + const float value = view.value_38 + (view.value_3c - view.value_38) * t; + const float radius_value = view.value_50 + (view.value_54 - view.value_50) * t; + const int x = left + static_cast(t * static_cast(right - left)); + const int y = bottom - static_cast((value - lo) / span * + static_cast(bottom - top)); + const int radius = std::clamp( + static_cast(std::fabs(radius_value) * 7.0F), 4, 22); + canvas.circle(x, y, radius, i + 1U == steps ? raster::kAccent : kGood); + if (i > 0U) { + const float tp = static_cast(i - 1U) / + static_cast(steps - 1U); + const float vp = view.value_38 + (view.value_3c - view.value_38) * tp; + const int px = left + static_cast(tp * static_cast(right - left)); + const int py = bottom - static_cast((vp - lo) / span * + static_cast(bottom - top)); + canvas.line(px, py, x, y, kGood); + } + } + return canvas.take(); +} + +[[nodiscard]] ImagePreview render_p_visual( + const effect_bank::Record& record, + const effect_bank::PRuntimeView& view) { + Canvas canvas{kViewWidth, kViewHeight}; + const int scale = raster::card_scale(kViewWidth); + canvas.text(18, 14, + "P " + std::to_string(record.id) + " GRAPH VISUAL", + raster::kAccent, scale); + canvas.text(18, 14 + 10 * scale, + "RUNTIME SUBTYPE " + std::to_string(view.subtype) + + " / " + std::to_string(view.target_offsets.size()) + " TARGETS", + raster::kDim, std::max(1, scale - 1)); + + const int cx = kViewWidth / 2; + const int cy = kViewHeight / 2; + const int radius = 360; + canvas.fill(30, 110, kViewWidth - 30, kViewHeight - 50, raster::kPanel); + canvas.circle(cx, cy, 46, raster::kAccent); + canvas.text(cx - 22, cy - 5, "ROOT", raster::kLabel, 1); + + const auto count = view.target_offsets.size(); + for (std::size_t i = 0U; i < count; ++i) { + const double angle = count == 0U ? 0.0 : + (static_cast(i) / static_cast(count)) * + 6.283185307179586; + const int x = cx + static_cast(std::cos(angle) * radius); + const int y = cy + static_cast(std::sin(angle) * radius); + canvas.line(cx, cy, x, y, kGood); + canvas.circle(x, y, 28, kGood); + canvas.text(x - 8, y - 5, std::to_string(i), raster::kLabel, 1); + } + return canvas.take(); +} + +} // namespace + +ImagePreview render_effect_visual_view( + const effect_bank::Record& record, + const ImagePreview* texture, + const effect_bank::SpriteAnimation* animation, + std::span linked) { + if (record.kind == 'E') { + if (const auto view = effect_bank::e_runtime_view(record)) { + return render_e_visual(record, *view, texture, animation); + } + } else if (record.kind == 'V') { + if (const auto view = effect_bank::v_runtime_view(record)) { + return render_v_visual(record, *view, linked); + } + } else if (record.kind == 'G') { + if (const auto view = effect_bank::g_runtime_view(record)) { + return render_g_visual(record, *view); + } + } else if (record.kind == 'P') { + if (const auto view = effect_bank::p_runtime_view(record)) { + return render_p_visual(record, *view); + } + } + return render_registered_fallback(record); +} + +ImagePreview render_effect_record_view( + const effect_bank::Record& record, + const ImagePreview* texture, + const effect_bank::SpriteAnimation* animation) { + if (record.kind == 'E') { + if (const auto view = effect_bank::e_runtime_view(record)) { + return render_e_record(record, *view, texture, animation); + } + } else if (record.kind == 'V') { + if (const auto view = effect_bank::v_runtime_view(record)) { + return render_v_record(record, *view); + } + } else if (record.kind == 'G') { + if (const auto view = effect_bank::g_runtime_view(record)) { + return render_g_record(record, *view); + } + } else if (record.kind == 'P') { + if (const auto view = effect_bank::p_runtime_view(record)) { + return render_p_record(record, *view); + } + } + return render_registered_fallback(record); +} + BinaryProfile profile_binary(std::span bytes) { BinaryProfile out; out.size = bytes.size(); diff --git a/app/src/main/cpp/modules/module_effects.cpp b/app/src/main/cpp/modules/module_effects.cpp index cfbb6711..00a51730 100644 --- a/app/src/main/cpp/modules/module_effects.cpp +++ b/app/src/main/cpp/modules/module_effects.cpp @@ -19,18 +19,42 @@ namespace { // Effect record budget for decoded thumbnails (RGBA pixels). constexpr std::uint64_t kMaxThumbnailPixels = 4U * 1024U * 1024U; -[[nodiscard]] std::string record_filename(const effect_bank::Record& r) { - char base[32]; - std::snprintf(base, sizeof(base), "%c%03u", r.kind, r.id); +// Internal decoder hint only. FXBANK does not store historical child filenames: + // the canonical loader addresses records by manifest kind + numeric id and + // physical PNST slot. Keep UI labels separate from these neutral probe names. +[[nodiscard]] std::string record_probe_filename(const effect_bank::Record& r) { + char base[48]; + std::snprintf(base, sizeof(base), "slot_%04u", r.slot); std::string name{base}; if (r.kind == 'T') return name + ".dds"; if (r.kind == 'M') { - if (r.bytes.size() >= 4U && std::memcmp(r.bytes.data(), "EFM ", 4U) == 0) return name + ".efm"; - return name + ".mod"; + if (r.bytes.size() >= 4U && std::memcmp(r.bytes.data(), "EFM ", 4U) == 0) { + return name + ".efm"; + } + if (r.bytes.size() >= 4U && std::memcmp(r.bytes.data(), "MOD", 3U) == 0) { + return name + ".mod"; + } + } + return name + ".bin"; +} + +[[nodiscard]] std::string record_format_label(const effect_bank::Record& r) { + if (r.kind == 'T' && !effect_bank::texture_dds(r).empty()) return "DDS"; + if (r.kind == 'M') { + if (r.bytes.size() >= 4U && std::memcmp(r.bytes.data(), "EFM ", 4U) == 0) return "EFM"; + if (r.bytes.size() >= 4U && std::memcmp(r.bytes.data(), "MOD", 3U) == 0) return "MOD"; } - name += ".fx"; - name.push_back(static_cast(r.kind >= 'A' && r.kind <= 'Z' ? r.kind + 32 : 'x')); - return name; + return {}; +} + +[[nodiscard]] std::string record_title(const effect_bank::Record& r) { + std::string title; + title.push_back(r.kind); + title += " " + std::to_string(r.id); + const auto format = record_format_label(r); + if (!format.empty()) title += " · " + format; + title += " · " + std::to_string(r.bytes.size()) + " B"; + return title; } PipelineResult run_effect_bank_module(const NativeModule& module, @@ -94,6 +118,7 @@ PipelineResult run_effect_bank_module(const NativeModule& module, // Decoded textures of this bank by id (sprite views sample them). std::map textures; + std::map, std::size_t> child_by_key; std::uint64_t thumbnail_pixels = 0U; std::size_t index = 0U; for (const auto& r : bank->records) { @@ -101,14 +126,14 @@ PipelineResult run_effect_bank_module(const NativeModule& module, if (r.bytes.empty()) continue; ChildResource child; child.id = "fx-" + std::to_string(index - 1U); - child.suggested_filename = record_filename(r); + child.suggested_filename = record_probe_filename(r); std::span payload = r.bytes; if (r.kind == 'T') { const auto dds = effect_bank::texture_dds(r); if (!dds.empty()) payload = dds; } child.source_bytes.assign(payload.begin(), payload.end()); - child.title = child.suggested_filename + " · " + std::to_string(r.bytes.size()) + " B"; + child.title = record_title(r); child.probe = dmcresource::probe(child.suggested_filename, child.source_bytes.data(), child.source_bytes.size()); child.capabilities = capability(ResourceCapability::Inspection); @@ -132,24 +157,136 @@ PipelineResult run_effect_bank_module(const NativeModule& module, child.image_preview = std::move(decoded.image_preview); } } + child_by_key[{r.kind, r.id}] = out.children.size(); out.children.push_back(std::move(child)); } - // Sprite animations: drawn over their texture when the bank holds it. - std::size_t child_index = 0U; + // Bank-local A records are reusable by E records. Keep the parsed + // animation keyed by its manifest id; this mirrors the EXE's A manager + // lookup rather than deriving identity from a synthetic filename. + std::map animations; for (const auto& r : bank->records) { - if (r.bytes.empty()) continue; - auto& child = out.children[child_index++]; - if (r.kind != 'A') continue; - const auto sprite = effect_bank::sprite_animation(r); - if (!sprite) continue; - const auto found = textures.find(sprite->texture); - child.image_preview = views::render_sprite_view( - *sprite, r.id, found != textures.end() ? &found->second : nullptr); - child.capabilities = child.capabilities | ResourceCapability::ImagePreview; - child.detail += "\nSprite: texture T" + std::to_string(sprite->texture) + ", " + - std::to_string(sprite->frames.size()) + " frames, frame time " + - std::to_string(sprite->frame_time) + (sprite->loop ? ", loop" : ", once"); + if (r.kind != 'A' || r.bytes.empty()) continue; + if (auto sprite = effect_bank::sprite_animation(r)) { + animations.emplace(r.id, std::move(*sprite)); + } + } + + // Every registered effect record gets two native surfaces when the + // runtime structure is understood: + // Visual = texture/graph/parameter reconstruction from confirmed links + // Info = the EXE-backed diagnostic view with offsets/fields. + // T remains the real decoded texture; M remains the ordinary MOD/EFM 3D + // renderer. Their generic info is already available through the reader's + // normal information panel. + for (const auto& r : bank->records) { + if (r.bytes.empty() || r.kind == 'T' || r.kind == 'M') continue; + const auto child_found = child_by_key.find({r.kind, r.id}); + if (child_found == child_by_key.end()) continue; + auto& child = out.children[child_found->second]; + + if (r.kind == 'A') { + const auto animation = animations.find(r.id); + if (animation == animations.end()) { + child.image_preview = views::render_effect_visual_view(r); + } else { + const auto found = textures.find(animation->second.texture); + child.image_preview = views::render_sprite_view( + animation->second, r.id, + found != textures.end() ? &found->second : nullptr); + child.detail += "\nSprite: texture T" + + std::to_string(animation->second.texture) + ", " + + std::to_string(animation->second.frames.size()) + + " frames, frame time " + + std::to_string(animation->second.frame_time) + + (animation->second.loop ? ", loop" : ", once"); + } + child.info_preview = views::render_effect_record_view(r); + } else { + const ImagePreview* texture = nullptr; + const effect_bank::SpriteAnimation* animation = nullptr; + if (r.kind == 'E') { + if (const auto runtime = effect_bank::e_runtime_view(r)) { + const auto texture_found = textures.find(runtime->texture_id); + if (texture_found != textures.end()) { + texture = &texture_found->second; + } + if (runtime->uses_animation) { + const auto animation_found = + animations.find(runtime->animation_id); + if (animation_found != animations.end()) { + animation = &animation_found->second; + } + } + child.detail += "\nRuntime E: mode " + + std::to_string(runtime->mode) + + ", T " + std::to_string(runtime->texture_id); + if (runtime->uses_animation) { + child.detail += ", A " + + std::to_string(runtime->animation_id); + } + } + } + + child.image_preview = + views::render_effect_visual_view(r, texture, animation); + child.info_preview = + views::render_effect_record_view(r, texture, animation); + } + + if (child.image_preview.available()) { + child.capabilities = + child.capabilities | ResourceCapability::ImagePreview; + } } + + // V is a composite dispatcher. Re-render its Visual surface after every + // direct child acquired its own Visual image so V can show the actual + // resolved E texture imagery (and the graphical P/G/V child views) + // instead of only labels. This is a static reconstruction of confirmed + // dependencies/transforms, not yet a claim of frame-accurate gameplay. + for (const auto& r : bank->records) { + if (r.kind != 'V' || r.bytes.empty()) continue; + const auto runtime = effect_bank::v_runtime_view(r); + const auto child_found = child_by_key.find({r.kind, r.id}); + if (!runtime || child_found == child_by_key.end()) continue; + + std::vector linked; + linked.reserve(runtime->entries.size()); + for (const auto& entry : runtime->entries) { + char kind = '?'; + switch (entry.dispatch) { + case 0U: kind = 'P'; break; + case 1U: kind = 'E'; break; + case 2U: kind = 'G'; break; + case 3U: kind = 'V'; break; + default: break; + } + + const ImagePreview* preview = nullptr; + if (kind != '?') { + const auto target = child_by_key.find({kind, entry.id}); + if (target != child_by_key.end()) { + const auto& target_child = out.children[target->second]; + if (target_child.image_preview.available()) { + preview = &target_child.image_preview; + } + } + } + linked.push_back({ + kind, + entry.id, + entry.translation, + entry.rotation_degrees, + entry.scale, + preview, + }); + } + + auto& child = out.children[child_found->second]; + child.image_preview = views::render_effect_visual_view( + r, nullptr, nullptr, linked); + } + out.detail = detail.str(); return out; } catch (...) { diff --git a/app/src/main/cpp/modules/resource_session.cpp b/app/src/main/cpp/modules/resource_session.cpp index 5f5966d5..50963b93 100644 --- a/app/src/main/cpp/modules/resource_session.cpp +++ b/app/src/main/cpp/modules/resource_session.cpp @@ -365,6 +365,16 @@ InspectionNode make_composite_inspection_part(const Session& source, } // namespace std::unique_ptr session_from_child(const ChildResource& child) { + // Bank-aware FXBANK children may carry both a visual surface and an + // EXE-backed diagnostic surface. Opening them must preserve those parent- + // resolved views instead of discarding bank context by reopening only the + // isolated raw payload. + if (child.info_preview.available()) { + auto session = make_session(child, child.trace); + session->info_preview = child.info_preview; + session->info_preview_active = false; + return session; + } if (!child.image_preview.available() && has_capability(child.capabilities, ResourceCapability::ImagePreview) && !child.source_bytes.empty()) { @@ -417,7 +427,8 @@ std::unique_ptr session_from_child(const ChildResource& child) { .render_mesh = &session->render_mesh, .triangle_texture_slots = session->render_triangle_texture_slots, .hierarchy_available = session->hierarchy_overlay.available(), - .image_preview_available = session->image_preview.available(), + .image_preview_available = + session_active_preview(session) != nullptr, .child_resource_count = session_child_count(session), .texture_companion_attached = session->texture_companion_attached, .uv_map_view = session->uv_gallery && session->uv_map_index && @@ -431,6 +442,32 @@ std::unique_ptr session_from_child(const ChildResource& child) { }); } +bool session_has_dual_preview(const Session* session) noexcept { + return session != nullptr && + session->image_preview.available() && + session->info_preview.available(); +} + +bool session_info_preview_active(const Session* session) noexcept { + return session_has_dual_preview(session) && session->info_preview_active; +} + +bool session_set_info_preview(Session* session, bool info) noexcept { + if (!session_has_dual_preview(session)) return false; + session->info_preview_active = info; + return true; +} + +const ImagePreview* session_active_preview(const Session* session) noexcept { + if (session == nullptr) return nullptr; + if (session->info_preview_active && session->info_preview.available()) { + return &session->info_preview; + } + if (session->image_preview.available()) return &session->image_preview; + if (session->info_preview.available()) return &session->info_preview; + return nullptr; +} + namespace { // Every opened file gets a picture: a session with no mesh, no pixels, no diff --git a/app/src/main/cpp/modules/session_gallery.cpp b/app/src/main/cpp/modules/session_gallery.cpp index eae85c53..bb6e8b76 100644 --- a/app/src/main/cpp/modules/session_gallery.cpp +++ b/app/src/main/cpp/modules/session_gallery.cpp @@ -1,11 +1,131 @@ #include "dmcresource/resource_session.h" +#include +#include +#include +#include + +#include "dmcresource/raster_card.h" + namespace dmcresource { namespace { bool valid_child(const Session* session, int index) noexcept { return index >= 0 && static_cast(index) < session_child_count(session); } constexpr std::uint32_t kThumbnailSize = 256U; + +ImagePreview square_thumbnail(const ImagePreview& source) { + if (!source.available()) return {}; + + ImagePreview out; + out.width = kThumbnailSize; + out.height = kThumbnailSize; + out.rgba8.resize(static_cast(kThumbnailSize) * + static_cast(kThumbnailSize) * 4U); + + // Same dark neutral field as the gallery tile. A generated thumbnail is a + // presentation surface only; the source image stays untouched and opens + // at its real resolution when the tile is selected. + for (std::size_t offset = 0U; offset < out.rgba8.size(); offset += 4U) { + out.rgba8[offset + 0U] = 16U; + out.rgba8[offset + 1U] = 16U; + out.rgba8[offset + 2U] = 20U; + out.rgba8[offset + 3U] = 255U; + } + + std::uint32_t draw_w = kThumbnailSize; + std::uint32_t draw_h = kThumbnailSize; + if (source.width >= source.height) { + draw_h = std::max( + 1U, + static_cast( + static_cast(source.height) * kThumbnailSize / + source.width)); + } else { + draw_w = std::max( + 1U, + static_cast( + static_cast(source.width) * kThumbnailSize / + source.height)); + } + + const std::uint32_t origin_x = (kThumbnailSize - draw_w) / 2U; + const std::uint32_t origin_y = (kThumbnailSize - draw_h) / 2U; + for (std::uint32_t y = 0U; y < draw_h; ++y) { + const auto source_y = std::min( + source.height - 1U, + static_cast( + static_cast(y) * source.height / draw_h)); + for (std::uint32_t x = 0U; x < draw_w; ++x) { + const auto source_x = std::min( + source.width - 1U, + static_cast( + static_cast(x) * source.width / draw_w)); + const auto source_offset = + (static_cast(source_y) * source.width + source_x) * 4U; + const auto target_offset = + (static_cast(origin_y + y) * kThumbnailSize + + static_cast(origin_x + x)) * 4U; + std::copy_n(source.rgba8.data() + source_offset, 4U, + out.rgba8.data() + target_offset); + } + } + return out; +} + +ImagePreview square_thumbnail(RgbaImage image) { + if (image.width <= 0 || image.height <= 0) return {}; + ImagePreview source{ + static_cast(image.width), + static_cast(image.height), + std::move(image.pixels), + }; + return square_thumbnail(source); +} + +const ImagePreview* materialize_child_thumbnail( + const ChildResource& child, ImagePreview* scratch) { + if (scratch == nullptr || child.source_bytes.empty()) return nullptr; + + auto opened = session_from_child(child); + if (!opened) return nullptr; + + // Static 2D resources, MOT/CLT/TSC cards, raw effect records and the raw + // binary fallback already expose ImagePreview through their ordinary + // reader. Reuse that exact view rather than creating a gallery-only parser. + if (opened->image_preview.available()) { + *scratch = square_thumbnail(opened->image_preview); + return scratch->available() ? scratch : nullptr; + } + + // MOD / SCM / renderable EFM children have geometry rather than a static + // image. Draw the same native scene the full viewer opens, at thumbnail + // resolution. No format-specific Android path is introduced here. + if (opened->renderable) { + auto rendered = render_session( + opened.get(), + static_cast(kThumbnailSize), + static_cast(kThumbnailSize), + 0.65F, -0.45F, 1.0F, + render_flag(RenderFlag::Preview)); + *scratch = square_thumbnail(std::move(rendered)); + return scratch->available() ? scratch : nullptr; + } + + // A nested container may deliberately have children and therefore no + // standalone image of its own. Its inspection document is still useful in + // the gallery: show the same evidence card/byte surface the reader uses for + // non-renderable files, while keeping the tile clickable for navigation. + try { + const auto bytes = std::span{ + child.source_bytes.data(), child.source_bytes.size()}; + *scratch = square_thumbnail( + raster::render_info_card(opened->inspection, opened->detail, bytes)); + return scratch->available() ? scratch : nullptr; + } catch (...) { + return nullptr; + } +} } std::unique_ptr open_uv_gallery(const Session* model) { @@ -41,15 +161,43 @@ std::pair session_child_preview_size( const Session* session, int index) noexcept { if (!valid_child(session, index)) return {}; if (session->uv_gallery) return {kThumbnailSize, kThumbnailSize}; - const auto& preview = session->children[index].image_preview; - if (!preview.available()) return {}; - return {preview.width, preview.height}; + + const auto& child = session->children[static_cast(index)]; + if (child.image_preview.available()) { + if (child.image_preview.width <= kThumbnailSize && + child.image_preview.height <= kThumbnailSize) { + return {child.image_preview.width, child.image_preview.height}; + } + return {kThumbnailSize, kThumbnailSize}; + } + + // The child has enough retained source bytes for the same native reader + // that opens it on tap to create a thumbnail lazily. Returning a fixed + // square here lets Android allocate one small bitmap instead of a full + // 1080x1440 inspection card only to shrink it into a gallery tile. + if (!child.source_bytes.empty()) return {kThumbnailSize, kThumbnailSize}; + return {}; } const ImagePreview* session_child_preview( const Session* session, int index, ImagePreview* scratch) { if (!valid_child(session, index)) return nullptr; - if (!session->uv_gallery) return &session->children[index].image_preview; + if (!session->uv_gallery) { + const auto& child = session->children[static_cast(index)]; + if (child.image_preview.available()) { + // Preserve the original zero-copy transport for already-small + // previews. Only large resident images are reduced for gallery + // memory/bitmap cost. + if (child.image_preview.width <= kThumbnailSize && + child.image_preview.height <= kThumbnailSize) { + return &child.image_preview; + } + if (scratch == nullptr) return nullptr; + *scratch = square_thumbnail(child.image_preview); + return scratch->available() ? scratch : nullptr; + } + return materialize_child_thumbnail(child, scratch); + } if (!scratch) return nullptr; const auto& gallery = *session->uv_gallery; auto image = render_uv_map(gallery.coordinates, gallery.maps[index].indices, diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/DmcRenderView.java b/app/src/main/java/com/dmcrengine/nativeviewer/DmcRenderView.java index ee998005..bea4efa5 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/DmcRenderView.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/DmcRenderView.java @@ -465,6 +465,13 @@ private void loadStaticImagePreview() { invalidate(); } + /** Reload the currently selected native static preview without replacing the session. */ + public void refreshStaticImagePreview() { + if (session == 0) return; + staticImagePreview = false; + loadStaticImagePreview(); + } + public void resetView() { yaw = DEFAULT_YAW; pitch = -0.45f; diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java index 5110ae28..8e834a92 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java @@ -108,6 +108,10 @@ private static final class StagedAsset { // Position in the collision cycle: -1 all attacks, then each used id. private int collisionCursor = -2; private Button infoButton; + private HorizontalScrollView effectModeScroll; + private LinearLayout effectModeBar; + private Button effectVisualButton; + private Button effectInfoButton; private HorizontalScrollView motionScroll; private HorizontalScrollView toolScroll; // In-viewport notice (replaces Toasts so messages never cover the motion @@ -132,7 +136,7 @@ private static final class StagedAsset { private LinearLayout headerBar; // Hidden by the top-edge swipe: bars and the visibility each had. private boolean uiHidden; - private final int[] barVisibility = new int[4]; + private final int[] barVisibility = new int[5]; // Archive the root scene was assembled from (re-opened on demand so the // per-file browser owns an independent read-only handle). private Uri assembledPacUri; @@ -306,6 +310,33 @@ private void applyResourceUiState() { hasSession ? blackWidowState.canInspect : !infoText.isEmpty()); refreshMotionStrip(); refreshVariantBar(); + refreshEffectModeBar(); + } + + private void refreshEffectModeBar() { + if (effectModeScroll == null || effectVisualButton == null || effectInfoButton == null) { + return; + } + final boolean available = session != 0 && NativeBridge.hasDualPreview(session); + if (!available) { + effectModeScroll.setVisibility(View.GONE); + return; + } + + final boolean info = NativeBridge.infoPreviewActive(session); + effectVisualButton.setActivated(!info); + effectVisualButton.setAlpha(info ? 0.68f : 1.0f); + effectInfoButton.setActivated(info); + effectInfoButton.setAlpha(info ? 1.0f : 0.68f); + effectModeScroll.setVisibility(uiHidden ? View.GONE : View.VISIBLE); + } + + private void selectEffectPreviewMode(boolean info) { + if (session == 0 || !NativeBridge.hasDualPreview(session)) return; + if (!NativeBridge.setInfoPreviewActive(session, info)) return; + renderView.refreshStaticImagePreview(); + refreshEffectModeBar(); + notice(info ? "Info view" : "Visual view", Toast.LENGTH_SHORT); } private void applySystemBarInsets(LinearLayout root) { @@ -389,6 +420,40 @@ private void buildUi() { LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); + effectModeScroll = new HorizontalScrollView(this); + effectModeScroll.setHorizontalScrollBarEnabled(false); + effectModeScroll.setFillViewport(true); + effectModeScroll.setVisibility(View.GONE); + effectModeBar = new LinearLayout(this); + effectModeBar.setOrientation(LinearLayout.HORIZONTAL); + effectModeBar.setGravity(Gravity.CENTER); + effectModeBar.setPadding(dp(8), dp(2), dp(8), dp(2)); + + effectVisualButton = makeSquareButton("Visual", "Show reconstructed effect view", 13f); + effectVisualButton.setPadding(dp(18), 0, dp(18), 0); + effectVisualButton.setOnClickListener(v -> selectEffectPreviewMode(false)); + LinearLayout.LayoutParams visualParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, dp(TOOL_SIZE_DP - 8)); + visualParams.setMarginStart(dp(TOOL_GAP_DP)); + visualParams.setMarginEnd(dp(TOOL_GAP_DP)); + effectModeBar.addView(effectVisualButton, visualParams); + + effectInfoButton = makeSquareButton("Info", "Show EXE-backed effect information", 13f); + effectInfoButton.setPadding(dp(18), 0, dp(18), 0); + effectInfoButton.setOnClickListener(v -> selectEffectPreviewMode(true)); + LinearLayout.LayoutParams infoParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, dp(TOOL_SIZE_DP - 8)); + infoParams.setMarginStart(dp(TOOL_GAP_DP)); + infoParams.setMarginEnd(dp(TOOL_GAP_DP)); + effectModeBar.addView(effectInfoButton, infoParams); + + effectModeScroll.addView(effectModeBar, new HorizontalScrollView.LayoutParams( + HorizontalScrollView.LayoutParams.WRAP_CONTENT, + HorizontalScrollView.LayoutParams.WRAP_CONTENT)); + root.addView(effectModeScroll, new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + FrameLayout viewport = new FrameLayout(this); renderView = new DmcRenderView(this); renderView.setGestureListener(gestureListener); @@ -820,7 +885,7 @@ private void showSettingsDialog() { } @Override public void onToggleUi() { - final View[] bars = {headerBar, variantScroll, motionScroll, toolScroll}; + final View[] bars = {headerBar, variantScroll, effectModeScroll, motionScroll, toolScroll}; uiHidden = !uiHidden; for (int i = 0; i < bars.length; ++i) { if (bars[i] == null) continue; @@ -834,6 +899,7 @@ private void showSettingsDialog() { if (!uiHidden) { refreshMotionStrip(); refreshVariantBar(); + refreshEffectModeBar(); } notice(uiHidden ? "Full view — swipe down from the top to bring the bars back" : "Bars shown", Toast.LENGTH_SHORT); diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java index c3df88f6..4e84efc5 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java @@ -24,6 +24,12 @@ private NativeBridge() {} public static native int imagePreviewWidth(long handle); public static native int imagePreviewHeight(long handle); public static native boolean imagePreview(long handle, Bitmap target); + + // Optional dual preview used by FXBANK and any future resource that has a + // visual/playback representation plus a separate evidence/info rendering. + public static native boolean hasDualPreview(long handle); + public static native boolean infoPreviewActive(long handle); + public static native boolean setInfoPreviewActive(long handle, boolean active); public static native String inspection(long handle); public static final int INSPECT_UV = 1; public static final int INSPECT_MESHES = 2; diff --git a/app/src/test/native/effect_visualization_test.cpp b/app/src/test/native/effect_visualization_test.cpp new file mode 100644 index 00000000..89b3332a --- /dev/null +++ b/app/src/test/native/effect_visualization_test.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include + +#include "dmcresource/effect_bank.h" +#include "dmcresource/format_views.h" + +namespace { + +void put_u16(std::vector& b, std::size_t o, std::uint16_t v) { + b[o + 0U] = static_cast(v & 0xFFU); + b[o + 1U] = static_cast((v >> 8U) & 0xFFU); +} + +void put_u32(std::vector& b, std::size_t o, std::uint32_t v) { + for (std::size_t i = 0U; i < 4U; ++i) { + b[o + i] = static_cast((v >> (8U * i)) & 0xFFU); + } +} + +void put_f32(std::vector& b, std::size_t o, float v) { + std::uint32_t bits{}; + std::memcpy(&bits, &v, sizeof(bits)); + put_u32(b, o, bits); +} + +dmcresource::effect_bank::Record record( + char kind, std::uint32_t id, std::vector& bytes) { + dmcresource::effect_bank::Record out; + out.kind = kind; + out.id = id; + out.bytes = bytes; + return out; +} + +} // namespace + +int main() { + using namespace dmcresource; + using namespace dmcresource::effect_bank; + + std::vector v_bytes(368U, 0U); + put_u16(v_bytes, 0x00U, 1U); + v_bytes[0x04U] = 1U; // E + put_u16(v_bytes, 0x06U, 745U); + put_f32(v_bytes, 0x0CU, 1.0F); + put_f32(v_bytes, 0x10U, 2.0F); + put_f32(v_bytes, 0x14U, 3.0F); + put_f32(v_bytes, 0x18U, 0.0F); + put_f32(v_bytes, 0x1CU, 90.0F); + put_f32(v_bytes, 0x20U, 180.0F); + put_f32(v_bytes, 0x24U, 1.0F); + put_f32(v_bytes, 0x28U, 1.0F); + put_f32(v_bytes, 0x2CU, 1.0F); + auto v_record = record('V', 10U, v_bytes); + const auto v = v_runtime_view(v_record); + assert(v && v->entries.size() == 1U); + assert(v->entries[0].dispatch == 1U); + assert(v->entries[0].id == 745U); + assert(v->entries[0].translation[2] == 3.0F); + assert(v->entries[0].rotation_degrees[1] == 90.0F); + assert(v->entries[0].scale[0] == 1.0F); + assert(views::render_effect_record_view(v_record).available()); + assert(views::render_effect_visual_view(v_record).available()); + + std::vector e_bytes(544U, 0U); + e_bytes[0x01U] = 1U; + put_u16(e_bytes, 0x04U, 5U); + e_bytes[0x06U] = 1U; + put_u16(e_bytes, 0x08U, 110U); + put_u16(e_bytes, 0x0CU, 0U); + put_u16(e_bytes, 0x0EU, 96U); + put_u16(e_bytes, 0x10U, 16U); + put_u16(e_bytes, 0x12U, 16U); + auto e_record = record('E', 745U, e_bytes); + const auto e = e_runtime_view(e_record); + assert(e && e->texture_id == 5U); + assert(e->uses_animation); + assert(e->animation_id == 110U); + assert(e->rectangle.y == 96U); + assert(e->rectangle.w == 16U); + assert(views::render_effect_record_view(e_record).available()); + assert(views::render_effect_visual_view(e_record).available()); + + std::vector g_bytes(96U, 0U); + put_u32(g_bytes, 0x20U, 700U); + g_bytes[0x30U] = 1U; + put_f32(g_bytes, 0x38U, 1.5F); + put_f32(g_bytes, 0x3CU, 1.0F); + put_u16(g_bytes, 0x40U, 15U); + put_f32(g_bytes, 0x50U, 1.0F); + put_f32(g_bytes, 0x54U, 1.0F); + auto g_record = record('G', 214U, g_bytes); + const auto g = g_runtime_view(g_record); + assert(g && g->value_20 == 700); + assert(g->steps_40 == 15U); + assert(g->value_38 == 1.5F); + assert(views::render_effect_record_view(g_record).available()); + assert(views::render_effect_visual_view(g_record).available()); + + std::vector p_bytes(336U, 0U); + put_u32(p_bytes, 0x00U, 2U); + put_u32(p_bytes, 0x10U, 0x10U); // base 0x10 -> root 0x20 + put_u32(p_bytes, 0x14U, 0xF0U); // base 0x10 -> list 0x100 + put_u32(p_bytes, 0x18U, 0x110U); // base 0x10 -> target 0x120 + p_bytes[0x21U] = 3U; + put_u16(p_bytes, 0xE0U, 1U); // root + 0xC0 + auto p_record = record('P', 22U, p_bytes); + const auto p = p_runtime_view(p_record); + assert(p && p->version == 2U); + assert(p->subtype == 3U); + assert(p->root_offset == 0x20U); + assert(p->list_offset == 0x100U); + assert(p->target_offsets.size() == 1U); + assert(p->target_offsets[0] == 0x120U); + assert(views::render_effect_record_view(p_record).available()); + assert(views::render_effect_visual_view(p_record).available()); + + // Registered-but-not-yet-typed kinds still receive a concrete byte-map + // visual rather than an empty tile. + std::vector c_bytes(64U, 0x55U); + auto c_record = record('C', 7U, c_bytes); + assert(views::render_effect_record_view(c_record).available()); + + return 0; +} diff --git a/app/src/test/native/player_coat_test.cpp b/app/src/test/native/player_coat_test.cpp index 1a5c70bd..1148a4f5 100644 --- a/app/src/test/native/player_coat_test.cpp +++ b/app/src/test/native/player_coat_test.cpp @@ -1175,12 +1175,32 @@ int main() { dmcresource::Format::EffectBank); auto session = dmcresource::open_session("slot_0041.fxbank", bank_bytes.data(), bank_bytes.size()); assert(session && session->inspection.format == "FXBANK" && session->children.size() == 4U); - assert(session->children[0].suggested_filename == "T005.dds" && - session->children[1].suggested_filename == "M007.mod" && - session->children[2].suggested_filename == "A009.fxa" && + // FXBANK runtime identity is kind+id from the manifest, not a claimed + // historical child filename. Neutral probe names retain physical slot + // identity and only byte-confirmed extensions. + assert(session->children[0].suggested_filename == "slot_0000.dds" && + session->children[0].title.find("T 5") != std::string::npos && + session->children[1].suggested_filename == "slot_0001.mod" && + session->children[1].title.find("M 7") != std::string::npos && + session->children[2].suggested_filename == "slot_0003.bin" && + session->children[2].title.find("A 9") != std::string::npos && session->children[2].image_preview.available()); // sprite view + assert(session->children[2].info_preview.available()); + assert(session->children[3].image_preview.available() && + session->children[3].info_preview.available()); + auto sprite_child = dmcresource::open_session_child(session.get(), 2); assert(sprite_child && sprite_child->image_preview.available()); + assert(dmcresource::session_has_dual_preview(sprite_child.get())); + const auto* visual = dmcresource::session_active_preview(sprite_child.get()); + assert(visual == &sprite_child->image_preview); + assert(dmcresource::session_set_info_preview(sprite_child.get(), true)); + assert(dmcresource::session_info_preview_active(sprite_child.get())); + assert(dmcresource::session_active_preview(sprite_child.get()) == + &sprite_child->info_preview); + assert(dmcresource::session_set_info_preview(sprite_child.get(), false)); + assert(!dmcresource::session_info_preview_active(sprite_child.get())); + const std::vector plain = pnst({model, model}); assert(!fx::looks_like_bank(plain)); } diff --git a/app/src/test/native/png_export_session_test.cpp b/app/src/test/native/png_export_session_test.cpp index 615d6da5..d39cf9b0 100644 --- a/app/src/test/native/png_export_session_test.cpp +++ b/app/src/test/native/png_export_session_test.cpp @@ -69,9 +69,30 @@ int main() { assert(widow::has_state(gallery_state, widow::StateFlag::CanExportPng)); assert(session_child_count(&gallery) == 1U); - // The gallery itself does not keep an RGBA thumbnail resident, but the - // retained canonical DDS payload can materialize the child on demand. + // Gallery tiles now reuse the ordinary child reader when a parent did not + // keep a resident preview. Android only needs one bounded 256x256 bitmap. assert(!gallery.children[0].image_preview.available()); + const auto [thumbnail_width, thumbnail_height] = + session_child_preview_size(&gallery, 0); + assert(thumbnail_width == 256U); + assert(thumbnail_height == 256U); + + ImagePreview thumbnail; + const auto* thumbnail_view = session_child_preview(&gallery, 0, &thumbnail); + assert(thumbnail_view == &thumbnail); + assert(thumbnail.available()); + assert(thumbnail.width == 256U); + assert(thumbnail.height == 256U); + // 4x4 DXT1 source fills the square, so the centre must still be red. + const std::size_t centre = + (static_cast(128U) * thumbnail.width + 128U) * 4U; + assert(thumbnail.rgba8[centre + 0U] == 255U); + assert(thumbnail.rgba8[centre + 1U] == 0U); + assert(thumbnail.rgba8[centre + 2U] == 0U); + assert(thumbnail.rgba8[centre + 3U] == 255U); + + // Selecting the tile still opens the original full-resolution child; the + // thumbnail path does not replace or mutate the source view. auto child = open_session_child(&gallery, 0); assert(child != nullptr); assert(child->probe.format == Format::Dds); diff --git a/tools/run_phase2_exact_head.py b/tools/run_phase2_exact_head.py index b240f58a..1c026259 100644 --- a/tools/run_phase2_exact_head.py +++ b/tools/run_phase2_exact_head.py @@ -50,6 +50,7 @@ "cxx23_profile", "dds_ptx_v1", "em028_corpus_contract", + "effect_visualization", "gdata_legacy", "mod_spatial_adapter", "module_registry",