diff --git a/common/dma/dma.cpp b/common/dma/dma.cpp index a6b747ef0..3eebab72e 100644 --- a/common/dma/dma.cpp +++ b/common/dma/dma.cpp @@ -4,7 +4,7 @@ #include "fmt/core.h" -std::string DmaTag::print() { +std::string DmaTag::print() const { std::string result; const char* mode_names[8] = {"refe", "cnt", "next", "ref", "refs", "call", "ret", "end"}; result += fmt::format("TAG: 0x{:08x} {:4s} qwc 0x{:04x}", addr, mode_names[(int)kind], qwc); @@ -15,7 +15,7 @@ std::string DmaTag::print() { return result; } -std::string VifCode::print() { +std::string VifCode::print() const { std::string result; switch (kind) { diff --git a/common/dma/dma.h b/common/dma/dma.h index d5a4f53f4..a7d5ec445 100644 --- a/common/dma/dma.h +++ b/common/dma/dma.h @@ -52,7 +52,7 @@ struct DmaTag { bool operator!=(const DmaTag& other) const { return !((*this) == other); } - std::string print(); + std::string print() const; }; inline void emulate_dma(const void* source_base, void* dest_base, u32 tadr, u32 dadr) { @@ -148,7 +148,7 @@ struct VifCode { u16 num; u16 immediate; - std::string print(); + std::string print() const; }; struct VifCodeStcycl { diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index d3ffe23ed..0f79463f7 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -15147,8 +15147,8 @@ :size-assert #x4 :flag-assert #xb00000004 (:methods - (init! (_type_) int) ;; 9 - (cloth-base-method-10 (_type_ cloth-params handle) int) ;; 10 + (update! (_type_) int) ;; 9 + (setup-from-params! (_type_ cloth-params handle) int) ;; 10 ) ) @@ -33950,7 +33950,7 @@ ) (deftype particle-array (inline-array-class) - ((data verlet-particle :dynamic :inline :offset-assert 16) + ((data verlet-particle :dynamic :inline :offset-assert 16 :score 1) ) :method-count-assert 14 :size-assert #x10 @@ -34017,12 +34017,12 @@ :size-assert #x40 :flag-assert #x1000000040 (:methods - (calculate-wind! + (accumulate-external-forces! "If this cloth system has the wind flag, calculate the wind force." (_type_) none) ;; 11 - (verlet-particle-system-method-12 (_type_ float) none) ;; 12 - (verlet-particle-system-method-13 (_type_) none) ;; 13 - (verlet-particle-system-method-14 (_type_) none) ;; 14 + (compute-verlet-step (_type_ float) none) ;; 12 + (run-one-iteration "Run one iteration of the system." (_type_) none) ;; 13 + (reset! "Reset to stationary/default state." (_type_) none) ;; 14 (debug-draw (_type_) none) ;; 15 ) ) @@ -34082,9 +34082,9 @@ "Set up this cloth system with the given [[cloth-params]]." (_type_ cloth-params) none) ;; 16 (debug-draw-spheres (_type_) none) ;; 17 - (cloth-system-method-18 (_type_) int) ;; 18 - (cloth-system-method-19 (_type_) none) ;; 19 - (cloth-system-method-20 (_type_) none) ;; 20 + (post-physics-update (_type_) int) ;; 18 + (enforce-constraints-1 (_type_) none) ;; 19 + (enforce-constraints-2 (_type_) none) ;; 20 (cloth-system-method-21 (_type_) none) ;; 21 (cloth-system-method-22 (_type_) none) ;; 22 (cloth-system-method-23 (_type_) none) ;; 23 @@ -34098,9 +34098,9 @@ (cloth-system-method-31 (_type_ current-position-info) none) ;; 31 (cloth-system-method-32 (_type_ vector int int current-position-info) none) ;; 32 (cloth-system-method-33 (_type_ vu-lights) none) ;; 33 - (cloth-system-method-34 (_type_) none) ;; 34 - (cloth-system-method-35 (_type_) none) ;; 35 - (cloth-system-method-36 (_type_) none) ;; 36 + (hide! (_type_) none) ;; 34 + (reset-locations (_type_) none) ;; 35 + (pre-physics-update "Callback to update prior to running verlet integration. Can handle movement of the entire system in the world, for example" (_type_) none) ;; 36 (cloth-system-cmd-handler (_type_ pair) none) ;; 37 ) ) @@ -34122,8 +34122,8 @@ ;; cloth ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-extern get-neighboring-faces (function vector int int int int int)) -(define-extern *normal-array* (pointer vector)) +(define-extern get-neighboring-faces (function vector4w int int int int int)) +(define-extern *normal-array* (inline-array vector)) (define-extern light-vertex (function current-position-info vector rgba)) (define-extern *once* symbol) (define-extern *cloth-fade-alpha* gs-alpha) diff --git a/decompiler/types2/ForwardProp.cpp b/decompiler/types2/ForwardProp.cpp index 4fddcfde4..f2c324eb3 100644 --- a/decompiler/types2/ForwardProp.cpp +++ b/decompiler/types2/ForwardProp.cpp @@ -2576,7 +2576,6 @@ void CallOp::propagate_types2(types2::Instruction& instr, if (can_use_call_parent) { out_types[Register(Reg::GPR, Reg::V0)]->type = TP_Type::make_from_ts(call_parent_result_type); - lg::print("used special {}\n", call_parent_result_type.print()); use_normal_last_arg = false; } } diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 74434b1b7..74e07e4c1 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -201,6 +201,7 @@ set(RUNTIME_SOURCE mips2c/jak3_functions/sky.cpp mips2c/jak3_functions/texture.cpp mips2c/jak3_functions/particle_curves.cpp + mips2c/jak3_functions/cloth.cpp mips2c/jak3_functions/collide_cache.cpp mips2c/jak3_functions/collide_hash.cpp mips2c/jak3_functions/collide_edge_grab.cpp diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index e8e4ae290..d92e5a81a 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -579,6 +579,7 @@ u32 get_direct_qwc_or_nop(const VifCode& code) { return code.immediate; } default: + printf("expected direct, got %s\n", code.print().c_str()); ASSERT(false); } } diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 51b477b71..0811bb06e 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -267,6 +267,11 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { GET_BUCKET_ID_FOR_LIST(BucketId::GMERC_L0_PRIS, BucketId::GMERC_L1_PRIS, i), m_generic2, Generic2::Mode::NORMAL); + init_bucket_renderer( + fmt::format("gmerc2-l{}-pris", i), BucketCategory::GENERIC, + GET_BUCKET_ID_FOR_LIST(BucketId::GMERC2_L0_PRIS, BucketId::GMERC2_L1_PRIS, i), m_generic2, + Generic2::Mode::PRIM); + init_bucket_renderer( fmt::format("merc-l{}-pris2", i), BucketCategory::MERC, GET_BUCKET_ID_FOR_LIST(BucketId::MERC_L0_PRIS2, BucketId::MERC_L1_PRIS2, i), m_merc2); @@ -274,6 +279,10 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { fmt::format("gmerc-l{}-pris2", i), BucketCategory::GENERIC, GET_BUCKET_ID_FOR_LIST(BucketId::GMERC_L0_PRIS2, BucketId::GMERC_L1_PRIS2, i), m_generic2, Generic2::Mode::NORMAL); + init_bucket_renderer( + fmt::format("gmerc2-l{}-pris2", i), BucketCategory::GENERIC, + GET_BUCKET_ID_FOR_LIST(BucketId::GMERC2_L0_PRIS2, BucketId::GMERC2_L1_PRIS2, i), + m_generic2, Generic2::Mode::PRIM); } // 401 @@ -285,6 +294,10 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { BucketId::GMERC_LCOM_PRIS, m_generic2, Generic2::Mode::NORMAL); + init_bucket_renderer("gmerc2-lcom-pris", BucketCategory::GENERIC, + BucketId::GMERC2_LCOM_PRIS, m_generic2, + Generic2::Mode::PRIM); + // 461 init_bucket_renderer("tex-lcom-sky-post", BucketCategory::TEX, BucketId::TEX_LCOM_SKY_POST, m_texture_animator); @@ -317,11 +330,20 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { BucketId::TEX_LCOM_WATER, m_texture_animator); init_bucket_renderer("merc-lcom-water", BucketCategory::MERC, BucketId::MERC_LCOM_WATER, m_merc2); + init_bucket_renderer("generic2-lcom-water", BucketCategory::GENERIC, + BucketId::GMERC2_LCOM_WATER, m_generic2, + Generic2::Mode::PRIM); // 568 init_bucket_renderer("tex-sprite", BucketCategory::TEX, BucketId::TEX_SPRITE, m_texture_animator); + init_bucket_renderer("generic-sprite-1", BucketCategory::GENERIC, + BucketId::GENERIC_SPRITE_1, m_generic2, + Generic2::Mode::PRIM); init_bucket_renderer("particles", BucketCategory::SPRITE, BucketId::PARTICLES); + init_bucket_renderer("generic-sprite-2", BucketCategory::GENERIC, + BucketId::GENERIC_SPRITE_2, m_generic2, + Generic2::Mode::PRIM); init_bucket_renderer("generic-sprite-3", BucketCategory::OTHER, BucketId::GENERIC_SPRITE_3, m_generic2, Generic2::Mode::LIGHTNING); diff --git a/game/graphics/opengl_renderer/foreground/Generic2.cpp b/game/graphics/opengl_renderer/foreground/Generic2.cpp index 7c711218e..3301d77ba 100644 --- a/game/graphics/opengl_renderer/foreground/Generic2.cpp +++ b/game/graphics/opengl_renderer/foreground/Generic2.cpp @@ -70,6 +70,9 @@ void Generic2::render_in_mode(DmaFollower& dma, case Mode::LIGHTNING: process_dma_lightning(dma, render_state->next_bucket); break; + case Mode::PRIM: + process_dma_prim(dma, render_state->next_bucket); + break; default: ASSERT_NOT_REACHED(); } @@ -83,6 +86,7 @@ void Generic2::render_in_mode(DmaFollower& dma, auto p = prof.make_scoped_child("setup"); switch (mode) { case Mode::NORMAL: + case Mode::PRIM: setup_draws(true, true); break; case Mode::LIGHTNING: diff --git a/game/graphics/opengl_renderer/foreground/Generic2.h b/game/graphics/opengl_renderer/foreground/Generic2.h index 63869c3fa..510abb0ed 100644 --- a/game/graphics/opengl_renderer/foreground/Generic2.h +++ b/game/graphics/opengl_renderer/foreground/Generic2.h @@ -11,7 +11,7 @@ class Generic2 { u32 num_buckets = 800); ~Generic2(); - enum class Mode { NORMAL, LIGHTNING, WARP }; + enum class Mode { NORMAL, LIGHTNING, WARP, PRIM }; void render_in_mode(DmaFollower& dma, SharedRenderState* render_state, @@ -43,6 +43,7 @@ class Generic2 { void process_dma_jak1(DmaFollower& dma, u32 next_bucket); void process_dma_lightning(DmaFollower& dma, u32 next_bucket); void process_dma_jak2(DmaFollower& dma, u32 next_bucket); + void process_dma_prim(DmaFollower& dma, u32 next_bucket); void setup_draws(bool enable_at, bool default_fog); void do_draws(SharedRenderState* render_state, ScopedProfilerNode& prof); void do_draws_for_alpha(SharedRenderState* render_state, @@ -85,6 +86,8 @@ class Generic2 { float hud_mat_23, hud_mat_32, hud_mat_33; bool uses_hud = false; + bool uses_full_matrix = false; + math::Vector4f full_matrix[4]; } m_drawing_config; struct GsState { @@ -199,7 +202,7 @@ class Generic2 { GLuint vertex_buffer; GLuint index_buffer; GLuint alpha_reject, color_mult, fog_color, scale, mat_23, mat_32, mat_33, fog_consts, - hvdf_offset; + hvdf_offset, use_full_matrix, full_matrix; GLuint gfx_hack_no_tex; GLuint warp_sample_mode; } m_ogl; diff --git a/game/graphics/opengl_renderer/foreground/Generic2_Build.cpp b/game/graphics/opengl_renderer/foreground/Generic2_Build.cpp index d4f52eed5..25b2963fd 100644 --- a/game/graphics/opengl_renderer/foreground/Generic2_Build.cpp +++ b/game/graphics/opengl_renderer/foreground/Generic2_Build.cpp @@ -271,6 +271,10 @@ void Generic2::process_matrices() { bool found_proj_matrix = false; std::array projection_matrix, hud_matrix; for (u32 i = 0; i < m_next_free_frag; i++) { + if (m_drawing_config.uses_full_matrix) { + memcpy(&m_drawing_config.full_matrix, m_fragments[i].header, 64); + break; + } float mat_33; memcpy(&mat_33, m_fragments[i].header + 15 * sizeof(float), sizeof(float)); if (mat_33 == 0) { diff --git a/game/graphics/opengl_renderer/foreground/Generic2_DMA.cpp b/game/graphics/opengl_renderer/foreground/Generic2_DMA.cpp index 02d7d5927..45f8b662e 100644 --- a/game/graphics/opengl_renderer/foreground/Generic2_DMA.cpp +++ b/game/graphics/opengl_renderer/foreground/Generic2_DMA.cpp @@ -550,6 +550,83 @@ void unpack_vertex(Generic2::Vertex* out, const u8* in, int count) { } } +void Generic2::process_dma_prim(DmaFollower& dma, u32 next_bucket) { + reset_buffers(); + auto first_data = dma.read_and_advance(); + + // handle the stuff at the beginning. + // if the engine didn't run the generic renderer setup function, this bucket will end here. + if (is_nop_zero(first_data) && next_bucket == dma.current_tag_offset()) { + return; + } + + // MARK NOP (for profiling) + auto v0k = first_data.vifcode0().kind; + ASSERT((v0k == VifCode::Kind::MARK || v0k == VifCode::Kind::NOP) && + first_data.vifcode1().kind == VifCode::Kind::NOP); + + // NOP DIRECT (set up GS, from generic setup) + auto direct_setup = dma.read_and_advance(); + ASSERT(direct_setup.size_bytes == 32 && direct_setup.vifcode0().kind == VifCode::Kind::NOP && + direct_setup.vifcode1().kind == VifCode::Kind::DIRECT); + m_drawing_config.zmsk = false; + m_drawing_config.uses_full_matrix = true; + + // STYCYCL to set up generic VU1 constants + auto constants = dma.read_and_advance(); + ASSERT(constants.size_bytes == 128); + ASSERT(constants.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(constants.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + memcpy(&m_drawing_config.pfog0, constants.data + 0, 4); + memcpy(&m_drawing_config.fog_min, constants.data + 4, 4); + memcpy(&m_drawing_config.fog_max, constants.data + 8, 4); + memcpy(m_drawing_config.hvdf_offset.data(), constants.data + 32, 16); + + // 32: MSCALF 0x0 STMOD 0b0 init generic VU1 + auto mscalf = dma.read_and_advance(); + ASSERT(mscalf.vifcode0().kind == VifCode::Kind::MSCALF && + mscalf.vifcode1().kind == VifCode::Kind::STMOD); + + // 0: NOP NOP + // auto another_nop = dma.read_and_advance(); + // ASSERT(is_nop_zero(another_nop)); + + while (dma.current_tag_offset() != next_bucket) { + auto up1 = dma.read_and_advance(); + while (up1.vifcode0().kind == VifCode::Kind::NOP && up1.vifcode1().kind == VifCode::Kind::NOP) { + up1 = dma.read_and_advance(); + } + if (up1.vifcode0().kind == VifCode::Kind::FLUSHA) { + while (dma.current_tag_offset() != next_bucket) { + auto it = dma.read_and_advance(); + } + break; + } + auto up2 = dma.read_and_advance(); + auto call = dma.read_and_advance(); + + // up1 is a 12 qw upload for control: + // up2 is vertex upload. + + auto* frag = &next_frag(); + ASSERT(up1.size_bytes == Generic2::FRAG_HEADER_SIZE + 5 * 16); // header + adgif + memcpy(frag->header, up1.data, Generic2::FRAG_HEADER_SIZE); + frag->adgif_idx = m_next_free_adgif; + frag->adgif_count = 1; + frag->mscal_addr = 6; + frag->uses_hud = false; + auto* adgif = &next_adgif(); + memcpy(&adgif->data, up1.data + Generic2::FRAG_HEADER_SIZE, sizeof(AdGifData)); + // (new 'static 'gif-tag-regs-32 :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 + // (gif-reg-id xyzf2)) + int num_vtx = up2.size_bytes / (16 * 3); + frag->vtx_count = num_vtx; + frag->vtx_idx = m_next_free_vert; + alloc_vtx(num_vtx); + unpack_vertex(&m_verts[frag->vtx_idx], up2.data, num_vtx); + } +} + void Generic2::process_dma_lightning(DmaFollower& dma, u32 next_bucket) { reset_buffers(); auto first_data = dma.read_and_advance(); diff --git a/game/graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp b/game/graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp index c90f0dd3c..434ee92f5 100644 --- a/game/graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp +++ b/game/graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp @@ -74,6 +74,8 @@ void Generic2::opengl_setup(ShaderLibrary& shaders) { m_ogl.hvdf_offset = glGetUniformLocation(id, "hvdf_offset"); m_ogl.gfx_hack_no_tex = glGetUniformLocation(id, "gfx_hack_no_tex"); m_ogl.warp_sample_mode = glGetUniformLocation(id, "warp_sample_mode"); + m_ogl.use_full_matrix = glGetUniformLocation(id, "use_full_matrix"); + m_ogl.full_matrix = glGetUniformLocation(id, "full_matrix"); } void Generic2::opengl_cleanup() { @@ -307,6 +309,12 @@ void Generic2::do_draws(SharedRenderState* render_state, ScopedProfilerNode& pro glPrimitiveRestartIndex(UINT32_MAX); opengl_bind_and_setup_proj(render_state); + if (m_drawing_config.uses_full_matrix) { + glUniform1i(m_ogl.use_full_matrix, 1); + glUniformMatrix4fv(m_ogl.full_matrix, 1, GL_FALSE, m_drawing_config.full_matrix[0].data()); + } else { + glUniform1i(m_ogl.use_full_matrix, 0); + } constexpr DrawMode::AlphaBlend alpha_order[ALPHA_MODE_COUNT] = { DrawMode::AlphaBlend::SRC_0_FIX_DST, DrawMode::AlphaBlend::SRC_SRC_SRC_SRC, DrawMode::AlphaBlend::SRC_DST_SRC_DST, DrawMode::AlphaBlend::SRC_0_SRC_DST, diff --git a/game/graphics/opengl_renderer/foreground/Merc2.cpp b/game/graphics/opengl_renderer/foreground/Merc2.cpp index 3b86072c3..dd8bee66e 100644 --- a/game/graphics/opengl_renderer/foreground/Merc2.cpp +++ b/game/graphics/opengl_renderer/foreground/Merc2.cpp @@ -768,9 +768,7 @@ void Merc2::switch_to_emerc(SharedRenderState* render_state) { void Merc2::render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof, - MercDebugStats* stats, - bool debug) { - m_debug = true; + MercDebugStats* stats) { bool hack = stats->collect_debug_model_list; *stats = {}; stats->collect_debug_model_list = hack; diff --git a/game/graphics/opengl_renderer/foreground/Merc2.h b/game/graphics/opengl_renderer/foreground/Merc2.h index 3f3001897..9705907b6 100644 --- a/game/graphics/opengl_renderer/foreground/Merc2.h +++ b/game/graphics/opengl_renderer/foreground/Merc2.h @@ -46,8 +46,7 @@ class Merc2 { void render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof, - MercDebugStats* stats, - bool debug); + MercDebugStats* stats); static constexpr int kMaxBlerc = 40; private: @@ -139,7 +138,6 @@ class Merc2 { }; Uniforms m_merc_uniforms, m_emerc_uniforms; - bool m_debug = false; void init_shader_common(Shader& shader, Uniforms* uniforms, bool include_lights); void handle_setup_dma(DmaFollower& dma, SharedRenderState* render_state); diff --git a/game/graphics/opengl_renderer/foreground/Merc2BucketRenderer.cpp b/game/graphics/opengl_renderer/foreground/Merc2BucketRenderer.cpp index 23afb2680..58157a99b 100644 --- a/game/graphics/opengl_renderer/foreground/Merc2BucketRenderer.cpp +++ b/game/graphics/opengl_renderer/foreground/Merc2BucketRenderer.cpp @@ -16,7 +16,7 @@ void Merc2BucketRenderer::render(DmaFollower& dma, return; } - m_renderer->render(dma, render_state, prof, &m_debug_stats, m_my_id == 362); + m_renderer->render(dma, render_state, prof, &m_debug_stats); m_empty = m_debug_stats.num_predicted_draws == 0; } diff --git a/game/graphics/opengl_renderer/shaders/generic.vert b/game/graphics/opengl_renderer/shaders/generic.vert index fa465f954..e2e1905e4 100644 --- a/game/graphics/opengl_renderer/shaders/generic.vert +++ b/game/graphics/opengl_renderer/shaders/generic.vert @@ -10,6 +10,8 @@ uniform vec3 fog_constants; uniform vec4 scale; uniform float mat_23; uniform float mat_33; +uniform bool use_full_matrix; +uniform mat4 full_matrix; uniform vec4 hvdf_offset; uniform uint warp_sample_mode; @@ -38,11 +40,17 @@ void main() { // maddax.xyzw ACC, vf08, vf16 matrix multiply X // vu.acc.madda(Mask::xyzw, gen.mat0, gen.vtx_load0.x()); - transformed.xyz = position_in * scale.xyz; - transformed.z += mat_32; - transformed.w = mat_23 * position_in.z + mat_33; - - transformed *= -1; // todo? + if (use_full_matrix) { + transformed = -full_matrix[3]; + transformed -= full_matrix[0] * position_in.x ; + transformed -= full_matrix[1] * position_in.y; + transformed -= full_matrix[2] * position_in.z ; + } else { + transformed.xyz = position_in * scale.xyz; + transformed.z += mat_32; + transformed.w = mat_23 * position_in.z + mat_33; + transformed *= -1; + } // div Q, vf01.x, vf12.w perspective divide diff --git a/game/mips2c/jak3_functions/cloth.cpp b/game/mips2c/jak3_functions/cloth.cpp new file mode 100644 index 000000000..b9a33cb3a --- /dev/null +++ b/game/mips2c/jak3_functions/cloth.cpp @@ -0,0 +1,220 @@ +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace method_21_cloth_system { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -80); // daddiu sp, sp, -80 + c->daddiu(a3, sp, 16); // daddiu a3, sp, 16 + c->daddiu(t0, sp, 32); // daddiu t0, sp, 32 + c->lwu(v1, 68, a0); // lwu v1, 68(a0) + c->lw(v1, 0, v1); // lw v1, 0(v1) + c->lw(a1, 96, a0); // lw a1, 96(a0) + c->daddiu(a1, a1, -1); // daddiu a1, a1, -1 + c->lw(a2, 100, a0); // lw a2, 100(a0) + c->daddiu(a2, a2, -1); // daddiu a2, a2, -1 + c->addiu(t1, r0, 0); // addiu t1, r0, 0 + c->addiu(t1, r0, 0); // addiu t1, r0, 0 + c->mov64(t1, a3); // or t1, a3, r0 + c->lui(t2, 16000); // lui t2, 16000 + c->mtc1(f0, t2); // mtc1 f0, t2 + c->swc1(f0, 0, t1); // swc1 f0, 0(t1) + c->lui(t2, 16000); // lui t2, 16000 + c->mtc1(f0, t2); // mtc1 f0, t2 + c->swc1(f0, 4, t1); // swc1 f0, 4(t1) + c->lui(t2, 16000); // lui t2, 16000 + c->mtc1(f0, t2); // mtc1 f0, t2 + c->swc1(f0, 8, t1); // swc1 f0, 8(t1) + c->lui(t2, 16000); // lui t2, 16000 + c->mtc1(f0, t2); // mtc1 f0, t2 + c->swc1(f0, 12, t1); // swc1 f0, 12(t1) + c->mov64(t1, t0); // or t1, t0, r0 + c->mtc1(f0, r0); // mtc1 f0, r0 + c->swc1(f0, 0, t1); // swc1 f0, 0(t1) + c->mtc1(f0, r0); // mtc1 f0, r0 + c->swc1(f0, 4, t1); // swc1 f0, 4(t1) + c->mtc1(f0, r0); // mtc1 f0, r0 + c->swc1(f0, 8, t1); // swc1 f0, 8(t1) + c->lwc1(f0, 144, a0); // lwc1 f0, 144(a0) + c->swc1(f0, 12, t1); // swc1 f0, 12(t1) + c->vmax_bc(DEST::xyzw, BC::w, vf1, vf0, vf0); // vmaxw.xyzw vf1, vf0, vf0 + c->lqc2(vf10, 0, a3); // lqc2 vf10, 0(a3) + c->lqc2(vf15, 0, t0); // lqc2 vf15, 0(t0) + c->sd(r0, 48, sp); // sd r0, 48(sp) + c->addiu(a3, r0, 0); // addiu a3, r0, 0 + //beq r0, r0, L187 // beq r0, r0, L187 + // nop // sll r0, r0, 0 + goto block_10; // branch always + + +block_1: + c->addiu(t0, r0, 0); // addiu t0, r0, 0 + //beq r0, r0, L186 // beq r0, r0, L186 + // nop // sll r0, r0, 0 + goto block_8; // branch always + + +block_2: + c->addiu(t1, r0, 48); // addiu t1, r0, 48 + c->ld(t2, 48, sp); // ld t2, 48(sp) + c->mult3(t1, t1, t2); // mult3 t1, t1, t2 + c->daddiu(t1, t1, 12); // daddiu t1, t1, 12 + c->lwu(t2, 0, a0); // lwu t2, 0(a0) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->sw(t1, 56, sp); // sw t1, 56(sp) + c->addiu(t1, r0, 48); // addiu t1, r0, 48 + c->ld(t2, 48, sp); // ld t2, 48(sp) + c->daddiu(t2, t2, 1); // daddiu t2, t2, 1 + c->mult3(t1, t1, t2); // mult3 t1, t1, t2 + c->daddiu(t1, t1, 12); // daddiu t1, t1, 12 + c->lwu(t2, 0, a0); // lwu t2, 0(a0) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->sw(t1, 60, sp); // sw t1, 60(sp) + c->addiu(t1, r0, 48); // addiu t1, r0, 48 + c->ld(t2, 48, sp); // ld t2, 48(sp) + c->lw(t3, 96, a0); // lw t3, 96(a0) + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->mult3(t1, t1, t2); // mult3 t1, t1, t2 + c->daddiu(t1, t1, 12); // daddiu t1, t1, 12 + c->lwu(t2, 0, a0); // lwu t2, 0(a0) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->sw(t1, 64, sp); // sw t1, 64(sp) + c->addiu(t1, r0, 48); // addiu t1, r0, 48 + c->lw(t2, 96, a0); // lw t2, 96(a0) + c->daddiu(t2, t2, 1); // daddiu t2, t2, 1 + c->ld(t3, 48, sp); // ld t3, 48(sp) + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->mult3(t1, t1, t2); // mult3 t1, t1, t2 + c->daddiu(t1, t1, 12); // daddiu t1, t1, 12 + c->lwu(t2, 0, a0); // lwu t2, 0(a0) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->sw(t1, 68, sp); // sw t1, 68(sp) + c->lwu(t1, 56, sp); // lwu t1, 56(sp) + c->lqc2(vf2, 0, t1); // lqc2 vf2, 0(t1) + c->lwu(t1, 68, sp); // lwu t1, 68(sp) + c->lqc2(vf5, 0, t1); // lqc2 vf5, 0(t1) + c->lwu(t1, 60, sp); // lwu t1, 60(sp) + c->lqc2(vf3, 0, t1); // lqc2 vf3, 0(t1) + c->lwu(t1, 64, sp); // lwu t1, 64(sp) + c->lqc2(vf4, 0, t1); // lqc2 vf4, 0(t1) + c->lwu(t1, 56, sp); // lwu t1, 56(sp) + c->lqc2(vf20, 32, t1); // lqc2 vf20, 32(t1) + c->lwu(t1, 68, sp); // lwu t1, 68(sp) + c->lqc2(vf23, 32, t1); // lqc2 vf23, 32(t1) + c->lwu(t1, 60, sp); // lwu t1, 60(sp) + c->lqc2(vf21, 32, t1); // lqc2 vf21, 32(t1) + c->lwu(t1, 64, sp); // lwu t1, 64(sp) + c->lqc2(vf22, 32, t1); // lqc2 vf22, 32(t1) + c->vmula_bc(DEST::xyzw, BC::x, vf2, vf20); // vmulax.xyzw acc, vf2, vf20 + c->vmadda_bc(DEST::xyzw, BC::x, vf3, vf21); // vmaddax.xyzw acc, vf3, vf21 + c->vmadda_bc(DEST::xyzw, BC::x, vf5, vf23); // vmaddax.xyzw acc, vf5, vf23 + c->vmadd_bc(DEST::xyzw, BC::x, vf8, vf4, vf22); // vmaddx.xyzw vf8, vf4, vf22 + c->vmul_bc(DEST::xyzw, BC::x, vf8, vf8, vf10); // vmulx.xyzw vf8, vf8, vf10 + c->lwu(t1, 68, a0); // lwu t1, 68(a0) + c->daddiu(t1, t1, 12); // daddiu t1, t1, 12 + c->addiu(t2, r0, 0); // addiu t2, r0, 0 + //beq r0, r0, L185 // beq r0, r0, L185 + // nop // sll r0, r0, 0 + goto block_6; // branch always + + +block_3: + c->lqc2(vf11, 0, t1); // lqc2 vf11, 0(t1) + c->vsub(DEST::xyzw, vf13, vf8, vf11); // vsub.xyzw vf13, vf8, vf11 + c->vmul(DEST::xyzw, vf9, vf13, vf13); // vmul.xyzw vf9, vf13, vf13 + c->vmula_bc(DEST::xyzw, BC::x, vf1, vf9); // vmulax.xyzw acc, vf1, vf9 + c->vmadda_bc(DEST::xyzw, BC::y, vf1, vf9); // vmadday.xyzw acc, vf1, vf9 + c->vmadd_bc(DEST::xyzw, BC::z, vf14, vf1, vf9); // vmaddz.xyzw vf14, vf1, vf9 + c->vadd_bc(DEST::w, BC::w, vf11, vf11, vf15); // vaddw.w vf11, vf11, vf15 + c->vmul(DEST::xyzw, vf12, vf11, vf11); // vmul.xyzw vf12, vf11, vf11 + c->vsub_bc(DEST::xyzw, BC::w, vf9, vf14, vf12); // vsubw.xyzw vf9, vf14, vf12 + c->mov128_gpr_vf(t3, vf9); // qmfc2.i t3, vf9 + bc = ((s64)c->sgpr64(t3)) >= 0; // bgez t3, L184 + // nop // sll r0, r0, 0 + if (bc) {goto block_5;} // branch non-likely + + c->vrsqrt(vf11, BC::w, vf14, BC::x); // vrsqrt Q, vf11.w, vf14.x + c->vmax_bc(DEST::xyz, BC::x, vf20, vf0, vf20); // vmaxx.xyz vf20, vf0, vf20 + c->vmax_bc(DEST::xyz, BC::x, vf21, vf0, vf21); // vmaxx.xyz vf21, vf0, vf21 + c->vmax_bc(DEST::xyz, BC::x, vf22, vf0, vf22); // vmaxx.xyz vf22, vf0, vf22 + c->vmax_bc(DEST::xyz, BC::x, vf23, vf0, vf23); // vmaxx.xyz vf23, vf0, vf23 + c->vwaitq(); // vwaitq + // Unknown instr: vmulaq.xyzw acc, vf13, Q + c->vmula_q(DEST::xyzw, vf13); + c->vmsuba(DEST::xyzw, vf1, vf13); // vmsuba.xyzw acc, vf1, vf13 + c->vmadd(DEST::xyzw, vf2, vf1, vf2); // vmadd.xyzw vf2, vf1, vf2 + c->vmadd(DEST::xyzw, vf3, vf1, vf3); // vmadd.xyzw vf3, vf1, vf3 + c->vmadd(DEST::xyzw, vf5, vf1, vf5); // vmadd.xyzw vf5, vf1, vf5 + c->vmadd(DEST::xyzw, vf4, vf1, vf4); // vmadd.xyzw vf4, vf1, vf4 + c->vmadd(DEST::xyzw, vf8, vf1, vf8); // vmadd.xyzw vf8, vf1, vf8 + +block_5: + c->daddiu(t1, t1, 16); // daddiu t1, t1, 16 + c->daddiu(t2, t2, 1); // daddiu t2, t2, 1 + +block_6: + c->slt(t3, t2, v1); // slt t3, t2, v1 + bc = c->sgpr64(t3) != 0; // bne t3, r0, L183 + // nop // sll r0, r0, 0 + if (bc) {goto block_3;} // branch non-likely + + c->mov64(t1, s7); // or t1, s7, r0 + c->mov64(t1, s7); // or t1, s7, r0 + c->lwu(t1, 56, sp); // lwu t1, 56(sp) + c->sqc2(vf2, 0, t1); // sqc2 vf2, 0(t1) + c->lwu(t1, 68, sp); // lwu t1, 68(sp) + c->sqc2(vf5, 0, t1); // sqc2 vf5, 0(t1) + c->lwu(t1, 60, sp); // lwu t1, 60(sp) + c->sqc2(vf3, 0, t1); // sqc2 vf3, 0(t1) + c->lwu(t1, 64, sp); // lwu t1, 64(sp) + c->sqc2(vf4, 0, t1); // sqc2 vf4, 0(t1) + c->mov128_gpr_vf(t1, vf4); // qmfc2.i t1, vf4 + c->ld(t1, 48, sp); // ld t1, 48(sp) + c->daddiu(t1, t1, 1); // daddiu t1, t1, 1 + c->sd(t1, 48, sp); // sd t1, 48(sp) + c->daddiu(t0, t0, 1); // daddiu t0, t0, 1 + +block_8: + c->slt(t1, t0, a1); // slt t1, t0, a1 + bc = c->sgpr64(t1) != 0; // bne t1, r0, L182 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(t0, s7); // or t0, s7, r0 + c->mov64(t0, s7); // or t0, s7, r0 + c->ld(t0, 48, sp); // ld t0, 48(sp) + c->daddiu(t0, t0, 1); // daddiu t0, t0, 1 + c->sd(t0, 48, sp); // sd t0, 48(sp) + c->daddiu(a3, a3, 1); // daddiu a3, a3, 1 + +block_10: + c->slt(t0, a3, a2); // slt t0, a3, a2 + bc = c->sgpr64(t0) != 0; // bne t0, r0, L181 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + c->mov64(v0, s7); // or v0, s7, r0 + //jr ra // jr ra + c->daddiu(sp, sp, 80); // daddiu sp, sp, 80 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("(method 21 cloth-system)", execute, 256); +} + +} // namespace method_21_cloth_system +} // namespace Mips2C + diff --git a/game/mips2c/mips2c_private.h b/game/mips2c/mips2c_private.h index 4c9f1e647..552d85a5a 100644 --- a/game/mips2c/mips2c_private.h +++ b/game/mips2c/mips2c_private.h @@ -905,6 +905,16 @@ struct ExecutionContext { } } + void vmula_q(DEST mask, int src0) { + auto s0 = vf_src(src0); + + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + acc.f[i] = s0.f[i] * Q; + } + } + } + void vadda_bc(DEST mask, BC bc, int src0, int src1) { auto s0 = vf_src(src0); auto s1 = vf_src(src1); diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 74c461c71..8865ef75e 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -393,6 +393,7 @@ namespace shadow_add_double_edges { extern void link(); } namespace shadow_add_single_tris { extern void link(); } namespace shadow_add_double_tris { extern void link(); } namespace shadow_execute { extern void link(); } +namespace method_21_cloth_system { extern void link(); } } // clang-format on @@ -654,7 +655,8 @@ PerGameVersion>> gMips2C jak3::shadow_find_single_edges::link, jak3::shadow_find_double_edges::link, jak3::shadow_add_verts::link, jak3::shadow_add_facing_single_tris::link, jak3::shadow_add_single_edges::link, jak3::shadow_add_double_edges::link, - jak3::shadow_add_single_tris::link, jak3::shadow_add_double_tris::link}}}}; + jak3::shadow_add_single_tris::link, jak3::shadow_add_double_tris::link}}, + {"cloth", {jak3::method_21_cloth_system::link}}}}; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { const auto& it = m_executes.insert({name, {exec, Ptr()}}); diff --git a/goal_src/jak3/engine/common-obs/cloth-art-h.gc b/goal_src/jak3/engine/common-obs/cloth-art-h.gc index c7a25ab30..0527fa11e 100644 --- a/goal_src/jak3/engine/common-obs/cloth-art-h.gc +++ b/goal_src/jak3/engine/common-obs/cloth-art-h.gc @@ -146,7 +146,7 @@ (deftype cloth-base (basic) () (:methods - (init! (_type_) int) - (cloth-base-method-10 (_type_ cloth-params handle) int) + (update! (_type_) int) + (setup-from-params! (_type_ cloth-params handle) int) ) ) diff --git a/goal_src/jak3/engine/draw/drawable-h.gc b/goal_src/jak3/engine/draw/drawable-h.gc index b8ebc2c28..1be8e51c4 100644 --- a/goal_src/jak3/engine/draw/drawable-h.gc +++ b/goal_src/jak3/engine/draw/drawable-h.gc @@ -6,11 +6,13 @@ ;; dgos: GAME (declare-type region-prim-list structure) +(declare-type draw-control structure) (define-extern sphere-cull "Is this sphere visible? Uses cached camera matrix registers, so use with care." (function vector symbol)) (define-extern sphere-in-view-frustum? (function sphere symbol)) (define-extern line-in-view-frustum? (function vector vector symbol)) (define-extern vis-cull (function int symbol)) +(define-extern calc-vu1-lights (function vu-lights draw-control symbol none)) ;; DECOMP BEGINS diff --git a/goal_src/jak3/engine/draw/drawable.gc b/goal_src/jak3/engine/draw/drawable.gc index 7b1246986..1e74c07dd 100644 --- a/goal_src/jak3/engine/draw/drawable.gc +++ b/goal_src/jak3/engine/draw/drawable.gc @@ -1458,7 +1458,7 @@ (shadow-execute-all gp-0) ) (lightning-draw-all) - ;(prim-engine-execute) + (prim-engine-execute) (none) ) diff --git a/goal_src/jak3/engine/physics/cloth-h.gc b/goal_src/jak3/engine/physics/cloth-h.gc index 7666da53c..17177e783 100644 --- a/goal_src/jak3/engine/physics/cloth-h.gc +++ b/goal_src/jak3/engine/physics/cloth-h.gc @@ -117,10 +117,10 @@ (momentum vector :inline) ) (:methods - (calculate-wind! (_type_) none) - (verlet-particle-system-method-12 (_type_ float) none) - (verlet-particle-system-method-13 (_type_) none) - (verlet-particle-system-method-14 (_type_) none) + (accumulate-external-forces! (_type_) none) + (compute-verlet-step (_type_ float) none) + (run-one-iteration (_type_) none) + (reset! (_type_) none) (debug-draw (_type_) none) ) ) @@ -173,9 +173,9 @@ (:methods (initialize-cloth-system! (_type_ cloth-params) none) (debug-draw-spheres (_type_) none) - (cloth-system-method-18 (_type_) int) - (cloth-system-method-19 (_type_) none) - (cloth-system-method-20 (_type_) none) + (post-physics-update (_type_) int) + (enforce-constraints-1 (_type_) none) + (enforce-constraints-2 (_type_) none) (cloth-system-method-21 (_type_) none) (cloth-system-method-22 (_type_) none) (cloth-system-method-23 (_type_) none) @@ -189,9 +189,9 @@ (cloth-system-method-31 (_type_ current-position-info) none) (cloth-system-method-32 (_type_ vector int int current-position-info) none) (cloth-system-method-33 (_type_ vu-lights) none) - (cloth-system-method-34 (_type_) none) - (cloth-system-method-35 (_type_) none) - (cloth-system-method-36 (_type_) none) + (hide! (_type_) none) + (reset-locations (_type_) none) + (pre-physics-update (_type_) none) (cloth-system-cmd-handler (_type_ pair) none) ) ) diff --git a/goal_src/jak3/engine/physics/cloth.gc b/goal_src/jak3/engine/physics/cloth.gc index 634672478..c969a7e4a 100644 --- a/goal_src/jak3/engine/physics/cloth.gc +++ b/goal_src/jak3/engine/physics/cloth.gc @@ -7,20 +7,2130 @@ ;; DECOMP BEGINS -(defmethod cloth-base-method-10 ((this cloth-base) (a cloth-params) (b handle)) - (format 0 "unimplemented cloth-base-method-10~%") - 0) +(defmethod relocate ((this verlet-particle-system) (offset int)) + (if (nonzero? (-> this particles)) + (&+! (-> this particles) offset) + ) + (call-parent-method this offset) + ) -(defmethod cloth-system-method-34 ((this cloth-system)) - (format 0 "unimplemented cloth-system-method-34~%") +(defmethod mem-usage ((this art-cloth-geo) (usage memory-usage-block) (flags int)) + (set! (-> usage length) (max 77 (-> usage length))) + (set! (-> usage data 76 name) "art-cloth-geo") + (+! (-> usage data 76 count) 1) + (let ((v1-6 (asize-of this))) + (+! (-> usage data 76 used) v1-6) + (+! (-> usage data 76 total) (logand -16 (+ v1-6 15))) + ) + this + ) + +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of ((this art-cloth-geo)) + (the-as int (+ (-> this type size) + (* (-> this length) 32) + (asize-of (-> this sphere-transforms)) + (asize-of (-> this disc-transforms)) + (asize-of (-> this anchor-transforms)) + ) + ) + ) + +(defmethod reset! ((this verlet-particle-system)) + "Reset to stationary/default state." + (set! (-> this accum-force quad) (the-as uint128 0)) + (dotimes (v1-1 (-> this particles length)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 v1-1)))) + (-> this particles data v1-1 pos quad) + ) + ) + 0 (none) ) -(defmethod cloth-system-cmd-handler ((this cloth-system) (cmds pair)) - (format 0 "unimplemented cloth-system-cmd-handler~%") +(defmethod reset! ((this cloth-system)) + "Reset to stationary/default state." + (reset-locations this) + (when (> (-> this anchor-points length) 0) + (let ((v1-6 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (-> this anchor-points data)) + (the-as vector (-> this particles data (-> this anchor-points data 0 particle-index))) + ) + ) + ) + (dotimes (a0-4 (-> this particles length)) + (vector+! (the-as vector (-> this particles data a0-4)) (the-as vector (-> this particles data a0-4)) v1-6) + ) + ) + ) + (dotimes (s5-0 1) + (run-one-iteration this) + ) + (call-parent-method this) (none) ) -(defmethod init! ((this cloth-base)) - ;; this looks more like run! than init to me. - 0) \ No newline at end of file +(defmethod pre-physics-update ((this cloth-system)) + "Callback to update prior to running verlet integration. Can handle movement of the entire system in the world, for example" + 0 + (none) + ) + +;; WARN: Return type mismatch cloth-flag vs none. +(defmethod pre-physics-update ((this cloth-on-skeleton)) + "Callback to update prior to running verlet integration. Can handle movement of the entire system in the world, for example" + (let ((s5-0 (new 'stack-no-clear 'matrix)) + (s4-0 (handle->process (-> this owner))) + ) + (when s4-0 + (cond + ((< -1 (-> this base-transform-index)) + (let* ((v1-4 s5-0) + (a3-0 (-> (the-as process-focusable s4-0) node-list data (-> this base-transform-index) bone transform)) + (a0-8 (-> a3-0 rvec quad)) + (a1-3 (-> a3-0 uvec quad)) + (a2-0 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> v1-4 rvec quad) a0-8) + (set! (-> v1-4 uvec quad) a1-3) + (set! (-> v1-4 fvec quad) a2-0) + (set! (-> v1-4 trans quad) a3-1) + ) + ) + (else + (quaternion->matrix s5-0 (-> (the-as process-focusable s4-0) root quat)) + (set! (-> s5-0 trans quad) (-> (the-as process-focusable s4-0) root trans quad)) + ) + ) + (vector-normalize! (-> s5-0 fvec) 1.0) + (vector-normalize! (-> s5-0 uvec) 1.0) + (vector-normalize! (-> s5-0 rvec) 1.0) + (vector-float*! (-> s5-0 trans) (-> s5-0 trans) (/ 1.0 (-> s5-0 trans w))) + (set! (-> s5-0 trans w) 1.0) + (when (logtest? (cloth-flag local-space local-space-xyz local-space-y) (-> this flags)) + (let ((s4-1 (matrix-identity! (new 'stack-no-clear 'matrix)))) + (if (logtest? (cloth-flag local-space-y) (-> this flags)) + (set! (-> s4-1 trans y) (- (-> s5-0 trans y) (-> this last-owner-mat trans y))) + (vector-! (-> s4-1 trans) (-> s5-0 trans) (-> this last-owner-mat trans)) + ) + (when (logtest? (cloth-flag local-space) (-> this flags)) + (let ((s3-0 (matrix-identity! (new 'stack-no-clear 'matrix)))) + (vector-float*! (-> s3-0 trans) (-> s5-0 trans) -1.0) + (matrix*! s4-1 s4-1 s3-0) + (matrix-4x4-inverse! s3-0 (-> this last-owner-mat)) + (matrix*! s3-0 s3-0 s5-0) + (set! (-> s3-0 trans quad) (the-as uint128 0)) + (set! (-> s3-0 trans w) 1.0) + (matrix*! s4-1 s4-1 s3-0) + (matrix-identity! s3-0) + (set! (-> s3-0 trans quad) (-> s5-0 trans quad)) + (matrix*! s4-1 s4-1 s3-0) + ) + ) + (dotimes (s3-1 (-> this particles length)) + (set! (-> this particles data s3-1 pos w) 1.0) + (vector-matrix*! + (the-as vector (-> this particles data s3-1)) + (the-as vector (-> this particles data s3-1)) + s4-1 + ) + (set! (-> this particles data s3-1 pos w) 1.0) + (set! (-> this particles data s3-1 prev-pos w) 1.0) + (vector-matrix*! + (the-as vector (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 s3-1))) + (the-as vector (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 s3-1))) + s4-1 + ) + (set! (-> this particles data s3-1 prev-pos w) 1.0) + ) + ) + ) + (let ((a2-7 (-> this last-owner-mat)) + (v1-54 (-> s5-0 rvec quad)) + (a0-42 (-> s5-0 uvec quad)) + (a1-23 (-> s5-0 fvec quad)) + (a3-2 (-> s5-0 trans quad)) + ) + (set! (-> a2-7 rvec quad) v1-54) + (set! (-> a2-7 uvec quad) a0-42) + (set! (-> a2-7 fvec quad) a1-23) + (set! (-> a2-7 trans quad) a3-2) + ) + (logclear! (-> this flags) (cloth-flag local-space local-space-xyz local-space-y)) + ) + ) + (none) + ) + +;; WARN: Return type mismatch symbol vs none. +(defmethod reset! ((this cloth-on-skeleton)) + "Reset to stationary/default state." + (let ((s5-0 (new 'stack-no-clear 'matrix)) + (s4-0 (handle->process (-> this owner))) + ) + (when s4-0 + (cond + ((< -1 (-> this base-transform-index)) + (let* ((v1-5 s5-0) + (a3-0 (-> (the-as process-focusable s4-0) node-list data (-> this base-transform-index) bone transform)) + (a0-8 (-> a3-0 rvec quad)) + (a1-3 (-> a3-0 uvec quad)) + (a2-0 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> v1-5 rvec quad) a0-8) + (set! (-> v1-5 uvec quad) a1-3) + (set! (-> v1-5 fvec quad) a2-0) + (set! (-> v1-5 trans quad) a3-1) + ) + ) + (else + (quaternion->matrix s5-0 (-> (the-as process-focusable s4-0) root quat)) + (set! (-> s5-0 trans quad) (-> (the-as process-focusable s4-0) root trans quad)) + ) + ) + (dotimes (s4-1 (-> this particles length)) + (vector-matrix*! (the-as vector (-> this particles data s4-1)) (the-as vector (-> this mesh mesh s4-1)) s5-0) + (vector-float*! + (the-as vector (-> this particles data s4-1)) + (the-as vector (-> this particles data s4-1)) + (/ 1.0 (-> this particles data s4-1 pos w)) + ) + (set! (-> this particles data s4-1 pos w) 1.0) + ) + (let ((v1-24 0) + (a0-24 (+ (-> this particles length) -1)) + ) + (while (>= a0-24 v1-24) + (+! v1-24 1) + ) + ) + (let ((a0-25 (-> s5-0 trans))) + (set! (-> this last-owner-pos quad) (-> a0-25 quad)) + ) + ) + ) + (set! (-> this accum-force quad) (the-as uint128 0)) + (dotimes (v1-29 (-> this particles length)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 v1-29)))) + (-> this particles data v1-29 pos quad) + ) + ) + (none) + ) + +(defmethod relocate ((this cloth-system) (offset int)) + (if (nonzero? (-> this stick-constraints)) + (&+! (-> this stick-constraints) offset) + ) + (if (nonzero? (-> this disc-collision-constraints)) + (&+! (-> this disc-collision-constraints) offset) + ) + (if (nonzero? (-> this collision-constraints)) + (&+! (-> this collision-constraints) offset) + ) + (if (nonzero? (-> this anchor-points)) + (&+! (-> this anchor-points) offset) + ) + (if (nonzero? (-> this strip)) + (&+! (-> this strip) offset) + ) + (if (nonzero? (-> this strip2)) + (&+! (-> this strip2) offset) + ) + (if (nonzero? (-> this strip3)) + (&+! (-> this strip3) offset) + ) + (call-parent-method this offset) + ) + +(defmethod relocate ((this cloth-on-skeleton) (offset int)) + (call-parent-method this offset) + ) + +(defmethod debug-draw ((this verlet-particle-system)) + (dotimes (s5-0 (-> this particles length)) + (let ((s4-0 add-debug-text-3d) + (s3-0 #t) + (s2-0 583) + ) + (format (clear *temp-string*) "~d" s5-0) + (s4-0 + s3-0 + (the-as bucket-id s2-0) + *temp-string* + (the-as vector (-> this particles data s5-0)) + (font-color red) + (the-as vector2h #f) + ) + ) + ) + 0 + (none) + ) + +(defmethod debug-draw ((this cloth-system)) + (dotimes (s5-0 (-> this particles length)) + (let* ((a0-1 (/ s5-0 (-> this cloth-width))) + (v1-2 (mod s5-0 (-> this cloth-width))) + (s1-0 (cond + ((not (logtest? a0-1 1)) + (if (or (< v1-2 (/ (-> this cloth-width) 4)) (>= v1-2 (/ (* 3 (-> this cloth-width)) 4))) + 3 + 4 + ) + ) + ((or (< v1-2 (/ (-> this cloth-width) 4)) (>= v1-2 (/ (* 3 (-> this cloth-width)) 4))) + 7 + ) + (else + 6 + ) + ) + ) + (s4-0 add-debug-text-3d) + (s3-0 #t) + (s2-0 583) + ) + (format (clear *temp-string*) "~d" s5-0) + (add-debug-sphere #t (the-as bucket-id s2-0) + (-> this particles data s5-0 pos) + (meters 0.02) + (static-rgba #x80 0 #x80 #x80) + ) + ; (s4-0 + ; s3-0 + ; (the-as bucket-id s2-0) + ; *temp-string* + ; (the-as vector (-> this particles data s5-0)) + ; (the-as font-color s1-0) + ; (the-as vector2h #f) + ; ) + ) + ) + 0 + (none) + ) + +(defmethod initialize-cloth-system! ((this cloth-system) (arg0 cloth-params)) + "Set up this cloth system with the given [[cloth-params]]." + (local-vars (sv-16 int) (sv-20 int) (sv-24 int) (sv-28 int)) + (if (or (zero? (-> this mesh)) (< (-> this mesh length) 4)) + (go process-drawable-art-error "cloth-mesh (art-cloth-geo)") + ) + (set! (-> this params) arg0) + (set! (-> this cloth-width) (the-as int (-> arg0 cloth-width))) + (set! (-> this cloth-height) (/ (the-as int (-> this mesh length)) (-> this cloth-width))) + (set! (-> this drag) (-> arg0 drag)) + (set! (-> this collision-constraints) + (new 'process 'collision-sphere-array (the-as int (-> arg0 num-sphere-constraints))) + ) + (set! (-> this disc-collision-constraints) + (new 'process 'collision-disc-array (the-as int (-> arg0 num-disc-constraints))) + ) + (set! (-> this anchor-points) (new 'process 'anchor-point-array (the-as int (-> arg0 num-anchor-points)))) + (set! (-> this wind-constant) (-> arg0 wind-constant)) + (set! (-> this gravity-constant) (-> arg0 gravity-constant)) + (set! (-> this thickness-scalar) (-> arg0 cloth-thickness)) + (set! (-> this flags) (-> arg0 flags)) + (set! (-> this timestep-frequency) (-> arg0 timestep-frequency)) + (set! (-> this secret-disable) (-> arg0 secret-disable)) + (when (<= (-> this mesh cloth-thickness length) 0) + ) + (if (logtest? (-> this flags) (cloth-flag flip-normals)) + (set! (-> this face-normal-scalar) -1.0) + (set! (-> this face-normal-scalar) 1.0) + ) + (set! (-> this particles) (new 'process 'particle-array (* (-> this cloth-width) (-> this cloth-height)))) + (if (not (and (nonzero? (-> this collision-constraints)) (and (nonzero? (-> this disc-collision-constraints)) + (nonzero? (-> this anchor-points)) + (nonzero? (-> this particles)) + ) + ) + ) + (go process-drawable-art-error "cloth-memory") + ) + (dotimes (v1-38 (-> this particles length)) + (set! (-> this particles data v1-38 pos quad) (-> this mesh mesh v1-38 pt quad)) + (set! (-> this particles data v1-38 mass-scale) 1.0) + ) + (set! sv-16 (* (+ (-> this cloth-width) -1) (-> this cloth-height))) + (set! sv-20 (* (+ (-> this cloth-height) -1) (-> this cloth-width))) + (set! sv-24 (+ (* (+ (-> this cloth-width) -2) 2) 2)) + (let ((v1-52 (* sv-24 (+ (-> this cloth-height) -1))) + (s4-0 (* (+ (-> this cloth-width) -2) (-> this cloth-height))) + ) + (set! sv-28 (+ s4-0 (* (-> this cloth-width) (+ (-> this cloth-height) -2)))) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (+! s4-0 (* (-> this cloth-height) 2)) + (set! sv-28 (+ sv-28 (* (-> this cloth-height) 2))) + ) + (set! sv-28 (max 0 sv-28)) + (let ((s3-1 (max 0 v1-52))) + (set! (-> this num-xy-constraints) (+ sv-16 sv-20)) + (set! (-> this num-diagonal-constraints) s3-1) + (if (zero? (-> this stick-constraints)) + (set! (-> this stick-constraints) (new 'process 'stick-constraint-array (+ sv-16 sv-20 s3-1 sv-28))) + ) + (let ((v1-62 0)) + (dotimes (a0-37 (-> this cloth-height)) + (dotimes (a1-20 (+ (-> this cloth-width) -1)) + (let ((a2-11 (+ a1-20 (* a0-37 (-> this cloth-width)))) + (a3-2 (-> this stick-constraints data v1-62)) + ) + (set! (-> a3-2 particle0) (the-as uint a2-11)) + (set! (-> a3-2 particle1) (the-as uint (+ a2-11 1))) + ) + (+! v1-62 1) + ) + ) + ) + (let ((v1-65 sv-16)) + (dotimes (a0-38 (+ (-> this cloth-height) -1)) + (dotimes (a1-24 (-> this cloth-width)) + (let ((a2-18 (+ a1-24 (* a0-38 (-> this cloth-width)))) + (a3-5 (-> this stick-constraints data v1-65)) + ) + (set! (-> a3-5 particle0) (the-as uint a2-18)) + (set! (-> a3-5 particle1) (the-as uint (+ a2-18 (-> this cloth-width)))) + ) + (+! v1-65 1) + ) + ) + ) + (let ((v1-69 (+ sv-16 sv-20))) + (dotimes (a0-40 (+ (-> this cloth-height) -1)) + (dotimes (a1-29 (-> this cloth-width)) + (let ((a2-24 (+ a1-29 (* a0-40 (-> this cloth-width)))) + (a3-8 (-> this stick-constraints data v1-69)) + ) + (when (< a1-29 (+ (-> this cloth-width) -1)) + (set! (-> a3-8 particle0) (the-as uint a2-24)) + (set! (-> a3-8 particle1) (the-as uint (+ (-> this cloth-width) 1 a2-24))) + (+! v1-69 1) + (set! a3-8 (-> this stick-constraints data v1-69)) + ) + (when (> a1-29 0) + (set! (-> a3-8 particle0) (the-as uint a2-24)) + (set! (-> a3-8 particle1) (the-as uint (+ (-> this cloth-width) -1 a2-24))) + (+! v1-69 1) + (-> this stick-constraints data v1-69) + ) + ) + ) + ) + ) + (let ((v1-74 (+ sv-16 sv-20 s3-1))) + (dotimes (a0-42 (-> this cloth-height)) + (dotimes (a1-34 (+ (-> this cloth-width) -2)) + (let ((a2-31 (+ a1-34 (* a0-42 (-> this cloth-width)))) + (a3-14 (-> this stick-constraints data v1-74)) + ) + (set! (-> a3-14 particle0) (the-as uint a2-31)) + (set! (-> a3-14 particle1) (the-as uint (+ a2-31 2))) + ) + (+! v1-74 1) + ) + ) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (dotimes (a0-48 (-> this cloth-height)) + (let ((a1-40 (+ (* (+ a0-48 1) (-> this cloth-width)) -3)) + (a2-38 (* a0-48 (-> this cloth-width))) + (a3-17 (-> this stick-constraints data v1-74)) + ) + (set! (-> a3-17 particle0) (the-as uint a1-40)) + (set! (-> a3-17 particle1) (the-as uint a2-38)) + ) + (let ((v1-75 (+ v1-74 1))) + (-> this stick-constraints data v1-75) + (let ((a1-46 (+ (* (+ a0-48 1) (-> this cloth-width)) -2)) + (a2-43 (+ (* a0-48 (-> this cloth-width)) 1)) + (a3-20 (-> this stick-constraints data v1-75)) + ) + (set! (-> a3-20 particle0) (the-as uint a1-46)) + (set! (-> a3-20 particle1) (the-as uint a2-43)) + ) + (set! v1-74 (+ v1-75 1)) + ) + (-> this stick-constraints data v1-74) + ) + ) + ) + (let ((v1-80 (+ sv-16 sv-20 s3-1 s4-0))) + (dotimes (a0-51 (+ (-> this cloth-height) -2)) + (dotimes (a1-51 (-> this cloth-width)) + (let ((a2-47 (+ a1-51 (* a0-51 (-> this cloth-width)))) + (a3-23 (-> this stick-constraints data v1-80)) + ) + (set! (-> a3-23 particle0) (the-as uint a2-47)) + (set! (-> a3-23 particle1) (the-as uint (+ a2-47 (* (-> this cloth-width) 2)))) + ) + (+! v1-80 1) + ) + ) + ) + ) + ) + (let ((s4-1 (* (if (logtest? (-> this flags) (cloth-flag double-sided)) + (+ (* (-> this cloth-width) 2) 1) + (+ (* 3 (+ (-> this cloth-width) -2)) 6) + ) + (+ (-> this cloth-height) -1) + ) + ) + ) + (if (zero? (-> this strip)) + (set! (-> this strip) + (new 'process 'prim-strip s4-1 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name)) + ) + ) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (when (zero? (-> this strip2)) + (set! (-> this strip2) + (new 'process 'prim-strip s4-1 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name2)) + ) + (set! (-> this strip2 num-verts) (the-as uint 0)) + 0 + ) + (when (zero? (-> this strip3)) + (let ((a2-53 (* (+ (* (-> this cloth-width) 2) (* (-> this cloth-height) 2)) 2))) + (set! (-> this strip3) + (new 'process 'prim-strip a2-53 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name3)) + ) + ) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + ) + ) + (set! (-> this strip num-verts) (the-as uint 0)) + 0 + (when (logtest? (-> this flags) (cloth-flag autogen-uvs)) + (dotimes (v1-115 (-> this particles length)) + (let ((a1-59 (mod v1-115 (-> this cloth-width))) + (a0-63 (/ v1-115 (-> this cloth-width))) + ) + (set! (-> this mesh mesh v1-115 u) (/ (the float a1-59) (the float (+ (-> this cloth-width) -1)))) + (set! (-> this mesh mesh v1-115 v) (- 1.0 (/ (the float a0-63) (the float (+ (-> this cloth-height) -1))))) + ) + (set! (-> this mesh mesh v1-115 v) (fmax 0.0 (fmin 1.0 (-> this mesh mesh v1-115 v)))) + ) + (dotimes (v1-118 (-> this cloth-width)) + (+ (-> this cloth-height) -1) + (set! (-> this mesh mesh v1-118 v) 0.99) + ) + ) + (logior! (-> this flags) (cloth-flag need-reset need-setup)) + (logior! (-> this flags) (cloth-flag active inited)) + (set! (-> this reset-count) 1) + 0 + (none) + ) + +(defmethod setup-from-params! ((this cloth-on-skeleton) (arg0 cloth-params) (arg1 handle)) + (if (logtest? (-> this flags) (cloth-flag inited)) + (return 0) + ) + (set! (-> this owner) arg1) + (set! (-> this num-iterations) (-> arg0 num-iterations)) + (let ((s4-0 (handle->process (-> this owner)))) + (when (and s4-0 (< -1 (-> arg0 mesh))) + (set! (-> this mesh) + (the-as art-cloth-geo (-> (the-as process-focusable s4-0) draw art-group data (-> arg0 mesh))) + ) + (when (or (not (-> this mesh)) (!= (-> this mesh type) art-cloth-geo)) + (if (logtest? (-> arg0 flags) (cloth-flag suppress-mesh-failure)) + (return 0) + (go process-drawable-art-error "cloth-mesh (art-cloth-geo)") + ) + ) + (set! (-> this base-transform-index) (-> arg0 initial-xform)) + (set! (-> arg0 num-anchor-points) + (the-as uint (max (-> this mesh anchor-transforms length) (the-as int (-> arg0 num-anchor-points)))) + ) + (set! (-> arg0 num-sphere-constraints) + (the-as uint (max (-> this mesh sphere-transforms length) (the-as int (-> arg0 num-sphere-constraints)))) + ) + (set! (-> arg0 num-disc-constraints) + (the-as uint (max (-> this mesh disc-transforms length) (the-as int (-> arg0 num-disc-constraints)))) + ) + (set! (-> this ball-collision-radius) (-> arg0 ball-collision-radius)) + (set! (-> this ball-collision-radius) (-> this ball-collision-radius)) + (dotimes (s3-0 (-> this mesh anchor-transforms length)) + (let ((s2-0 (-> this mesh anchor-transforms data s3-0))) + (when (< (-> s2-0 joint) 0) + (let ((v1-47 + (the-as + joint + (get-art-by-name-method (-> (the-as process-focusable s4-0) draw jgeo) (-> s2-0 joint-name) (the-as type #f)) + ) + ) + ) + (set! (-> s2-0 joint) (if v1-47 + (+ (-> v1-47 number) 1) + 0 + ) + ) + ) + ) + ) + ) + (dotimes (s3-1 (-> this mesh sphere-transforms length)) + (let ((s2-1 (-> this mesh sphere-transforms data s3-1))) + (when (< (-> s2-1 joint) 0) + (let ((v1-61 + (the-as + joint + (get-art-by-name-method (-> (the-as process-focusable s4-0) draw jgeo) (-> s2-1 joint-name) (the-as type #f)) + ) + ) + ) + (set! (-> s2-1 joint) (if v1-61 + (+ (-> v1-61 number) 1) + 0 + ) + ) + ) + ) + ) + ) + (dotimes (s3-2 (-> this mesh disc-transforms length)) + (let ((s2-2 (-> this mesh disc-transforms data s3-2))) + (when (< (-> s2-2 joint) 0) + (let ((v1-76 (the-as joint (get-art-by-name-method + (-> (the-as process-focusable s4-0) draw jgeo) + (the-as string (-> s2-2 joint-name)) + (the-as type #f) + ) + ) + ) + ) + (set! (-> s2-2 joint) (if v1-76 + (+ (-> v1-76 number) 1) + 0 + ) + ) + ) + ) + ) + ) + ) + ) + (initialize-cloth-system! this arg0) + 0 + ) + +(defmethod run-one-iteration ((this verlet-particle-system)) + "Run one iteration of the system." + 0 + (none) + ) + +(defmethod update! ((this verlet-particle-system)) + (with-pp + (accumulate-external-forces! this) + (let ((v1-4 (- (current-time) (-> pp clock old-frame-counter)))) + (if (> (-> this timestep-frequency) 0) + (compute-verlet-step this (* 0.0033333334 (the float (-> this timestep-frequency)))) + (compute-verlet-step this (* 0.0033333334 (the float v1-4))) + ) + ) + ;; (debug-draw this) + 0 + ) + ) + +(defmethod update! ((this cloth-system)) + (if (not (logtest? (-> this flags) (cloth-flag active))) + (return 0) + ) + (when (logtest? (-> this flags) (cloth-flag need-setup)) + (cond + ((or (> (-> this reset-count) 0) (logtest? (-> this flags) (cloth-flag no-draw))) + (reset! this) + (+! (-> this reset-count) -1) + (set! (-> this reset-count) (max 0 (-> this reset-count))) + ) + (else + (reset! this) + (logclear! (-> this flags) (cloth-flag need-setup)) + (dotimes (s5-0 (-> this stick-constraints length)) + (let ((s4-0 (-> this stick-constraints data s5-0))) + 0.0 + (let ((f0-1 (vector-vector-distance + (the-as vector (-> this particles data (-> s4-0 particle0))) + (the-as vector (-> this particles data (-> s4-0 particle1))) + ) + ) + ) + (set! (-> s4-0 one-over-two-times-constraint-length) (/ 1.0 (* 2.0 f0-1))) + (set! (-> s4-0 constraint-length-sqd) (* f0-1 f0-1)) + (set! (-> s4-0 constraint-length-half) (* 0.5 f0-1)) + ) + ) + ) + ) + ) + ) + (when (and (logtest? (-> this flags) (cloth-flag need-reset)) + (not (logtest? (-> this flags) (cloth-flag need-setup))) + ) + (reset! this) + (if (> (-> this reset-count) 0) + (+! (-> this reset-count) -1) + (logclear! (-> this flags) (cloth-flag need-reset)) + ) + ) + (pre-physics-update this) + (call-parent-method this) + (reset-locations this) + (let ((s5-1 (-> this num-iterations))) + (if (logtest? (cloth-flag riding) (-> this flags)) + (+! s5-1 1) + ) + (dotimes (s4-1 s5-1) + (run-one-iteration this) + ) + ) + (when (and (> (the-as uint (-> this secret-disable)) 0) + (> (the-as uint (logand (-> *game-info* secrets) (-> this secret-disable))) 0) + ) + (hide! this) + (return 0) + ) + (post-physics-update this) + 0 + ) + +(defmethod update! ((this cloth-on-skeleton)) + (if (not (logtest? (cloth-flag hidden) (-> this flags))) + (logclear! (-> this flags) (cloth-flag no-draw)) + ) + (when (and (handle->process (-> this owner)) (= (-> (handle->process (-> this owner)) type) target)) + (let* ((s5-0 (handle->process (-> this owner))) + (a0-16 (if (type? s5-0 process-focusable) + s5-0 + ) + ) + ) + (when (and a0-16 (focus-test? (the-as process-focusable a0-16) teleporting)) + (set! (-> this reset-count) 1) + (logior! (-> this flags) (cloth-flag need-reset no-draw)) + ) + ) + ) + (let ((s5-1 (handle->process (-> this owner)))) + (if (and s5-1 + (nonzero? (-> (the-as process-focusable s5-1) draw)) + (logtest? (-> (the-as process-focusable s5-1) draw status) + (draw-control-status no-draw no-draw-temp no-draw-bounds no-draw-bounds2) + ) + ) + (logior! (-> this flags) (cloth-flag no-draw)) + ) + (when (and s5-1 (nonzero? (-> (the-as process-focusable s5-1) draw))) + (let ((s4-0 (-> (the-as process-focusable s5-1) draw))) + (setup-dma-and-tex (-> this strip) s4-0) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (setup-dma-and-tex (-> this strip2) s4-0) + (setup-dma-and-tex (-> this strip3) s4-0) + ) + ) + ) + (when (< -1 (-> this base-transform-index)) + (let ((s5-2 (-> (the-as process-focusable s5-1) node-list data 3 bone transform trans))) + (let ((f0-0 12288.0)) + (when (< (* f0-0 f0-0) (vector-vector-distance-squared (-> this last-owner-pos) s5-2)) + ) + ) + (set! (-> this last-owner-pos quad) (-> s5-2 quad)) + ) + ) + ) + (call-parent-method this) + ) + +(defmethod accumulate-external-forces! ((this verlet-particle-system)) + "If this cloth system has the wind flag, calculate the wind force." + 0 + (none) + ) + +(defmethod hide! ((this cloth-system)) + (logior! (-> this flags) (cloth-flag no-draw hidden)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (none) + ) + +(defmethod accumulate-external-forces! ((this cloth-system)) + "If this cloth system has the wind flag, calculate the wind force." + (if (not (logtest? (-> this flags) (cloth-flag no-gravity))) + (vector-float*! (-> this accum-force) (new 'static 'vector :y -1.0) (-> this gravity-constant)) + ) + (if (logtest? (-> this flags) (cloth-flag use-momentum)) + (vector+float*! (-> this accum-force) (-> this accum-force) (-> this momentum) 1.0) + ) + (when (logtest? (-> this flags) (cloth-flag use-wind)) + (let ((s5-0 (new 'stack-no-clear 'vector))) + 0.0 + (cond + ((-> *setting-control* user-current global-wind) + (vector-float*! s5-0 (the-as vector (-> *setting-control* user-current global-wind)) (-> this wind-constant)) + ) + (else + (let ((v1-17 s5-0) + (a1-1 (-> this particles data)) + ) + (vector-float*! + v1-17 + (-> *wind-work* + wind-array + (logand (+ (the int (-> a1-1 0 pos x)) (the int (-> a1-1 0 pos z)) (-> *wind-work* wind-time)) 63) + ) + (* 2048.0 (-> this wind-constant) (-> *setting-control* user-current ambient-wind-scalar)) + ) + ) + ) + ) + (let* ((f0-11 (vector-normalize-ret-len! s5-0 1.0)) + (f0-12 (fmin 163840.0 f0-11)) + ) + (vector+float*! (-> this accum-force) (-> this accum-force) s5-0 f0-12) + ) + ) + ) + 0 + (none) + ) + +(defmethod compute-verlet-step ((this verlet-particle-system) (arg0 float)) + (let ((f0-1 (* arg0 arg0)) + (f1-1 (-> this drag)) + ) + (dotimes (v1-0 (-> this particles length)) + (let ((a2-1 (-> this particles data v1-0)) + (a1-4 (new 'stack-no-clear 'vector)) + ) + (let ((a3-0 (-> this accum-force))) + (vector-float*! a1-4 (-> a2-1 pos) (- 2.0 f1-1)) + (vector-! a1-4 a1-4 (vector-float*! (new 'stack-no-clear 'vector) (-> a2-1 prev-pos) (- 1.0 f1-1))) + (vector+float*! a1-4 a1-4 a3-0 f0-1) + ) + (set! (-> a2-1 prev-pos quad) (-> a2-1 pos quad)) + (set! (-> a2-1 pos quad) (-> a1-4 quad)) + ) + ) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch symbol vs none. +;; ERROR: Failed load: (set! vf10 (l.vf (+ a2-8 32))) at op 59 +(defmethod enforce-constraints-1 ((this cloth-system)) + (local-vars (a1-8 float)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (let ((v1-0 (new 'stack-no-clear 'vector))) + (set! (-> v1-0 x) 0.5) + (set! (-> v1-0 y) 0.5) + (set! (-> v1-0 z) 0.5) + (set! (-> v1-0 w) 0.5) + (let ((a1-4 (new 'stack-no-clear 'vector))) + (set! (-> a1-4 x) 3.0) + (set! (-> a1-4 y) 3.0) + (set! (-> a1-4 z) 3.0) + (set! (-> a1-4 w) 3.0) + (.max.w.vf vf7 vf0 vf0) + (.lvf vf8 (&-> v1-0 quad)) + (.lvf vf12 (&-> a1-4 quad)) + ) + ) + (.sub.w.vf vf9 vf0 vf0) + (dotimes (v1-1 (-> this stick-constraints length)) + (let* ((a1-7 (-> this stick-constraints data v1-1)) + (a2-8 (-> this particles data (-> a1-7 particle0))) + (a3-5 (-> this particles data (-> a1-7 particle1))) + ) + (.lvf vf2 (&-> a2-8 pos quad)) + (.lvf vf3 (&-> a3-5 pos quad)) + (.lvf vf6 (&-> a1-7 vec quad)) + (.sub.vf vf4 vf3 vf2) + (.mul.vf vf5 vf4 vf4) + (.mul.z.vf acc vf7 vf5) + (.add.mul.y.vf acc vf7 vf5 acc) + (.add.mul.x.vf acc vf7 vf5 acc) + (.add.mul.z.vf vf5 vf7 vf6 acc) + (.mul.y.vf vf5 vf5 vf6) + (.div.vf Q vf6 vf5 :fsf #b0 :ftf #b0) + (.lvf vf10 (&+ a2-8 32)) + (.lvf vf11 (&+ a3-5 32)) + (.max.x.vf vf10 vf0 vf10 :mask #b111) + (.max.x.vf vf11 vf0 vf11 :mask #b111) + (.add.vf vf13 vf10 vf11) + (.sub.vf vf13 vf12 vf13) + (.mul.vf vf10 vf10 vf13) + (.mul.vf vf11 vf11 vf13) + (.wait.vf) + (.sub.vf vf5 vf8 Q) + (.mul.vf vf5 vf5 vf4) + (.mul.vf vf10 vf10 vf5) + (.add.vf vf2 vf2 vf10) + (.mul.vf vf11 vf11 vf5) + (.sub.vf vf3 vf3 vf11) + (.svf (&-> a2-8 pos quad) vf2) + (.svf (&-> a3-5 pos quad) vf3) + ) + (.mov a1-8 vf3) + ) + (none) + ) + ) + +;; WARN: Return type mismatch symbol vs none. +(defmethod enforce-constraints-2 ((this cloth-system)) + (dotimes (v1-0 (-> this stick-constraints length)) + (let* ((t0-0 (-> this stick-constraints data v1-0)) + (a1-5 (-> this particles data (-> t0-0 particle0))) + (a2-6 (-> this particles data (-> t0-0 particle1))) + (f0-1 (* 2.0 (-> t0-0 constraint-length-half))) + (a3-4 (vector-! (new 'stack-no-clear 'vector) (-> a2-6 pos) (-> a1-5 pos))) + ) + 0.0 + (let ((f1-2 (* f0-1 f0-1))) + 0.0 + 0.0 + (let* ((f1-4 (/ (+ f1-2 (vector-dot a3-4 a3-4)) (* 2.0 f0-1))) + (f0-3 (/ (- f1-4 f0-1) f1-4)) + ) + (vector-float*! a3-4 a3-4 (* 0.5 f0-3)) + ) + ) + (let ((f1-6 1.0) + (f0-5 -1.0) + ) + (cond + ((< (-> t0-0 particle0) (the-as uint 7)) + (set! f1-6 (* 0.0 f1-6)) + (set! f0-5 (* 2.0 f0-5)) + ) + ((< (-> t0-0 particle1) (the-as uint 7)) + (set! f1-6 (* 2.0 f1-6)) + (set! f0-5 (* 0.0 f0-5)) + ) + ) + (vector+float*! (-> a1-5 pos) (-> a1-5 pos) a3-4 f1-6) + (vector+float*! (-> a2-6 pos) (-> a2-6 pos) a3-4 f0-5) + ) + ) + ) + (none) + ) + +(defmethod-mips2c "(method 21 cloth-system)" 21 cloth-system) + +;; WARN: Return type mismatch symbol vs none. +(defmethod cloth-system-method-23 ((this cloth-system)) + (local-vars + (sv-32 int) + (sv-40 int) + (sv-48 int) + (sv-56 int) + (sv-64 matrix) + (sv-68 verlet-particle) + (sv-72 verlet-particle) + (sv-76 verlet-particle) + (sv-80 verlet-particle) + (sv-144 vector) + (sv-148 vector) + (sv-152 float) + (sv-156 float) + (sv-160 vector) + (sv-164 float) + (sv-168 float) + (sv-208 vector) + (sv-212 float) + (sv-216 vector) + ) + (set! sv-32 0) + (set! sv-40 0) + (set! sv-48 0) + (set! sv-56 -1) + (set! sv-64 (new 'stack-no-clear 'matrix)) + (dotimes (s5-0 (+ (-> this cloth-height) -1)) + (dotimes (s4-0 (+ (-> this cloth-width) -1)) + (set! sv-68 (-> this particles data sv-32)) + (set! sv-72 (-> this particles data (+ sv-32 1))) + (set! sv-76 (-> this particles data (+ sv-32 (-> this cloth-width)))) + (set! sv-80 (-> this particles data (+ (-> this cloth-width) 1 sv-32))) + (set! sv-144 (vector-! (new 'stack-no-clear 'vector) (-> sv-80 pos) (-> sv-68 pos))) + (set! sv-148 (vector-! (new 'stack-no-clear 'vector) (-> sv-72 pos) (-> sv-76 pos))) + (set! sv-152 (the-as float 0.0)) + (set! sv-156 (the-as float 0.0)) + (set! sv-160 (new 'stack-no-clear 'vector)) + (set! sv-164 (the-as float 0.0)) + (vector-float*! sv-160 (-> sv-72 pos) (-> sv-72 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-68 pos) (-> sv-68 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-76 pos) (-> sv-76 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-80 pos) (-> sv-80 mass-scale)) + (vector-float*! sv-160 sv-160 0.25) + (set! sv-40 0) + (set! sv-56 -1) + (set! (-> sv-64 rvec quad) (the-as uint128 0)) + (dotimes (s3-0 (-> this collision-constraints length)) + (when (!= s3-0 sv-56) + (let ((v1-39 (-> this collision-constraints data s3-0))) + (set! sv-164 (the-as float 204.8)) + (set! sv-168 (the-as float 0.0)) + (set! sv-168 (+ (-> v1-39 r) (the-as float sv-164))) + (set! sv-208 (vector-! (new 'stack-no-clear 'vector) sv-160 (the-as vector v1-39))) + ) + (set! sv-212 (the-as float 0.0)) + (set! sv-216 (new 'stack-no-clear 'vector)) + (set! sv-212 (vector-dot sv-208 sv-208)) + (when (< sv-212 (* sv-168 sv-168)) + (vector-normalize-copy! sv-216 sv-208 sv-168) + (vector-! sv-216 sv-216 sv-208) + (when (and (> sv-40 0) (< (vector-dot sv-216 (the-as vector sv-64)) 0.0)) + ) + (vector+float*! (-> sv-68 pos) (-> sv-68 pos) sv-216 (-> sv-68 mass-scale)) + (vector+float*! (-> sv-72 pos) (-> sv-72 pos) sv-216 (-> sv-72 mass-scale)) + (vector+float*! (-> sv-76 pos) (-> sv-76 pos) sv-216 (-> sv-76 mass-scale)) + (vector+float*! (-> sv-80 pos) (-> sv-80 pos) sv-216 (-> sv-80 mass-scale)) + (vector+! sv-160 sv-160 sv-216) + (set! sv-40 (+ sv-40 1)) + ) + ) + ) + (set! sv-32 (+ sv-32 1)) + ) + (set! sv-32 (+ sv-32 1)) + ) + (none) + ) + +;; WARN: Return type mismatch symbol vs none. +(defmethod cloth-system-method-22 ((this cloth-system)) + (local-vars + (v1-25 float) + (v1-27 float) + (sv-16 sphere) + (sv-24 int) + (sv-32 verlet-particle) + (sv-36 verlet-particle) + (sv-40 verlet-particle) + (sv-44 verlet-particle) + (sv-96 vector) + (sv-100 vector) + (sv-104 float) + (sv-108 float) + (sv-112 vector) + (sv-116 float) + (sv-120 float) + (sv-160 float) + (sv-164 float) + (sv-168 vector) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (dotimes (s5-0 (-> this collision-constraints length)) + (set! sv-16 (-> this collision-constraints data s5-0)) + (set! sv-24 0) + (dotimes (s4-0 (+ (-> this cloth-height) -1)) + (dotimes (s3-0 (+ (-> this cloth-width) -1)) + (set! sv-32 (-> this particles data sv-24)) + (set! sv-36 (-> this particles data (+ sv-24 1))) + (set! sv-40 (-> this particles data (+ sv-24 (-> this cloth-width)))) + (set! sv-44 (-> this particles data (+ (-> this cloth-width) 1 sv-24))) + (set! sv-96 (vector-! (new 'stack-no-clear 'vector) (-> sv-44 pos) (-> sv-32 pos))) + (set! sv-100 (vector-! (new 'stack-no-clear 'vector) (-> sv-36 pos) (-> sv-40 pos))) + (set! sv-104 (the-as float 0.0)) + (set! sv-108 (the-as float 0.0)) + (set! sv-112 (new 'stack-no-clear 'vector)) + (set! sv-116 (the-as float 0.0)) + (.lvf vf1 (&-> sv-96 quad)) + (.add.w.vf vf2 vf0 vf0 :mask #b1) + (.mul.vf vf1 vf1 vf1) + (.mul.x.vf acc vf2 vf1 :mask #b1) + (.add.mul.y.vf acc vf2 vf1 acc :mask #b1) + (.add.mul.z.vf vf1 vf2 vf1 acc :mask #b1) + (.mov v1-25 vf1) + (set! sv-104 v1-25) + (.lvf vf1 (&-> sv-100 quad)) + (.add.w.vf vf2 vf0 vf0 :mask #b1) + (.mul.vf vf1 vf1 vf1) + (.mul.x.vf acc vf2 vf1 :mask #b1) + (.add.mul.y.vf acc vf2 vf1 acc :mask #b1) + (.add.mul.z.vf vf1 vf2 vf1 acc :mask #b1) + (.mov v1-27 vf1) + (set! sv-108 v1-27) + (if (< sv-108 sv-104) + (vector+float*! sv-112 (-> sv-32 pos) sv-96 0.5) + (vector+float*! sv-112 (-> sv-40 pos) sv-100 0.5) + ) + (set! sv-116 (the-as float 0.0)) + (set! sv-120 (the-as float 0.0)) + (set! sv-120 (-> sv-16 r)) + (set! sv-160 (the-as float (vector-! (new 'stack-no-clear 'vector) sv-112 (the-as vector sv-16)))) + (set! sv-164 (the-as float 0.0)) + (set! sv-168 (new 'stack-no-clear 'vector)) + (set! sv-164 (vector-dot (the-as vector sv-160) (the-as vector sv-160))) + (when (< sv-164 (* sv-120 sv-120)) + (vector-normalize-copy! sv-168 (the-as vector sv-160) sv-120) + (vector-! sv-168 sv-168 (the-as vector sv-160)) + (vector+! (-> sv-32 pos) (-> sv-32 pos) sv-168) + (vector+! (-> sv-36 pos) (-> sv-36 pos) sv-168) + (vector+! (-> sv-40 pos) (-> sv-40 pos) sv-168) + (vector+! (-> sv-44 pos) (-> sv-44 pos) sv-168) + ) + (set! sv-24 (+ sv-24 1)) + ) + (set! sv-24 (+ sv-24 1)) + ) + ) + (none) + ) + ) + +(defmethod run-one-iteration ((this cloth-system)) + "Run one iteration of the system." + (enforce-constraints-1 this) + (cloth-system-method-21 this) + (dotimes (v1-4 0) + (let* ((a0-6 (-> this disc-collision-constraints data v1-4)) + (a2-0 (-> a0-6 start-particle-index)) + (a3-0 (-> a0-6 end-particle-index)) + (a1-2 (max 0 (min a2-0 (+ (-> this particles length) -1)))) + ) + (if (< a3-0 0) + (set! a3-0 (+ (-> this particles length) -1)) + ) + (let ((a2-8 (max 0 (min a3-0 (+ (-> this particles length) -1))))) + (while (>= a2-8 a1-2) + (let ((a3-7 (-> this particles data a1-2 pos))) + 0.0 + (let ((t1-0 (new 'stack-no-clear 'vector)) + (t0-7 (new 'stack-no-clear 'vector)) + ) + (vector-! t1-0 a3-7 (-> a0-6 origin)) + (let ((f0-2 (vector-dot t1-0 (-> a0-6 normal)))) + (when (< 0.0 f0-2) + (vector+float*! t0-7 a3-7 (-> a0-6 normal) (* -1.0 f0-2)) + (if (< (vector-length (vector-! (new 'stack-no-clear 'vector) t0-7 (-> a0-6 origin))) (-> a0-6 radius)) + (set! (-> a3-7 quad) (-> t0-7 quad)) + ) + ) + ) + ) + ) + (+! a1-2 1) + ) + ) + ) + ) + (dotimes (v1-7 (-> this anchor-points length)) + (set! (-> this particles data (-> this anchor-points data v1-7 particle-index) pos quad) + (-> this anchor-points data v1-7 anchor-pos quad) + ) + (set! (-> this particles data (-> this anchor-points data v1-7 particle-index) mass-scale) 0.0) + ) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (dotimes (v1-13 (-> this cloth-height)) + (let ((a0-19 (-> this particles data (+ (* v1-13 (-> this cloth-width)) -1 (-> this cloth-width)))) + (a1-20 (the-as object (&-> (-> this particles) _data (* (* 48 (-> this cloth-width)) v1-13)))) + ) + (set! (-> a0-19 mass-scale) 0.0) + (set! (-> a0-19 pos quad) (-> (the-as vector (&-> (the-as vector a1-20) x)) quad)) + (set! (-> a0-19 prev-pos quad) (-> (the-as vector (&-> (the-as vector a1-20) x)) quad)) + ) + ) + ) + (when (logtest? (-> this flags) (cloth-flag check-ground)) + (dotimes (v1-19 (-> this particles length)) + (let ((a0-25 (-> this particles data v1-19))) + (set! (-> a0-25 pos y) (fmax (-> a0-25 pos y) (-> this ground-constraint))) + ) + ) + ) + 0 + (none) + ) + +(defun get-neighboring-faces ((arg0 vector4w) (arg1 int) (arg2 int) (arg3 int) (arg4 int)) + (let ((v0-0 0)) + (when (and (< arg2 (+ arg4 -1)) (< arg1 (+ arg3 -1))) + (set! (-> arg0 data v0-0) (+ (* arg2 (+ arg3 -1)) arg1)) + (+! v0-0 1) + ) + (when (and (> arg2 0) (< arg1 (+ arg3 -1))) + (set! (-> arg0 data v0-0) (+ (* (+ arg2 -1) (+ arg3 -1)) arg1)) + (+! v0-0 1) + ) + (when (and (> arg2 0) (> arg1 0)) + (set! (-> arg0 data v0-0) (+ arg1 -1 (* (+ arg2 -1) (+ arg3 -1)))) + (+! v0-0 1) + ) + (when (and (< arg2 (+ arg4 -1)) (> arg1 0)) + (set! (-> arg0 data v0-0) (+ arg1 -1 (* arg2 (+ arg3 -1)))) + (+! v0-0 1) + ) + v0-0 + ) + ) + +(kmemopen global "cloth-buffers") + +(define *normal-array* (the-as (inline-array vector) (malloc 'global 6400))) + +(kmemclose) + +(defmethod cloth-system-method-27 ((this cloth-system) (arg0 vector) (arg1 int) (arg2 int) (arg3 current-position-info)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (let ((s3-0 (new 'stack-no-clear 'vector4w))) + 0 + (let ((v1-1 (get-neighboring-faces s3-0 arg1 arg2 (-> this cloth-width) (-> this cloth-height)))) + (set! (-> arg0 quad) (the-as uint128 0)) + (dotimes (a0-3 v1-1) + (vector+! arg0 arg0 (-> *normal-array* (-> s3-0 data a0-3))) + ) + ) + ) + (let ((v1-4 arg0)) + (let ((f0-0 1.0)) + (.lvf vf1 (&-> v1-4 quad)) + (.mul.vf vf2 vf1 vf1 :mask #b111) + (let ((a0-5 f0-0)) + (.mov vf3 a0-5) + ) + ) + (.mul.x.vf acc vf0 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.z.vf vf2 vf0 vf2 acc :mask #b1000) + (.isqrt.vf Q vf3 vf2 :fsf #b0 :ftf #b11) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.svf (&-> v1-4 quad) vf1) + ) + (if (-> arg3 face-normal-needs-flip?) + (vector-float*! arg0 arg0 -1.0) + ) + (vector-float*! arg0 arg0 (-> this face-normal-scalar)) + arg0 + ) + ) + +;; WARN: Return type mismatch int vs rgba. +(defun light-vertex ((arg0 current-position-info) (arg1 vector)) + (local-vars (v0-0 uint128) (v0-1 uint128) (v0-2 uint128)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 lights direction 0 quad)) + (.lvf vf2 (&-> arg0 lights direction 1 quad)) + (.lvf vf3 (&-> arg0 lights direction 2 quad)) + (.lvf vf4 (&-> arg0 lights color 0 quad)) + (.lvf vf5 (&-> arg0 lights color 1 quad)) + (.lvf vf6 (&-> arg0 lights color 2 quad)) + (.lvf vf7 (&-> arg0 lights ambient quad)) + (.lvf vf10 (&-> (-> arg0 scale) quad)) + (.lvf vf11 (&-> (-> arg0 clamp-col) quad)) + (.lvf vf8 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf8) + (.add.mul.y.vf acc vf2 vf8 acc) + (.add.mul.z.vf vf8 vf3 vf8 acc) + (.max.x.vf vf8 vf8 vf0) + (.mul.w.vf acc vf7 vf0) + (.add.mul.x.vf acc vf4 vf8 acc) + (.add.mul.y.vf acc vf5 vf8 acc) + (.add.mul.z.vf vf9 vf6 vf8 acc) + (.mul.x.vf vf9 vf9 vf10) + (.min.vf vf9 vf9 vf11) + (.ftoi.vf vf9 vf9) + (.mov v0-0 vf9) + (.ppach v0-1 (the-as uint128 0) v0-0) + (.ppacb v0-2 (the-as uint128 0) v0-1) + (the-as rgba v0-2) + ) + ) + +(defmethod cloth-system-method-28 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info)) + (local-vars + (sv-16 verlet-particle) + (sv-80 vector) + (sv-84 vector) + (sv-88 vector) + (sv-92 symbol) + (sv-112 vector) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (set! sv-16 (-> this particles data (+ arg0 (* arg1 (-> this cloth-width))))) + (set! sv-80 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) + (* (- (-> arg2 current-vert-index) (the-as uint (-> arg2 cross-index0))) 32) + ) + ) + (the-as vector sv-16) + ) + ) + (set! sv-84 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) + (* (- (-> arg2 current-vert-index) (the-as uint (-> arg2 cross-index1))) 32) + ) + ) + (the-as vector sv-16) + ) + ) + (set! sv-88 (new 'stack-no-clear 'vector)) + (set! sv-92 (the-as symbol #f)) + (vector-cross! sv-88 sv-80 sv-84) + (let ((a0-10 (-> arg2 cross-index0))) + (set! (-> arg2 cross-index0) (-> arg2 cross-index1)) + (set! (-> arg2 cross-index1) a0-10) + ) + (let ((s2-0 sv-88) + (s0-0 sv-16) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! sv-112 s1-0) + (let ((v0-0 (math-camera-pos))) + (.lvf vf4 (&-> s0-0 pos quad)) + (.lvf vf5 (&-> v0-0 quad)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> sv-112 quad) vf6) + (let ((v1-12 (< 0.0 (vector-dot s1-0 s2-0)))) + (when (!= v1-12 (-> arg2 face-normal-needs-flip?)) + (set! (-> arg2 face-normal-needs-flip?) (not (-> arg2 face-normal-needs-flip?))) + (cloth-system-method-30 + this + (the-as int (-> arg2 last-2-x-index)) + (the-as int (-> arg2 last-2-y-index)) + arg2 + 1 + ) + (cloth-system-method-30 this (the-as int (-> arg2 last-x-index)) (the-as int (-> arg2 last-y-index)) arg2 1) + ) + ) + ) + (cloth-system-method-30 this arg0 arg1 arg2 0) + (none) + ) + ) + +(defmethod cloth-system-method-31 ((this cloth-system) (arg0 current-position-info)) + (let ((a0-1 (-> arg0 last-normal)) + (s5-0 (+ (-> arg0 current-vert-index) -1)) + ) + (let ((v1-1 (-> arg0 backside-normal))) + (vector+float*! + (the-as vector (+ (the-as uint (-> this strip2 data 0 pos)) (* s5-0 32))) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) (* s5-0 32))) + a0-1 + (-> this thickness-scalar) + ) + (set! (-> this strip2 data s5-0 col) (light-vertex arg0 v1-1)) + ) + (set! (-> this strip2 data s5-0 stq x) (-> this strip data s5-0 stq x)) + (set! (-> this strip2 data s5-0 stq y) (-> this strip data s5-0 stq y)) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch vector vs none. +(defmethod cloth-system-method-32 ((this cloth-system) (arg0 vector) (arg1 int) (arg2 int) (arg3 current-position-info)) + (cond + ((> (-> this mesh cloth-thickness length) 0) + (let ((v1-5 (+ arg1 (* arg2 (-> this cloth-width))))) + 0.0 + (let ((f0-4 (* -1.0 + (-> this mesh thickness-scalar) + (-> this face-normal-scalar) + (the float (-> this mesh cloth-thickness data v1-5)) + ) + ) + ) + (vector-float*! (-> arg3 backside-normal) arg0 -1.0) + (vector-float*! arg0 arg0 f0-4) + ) + ) + ) + (else + (vector-float*! (-> arg3 backside-normal) arg0 -1.0) + (vector-float*! arg0 arg0 (* 204.8 + (/ (the float arg2) (the float (+ (-> this cloth-height) -1))) + (-> this thickness-scalar) + (-> this face-normal-scalar) + ) + ) + ) + ) + (none) + ) + +;; WARN: Return type mismatch uint vs none. +(defmethod cloth-system-method-30 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info) (arg3 int)) + (let ((s1-0 (+ arg0 (* arg1 (-> this cloth-width))))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> arg2 current-vert-index) 32))) + ) + (-> this particles data s1-0 pos quad) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq z) (the-as float arg3)) + (let ((s0-0 (new 'stack-no-clear 'vector))) + (cloth-system-method-27 this s0-0 arg0 arg1 arg2) + (set! (-> this strip data (-> arg2 current-vert-index) col) (light-vertex arg2 s0-0)) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq x) (-> this mesh mesh s1-0 u)) + (set! (-> this strip data (-> arg2 current-vert-index) stq y) (-> this mesh mesh s1-0 v)) + ) + (when (zero? arg3) + (set! (-> arg2 last-2-x-index) (-> arg2 last-x-index)) + (set! (-> arg2 last-2-y-index) (-> arg2 last-y-index)) + (set! (-> arg2 last-x-index) (the-as uint arg0)) + (set! (-> arg2 last-y-index) (the-as uint arg1)) + ) + (+! (-> arg2 current-vert-index) 1) + (none) + ) + +(defmethod cloth-system-method-29 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info) (arg3 int)) + (let ((s2-0 (+ arg0 (* arg1 (-> this cloth-width))))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> arg2 current-vert-index) 32))) + ) + (-> this particles data s2-0 pos quad) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq z) (the-as float arg3)) + (let ((s1-0 (-> arg2 last-normal))) + (cloth-system-method-27 this s1-0 arg0 arg1 arg2) + (set! (-> this strip data (-> arg2 current-vert-index) col) (light-vertex arg2 s1-0)) + (set! (-> this strip data (-> arg2 current-vert-index) stq x) (-> this mesh mesh s2-0 u)) + (set! (-> this strip data (-> arg2 current-vert-index) stq y) (-> this mesh mesh s2-0 v)) + (cloth-system-method-32 this s1-0 arg0 arg1 arg2) + ) + ) + (let ((v0-3 (+ (-> arg2 current-vert-index) 1))) + (set! (-> arg2 current-vert-index) v0-3) + v0-3 + ) + ) + +(defmethod cloth-system-method-26 ((this cloth-system)) + (* (+ (-> this cloth-width) -1) (+ (-> this cloth-height) -1)) + (dotimes (v1-3 (+ (-> this cloth-height) -1)) + (dotimes (a1-2 (+ (-> this cloth-width) -1)) + (let* ((a2-0 a1-2) + (t1-0 (+ (* v1-3 (-> this cloth-width)) a2-0)) + (a2-1 (new 'stack-no-clear 'vector)) + (a3-2 (new 'stack-no-clear 'vector)) + (t0-4 (+ a1-2 (* v1-3 (+ (-> this cloth-width) -1)))) + ) + (vector-! + a2-1 + (the-as vector (-> this particles data t1-0)) + (the-as vector (-> this particles data (+ (-> this cloth-width) 1 t1-0))) + ) + (vector-! + a3-2 + (the-as vector (-> this particles data (+ t1-0 1))) + (the-as vector (-> this particles data (+ t1-0 (-> this cloth-width)))) + ) + (vector-cross! (-> *normal-array* t0-4) a2-1 a3-2) + ) + ) + ) + 0 + (none) + ) + +(defmethod cloth-system-method-33 ((this cloth-system) (lights vu-lights)) + (vu-lights<-light-group! lights (the-as light-group (-> *time-of-day-context* light-group))) + (none) + ) + +(defmethod cloth-system-method-33 ((this cloth-on-skeleton) (lights vu-lights)) + (let ((draw-ctrl (-> (the-as process-focusable (handle->process (-> this owner))) draw))) + (cond + ((logtest? (-> draw-ctrl global-effect) (draw-control-global-effect no-textures)) + (logclear! (-> this strip flags) (prim-flags texture-enable)) + (logclear! (-> this strip2 flags) (prim-flags texture-enable)) + (logclear! (-> this strip3 flags) (prim-flags texture-enable)) + ) + (else + (logior! (-> this strip flags) (prim-flags texture-enable)) + (logior! (-> this strip2 flags) (prim-flags texture-enable)) + (logior! (-> this strip3 flags) (prim-flags texture-enable)) + ) + ) + (calc-vu1-lights lights draw-ctrl #f) + ) + (none) + ) + +(defmethod cloth-system-method-25 ((this cloth-system)) + (local-vars (v0-1 texture-id) (v0-4 texture-id) (a0-72 int) (a0-74 int) (sv-224 int)) + (cond + ((and (not (logtest? (cloth-flag using-alt-tex) (-> this flags))) + (and (>= (-> *game-info* skill-total) 600.0) (-> this params alt-tex-name)) + ) + (logior! (-> this flags) (cloth-flag using-alt-tex)) + (set! (-> this strip tex-id) (lookup-texture-id-by-name (-> this params alt-tex-name) (the-as string #f))) + (set! v0-1 + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 tex-id) (lookup-texture-id-by-name (-> this params alt-tex-name2) (the-as string #f))) + (set! v0-1 (lookup-texture-id-by-name (-> this params alt-tex-name3) (the-as string #f))) + (set! (-> this strip3 tex-id) v0-1) + v0-1 + ) + ) + ) + ((and (logtest? (cloth-flag using-alt-tex) (-> this flags)) (< (-> *game-info* skill-total) 600.0)) + (logclear! (-> this flags) (cloth-flag using-alt-tex)) + (set! (-> this strip tex-id) (lookup-texture-id-by-name (-> this params tex-name) (the-as string #f))) + (set! v0-4 + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 tex-id) (lookup-texture-id-by-name (-> this params tex-name2) (the-as string #f))) + (set! v0-4 (lookup-texture-id-by-name (-> this params tex-name3) (the-as string #f))) + (set! (-> this strip3 tex-id) v0-4) + v0-4 + ) + ) + ) + ) + (when (logtest? (-> this flags) (cloth-flag no-draw)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (return 0) + ) + (set! (-> this strip adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip2 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip2 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip3 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip3 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip alpha) (new 'static 'gs-alpha)) + (set! (-> this strip2 alpha) (-> this strip alpha)) + (set! (-> this strip3 alpha) (-> this strip alpha)) + (set! (-> this strip clamp) (new 'static 'gs-clamp)) + (set! (-> this strip2 clamp) (new 'static 'gs-clamp)) + (set! (-> this strip3 clamp) (new 'static 'gs-clamp)) + (logior! (-> this strip flags) (prim-flags fog-enable)) + (logior! (-> this strip2 flags) (prim-flags fog-enable)) + (logior! (-> this strip3 flags) (prim-flags fog-enable)) + (cloth-system-method-26 this) + (let ((s5-0 (new 'stack-no-clear 'current-position-info))) + (let ((s4-0 0) + (s3-0 1) + (s2-0 1) + (s1-0 -1) + ) + (set! (-> s5-0 current-vert-index) (the-as uint 0)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (cloth-system-method-33 this (-> s5-0 lights)) + (set-vector! (-> s5-0 scale) 128.0 128.0 128.0 128.0) + (set-vector! (-> s5-0 clamp-col) 255.0 255.0 255.0 128.0) + (dotimes (s0-0 (+ (-> this cloth-height) -1)) + (set! sv-224 0) + (while (< sv-224 (-> this cloth-width)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (cloth-system-method-29 this s4-0 s3-0 s5-0 0) + (cloth-system-method-31 this s5-0) + (cloth-system-method-29 this s4-0 (+ s3-0 s1-0) s5-0 0) + (cloth-system-method-31 this s5-0) + (+! s4-0 s2-0) + (set! sv-224 (+ sv-224 1)) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq quad) + (-> this strip data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip2 data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip2 data (-> s5-0 current-vert-index) stq quad) + (-> this strip2 data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip2 data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (+! (-> s5-0 current-vert-index) 1) + (set! s2-0 (* -1 s2-0)) + (set! s1-0 (* -1 s1-0)) + (+! s4-0 s2-0) + (if (< s1-0 0) + (+! s3-0 2) + ) + ) + ) + (set! (-> this strip num-verts) (-> s5-0 current-vert-index)) + (set! (-> this strip2 num-verts) (-> s5-0 current-vert-index)) + ) + 0 + (let ((v1-110 0)) + (let ((a0-67 1)) + (dotimes (a1-27 (-> this cloth-width)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-67 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-67 stq quad)) + (let ((v1-111 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-111 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-67 32)))) + ) + (set! (-> this strip3 data v1-111 stq quad) (-> this strip2 data a0-67 stq quad)) + (set! v1-110 (+ v1-111 1)) + ) + (+! a0-67 2) + ) + ) + (let ((a0-71 (* (-> this cloth-width) 2))) + (dotimes (a1-28 (+ (-> this cloth-height) -1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-71 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-71 stq quad)) + (set! (-> this strip3 data v1-110 stq z) 0.0) + (let ((v1-112 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-112 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-71 32)))) + ) + (set! (-> this strip3 data v1-112 stq quad) (-> this strip2 data a0-71 stq quad)) + (set! (-> this strip3 data v1-112 stq z) 0.0) + (set! v1-110 (+ v1-112 1)) + ) + (if (= (logand a1-28 1) 1) + (+! a0-71 (* (-> this cloth-width) 4)) + (+! a0-71 2) + ) + ) + (let ((a1-31 -2)) + (cond + ((= (logand (-> this cloth-height) 1) 1) + (set! a0-72 (- a0-71 (* (-> this cloth-width) 4))) + (set! a1-31 (* -1 a1-31)) + ) + (else + (set! a0-72 (+ a0-71 a1-31 a1-31)) + ) + ) + (dotimes (a2-44 (-> this cloth-width)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-72 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-72 stq quad)) + (let ((v1-113 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-113 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-72 32)))) + ) + (set! (-> this strip3 data v1-113 stq quad) (-> this strip2 data a0-72 stq quad)) + (set! v1-110 (+ v1-113 1)) + ) + (+! a0-72 a1-31) + ) + ) + ) + (if (not (logtest? (-> this cloth-height) 1)) + (set! a0-74 (+ a0-72 2)) + (set! a0-74 (+ a0-72 -2 1)) + ) + (dotimes (a1-38 (+ (-> this cloth-height) -1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-74 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-74 stq quad)) + (set! (-> this strip3 data v1-110 stq z) 0.0) + (let ((v1-114 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-114 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-74 32)))) + ) + (set! (-> this strip3 data v1-114 stq quad) (-> this strip2 data a0-74 stq quad)) + (set! (-> this strip3 data v1-114 stq z) 0.0) + (set! v1-110 (+ v1-114 1)) + ) + (if (not (logtest? (- (-> this cloth-height) (+ a1-38 1)) 1)) + (set! a0-74 (- a0-74 (* (-> this cloth-width) 4))) + (+! a0-74 -2) + ) + ) + (set! (-> this strip3 num-verts) (the-as uint v1-110)) + ) + 0 + ) + +(defmethod post-physics-update ((this cloth-system)) + (when (logtest? (-> this flags) (cloth-flag no-draw)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (return 0) + ) + (if (logtest? (-> this flags) (cloth-flag double-sided)) + (cloth-system-method-25 this) + (cloth-system-method-24 this) + ) + ) + +(defmethod post-physics-update ((this cloth-on-skeleton)) + (let ((a1-0 (handle->process (-> this owner)))) + (if (and a1-0 (logtest? (-> (the-as process-focusable a1-0) draw status) (draw-control-status on-screen))) + (call-parent-method this) + ) + ) + ) + +(defmethod cloth-system-method-24 ((this cloth-system)) + (local-vars (sv-16 int) (sv-24 int) (sv-32 int) (sv-40 int)) + (cloth-system-method-26 this) + (set! sv-16 0) + (set! sv-24 1) + (set! sv-32 1) + (set! sv-40 -1) + (let ((s5-0 (new 'stack-no-clear 'current-position-info))) + (set! (-> s5-0 current-vert-index) (the-as uint 0)) + (set! (-> s5-0 last-x-index) (the-as uint -1)) + (set! (-> s5-0 last-y-index) (the-as uint -1)) + (set! (-> s5-0 last-2-x-index) (the-as uint -1)) + (set! (-> s5-0 last-2-y-index) (the-as uint -1)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (set-vector! (-> s5-0 scale) 128.0 128.0 128.0 128.0) + (set-vector! (-> s5-0 clamp-col) 255.0 255.0 255.0 128.0) + (vu-lights<-light-group! (-> s5-0 lights) (the-as light-group (-> *time-of-day-context* light-group))) + (dotimes (s4-0 (+ (-> this cloth-height) -1)) + (let* ((a0-17 (+ sv-16 (/ (+ sv-32 -1) 2) (* (+ sv-24 (/ (+ sv-40 -1) 2)) (+ (-> this cloth-width) -1)))) + (s3-0 (-> *normal-array* a0-17)) + (s1-0 (-> this particles data (+ sv-16 (* sv-24 (-> this cloth-width))))) + (s2-0 (new 'stack-no-clear 'vector)) + ) + (vector-! s2-0 (the-as vector s1-0) (math-camera-pos)) + (set! (-> s5-0 face-normal-needs-flip?) (< 0.0 (vector-dot s2-0 s3-0))) + ) + (cloth-system-method-30 this sv-16 sv-24 s5-0 0) + (cloth-system-method-30 this sv-16 (+ sv-24 sv-40) s5-0 0) + (set! (-> s5-0 cross-index0) 2) + (set! (-> s5-0 cross-index1) 1) + (set! sv-16 (+ sv-16 sv-32)) + (let ((s3-1 1) + (s2-1 (+ (-> this cloth-width) -1)) + ) + (while (>= s2-1 s3-1) + (cloth-system-method-28 this sv-16 sv-24 s5-0) + (cloth-system-method-28 this sv-16 (+ sv-24 sv-40) s5-0) + (set! sv-16 (+ sv-16 sv-32)) + (+! s3-1 1) + ) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq quad) + (-> this strip data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (+! (-> s5-0 current-vert-index) 1) + (set! sv-32 (* -1 sv-32)) + (set! sv-40 (* -1 sv-40)) + (set! sv-16 (+ sv-16 sv-32)) + (if (< sv-40 0) + (set! sv-24 (+ sv-24 2)) + ) + ) + (set! (-> this strip num-verts) (-> s5-0 current-vert-index)) + ) + 0 + ) + +;; WARN: Return type mismatch symbol vs none. +(defmethod reset-locations ((this cloth-on-skeleton)) + (let ((s5-0 (handle->process (-> this owner)))) + (when (nonzero? (-> this mesh anchor-transforms)) + (dotimes (s4-0 (-> this mesh anchor-transforms length)) + (set! (-> this anchor-points data s4-0 particle-index) + (the-as uint (-> this mesh anchor-transforms data s4-0 constraint-index)) + ) + (cond + (s5-0 + (let ((a2-0 + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh anchor-transforms data s4-0 joint) + bone + transform + ) + ) + ) + (vector-matrix*! + (the-as vector (-> this anchor-points data s4-0)) + (the-as vector (-> this mesh anchor-transforms data s4-0)) + a2-0 + ) + ) + (vector-float*! + (the-as vector (-> this anchor-points data s4-0)) + (the-as vector (-> this anchor-points data s4-0)) + (/ 1.0 (-> this anchor-points data s4-0 anchor-pos w)) + ) + (set! (-> this anchor-points data s4-0 anchor-pos w) 1.0) + ) + (else + (set! (-> this anchor-points data s4-0 anchor-pos quad) + (-> this mesh anchor-transforms data s4-0 offset quad) + ) + ) + ) + ) + ) + (when (nonzero? (-> this mesh sphere-transforms)) + (dotimes (s4-1 (-> this mesh sphere-transforms length)) + (cond + (s5-0 + (let ((s3-0 (new 'stack-no-clear 'vector))) + (set! (-> s3-0 quad) (-> this collision-constraints data s4-1 quad)) + (set! (-> s3-0 w) 1.0) + (vector-matrix*! + s3-0 + (the-as vector (-> this mesh sphere-transforms data s4-1)) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh sphere-transforms data s4-1 joint) + bone + transform + ) + ) + (vector-float*! s3-0 s3-0 (/ 1.0 (-> s3-0 w))) + (set! (-> this collision-constraints data s4-1 x) (-> s3-0 x)) + (set! (-> this collision-constraints data s4-1 y) (-> s3-0 y)) + (set! (-> this collision-constraints data s4-1 z) (-> s3-0 z)) + ) + ) + (else + (set! (-> this collision-constraints data s4-1 quad) (-> this mesh sphere-transforms data s4-1 offset quad)) + ) + ) + (set! (-> this collision-constraints data s4-1 r) (-> this mesh sphere-transforms data s4-1 radius)) + ) + ) + (when (nonzero? (-> this mesh disc-transforms)) + (dotimes (s4-2 (-> this mesh disc-transforms length)) + (cond + (s5-0 + (vector-matrix*! + (the-as vector (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s4-2))) + (the-as vector (-> this mesh disc-transforms data s4-2)) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh disc-transforms data s4-2 joint) + bone + transform + ) + ) + (vector-rotate*! + (the-as vector (-> this disc-collision-constraints data s4-2)) + (the-as vector (+ (the-as uint (-> this mesh disc-transforms data 0 normal)) (* 48 s4-2))) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh disc-transforms data s4-2 joint) + bone + transform + ) + ) + ) + (else + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s4-2))) + ) + (-> this mesh disc-transforms data s4-2 offset quad) + ) + (set! (-> this disc-collision-constraints data s4-2 normal quad) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this mesh disc-transforms data 0 normal)) (* 48 s4-2)))) + ) + ) + ) + (set! (-> this disc-collision-constraints data s4-2 radius) (-> this mesh disc-transforms data s4-2 radius)) + (set! (-> this disc-collision-constraints data s4-2 start-particle-index) + (-> this mesh disc-transforms data s4-2 start-particle-index) + ) + (set! (-> this disc-collision-constraints data s4-2 end-particle-index) + (-> this mesh disc-transforms data s4-2 end-particle-index) + ) + ) + ) + ) + (none) + ) + +(defmethod reset-locations ((this cloth-system)) + 0 + (none) + ) + +(define *once* #f) + +(defmethod debug-draw-spheres ((this cloth-system)) + (dotimes (s5-0 (-> this collision-constraints length)) + (add-debug-sphere + #t + (bucket-id debug) + (-> this collision-constraints data s5-0) + (-> this collision-constraints data s5-0 r) + *color-cyan* + ) + (format *stdcon* "Transform ~d, size ~f~%" s5-0 (* 0.00024414062 (-> this collision-constraints data s5-0 r))) + ) + (dotimes (s5-1 (-> this disc-collision-constraints length)) + (add-debug-sphere + #t + (bucket-id debug) + (the-as vector (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s5-1))) + (-> this disc-collision-constraints data s5-1 radius) + *color-red* + ) + ) + 0 + (none) + ) + +(define *cloth-fade-alpha* (new 'static 'gs-alpha :b #x1 :d #x1)) + +;; WARN: Return type mismatch symbol vs int. +(defmethod cloth-system-method-25 ((this cloth-on-skeleton)) + (call-parent-method this) + (let ((proc (handle->process (-> this owner)))) + (the-as int (when (and proc (nonzero? (-> (the-as process-drawable proc) draw))) + (let ((draw-ctrl (-> (the-as process-focusable proc) draw))) + (let ((fade (-> draw-ctrl force-fade))) + (when (logtest? (-> draw-ctrl status) (draw-control-status force-fade)) + (set! (-> this strip data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip alpha) *cloth-fade-alpha*) + (dotimes (a0-14 (the-as int (-> this strip num-verts))) + (set! (-> this strip data a0-14 col a) fade) + ) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip2 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip2 alpha) *cloth-fade-alpha*) + (set! (-> this strip3 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip3 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip3 alpha) *cloth-fade-alpha*) + (dotimes (a0-25 (the-as int (-> this strip2 num-verts))) + (set! (-> this strip2 data a0-25 col a) fade) + ) + (dotimes (a0-28 (the-as int (-> this strip3 num-verts))) + (set! (-> this strip3 data a0-28 col a) fade) + ) + #f + ) + ) + ) + ) + ) + ) + ) + ) + +(defmethod accumulate-external-forces! ((this cloth-on-skeleton)) + "If this cloth system has the wind flag, calculate the wind force." + (when (logtest? (-> this flags) (cloth-flag use-parent-momentum)) + (let ((proc (handle->process (-> this owner)))) + (if proc + (set! (-> this momentum quad) (-> (the-as process-drawable proc) root transv quad)) + ) + ) + ) + (call-parent-method this) + (none) + ) + +;; WARN: Return type mismatch int vs cloth-flag. +(defun symbol->cloth-flags ((arg0 symbol)) + (let ((v1-0 arg0)) + (the-as cloth-flag (cond + ((= v1-0 'local-space) + #x40000 + ) + ((= v1-0 'local-space-xyz) + #x80000 + ) + ((= v1-0 'local-space-y) + #x100000 + ) + ((= v1-0 'riding) + #x10000 + ) + (else + 0 + ) + ) + ) + ) + ) + +(defmethod cloth-system-cmd-handler ((this cloth-system) (command pair)) + (let ((msg (-> command car))) + (case msg + (('scene-reset-frame) + (if (logtest? (cloth-flag use-old-resets) (-> this flags)) + (logior! (-> this flags) (cloth-flag need-reset)) + (logior! (-> this flags) (cloth-flag local-space)) + ) + ) + (('set-flags 'clear-flags) + (let ((flags (cloth-flag))) + (let* ((s3-0 (-> command cdr)) + (a0-9 (-> (the-as pair s3-0) car)) + ) + (while (not (null? s3-0)) + (set! flags (logior (the-as cloth-flag flags) (symbol->cloth-flags (the-as symbol a0-9)))) + (set! s3-0 (-> (the-as pair s3-0) cdr)) + (set! a0-9 (-> (the-as pair s3-0) car)) + ) + ) + (if (= msg 'set-flags) + (logior! (-> this flags) flags) + (logclear! (-> this flags) flags) + ) + ) + ) + (('hide) + (hide! this) + ) + (('show) + (logclear! (-> this flags) (cloth-flag hidden)) + ) + (('wind-strength) + (set! (-> this wind-constant) (command-get-float (-> (the-as pair (-> command cdr)) car) 0.0)) + ) + (('reset) + (logior! (-> this flags) (cloth-flag need-reset)) + ) + ) + ) + 0 + (none) + ) diff --git a/goal_src/jak3/engine/process-drawable/process-drawable.gc b/goal_src/jak3/engine/process-drawable/process-drawable.gc index 64dde5508..af9c9cdc5 100644 --- a/goal_src/jak3/engine/process-drawable/process-drawable.gc +++ b/goal_src/jak3/engine/process-drawable/process-drawable.gc @@ -414,7 +414,7 @@ (let ((proc (handle->process (-> gp-0 s4-0)))) (when proc (dotimes (i (-> (the-as process-drawable proc) draw cloth-instances length)) - (init! (-> (the-as process-drawable proc) draw cloth-instances i)) + (update! (-> (the-as process-drawable proc) draw cloth-instances i)) ) ) ) @@ -919,7 +919,7 @@ (set! (-> this draw cloth-instances length) (-> this draw cloth-instances allocated-length)) (dotimes (s4-4 (-> arg0 clothing length)) (set! (-> this draw cloth-instances s4-4) (new 'process 'cloth-on-skeleton)) - (cloth-base-method-10 (-> this draw cloth-instances s4-4) (-> arg0 clothing s4-4) (process->handle this)) + (setup-from-params! (-> this draw cloth-instances s4-4) (-> arg0 clothing s4-4) (process->handle this)) ) ) (logior! (-> this draw global-effect) (-> arg0 global-effects)) @@ -2273,7 +2273,7 @@ ) (dotimes (i (-> proc draw cloth-instances length)) (if (not arg1) - (cloth-system-method-34 (-> proc draw cloth-instances i)) + (hide! (-> proc draw cloth-instances i)) (logclear! (-> proc draw cloth-instances i flags) (cloth-flag hidden)) ) ) diff --git a/goal_src/jak3/engine/target/target-death.gc b/goal_src/jak3/engine/target/target-death.gc index 2edde8d10..944b8253a 100644 --- a/goal_src/jak3/engine/target/target-death.gc +++ b/goal_src/jak3/engine/target/target-death.gc @@ -424,7 +424,7 @@ (case (-> self ext-geo) (((target-geo jakc)) (dotimes (s5-1 (-> gp-1 clothing length)) - (cloth-base-method-10 (-> self draw cloth-instances s5-1) (-> gp-1 clothing s5-1) (process->handle self)) + (setup-from-params! (-> self draw cloth-instances s5-1) (-> gp-1 clothing s5-1) (process->handle self)) (logior! (-> self draw cloth-instances s5-1 flags) (cloth-flag need-reset active)) ) ) diff --git a/test/decompiler/reference/jak3/engine/common-obs/cloth-art-h_REF.gc b/test/decompiler/reference/jak3/engine/common-obs/cloth-art-h_REF.gc index 3a2047652..626fcf137 100644 --- a/test/decompiler/reference/jak3/engine/common-obs/cloth-art-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/common-obs/cloth-art-h_REF.gc @@ -255,8 +255,8 @@ (deftype cloth-base (basic) () (:methods - (init! (_type_) int) - (cloth-base-method-10 (_type_ cloth-params handle) int) + (update! (_type_) int) + (setup-from-params! (_type_ cloth-params handle) int) ) ) @@ -273,7 +273,3 @@ ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/physics/cloth-h_REF.gc b/test/decompiler/reference/jak3/engine/physics/cloth-h_REF.gc index 56eb88552..dab5be395 100644 --- a/test/decompiler/reference/jak3/engine/physics/cloth-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/physics/cloth-h_REF.gc @@ -291,10 +291,10 @@ (momentum vector :inline) ) (:methods - (calculate-wind! (_type_) none) - (verlet-particle-system-method-12 (_type_ float) none) - (verlet-particle-system-method-13 (_type_) none) - (verlet-particle-system-method-14 (_type_) none) + (accumulate-external-forces! (_type_) none) + (compute-verlet-step (_type_ float) none) + (run-one-iteration (_type_) none) + (reset! (_type_) none) (debug-draw (_type_) none) ) ) @@ -388,9 +388,9 @@ (:methods (initialize-cloth-system! (_type_ cloth-params) none) (debug-draw-spheres (_type_) none) - (cloth-system-method-18 (_type_) int) - (cloth-system-method-19 (_type_) none) - (cloth-system-method-20 (_type_) none) + (post-physics-update (_type_) int) + (enforce-constraints-1 (_type_) none) + (enforce-constraints-2 (_type_) none) (cloth-system-method-21 (_type_) none) (cloth-system-method-22 (_type_) none) (cloth-system-method-23 (_type_) none) @@ -404,9 +404,9 @@ (cloth-system-method-31 (_type_ current-position-info) none) (cloth-system-method-32 (_type_ vector int int current-position-info) none) (cloth-system-method-33 (_type_ vu-lights) none) - (cloth-system-method-34 (_type_) none) - (cloth-system-method-35 (_type_) none) - (cloth-system-method-36 (_type_) none) + (hide! (_type_) none) + (reset-locations (_type_) none) + (pre-physics-update (_type_) none) (cloth-system-cmd-handler (_type_ pair) none) ) ) diff --git a/test/decompiler/reference/jak3/engine/physics/cloth_REF.gc b/test/decompiler/reference/jak3/engine/physics/cloth_REF.gc new file mode 100644 index 000000000..483b87b02 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/physics/cloth_REF.gc @@ -0,0 +1,2284 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 7 of type verlet-particle-system +(defmethod relocate ((this verlet-particle-system) (offset int)) + (if (nonzero? (-> this particles)) + (&+! (-> this particles) offset) + ) + (call-parent-method this offset) + ) + +;; definition for method 8 of type art-cloth-geo +(defmethod mem-usage ((this art-cloth-geo) (usage memory-usage-block) (flags int)) + (set! (-> usage length) (max 77 (-> usage length))) + (set! (-> usage data 76 name) "art-cloth-geo") + (+! (-> usage data 76 count) 1) + (let ((v1-6 (asize-of this))) + (+! (-> usage data 76 used) v1-6) + (+! (-> usage data 76 total) (logand -16 (+ v1-6 15))) + ) + this + ) + +;; definition for method 5 of type art-cloth-geo +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of ((this art-cloth-geo)) + (the-as int (+ (-> this type size) + (* (-> this length) 32) + (asize-of (-> this sphere-transforms)) + (asize-of (-> this disc-transforms)) + (asize-of (-> this anchor-transforms)) + ) + ) + ) + +;; definition for method 14 of type verlet-particle-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod reset! ((this verlet-particle-system)) + "Reset to stationary/default state." + (set! (-> this accum-force quad) (the-as uint128 0)) + (dotimes (v1-1 (-> this particles length)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 v1-1)))) + (-> this particles data v1-1 pos quad) + ) + ) + 0 + (none) + ) + +;; definition for method 14 of type cloth-system +(defmethod reset! ((this cloth-system)) + "Reset to stationary/default state." + (reset-locations this) + (when (> (-> this anchor-points length) 0) + (let ((v1-6 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (-> this anchor-points data)) + (the-as vector (-> this particles data (-> this anchor-points data 0 particle-index))) + ) + ) + ) + (dotimes (a0-4 (-> this particles length)) + (vector+! (the-as vector (-> this particles data a0-4)) (the-as vector (-> this particles data a0-4)) v1-6) + ) + ) + ) + (dotimes (s5-0 1) + (run-one-iteration this) + ) + (call-parent-method this) + (none) + ) + +;; definition for method 36 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod pre-physics-update ((this cloth-system)) + "Callback to update prior to running verlet integration. Can handle movement of the entire system in the world, for example" + 0 + (none) + ) + +;; definition for method 36 of type cloth-on-skeleton +;; INFO: Used lq/sq +;; WARN: Return type mismatch cloth-flag vs none. +(defmethod pre-physics-update ((this cloth-on-skeleton)) + "Callback to update prior to running verlet integration. Can handle movement of the entire system in the world, for example" + (let ((s5-0 (new 'stack-no-clear 'matrix)) + (s4-0 (handle->process (-> this owner))) + ) + (when s4-0 + (cond + ((< -1 (-> this base-transform-index)) + (let* ((v1-4 s5-0) + (a3-0 (-> (the-as process-focusable s4-0) node-list data (-> this base-transform-index) bone transform)) + (a0-8 (-> a3-0 rvec quad)) + (a1-3 (-> a3-0 uvec quad)) + (a2-0 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> v1-4 rvec quad) a0-8) + (set! (-> v1-4 uvec quad) a1-3) + (set! (-> v1-4 fvec quad) a2-0) + (set! (-> v1-4 trans quad) a3-1) + ) + ) + (else + (quaternion->matrix s5-0 (-> (the-as process-focusable s4-0) root quat)) + (set! (-> s5-0 trans quad) (-> (the-as process-focusable s4-0) root trans quad)) + ) + ) + (vector-normalize! (-> s5-0 fvec) 1.0) + (vector-normalize! (-> s5-0 uvec) 1.0) + (vector-normalize! (-> s5-0 rvec) 1.0) + (vector-float*! (-> s5-0 trans) (-> s5-0 trans) (/ 1.0 (-> s5-0 trans w))) + (set! (-> s5-0 trans w) 1.0) + (when (logtest? (cloth-flag local-space local-space-xyz local-space-y) (-> this flags)) + (let ((s4-1 (matrix-identity! (new 'stack-no-clear 'matrix)))) + (if (logtest? (cloth-flag local-space-y) (-> this flags)) + (set! (-> s4-1 trans y) (- (-> s5-0 trans y) (-> this last-owner-mat trans y))) + (vector-! (-> s4-1 trans) (-> s5-0 trans) (-> this last-owner-mat trans)) + ) + (when (logtest? (cloth-flag local-space) (-> this flags)) + (let ((s3-0 (matrix-identity! (new 'stack-no-clear 'matrix)))) + (vector-float*! (-> s3-0 trans) (-> s5-0 trans) -1.0) + (matrix*! s4-1 s4-1 s3-0) + (matrix-4x4-inverse! s3-0 (-> this last-owner-mat)) + (matrix*! s3-0 s3-0 s5-0) + (set! (-> s3-0 trans quad) (the-as uint128 0)) + (set! (-> s3-0 trans w) 1.0) + (matrix*! s4-1 s4-1 s3-0) + (matrix-identity! s3-0) + (set! (-> s3-0 trans quad) (-> s5-0 trans quad)) + (matrix*! s4-1 s4-1 s3-0) + ) + ) + (dotimes (s3-1 (-> this particles length)) + (set! (-> this particles data s3-1 pos w) 1.0) + (vector-matrix*! + (the-as vector (-> this particles data s3-1)) + (the-as vector (-> this particles data s3-1)) + s4-1 + ) + (set! (-> this particles data s3-1 pos w) 1.0) + (set! (-> this particles data s3-1 prev-pos w) 1.0) + (vector-matrix*! + (the-as vector (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 s3-1))) + (the-as vector (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 s3-1))) + s4-1 + ) + (set! (-> this particles data s3-1 prev-pos w) 1.0) + ) + ) + ) + (let ((a2-7 (-> this last-owner-mat)) + (v1-54 (-> s5-0 rvec quad)) + (a0-42 (-> s5-0 uvec quad)) + (a1-23 (-> s5-0 fvec quad)) + (a3-2 (-> s5-0 trans quad)) + ) + (set! (-> a2-7 rvec quad) v1-54) + (set! (-> a2-7 uvec quad) a0-42) + (set! (-> a2-7 fvec quad) a1-23) + (set! (-> a2-7 trans quad) a3-2) + ) + (logclear! (-> this flags) (cloth-flag local-space local-space-xyz local-space-y)) + ) + ) + (none) + ) + +;; definition for method 14 of type cloth-on-skeleton +;; INFO: Used lq/sq +;; WARN: Return type mismatch symbol vs none. +(defmethod reset! ((this cloth-on-skeleton)) + "Reset to stationary/default state." + (let ((s5-0 (new 'stack-no-clear 'matrix)) + (s4-0 (handle->process (-> this owner))) + ) + (when s4-0 + (cond + ((< -1 (-> this base-transform-index)) + (let* ((v1-5 s5-0) + (a3-0 (-> (the-as process-focusable s4-0) node-list data (-> this base-transform-index) bone transform)) + (a0-8 (-> a3-0 rvec quad)) + (a1-3 (-> a3-0 uvec quad)) + (a2-0 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> v1-5 rvec quad) a0-8) + (set! (-> v1-5 uvec quad) a1-3) + (set! (-> v1-5 fvec quad) a2-0) + (set! (-> v1-5 trans quad) a3-1) + ) + ) + (else + (quaternion->matrix s5-0 (-> (the-as process-focusable s4-0) root quat)) + (set! (-> s5-0 trans quad) (-> (the-as process-focusable s4-0) root trans quad)) + ) + ) + (dotimes (s4-1 (-> this particles length)) + (vector-matrix*! (the-as vector (-> this particles data s4-1)) (the-as vector (-> this mesh mesh s4-1)) s5-0) + (vector-float*! + (the-as vector (-> this particles data s4-1)) + (the-as vector (-> this particles data s4-1)) + (/ 1.0 (-> this particles data s4-1 pos w)) + ) + (set! (-> this particles data s4-1 pos w) 1.0) + ) + (let ((v1-24 0) + (a0-24 (+ (-> this particles length) -1)) + ) + (while (>= a0-24 v1-24) + (+! v1-24 1) + ) + ) + (let ((a0-25 (-> s5-0 trans))) + (set! (-> this last-owner-pos quad) (-> a0-25 quad)) + ) + ) + ) + (set! (-> this accum-force quad) (the-as uint128 0)) + (dotimes (v1-29 (-> this particles length)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this particles data 0 prev-pos)) (* 48 v1-29)))) + (-> this particles data v1-29 pos quad) + ) + ) + (none) + ) + +;; definition for method 7 of type cloth-system +(defmethod relocate ((this cloth-system) (offset int)) + (if (nonzero? (-> this stick-constraints)) + (&+! (-> this stick-constraints) offset) + ) + (if (nonzero? (-> this disc-collision-constraints)) + (&+! (-> this disc-collision-constraints) offset) + ) + (if (nonzero? (-> this collision-constraints)) + (&+! (-> this collision-constraints) offset) + ) + (if (nonzero? (-> this anchor-points)) + (&+! (-> this anchor-points) offset) + ) + (if (nonzero? (-> this strip)) + (&+! (-> this strip) offset) + ) + (if (nonzero? (-> this strip2)) + (&+! (-> this strip2) offset) + ) + (if (nonzero? (-> this strip3)) + (&+! (-> this strip3) offset) + ) + (call-parent-method this offset) + ) + +;; definition for method 7 of type cloth-on-skeleton +(defmethod relocate ((this cloth-on-skeleton) (offset int)) + (call-parent-method this offset) + ) + +;; definition for method 15 of type verlet-particle-system +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw ((this verlet-particle-system)) + (dotimes (s5-0 (-> this particles length)) + (let ((s4-0 add-debug-text-3d) + (s3-0 #t) + (s2-0 583) + ) + (format (clear *temp-string*) "~d" s5-0) + (s4-0 + s3-0 + (the-as bucket-id s2-0) + *temp-string* + (the-as vector (-> this particles data s5-0)) + (font-color red) + (the-as vector2h #f) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 15 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw ((this cloth-system)) + (dotimes (s5-0 (-> this particles length)) + (let* ((a0-1 (/ s5-0 (-> this cloth-width))) + (v1-2 (mod s5-0 (-> this cloth-width))) + (s1-0 (cond + ((not (logtest? a0-1 1)) + (if (or (< v1-2 (/ (-> this cloth-width) 4)) (>= v1-2 (/ (* 3 (-> this cloth-width)) 4))) + 3 + 4 + ) + ) + ((or (< v1-2 (/ (-> this cloth-width) 4)) (>= v1-2 (/ (* 3 (-> this cloth-width)) 4))) + 7 + ) + (else + 6 + ) + ) + ) + (s4-0 add-debug-text-3d) + (s3-0 #t) + (s2-0 583) + ) + (format (clear *temp-string*) "~d" s5-0) + (s4-0 + s3-0 + (the-as bucket-id s2-0) + *temp-string* + (the-as vector (-> this particles data s5-0)) + (the-as font-color s1-0) + (the-as vector2h #f) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 16 of type cloth-system +;; INFO: Used lq/sq +;; WARN: Stack slot offset 24 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 24 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 24 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 24 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 28 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 20 signed mismatch +;; WARN: Return type mismatch int vs none. +(defmethod initialize-cloth-system! ((this cloth-system) (arg0 cloth-params)) + "Set up this cloth system with the given [[cloth-params]]." + (local-vars (sv-16 int) (sv-20 int) (sv-24 int) (sv-28 int)) + (if (or (zero? (-> this mesh)) (< (-> this mesh length) 4)) + (go process-drawable-art-error "cloth-mesh (art-cloth-geo)") + ) + (set! (-> this params) arg0) + (set! (-> this cloth-width) (the-as int (-> arg0 cloth-width))) + (set! (-> this cloth-height) (/ (the-as int (-> this mesh length)) (-> this cloth-width))) + (set! (-> this drag) (-> arg0 drag)) + (set! (-> this collision-constraints) + (new 'process 'collision-sphere-array (the-as int (-> arg0 num-sphere-constraints))) + ) + (set! (-> this disc-collision-constraints) + (new 'process 'collision-disc-array (the-as int (-> arg0 num-disc-constraints))) + ) + (set! (-> this anchor-points) (new 'process 'anchor-point-array (the-as int (-> arg0 num-anchor-points)))) + (set! (-> this wind-constant) (-> arg0 wind-constant)) + (set! (-> this gravity-constant) (-> arg0 gravity-constant)) + (set! (-> this thickness-scalar) (-> arg0 cloth-thickness)) + (set! (-> this flags) (-> arg0 flags)) + (set! (-> this timestep-frequency) (-> arg0 timestep-frequency)) + (set! (-> this secret-disable) (-> arg0 secret-disable)) + (when (<= (-> this mesh cloth-thickness length) 0) + ) + (if (logtest? (-> this flags) (cloth-flag flip-normals)) + (set! (-> this face-normal-scalar) -1.0) + (set! (-> this face-normal-scalar) 1.0) + ) + (set! (-> this particles) (new 'process 'particle-array (* (-> this cloth-width) (-> this cloth-height)))) + (if (not (and (nonzero? (-> this collision-constraints)) (and (nonzero? (-> this disc-collision-constraints)) + (nonzero? (-> this anchor-points)) + (nonzero? (-> this particles)) + ) + ) + ) + (go process-drawable-art-error "cloth-memory") + ) + (dotimes (v1-38 (-> this particles length)) + (set! (-> this particles data v1-38 pos quad) (-> this mesh mesh v1-38 pt quad)) + (set! (-> this particles data v1-38 mass-scale) 1.0) + ) + (set! sv-16 (* (+ (-> this cloth-width) -1) (-> this cloth-height))) + (set! sv-20 (* (+ (-> this cloth-height) -1) (-> this cloth-width))) + (set! sv-24 (+ (* (+ (-> this cloth-width) -2) 2) 2)) + (let ((v1-52 (* sv-24 (+ (-> this cloth-height) -1))) + (s4-0 (* (+ (-> this cloth-width) -2) (-> this cloth-height))) + ) + (set! sv-28 (+ s4-0 (* (-> this cloth-width) (+ (-> this cloth-height) -2)))) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (+! s4-0 (* (-> this cloth-height) 2)) + (set! sv-28 (+ sv-28 (* (-> this cloth-height) 2))) + ) + (set! sv-28 (max 0 sv-28)) + (let ((s3-1 (max 0 v1-52))) + (set! (-> this num-xy-constraints) (+ sv-16 sv-20)) + (set! (-> this num-diagonal-constraints) s3-1) + (if (zero? (-> this stick-constraints)) + (set! (-> this stick-constraints) (new 'process 'stick-constraint-array (+ sv-16 sv-20 s3-1 sv-28))) + ) + (let ((v1-62 0)) + (dotimes (a0-37 (-> this cloth-height)) + (dotimes (a1-20 (+ (-> this cloth-width) -1)) + (let ((a2-11 (+ a1-20 (* a0-37 (-> this cloth-width)))) + (a3-2 (-> this stick-constraints data v1-62)) + ) + (set! (-> a3-2 particle0) (the-as uint a2-11)) + (set! (-> a3-2 particle1) (the-as uint (+ a2-11 1))) + ) + (+! v1-62 1) + ) + ) + ) + (let ((v1-65 sv-16)) + (dotimes (a0-38 (+ (-> this cloth-height) -1)) + (dotimes (a1-24 (-> this cloth-width)) + (let ((a2-18 (+ a1-24 (* a0-38 (-> this cloth-width)))) + (a3-5 (-> this stick-constraints data v1-65)) + ) + (set! (-> a3-5 particle0) (the-as uint a2-18)) + (set! (-> a3-5 particle1) (the-as uint (+ a2-18 (-> this cloth-width)))) + ) + (+! v1-65 1) + ) + ) + ) + (let ((v1-69 (+ sv-16 sv-20))) + (dotimes (a0-40 (+ (-> this cloth-height) -1)) + (dotimes (a1-29 (-> this cloth-width)) + (let ((a2-24 (+ a1-29 (* a0-40 (-> this cloth-width)))) + (a3-8 (-> this stick-constraints data v1-69)) + ) + (when (< a1-29 (+ (-> this cloth-width) -1)) + (set! (-> a3-8 particle0) (the-as uint a2-24)) + (set! (-> a3-8 particle1) (the-as uint (+ (-> this cloth-width) 1 a2-24))) + (+! v1-69 1) + (set! a3-8 (-> this stick-constraints data v1-69)) + ) + (when (> a1-29 0) + (set! (-> a3-8 particle0) (the-as uint a2-24)) + (set! (-> a3-8 particle1) (the-as uint (+ (-> this cloth-width) -1 a2-24))) + (+! v1-69 1) + (-> this stick-constraints data v1-69) + ) + ) + ) + ) + ) + (let ((v1-74 (+ sv-16 sv-20 s3-1))) + (dotimes (a0-42 (-> this cloth-height)) + (dotimes (a1-34 (+ (-> this cloth-width) -2)) + (let ((a2-31 (+ a1-34 (* a0-42 (-> this cloth-width)))) + (a3-14 (-> this stick-constraints data v1-74)) + ) + (set! (-> a3-14 particle0) (the-as uint a2-31)) + (set! (-> a3-14 particle1) (the-as uint (+ a2-31 2))) + ) + (+! v1-74 1) + ) + ) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (dotimes (a0-48 (-> this cloth-height)) + (let ((a1-40 (+ (* (+ a0-48 1) (-> this cloth-width)) -3)) + (a2-38 (* a0-48 (-> this cloth-width))) + (a3-17 (-> this stick-constraints data v1-74)) + ) + (set! (-> a3-17 particle0) (the-as uint a1-40)) + (set! (-> a3-17 particle1) (the-as uint a2-38)) + ) + (let ((v1-75 (+ v1-74 1))) + (-> this stick-constraints data v1-75) + (let ((a1-46 (+ (* (+ a0-48 1) (-> this cloth-width)) -2)) + (a2-43 (+ (* a0-48 (-> this cloth-width)) 1)) + (a3-20 (-> this stick-constraints data v1-75)) + ) + (set! (-> a3-20 particle0) (the-as uint a1-46)) + (set! (-> a3-20 particle1) (the-as uint a2-43)) + ) + (set! v1-74 (+ v1-75 1)) + ) + (-> this stick-constraints data v1-74) + ) + ) + ) + (let ((v1-80 (+ sv-16 sv-20 s3-1 s4-0))) + (dotimes (a0-51 (+ (-> this cloth-height) -2)) + (dotimes (a1-51 (-> this cloth-width)) + (let ((a2-47 (+ a1-51 (* a0-51 (-> this cloth-width)))) + (a3-23 (-> this stick-constraints data v1-80)) + ) + (set! (-> a3-23 particle0) (the-as uint a2-47)) + (set! (-> a3-23 particle1) (the-as uint (+ a2-47 (* (-> this cloth-width) 2)))) + ) + (+! v1-80 1) + ) + ) + ) + ) + ) + (let ((s4-1 (* (if (logtest? (-> this flags) (cloth-flag double-sided)) + (+ (* (-> this cloth-width) 2) 1) + (+ (* 3 (+ (-> this cloth-width) -2)) 6) + ) + (+ (-> this cloth-height) -1) + ) + ) + ) + (if (zero? (-> this strip)) + (set! (-> this strip) + (new 'process 'prim-strip s4-1 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name)) + ) + ) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (when (zero? (-> this strip2)) + (set! (-> this strip2) + (new 'process 'prim-strip s4-1 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name2)) + ) + (set! (-> this strip2 num-verts) (the-as uint 0)) + 0 + ) + (when (zero? (-> this strip3)) + (let ((a2-53 (* (+ (* (-> this cloth-width) 2) (* (-> this cloth-height) 2)) 2))) + (set! (-> this strip3) + (new 'process 'prim-strip a2-53 (new 'static 'texture-id :index #x3 :page #x1) (-> arg0 tex-name3)) + ) + ) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + ) + ) + (set! (-> this strip num-verts) (the-as uint 0)) + 0 + (when (logtest? (-> this flags) (cloth-flag autogen-uvs)) + (dotimes (v1-115 (-> this particles length)) + (let ((a1-59 (mod v1-115 (-> this cloth-width))) + (a0-63 (/ v1-115 (-> this cloth-width))) + ) + (set! (-> this mesh mesh v1-115 u) (/ (the float a1-59) (the float (+ (-> this cloth-width) -1)))) + (set! (-> this mesh mesh v1-115 v) (- 1.0 (/ (the float a0-63) (the float (+ (-> this cloth-height) -1))))) + ) + (set! (-> this mesh mesh v1-115 v) (fmax 0.0 (fmin 1.0 (-> this mesh mesh v1-115 v)))) + ) + (dotimes (v1-118 (-> this cloth-width)) + (+ (-> this cloth-height) -1) + (set! (-> this mesh mesh v1-118 v) 0.99) + ) + ) + (logior! (-> this flags) (cloth-flag need-reset need-setup)) + (logior! (-> this flags) (cloth-flag active inited)) + (set! (-> this reset-count) 1) + 0 + (none) + ) + +;; definition for method 10 of type cloth-on-skeleton +(defmethod setup-from-params! ((this cloth-on-skeleton) (arg0 cloth-params) (arg1 handle)) + (if (logtest? (-> this flags) (cloth-flag inited)) + (return 0) + ) + (set! (-> this owner) arg1) + (set! (-> this num-iterations) (-> arg0 num-iterations)) + (let ((s4-0 (handle->process (-> this owner)))) + (when (and s4-0 (< -1 (-> arg0 mesh))) + (set! (-> this mesh) + (the-as art-cloth-geo (-> (the-as process-focusable s4-0) draw art-group data (-> arg0 mesh))) + ) + (when (or (not (-> this mesh)) (!= (-> this mesh type) art-cloth-geo)) + (if (logtest? (-> arg0 flags) (cloth-flag suppress-mesh-failure)) + (return 0) + (go process-drawable-art-error "cloth-mesh (art-cloth-geo)") + ) + ) + (set! (-> this base-transform-index) (-> arg0 initial-xform)) + (set! (-> arg0 num-anchor-points) + (the-as uint (max (-> this mesh anchor-transforms length) (the-as int (-> arg0 num-anchor-points)))) + ) + (set! (-> arg0 num-sphere-constraints) + (the-as uint (max (-> this mesh sphere-transforms length) (the-as int (-> arg0 num-sphere-constraints)))) + ) + (set! (-> arg0 num-disc-constraints) + (the-as uint (max (-> this mesh disc-transforms length) (the-as int (-> arg0 num-disc-constraints)))) + ) + (set! (-> this ball-collision-radius) (-> arg0 ball-collision-radius)) + (set! (-> this ball-collision-radius) (-> this ball-collision-radius)) + (dotimes (s3-0 (-> this mesh anchor-transforms length)) + (let ((s2-0 (-> this mesh anchor-transforms data s3-0))) + (when (< (-> s2-0 joint) 0) + (let ((v1-47 + (the-as + joint + (get-art-by-name-method (-> (the-as process-focusable s4-0) draw jgeo) (-> s2-0 joint-name) (the-as type #f)) + ) + ) + ) + (set! (-> s2-0 joint) (if v1-47 + (+ (-> v1-47 number) 1) + 0 + ) + ) + ) + ) + ) + ) + (dotimes (s3-1 (-> this mesh sphere-transforms length)) + (let ((s2-1 (-> this mesh sphere-transforms data s3-1))) + (when (< (-> s2-1 joint) 0) + (let ((v1-61 + (the-as + joint + (get-art-by-name-method (-> (the-as process-focusable s4-0) draw jgeo) (-> s2-1 joint-name) (the-as type #f)) + ) + ) + ) + (set! (-> s2-1 joint) (if v1-61 + (+ (-> v1-61 number) 1) + 0 + ) + ) + ) + ) + ) + ) + (dotimes (s3-2 (-> this mesh disc-transforms length)) + (let ((s2-2 (-> this mesh disc-transforms data s3-2))) + (when (< (-> s2-2 joint) 0) + (let ((v1-76 (the-as joint (get-art-by-name-method + (-> (the-as process-focusable s4-0) draw jgeo) + (the-as string (-> s2-2 joint-name)) + (the-as type #f) + ) + ) + ) + ) + (set! (-> s2-2 joint) (if v1-76 + (+ (-> v1-76 number) 1) + 0 + ) + ) + ) + ) + ) + ) + ) + ) + (initialize-cloth-system! this arg0) + 0 + ) + +;; definition for method 13 of type verlet-particle-system +;; WARN: Return type mismatch int vs none. +(defmethod run-one-iteration ((this verlet-particle-system)) + "Run one iteration of the system." + 0 + (none) + ) + +;; definition for method 9 of type verlet-particle-system +(defmethod update! ((this verlet-particle-system)) + (with-pp + (accumulate-external-forces! this) + (let ((v1-4 (- (current-time) (-> pp clock old-frame-counter)))) + (if (> (-> this timestep-frequency) 0) + (compute-verlet-step this (* 0.0033333334 (the float (-> this timestep-frequency)))) + (compute-verlet-step this (* 0.0033333334 (the float v1-4))) + ) + ) + 0 + ) + ) + +;; definition for method 9 of type cloth-system +(defmethod update! ((this cloth-system)) + (if (not (logtest? (-> this flags) (cloth-flag active))) + (return 0) + ) + (when (logtest? (-> this flags) (cloth-flag need-setup)) + (cond + ((or (> (-> this reset-count) 0) (logtest? (-> this flags) (cloth-flag no-draw))) + (reset! this) + (+! (-> this reset-count) -1) + (set! (-> this reset-count) (max 0 (-> this reset-count))) + ) + (else + (reset! this) + (logclear! (-> this flags) (cloth-flag need-setup)) + (dotimes (s5-0 (-> this stick-constraints length)) + (let ((s4-0 (-> this stick-constraints data s5-0))) + 0.0 + (let ((f0-1 (vector-vector-distance + (the-as vector (-> this particles data (-> s4-0 particle0))) + (the-as vector (-> this particles data (-> s4-0 particle1))) + ) + ) + ) + (set! (-> s4-0 one-over-two-times-constraint-length) (/ 1.0 (* 2.0 f0-1))) + (set! (-> s4-0 constraint-length-sqd) (* f0-1 f0-1)) + (set! (-> s4-0 constraint-length-half) (* 0.5 f0-1)) + ) + ) + ) + ) + ) + ) + (when (and (logtest? (-> this flags) (cloth-flag need-reset)) + (not (logtest? (-> this flags) (cloth-flag need-setup))) + ) + (reset! this) + (if (> (-> this reset-count) 0) + (+! (-> this reset-count) -1) + (logclear! (-> this flags) (cloth-flag need-reset)) + ) + ) + (pre-physics-update this) + (call-parent-method this) + (reset-locations this) + (let ((s5-1 (-> this num-iterations))) + (if (logtest? (cloth-flag riding) (-> this flags)) + (+! s5-1 1) + ) + (dotimes (s4-1 s5-1) + (run-one-iteration this) + ) + ) + (when (and (> (the-as uint (-> this secret-disable)) 0) + (> (the-as uint (logand (-> *game-info* secrets) (-> this secret-disable))) 0) + ) + (hide! this) + (return 0) + ) + (post-physics-update this) + 0 + ) + +;; definition for method 9 of type cloth-on-skeleton +;; INFO: Used lq/sq +(defmethod update! ((this cloth-on-skeleton)) + (if (not (logtest? (cloth-flag hidden) (-> this flags))) + (logclear! (-> this flags) (cloth-flag no-draw)) + ) + (when (and (handle->process (-> this owner)) (= (-> (handle->process (-> this owner)) type) target)) + (let* ((s5-0 (handle->process (-> this owner))) + (a0-16 (if (type? s5-0 process-focusable) + s5-0 + ) + ) + ) + (when (and a0-16 (focus-test? (the-as process-focusable a0-16) teleporting)) + (set! (-> this reset-count) 1) + (logior! (-> this flags) (cloth-flag need-reset no-draw)) + ) + ) + ) + (let ((s5-1 (handle->process (-> this owner)))) + (if (and s5-1 + (nonzero? (-> (the-as process-focusable s5-1) draw)) + (logtest? (-> (the-as process-focusable s5-1) draw status) + (draw-control-status no-draw no-draw-temp no-draw-bounds no-draw-bounds2) + ) + ) + (logior! (-> this flags) (cloth-flag no-draw)) + ) + (when (and s5-1 (nonzero? (-> (the-as process-focusable s5-1) draw))) + (let ((s4-0 (-> (the-as process-focusable s5-1) draw))) + (setup-dma-and-tex (-> this strip) s4-0) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (setup-dma-and-tex (-> this strip2) s4-0) + (setup-dma-and-tex (-> this strip3) s4-0) + ) + ) + ) + (when (< -1 (-> this base-transform-index)) + (let ((s5-2 (-> (the-as process-focusable s5-1) node-list data 3 bone transform trans))) + (let ((f0-0 12288.0)) + (when (< (* f0-0 f0-0) (vector-vector-distance-squared (-> this last-owner-pos) s5-2)) + ) + ) + (set! (-> this last-owner-pos quad) (-> s5-2 quad)) + ) + ) + ) + (call-parent-method this) + ) + +;; definition for method 11 of type verlet-particle-system +;; WARN: Return type mismatch int vs none. +(defmethod accumulate-external-forces! ((this verlet-particle-system)) + "If this cloth system has the wind flag, calculate the wind force." + 0 + (none) + ) + +;; definition for method 34 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod hide! ((this cloth-system)) + (logior! (-> this flags) (cloth-flag no-draw hidden)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (none) + ) + +;; definition for method 11 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod accumulate-external-forces! ((this cloth-system)) + "If this cloth system has the wind flag, calculate the wind force." + (if (not (logtest? (-> this flags) (cloth-flag no-gravity))) + (vector-float*! (-> this accum-force) (new 'static 'vector :y -1.0) (-> this gravity-constant)) + ) + (if (logtest? (-> this flags) (cloth-flag use-momentum)) + (vector+float*! (-> this accum-force) (-> this accum-force) (-> this momentum) 1.0) + ) + (when (logtest? (-> this flags) (cloth-flag use-wind)) + (let ((s5-0 (new 'stack-no-clear 'vector))) + 0.0 + (cond + ((-> *setting-control* user-current global-wind) + (vector-float*! s5-0 (the-as vector (-> *setting-control* user-current global-wind)) (-> this wind-constant)) + ) + (else + (let ((v1-17 s5-0) + (a1-1 (-> this particles data)) + ) + (vector-float*! + v1-17 + (-> *wind-work* + wind-array + (logand (+ (the int (-> a1-1 0 pos x)) (the int (-> a1-1 0 pos z)) (-> *wind-work* wind-time)) 63) + ) + (* 2048.0 (-> this wind-constant) (-> *setting-control* user-current ambient-wind-scalar)) + ) + ) + ) + ) + (let* ((f0-11 (vector-normalize-ret-len! s5-0 1.0)) + (f0-12 (fmin 163840.0 f0-11)) + ) + (vector+float*! (-> this accum-force) (-> this accum-force) s5-0 f0-12) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 12 of type verlet-particle-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod compute-verlet-step ((this verlet-particle-system) (arg0 float)) + (let ((f0-1 (* arg0 arg0)) + (f1-1 (-> this drag)) + ) + (dotimes (v1-0 (-> this particles length)) + (let ((a2-1 (-> this particles data v1-0)) + (a1-4 (new 'stack-no-clear 'vector)) + ) + (let ((a3-0 (-> this accum-force))) + (vector-float*! a1-4 (-> a2-1 pos) (- 2.0 f1-1)) + (vector-! a1-4 a1-4 (vector-float*! (new 'stack-no-clear 'vector) (-> a2-1 prev-pos) (- 1.0 f1-1))) + (vector+float*! a1-4 a1-4 a3-0 f0-1) + ) + (set! (-> a2-1 prev-pos quad) (-> a2-1 pos quad)) + (set! (-> a2-1 pos quad) (-> a1-4 quad)) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 19 of type cloth-system +;; WARN: Return type mismatch symbol vs none. +;; ERROR: Failed load: (set! vf10 (l.vf (+ a2-8 32))) at op 59 +(defmethod enforce-constraints-1 ((this cloth-system)) + (local-vars (a1-8 float)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (let ((v1-0 (new 'stack-no-clear 'vector))) + (set! (-> v1-0 x) 0.5) + (set! (-> v1-0 y) 0.5) + (set! (-> v1-0 z) 0.5) + (set! (-> v1-0 w) 0.5) + (let ((a1-4 (new 'stack-no-clear 'vector))) + (set! (-> a1-4 x) 3.0) + (set! (-> a1-4 y) 3.0) + (set! (-> a1-4 z) 3.0) + (set! (-> a1-4 w) 3.0) + (.max.w.vf vf7 vf0 vf0) + (.lvf vf8 (&-> v1-0 quad)) + (.lvf vf12 (&-> a1-4 quad)) + ) + ) + (.sub.w.vf vf9 vf0 vf0) + (dotimes (v1-1 (-> this stick-constraints length)) + (let* ((a1-7 (-> this stick-constraints data v1-1)) + (a2-8 (-> this particles data (-> a1-7 particle0))) + (a3-5 (-> this particles data (-> a1-7 particle1))) + ) + (.lvf vf2 (&-> a2-8 pos quad)) + (.lvf vf3 (&-> a3-5 pos quad)) + (.lvf vf6 (&-> a1-7 vec quad)) + (.sub.vf vf4 vf3 vf2) + (.mul.vf vf5 vf4 vf4) + (.mul.z.vf acc vf7 vf5) + (.add.mul.y.vf acc vf7 vf5 acc) + (.add.mul.x.vf acc vf7 vf5 acc) + (.add.mul.z.vf vf5 vf7 vf6 acc) + (.mul.y.vf vf5 vf5 vf6) + (.div.vf Q vf6 vf5 :fsf #b0 :ftf #b0) + (.lvf vf10 (+ a2-8 32)) + (.lvf vf11 (+ a3-5 32)) + (.max.x.vf vf10 vf0 vf10 :mask #b111) + (.max.x.vf vf11 vf0 vf11 :mask #b111) + (.add.vf vf13 vf10 vf11) + (.sub.vf vf13 vf12 vf13) + (.mul.vf vf10 vf10 vf13) + (.mul.vf vf11 vf11 vf13) + (.wait.vf) + (.sub.vf vf5 vf8 Q) + (.mul.vf vf5 vf5 vf4) + (.mul.vf vf10 vf10 vf5) + (.add.vf vf2 vf2 vf10) + (.mul.vf vf11 vf11 vf5) + (.sub.vf vf3 vf3 vf11) + (.svf (&-> a2-8 pos quad) vf2) + (.svf (&-> a3-5 pos quad) vf3) + ) + (.mov a1-8 vf3) + ) + (none) + ) + ) + +;; definition for method 20 of type cloth-system +;; WARN: Return type mismatch symbol vs none. +(defmethod enforce-constraints-2 ((this cloth-system)) + (dotimes (v1-0 (-> this stick-constraints length)) + (let* ((t0-0 (-> this stick-constraints data v1-0)) + (a1-5 (-> this particles data (-> t0-0 particle0))) + (a2-6 (-> this particles data (-> t0-0 particle1))) + (f0-1 (* 2.0 (-> t0-0 constraint-length-half))) + (a3-4 (vector-! (new 'stack-no-clear 'vector) (-> a2-6 pos) (-> a1-5 pos))) + ) + 0.0 + (let ((f1-2 (* f0-1 f0-1))) + 0.0 + 0.0 + (let* ((f1-4 (/ (+ f1-2 (vector-dot a3-4 a3-4)) (* 2.0 f0-1))) + (f0-3 (/ (- f1-4 f0-1) f1-4)) + ) + (vector-float*! a3-4 a3-4 (* 0.5 f0-3)) + ) + ) + (let ((f1-6 1.0) + (f0-5 -1.0) + ) + (cond + ((< (-> t0-0 particle0) (the-as uint 7)) + (set! f1-6 (* 0.0 f1-6)) + (set! f0-5 (* 2.0 f0-5)) + ) + ((< (-> t0-0 particle1) (the-as uint 7)) + (set! f1-6 (* 2.0 f1-6)) + (set! f0-5 (* 0.0 f0-5)) + ) + ) + (vector+float*! (-> a1-5 pos) (-> a1-5 pos) a3-4 f1-6) + (vector+float*! (-> a2-6 pos) (-> a2-6 pos) a3-4 f0-5) + ) + ) + ) + (none) + ) + +;; definition for method 21 of type cloth-system +;; INFO: function output is handled by mips2c +(defmethod-mips2c "(method 21 cloth-system)" 21 cloth-system) + +;; definition for method 23 of type cloth-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch symbol vs none. +(defmethod cloth-system-method-23 ((this cloth-system)) + (local-vars + (sv-32 int) + (sv-40 int) + (sv-48 int) + (sv-56 int) + (sv-64 matrix) + (sv-68 verlet-particle) + (sv-72 verlet-particle) + (sv-76 verlet-particle) + (sv-80 verlet-particle) + (sv-144 vector) + (sv-148 vector) + (sv-152 float) + (sv-156 float) + (sv-160 vector) + (sv-164 float) + (sv-168 float) + (sv-208 vector) + (sv-212 float) + (sv-216 vector) + ) + (set! sv-32 0) + (set! sv-40 0) + (set! sv-48 0) + (set! sv-56 -1) + (set! sv-64 (new 'stack-no-clear 'matrix)) + (dotimes (s5-0 (+ (-> this cloth-height) -1)) + (dotimes (s4-0 (+ (-> this cloth-width) -1)) + (set! sv-68 (-> this particles data sv-32)) + (set! sv-72 (-> this particles data (+ sv-32 1))) + (set! sv-76 (-> this particles data (+ sv-32 (-> this cloth-width)))) + (set! sv-80 (-> this particles data (+ (-> this cloth-width) 1 sv-32))) + (set! sv-144 (vector-! (new 'stack-no-clear 'vector) (-> sv-80 pos) (-> sv-68 pos))) + (set! sv-148 (vector-! (new 'stack-no-clear 'vector) (-> sv-72 pos) (-> sv-76 pos))) + (set! sv-152 (the-as float 0.0)) + (set! sv-156 (the-as float 0.0)) + (set! sv-160 (new 'stack-no-clear 'vector)) + (set! sv-164 (the-as float 0.0)) + (vector-float*! sv-160 (-> sv-72 pos) (-> sv-72 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-68 pos) (-> sv-68 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-76 pos) (-> sv-76 mass-scale)) + (vector+float*! sv-160 sv-160 (-> sv-80 pos) (-> sv-80 mass-scale)) + (vector-float*! sv-160 sv-160 0.25) + (set! sv-40 0) + (set! sv-56 -1) + (set! (-> sv-64 rvec quad) (the-as uint128 0)) + (dotimes (s3-0 (-> this collision-constraints length)) + (when (!= s3-0 sv-56) + (let ((v1-39 (-> this collision-constraints data s3-0))) + (set! sv-164 (the-as float 204.8)) + (set! sv-168 (the-as float 0.0)) + (set! sv-168 (+ (-> v1-39 r) (the-as float sv-164))) + (set! sv-208 (vector-! (new 'stack-no-clear 'vector) sv-160 (the-as vector v1-39))) + ) + (set! sv-212 (the-as float 0.0)) + (set! sv-216 (new 'stack-no-clear 'vector)) + (set! sv-212 (vector-dot sv-208 sv-208)) + (when (< sv-212 (* sv-168 sv-168)) + (vector-normalize-copy! sv-216 sv-208 sv-168) + (vector-! sv-216 sv-216 sv-208) + (when (and (> sv-40 0) (< (vector-dot sv-216 (the-as vector sv-64)) 0.0)) + ) + (vector+float*! (-> sv-68 pos) (-> sv-68 pos) sv-216 (-> sv-68 mass-scale)) + (vector+float*! (-> sv-72 pos) (-> sv-72 pos) sv-216 (-> sv-72 mass-scale)) + (vector+float*! (-> sv-76 pos) (-> sv-76 pos) sv-216 (-> sv-76 mass-scale)) + (vector+float*! (-> sv-80 pos) (-> sv-80 pos) sv-216 (-> sv-80 mass-scale)) + (vector+! sv-160 sv-160 sv-216) + (set! sv-40 (+ sv-40 1)) + ) + ) + ) + (set! sv-32 (+ sv-32 1)) + ) + (set! sv-32 (+ sv-32 1)) + ) + (none) + ) + +;; definition for method 22 of type cloth-system +;; WARN: Return type mismatch symbol vs none. +(defmethod cloth-system-method-22 ((this cloth-system)) + (local-vars + (v1-25 float) + (v1-27 float) + (sv-16 sphere) + (sv-24 int) + (sv-32 verlet-particle) + (sv-36 verlet-particle) + (sv-40 verlet-particle) + (sv-44 verlet-particle) + (sv-96 vector) + (sv-100 vector) + (sv-104 float) + (sv-108 float) + (sv-112 vector) + (sv-116 float) + (sv-120 float) + (sv-160 float) + (sv-164 float) + (sv-168 vector) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (dotimes (s5-0 (-> this collision-constraints length)) + (set! sv-16 (-> this collision-constraints data s5-0)) + (set! sv-24 0) + (dotimes (s4-0 (+ (-> this cloth-height) -1)) + (dotimes (s3-0 (+ (-> this cloth-width) -1)) + (set! sv-32 (-> this particles data sv-24)) + (set! sv-36 (-> this particles data (+ sv-24 1))) + (set! sv-40 (-> this particles data (+ sv-24 (-> this cloth-width)))) + (set! sv-44 (-> this particles data (+ (-> this cloth-width) 1 sv-24))) + (set! sv-96 (vector-! (new 'stack-no-clear 'vector) (-> sv-44 pos) (-> sv-32 pos))) + (set! sv-100 (vector-! (new 'stack-no-clear 'vector) (-> sv-36 pos) (-> sv-40 pos))) + (set! sv-104 (the-as float 0.0)) + (set! sv-108 (the-as float 0.0)) + (set! sv-112 (new 'stack-no-clear 'vector)) + (set! sv-116 (the-as float 0.0)) + (.lvf vf1 (&-> sv-96 quad)) + (.add.w.vf vf2 vf0 vf0 :mask #b1) + (.mul.vf vf1 vf1 vf1) + (.mul.x.vf acc vf2 vf1 :mask #b1) + (.add.mul.y.vf acc vf2 vf1 acc :mask #b1) + (.add.mul.z.vf vf1 vf2 vf1 acc :mask #b1) + (.mov v1-25 vf1) + (set! sv-104 v1-25) + (.lvf vf1 (&-> sv-100 quad)) + (.add.w.vf vf2 vf0 vf0 :mask #b1) + (.mul.vf vf1 vf1 vf1) + (.mul.x.vf acc vf2 vf1 :mask #b1) + (.add.mul.y.vf acc vf2 vf1 acc :mask #b1) + (.add.mul.z.vf vf1 vf2 vf1 acc :mask #b1) + (.mov v1-27 vf1) + (set! sv-108 v1-27) + (if (< sv-108 sv-104) + (vector+float*! sv-112 (-> sv-32 pos) sv-96 0.5) + (vector+float*! sv-112 (-> sv-40 pos) sv-100 0.5) + ) + (set! sv-116 (the-as float 0.0)) + (set! sv-120 (the-as float 0.0)) + (set! sv-120 (-> sv-16 r)) + (set! sv-160 (the-as float (vector-! (new 'stack-no-clear 'vector) sv-112 (the-as vector sv-16)))) + (set! sv-164 (the-as float 0.0)) + (set! sv-168 (new 'stack-no-clear 'vector)) + (set! sv-164 (vector-dot (the-as vector sv-160) (the-as vector sv-160))) + (when (< sv-164 (* sv-120 sv-120)) + (vector-normalize-copy! sv-168 (the-as vector sv-160) sv-120) + (vector-! sv-168 sv-168 (the-as vector sv-160)) + (vector+! (-> sv-32 pos) (-> sv-32 pos) sv-168) + (vector+! (-> sv-36 pos) (-> sv-36 pos) sv-168) + (vector+! (-> sv-40 pos) (-> sv-40 pos) sv-168) + (vector+! (-> sv-44 pos) (-> sv-44 pos) sv-168) + ) + (set! sv-24 (+ sv-24 1)) + ) + (set! sv-24 (+ sv-24 1)) + ) + ) + (none) + ) + ) + +;; definition for method 13 of type cloth-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod run-one-iteration ((this cloth-system)) + "Run one iteration of the system." + (enforce-constraints-1 this) + (cloth-system-method-21 this) + (dotimes (v1-4 0) + (let* ((a0-6 (-> this disc-collision-constraints data v1-4)) + (a2-0 (-> a0-6 start-particle-index)) + (a3-0 (-> a0-6 end-particle-index)) + (a1-2 (max 0 (min a2-0 (+ (-> this particles length) -1)))) + ) + (if (< a3-0 0) + (set! a3-0 (+ (-> this particles length) -1)) + ) + (let ((a2-8 (max 0 (min a3-0 (+ (-> this particles length) -1))))) + (while (>= a2-8 a1-2) + (let ((a3-7 (-> this particles data a1-2 pos))) + 0.0 + (let ((t1-0 (new 'stack-no-clear 'vector)) + (t0-7 (new 'stack-no-clear 'vector)) + ) + (vector-! t1-0 a3-7 (-> a0-6 origin)) + (let ((f0-2 (vector-dot t1-0 (-> a0-6 normal)))) + (when (< 0.0 f0-2) + (vector+float*! t0-7 a3-7 (-> a0-6 normal) (* -1.0 f0-2)) + (if (< (vector-length (vector-! (new 'stack-no-clear 'vector) t0-7 (-> a0-6 origin))) (-> a0-6 radius)) + (set! (-> a3-7 quad) (-> t0-7 quad)) + ) + ) + ) + ) + ) + (+! a1-2 1) + ) + ) + ) + ) + (dotimes (v1-7 (-> this anchor-points length)) + (set! (-> this particles data (-> this anchor-points data v1-7 particle-index) pos quad) + (-> this anchor-points data v1-7 anchor-pos quad) + ) + (set! (-> this particles data (-> this anchor-points data v1-7 particle-index) mass-scale) 0.0) + ) + (when (logtest? (-> this flags) (cloth-flag wraps)) + (dotimes (v1-13 (-> this cloth-height)) + (let ((a0-19 (-> this particles data (+ (* v1-13 (-> this cloth-width)) -1 (-> this cloth-width)))) + (a1-20 (the-as object (&-> (-> this particles) _data (* (* 48 (-> this cloth-width)) v1-13)))) + ) + (set! (-> a0-19 mass-scale) 0.0) + (set! (-> a0-19 pos quad) (-> (the-as vector (&-> (the-as vector a1-20) x)) quad)) + (set! (-> a0-19 prev-pos quad) (-> (the-as vector (&-> (the-as vector a1-20) x)) quad)) + ) + ) + ) + (when (logtest? (-> this flags) (cloth-flag check-ground)) + (dotimes (v1-19 (-> this particles length)) + (let ((a0-25 (-> this particles data v1-19))) + (set! (-> a0-25 pos y) (fmax (-> a0-25 pos y) (-> this ground-constraint))) + ) + ) + ) + 0 + (none) + ) + +;; definition for function get-neighboring-faces +(defun get-neighboring-faces ((arg0 vector4w) (arg1 int) (arg2 int) (arg3 int) (arg4 int)) + (let ((v0-0 0)) + (when (and (< arg2 (+ arg4 -1)) (< arg1 (+ arg3 -1))) + (set! (-> arg0 data v0-0) (+ (* arg2 (+ arg3 -1)) arg1)) + (+! v0-0 1) + ) + (when (and (> arg2 0) (< arg1 (+ arg3 -1))) + (set! (-> arg0 data v0-0) (+ (* (+ arg2 -1) (+ arg3 -1)) arg1)) + (+! v0-0 1) + ) + (when (and (> arg2 0) (> arg1 0)) + (set! (-> arg0 data v0-0) (+ arg1 -1 (* (+ arg2 -1) (+ arg3 -1)))) + (+! v0-0 1) + ) + (when (and (< arg2 (+ arg4 -1)) (> arg1 0)) + (set! (-> arg0 data v0-0) (+ arg1 -1 (* arg2 (+ arg3 -1)))) + (+! v0-0 1) + ) + v0-0 + ) + ) + +;; failed to figure out what this is: +(kmemopen global "cloth-buffers") + +;; definition for symbol *normal-array*, type (inline-array vector) +(define *normal-array* (the-as (inline-array vector) (malloc 'global 6400))) + +;; failed to figure out what this is: +(kmemclose) + +;; definition for method 27 of type cloth-system +;; INFO: Used lq/sq +(defmethod cloth-system-method-27 ((this cloth-system) (arg0 vector) (arg1 int) (arg2 int) (arg3 current-position-info)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (let ((s3-0 (new 'stack-no-clear 'vector4w))) + 0 + (let ((v1-1 (get-neighboring-faces s3-0 arg1 arg2 (-> this cloth-width) (-> this cloth-height)))) + (set! (-> arg0 quad) (the-as uint128 0)) + (dotimes (a0-3 v1-1) + (vector+! arg0 arg0 (-> *normal-array* (-> s3-0 data a0-3))) + ) + ) + ) + (let ((v1-4 arg0)) + (let ((f0-0 1.0)) + (.lvf vf1 (&-> v1-4 quad)) + (.mul.vf vf2 vf1 vf1 :mask #b111) + (let ((a0-5 f0-0)) + (.mov vf3 a0-5) + ) + ) + (.mul.x.vf acc vf0 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.z.vf vf2 vf0 vf2 acc :mask #b1000) + (.isqrt.vf Q vf3 vf2 :fsf #b0 :ftf #b11) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.svf (&-> v1-4 quad) vf1) + ) + (if (-> arg3 face-normal-needs-flip?) + (vector-float*! arg0 arg0 -1.0) + ) + (vector-float*! arg0 arg0 (-> this face-normal-scalar)) + arg0 + ) + ) + +;; definition for function light-vertex +;; WARN: Return type mismatch int vs rgba. +(defun light-vertex ((arg0 current-position-info) (arg1 vector)) + (local-vars (v0-0 uint128) (v0-1 uint128) (v0-2 uint128)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 lights direction 0 quad)) + (.lvf vf2 (&-> arg0 lights direction 1 quad)) + (.lvf vf3 (&-> arg0 lights direction 2 quad)) + (.lvf vf4 (&-> arg0 lights color 0 quad)) + (.lvf vf5 (&-> arg0 lights color 1 quad)) + (.lvf vf6 (&-> arg0 lights color 2 quad)) + (.lvf vf7 (&-> arg0 lights ambient quad)) + (.lvf vf10 (&-> (-> arg0 scale) quad)) + (.lvf vf11 (&-> (-> arg0 clamp-col) quad)) + (.lvf vf8 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf8) + (.add.mul.y.vf acc vf2 vf8 acc) + (.add.mul.z.vf vf8 vf3 vf8 acc) + (.max.x.vf vf8 vf8 vf0) + (.mul.w.vf acc vf7 vf0) + (.add.mul.x.vf acc vf4 vf8 acc) + (.add.mul.y.vf acc vf5 vf8 acc) + (.add.mul.z.vf vf9 vf6 vf8 acc) + (.mul.x.vf vf9 vf9 vf10) + (.min.vf vf9 vf9 vf11) + (.ftoi.vf vf9 vf9) + (.mov v0-0 vf9) + (.ppach v0-1 (the-as uint128 0) v0-0) + (.ppacb v0-2 (the-as uint128 0) v0-1) + (the-as rgba v0-2) + ) + ) + +;; definition for method 28 of type cloth-system +;; INFO: Used lq/sq +(defmethod cloth-system-method-28 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info)) + (local-vars + (sv-16 verlet-particle) + (sv-80 vector) + (sv-84 vector) + (sv-88 vector) + (sv-92 symbol) + (sv-112 vector) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (set! sv-16 (-> this particles data (+ arg0 (* arg1 (-> this cloth-width))))) + (set! sv-80 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) + (* (- (-> arg2 current-vert-index) (the-as uint (-> arg2 cross-index0))) 32) + ) + ) + (the-as vector sv-16) + ) + ) + (set! sv-84 (vector-! + (new 'stack-no-clear 'vector) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) + (* (- (-> arg2 current-vert-index) (the-as uint (-> arg2 cross-index1))) 32) + ) + ) + (the-as vector sv-16) + ) + ) + (set! sv-88 (new 'stack-no-clear 'vector)) + (set! sv-92 (the-as symbol #f)) + (vector-cross! sv-88 sv-80 sv-84) + (let ((a0-10 (-> arg2 cross-index0))) + (set! (-> arg2 cross-index0) (-> arg2 cross-index1)) + (set! (-> arg2 cross-index1) a0-10) + ) + (let ((s2-0 sv-88) + (s0-0 sv-16) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! sv-112 s1-0) + (let ((v0-0 (math-camera-pos))) + (.lvf vf4 (&-> s0-0 pos quad)) + (.lvf vf5 (&-> v0-0 quad)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> sv-112 quad) vf6) + (let ((v1-12 (< 0.0 (vector-dot s1-0 s2-0)))) + (when (!= v1-12 (-> arg2 face-normal-needs-flip?)) + (set! (-> arg2 face-normal-needs-flip?) (not (-> arg2 face-normal-needs-flip?))) + (cloth-system-method-30 + this + (the-as int (-> arg2 last-2-x-index)) + (the-as int (-> arg2 last-2-y-index)) + arg2 + 1 + ) + (cloth-system-method-30 this (the-as int (-> arg2 last-x-index)) (the-as int (-> arg2 last-y-index)) arg2 1) + ) + ) + ) + (cloth-system-method-30 this arg0 arg1 arg2 0) + (none) + ) + ) + +;; definition for method 31 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod cloth-system-method-31 ((this cloth-system) (arg0 current-position-info)) + (let ((a0-1 (-> arg0 last-normal)) + (s5-0 (+ (-> arg0 current-vert-index) -1)) + ) + (let ((v1-1 (-> arg0 backside-normal))) + (vector+float*! + (the-as vector (+ (the-as uint (-> this strip2 data 0 pos)) (* s5-0 32))) + (the-as vector (+ (the-as uint (-> this strip data 0 pos)) (* s5-0 32))) + a0-1 + (-> this thickness-scalar) + ) + (set! (-> this strip2 data s5-0 col) (light-vertex arg0 v1-1)) + ) + (set! (-> this strip2 data s5-0 stq x) (-> this strip data s5-0 stq x)) + (set! (-> this strip2 data s5-0 stq y) (-> this strip data s5-0 stq y)) + ) + 0 + (none) + ) + +;; definition for method 32 of type cloth-system +;; WARN: Return type mismatch vector vs none. +(defmethod cloth-system-method-32 ((this cloth-system) (arg0 vector) (arg1 int) (arg2 int) (arg3 current-position-info)) + (cond + ((> (-> this mesh cloth-thickness length) 0) + (let ((v1-5 (+ arg1 (* arg2 (-> this cloth-width))))) + 0.0 + (let ((f0-4 (* -1.0 + (-> this mesh thickness-scalar) + (-> this face-normal-scalar) + (the float (-> this mesh cloth-thickness data v1-5)) + ) + ) + ) + (vector-float*! (-> arg3 backside-normal) arg0 -1.0) + (vector-float*! arg0 arg0 f0-4) + ) + ) + ) + (else + (vector-float*! (-> arg3 backside-normal) arg0 -1.0) + (vector-float*! arg0 arg0 (* 204.8 + (/ (the float arg2) (the float (+ (-> this cloth-height) -1))) + (-> this thickness-scalar) + (-> this face-normal-scalar) + ) + ) + ) + ) + (none) + ) + +;; definition for method 30 of type cloth-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch uint vs none. +(defmethod cloth-system-method-30 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info) (arg3 int)) + (let ((s1-0 (+ arg0 (* arg1 (-> this cloth-width))))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> arg2 current-vert-index) 32))) + ) + (-> this particles data s1-0 pos quad) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq z) (the-as float arg3)) + (let ((s0-0 (new 'stack-no-clear 'vector))) + (cloth-system-method-27 this s0-0 arg0 arg1 arg2) + (set! (-> this strip data (-> arg2 current-vert-index) col) (light-vertex arg2 s0-0)) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq x) (-> this mesh mesh s1-0 u)) + (set! (-> this strip data (-> arg2 current-vert-index) stq y) (-> this mesh mesh s1-0 v)) + ) + (when (zero? arg3) + (set! (-> arg2 last-2-x-index) (-> arg2 last-x-index)) + (set! (-> arg2 last-2-y-index) (-> arg2 last-y-index)) + (set! (-> arg2 last-x-index) (the-as uint arg0)) + (set! (-> arg2 last-y-index) (the-as uint arg1)) + ) + (+! (-> arg2 current-vert-index) 1) + (none) + ) + +;; definition for method 29 of type cloth-system +;; INFO: Used lq/sq +(defmethod cloth-system-method-29 ((this cloth-system) (arg0 int) (arg1 int) (arg2 current-position-info) (arg3 int)) + (let ((s2-0 (+ arg0 (* arg1 (-> this cloth-width))))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> arg2 current-vert-index) 32))) + ) + (-> this particles data s2-0 pos quad) + ) + (set! (-> this strip data (-> arg2 current-vert-index) stq z) (the-as float arg3)) + (let ((s1-0 (-> arg2 last-normal))) + (cloth-system-method-27 this s1-0 arg0 arg1 arg2) + (set! (-> this strip data (-> arg2 current-vert-index) col) (light-vertex arg2 s1-0)) + (set! (-> this strip data (-> arg2 current-vert-index) stq x) (-> this mesh mesh s2-0 u)) + (set! (-> this strip data (-> arg2 current-vert-index) stq y) (-> this mesh mesh s2-0 v)) + (cloth-system-method-32 this s1-0 arg0 arg1 arg2) + ) + ) + (let ((v0-3 (+ (-> arg2 current-vert-index) 1))) + (set! (-> arg2 current-vert-index) v0-3) + v0-3 + ) + ) + +;; definition for method 26 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod cloth-system-method-26 ((this cloth-system)) + (* (+ (-> this cloth-width) -1) (+ (-> this cloth-height) -1)) + (dotimes (v1-3 (+ (-> this cloth-height) -1)) + (dotimes (a1-2 (+ (-> this cloth-width) -1)) + (let* ((a2-0 a1-2) + (t1-0 (+ (* v1-3 (-> this cloth-width)) a2-0)) + (a2-1 (new 'stack-no-clear 'vector)) + (a3-2 (new 'stack-no-clear 'vector)) + (t0-4 (+ a1-2 (* v1-3 (+ (-> this cloth-width) -1)))) + ) + (vector-! + a2-1 + (the-as vector (-> this particles data t1-0)) + (the-as vector (-> this particles data (+ (-> this cloth-width) 1 t1-0))) + ) + (vector-! + a3-2 + (the-as vector (-> this particles data (+ t1-0 1))) + (the-as vector (-> this particles data (+ t1-0 (-> this cloth-width)))) + ) + (vector-cross! (-> *normal-array* t0-4) a2-1 a3-2) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 33 of type cloth-system +(defmethod cloth-system-method-33 ((this cloth-system) (lights vu-lights)) + (vu-lights<-light-group! lights (the-as light-group (-> *time-of-day-context* light-group))) + (none) + ) + +;; definition for method 33 of type cloth-on-skeleton +(defmethod cloth-system-method-33 ((this cloth-on-skeleton) (lights vu-lights)) + (let ((draw-ctrl (-> (the-as process-focusable (handle->process (-> this owner))) draw))) + (cond + ((logtest? (-> draw-ctrl global-effect) (draw-control-global-effect no-textures)) + (logclear! (-> this strip flags) (prim-flags texture-enable)) + (logclear! (-> this strip2 flags) (prim-flags texture-enable)) + (logclear! (-> this strip3 flags) (prim-flags texture-enable)) + ) + (else + (logior! (-> this strip flags) (prim-flags texture-enable)) + (logior! (-> this strip2 flags) (prim-flags texture-enable)) + (logior! (-> this strip3 flags) (prim-flags texture-enable)) + ) + ) + (calc-vu1-lights lights draw-ctrl #f) + ) + (none) + ) + +;; definition for method 25 of type cloth-system +;; INFO: Used lq/sq +(defmethod cloth-system-method-25 ((this cloth-system)) + (local-vars (v0-1 texture-id) (v0-4 texture-id) (a0-72 int) (a0-74 int) (sv-224 int)) + (cond + ((and (not (logtest? (cloth-flag using-alt-tex) (-> this flags))) + (and (>= (-> *game-info* skill-total) 600.0) (-> this params alt-tex-name)) + ) + (logior! (-> this flags) (cloth-flag using-alt-tex)) + (set! (-> this strip tex-id) (lookup-texture-id-by-name (-> this params alt-tex-name) (the-as string #f))) + (set! v0-1 + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 tex-id) (lookup-texture-id-by-name (-> this params alt-tex-name2) (the-as string #f))) + (set! v0-1 (lookup-texture-id-by-name (-> this params alt-tex-name3) (the-as string #f))) + (set! (-> this strip3 tex-id) v0-1) + v0-1 + ) + ) + ) + ((and (logtest? (cloth-flag using-alt-tex) (-> this flags)) (< (-> *game-info* skill-total) 600.0)) + (logclear! (-> this flags) (cloth-flag using-alt-tex)) + (set! (-> this strip tex-id) (lookup-texture-id-by-name (-> this params tex-name) (the-as string #f))) + (set! v0-4 + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 tex-id) (lookup-texture-id-by-name (-> this params tex-name2) (the-as string #f))) + (set! v0-4 (lookup-texture-id-by-name (-> this params tex-name3) (the-as string #f))) + (set! (-> this strip3 tex-id) v0-4) + v0-4 + ) + ) + ) + ) + (when (logtest? (-> this flags) (cloth-flag no-draw)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (return 0) + ) + (set! (-> this strip adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip2 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip2 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip3 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip3 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip alpha) (new 'static 'gs-alpha)) + (set! (-> this strip2 alpha) (-> this strip alpha)) + (set! (-> this strip3 alpha) (-> this strip alpha)) + (set! (-> this strip clamp) (new 'static 'gs-clamp)) + (set! (-> this strip2 clamp) (new 'static 'gs-clamp)) + (set! (-> this strip3 clamp) (new 'static 'gs-clamp)) + (logior! (-> this strip flags) (prim-flags fog-enable)) + (logior! (-> this strip2 flags) (prim-flags fog-enable)) + (logior! (-> this strip3 flags) (prim-flags fog-enable)) + (cloth-system-method-26 this) + (let ((s5-0 (new 'stack-no-clear 'current-position-info))) + (let ((s4-0 0) + (s3-0 1) + (s2-0 1) + (s1-0 -1) + ) + (set! (-> s5-0 current-vert-index) (the-as uint 0)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (cloth-system-method-33 this (-> s5-0 lights)) + (set-vector! (-> s5-0 scale) 128.0 128.0 128.0 128.0) + (set-vector! (-> s5-0 clamp-col) 255.0 255.0 255.0 128.0) + (dotimes (s0-0 (+ (-> this cloth-height) -1)) + (set! sv-224 0) + (while (< sv-224 (-> this cloth-width)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (cloth-system-method-29 this s4-0 s3-0 s5-0 0) + (cloth-system-method-31 this s5-0) + (cloth-system-method-29 this s4-0 (+ s3-0 s1-0) s5-0 0) + (cloth-system-method-31 this s5-0) + (+! s4-0 s2-0) + (set! sv-224 (+ sv-224 1)) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq quad) + (-> this strip data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip2 data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip2 data (-> s5-0 current-vert-index) stq quad) + (-> this strip2 data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip2 data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (+! (-> s5-0 current-vert-index) 1) + (set! s2-0 (* -1 s2-0)) + (set! s1-0 (* -1 s1-0)) + (+! s4-0 s2-0) + (if (< s1-0 0) + (+! s3-0 2) + ) + ) + ) + (set! (-> this strip num-verts) (-> s5-0 current-vert-index)) + (set! (-> this strip2 num-verts) (-> s5-0 current-vert-index)) + ) + 0 + (let ((v1-110 0)) + (let ((a0-67 1)) + (dotimes (a1-27 (-> this cloth-width)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-67 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-67 stq quad)) + (let ((v1-111 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-111 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-67 32)))) + ) + (set! (-> this strip3 data v1-111 stq quad) (-> this strip2 data a0-67 stq quad)) + (set! v1-110 (+ v1-111 1)) + ) + (+! a0-67 2) + ) + ) + (let ((a0-71 (* (-> this cloth-width) 2))) + (dotimes (a1-28 (+ (-> this cloth-height) -1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-71 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-71 stq quad)) + (set! (-> this strip3 data v1-110 stq z) 0.0) + (let ((v1-112 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-112 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-71 32)))) + ) + (set! (-> this strip3 data v1-112 stq quad) (-> this strip2 data a0-71 stq quad)) + (set! (-> this strip3 data v1-112 stq z) 0.0) + (set! v1-110 (+ v1-112 1)) + ) + (if (= (logand a1-28 1) 1) + (+! a0-71 (* (-> this cloth-width) 4)) + (+! a0-71 2) + ) + ) + (let ((a1-31 -2)) + (cond + ((= (logand (-> this cloth-height) 1) 1) + (set! a0-72 (- a0-71 (* (-> this cloth-width) 4))) + (set! a1-31 (* -1 a1-31)) + ) + (else + (set! a0-72 (+ a0-71 a1-31 a1-31)) + ) + ) + (dotimes (a2-44 (-> this cloth-width)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-72 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-72 stq quad)) + (let ((v1-113 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-113 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-72 32)))) + ) + (set! (-> this strip3 data v1-113 stq quad) (-> this strip2 data a0-72 stq quad)) + (set! v1-110 (+ v1-113 1)) + ) + (+! a0-72 a1-31) + ) + ) + ) + (if (not (logtest? (-> this cloth-height) 1)) + (set! a0-74 (+ a0-72 2)) + (set! a0-74 (+ a0-72 -2 1)) + ) + (dotimes (a1-38 (+ (-> this cloth-height) -1)) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-110 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* a0-74 32)))) + ) + (set! (-> this strip3 data v1-110 stq quad) (-> this strip data a0-74 stq quad)) + (set! (-> this strip3 data v1-110 stq z) 0.0) + (let ((v1-114 (+ v1-110 1))) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip3 data 0 pos)) (* v1-114 32)))) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip2 data 0 pos)) (* a0-74 32)))) + ) + (set! (-> this strip3 data v1-114 stq quad) (-> this strip2 data a0-74 stq quad)) + (set! (-> this strip3 data v1-114 stq z) 0.0) + (set! v1-110 (+ v1-114 1)) + ) + (if (not (logtest? (- (-> this cloth-height) (+ a1-38 1)) 1)) + (set! a0-74 (- a0-74 (* (-> this cloth-width) 4))) + (+! a0-74 -2) + ) + ) + (set! (-> this strip3 num-verts) (the-as uint v1-110)) + ) + 0 + ) + +;; definition for method 18 of type cloth-system +(defmethod post-physics-update ((this cloth-system)) + (when (logtest? (-> this flags) (cloth-flag no-draw)) + (set! (-> this strip num-verts) (the-as uint 0)) + (when (nonzero? (-> this strip2)) + (set! (-> this strip2 num-verts) (the-as uint 0)) + (set! (-> this strip3 num-verts) (the-as uint 0)) + 0 + ) + (return 0) + ) + (if (logtest? (-> this flags) (cloth-flag double-sided)) + (cloth-system-method-25 this) + (cloth-system-method-24 this) + ) + ) + +;; definition for method 18 of type cloth-on-skeleton +(defmethod post-physics-update ((this cloth-on-skeleton)) + (let ((a1-0 (handle->process (-> this owner)))) + (if (and a1-0 (logtest? (-> (the-as process-focusable a1-0) draw status) (draw-control-status on-screen))) + (call-parent-method this) + ) + ) + ) + +;; definition for method 24 of type cloth-system +;; INFO: Used lq/sq +(defmethod cloth-system-method-24 ((this cloth-system)) + (local-vars (sv-16 int) (sv-24 int) (sv-32 int) (sv-40 int)) + (cloth-system-method-26 this) + (set! sv-16 0) + (set! sv-24 1) + (set! sv-32 1) + (set! sv-40 -1) + (let ((s5-0 (new 'stack-no-clear 'current-position-info))) + (set! (-> s5-0 current-vert-index) (the-as uint 0)) + (set! (-> s5-0 last-x-index) (the-as uint -1)) + (set! (-> s5-0 last-y-index) (the-as uint -1)) + (set! (-> s5-0 last-2-x-index) (the-as uint -1)) + (set! (-> s5-0 last-2-y-index) (the-as uint -1)) + (set! (-> s5-0 face-normal-needs-flip?) #f) + (set-vector! (-> s5-0 scale) 128.0 128.0 128.0 128.0) + (set-vector! (-> s5-0 clamp-col) 255.0 255.0 255.0 128.0) + (vu-lights<-light-group! (-> s5-0 lights) (the-as light-group (-> *time-of-day-context* light-group))) + (dotimes (s4-0 (+ (-> this cloth-height) -1)) + (let* ((a0-17 (+ sv-16 (/ (+ sv-32 -1) 2) (* (+ sv-24 (/ (+ sv-40 -1) 2)) (+ (-> this cloth-width) -1)))) + (s3-0 (-> *normal-array* a0-17)) + (s1-0 (-> this particles data (+ sv-16 (* sv-24 (-> this cloth-width))))) + (s2-0 (new 'stack-no-clear 'vector)) + ) + (vector-! s2-0 (the-as vector s1-0) (math-camera-pos)) + (set! (-> s5-0 face-normal-needs-flip?) (< 0.0 (vector-dot s2-0 s3-0))) + ) + (cloth-system-method-30 this sv-16 sv-24 s5-0 0) + (cloth-system-method-30 this sv-16 (+ sv-24 sv-40) s5-0 0) + (set! (-> s5-0 cross-index0) 2) + (set! (-> s5-0 cross-index1) 1) + (set! sv-16 (+ sv-16 sv-32)) + (let ((s3-1 1) + (s2-1 (+ (-> this cloth-width) -1)) + ) + (while (>= s2-1 s3-1) + (cloth-system-method-28 this sv-16 sv-24 s5-0) + (cloth-system-method-28 this sv-16 (+ sv-24 sv-40) s5-0) + (set! sv-16 (+ sv-16 sv-32)) + (+! s3-1 1) + ) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this strip data 0 pos)) (* (-> s5-0 current-vert-index) 32))) + ) + (-> (the-as + (pointer uint128) + (+ (the-as uint (-> this strip data 0 pos)) (* (+ (-> s5-0 current-vert-index) -2) 32)) + ) + ) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq quad) + (-> this strip data (+ (-> s5-0 current-vert-index) -2) stq quad) + ) + (set! (-> this strip data (-> s5-0 current-vert-index) stq z) (the-as float #x1)) + (+! (-> s5-0 current-vert-index) 1) + (set! sv-32 (* -1 sv-32)) + (set! sv-40 (* -1 sv-40)) + (set! sv-16 (+ sv-16 sv-32)) + (if (< sv-40 0) + (set! sv-24 (+ sv-24 2)) + ) + ) + (set! (-> this strip num-verts) (-> s5-0 current-vert-index)) + ) + 0 + ) + +;; definition for method 35 of type cloth-on-skeleton +;; INFO: Used lq/sq +;; WARN: Return type mismatch symbol vs none. +(defmethod reset-locations ((this cloth-on-skeleton)) + (let ((s5-0 (handle->process (-> this owner)))) + (when (nonzero? (-> this mesh anchor-transforms)) + (dotimes (s4-0 (-> this mesh anchor-transforms length)) + (set! (-> this anchor-points data s4-0 particle-index) + (the-as uint (-> this mesh anchor-transforms data s4-0 constraint-index)) + ) + (cond + (s5-0 + (let ((a2-0 + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh anchor-transforms data s4-0 joint) + bone + transform + ) + ) + ) + (vector-matrix*! + (the-as vector (-> this anchor-points data s4-0)) + (the-as vector (-> this mesh anchor-transforms data s4-0)) + a2-0 + ) + ) + (vector-float*! + (the-as vector (-> this anchor-points data s4-0)) + (the-as vector (-> this anchor-points data s4-0)) + (/ 1.0 (-> this anchor-points data s4-0 anchor-pos w)) + ) + (set! (-> this anchor-points data s4-0 anchor-pos w) 1.0) + ) + (else + (set! (-> this anchor-points data s4-0 anchor-pos quad) + (-> this mesh anchor-transforms data s4-0 offset quad) + ) + ) + ) + ) + ) + (when (nonzero? (-> this mesh sphere-transforms)) + (dotimes (s4-1 (-> this mesh sphere-transforms length)) + (cond + (s5-0 + (let ((s3-0 (new 'stack-no-clear 'vector))) + (set! (-> s3-0 quad) (-> this collision-constraints data s4-1 quad)) + (set! (-> s3-0 w) 1.0) + (vector-matrix*! + s3-0 + (the-as vector (-> this mesh sphere-transforms data s4-1)) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh sphere-transforms data s4-1 joint) + bone + transform + ) + ) + (vector-float*! s3-0 s3-0 (/ 1.0 (-> s3-0 w))) + (set! (-> this collision-constraints data s4-1 x) (-> s3-0 x)) + (set! (-> this collision-constraints data s4-1 y) (-> s3-0 y)) + (set! (-> this collision-constraints data s4-1 z) (-> s3-0 z)) + ) + ) + (else + (set! (-> this collision-constraints data s4-1 quad) (-> this mesh sphere-transforms data s4-1 offset quad)) + ) + ) + (set! (-> this collision-constraints data s4-1 r) (-> this mesh sphere-transforms data s4-1 radius)) + ) + ) + (when (nonzero? (-> this mesh disc-transforms)) + (dotimes (s4-2 (-> this mesh disc-transforms length)) + (cond + (s5-0 + (vector-matrix*! + (the-as vector (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s4-2))) + (the-as vector (-> this mesh disc-transforms data s4-2)) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh disc-transforms data s4-2 joint) + bone + transform + ) + ) + (vector-rotate*! + (the-as vector (-> this disc-collision-constraints data s4-2)) + (the-as vector (+ (the-as uint (-> this mesh disc-transforms data 0 normal)) (* 48 s4-2))) + (-> (the-as process-focusable s5-0) + node-list + data + (-> this mesh disc-transforms data s4-2 joint) + bone + transform + ) + ) + ) + (else + (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s4-2))) + ) + (-> this mesh disc-transforms data s4-2 offset quad) + ) + (set! (-> this disc-collision-constraints data s4-2 normal quad) + (-> (the-as (pointer uint128) (+ (the-as uint (-> this mesh disc-transforms data 0 normal)) (* 48 s4-2)))) + ) + ) + ) + (set! (-> this disc-collision-constraints data s4-2 radius) (-> this mesh disc-transforms data s4-2 radius)) + (set! (-> this disc-collision-constraints data s4-2 start-particle-index) + (-> this mesh disc-transforms data s4-2 start-particle-index) + ) + (set! (-> this disc-collision-constraints data s4-2 end-particle-index) + (-> this mesh disc-transforms data s4-2 end-particle-index) + ) + ) + ) + ) + (none) + ) + +;; definition for method 35 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod reset-locations ((this cloth-system)) + 0 + (none) + ) + +;; definition for symbol *once*, type symbol +(define *once* #f) + +;; definition for method 17 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw-spheres ((this cloth-system)) + (dotimes (s5-0 (-> this collision-constraints length)) + (add-debug-sphere + #t + (bucket-id debug) + (-> this collision-constraints data s5-0) + (-> this collision-constraints data s5-0 r) + *color-cyan* + ) + (format *stdcon* "Transform ~d, size ~f~%" s5-0 (* 0.00024414062 (-> this collision-constraints data s5-0 r))) + ) + (dotimes (s5-1 (-> this disc-collision-constraints length)) + (add-debug-sphere + #t + (bucket-id debug) + (the-as vector (+ (the-as uint (-> this disc-collision-constraints data 0 origin)) (* 48 s5-1))) + (-> this disc-collision-constraints data s5-1 radius) + *color-red* + ) + ) + 0 + (none) + ) + +;; definition for symbol *cloth-fade-alpha*, type gs-alpha +(define *cloth-fade-alpha* (new 'static 'gs-alpha :b #x1 :d #x1)) + +;; definition for method 25 of type cloth-on-skeleton +;; WARN: Return type mismatch symbol vs int. +(defmethod cloth-system-method-25 ((this cloth-on-skeleton)) + (call-parent-method this) + (let ((proc (handle->process (-> this owner)))) + (the-as int (when (and proc (nonzero? (-> (the-as process-drawable proc) draw))) + (let ((draw-ctrl (-> (the-as process-focusable proc) draw))) + (let ((fade (-> draw-ctrl force-fade))) + (when (logtest? (-> draw-ctrl status) (draw-control-status force-fade)) + (set! (-> this strip data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip alpha) *cloth-fade-alpha*) + (dotimes (a0-14 (the-as int (-> this strip num-verts))) + (set! (-> this strip data a0-14 col a) fade) + ) + (when (logtest? (-> this flags) (cloth-flag double-sided)) + (set! (-> this strip2 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip2 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip2 alpha) *cloth-fade-alpha*) + (set! (-> this strip3 adnops 0 cmds) (gs-reg64 test-1)) + (set! (-> this strip3 data0) (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :afail #x1 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + (set! (-> this strip3 alpha) *cloth-fade-alpha*) + (dotimes (a0-25 (the-as int (-> this strip2 num-verts))) + (set! (-> this strip2 data a0-25 col a) fade) + ) + (dotimes (a0-28 (the-as int (-> this strip3 num-verts))) + (set! (-> this strip3 data a0-28 col a) fade) + ) + #f + ) + ) + ) + ) + ) + ) + ) + ) + +;; definition for method 11 of type cloth-on-skeleton +;; INFO: Used lq/sq +(defmethod accumulate-external-forces! ((this cloth-on-skeleton)) + "If this cloth system has the wind flag, calculate the wind force." + (when (logtest? (-> this flags) (cloth-flag use-parent-momentum)) + (let ((proc (handle->process (-> this owner)))) + (if proc + (set! (-> this momentum quad) (-> (the-as process-drawable proc) root transv quad)) + ) + ) + ) + (call-parent-method this) + (none) + ) + +;; definition for function symbol->cloth-flags +;; WARN: Return type mismatch int vs cloth-flag. +(defun symbol->cloth-flags ((arg0 symbol)) + (let ((v1-0 arg0)) + (the-as cloth-flag (cond + ((= v1-0 'local-space) + #x40000 + ) + ((= v1-0 'local-space-xyz) + #x80000 + ) + ((= v1-0 'local-space-y) + #x100000 + ) + ((= v1-0 'riding) + #x10000 + ) + (else + 0 + ) + ) + ) + ) + ) + +;; definition for method 37 of type cloth-system +;; WARN: Return type mismatch int vs none. +(defmethod cloth-system-cmd-handler ((this cloth-system) (command pair)) + (let ((msg (-> command car))) + (case msg + (('scene-reset-frame) + (if (logtest? (cloth-flag use-old-resets) (-> this flags)) + (logior! (-> this flags) (cloth-flag need-reset)) + (logior! (-> this flags) (cloth-flag local-space)) + ) + ) + (('set-flags 'clear-flags) + (let ((flags 0)) + (let* ((s3-0 (-> command cdr)) + (a0-9 (-> (the-as pair s3-0) car)) + ) + (while (not (null? s3-0)) + (set! flags (logior (the-as cloth-flag flags) (symbol->cloth-flags (the-as symbol a0-9)))) + (set! s3-0 (-> (the-as pair s3-0) cdr)) + (set! a0-9 (-> (the-as pair s3-0) car)) + ) + ) + (if (= msg 'set-flags) + (logior! (-> this flags) flags) + (logclear! (-> this flags) flags) + ) + ) + ) + (('hide) + (hide! this) + ) + (('show) + (logclear! (-> this flags) (cloth-flag hidden)) + ) + (('wind-strength) + (set! (-> this wind-constant) (command-get-float (-> (the-as pair (-> command cdr)) car) 0.0)) + ) + (('reset) + (logior! (-> this flags) (cloth-flag need-reset)) + ) + ) + ) + 0 + (none) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/process-drawable/process-drawable_REF.gc b/test/decompiler/reference/jak3/engine/process-drawable/process-drawable_REF.gc index 672c3536c..a62b977e9 100644 --- a/test/decompiler/reference/jak3/engine/process-drawable/process-drawable_REF.gc +++ b/test/decompiler/reference/jak3/engine/process-drawable/process-drawable_REF.gc @@ -378,7 +378,7 @@ (let ((proc (handle->process (-> gp-0 s4-0)))) (when proc (dotimes (i (-> (the-as process-drawable proc) draw cloth-instances length)) - (init! (-> (the-as process-drawable proc) draw cloth-instances i)) + (update! (-> (the-as process-drawable proc) draw cloth-instances i)) ) ) ) @@ -898,7 +898,7 @@ (set! (-> this draw cloth-instances length) (-> this draw cloth-instances allocated-length)) (dotimes (s4-4 (-> arg0 clothing length)) (set! (-> this draw cloth-instances s4-4) (new 'process 'cloth-on-skeleton)) - (cloth-base-method-10 (-> this draw cloth-instances s4-4) (-> arg0 clothing s4-4) (process->handle this)) + (setup-from-params! (-> this draw cloth-instances s4-4) (-> arg0 clothing s4-4) (process->handle this)) ) ) (logior! (-> this draw global-effect) (-> arg0 global-effects)) @@ -2312,7 +2312,7 @@ ) (dotimes (i (-> proc draw cloth-instances length)) (if (not arg1) - (cloth-system-method-34 (-> proc draw cloth-instances i)) + (hide! (-> proc draw cloth-instances i)) (logclear! (-> proc draw cloth-instances i flags) (cloth-flag hidden)) ) ) diff --git a/test/decompiler/reference/jak3/engine/target/target-death_REF.gc b/test/decompiler/reference/jak3/engine/target/target-death_REF.gc index 579909310..fddb65f23 100644 --- a/test/decompiler/reference/jak3/engine/target/target-death_REF.gc +++ b/test/decompiler/reference/jak3/engine/target/target-death_REF.gc @@ -427,7 +427,7 @@ (case (-> self ext-geo) (((target-geo jakc)) (dotimes (s5-1 (-> gp-1 clothing length)) - (cloth-base-method-10 (-> self draw cloth-instances s5-1) (-> gp-1 clothing s5-1) (process->handle self)) + (setup-from-params! (-> self draw cloth-instances s5-1) (-> gp-1 clothing s5-1) (process->handle self)) (logior! (-> self draw cloth-instances s5-1 flags) (cloth-flag need-reset active)) ) ) diff --git a/test/offline/config/jak3/config.jsonc b/test/offline/config/jak3/config.jsonc index 0fada7966..32c18ca30 100644 --- a/test/offline/config/jak3/config.jsonc +++ b/test/offline/config/jak3/config.jsonc @@ -384,7 +384,10 @@ // asm "close-sky-buffer", // protect-gunship - "find-reposition-pt" + "find-reposition-pt", + // asm + "(method 19 cloth-system)", + "(method 37 cloth-system)" ], "skip_compile_states": {