From 8ae4829f48817eedd2f72222b523cd1d0b8ae509 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sat, 29 Oct 2022 20:32:03 -0400 Subject: [PATCH] [decomp] collide-hash, collide-frag, collide-probe (#1998) The only interesting one is `collide-hash`, which is untested. The other two are very likely unused. I skipped the annoying code in `collide-probe` because it's not used and the same as jak 1. --- decompiler/analysis/mips2c.cpp | 19 + decompiler/config/jak2/all-types.gc | 166 +- decompiler/config/jak2/hacks.jsonc | 11 +- decompiler/config/jak2/stack_structures.jsonc | 14 +- decompiler/config/jak2/type_casts.jsonc | 22 + decompiler/types2/types2.cpp | 13 +- game/CMakeLists.txt | 1 + game/mips2c/jak2_functions/collide_hash.cpp | 1541 +++++++++++++++++ .../jak2_functions/sparticle_launcher.cpp | 2 - game/mips2c/mips2c_private.h | 14 + game/mips2c/mips2c_table.cpp | 9 +- .../jak2/engine/collide/collide-cache-h.gc | 20 +- goal_src/jak2/engine/collide/collide-frag.gc | 90 + goal_src/jak2/engine/collide/collide-h.gc | 77 +- goal_src/jak2/engine/collide/collide-probe.gc | 227 +++ .../jak2/engine/collide/collide-shape-h.gc | 4 +- goal_src/jak2/engine/collide/los-control.gc | 2 +- goal_src/jak2/engine/draw/drawable-h.gc | 13 +- goal_src/jak2/engine/draw/drawable.gc | 8 +- .../jak2/engine/gfx/background/prototype-h.gc | 19 +- goal_src/jak2/engine/gfx/mood/weather-part.gc | 2 +- goal_src/jak2/engine/gfx/ocean/ocean-h.gc | 2 +- goal_src/jak2/engine/physics/trajectory.gc | 2 +- .../engine/spatial-hash/collide-hash-h.gc | 29 +- .../jak2/engine/spatial-hash/collide-hash.gc | 592 +++++++ goal_src/jak2/engine/target/logic-target.gc | 8 +- goal_src/jak2/examples/collide-hash-debug.gc | 87 + .../reference/jak2/decompiler-macros.gc | 12 +- .../engine/collide/collide-cache-h_REF.gc | 39 +- .../jak2/engine/collide/collide-frag_REF.gc | 106 ++ .../jak2/engine/collide/collide-h_REF.gc | 81 +- .../engine/collide/collide-shape-h_REF.gc | 4 +- .../jak2/engine/collide/los-control_REF.gc | 13 +- .../jak2/engine/draw/drawable-h_REF.gc | 10 +- .../engine/gfx/background/prototype-h_REF.gc | 187 +- .../jak2/engine/gfx/mood/weather-part_REF.gc | 2 +- .../jak2/engine/gfx/ocean/ocean-h_REF.gc | 2 +- .../engine/spatial-hash/collide-hash-h_REF.gc | 59 +- .../engine/spatial-hash/collide-hash_REF.gc | 703 ++++++++ .../jak2/engine/target/logic-target_REF.gc | 8 +- test/offline/offline_test_main.cpp | 1 + 41 files changed, 3802 insertions(+), 419 deletions(-) create mode 100644 game/mips2c/jak2_functions/collide_hash.cpp create mode 100644 goal_src/jak2/examples/collide-hash-debug.gc create mode 100644 test/decompiler/reference/jak2/engine/collide/collide-frag_REF.gc create mode 100644 test/decompiler/reference/jak2/engine/spatial-hash/collide-hash_REF.gc diff --git a/decompiler/analysis/mips2c.cpp b/decompiler/analysis/mips2c.cpp index 10be92788c..4d4c532fed 100644 --- a/decompiler/analysis/mips2c.cpp +++ b/decompiler/analysis/mips2c.cpp @@ -757,6 +757,18 @@ Mips2C_Line handle_vmadda(const Instruction& i0, const std::string& instr_str) { instr_str}; } +Mips2C_Line handle_vmsuba(const Instruction& i0, const std::string& instr_str) { + return {fmt::format("c->vmsuba(DEST::{}, {}, {});", dest_to_char(i0.cop2_dest), + reg_to_name(i0.get_src(0)), reg_to_name(i0.get_src(1))), + instr_str}; +} + +Mips2C_Line handle_vmula(const Instruction& i0, const std::string& instr_str) { + return {fmt::format("c->vmula(DEST::{}, {}, {});", dest_to_char(i0.cop2_dest), + reg_to_name(i0.get_src(0)), reg_to_name(i0.get_src(1))), + instr_str}; +} + Mips2C_Line handle_vadda_bc(const Instruction& i0, const std::string& instr_str) { return {fmt::format("c->vadda_bc(DEST::{}, BC::{}, {}, {});", dest_to_char(i0.cop2_dest), i0.cop2_bc_to_char(), reg_to_name(i0.get_src(0)), reg_to_name(i0.get_src(1))), @@ -988,6 +1000,8 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output, return handle_generic_op3_bc_mask(i0, instr_str, "vmul_bc"); case InstructionKind::VMADD: return handle_generic_op3_mask(i0, instr_str, "vmadd"); + case InstructionKind::VMSUB: + return handle_generic_op3_mask(i0, instr_str, "vmsub"); case InstructionKind::VMUL: return handle_generic_op3_mask(i0, instr_str, "vmul"); case InstructionKind::VADD: @@ -1072,6 +1086,7 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output, case InstructionKind::SLTU: case InstructionKind::DSRAV: case InstructionKind::DSLLV: + case InstructionKind::SLLV: case InstructionKind::PAND: case InstructionKind::PCEQB: case InstructionKind::PPACW: @@ -1112,6 +1127,10 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output, return handle_vmsuba_bc(i0, instr_str); case InstructionKind::VMADDA: return handle_vmadda(i0, instr_str); + case InstructionKind::VMSUBA: + return handle_vmsuba(i0, instr_str); + case InstructionKind::VMULA: + return handle_vmula(i0, instr_str); case InstructionKind::VMADD_BC: return handle_generic_op3_bc_mask(i0, instr_str, "vmadd_bc"); case InstructionKind::VMSUB_BC: diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index 6a51f021e2..a8f61ca7b5 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -8457,6 +8457,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (declare-type region-prim-list structure) +(declare-type collide-list structure) +(declare-type collide-query structure) (deftype drawable (basic) ((id int16 :offset-assert 4) @@ -8468,11 +8470,11 @@ (:methods (login (_type_) _type_ 9) (draw (_type_ _type_ display-frame) none 10) - (drawable-method-11 () none 11) ;; (collide-with-box (_type_ int collide-list) none 11) - (drawable-method-12 () none 12) ;; (collide-y-probe (_type_ int collide-list) none 12) - (collect-stats (_type_) none 13) ;; (collide-ray (_type_ int collide-list) none 13) + (fill-collide-list-from-box (_type_ int collide-list collide-query) int 11) + (fill-collide-list-from-line-sphere (_type_ int collide-list collide-query) int 12) + (collect-stats (_type_) none 13) (debug-draw (_type_ drawable display-frame) none 14) - (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) ;; + (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) (collect-regions "Determines the number of [[drawable]]s in the `obj` that overlap the given `area-of-interest` this number is stored in the `region-list`'s item count @param area-of-interest The area defined by a sphere that we care about overlaps @@ -10653,7 +10655,7 @@ (ocean-method-15 () none 15) (ocean-method-16 () none 16) (ocean-method-17 () none 17) - (ocean-method-18 () none 18) + (ocean-method-18 (_type_ object object) none 18) (ocean-method-19 () none 19) (ocean-method-20 () none 20) (ocean-method-21 (_type_ float float) float 21) @@ -13164,8 +13166,8 @@ (disable 0) (tpage-alpha 2) (vanish 3) + (no-collide 6) (tpage-water 7) - ) (deftype prototype-bucket (basic) @@ -13229,6 +13231,7 @@ ) (declare-type prototype-tie drawable) +(declare-type collide-hash-fragment-array basic) (deftype prototype-bucket-tie (prototype-bucket) ((next uint32 12 :offset-assert 64) ;; guessed by decompiler @@ -13242,7 +13245,7 @@ (envmap-fade-far float :offset-assert 164) (envmap-shader adgif-shader :offset-assert 168) (tint-color uint32 :offset-assert 172) - (collide-hash-fragment-array basic :offset-assert 176) + (collide-hash-fragment-array collide-hash-fragment-array :offset-assert 176) (tie-colors time-of-day-palette :offset-assert 180) ;; guessed by decompiler (data uint32 :dynamic :offset-assert 184) ;; guessed by decompiler (color-index-qwc uint32 :dynamic :offset-assert 184) ;; guessed by decompiler @@ -13340,10 +13343,15 @@ :flag-assert #x900000010 ) +(defenum instance-flags + :type uint16 + :bitfield #t + (no-collide 0) + ) (deftype instance (drawable) ((bucket-index uint16 :offset 6) (origin matrix4h :inline :offset-assert 32) - (flags uint16 :offset 46) + (flags instance-flags :offset 46) (wind-index uint16 :offset 62) ) :method-count-assert 17 @@ -16024,8 +16032,8 @@ (:methods (new (symbol type collide-shape uint int) _type_ 0) (collide-shape-prim-method-9 () none 9) ;; (move-by-vector! (_type_ vector) none 9) - (collide-shape-prim-method-10 () none 10) ;; (find-prim-by-id (_type_ uint) collide-shape-prim 10) - (collide-shape-prim-method-11 () none 11) ;; (debug-draw-world-sphere (_type_) symbol 11) + (add-fg-prim-using-box () none 10) ;; (find-prim-by-id (_type_ uint) collide-shape-prim 10) + (add-fg-prim-using-line-sphere () none 11) ;; (debug-draw-world-sphere (_type_) symbol 11) (collide-shape-prim-method-12 () none 12) ;; (add-fg-prim-using-box (_type_ collide-cache) none 12) (collide-shape-prim-method-13 () none 13) ;; (add-fg-prim-using-line-sphere (_type_ collide-cache) none 13) (collide-shape-prim-method-14 () none 14) ;; (add-fg-prim-using-y-probe (_type_ collide-cache) none 14) @@ -17396,6 +17404,7 @@ ((id uint32 :offset-assert 0) (collidable basic :offset-assert 4) ) + :pack-me :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 @@ -17452,7 +17461,7 @@ ) (deftype collide-hash-fragment-array (array) - () + ((fragments collide-hash-fragment :dynamic :offset 16)) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 @@ -17469,7 +17478,7 @@ (axis-scale vector :inline :offset 48) (avg-extents vector :inline :offset 64) (bucket-array uint32 :offset 44) - (item-array uint32 :offset 60) + (item-array (inline-array collide-hash-item) :offset 60 :score 1) (dimension-array uint32 3 :offset 76) ;; ? (num-items uint32 :offset 92) ) @@ -17610,7 +17619,7 @@ "Spawns associated particles with the projectile if applicable" (_type_) none 25) (spawn-shell-particles "TODO - confirm" (_type_) none 26) - (unknown-particles "TODO - confirm" (_type_) none 27) + (unknown-particles "TODO - confirm" (_type_) none 27) (play-impact-sound (_type_ projectile-options) sound-id 28) (stop-sound! "Stops the current `sound-id` if set, re-init the `sound-id` after being stopped" @@ -18167,10 +18176,14 @@ ) (declare-type collide-query structure) +(declare-type collide-list structure) + (deftype collide-cache (basic) ((num-tris int32 :offset-assert 4) + (num-tris-u32 uint32 :offset 4) (num-prims int32 :offset-assert 8) + (num-prims-u32 uint32 :offset 8) (ignore-mask pat-surface :offset-assert 12) ;; guessed by decompiler (ignore-processes process 2 :offset-assert 16) (collide-box bounding-box :inline :offset-assert 32) @@ -18187,16 +18200,16 @@ (collide-cache-method-9 () none 9) ;; (debug-draw (_type_) none 9) (fill-and-probe-using-line-sphere (_type_ collide-query) float 10) (fill-and-probe-using-spheres (_type_ collide-query) symbol 11) - (collide-cache-method-12 (_type_ collide-query) none 12) ;; (fill-and-probe-using-y-probe (_type_ vector float collide-kind process-drawable collide-tri-result pat-surface) float 12) + (fill-using-bounding-box (_type_ collide-query) none 12) ;; (fill-and-probe-using-y-probe (_type_ vector float collide-kind process-drawable collide-tri-result pat-surface) float 12) (fill-using-line-sphere (_type_ collide-query) none 13) ;; (fill-using-bounding-box (_type_ bounding-box collide-kind process-drawable pat-surface) none 13) (fill-using-spheres (_type_ collide-query) none 14) - (collide-cache-method-15 () none 15) - (collide-cache-method-16 (_type_ collide-query) float 16) ;; (fill-using-y-probe (_type_ vector float collide-kind process-drawable pat-surface) none 16) + (reset (_type_) none 15) + (probe-using-line-sphere (_type_ collide-query) float 16) ;; (fill-using-y-probe (_type_ vector float collide-kind process-drawable pat-surface) none 16) (probe-using-spheres (_type_ collide-query) symbol 17) ;; (initialize (_type_) none 17) - (collide-cache-method-18 () none 18) ;; (probe-using-line-sphere (_type_ vector vector float collide-kind collide-tri-result pat-surface) float 18) - (collide-cache-method-19 () none 19) ;; (probe-using-spheres (_type_ collide-using-spheres-params) symbol 19) - (collide-cache-method-20 () none 20) ;; (probe-using-y-probe (_type_ vector float collide-kind collide-tri-result pat-surface) float 20) - (collide-cache-method-21 () none 21) ;; (fill-from-background (_type_ (function bsp-header int collide-list none) (function collide-cache object none)) none 21) + (fill-from-bg (_type_ (function collide-hash int collide-list collide-query int) (function collide-cache collide-list collide-query none) collide-query) none 18) ;; (probe-using-line-sphere (_type_ vector vector float collide-kind collide-tri-result pat-surface) float 18) + (fill-from-fg-boxes (_type_) none 19) ;; (probe-using-spheres (_type_ collide-using-spheres-params) symbol 19) + (fill-from-fg-line-sphere (_type_) none 20) ;; (probe-using-y-probe (_type_ vector float collide-kind collide-tri-result pat-surface) float 20) + (fill-from-water (_type_ water-control) none 21) ;; (fill-from-background (_type_ (function bsp-header int collide-list none) (function collide-cache object none)) none 21) (collide-cache-method-22 () none 22) ;; (fill-from-foreground-using-box (_type_) none 22) (collide-cache-method-23 () none 23) ;; (fill-from-foreground-using-line-sphere (_type_) none 23) (collide-cache-method-24 () none 24) ;; (fill-from-foreground-using-y-probe (_type_) none 24) @@ -18204,8 +18217,10 @@ ) ) +(declare-type instance-tie basic) + (deftype collide-list-item (structure) - ((mesh collide-frag-mesh :offset-assert 0) ;; guessed by decompiler + ((mesh instance-tie :offset-assert 0) ;; guessed by decompiler (inst basic :offset-assert 4) ) :pack-me @@ -18233,11 +18248,14 @@ (deftype collide-query (structure) ((best-other-tri collide-tri-result :inline :offset-assert 0) (best-my-tri collide-tri-result :inline :offset 0) - (ignore-processes process-tree 2 :offset-assert 88) - (ignore-process0 process-tree :offset 88) - (ignore-process1 process-tree :offset 92) + (ignore-processes process-tree 2 :offset-assert 88) + (ignore-process0 process-tree :offset 88) + (ignore-process1 process-tree :offset 92) (ignore-pat pat-surface :offset-assert 96) + (ignore-pat-s32 int32 :offset 96) + (collide-with collide-spec :offset-assert 100) + (collide-with-s32 int32 :offset 100) (overlay-params uint32 3 :offset 112) ;; ? (bbox bounding-box :inline :offset-assert 128) (bbox4w bounding-box4w :inline :offset-assert 160) @@ -18245,7 +18263,7 @@ (start-pos vector :inline :offset-assert 208) (move-dist vector :inline :offset-assert 224) (rlength vector :inline :offset-assert 240) - (exit-planes plane 2 :offset-assert 256) ;; ? + (exit-planes plane 2 :inline :offset-assert 256) ;; ? (radius float :offset 268) (inv-mat matrix :inline :offset 288) (spheres (inline-array sphere) :offset 112 :score 1) @@ -26145,19 +26163,18 @@ ;; collide-hash ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern add-collide-debug-box function) -;; (define-extern print-collide-cache-tri-count function) -;; (define-extern print-exceeded-max-cache-tris function) -;; (define-extern fill-bg-using-box-new function) -;; (define-extern fill-bg-using-line-sphere-new function) -;; (define-extern collide-list-fill-bg-using-box function) -;; (define-extern collide-list-fill-bg-using-line-sphere function) +(define-extern add-collide-debug-box (function vector rgba none)) +(define-extern print-collide-cache-tri-count (function none)) +(define-extern print-exceeded-max-cache-tris (function none)) +(define-extern fill-bg-using-box-new (function collide-cache object collide-query none)) +(define-extern fill-bg-using-line-sphere-new (function collide-cache object collide-query none)) +(define-extern collide-list-fill-bg-using-box (function collide-cache collide-list collide-query none)) +(define-extern collide-list-fill-bg-using-line-sphere (function collide-cache collide-list collide-query none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; collide-probe ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype collide-probe-stack-elem (structure) ((child uint32 :offset-assert 0) (count uint32 :offset-assert 4) @@ -26166,40 +26183,37 @@ :size-assert #x8 :flag-assert #x900000008 ) -|# -#| (deftype collide-probe-stack (structure) - ((data collide-probe-stack-elem 1024 :offset-assert 0) ;; guessed by decompiler + ((data collide-probe-stack-elem 1024 :inline :offset-assert 0) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x4000 :flag-assert #x900004000 ) -|# -;; (define-extern creates-new-method? function) ;; (function type int symbol) -;; (define-extern overrides-parent-method? function) ;; (function type int symbol) -;; (define-extern describe-methods function) ;; (function type symbol) -;; (define-extern indent-to function) ;; (function int none) -;; (define-extern probe-traverse-draw-node function) ;; (function draw-node int none) -;; (define-extern probe-traverse-inline-array-node function) ;; (function drawable-inline-array-node int none) -;; (define-extern probe-traverse-collide-fragment function) ;; (function drawable-tree-collide-fragment int none) -;; (define-extern *collide-probe-stack* object) ;; collide-probe-stack -;; (define-extern collide-vu0-block object) ;; vu-function -;; (define-extern collide-probe-node function) ;; (function (inline-array draw-node) int collide-list int) -;; (define-extern print-out function) ;; (function int object) -;; (define-extern collide-probe-instance-tie-collide-frags function) ;; (function none) -;; (define-extern collide-probe-instance-tie function) ;; (function object int collide-list int int) -;; (define-extern collide-probe-collide-fragment-tree-make-list function) ;; (function drawable-tree-collide-fragment collide-list none) -;; (define-extern collide-probe-instance-tie-tree-make-list function) ;; (function drawable-tree-instance-tie collide-list int) -;; (define-extern collide-upload-vu0 function) ;; (function none) -;; (define-extern collide-probe-make-list function) ;; (function level collide-list none) -;; (define-extern distc function) ;; (function vector vector float) -;; (define-extern interpolate function) ;; (function float float float float float float) -;; (define-extern misty-ambush-height function) ;; (function vector float) -;; (define-extern misty-ambush-height-probe function) ;; (function vector float float) -;; (define-extern pke-collide-test function) ;; (function none) +(define-extern creates-new-method? (function type int symbol)) +(define-extern overrides-parent-method? (function type int symbol)) +(define-extern describe-methods (function type symbol)) +(define-extern indent-to (function int none)) +(define-extern probe-traverse-draw-node (function draw-node int none)) +(define-extern probe-traverse-inline-array-node (function drawable-inline-array-node int none)) +(define-extern probe-traverse-collide-fragment (function drawable-tree-collide-fragment int none)) +(define-extern *collide-probe-stack* collide-probe-stack) +(define-extern collide-vu0-block vu-function) +(define-extern collide-probe-node (function (inline-array draw-node) int collide-list int)) +(define-extern print-out (function int object)) +(define-extern collide-probe-instance-tie-collide-frags (function none)) +(define-extern collide-probe-instance-tie (function object int collide-list int int)) +(define-extern collide-probe-collide-fragment-tree-make-list (function drawable-tree-collide-fragment collide-list none)) +(define-extern collide-probe-instance-tie-tree-make-list (function drawable-tree-instance-tie collide-list int)) +(define-extern collide-upload-vu0 (function none)) +(define-extern collide-probe-make-list (function level collide-list none)) +(define-extern distc (function vector vector float)) +(define-extern interpolate (function float float float float float float)) +(define-extern misty-ambush-height (function vector float)) +(define-extern misty-ambush-height-probe (function vector float float)) +(define-extern pke-collide-test (function none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; collide-frag ;; @@ -28324,7 +28338,7 @@ ) (define-extern remote-track (function none :behavior remote)) -(define-extern voicebox-init-by-other (function vector handle none :behavior voicebox)) ;; +(define-extern voicebox-init-by-other (function vector handle none :behavior voicebox)) ;; (define-extern voicebox-spawn (function process-drawable vector (pointer process))) ;; (function process vector (pointer process)) (define-extern judge-init-by-other (function vector uint none :behavior judge)) (define-extern judge-spawn (function process-tree vector uint (pointer judge))) @@ -29261,9 +29275,9 @@ ;; main-collide ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-extern drawable-sphere-box-intersect? (function drawable bounding-box4w symbol)) ;; -(define-extern instance-sphere-box-intersect? (function drawable instance-tie bounding-box4w symbol)) ;; -(define-extern instance-tfragment-add-debug-sphere (function drawable instance-tie symbol)) ;; +(define-extern drawable-sphere-box-intersect? (function drawable bounding-box4w symbol)) ;; +(define-extern instance-sphere-box-intersect? (function drawable instance-tie bounding-box4w symbol)) ;; +(define-extern instance-tfragment-add-debug-sphere (function drawable instance-tie symbol)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; video ;; @@ -29328,7 +29342,6 @@ ;; collide-cache ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype collide-puls-work (structure) ((ignore-pat pat-surface :offset-assert 0) ;; guessed by decompiler (bsphere sphere :inline :offset-assert 16) @@ -29338,9 +29351,7 @@ :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype lsmi-work (structure) ((best-u float :offset-assert 0) (orig-best-u float :offset-assert 4) @@ -29351,9 +29362,8 @@ :size-assert #x22c :flag-assert #x90000022c ) -|# -;; (define-extern test-closest-pt-in-triangle function) ;; (function collide-cache symbol) +(define-extern test-closest-pt-in-triangle (function collide-cache symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; collide-debug ;; @@ -30766,15 +30776,15 @@ (define-extern *viewer* viewer) (define-extern *viewer-sg* skeleton-group) ;; skeleton-group -(define-extern viewer-process (state viewer)) ;; -(define-extern viewer-string string) ;; +(define-extern viewer-process (state viewer)) ;; +(define-extern viewer-string string) ;; (define-extern viewer-ja-name string) ;; string (define-extern viewer-geo-name string) ;; string -(define-extern actor-get-arg! (function string string string symbol)) ;; -(define-extern art-part-name (function string string)) ;; -(define-extern init-viewer (function string string none :behavior viewer)) ;; -(define-extern init-viewer-for-other (function string vector entity-actor none :behavior viewer)) ;; -(define-extern add-a-bunch (function string int int float process-tree entity-actor symbol)) ;; +(define-extern actor-get-arg! (function string string string symbol)) ;; +(define-extern art-part-name (function string string)) ;; +(define-extern init-viewer (function string string none :behavior viewer)) ;; +(define-extern init-viewer-for-other (function string vector entity-actor none :behavior viewer)) ;; +(define-extern add-a-bunch (function string int int float process-tree entity-actor symbol)) ;; (define-extern birth-viewer (function process entity-actor object)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -32854,7 +32864,7 @@ (define-extern *nav-enemy-null-callback-info* nav-callback-info) (define-extern *nav-enemy-callback-info* nav-callback-info) (define-extern *nav-enemy-physics-callback-info* nav-callback-info) -(define-extern nav-enemy-simple-post (function none :behavior nav-enemy)) ;; +(define-extern nav-enemy-simple-post (function none :behavior nav-enemy)) ;; (define-extern nav-enemy-die-falling-post (function none :behavior nav-enemy)) (define-extern nav-enemy-travel-post (function none :behavior nav-enemy)) ;; (function none :behavior nav-enemy) (define-extern nav-enemy-patrol-post (function none :behavior nav-enemy)) ;; (function none :behavior nav-enemy) @@ -32863,8 +32873,8 @@ (define-extern nav-enemy-face-focus-post (function none :behavior nav-enemy)) (define-extern nav-enemy-stare-post (function none :behavior nav-enemy)) (define-extern nav-enemy-falling-post (function none :behavior nav-enemy)) ;; (function none :behavior nav-enemy) -(define-extern nav-enemy-turn-to-face-dir (function vector float none :behavior nav-enemy)) ;; -(define-extern nav-enemy-turn-to-face-point (function vector float none :behavior nav-enemy)) ;; +(define-extern nav-enemy-turn-to-face-dir (function vector float none :behavior nav-enemy)) ;; +(define-extern nav-enemy-turn-to-face-point (function vector float none :behavior nav-enemy)) ;; (define-extern *nav-enemy-debug-control-info* nav-enemy-debug-control-info) (define-extern nav-enemy-debug-control-post (function none :behavior nav-enemy)) diff --git a/decompiler/config/jak2/hacks.jsonc b/decompiler/config/jak2/hacks.jsonc index f0b61d0634..02f75a30fd 100644 --- a/decompiler/config/jak2/hacks.jsonc +++ b/decompiler/config/jak2/hacks.jsonc @@ -345,6 +345,7 @@ "(method 11 sparticle-launch-control)": [ 18, 24, 25, 28, 29, 32, 33, 34, 36, 41, 55, 58, 93, 95 ], + "(method 22 gui-control)": [ 10, // goto L63 (B39) 16, // goto L58 (B27) @@ -362,9 +363,11 @@ 117, // goto L91 120 ], + "(anon-function 11 game-save)": [0, 3, 4, 5], "update-actor-hash": [0, 2, 4], - "(code target-death)": [111, 140] + "(code target-death)": [111, 140], + "(method 13 collide-cache)": [7, 9] }, // Sometimes the game might use format strings that are fetched dynamically, @@ -426,7 +429,11 @@ "(method 33 sky-work)", "(method 28 sky-work)", "(method 29 sky-work)", - "(method 30 sky-work)" + "(method 30 sky-work)", + "(method 11 collide-hash)", + "(method 12 collide-hash)", + "fill-bg-using-box-new", + "fill-bg-using-line-sphere-new" ], "mips2c_jump_table_functions": {}, diff --git a/decompiler/config/jak2/stack_structures.jsonc b/decompiler/config/jak2/stack_structures.jsonc index dbd50c0ce1..e6d775c2bf 100644 --- a/decompiler/config/jak2/stack_structures.jsonc +++ b/decompiler/config/jak2/stack_structures.jsonc @@ -1102,5 +1102,17 @@ "(code target-carry-drop)": [[672, ["inline-array", "sphere", 1]]], "(code target-carry-throw)": [[640, ["inline-array", "sphere", 1]]], "(code target-hit)": [[16, "vector"]], - "(method 39 battle)": [[64, "transformq"]] + "(method 39 battle)": [[64, "transformq"]], + "add-collide-debug-box":[ + [16, "bounding-box"] + ], + "collide-list-fill-bg-using-box": [ + [32, "matrix"], + [96, "collide-query"] + ], + "collide-list-fill-bg-using-line-sphere": [ + [32, "matrix"], + [96, "collide-query"] + ], + "add-a-bunch": [[16, "vector"]] } diff --git a/decompiler/config/jak2/type_casts.jsonc b/decompiler/config/jak2/type_casts.jsonc index f64619586b..94e07cec6e 100644 --- a/decompiler/config/jak2/type_casts.jsonc +++ b/decompiler/config/jak2/type_casts.jsonc @@ -4048,5 +4048,27 @@ "(method 29 battle)": [ ["_stack_", 16, "res-tag"], ["_stack_", 32, "res-tag"] + ], + "(method 12 collide-cache)": [ + [76, "v1", "process-drawable"] + ], + "collide-list-fill-bg-using-box": [ + [[207, 213], "v1", "collide-hash-scratch"], + [223, "a0", "collide-hash-scratch"], + [[241, 247], "v1", "collide-hash-scratch"], + [255, "a0", "collide-hash-scratch"] + ], + "collide-list-fill-bg-using-line-sphere": [ + [261, "a0", "collide-hash-scratch"], + [[279, 285], "v1", "collide-hash-scratch"], + [[246, 251], "v1", "collide-hash-scratch"], + [293, "a0", "collide-hash-scratch"], + [102, "v1", "float"] + ], + "(method 8 collide-hash)": [ + [34, "a1", "collide-hash-scratch"], + [50, "a2", "collide-hash-scratch"], + [62, "a2", "collide-hash-scratch"], + [73, "a1", "collide-hash-scratch"] ] } diff --git a/decompiler/types2/types2.cpp b/decompiler/types2/types2.cpp index 6c473acce8..81d684a7ad 100644 --- a/decompiler/types2/types2.cpp +++ b/decompiler/types2/types2.cpp @@ -750,12 +750,13 @@ end_type_pass: auto& type = instr.unknown_stack_structure_tag->selected_type.value(); int offset = instr.unknown_stack_structure_tag->stack_offset; - ASSERT(type.base_type() != "pointer"); // want to test this if we find example... - StackStructureHint hint; - hint.stack_offset = offset; - hint.container_type = StackStructureHint::ContainerType::NONE; - hint.element_type = type.print(); - env.add_stack_structure_hint(hint); + if (type.base_type() != "pointer") { + StackStructureHint hint; + hint.stack_offset = offset; + hint.container_type = StackStructureHint::ContainerType::NONE; + hint.element_type = type.print(); + env.add_stack_structure_hint(hint); + } } } diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index d3cb89bcdc..5de75b3e8f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -83,6 +83,7 @@ set(RUNTIME_SOURCE mips2c/jak1_functions/tie_methods.cpp mips2c/jak1_functions/time_of_day.cpp mips2c/jak2_functions/collide_func.cpp + mips2c/jak2_functions/collide_hash.cpp mips2c/jak2_functions/debug.cpp mips2c/jak2_functions/font.cpp mips2c/jak2_functions/joint.cpp diff --git a/game/mips2c/jak2_functions/collide_hash.cpp b/game/mips2c/jak2_functions/collide_hash.cpp new file mode 100644 index 0000000000..d7e14a113e --- /dev/null +++ b/game/mips2c/jak2_functions/collide_hash.cpp @@ -0,0 +1,1541 @@ +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace method_11_collide_hash { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + c->daddiu(sp, sp, -96); // daddiu sp, sp, -96 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s2, 16, sp); // sq s2, 16(sp) + c->sq(s3, 32, sp); // sq s3, 32(sp) + c->sq(s4, 48, sp); // sq s4, 48(sp) + c->sq(s5, 64, sp); // sq s5, 64(sp) + c->sq(gp, 80, sp); // sq gp, 80(sp) + c->addiu(v1, r0, 0); // addiu v1, r0, 0 + //beq r0, r0, L91 // beq r0, r0, L91 + // nop // sll r0, r0, 0 + goto block_2; // branch always + + + block_1: + c->dsll(a1, v1, 4); // dsll a1, v1, 4 + get_fake_spad_addr2(t0, cache.fake_scratchpad_data, 0, c);// lui t0, 28672 + c->daddu(a1, a1, t0); // daddu a1, a1, t0 + c->sq(r0, 0, a1); // sq r0, 0(a1) + c->daddiu(v1, v1, 1); // daddiu v1, v1, 1 + + block_2: + c->lwu(a1, 8, a0); // lwu a1, 8(a0) + c->slt(a1, v1, a1); // slt a1, v1, a1 + bc = c->sgpr64(a1) != 0; // bne a1, r0, L90 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + c->mov64(v1, s7); // or v1, s7, r0 + // nop // sll r0, r0, 0 + c->lw(v1, 72, a0); // lw v1, 72(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf1, 28, a0); // lqc2 vf1, 28(a0) + c->lui(a1, 1); // lui a1, 1 + c->lqc2(vf2, 128, a3); // lqc2 vf2, 128(a3) + c->ori(a1, a1, 257); // ori a1, a1, 257 + c->lqc2(vf3, 144, a3); // lqc2 vf3, 144(a3) + c->dsubu(v1, v1, a1); // dsubu v1, v1, a1 + c->lqc2(vf4, 44, a0); // lqc2 vf4, 44(a0) + c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1 + c->lq(a1, 160, a3); // lq a1, 160(a3) + c->vsub(DEST::xyzw, vf3, vf3, vf1); // vsub.xyzw vf3, vf3, vf1 + c->lq(t0, 176, a3); // lq t0, 176(a3) + c->pextlb(v1, r0, v1); // pextlb v1, r0, v1 + c->lq(t1, 60, a0); // lq t1, 60(a0) + c->pextlh(v1, r0, v1); // pextlh v1, r0, v1 + c->lq(t2, 76, a0); // lq t2, 76(a0) + c->pcgtw(t0, t1, t0); // pcgtw t0, t1, t0 + c->vmul(DEST::xyzw, vf2, vf2, vf4); // vmul.xyzw vf2, vf2, vf4 + c->pcgtw(a1, a1, t2); // pcgtw a1, a1, t2 + c->vmul(DEST::xyzw, vf3, vf3, vf4); // vmul.xyzw vf3, vf3, vf4 + c->por(a1, t0, a1); // por a1, t0, a1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->ppach(a1, r0, a1); // ppach a1, r0, a1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->dsll(a1, a1, 16); // dsll a1, a1, 16 + c->vftoi0(DEST::xyzw, vf2, vf2); // vftoi0.xyzw vf2, vf2 + bc = c->sgpr64(a1) != 0; // bne a1, r0, L98 + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + if (bc) {goto block_16;} // branch non-likely + + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf2); // qmfc2.i t0, vf2 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a1, vf3); // qmfc2.i a1, vf3 + c->pmaxw(t0, t0, r0); // pmaxw t0, t0, r0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pmaxw(a1, a1, r0); // pmaxw a1, a1, r0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pminw(t0, t0, v1); // pminw t0, t0, v1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pminw(v1, a1, v1); // pminw v1, a1, v1 + c->mfc1(r0, f31); // mfc1 r0, f31 + // nop // sll r0, r0, 0 + c->sq(t0, 400, a3); // sq t0, 400(a3) + // nop // sll r0, r0, 0 + c->sq(v1, 416, a3); // sq v1, 416(a3) + c->addiu(v1, r0, 4); // addiu v1, r0, 4 + c->lbu(a1, 72, a0); // lbu a1, 72(a0) + c->multu3(a1, a1, v1); // multu3 a1, a1, v1 + c->lbu(t0, 74, a0); // lbu t0, 74(a0) + c->multu3(t0, t0, a1); // multu3 t0, t0, a1 + c->addiu(t1, r0, 1); // addiu t1, r0, 1 + c->lw(t2, 400, a3); // lw t2, 400(a3) + c->dsubu(t1, t1, t2); // dsubu t1, t1, t2 + c->lw(t2, 416, a3); // lw t2, 416(a3) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->addiu(t2, r0, 1); // addiu t2, r0, 1 + c->lw(t3, 404, a3); // lw t3, 404(a3) + c->dsubu(t2, t2, t3); // dsubu t2, t2, t3 + c->lw(t3, 420, a3); // lw t3, 420(a3) + c->daddu(t4, t2, t3); // daddu t4, t2, t3 + c->addiu(t2, r0, 1); // addiu t2, r0, 1 + c->lw(t3, 408, a3); // lw t3, 408(a3) + c->dsubu(t2, t2, t3); // dsubu t2, t2, t3 + c->lw(t3, 424, a3); // lw t3, 424(a3) + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->lwu(t3, 40, a0); // lwu t3, 40(a0) + c->lw(t5, 400, a3); // lw t5, 400(a3) + c->mult3(t5, t5, v1); // mult3 t5, t5, v1 + c->lw(t6, 404, a3); // lw t6, 404(a3) + c->mult3(t6, t6, t0); // mult3 t6, t6, t0 + c->daddu(t5, t5, t6); // daddu t5, t5, t6 + c->lw(t6, 408, a3); // lw t6, 408(a3) + c->mult3(t6, t6, a1); // mult3 t6, t6, a1 + c->daddu(t5, t5, t6); // daddu t5, t5, t6 + c->daddu(t3, t3, t5); // daddu t3, t3, t5 + c->mov64(t4, t4); // or t4, t4, r0 + // nop // sll r0, r0, 0 + + block_5: + c->mov64(t5, t2); // or t5, t2, r0 + c->mov64(t6, t3); // or t6, t3, r0 + + block_6: + c->mov64(t7, t1); // or t7, t1, r0 + c->mov64(t8, t6); // or t8, t6, r0 + + block_7: + // nop // sll r0, r0, 0 + c->lhu(t9, 0, t8); // lhu t9, 0(t8) + // nop // sll r0, r0, 0 + c->lw(ra, 56, a0); // lw ra, 56(a0) + c->sll(gp, t9, 3); // sll gp, t9, 3 + c->lhu(t9, 2, t8); // lhu t9, 2(t8) + bc = c->sgpr64(t9) == 0; // beq t9, r0, L97 + c->daddu(ra, gp, ra); // daddu ra, gp, ra + if (bc) {goto block_13;} // branch non-likely + + + block_8: + get_fake_spad_addr2(s5, cache.fake_scratchpad_data, 0, c);// lui s5, 28672 + c->lw(s2, 0, ra); // lw s2, 0(ra) + c->addiu(s4, r0, 1); // addiu s4, r0, 1 + c->lw(gp, 4, ra); // lw gp, 4(ra) + c->andi(s3, s2, 7); // andi s3, s2, 7 + c->sra(s2, s2, 3); // sra s2, s2, 3 + c->daddu(s5, s2, s5); // daddu s5, s2, s5 + c->lqc2(vf8, 12, gp); // lqc2 vf8, 12(gp) + c->sllv(s4, s4, s3); // sllv s4, s4, s3 + c->lb(s3, 0, s5); // lb s3, 0(s5) + c->and_(s2, s3, s4); // and s2, s3, s4 + c->daddiu(t9, t9, -1); // daddiu t9, t9, -1 + bc = c->sgpr64(s2) != 0; // bne s2, r0, L96 + c->or_(s4, s3, s4); // or s4, s3, s4 + if (bc) {goto block_12;} // branch non-likely + + c->vsub_bc(DEST::xyzw, BC::w, vf2, vf8, vf8); // vsubw.xyzw vf2, vf8, vf8 + c->sb(s4, 0, s5); // sb s4, 0(s5) + c->vadd_bc(DEST::xyzw, BC::w, vf3, vf8, vf8); // vaddw.xyzw vf3, vf8, vf8 + // nop // sll r0, r0, 0 + c->vftoi0(DEST::xyzw, vf2, vf2); // vftoi0.xyzw vf2, vf2 + c->lq(s5, 160, a3); // lq s5, 160(a3) + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + c->lq(s3, 176, a3); // lq s3, 176(a3) + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(s2, vf2); // qmfc2.i s2, vf2 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(s4, vf3); // qmfc2.i s4, vf3 + c->pcgtw(s3, s2, s3); // pcgtw s3, s2, s3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcgtw(s5, s5, s4); // pcgtw s5, s5, s4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->por(s5, s3, s5); // por s5, s3, s5 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->ppach(s5, r0, s5); // ppach s5, r0, s5 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->dsll(s5, s5, 16); // dsll s5, s5, 16 + // nop // sll r0, r0, 0 + bc = c->sgpr64(s5) != 0; // bne s5, r0, L96 + // nop // sll r0, r0, 0 + if (bc) {goto block_12;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(s4, 0, a2); // lw s4, 0(a2) + c->daddiu(s3, s4, -256); // daddiu s3, s4, -256 + c->sll(s5, s4, 3); // sll s5, s4, 3 + bc = ((s64)c->sgpr64(s3)) >= 0; // bgez s3, L98 + c->daddiu(s4, s4, 1); // daddiu s4, s4, 1 + if (bc) {goto block_16;} // branch non-likely + + c->daddu(s5, s5, a2); // daddu s5, s5, a2 + c->sw(s4, 0, a2); // sw s4, 0(a2) + // nop // sll r0, r0, 0 + c->sw(s7, 20, s5); // sw s7, 20(s5) + // nop // sll r0, r0, 0 + c->sw(gp, 16, s5); // sw gp, 16(s5) + + block_12: + bc = ((s64)c->sgpr64(t9)) > 0; // bgtz t9, L95 + c->daddiu(ra, ra, 8); // daddiu ra, ra, 8 + if (bc) {goto block_8;} // branch non-likely + + + block_13: + c->daddiu(t7, t7, -1); // daddiu t7, t7, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t7) != 0; // bne t7, r0, L94 + c->daddu(t8, t8, v1); // daddu t8, t8, v1 + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t5, t5, -1); // daddiu t5, t5, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t5) != 0; // bne t5, r0, L93 + c->daddu(t6, t6, a1); // daddu t6, t6, a1 + if (bc) {goto block_6;} // branch non-likely + + c->daddiu(t4, t4, -1); // daddiu t4, t4, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t4) != 0; // bne t4, r0, L92 + c->daddu(t3, t3, t0); // daddu t3, t3, t0 + if (bc) {goto block_5;} // branch non-likely + + + block_16: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 80, sp); // lq gp, 80(sp) + c->lq(s5, 64, sp); // lq s5, 64(sp) + c->lq(s4, 48, sp); // lq s4, 48(sp) + c->lq(s3, 32, sp); // lq s3, 32(sp) + c->lq(s2, 16, sp); // lq s2, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 96); // daddiu sp, sp, 96 + 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() { + cache.fake_scratchpad_data = intern_from_c("*fake-scratchpad-data*").c(); + gLinkedFunctionTable.reg("(method 11 collide-hash)", execute, 256); +} + +} // namespace method_11_collide_hash +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace method_12_collide_hash { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -112); // daddiu sp, sp, -112 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s1, 16, sp); // sq s1, 16(sp) + c->sq(s2, 32, sp); // sq s2, 32(sp) + c->sq(s3, 48, sp); // sq s3, 48(sp) + c->sq(s4, 64, sp); // sq s4, 64(sp) + c->sq(s5, 80, sp); // sq s5, 80(sp) + c->sq(gp, 96, sp); // sq gp, 96(sp) + c->addiu(v1, r0, 0); // addiu v1, r0, 0 + //beq r0, r0, L81 // beq r0, r0, L81 + // nop // sll r0, r0, 0 + goto block_2; // branch always + + + block_1: + c->dsll(a1, v1, 4); // dsll a1, v1, 4 + get_fake_spad_addr2(t0, cache.fake_scratchpad_data, 0, c);// lui t0, 28672 + c->daddu(a1, a1, t0); // daddu a1, a1, t0 + c->sq(r0, 0, a1); // sq r0, 0(a1) + c->daddiu(v1, v1, 1); // daddiu v1, v1, 1 + + block_2: + c->lwu(a1, 8, a0); // lwu a1, 8(a0) + c->slt(a1, v1, a1); // slt a1, v1, a1 + bc = c->sgpr64(a1) != 0; // bne a1, r0, L80 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + c->mov64(v1, s7); // or v1, s7, r0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->lw(v1, 72, a0); // lw v1, 72(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf2, 28, a0); // lqc2 vf2, 28(a0) + c->lui(a1, 1); // lui a1, 1 + c->lqc2(vf3, 128, a3); // lqc2 vf3, 128(a3) + c->ori(a1, a1, 257); // ori a1, a1, 257 + c->lqc2(vf4, 144, a3); // lqc2 vf4, 144(a3) + c->dsubu(v1, v1, a1); // dsubu v1, v1, a1 + c->lqc2(vf5, 44, a0); // lqc2 vf5, 44(a0) + c->vsub(DEST::xyzw, vf3, vf3, vf2); // vsub.xyzw vf3, vf3, vf2 + c->lq(a1, 160, a3); // lq a1, 160(a3) + c->vsub(DEST::xyzw, vf4, vf4, vf2); // vsub.xyzw vf4, vf4, vf2 + c->lq(t0, 176, a3); // lq t0, 176(a3) + c->pextlb(v1, r0, v1); // pextlb v1, r0, v1 + c->lq(t1, 60, a0); // lq t1, 60(a0) + c->pextlh(v1, r0, v1); // pextlh v1, r0, v1 + c->lq(t2, 76, a0); // lq t2, 76(a0) + c->pcgtw(t0, t1, t0); // pcgtw t0, t1, t0 + c->vmul(DEST::xyzw, vf3, vf3, vf5); // vmul.xyzw vf3, vf3, vf5 + c->pcgtw(a1, a1, t2); // pcgtw a1, a1, t2 + c->vmul(DEST::xyzw, vf4, vf4, vf5); // vmul.xyzw vf4, vf4, vf5 + c->por(a1, t0, a1); // por a1, t0, a1 + c->lqc2(vf10, 256, a3); // lqc2 vf10, 256(a3) + c->ppach(a1, r0, a1); // ppach a1, r0, a1 + c->lqc2(vf11, 272, a3); // lqc2 vf11, 272(a3) + c->dsll(a1, a1, 16); // dsll a1, a1, 16 + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + bc = c->sgpr64(a1) != 0; // bne a1, r0, L88 + c->vftoi0(DEST::xyzw, vf4, vf4); // vftoi0.xyzw vf4, vf4 + if (bc) {goto block_19;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lqc2(vf8, 208, a3); // lqc2 vf8, 208(a3) + // nop // sll r0, r0, 0 + c->lqc2(vf9, 224, a3); // lqc2 vf9, 224(a3) + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf3); // qmfc2.i t0, vf3 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a1, vf4); // qmfc2.i a1, vf4 + c->pmaxw(t0, t0, r0); // pmaxw t0, t0, r0 + c->lqc2(vf6, 12, a0); // lqc2 vf6, 12(a0) + c->pmaxw(a1, a1, r0); // pmaxw a1, a1, r0 + c->lqc2(vf7, 240, a3); // lqc2 vf7, 240(a3) + c->pminw(t0, t0, v1); // pminw t0, t0, v1 + c->vmax_bc(DEST::xyzw, BC::w, vf1, vf0, vf0); // vmaxw.xyzw vf1, vf0, vf0 + c->pminw(v1, a1, v1); // pminw v1, a1, v1 + c->mfc1(r0, f31); // mfc1 r0, f31 + // nop // sll r0, r0, 0 + c->sq(t0, 400, a3); // sq t0, 400(a3) + // nop // sll r0, r0, 0 + c->sq(v1, 416, a3); // sq v1, 416(a3) + c->addiu(v1, r0, 4); // addiu v1, r0, 4 + c->lbu(a1, 72, a0); // lbu a1, 72(a0) + c->multu3(a1, a1, v1); // multu3 a1, a1, v1 + c->lbu(t0, 74, a0); // lbu t0, 74(a0) + c->multu3(t0, t0, a1); // multu3 t0, t0, a1 + c->addiu(t1, r0, 1); // addiu t1, r0, 1 + c->lw(t2, 400, a3); // lw t2, 400(a3) + c->dsubu(t1, t1, t2); // dsubu t1, t1, t2 + c->lw(t2, 416, a3); // lw t2, 416(a3) + c->daddu(t1, t1, t2); // daddu t1, t1, t2 + c->addiu(t2, r0, 1); // addiu t2, r0, 1 + c->lw(t3, 404, a3); // lw t3, 404(a3) + c->dsubu(t2, t2, t3); // dsubu t2, t2, t3 + c->lw(t3, 420, a3); // lw t3, 420(a3) + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->addiu(t3, r0, 1); // addiu t3, r0, 1 + c->lw(t4, 408, a3); // lw t4, 408(a3) + c->dsubu(t3, t3, t4); // dsubu t3, t3, t4 + c->lw(t4, 424, a3); // lw t4, 424(a3) + c->daddu(t3, t3, t4); // daddu t3, t3, t4 + c->lwu(t4, 40, a0); // lwu t4, 40(a0) + c->lw(t5, 400, a3); // lw t5, 400(a3) + c->mult3(t5, t5, v1); // mult3 t5, t5, v1 + c->lw(t6, 404, a3); // lw t6, 404(a3) + c->mult3(t6, t6, t0); // mult3 t6, t6, t0 + c->daddu(t5, t5, t6); // daddu t5, t5, t6 + c->lw(t6, 408, a3); // lw t6, 408(a3) + c->mult3(t6, t6, a1); // mult3 t6, t6, a1 + c->daddu(t5, t5, t6); // daddu t5, t5, t6 + c->daddu(t4, t4, t5); // daddu t4, t4, t5 + c->mov64(t5, t2); // or t5, t2, r0 + // nop // sll r0, r0, 0 + + block_5: + c->mov64(t6, t3); // or t6, t3, r0 + c->mov64(t7, t4); // or t7, t4, r0 + + block_6: + c->mov64(t8, t1); // or t8, t1, r0 + c->mov64(t9, t7); // or t9, t7, r0 + + block_7: + c->dsubu(s3, t1, t8); // dsubu s3, t1, t8 + c->lw(s2, 400, a3); // lw s2, 400(a3) + c->dsubu(s5, t2, t5); // dsubu s5, t2, t5 + c->lw(s4, 404, a3); // lw s4, 404(a3) + c->dsubu(ra, t3, t6); // dsubu ra, t3, t6 + c->lw(gp, 408, a3); // lw gp, 408(a3) + c->daddu(s3, s3, s2); // daddu s3, s3, s2 + c->sw(r0, 444, a3); // sw r0, 444(a3) + c->daddu(s5, s5, s4); // daddu s5, s5, s4 + c->sw(s3, 432, a3); // sw s3, 432(a3) + c->daddu(ra, ra, gp); // daddu ra, ra, gp + c->sw(s5, 436, a3); // sw s5, 436(a3) + // nop // sll r0, r0, 0 + c->sw(ra, 440, a3); // sw ra, 440(a3) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 432, a3); // lqc2 vf3, 432(a3) + c->vitof0(DEST::xyzw, vf3, vf3); // vitof0.xyzw vf3, vf3 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf3, vf6); // vmula.xyzw acc, vf3, vf6 + // nop // sll r0, r0, 0 + c->vmadda(DEST::xyzw, vf1, vf2); // vmadda.xyzw acc, vf1, vf2 + // nop // sll r0, r0, 0 + c->vmsub_bc(DEST::xyzw, BC::w, vf3, vf1, vf10); // vmsubw.xyzw vf3, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmadda(DEST::xyzw, vf1, vf6); // vmadda.xyzw acc, vf1, vf6 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf4, vf1, vf10); // vmaddw.xyzw vf4, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf3); // vmula.xyzw acc, vf7, vf3 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf13, vf1, vf10); // vmsub.xyzw vf13, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf15, vf1, vf11); // vmadd.xyzw vf15, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf4); // vmula.xyzw acc, vf7, vf4 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf14, vf1, vf11); // vmsub.xyzw vf14, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf16, vf1, vf10); // vmadd.xyzw vf16, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmax(DEST::xyzw, vf13, vf13, vf14); // vmax.xyzw vf13, vf13, vf14 + // nop // sll r0, r0, 0 + c->vmini(DEST::xyzw, vf15, vf15, vf16); // vmini.xyzw vf15, vf15, vf16 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::y, vf13, vf13, vf13); // vmaxy.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::y, vf15, vf15, vf15); // vminiy.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::z, vf13, vf13, vf13); // vmaxz.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::z, vf15, vf15, vf15); // vminiz.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vftoi4(DEST::xyzw, vf13, vf13); // vftoi4.xyzw vf13, vf13 + // nop // sll r0, r0, 0 + c->vftoi4(DEST::xyzw, vf15, vf15); // vftoi4.xyzw vf15, vf15 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(s5, vf13); // qmfc2.i s5, vf13 + c->addiu(s4, r0, 4096); // addiu s4, r0, 4096 + c->mov128_gpr_vf(ra, vf15); // qmfc2.i ra, vf15 + c->subu(gp, ra, s5); // subu gp, ra, s5 + c->subu(s5, s4, s5); // subu s5, s4, s5 + bc = ((s64)c->sgpr64(gp)) < 0; // bltz gp, L87 + // nop // sll r0, r0, 0 + if (bc) {goto block_16;} // branch non-likely + + bc = ((s64)c->sgpr64(s5)) < 0; // bltz s5, L87 + // nop // sll r0, r0, 0 + if (bc) {goto block_16;} // branch non-likely + + bc = ((s64)c->sgpr64(ra)) < 0; // bltz ra, L87 + // nop // sll r0, r0, 0 + if (bc) {goto block_16;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lhu(ra, 0, t9); // lhu ra, 0(t9) + // nop // sll r0, r0, 0 + c->lw(gp, 56, a0); // lw gp, 56(a0) + c->sll(s5, ra, 3); // sll s5, ra, 3 + c->lhu(ra, 2, t9); // lhu ra, 2(t9) + bc = c->sgpr64(ra) == 0; // beq ra, r0, L87 + c->daddu(gp, s5, gp); // daddu gp, s5, gp + if (bc) {goto block_16;} // branch non-likely + + + block_11: + get_fake_spad_addr2(s4, cache.fake_scratchpad_data, 0, c);// lui s4, 28672 + c->lw(s1, 0, gp); // lw s1, 0(gp) + c->addiu(s3, r0, 1); // addiu s3, r0, 1 + c->lw(s5, 4, gp); // lw s5, 4(gp) + c->andi(s2, s1, 7); // andi s2, s1, 7 + c->sra(s1, s1, 3); // sra s1, s1, 3 + c->daddu(s4, s1, s4); // daddu s4, s1, s4 + c->lqc2(vf12, 12, s5); // lqc2 vf12, 12(s5) + c->sllv(s3, s3, s2); // sllv s3, s3, s2 + c->lb(s2, 0, s4); // lb s2, 0(s4) + c->and_(s1, s2, s3); // and s1, s2, s3 + c->daddiu(ra, ra, -1); // daddiu ra, ra, -1 + bc = c->sgpr64(s1) != 0; // bne s1, r0, L86 + c->or_(s3, s2, s3); // or s3, s2, s3 + if (bc) {goto block_15;} // branch non-likely + + c->vmula(DEST::xyzw, vf9, vf12); // vmula.xyzw acc, vf9, vf12 + c->sb(s3, 0, s4); // sb s3, 0(s4) + c->vmsub(DEST::xyzw, vf13, vf9, vf8); // vmsub.xyzw vf13, vf9, vf8 + // nop // sll r0, r0, 0 + c->vmul_bc(DEST::xyzw, BC::w, vf14, vf1, vf7); // vmulw.xyzw vf14, vf1, vf7 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::w, vf1, vf12); // vmulaw.xyzw acc, vf1, vf12 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf15, vf1, vf10); // vmaddw.xyzw vf15, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::w, vf13, vf7); // vmulaw.xyzw acc, vf13, vf7 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf14, vf13); // vmadday.xyzw acc, vf14, vf13 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::z, vf13, vf14, vf13); // vmaddz.xyzw vf13, vf14, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::w, vf13, vf13, vf0); // vminiw.xyzw vf13, vf13, vf0 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::x, vf13, vf13, vf0); // vmaxx.xyzw vf13, vf13, vf0 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf9, vf13); // vmulax.xyzw acc, vf9, vf13 + // nop // sll r0, r0, 0 + c->vmadda(DEST::xyzw, vf1, vf8); // vmadda.xyzw acc, vf1, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf13, vf1, vf12); // vmsub.xyzw vf13, vf1, vf12 + // nop // sll r0, r0, 0 + c->vmul(DEST::xyzw, vf13, vf13, vf13); // vmul.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf0, vf0); // vmulax.xyzw acc, vf0, vf0 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf15, vf15); // vmsuba.xyzw acc, vf15, vf15 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::x, vf1, vf13); // vmaddax.xyzw acc, vf1, vf13 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf1, vf13); // vmadday.xyzw acc, vf1, vf13 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::z, vf13, vf1, vf13); // vmaddz.xyzw vf13, vf1, vf13 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(s4, vf13); // qmfc2.i s4, vf13 + bc = ((s64)c->sgpr64(s4)) > 0; // bgtz s4, L86 + // nop // sll r0, r0, 0 + if (bc) {goto block_15;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(s3, 0, a2); // lw s3, 0(a2) + c->daddiu(s2, s3, -256); // daddiu s2, s3, -256 + c->sll(s4, s3, 3); // sll s4, s3, 3 + bc = ((s64)c->sgpr64(s2)) >= 0; // bgez s2, L88 + c->daddiu(s3, s3, 1); // daddiu s3, s3, 1 + if (bc) {goto block_19;} // branch non-likely + + c->daddu(s4, s4, a2); // daddu s4, s4, a2 + c->sw(s3, 0, a2); // sw s3, 0(a2) + // nop // sll r0, r0, 0 + c->sw(s7, 20, s4); // sw s7, 20(s4) + // nop // sll r0, r0, 0 + c->sw(s5, 16, s4); // sw s5, 16(s4) + + block_15: + bc = ((s64)c->sgpr64(ra)) > 0; // bgtz ra, L85 + c->daddiu(gp, gp, 8); // daddiu gp, gp, 8 + if (bc) {goto block_11;} // branch non-likely + + + block_16: + c->daddiu(t8, t8, -1); // daddiu t8, t8, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t8) != 0; // bne t8, r0, L84 + c->daddu(t9, t9, v1); // daddu t9, t9, v1 + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t6, t6, -1); // daddiu t6, t6, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t6) != 0; // bne t6, r0, L83 + c->daddu(t7, t7, a1); // daddu t7, t7, a1 + if (bc) {goto block_6;} // branch non-likely + + c->daddiu(t5, t5, -1); // daddiu t5, t5, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t5) != 0; // bne t5, r0, L82 + c->daddu(t4, t4, t0); // daddu t4, t4, t0 + if (bc) {goto block_5;} // branch non-likely + + + block_19: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 96, sp); // lq gp, 96(sp) + c->lq(s5, 80, sp); // lq s5, 80(sp) + c->lq(s4, 64, sp); // lq s4, 64(sp) + c->lq(s3, 48, sp); // lq s3, 48(sp) + c->lq(s2, 32, sp); // lq s2, 32(sp) + c->lq(s1, 16, sp); // lq s1, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 112); // daddiu sp, sp, 112 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.fake_scratchpad_data = intern_from_c("*fake-scratchpad-data*").c(); + gLinkedFunctionTable.reg("(method 12 collide-hash)", execute, 256); +} + +} // namespace method_12_collide_hash +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace fill_bg_using_box_new { +struct Cache { + void* cheat_mode; // *cheat-mode* + void* collide_stats; // *collide-stats* + void* fake_scratchpad_data; // *fake-scratchpad-data* + void* debug; // debug + void* print_exceeded_max_cache_tris; // print-exceeded-max-cache-tris +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -128); // daddiu sp, sp, -128 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s0, 16, sp); // sq s0, 16(sp) + c->sq(s1, 32, sp); // sq s1, 32(sp) + c->sq(s2, 48, sp); // sq s2, 48(sp) + c->sq(s3, 64, sp); // sq s3, 64(sp) + c->sq(s4, 80, sp); // sq s4, 80(sp) + c->sq(s5, 96, sp); // sq s5, 96(sp) + c->sq(gp, 112, sp); // sq gp, 112(sp) + // nop // sll r0, r0, 0 + c->lw(v1, 40, a1); // lw v1, 40(a1) + // nop // sll r0, r0, 0 + c->lqc2(vf1, 44, a1); // lqc2 vf1, 44(a1) + c->lui(a3, 1); // lui a3, 1 + c->lqc2(vf2, 128, a2); // lqc2 vf2, 128(a2) + c->ori(a3, a3, 257); // ori a3, a3, 257 + c->lqc2(vf3, 144, a2); // lqc2 vf3, 144(a2) + c->dsubu(v1, v1, a3); // dsubu v1, v1, a3 + c->lqc2(vf6, 60, a1); // lqc2 vf6, 60(a1) + c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1 + c->lq(a3, 160, a2); // lq a3, 160(a2) + c->vsub(DEST::xyzw, vf3, vf3, vf1); // vsub.xyzw vf3, vf3, vf1 + c->lq(t0, 176, a2); // lq t0, 176(a2) + c->pextlb(v1, r0, v1); // pextlb v1, r0, v1 + c->lq(t1, 76, a1); // lq t1, 76(a1) + c->pextlh(v1, r0, v1); // pextlh v1, r0, v1 + c->lq(t2, 92, a1); // lq t2, 92(a1) + c->pcgtw(t0, t1, t0); // pcgtw t0, t1, t0 + c->vftoi0(DEST::xyzw, vf4, vf2); // vftoi0.xyzw vf4, vf2 + c->pcgtw(a3, a3, t2); // pcgtw a3, a3, t2 + c->vftoi0(DEST::xyzw, vf5, vf3); // vftoi0.xyzw vf5, vf3 + c->por(a3, t0, a3); // por a3, t0, a3 + c->vmul(DEST::xyzw, vf2, vf2, vf6); // vmul.xyzw vf2, vf2, vf6 + c->ppach(a3, r0, a3); // ppach a3, r0, a3 + c->vmul(DEST::xyzw, vf3, vf3, vf6); // vmul.xyzw vf3, vf3, vf6 + c->dsll(t0, a3, 16); // dsll t0, a3, 16 + c->mov128_gpr_vf(a3, vf4); // qmfc2.i a3, vf4 + bc = c->sgpr64(t0) != 0; // bne t0, r0, L75 + c->mov128_gpr_vf(t0, vf5); // qmfc2.i t0, vf5 + if (bc) {goto block_17;} // branch non-likely + + c->vftoi0(DEST::xyzw, vf2, vf2); // vftoi0.xyzw vf2, vf2 + c->psraw(a3, a3, 4); // psraw a3, a3, 4 + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + c->psraw(t0, t0, 4); // psraw t0, t0, 4 + // nop // sll r0, r0, 0 + c->sq(a3, 368, a2); // sq a3, 368(a2) + // nop // sll r0, r0, 0 + c->sq(t0, 384, a2); // sq t0, 384(a2) + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf2); // qmfc2.i t0, vf2 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf3); // qmfc2.i a3, vf3 + c->pmaxw(t0, t0, r0); // pmaxw t0, t0, r0 + c->lqc2(vf10, 448, a2); // lqc2 vf10, 448(a2) + c->pmaxw(a3, a3, r0); // pmaxw a3, a3, r0 + c->lqc2(vf11, 464, a2); // lqc2 vf11, 464(a2) + c->pminw(t0, t0, v1); // pminw t0, t0, v1 + c->lqc2(vf12, 480, a2); // lqc2 vf12, 480(a2) + c->pminw(v1, a3, v1); // pminw v1, a3, v1 + c->lqc2(vf13, 496, a2); // lqc2 vf13, 496(a2) + // nop // sll r0, r0, 0 + c->sq(t0, 400, a2); // sq t0, 400(a2) + // nop // sll r0, r0, 0 + c->sq(v1, 416, a2); // sq v1, 416(a2) + c->addiu(v1, r0, 4); // addiu v1, r0, 4 + c->lbu(a3, 40, a1); // lbu a3, 40(a1) + c->multu3(t8, a3, v1); // multu3 t8, a3, v1 + c->lbu(a3, 42, a1); // lbu a3, 42(a1) + c->multu3(t6, a3, t8); // multu3 t6, a3, t8 + c->addiu(a3, r0, 1); // addiu a3, r0, 1 + c->lw(t0, 400, a2); // lw t0, 400(a2) + c->dsubu(a3, a3, t0); // dsubu a3, a3, t0 + c->lw(t0, 416, a2); // lw t0, 416(a2) + c->daddu(a3, a3, t0); // daddu a3, a3, t0 + c->addiu(t0, r0, 1); // addiu t0, r0, 1 + c->lw(t1, 404, a2); // lw t1, 404(a2) + c->dsubu(t0, t0, t1); // dsubu t0, t0, t1 + c->lw(t1, 420, a2); // lw t1, 420(a2) + c->daddu(t1, t0, t1); // daddu t1, t0, t1 + c->addiu(t0, r0, 1); // addiu t0, r0, 1 + c->lw(t2, 408, a2); // lw t2, 408(a2) + c->dsubu(t0, t0, t2); // dsubu t0, t0, t2 + c->lw(t2, 424, a2); // lw t2, 424(a2) + c->daddu(t0, t0, t2); // daddu t0, t0, t2 + c->lwu(t2, 8, a1); // lwu t2, 8(a1) + c->lw(t3, 400, a2); // lw t3, 400(a2) + c->mult3(t3, t3, v1); // mult3 t3, t3, v1 + c->lw(t4, 404, a2); // lw t4, 404(a2) + c->mult3(t4, t4, t6); // mult3 t4, t4, t6 + c->daddu(t3, t3, t4); // daddu t3, t3, t4 + c->lw(t4, 408, a2); // lw t4, 408(a2) + c->mult3(t4, t4, t8); // mult3 t4, t4, t8 + c->daddu(t3, t3, t4); // daddu t3, t3, t4 + c->daddu(t7, t2, t3); // daddu t7, t2, t3 + c->mov64(t1, t1); // or t1, t1, r0 + // nop // sll r0, r0, 0 + + block_2: + c->mov64(t5, t0); // or t5, t0, r0 + c->mov64(t9, t7); // or t9, t7, r0 + // nop // sll r0, r0, 0 + c->sw(t7, 524, a2); // sw t7, 524(a2) + // nop // sll r0, r0, 0 + c->sw(t6, 528, a2); // sw t6, 528(a2) + + block_3: + c->mov64(t6, a3); // or t6, a3, r0 + c->mov64(t7, t9); // or t7, t9, r0 + // nop // sll r0, r0, 0 + c->sw(t9, 532, a2); // sw t9, 532(a2) + // nop // sll r0, r0, 0 + c->sw(t8, 536, a2); // sw t8, 536(a2) + + block_4: + // nop // sll r0, r0, 0 + c->lhu(ra, 0, t7); // lhu ra, 0(t7) + // nop // sll r0, r0, 0 + c->lw(gp, 104, a1); // lw gp, 104(a1) + // nop // sll r0, r0, 0 + c->lhu(t8, 2, t7); // lhu t8, 2(t7) + // nop // sll r0, r0, 0 + c->lw(t9, 72, a1); // lw t9, 72(a1) + bc = c->sgpr64(t8) == 0; // beq t8, r0, L74 + c->daddu(ra, ra, gp); // daddu ra, ra, gp + if (bc) {goto block_13;} // branch non-likely + + + block_5: + get_fake_spad_addr2(gp, cache.fake_scratchpad_data, 0, c);// lui gp, 28672 + c->lbu(s4, 0, ra); // lbu s4, 0(ra) + c->addiu(s3, r0, 1); // addiu s3, r0, 1 + c->andi(s2, s4, 7); // andi s2, s4, 7 + c->sra(s5, s4, 3); // sra s5, s4, 3 + c->sll(s4, s4, 2); // sll s4, s4, 2 + c->daddu(s5, s5, gp); // daddu s5, s5, gp + c->daddu(s4, s4, t9); // daddu s4, s4, t9 + c->sllv(s3, s3, s2); // sllv s3, s3, s2 + c->lb(s2, 0, s5); // lb s2, 0(s5) + // nop // sll r0, r0, 0 + c->lbu(s0, 3, s4); // lbu s0, 3(s4) + c->and_(s1, s2, s3); // and s1, s2, s3 + c->daddiu(t8, t8, -1); // daddiu t8, t8, -1 + bc = c->sgpr64(s1) != 0; // bne s1, r0, L73 + c->lw(s1, 4, a1); // lw s1, 4(a1) + if (bc) {goto block_12;} // branch non-likely + + c->dsll(s0, s0, 2); // dsll s0, s0, 2 + c->or_(s3, s2, s3); // or s3, s2, s3 + c->daddu(s2, s0, s1); // daddu s2, s0, s1 + c->sb(s3, 0, s5); // sb s3, 0(s5) + // nop // sll r0, r0, 0 + c->lwu(s5, 0, s2); // lwu s5, 0(s2) + // nop // sll r0, r0, 0 + c->lwu(s2, 96, a2); // lwu s2, 96(a2) + // nop // sll r0, r0, 0 + c->lw(s3, 88, a1); // lw s3, 88(a1) + c->and_(s2, s2, s5); // and s2, s2, s5 + c->lbu(s1, 0, s4); // lbu s1, 0(s4) + bc = c->sgpr64(s2) != 0; // bne s2, r0, L73 + c->lbu(s2, 1, s4); // lbu s2, 1(s4) + if (bc) {goto block_12;} // branch non-likely + + c->sll(s1, s1, 1); // sll s1, s1, 1 + c->lbu(s4, 2, s4); // lbu s4, 2(s4) + c->sll(s0, s1, 1); // sll s0, s1, 1 + c->sll(s2, s2, 1); // sll s2, s2, 1 + c->daddu(s1, s1, s0); // daddu s1, s1, s0 + c->sll(s0, s2, 1); // sll s0, s2, 1 + c->sll(s4, s4, 1); // sll s4, s4, 1 + c->daddu(s0, s2, s0); // daddu s0, s2, s0 + c->sll(v0, s4, 1); // sll v0, s4, 1 + c->daddu(s2, s1, s3); // daddu s2, s1, s3 + c->daddu(s4, s4, v0); // daddu s4, s4, v0 + c->daddu(s1, s0, s3); // daddu s1, s0, s3 + c->daddu(s4, s4, s3); // daddu s4, s4, s3 + c->ldr(t2, 0, s2); // ldr t2, 0(s2) + // nop // sll r0, r0, 0 + c->ldl(t2, 7, s2); // ldl t2, 7(s2) + // nop // sll r0, r0, 0 + c->ldr(t3, 0, s1); // ldr t3, 0(s1) + // nop // sll r0, r0, 0 + c->ldl(t3, 7, s1); // ldl t3, 7(s1) + // nop // sll r0, r0, 0 + c->ldr(t4, 0, s4); // ldr t4, 0(s4) + c->pextlh(t2, r0, t2); // pextlh t2, r0, t2 + c->ldl(t4, 7, s4); // ldl t4, 7(s4) + c->pextlh(t3, r0, t3); // pextlh t3, r0, t3 + c->lq(s4, 368, a2); // lq s4, 368(a2) + c->pextlh(t4, r0, t4); // pextlh t4, r0, t4 + c->lq(s3, 384, a2); // lq s3, 384(a2) + c->pminw(s1, t2, t3); // pminw s1, t2, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pmaxw(s2, t2, t3); // pmaxw s2, t2, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pminw(s1, s1, t4); // pminw s1, s1, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pmaxw(s2, s2, t4); // pmaxw s2, s2, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcgtw(s3, s1, s3); // pcgtw s3, s1, s3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcgtw(s4, s4, s2); // pcgtw s4, s4, s2 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->por(s4, s3, s4); // por s4, s3, s4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->ppach(s4, r0, s4); // ppach s4, r0, s4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->dsll(s4, s4, 16); // dsll s4, s4, 16 + // nop // sll r0, r0, 0 + bc = c->sgpr64(s4) != 0; // bne s4, r0, L73 + // nop // sll r0, r0, 0 + if (bc) {goto block_12;} // branch non-likely + + c->psllw(t2, t2, 4); // psllw t2, t2, 4 + c->lw(s4, 2048, gp); // lw s4, 2048(gp) + c->psllw(t3, t3, 4); // psllw t3, t3, 4 + c->mov128_vf_gpr(vf7, t2); // qmtc2.i vf7, t2 + c->psllw(t4, t4, 4); // psllw t4, t4, 4 + c->mov128_vf_gpr(vf8, t3); // qmtc2.i vf8, t3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t4); // qmtc2.i vf9, t4 + c->vitof0(DEST::xyzw, vf7, vf7); // vitof0.xyzw vf7, vf7 + c->daddiu(s4, s4, 1); // daddiu s4, s4, 1 + c->vitof0(DEST::xyzw, vf8, vf8); // vitof0.xyzw vf8, vf8 + c->sw(s4, 2048, gp); // sw s4, 2048(gp) + c->vitof0(DEST::xyzw, vf9, vf9); // vitof0.xyzw vf9, vf9 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf7, vf7, vf1); // vadd.xyzw vf7, vf7, vf1 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf8, vf8, vf1); // vadd.xyzw vf8, vf8, vf1 + c->lwu(gp, 512, a2); // lwu gp, 512(a2) + c->vadd(DEST::xyzw, vf9, vf9, vf1); // vadd.xyzw vf9, vf9, vf1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(gp) == c->sgpr64(s7); // beq gp, s7, L72 + // nop // sll r0, r0, 0 + if (bc) {goto block_10;} // branch non-likely + + c->vmula_bc(DEST::xyzw, BC::x, vf10, vf7); // vmulax.xyzw acc, vf10, vf7 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf11, vf7); // vmadday.xyzw acc, vf11, vf7 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::z, vf12, vf7); // vmaddaz.xyzw acc, vf12, vf7 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf7, vf13, vf0); // vmaddw.xyzw vf7, vf13, vf0 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf10, vf8); // vmulax.xyzw acc, vf10, vf8 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf11, vf8); // vmadday.xyzw acc, vf11, vf8 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::z, vf12, vf8); // vmaddaz.xyzw acc, vf12, vf8 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf8, vf13, vf0); // vmaddw.xyzw vf8, vf13, vf0 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf10, vf9); // vmulax.xyzw acc, vf10, vf9 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf11, vf9); // vmadday.xyzw acc, vf11, vf9 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::z, vf12, vf9); // vmaddaz.xyzw acc, vf12, vf9 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf9, vf13, vf0); // vmaddw.xyzw vf9, vf13, vf0 + // nop // sll r0, r0, 0 + + block_10: + c->pextlw(gp, gp, s5); // pextlw gp, gp, s5 + c->lw(s4, 0, a0); // lw s4, 0(a0) + // nop // sll r0, r0, 0 + c->daddiu(s5, a0, 4908); // daddiu s5, a0, 4908 + c->daddiu(s3, s4, -460); // daddiu s3, s4, -460 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(s3)) >= 0; // bgez s3, L76 + c->dsll(s3, s4, 6); // dsll s3, s4, 6 + if (bc) {goto block_18;} // branch non-likely + + c->daddiu(s4, s4, 1); // daddiu s4, s4, 1 + c->daddu(s5, s5, s3); // daddu s5, s5, s3 + // nop // sll r0, r0, 0 + c->sw(s4, 0, a0); // sw s4, 0(a0) + // nop // sll r0, r0, 0 + c->sq(gp, 48, s5); // sq gp, 48(s5) + // nop // sll r0, r0, 0 + c->sqc2(vf7, 0, s5); // sqc2 vf7, 0(s5) + // nop // sll r0, r0, 0 + c->sqc2(vf8, 16, s5); // sqc2 vf8, 16(s5) + // nop // sll r0, r0, 0 + c->sqc2(vf9, 32, s5); // sqc2 vf9, 32(s5) + + block_12: + bc = ((s64)c->sgpr64(t8)) > 0; // bgtz t8, L71 + c->daddiu(ra, ra, 1); // daddiu ra, ra, 1 + if (bc) {goto block_5;} // branch non-likely + + + block_13: + c->daddiu(t6, t6, -1); // daddiu t6, t6, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t6) != 0; // bne t6, r0, L70 + c->daddu(t7, t7, v1); // daddu t7, t7, v1 + if (bc) {goto block_4;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(t6, 532, a2); // lw t6, 532(a2) + // nop // sll r0, r0, 0 + c->lw(t8, 536, a2); // lw t8, 536(a2) + c->daddiu(t5, t5, -1); // daddiu t5, t5, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t5) != 0; // bne t5, r0, L69 + c->daddu(t9, t6, t8); // daddu t9, t6, t8 + if (bc) {goto block_3;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(t5, 524, a2); // lw t5, 524(a2) + // nop // sll r0, r0, 0 + c->lw(t6, 528, a2); // lw t6, 528(a2) + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t1) != 0; // bne t1, r0, L68 + c->daddu(t7, t5, t6); // daddu t7, t5, t6 + if (bc) {goto block_2;} // branch non-likely + + c->load_symbol2(v1, cache.collide_stats); // lw v1, *collide-stats*(s7) + c->lwu(v1, 12, v1); // lwu v1, 12(v1) + c->daddiu(v1, v1, 1); // daddiu v1, v1, 1 + c->load_symbol2(a0, cache.collide_stats); // lw a0, *collide-stats*(s7) + c->sw(v1, 12, a0); // sw v1, 12(a0) + + block_17: + c->mov64(v0, s7); // or v0, s7, r0 + //beq r0, r0, L78 // beq r0, r0, L78 + // nop // sll r0, r0, 0 + goto block_21; // branch always + + + block_18: + c->load_symbol_addr(v1, cache.debug); // daddiu v1, s7, debug + c->load_symbol2(a0, cache.cheat_mode); // lw a0, *cheat-mode*(s7) + bc = c->sgpr64(a0) != c->sgpr64(v1); // bne a0, v1, L77 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_20;} // branch non-likely + + c->load_symbol2(t9, cache.print_exceeded_max_cache_tris);// lw t9, print-exceeded-max-cache-tris(s7) + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + + block_20: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + + block_21: + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 112, sp); // lq gp, 112(sp) + c->lq(s5, 96, sp); // lq s5, 96(sp) + c->lq(s4, 80, sp); // lq s4, 80(sp) + c->lq(s3, 64, sp); // lq s3, 64(sp) + c->lq(s2, 48, sp); // lq s2, 48(sp) + c->lq(s1, 32, sp); // lq s1, 32(sp) + c->lq(s0, 16, sp); // lq s0, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 128); // daddiu sp, sp, 128 + 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() { + cache.cheat_mode = intern_from_c("*cheat-mode*").c(); + cache.collide_stats = intern_from_c("*collide-stats*").c(); + cache.fake_scratchpad_data = intern_from_c("*fake-scratchpad-data*").c(); + cache.debug = intern_from_c("debug").c(); + cache.print_exceeded_max_cache_tris = intern_from_c("print-exceeded-max-cache-tris").c(); + gLinkedFunctionTable.reg("fill-bg-using-box-new", execute, 256); +} + +} // namespace fill_bg_using_box_new +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace fill_bg_using_line_sphere_new { +struct Cache { + void* cheat_mode; // *cheat-mode* + void* collide_stats; // *collide-stats* + void* fake_scratchpad_data; // *fake-scratchpad-data* + void* debug; // debug + void* print_exceeded_max_cache_tris; // print-exceeded-max-cache-tris +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -128); // daddiu sp, sp, -128 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s0, 16, sp); // sq s0, 16(sp) + c->sq(s1, 32, sp); // sq s1, 32(sp) + c->sq(s2, 48, sp); // sq s2, 48(sp) + c->sq(s3, 64, sp); // sq s3, 64(sp) + c->sq(s4, 80, sp); // sq s4, 80(sp) + c->sq(s5, 96, sp); // sq s5, 96(sp) + c->sq(gp, 112, sp); // sq gp, 112(sp) + // nop // sll r0, r0, 0 + c->lw(v1, 40, a1); // lw v1, 40(a1) + // nop // sll r0, r0, 0 + c->lqc2(vf2, 44, a1); // lqc2 vf2, 44(a1) + c->lui(a3, 1); // lui a3, 1 + c->lqc2(vf3, 128, a2); // lqc2 vf3, 128(a2) + c->ori(a3, a3, 257); // ori a3, a3, 257 + c->lqc2(vf4, 144, a2); // lqc2 vf4, 144(a2) + c->dsubu(v1, v1, a3); // dsubu v1, v1, a3 + c->lqc2(vf5, 60, a1); // lqc2 vf5, 60(a1) + c->vsub(DEST::xyzw, vf3, vf3, vf2); // vsub.xyzw vf3, vf3, vf2 + c->lq(a3, 160, a2); // lq a3, 160(a2) + c->vsub(DEST::xyzw, vf4, vf4, vf2); // vsub.xyzw vf4, vf4, vf2 + c->lq(t0, 176, a2); // lq t0, 176(a2) + c->pextlb(v1, r0, v1); // pextlb v1, r0, v1 + c->lq(t1, 76, a1); // lq t1, 76(a1) + c->pextlh(v1, r0, v1); // pextlh v1, r0, v1 + c->lq(t2, 92, a1); // lq t2, 92(a1) + c->pcgtw(t0, t1, t0); // pcgtw t0, t1, t0 + c->vmul(DEST::xyzw, vf3, vf3, vf5); // vmul.xyzw vf3, vf3, vf5 + c->pcgtw(a3, a3, t2); // pcgtw a3, a3, t2 + c->vmul(DEST::xyzw, vf4, vf4, vf5); // vmul.xyzw vf4, vf4, vf5 + c->por(a3, t0, a3); // por a3, t0, a3 + c->lqc2(vf10, 256, a2); // lqc2 vf10, 256(a2) + c->ppach(a3, r0, a3); // ppach a3, r0, a3 + c->lqc2(vf11, 272, a2); // lqc2 vf11, 272(a2) + c->dsll(a3, a3, 16); // dsll a3, a3, 16 + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + bc = c->sgpr64(a3) != 0; // bne a3, r0, L63 + c->vftoi0(DEST::xyzw, vf4, vf4); // vftoi0.xyzw vf4, vf4 + if (bc) {goto block_22;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lqc2(vf8, 208, a2); // lqc2 vf8, 208(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf9, 224, a2); // lqc2 vf9, 224(a2) + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf3); // qmfc2.i t0, vf3 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf4); // qmfc2.i a3, vf4 + c->pmaxw(t0, t0, r0); // pmaxw t0, t0, r0 + c->lqc2(vf6, 28, a1); // lqc2 vf6, 28(a1) + c->pmaxw(a3, a3, r0); // pmaxw a3, a3, r0 + c->lqc2(vf7, 240, a2); // lqc2 vf7, 240(a2) + c->pminw(t0, t0, v1); // pminw t0, t0, v1 + c->vmax_bc(DEST::xyzw, BC::w, vf1, vf0, vf0); // vmaxw.xyzw vf1, vf0, vf0 + c->pminw(v1, a3, v1); // pminw v1, a3, v1 + c->lqc2(vf23, 448, a2); // lqc2 vf23, 448(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf24, 464, a2); // lqc2 vf24, 464(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf25, 480, a2); // lqc2 vf25, 480(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf26, 496, a2); // lqc2 vf26, 496(a2) + // nop // sll r0, r0, 0 + c->sq(t0, 400, a2); // sq t0, 400(a2) + // nop // sll r0, r0, 0 + c->sq(v1, 416, a2); // sq v1, 416(a2) + c->vsub(DEST::xyzw, vf8, vf8, vf2); // vsub.xyzw vf8, vf8, vf2 + // nop // sll r0, r0, 0 + c->addiu(t8, r0, 4); // addiu t8, r0, 4 + c->lbu(v1, 40, a1); // lbu v1, 40(a1) + c->multu3(t9, v1, t8); // multu3 t9, v1, t8 + c->lbu(v1, 42, a1); // lbu v1, 42(a1) + c->multu3(t6, v1, t9); // multu3 t6, v1, t9 + c->addiu(v1, r0, 1); // addiu v1, r0, 1 + c->lw(a3, 400, a2); // lw a3, 400(a2) + c->dsubu(v1, v1, a3); // dsubu v1, v1, a3 + c->lw(a3, 416, a2); // lw a3, 416(a2) + c->daddu(v1, v1, a3); // daddu v1, v1, a3 + c->addiu(a3, r0, 1); // addiu a3, r0, 1 + c->lw(t0, 404, a2); // lw t0, 404(a2) + c->dsubu(a3, a3, t0); // dsubu a3, a3, t0 + c->lw(t0, 420, a2); // lw t0, 420(a2) + c->daddu(a3, a3, t0); // daddu a3, a3, t0 + c->addiu(t0, r0, 1); // addiu t0, r0, 1 + c->lw(t1, 408, a2); // lw t1, 408(a2) + c->dsubu(t0, t0, t1); // dsubu t0, t0, t1 + c->lw(t1, 424, a2); // lw t1, 424(a2) + c->daddu(t0, t0, t1); // daddu t0, t0, t1 + c->lwu(t1, 8, a1); // lwu t1, 8(a1) + c->lw(t2, 400, a2); // lw t2, 400(a2) + c->mult3(t2, t2, t8); // mult3 t2, t2, t8 + c->lw(t3, 404, a2); // lw t3, 404(a2) + c->mult3(t3, t3, t6); // mult3 t3, t3, t6 + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->lw(t3, 408, a2); // lw t3, 408(a2) + c->mult3(t3, t3, t9); // mult3 t3, t3, t9 + c->daddu(t2, t2, t3); // daddu t2, t2, t3 + c->daddu(t7, t1, t2); // daddu t7, t1, t2 + c->mov64(t1, a3); // or t1, a3, r0 + // nop // sll r0, r0, 0 + + block_2: + c->mov64(t2, t0); // or t2, t0, r0 + c->mov64(ra, t7); // or ra, t7, r0 + // nop // sll r0, r0, 0 + c->sw(t7, 524, a2); // sw t7, 524(a2) + // nop // sll r0, r0, 0 + c->sw(t6, 528, a2); // sw t6, 528(a2) + + block_3: + c->mov64(t6, v1); // or t6, v1, r0 + c->mov64(t7, ra); // or t7, ra, r0 + // nop // sll r0, r0, 0 + c->sw(ra, 532, a2); // sw ra, 532(a2) + // nop // sll r0, r0, 0 + c->sw(t9, 536, a2); // sw t9, 536(a2) + + block_4: + // nop // sll r0, r0, 0 + c->sw(t8, 520, a2); // sw t8, 520(a2) + c->dsubu(s5, v1, t6); // dsubu s5, v1, t6 + c->lw(s4, 400, a2); // lw s4, 400(a2) + c->dsubu(ra, a3, t1); // dsubu ra, a3, t1 + c->lw(gp, 404, a2); // lw gp, 404(a2) + c->dsubu(t8, t0, t2); // dsubu t8, t0, t2 + c->lw(t9, 408, a2); // lw t9, 408(a2) + c->daddu(s5, s5, s4); // daddu s5, s5, s4 + c->sw(r0, 444, a2); // sw r0, 444(a2) + c->daddu(ra, ra, gp); // daddu ra, ra, gp + c->sw(s5, 432, a2); // sw s5, 432(a2) + c->daddu(t8, t8, t9); // daddu t8, t8, t9 + c->sw(ra, 436, a2); // sw ra, 436(a2) + // nop // sll r0, r0, 0 + c->sw(t8, 440, a2); // sw t8, 440(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 432, a2); // lqc2 vf3, 432(a2) + c->vitof0(DEST::xyzw, vf3, vf3); // vitof0.xyzw vf3, vf3 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf3, vf6); // vmula.xyzw acc, vf3, vf6 + // nop // sll r0, r0, 0 + c->vmsub_bc(DEST::xyzw, BC::w, vf3, vf1, vf10); // vmsubw.xyzw vf3, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmadda(DEST::xyzw, vf1, vf6); // vmadda.xyzw acc, vf1, vf6 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf4, vf1, vf10); // vmaddw.xyzw vf4, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf3); // vmula.xyzw acc, vf7, vf3 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf13, vf1, vf10); // vmsub.xyzw vf13, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf15, vf1, vf11); // vmadd.xyzw vf15, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf4); // vmula.xyzw acc, vf7, vf4 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf14, vf1, vf11); // vmsub.xyzw vf14, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf16, vf1, vf10); // vmadd.xyzw vf16, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmax(DEST::xyzw, vf13, vf13, vf14); // vmax.xyzw vf13, vf13, vf14 + // nop // sll r0, r0, 0 + c->vmini(DEST::xyzw, vf15, vf15, vf16); // vmini.xyzw vf15, vf15, vf16 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::y, vf13, vf13, vf13); // vmaxy.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::y, vf15, vf15, vf15); // vminiy.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::z, vf13, vf13, vf13); // vmaxz.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::z, vf15, vf15, vf15); // vminiz.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vftoi12(DEST::xyzw, vf13, vf13); // vftoi12.xyzw vf13, vf13 + // nop // sll r0, r0, 0 + c->vftoi12(DEST::xyzw, vf15, vf15); // vftoi12.xyzw vf15, vf15 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(ra, vf13); // qmfc2.i ra, vf13 + c->addiu(gp, r0, 4096); // addiu gp, r0, 4096 + c->mov128_gpr_vf(t8, vf15); // qmfc2.i t8, vf15 + c->subu(t9, t8, ra); // subu t9, t8, ra + c->subu(ra, gp, ra); // subu ra, gp, ra + bc = ((s64)c->sgpr64(t9)) < 0; // bltz t9, L62 + // nop // sll r0, r0, 0 + if (bc) {goto block_18;} // branch non-likely + + bc = ((s64)c->sgpr64(ra)) < 0; // bltz ra, L62 + // nop // sll r0, r0, 0 + if (bc) {goto block_18;} // branch non-likely + + bc = ((s64)c->sgpr64(t8)) < 0; // bltz t8, L62 + // nop // sll r0, r0, 0 + if (bc) {goto block_18;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lhu(ra, 0, t7); // lhu ra, 0(t7) + // nop // sll r0, r0, 0 + c->lw(gp, 104, a1); // lw gp, 104(a1) + // nop // sll r0, r0, 0 + c->lhu(t8, 2, t7); // lhu t8, 2(t7) + // nop // sll r0, r0, 0 + c->lw(t9, 72, a1); // lw t9, 72(a1) + bc = c->sgpr64(t8) == 0; // beq t8, r0, L62 + c->daddu(ra, ra, gp); // daddu ra, ra, gp + if (bc) {goto block_18;} // branch non-likely + + + block_8: + get_fake_spad_addr2(gp, cache.fake_scratchpad_data, 0, c);// lui gp, 28672 + c->lbu(s4, 0, ra); // lbu s4, 0(ra) + c->addiu(s3, r0, 1); // addiu s3, r0, 1 + c->andi(s2, s4, 7); // andi s2, s4, 7 + c->sra(s5, s4, 3); // sra s5, s4, 3 + c->sll(s4, s4, 2); // sll s4, s4, 2 + c->daddu(s5, s5, gp); // daddu s5, s5, gp + c->daddu(s4, s4, t9); // daddu s4, s4, t9 + c->sllv(s3, s3, s2); // sllv s3, s3, s2 + c->lb(s2, 0, s5); // lb s2, 0(s5) + // nop // sll r0, r0, 0 + c->lbu(s0, 3, s4); // lbu s0, 3(s4) + c->and_(s1, s2, s3); // and s1, s2, s3 + c->daddiu(t8, t8, -1); // daddiu t8, t8, -1 + bc = c->sgpr64(s1) != 0; // bne s1, r0, L61 + c->lw(s1, 4, a1); // lw s1, 4(a1) + if (bc) {goto block_17;} // branch non-likely + + c->dsll(s0, s0, 2); // dsll s0, s0, 2 + c->or_(s3, s2, s3); // or s3, s2, s3 + c->daddu(s2, s0, s1); // daddu s2, s0, s1 + c->sb(s3, 0, s5); // sb s3, 0(s5) + // nop // sll r0, r0, 0 + c->lwu(s5, 0, s2); // lwu s5, 0(s2) + // nop // sll r0, r0, 0 + c->lwu(s2, 96, a2); // lwu s2, 96(a2) + // nop // sll r0, r0, 0 + c->lw(s3, 88, a1); // lw s3, 88(a1) + c->and_(s2, s2, s5); // and s2, s2, s5 + c->lbu(s1, 0, s4); // lbu s1, 0(s4) + bc = c->sgpr64(s2) != 0; // bne s2, r0, L61 + c->lbu(s2, 1, s4); // lbu s2, 1(s4) + if (bc) {goto block_17;} // branch non-likely + + c->sll(s1, s1, 1); // sll s1, s1, 1 + c->lbu(s4, 2, s4); // lbu s4, 2(s4) + c->sll(s0, s1, 1); // sll s0, s1, 1 + c->sll(s2, s2, 1); // sll s2, s2, 1 + c->daddu(s1, s1, s0); // daddu s1, s1, s0 + c->sll(s0, s2, 1); // sll s0, s2, 1 + c->sll(s4, s4, 1); // sll s4, s4, 1 + c->daddu(s0, s2, s0); // daddu s0, s2, s0 + c->sll(v0, s4, 1); // sll v0, s4, 1 + c->daddu(s2, s1, s3); // daddu s2, s1, s3 + c->daddu(s1, s4, v0); // daddu s1, s4, v0 + c->daddu(s4, s0, s3); // daddu s4, s0, s3 + c->daddu(s3, s1, s3); // daddu s3, s1, s3 + c->ldr(t3, 0, s2); // ldr t3, 0(s2) + // nop // sll r0, r0, 0 + c->ldl(t3, 7, s2); // ldl t3, 7(s2) + // nop // sll r0, r0, 0 + c->ldr(t4, 0, s4); // ldr t4, 0(s4) + c->pextlh(t3, r0, t3); // pextlh t3, r0, t3 + c->ldl(t4, 7, s4); // ldl t4, 7(s4) + c->psllw(t3, t3, 4); // psllw t3, t3, 4 + c->ldr(t5, 0, s3); // ldr t5, 0(s3) + c->pextlh(t4, r0, t4); // pextlh t4, r0, t4 + c->ldl(t5, 7, s3); // ldl t5, 7(s3) + c->psllw(t4, t4, 4); // psllw t4, t4, 4 + c->mov128_vf_gpr(vf17, t3); // qmtc2.i vf17, t3 + c->pextlh(t5, r0, t5); // pextlh t5, r0, t5 + c->mov128_vf_gpr(vf18, t4); // qmtc2.i vf18, t4 + c->psllw(t5, t5, 4); // psllw t5, t5, 4 + c->lw(s4, 2048, gp); // lw s4, 2048(gp) + c->mov128_vf_gpr(vf19, t5); // qmtc2.i vf19, t5 + // nop // sll r0, r0, 0 + c->vitof0(DEST::xyzw, vf17, vf17); // vitof0.xyzw vf17, vf17 + c->daddiu(s4, s4, 1); // daddiu s4, s4, 1 + c->vitof0(DEST::xyzw, vf18, vf18); // vitof0.xyzw vf18, vf18 + c->sw(s4, 2048, gp); // sw s4, 2048(gp) + c->vitof0(DEST::xyzw, vf19, vf19); // vitof0.xyzw vf19, vf19 + // nop // sll r0, r0, 0 + c->vmini(DEST::xyzw, vf3, vf17, vf18); // vmini.xyzw vf3, vf17, vf18 + // nop // sll r0, r0, 0 + c->vmax(DEST::xyzw, vf4, vf17, vf18); // vmax.xyzw vf4, vf17, vf18 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf17, vf17, vf2); // vadd.xyzw vf17, vf17, vf2 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf18, vf18, vf2); // vadd.xyzw vf18, vf18, vf2 + // nop // sll r0, r0, 0 + c->vmini(DEST::xyzw, vf3, vf3, vf19); // vmini.xyzw vf3, vf3, vf19 + // nop // sll r0, r0, 0 + c->vmax(DEST::xyzw, vf4, vf4, vf19); // vmax.xyzw vf4, vf4, vf19 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf19, vf19, vf2); // vadd.xyzw vf19, vf19, vf2 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->vsub_bc(DEST::xyzw, BC::w, vf3, vf3, vf10); // vsubw.xyzw vf3, vf3, vf10 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::xyzw, BC::w, vf4, vf4, vf10); // vaddw.xyzw vf4, vf4, vf10 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf3); // vmula.xyzw acc, vf7, vf3 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf13, vf1, vf10); // vmsub.xyzw vf13, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf15, vf1, vf11); // vmadd.xyzw vf15, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmula(DEST::xyzw, vf7, vf4); // vmula.xyzw acc, vf7, vf4 + // nop // sll r0, r0, 0 + c->vmsuba(DEST::xyzw, vf7, vf8); // vmsuba.xyzw acc, vf7, vf8 + // nop // sll r0, r0, 0 + c->vmsub(DEST::xyzw, vf14, vf1, vf11); // vmsub.xyzw vf14, vf1, vf11 + // nop // sll r0, r0, 0 + c->vmadd(DEST::xyzw, vf16, vf1, vf10); // vmadd.xyzw vf16, vf1, vf10 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf23, vf17); // vmulax.xyzw acc, vf23, vf17 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf24, vf17); // vmadday.xyzw acc, vf24, vf17 + // nop // sll r0, r0, 0 + c->vmax(DEST::xyzw, vf13, vf13, vf14); // vmax.xyzw vf13, vf13, vf14 + // nop // sll r0, r0, 0 + c->vmini(DEST::xyzw, vf15, vf15, vf16); // vmini.xyzw vf15, vf15, vf16 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::z, vf25, vf17); // vmaddaz.xyzw acc, vf25, vf17 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf20, vf26, vf0); // vmaddw.xyzw vf20, vf26, vf0 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::y, vf13, vf13, vf13); // vmaxy.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::y, vf15, vf15, vf15); // vminiy.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf23, vf18); // vmulax.xyzw acc, vf23, vf18 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf24, vf18); // vmadday.xyzw acc, vf24, vf18 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::xyzw, BC::z, vf13, vf13, vf13); // vmaxz.xyzw vf13, vf13, vf13 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::xyzw, BC::z, vf15, vf15, vf15); // vminiz.xyzw vf15, vf15, vf15 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::z, vf25, vf18); // vmaddaz.xyzw acc, vf25, vf18 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf21, vf26, vf0); // vmaddw.xyzw vf21, vf26, vf0 + // nop // sll r0, r0, 0 + c->vftoi12(DEST::xyzw, vf13, vf13); // vftoi12.xyzw vf13, vf13 + // nop // sll r0, r0, 0 + c->vftoi12(DEST::xyzw, vf15, vf15); // vftoi12.xyzw vf15, vf15 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::x, vf23, vf19); // vmulax.xyzw acc, vf23, vf19 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf24, vf19); // vmadday.xyzw acc, vf24, vf19 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(s3, vf13); // qmfc2.i s3, vf13 + c->addiu(s2, r0, 4096); // addiu s2, r0, 4096 + c->mov128_gpr_vf(s4, vf15); // qmfc2.i s4, vf15 + c->subu(gp, s4, s3); // subu gp, s4, s3 + c->subu(s3, s2, s3); // subu s3, s2, s3 + bc = ((s64)c->sgpr64(gp)) < 0; // bltz gp, L61 + c->lwu(gp, 512, a2); // lwu gp, 512(a2) + if (bc) {goto block_17;} // branch non-likely + + bc = ((s64)c->sgpr64(s3)) < 0; // bltz s3, L61 + // nop // sll r0, r0, 0 + if (bc) {goto block_17;} // branch non-likely + + bc = ((s64)c->sgpr64(s4)) < 0; // bltz s4, L61 + // nop // sll r0, r0, 0 + if (bc) {goto block_17;} // branch non-likely + + c->pextlw(s5, gp, s5); // pextlw s5, gp, s5 + c->lw(s3, 0, a0); // lw s3, 0(a0) + // nop // sll r0, r0, 0 + c->daddiu(s4, a0, 4908); // daddiu s4, a0, 4908 + c->daddiu(s2, s3, -460); // daddiu s2, s3, -460 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(s2)) >= 0; // bgez s2, L64 + c->dsll(s2, s3, 6); // dsll s2, s3, 6 + if (bc) {goto block_23;} // branch non-likely + + c->daddiu(s3, s3, 1); // daddiu s3, s3, 1 + c->daddu(s4, s4, s2); // daddu s4, s4, s2 + bc = c->sgpr64(gp) == c->sgpr64(s7); // beq gp, s7, L60 + c->sw(s3, 0, a0); // sw s3, 0(a0) + if (bc) {goto block_16;} // branch non-likely + + c->vmadda_bc(DEST::xyzw, BC::z, vf25, vf19); // vmaddaz.xyzw acc, vf25, vf19 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyzw, BC::w, vf22, vf26, vf0); // vmaddw.xyzw vf22, vf26, vf0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sq(s5, 48, s4); // sq s5, 48(s4) + // nop // sll r0, r0, 0 + c->sqc2(vf20, 0, s4); // sqc2 vf20, 0(s4) + // nop // sll r0, r0, 0 + c->sqc2(vf21, 16, s4); // sqc2 vf21, 16(s4) + //beq r0, r0, L61 // beq r0, r0, L61 + c->sqc2(vf22, 32, s4); // sqc2 vf22, 32(s4) + goto block_17; // branch always + + + block_16: + // nop // sll r0, r0, 0 + c->sq(s5, 48, s4); // sq s5, 48(s4) + // nop // sll r0, r0, 0 + c->sqc2(vf17, 0, s4); // sqc2 vf17, 0(s4) + // nop // sll r0, r0, 0 + c->sqc2(vf18, 16, s4); // sqc2 vf18, 16(s4) + // nop // sll r0, r0, 0 + c->sqc2(vf19, 32, s4); // sqc2 vf19, 32(s4) + + block_17: + bc = ((s64)c->sgpr64(t8)) > 0; // bgtz t8, L59 + c->daddiu(ra, ra, 1); // daddiu ra, ra, 1 + if (bc) {goto block_8;} // branch non-likely + + + block_18: + // nop // sll r0, r0, 0 + c->lw(t8, 520, a2); // lw t8, 520(a2) + c->daddiu(t6, t6, -1); // daddiu t6, t6, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t6) != 0; // bne t6, r0, L58 + c->daddu(t7, t7, t8); // daddu t7, t7, t8 + if (bc) {goto block_4;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(t6, 532, a2); // lw t6, 532(a2) + // nop // sll r0, r0, 0 + c->lw(t9, 536, a2); // lw t9, 536(a2) + c->daddiu(t2, t2, -1); // daddiu t2, t2, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t2) != 0; // bne t2, r0, L57 + c->daddu(ra, t6, t9); // daddu ra, t6, t9 + if (bc) {goto block_3;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lw(t2, 524, a2); // lw t2, 524(a2) + // nop // sll r0, r0, 0 + c->lw(t6, 528, a2); // lw t6, 528(a2) + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t1) != 0; // bne t1, r0, L56 + c->daddu(t7, t2, t6); // daddu t7, t2, t6 + if (bc) {goto block_2;} // branch non-likely + + c->load_symbol2(v1, cache.collide_stats); // lw v1, *collide-stats*(s7) + c->lwu(v1, 12, v1); // lwu v1, 12(v1) + c->daddiu(v1, v1, 1); // daddiu v1, v1, 1 + c->load_symbol2(a0, cache.collide_stats); // lw a0, *collide-stats*(s7) + c->sw(v1, 12, a0); // sw v1, 12(a0) + + block_22: + c->mov64(v0, s7); // or v0, s7, r0 + //beq r0, r0, L66 // beq r0, r0, L66 + // nop // sll r0, r0, 0 + goto block_26; // branch always + + + block_23: + c->load_symbol_addr(v1, cache.debug); // daddiu v1, s7, debug + c->load_symbol2(a0, cache.cheat_mode); // lw a0, *cheat-mode*(s7) + bc = c->sgpr64(a0) != c->sgpr64(v1); // bne a0, v1, L65 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_25;} // branch non-likely + + c->load_symbol2(t9, cache.print_exceeded_max_cache_tris);// lw t9, print-exceeded-max-cache-tris(s7) + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + + block_25: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + + block_26: + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 112, sp); // lq gp, 112(sp) + c->lq(s5, 96, sp); // lq s5, 96(sp) + c->lq(s4, 80, sp); // lq s4, 80(sp) + c->lq(s3, 64, sp); // lq s3, 64(sp) + c->lq(s2, 48, sp); // lq s2, 48(sp) + c->lq(s1, 32, sp); // lq s1, 32(sp) + c->lq(s0, 16, sp); // lq s0, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 128); // daddiu sp, sp, 128 + 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() { + cache.cheat_mode = intern_from_c("*cheat-mode*").c(); + cache.collide_stats = intern_from_c("*collide-stats*").c(); + cache.fake_scratchpad_data = intern_from_c("*fake-scratchpad-data*").c(); + cache.debug = intern_from_c("debug").c(); + cache.print_exceeded_max_cache_tris = intern_from_c("print-exceeded-max-cache-tris").c(); + gLinkedFunctionTable.reg("fill-bg-using-line-sphere-new", execute, 256); +} + +} // namespace fill_bg_using_line_sphere_new +} // namespace Mips2C + diff --git a/game/mips2c/jak2_functions/sparticle_launcher.cpp b/game/mips2c/jak2_functions/sparticle_launcher.cpp index 9d51f68421..29b98f4e82 100644 --- a/game/mips2c/jak2_functions/sparticle_launcher.cpp +++ b/game/mips2c/jak2_functions/sparticle_launcher.cpp @@ -13,7 +13,6 @@ struct Cache { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; bool bc = false; - u32 call_addr = 0; c->mov64(v1, a0); // or v1, a0, r0 c->mov64(v1, a2); // or v1, a2, r0 c->mov64(v1, a3); // or v1, a3, r0 @@ -34,7 +33,6 @@ u64 execute(void* ctxt) { goto block_1; } - block_3: c->dsubu(a1, a2, a3); // dsubu a1, a2, a3 // nop // sll r0, r0, 0 bc = ((s64)c->sgpr64(a1)) >= 0; // bgez a1, L292 diff --git a/game/mips2c/mips2c_private.h b/game/mips2c/mips2c_private.h index ff70146b51..3597d4e387 100644 --- a/game/mips2c/mips2c_private.h +++ b/game/mips2c/mips2c_private.h @@ -894,6 +894,17 @@ struct ExecutionContext { } } + void vmsuba(DEST mask, int src0, int src1) { + auto s0 = vf_src(src0); + auto s1 = vf_src(src1); + + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + acc.f[i] -= s0.f[i] * s1.f[i]; + } + } + } + void vmsuba_bc(DEST mask, BC bc, int src0, int src1) { auto s0 = vf_src(src0); auto s1 = vf_src(src1); @@ -1064,6 +1075,9 @@ struct ExecutionContext { void dsllv(int dst, int src, int sa) { gprs[dst].ds64[0] = gpr_src(src).ds64[0] << (gpr_src(sa).du32[0] & 0b111111); } + void sllv(int dst, int src, int sa) { + gprs[dst].ds64[0] = gpr_src(src).ds32[0] << (gpr_src(sa).du32[0] & 0b11111); + } void dsra32(int dst, int src, int sa) { gprs[dst].ds64[0] = gpr_src(src).ds64[0] >> (32 + sa); } void dsrl32(int dst, int src, int sa) { gprs[dst].du64[0] = gpr_src(src).du64[0] >> (32 + sa); } void sra(int dst, int src, int sa) { gprs[dst].ds64[0] = gpr_src(src).ds32[0] >> sa; } diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 1d98d3e1cc..27f9d3a55e 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -147,6 +147,10 @@ namespace method_33_sky_work { extern void link(); } namespace method_28_sky_work { extern void link(); } namespace method_29_sky_work { extern void link(); } namespace method_30_sky_work { extern void link(); } +namespace method_11_collide_hash { extern void link(); } +namespace method_12_collide_hash { extern void link(); } +namespace fill_bg_using_box_new { extern void link(); } +namespace fill_bg_using_line_sphere_new { extern void link(); } } // clang-format on @@ -241,7 +245,10 @@ PerGameVersion>> gMips2C jak2::render_sky_tri::link, jak2::method_16_sky_work::link, jak2::method_17_sky_work::link, jak2::method_32_sky_work::link, jak2::method_33_sky_work::link, jak2::method_28_sky_work::link, jak2::method_29_sky_work::link, - jak2::method_30_sky_work::link, jak2::set_sky_vf23_value::link}}}, + jak2::method_30_sky_work::link, jak2::set_sky_vf23_value::link}}, + {"collide-hash", + {jak2::method_11_collide_hash::link, jak2::method_12_collide_hash::link, + jak2::fill_bg_using_box_new::link, jak2::fill_bg_using_line_sphere_new::link}}}, }; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { diff --git a/goal_src/jak2/engine/collide/collide-cache-h.gc b/goal_src/jak2/engine/collide/collide-cache-h.gc index 3628dd903c..5fd93f501c 100644 --- a/goal_src/jak2/engine/collide/collide-cache-h.gc +++ b/goal_src/jak2/engine/collide/collide-cache-h.gc @@ -6,6 +6,8 @@ ;; dgos: ENGINE, GAME (declare-type collide-query structure) +(declare-type instance-tie basic) + ;; DECOMP BEGINS @@ -76,7 +78,9 @@ (deftype collide-cache (basic) ((num-tris int32 :offset-assert 4) + (num-tris-u32 uint32 :offset 4) (num-prims int32 :offset-assert 8) + (num-prims-u32 uint32 :offset 8) (ignore-mask pat-surface :offset-assert 12) (ignore-processes process 2 :offset-assert 16) (collide-box bounding-box :inline :offset-assert 32) @@ -93,16 +97,16 @@ (collide-cache-method-9 () none 9) (fill-and-probe-using-line-sphere (_type_ collide-query) float 10) (fill-and-probe-using-spheres (_type_ collide-query) symbol 11) - (collide-cache-method-12 (_type_ collide-query) none 12) + (fill-using-bounding-box (_type_ collide-query) none 12) (fill-using-line-sphere (_type_ collide-query) none 13) (fill-using-spheres (_type_ collide-query) none 14) - (collide-cache-method-15 () none 15) - (collide-cache-method-16 (_type_ collide-query) float 16) + (reset (_type_) none 15) + (probe-using-line-sphere (_type_ collide-query) float 16) (probe-using-spheres (_type_ collide-query) symbol 17) - (collide-cache-method-18 () none 18) - (collide-cache-method-19 () none 19) - (collide-cache-method-20 () none 20) - (collide-cache-method-21 () none 21) + (fill-from-bg (_type_ (function collide-hash int collide-list collide-query int) (function collide-cache collide-list collide-query none) collide-query) none 18) + (fill-from-fg-boxes (_type_) none 19) + (fill-from-fg-line-sphere (_type_) none 20) + (fill-from-water (_type_ water-control) none 21) (collide-cache-method-22 () none 22) (collide-cache-method-23 () none 23) (collide-cache-method-24 () none 24) @@ -112,7 +116,7 @@ (deftype collide-list-item (structure) - ((mesh collide-frag-mesh :offset-assert 0) + ((mesh instance-tie :offset-assert 0) (inst basic :offset-assert 4) ) :pack-me diff --git a/goal_src/jak2/engine/collide/collide-frag.gc b/goal_src/jak2/engine/collide/collide-frag.gc index dbb5b23a53..23e60206a3 100644 --- a/goal_src/jak2/engine/collide/collide-frag.gc +++ b/goal_src/jak2/engine/collide/collide-frag.gc @@ -5,5 +5,95 @@ ;; name in dgo: collide-frag ;; dgos: ENGINE, GAME +;; Note: this is probably not used in jak 2 - this is the old tree-based background collision stuff. + ;; DECOMP BEGINS +(defmethod login drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment)) + obj + ) + +(defmethod draw drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment) (arg0 drawable-tree-collide-fragment) (arg1 display-frame)) + (when *display-render-collision* + (dotimes (s4-0 (-> obj length)) + (draw (-> obj data s4-0) (-> obj data s4-0) arg1) + ) + ) + 0 + (none) + ) + +(defmethod unpack-vis drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment) (arg0 (pointer int8)) (arg1 (pointer int8))) + arg1 + ) + +(defmethod mem-usage collide-fragment ((obj collide-fragment) (arg0 memory-usage-block) (arg1 int)) + (let ((s5-0 (if (logtest? arg1 1) + 54 + 50 + ) + ) + (s4-0 (-> obj mesh)) + ) + (set! (-> arg0 data s5-0 name) (symbol->string 'collide-fragment)) + (+! (-> arg0 data s5-0 count) 1) + (let ((v1-11 (+ (asize-of obj) (asize-of s4-0)))) + (+! (-> arg0 data s5-0 used) v1-11) + (+! (-> arg0 data s5-0 total) (logand -16 (+ v1-11 15))) + ) + (set! (-> arg0 data (+ s5-0 1) name) "collision-poly") + (+! (-> arg0 data (+ s5-0 1) count) (-> s4-0 poly-count)) + (let ((v1-22 (+ (-> s4-0 strip-data-len) (-> s4-0 poly-count)))) + (+! (-> arg0 data (+ s5-0 1) used) v1-22) + (+! (-> arg0 data (+ s5-0 1) total) v1-22) + ) + (set! (-> arg0 data (+ s5-0 2) name) "collision-vertex") + (+! (-> arg0 data (+ s5-0 2) count) (-> s4-0 vertex-count)) + (let ((v1-31 (* (-> s4-0 vertex-data-qwc) 16))) + (+! (-> arg0 data (+ s5-0 2) used) v1-31) + (let ((v0-2 (+ (-> arg0 data (+ s5-0 2) total) v1-31))) + (set! (-> arg0 data (+ s5-0 2) total) v0-2) + (the-as collide-fragment v0-2) + ) + ) + ) + ) + +(defmethod login drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment)) + obj + ) + +(defmethod draw collide-fragment ((obj collide-fragment) (arg0 collide-fragment) (arg1 display-frame)) + 0 + (none) + ) + +(defmethod draw drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment) + (arg0 drawable-inline-array-collide-fragment) + (arg1 display-frame) + ) + (dotimes (s4-0 (-> obj length)) + (let ((s3-0 (-> obj data s4-0))) + (if (sphere-cull (-> s3-0 bsphere)) + (draw s3-0 s3-0 arg1) + ) + ) + ) + 0 + (none) + ) + +(defmethod mem-usage drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 1 (-> arg0 length))) + (set! (-> arg0 data 0 name) (symbol->string 'drawable-group)) + (+! (-> arg0 data 0 count) 1) + (let ((v1-7 32)) + (+! (-> arg0 data 0 used) v1-7) + (+! (-> arg0 data 0 total) (logand -16 (+ v1-7 15))) + ) + (dotimes (s3-0 (-> obj length)) + (mem-usage (-> obj data s3-0) arg0 arg1) + ) + obj + ) + diff --git a/goal_src/jak2/engine/collide/collide-h.gc b/goal_src/jak2/engine/collide/collide-h.gc index ec154f740d..cfff4763db 100644 --- a/goal_src/jak2/engine/collide/collide-h.gc +++ b/goal_src/jak2/engine/collide/collide-h.gc @@ -10,43 +10,46 @@ ;; DECOMP BEGINS (deftype collide-query (structure) - ((best-other-tri collide-tri-result :inline :offset-assert 0) - (best-my-tri collide-tri-result :inline :offset 0) - (ignore-processes process-tree 2 :offset-assert 88) - (ignore-process0 process-tree :offset 88) - (ignore-process1 process-tree :offset 92) - (ignore-pat pat-surface :offset-assert 96) - (collide-with collide-spec :offset-assert 100) - (overlay-params uint32 3 :offset 112) - (bbox bounding-box :inline :offset-assert 128) - (bbox4w bounding-box4w :inline :offset-assert 160) - (bsphere sphere :inline :offset-assert 192) - (start-pos vector :inline :offset-assert 208) - (move-dist vector :inline :offset-assert 224) - (rlength vector :inline :offset-assert 240) - (exit-planes plane 2 :offset-assert 256) - (radius float :offset 268) - (inv-mat matrix :inline :offset 288) - (spheres (inline-array sphere) :offset 112) - (num-spheres uint32 :offset 116) - (solid-only symbol :offset 120) - (best-dist float :offset 112) - (best-other-prim basic :offset 116) - (best-my-prim collide-shape-prim :offset 120) - (move-vec vector :inline :offset 224) - (best-u float :offset 112) - (action-mask collide-action :offset-assert 352) - (local-box4w bounding-box4w :inline :offset-assert 368) - (search-box bounding-box4w :inline :offset-assert 400) - (search-vector vector4w :inline :offset-assert 432) - (instance-mat matrix :inline :offset-assert 448) - (instance-ptr basic :offset-assert 512) - (x-addr uint32 :offset-assert 516) - (x-step uint32 :offset-assert 520) - (y-addr uint32 :offset-assert 524) - (y-step uint32 :offset-assert 528) - (z-addr uint32 :offset-assert 532) - (z-step uint32 :offset-assert 536) + ((best-other-tri collide-tri-result :inline :offset-assert 0) + (best-my-tri collide-tri-result :inline :offset 0) + (ignore-processes process-tree 2 :offset-assert 88) + (ignore-process0 process-tree :offset 88) + (ignore-process1 process-tree :offset 92) + (ignore-pat pat-surface :offset-assert 96) + (ignore-pat-s32 int32 :offset 96) + + (collide-with collide-spec :offset-assert 100) + (collide-with-s32 int32 :offset 100) + (overlay-params uint32 3 :offset 112) ;; ? + (bbox bounding-box :inline :offset-assert 128) + (bbox4w bounding-box4w :inline :offset-assert 160) + (bsphere sphere :inline :offset-assert 192) + (start-pos vector :inline :offset-assert 208) + (move-dist vector :inline :offset-assert 224) + (rlength vector :inline :offset-assert 240) + (exit-planes plane 2 :inline :offset-assert 256) ;; ? + (radius float :offset 268) + (inv-mat matrix :inline :offset 288) + (spheres (inline-array sphere) :offset 112 :score 1) + (num-spheres uint32 :offset 116) + (solid-only symbol :offset 120) + (best-dist float :offset 112 :score -1) + (best-other-prim basic :offset 116) + (best-my-prim collide-shape-prim :offset 120 :score 1) + (move-vec vector :inline :offset 224) + (best-u float :offset 112 :score -1) + (action-mask collide-action :offset-assert 352) + (local-box4w bounding-box4w :inline :offset-assert 368) + (search-box bounding-box4w :inline :offset-assert 400) + (search-vector vector4w :inline :offset-assert 432) + (instance-mat matrix :inline :offset-assert 448) + (instance-ptr basic :offset-assert 512) + (x-addr uint32 :offset-assert 516) + (x-step uint32 :offset-assert 520) + (y-addr uint32 :offset-assert 524) + (y-step uint32 :offset-assert 528) + (z-addr uint32 :offset-assert 532) + (z-step uint32 :offset-assert 536) ) :method-count-assert 9 :size-assert #x21c diff --git a/goal_src/jak2/engine/collide/collide-probe.gc b/goal_src/jak2/engine/collide/collide-probe.gc index 5d07a818c4..6eab82af9d 100644 --- a/goal_src/jak2/engine/collide/collide-probe.gc +++ b/goal_src/jak2/engine/collide/collide-probe.gc @@ -7,3 +7,230 @@ ;; DECOMP BEGINS +;; this file is unused in jak 2. +;; a number of functions require a bunch of annoying casts/mips2c stuff, but are unused. + +(defun creates-new-method? ((arg0 type) (arg1 int)) + (let ((v1-1 (-> arg0 parent allocated-length))) + (-> arg0 allocated-length) + (>= arg1 (the-as int v1-1)) + ) + ) + +(defun overrides-parent-method? ((arg0 type) (arg1 int)) + (!= (-> arg0 method-table arg1) (-> arg0 parent method-table arg1)) + ) + +(defun describe-methods ((arg0 type)) + (let ((s5-0 (-> arg0 allocated-length))) + (dotimes (s4-0 (the-as int s5-0)) + (let ((s3-0 arg0)) + (format #t "~3d:~%" s4-0) + (while (!= s3-0 basic) + (cond + ((creates-new-method? s3-0 s4-0) + (format #t " created by ~s.~%" (symbol->string (-> s3-0 symbol))) + (set! s3-0 basic) + ) + ((overrides-parent-method? s3-0 s4-0) + (format #t " overridden by ~s.~%" (symbol->string (-> s3-0 symbol))) + (set! s3-0 (-> s3-0 parent)) + ) + (else + (set! s3-0 (-> s3-0 parent)) + ) + ) + ) + ) + ) + ) + #f + ) + +(defun indent-to ((arg0 int)) + (dotimes (s5-0 arg0) + (format #t " ") + ) + (none) + ) +(define-extern probe-traverse-draw-node (function draw-node int none)) + +(defun probe-traverse-draw-node ((arg0 draw-node) (arg1 int)) + (indent-to arg1) + (format + #t + "[~08x] child-count: ~d, flags: ~d, dist: ~f, child: ~a~%" + arg0 + (-> arg0 child-count) + (-> arg0 flags) + (-> arg0 distance) + (-> arg0 child) + ) + (cond + ((nonzero? (-> arg0 flags)) + (let ((s4-0 (-> arg0 child))) + (dotimes (s3-0 (the-as int (-> arg0 child-count))) + (probe-traverse-draw-node (the-as draw-node (+ (the-as uint s4-0) (* s3-0 32))) (+ arg1 1)) + ) + ) + ) + (else + ) + ) + 0 + (none) + ) + +(defun probe-traverse-inline-array-node ((arg0 drawable-inline-array-node) (arg1 int)) + (indent-to arg1) + (format #t "[~08x] drawable-inline-array-node: length = ~d~%" arg0 (-> arg0 length)) + (let ((s4-0 (-> arg0 length))) + (dotimes (s3-0 s4-0) + (indent-to arg1) + (format #t "(~3d) ~a~%" s3-0 (-> arg0 data s3-0)) + (if (= (-> arg0 data s3-0 type) draw-node) + (probe-traverse-draw-node (-> arg0 data s3-0) (+ arg1 1)) + ) + ) + ) + (none) + ) + +(defun probe-traverse-collide-fragment ((arg0 drawable-tree-collide-fragment) (arg1 int)) + (indent-to arg1) + (format #t "[~08x] drawable-tree-collide-fragment: length = ~d~%" arg0 (-> arg0 length)) + (let ((s4-0 (-> arg0 length))) + (dotimes (s3-0 (+ s4-0 -1)) + (indent-to arg1) + (if (= (-> arg0 data s3-0 type) drawable-inline-array-node) + (probe-traverse-inline-array-node (the-as drawable-inline-array-node (-> arg0 data s3-0)) (+ arg1 1)) + (format #t "unknown: ~a~%" (-> arg0 data s3-0)) + ) + ) + ) + (none) + ) + +(deftype collide-probe-stack-elem (structure) + ((child uint32 :offset-assert 0) + (count uint32 :offset-assert 4) + ) + :method-count-assert 9 + :size-assert #x8 + :flag-assert #x900000008 + ) + +(deftype collide-probe-stack (structure) + ((data collide-probe-stack-elem 1024 :inline :offset-assert 0) + ) + :method-count-assert 9 + :size-assert #x4000 + :flag-assert #x900004000 + ) + + +(define *collide-probe-stack* (the-as collide-probe-stack (+ 4192 #x70000000))) + +(define collide-vu0-block (new 'static 'vu-function :length 90 :qlength 45)) + +;; definition for function collide-probe-node +;; ERROR: function was not converted to expressions. Cannot decompile. + +(defun print-out ((arg0 int)) + (format *stdcon* "~d~%" arg0) + ) + +(defun collide-probe-instance-tie-collide-frags () + 0 + (none) + ) + +;; definition for function collide-probe-instance-tie +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function collide-probe-collide-fragment-tree-make-list +;; ERROR: failed type prop at 6: Could not figure out load: (set! v1 (l.h (+ v1 2))) +;; ERROR: Function may read a register that is not set: a2 + + +;; definition for function collide-probe-instance-tie-tree-make-list +;; ERROR: failed type prop at 6: Could not figure out load: (set! v1 (l.h (+ v1 2))) +;; WARN: Return type mismatch none vs int. +;; ERROR: Function may read a register that is not set: a2 + + +;; definition for function collide-upload-vu0 +;; WARN: Return type mismatch int vs none. +;; WARN: Failed store: (s.d! (+ a0-5 8) 0) at op 17 + + +;; definition for function collide-probe-make-list +;; ERROR: failed type prop at 23: Could not figure out load: (set! a1 (l.h (+ v1 2))) +;; WARN: Return type mismatch symbol vs none. +;; ERROR: Function may read a register that is not set: a2 + + +(defun distc ((arg0 vector) (arg1 vector)) + (let* ((f0-1 (- (-> arg0 x) (-> arg1 x))) + (f0-3 (* f0-1 f0-1)) + (f1-2 (- (-> arg0 z) (-> arg1 z))) + ) + (sqrtf (+ f0-3 (* f1-2 f1-2))) + ) + ) + +(defun interpolate ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + (let ((f0-1 (- arg3 arg1)) + (f1-2 (- arg4 arg2)) + (f3-1 (- arg0 arg1)) + ) + (+ arg2 (/ (* f3-1 f1-2) f0-1)) + ) + ) + +(defun misty-ambush-height ((arg0 vector)) + (let* ((a1-0 (new 'static 'vector :x -808960.0 :y 111656.96 :z 3924992.0)) + (f0-0 (distc arg0 a1-0)) + ) + (cond + ((< f0-0 52019.2) + 111656.96 + ) + ((>= 58982.4 f0-0) + (interpolate f0-0 52019.2 111656.96 58982.4 116776.96) + ) + ((>= 124436.48 f0-0) + (interpolate f0-0 58982.4 116776.96 124436.48 114688.0) + ) + ((>= 219217.92 f0-0) + (interpolate f0-0 124436.48 114688.0 219217.92 113254.4) + ) + (else + 113254.4 + ) + ) + ) + ) + +(defun misty-ambush-height-probe ((arg0 vector) (arg1 float)) + (let ((f0-0 (misty-ambush-height arg0))) + (cond + ((< f0-0 (-> arg0 y)) + (/ (- (-> arg0 y) f0-0) arg1) + ) + (else + (format 0 "WARNING: ~%height = ~f, pos.y = ~f" (* 0.00024414062 f0-0) (* 0.00024414062 (-> arg0 y))) + -1.0 + ) + ) + ) + ) + +(defun pke-collide-test () + 0 + (none) + ) + + + + diff --git a/goal_src/jak2/engine/collide/collide-shape-h.gc b/goal_src/jak2/engine/collide/collide-shape-h.gc index 9a1e64c3cf..05a4533433 100644 --- a/goal_src/jak2/engine/collide/collide-shape-h.gc +++ b/goal_src/jak2/engine/collide/collide-shape-h.gc @@ -381,8 +381,8 @@ (:methods (new (symbol type collide-shape uint int) _type_ 0) (collide-shape-prim-method-9 () none 9) - (collide-shape-prim-method-10 () none 10) - (collide-shape-prim-method-11 () none 11) + (add-fg-prim-using-box () none 10) + (add-fg-prim-using-line-sphere () none 11) (collide-shape-prim-method-12 () none 12) (collide-shape-prim-method-13 () none 13) (collide-shape-prim-method-14 () none 14) diff --git a/goal_src/jak2/engine/collide/los-control.gc b/goal_src/jak2/engine/collide/los-control.gc index 3e4e1519f7..2bcdcfe05e 100644 --- a/goal_src/jak2/engine/collide/los-control.gc +++ b/goal_src/jak2/engine/collide/los-control.gc @@ -50,7 +50,7 @@ (set! (-> query action-mask) (collide-action solid)) ) (fill-using-line-sphere *collide-cache* cquery) - (let ((f30-0 (collide-cache-method-16 *collide-cache* cquery))) + (let ((f30-0 (probe-using-line-sphere *collide-cache* cquery))) (quad-copy! (the-as pointer (-> obj last-collide-result)) (the-as pointer (-> cquery best-other-tri)) 6) (if (>= 0.0 f30-0) (set! (-> obj have-no-los) (-> self clock frame-counter)) diff --git a/goal_src/jak2/engine/draw/drawable-h.gc b/goal_src/jak2/engine/draw/drawable-h.gc index 8479c6915b..1ae1991d97 100644 --- a/goal_src/jak2/engine/draw/drawable-h.gc +++ b/goal_src/jak2/engine/draw/drawable-h.gc @@ -6,6 +6,9 @@ ;; dgos: ENGINE, GAME (declare-type region-prim-list structure) +(declare-type collide-list structure) +(declare-type collide-query structure) + ;; NOTE - for sparticle-launcher and editable (define-extern sphere-in-view-frustum? (function sphere symbol)) @@ -18,12 +21,13 @@ (define-extern prototype-bucket-recalc-fields (function prototype-bucket prototype-bucket)) (define-extern determine-pause-mode (function int)) (define-extern vis-cull (function int symbol)) +(define-extern sphere-cull (function vector symbol)) ;; DECOMP BEGINS (deftype drawable (basic) - ((id int16 :offset-assert 4) - (bsphere vector :inline :offset-assert 16) + ((id int16 :offset-assert 4) + (bsphere vector :inline :offset-assert 16) ) :method-count-assert 17 :size-assert #x20 @@ -31,11 +35,12 @@ (:methods (login (_type_) _type_ 9) (draw (_type_ _type_ display-frame) none 10) - (drawable-method-11 () none 11) - (drawable-method-12 () none 12) + (fill-collide-list-from-box (_type_ int collide-list collide-query) int 11) + (fill-collide-list-from-line-sphere (_type_ int collide-list collide-query) int 12) (collect-stats (_type_) none 13) (debug-draw (_type_ drawable display-frame) none 14) (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) + (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) (collect-regions (_type_ sphere int region-prim-list) none 16) ) ) diff --git a/goal_src/jak2/engine/draw/drawable.gc b/goal_src/jak2/engine/draw/drawable.gc index a23c06cf59..0483a7a62f 100644 --- a/goal_src/jak2/engine/draw/drawable.gc +++ b/goal_src/jak2/engine/draw/drawable.gc @@ -224,14 +224,14 @@ (none) ) -(defmethod drawable-method-11 drawable () +(defmethod fill-collide-list-from-box drawable ((obj drawable) (arg0 int) (arg1 collide-list) (arg2 collide-query)) + "Collect a list of collision meshes contained in the box." 0 - (none) ) -(defmethod drawable-method-12 drawable () +(defmethod fill-collide-list-from-line-sphere drawable ((obj drawable) (arg0 int) (arg1 collide-list) (arg2 collide-query)) + "Collect a list of collision meshes contained in 'line-sphere'." 0 - (none) ) (defmethod collect-regions drawable ((obj drawable) (arg0 sphere) (arg1 int) (arg2 region-prim-list)) diff --git a/goal_src/jak2/engine/gfx/background/prototype-h.gc b/goal_src/jak2/engine/gfx/background/prototype-h.gc index 3abc8a5ec6..0069abfeca 100644 --- a/goal_src/jak2/engine/gfx/background/prototype-h.gc +++ b/goal_src/jak2/engine/gfx/background/prototype-h.gc @@ -6,6 +6,7 @@ ;; dgos: ENGINE, GAME (declare-type prototype-tie drawable) +(declare-type collide-hash-fragment-array basic) (defenum prototype-flags :bitfield #t @@ -14,10 +15,17 @@ ;; (use-envmap 1) maybe (tpage-alpha 2) (vanish 3) + (no-collide 6) (tpage-water 7) ) +(defenum instance-flags + :type uint16 + :bitfield #t + (no-collide 0) + ) + ;; DECOMP BEGINS (deftype prototype-bucket (basic) @@ -90,7 +98,7 @@ (envmap-fade-far float :offset-assert 164) (envmap-shader adgif-shader :offset-assert 168) (tint-color uint32 :offset-assert 172) - (collide-hash-fragment-array basic :offset-assert 176) + (collide-hash-fragment-array collide-hash-fragment-array :offset-assert 176) (tie-colors time-of-day-palette :offset-assert 180) (data uint32 :dynamic :offset-assert 184) (color-index-qwc uint32 :dynamic :offset-assert 184) @@ -188,12 +196,13 @@ ) (deftype instance (drawable) - ((bucket-index uint16 :offset 6) - (origin matrix4h :inline :offset-assert 32) - (flags uint16 :offset 46) - (wind-index uint16 :offset 62) + ((bucket-index uint16 :offset 6) + (origin matrix4h :inline :offset-assert 32) + (flags instance-flags :offset 46) + (wind-index uint16 :offset 62) ) :method-count-assert 17 :size-assert #x40 :flag-assert #x1100000040 ) + diff --git a/goal_src/jak2/engine/gfx/mood/weather-part.gc b/goal_src/jak2/engine/gfx/mood/weather-part.gc index 3e3db0ca37..6248f9b3af 100644 --- a/goal_src/jak2/engine/gfx/mood/weather-part.gc +++ b/goal_src/jak2/engine/gfx/mood/weather-part.gc @@ -582,7 +582,7 @@ ) (fill-using-line-sphere *collide-cache* s4-0) (cond - ((>= (collide-cache-method-16 *collide-cache* s4-0) 0.0) + ((>= (probe-using-line-sphere *collide-cache* s4-0) 0.0) (set! (-> arg1 user-float) (-> s4-0 best-other-tri intersect y)) (let ((f0-8 (+ 65536.0 (-> *math-camera* trans y)))) (if (< (-> arg1 user-float) f0-8) diff --git a/goal_src/jak2/engine/gfx/ocean/ocean-h.gc b/goal_src/jak2/engine/gfx/ocean/ocean-h.gc index bdd074da9d..6fab74f322 100644 --- a/goal_src/jak2/engine/gfx/ocean/ocean-h.gc +++ b/goal_src/jak2/engine/gfx/ocean/ocean-h.gc @@ -519,7 +519,7 @@ (ocean-method-15 () none 15) (ocean-method-16 () none 16) (ocean-method-17 () none 17) - (ocean-method-18 () none 18) + (ocean-method-18 (_type_ object object) none 18) (ocean-method-19 () none 19) (ocean-method-20 () none 20) (ocean-method-21 (_type_ float float) float 21) diff --git a/goal_src/jak2/engine/physics/trajectory.gc b/goal_src/jak2/engine/physics/trajectory.gc index cacb41e5f9..7680c486de 100644 --- a/goal_src/jak2/engine/physics/trajectory.gc +++ b/goal_src/jak2/engine/physics/trajectory.gc @@ -162,7 +162,7 @@ ) (set! (-> a0-6 radius) (-> obj radius)) (set! (-> a0-6 collide-with) (-> obj collide-with)) - (set! (-> a0-6 ignore-process0) v1-2) + (set! (-> a0-6 ignore-process0) (the process-drawable v1-2)) (set! (-> a0-6 ignore-process1) #f) (set! (-> a0-6 ignore-pat) arg2) (set! (-> a0-6 action-mask) (collide-action solid)) diff --git a/goal_src/jak2/engine/spatial-hash/collide-hash-h.gc b/goal_src/jak2/engine/spatial-hash/collide-hash-h.gc index d03570df85..681f91dbe3 100644 --- a/goal_src/jak2/engine/spatial-hash/collide-hash-h.gc +++ b/goal_src/jak2/engine/spatial-hash/collide-hash-h.gc @@ -41,6 +41,7 @@ ((id uint32 :offset-assert 0) (collidable basic :offset-assert 4) ) + :pack-me :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 @@ -95,26 +96,26 @@ ) (deftype collide-hash-fragment-array (array) - () + ((fragments collide-hash-fragment :dynamic :offset 16)) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) (deftype collide-hash (drawable) - ((num-ids uint16 :offset 4) - (id-count uint16 :offset 6) - (num-buckets uint32 :offset 8) - (qwc-id-bits uint32 :offset 12) - (grid-step vector :inline :offset 16) - (bbox bounding-box :inline :offset-assert 32) - (bbox4w bounding-box4w :inline :offset-assert 64) - (axis-scale vector :inline :offset 48) - (avg-extents vector :inline :offset 64) - (bucket-array uint32 :offset 44) - (item-array uint32 :offset 60) - (dimension-array uint32 3 :offset 76) - (num-items uint32 :offset 92) + ((num-ids uint16 :offset 4) + (id-count uint16 :offset 6) + (num-buckets uint32 :offset 8) + (qwc-id-bits uint32 :offset 12) + (grid-step vector :inline :offset 16) + (bbox bounding-box :inline :offset-assert 32) + (bbox4w bounding-box4w :inline :offset-assert 64) + (axis-scale vector :inline :offset 48) + (avg-extents vector :inline :offset 64) + (bucket-array uint32 :offset 44) + (item-array (inline-array collide-hash-item) :offset 60) + (dimension-array uint32 3 :offset 76) + (num-items uint32 :offset 92) ) :method-count-assert 17 :size-assert #x60 diff --git a/goal_src/jak2/engine/spatial-hash/collide-hash.gc b/goal_src/jak2/engine/spatial-hash/collide-hash.gc index e410f410a8..0590276f18 100644 --- a/goal_src/jak2/engine/spatial-hash/collide-hash.gc +++ b/goal_src/jak2/engine/spatial-hash/collide-hash.gc @@ -7,3 +7,595 @@ ;; DECOMP BEGINS +;; collide-hash is the broad phase collision detector for background collisions. +;; It esssentially answers the question "what collide fragments are near X"? +;; and this answer is passed down to lower level collision checks. + + +;; unlike jak 1, this uses a "spatial hash". The idea is to divide space into a grid, then map +;; cells in this grid to a smaller number of buckets using a hash function. + +;; hash collisions are probably not too common, as most space is empty, and can be reject relatively quickly +;; by doing a bounding sphere check with the collision fragments. + +;; in this file, boxes are commonly represented as a vector, with xyz being the origin, and w being half +;; the side length. + +(defun add-collide-debug-box ((arg0 vector) (arg1 rgba)) + "Debug draw a box represented as (origin, half-side-length)." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (let ((a3-0 (new 'stack-no-clear 'bounding-box))) + (.lvf vf1 (&-> arg0 quad)) + (.sub.w.vf vf2 vf1 vf1) + (.add.w.vf vf3 vf1 vf1) + (.svf (&-> a3-0 min quad) vf2) + (.svf (&-> a3-0 max quad) vf3) + (add-debug-box #t (bucket-id debug2) (-> a3-0 min) (-> a3-0 max) arg1) + ) + (none) + ) + ) + +(defun-debug print-collide-cache-tri-count () + "Print the number of triangles in the collide cache." + (let ((gp-0 0) + (s4-0 0) + (s5-0 0) + (s3-0 0) + ) + (let ((v1-0 *collide-cache*)) + (dotimes (a0-0 (-> v1-0 num-tris)) + (case (-> v1-0 tris a0-0 pat mode) + (((pat-mode ground)) + (+! gp-0 1) + ) + (((pat-mode wall)) + (+! s5-0 1) + ) + (((pat-mode obstacle)) + (+! s4-0 1) + ) + (else + (+! s3-0 1) + ) + ) + ) + (format *stdcon* "tris ~d (~4,,1f%) " (-> v1-0 num-tris) (* 0.2173913 (the float (-> v1-0 num-tris)))) + ) + (format *stdcon* "(ground ~d, wall ~d, obstacle ~d, other ~d)~%" gp-0 s5-0 s4-0 s3-0) + ) + (none) + ) + +(defun-debug print-exceeded-max-cache-tris () + "Complain that the collide cache is full." + (with-pp + (when (not *already-printed-exeeded-max-cache-tris*) + (set! *already-printed-exeeded-max-cache-tris* #t) + (if pp + (format *stdcon* "Exceeded collide cache max # of tris (~s)!~%" (-> pp name)) + (format *stdcon* "Exceeded collide cache max # of tris!~%") + ) + (print-collide-cache-tri-count) + ) + 0 + (none) + ) + ) + +;; these methods fill a collide list, given a collide query. This does the actual spatial hash. +(defmethod-mips2c "(method 11 collide-hash)" 11 collide-hash) +(defmethod-mips2c "(method 12 collide-hash)" 12 collide-hash) + +;; these methods do the work of writing triangles into the collide cache. +(def-mips2c fill-bg-using-box-new (function collide-cache object collide-query none)) +(def-mips2c fill-bg-using-line-sphere-new (function collide-cache object collide-query none)) + +(defun collide-list-fill-bg-using-box ((arg0 collide-cache) (arg1 collide-list) (arg2 collide-query)) + "Given a list of collision meshes, fill the given collide collide with triangles which are + inside the box." + (local-vars + (v1-12 uint128) + (v1-14 uint128) + (v1-15 uint128) + (a0-10 uint128) + (a0-11 uint128) + (a1-3 uint128) + (a2-3 uint128) + (a2-4 uint128) + (sv-16 int) + (sv-20 collide-list) + (sv-640 int) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf16 :class vf) + (vf17 :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) + (set! sv-16 (-> arg1 num-items)) + (set! sv-20 arg1) + + ;; loop over collision meshes. + (dotimes (s4-0 sv-16) + (let ((s3-0 (-> sv-20 items s4-0 mesh))) + (cond + ((= (-> s3-0 type) instance-tie) ;; it's an instanced collision mesh. + (let* ((v1-4 s3-0) + (s1-0 (-> v1-4 bucket-ptr)) + ) + ;; only both checking if collision is enabled on this geometry. + (when (not (or (logtest? (-> s1-0 flags) (prototype-flags no-collide)) + (logtest? (-> v1-4 flags) (instance-flags no-collide)) + ) + ) + ;; debug draw. + (if *collide-list-boxes* + (add-collide-debug-box (-> s3-0 bsphere) (new 'static 'rgba :r #xff :a #x80)) + ) + + ;; we need to created a modified query to account for the transformation of the instanced mesh. + (let ((s0-0 (new 'stack-no-clear 'matrix)) + (s2-0 (new 'stack-no-clear 'collide-query)) + ) + ;; start with the input query, copied. + (mem-copy! (the-as pointer s2-0) (the-as pointer arg2) 540) + + ;; unpack the instance matrix. + (let ((v1-11 (the-as uint128 (-> s3-0 origin vector4h 3 long)))) + (let ((a2-2 (the-as uint128 (-> s3-0 origin vector4h 0 long)))) + (.pextlh v1-12 v1-11 0) + (let ((a0-9 (the-as uint128 (-> s3-0 origin vector4h 1 long)))) + (.pw.sra a1-3 v1-12 10) + (let ((v1-13 (the-as uint128 (-> s3-0 origin vector4h 2 long)))) + (.pextlh a2-3 a2-2 0) + (.pw.sra a2-4 a2-3 16) + (.pextlh a0-10 a0-9 0) + (.mov vf4 a1-3) + (.pw.sra a0-11 a0-10 16) + (.mov vf1 a2-4) + (.pextlh v1-14 v1-13 0) + ) + ) + ) + ) + (.mov vf2 a0-11) + (.pw.sra v1-15 v1-14 16) + (.lvf vf5 (&-> s3-0 bsphere quad)) + (.mov vf3 v1-15) + (.itof.vf vf4 vf4) + (vitof12.xyzw vf1 vf1) + (vitof12.xyzw vf2 vf2) + (vitof12.xyzw vf3 vf3) + (.add.vf vf4 vf4 vf5 :mask #b111) + + ;; pass the instance mat down. + (.svf (&-> s2-0 instance-mat vector 0 quad) vf1) + (.svf (&-> s2-0 instance-mat vector 1 quad) vf2) + (.svf (&-> s2-0 instance-mat vector 2 quad) vf3) + (.svf (&-> s2-0 instance-mat trans quad) vf4) + + ;; transform the bounding box to instance coordinates. + (matrix-4x4-inverse! s0-0 (-> s2-0 instance-mat)) + (.lvf vf7 (&-> arg2 bbox min quad)) + (.lvf vf14 (&-> arg2 bbox max quad)) + (.lvf vf1 (&-> s0-0 vector 0 quad)) + (.lvf vf2 (&-> s0-0 vector 1 quad)) + (.lvf vf3 (&-> s0-0 vector 2 quad)) + (.lvf vf4 (&-> s0-0 trans quad)) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf7 acc) + (.add.mul.y.vf acc vf2 vf7 acc) + (.add.mul.z.vf vf8 vf3 vf14 acc) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf7 acc) + (.add.mul.y.vf acc vf2 vf14 acc) + (.add.mul.z.vf vf9 vf3 vf7 acc) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf7 acc) + (.add.mul.y.vf acc vf2 vf14 acc) + (.add.mul.z.vf vf10 vf3 vf14 acc) + (.min.vf vf5 vf8 vf9) + (.max.vf vf6 vf8 vf9) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf14 acc) + (.add.mul.y.vf acc vf2 vf7 acc) + (.add.mul.z.vf vf11 vf3 vf7 acc) + (.min.vf vf5 vf5 vf10) + (.max.vf vf6 vf6 vf10) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf14 acc) + (.add.mul.y.vf acc vf2 vf7 acc) + (.add.mul.z.vf vf12 vf3 vf14 acc) + (.min.vf vf5 vf5 vf11) + (.max.vf vf6 vf6 vf11) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf14 acc) + (.add.mul.y.vf acc vf2 vf14 acc) + (.add.mul.z.vf vf13 vf3 vf7 acc) + (.min.vf vf5 vf5 vf12) + (.max.vf vf6 vf6 vf12) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf14 acc) + (.add.mul.y.vf acc vf2 vf14 acc) + (.add.mul.z.vf vf14 vf3 vf14 acc) + (.min.vf vf5 vf5 vf13) + (.max.vf vf6 vf6 vf13) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf7 acc) + (.add.mul.y.vf acc vf2 vf7 acc) + (.add.mul.z.vf vf7 vf3 vf7 acc) + (.min.vf vf5 vf5 vf14) + (.max.vf vf6 vf6 vf14) + (.min.vf vf5 vf5 vf7) + (.max.vf vf6 vf6 vf7) + (.ftoi.vf vf16 vf5) + (.ftoi.vf vf17 vf6) + + ;; update collision query with transformed box + (.svf (&-> s2-0 bbox min quad) vf5) + (.svf (&-> s2-0 bbox max quad) vf6) + (.svf (&-> s2-0 bbox4w min quad) vf16) + (.svf (&-> s2-0 bbox4w max quad) vf17) + + ;; loop over fragments in the mesh. + (let ((s1-1 (-> s1-0 collide-hash-fragment-array))) + (set! sv-640 (-> s1-1 length)) + (set! (-> s2-0 instance-ptr) s3-0) + (dotimes (s3-1 sv-640) + ;; not sure why we set this, maybe something used by the asm function + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 0) (the-as uint128 0)) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 1) (the-as uint128 0)) + ;; reset triangle count + (set! (-> (scratchpad-object collide-hash-scratch) tris) (the-as uint 0)) + ;; unpack triangles, filter, and store in collide cache. + (fill-bg-using-box-new arg0 (-> s1-1 fragments s3-1) s2-0) + ;; update stats + (+! (-> *collide-stats* tris) (-> (scratchpad-object collide-hash-scratch) tris)) + ) + ) + ) + ) + ) + ) + (else + ;; colliding with non-instanced mesh. Don't need to update query. + (if *collide-list-boxes* + (add-collide-debug-box (-> s3-0 bsphere) (new 'static 'rgba :r #xff :g #xff :a #x80)) + ) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 0) (the-as uint128 0)) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 1) (the-as uint128 0)) + (set! (-> arg2 instance-ptr) #f) + (set! (-> (scratchpad-object collide-hash-scratch) tris) (the-as uint 0)) + (fill-bg-using-box-new arg0 s3-0 arg2) + (+! (-> *collide-stats* tris) (-> (scratchpad-object collide-hash-scratch) tris)) + ) + ) + ) + ) + 0 + (none) + ) + ) + +(defmacro .sll (result in sa) + `(set! ,result (sext32 (the-as int (shl (logand ,in #xffffffff) ,sa)))) + ) + +(defun collide-list-fill-bg-using-line-sphere ((arg0 collide-cache) (arg1 collide-list) (arg2 collide-query)) + "line-sphere version of collide-list-fill-bg-using-box. + Logic is basically the same, but transforming the line-sphere query is a bit trickier." + (local-vars + (v1-12 uint128) + (v1-14 uint128) + (v1-15 uint128) + (v1-17 number) + (v1-26 float) + (a0-10 uint128) + (a0-11 uint128) + (a1-3 uint128) + (a2-3 uint128) + (a2-4 uint128) + (sv-16 int) + (sv-640 int) + ) + (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) + (set! sv-16 (-> arg1 num-items)) + (dotimes (s3-0 sv-16) + (let ((s2-0 (-> arg1 items s3-0 mesh))) + (cond + ((= (-> s2-0 type) instance-tie) + ;; it's an instance, we'll need some fancy logic to transform the query to be in the instance coordinates. + (let ((v1-4 s2-0)) + (when (not (or (logtest? (-> v1-4 bucket-ptr flags) (prototype-flags no-collide)) + (logtest? (-> v1-4 flags) (instance-flags no-collide)) + ) + ) + (if *collide-list-boxes* + (add-collide-debug-box (-> s2-0 bsphere) (new 'static 'rgba :r #xff :a #x80)) + ) + (let ((s0-0 (new 'stack-no-clear 'matrix)) + (s1-0 (new 'stack-no-clear 'collide-query)) + ) + ;; copy original query + (mem-copy! (the-as pointer s1-0) (the-as pointer arg2) 540) + ;; unpack instance matrix + (let ((v1-11 (the-as uint128 (-> s2-0 origin vector4h 3 long)))) + (let ((a2-2 (the-as uint128 (-> s2-0 origin vector4h 0 long)))) + (.pextlh v1-12 v1-11 0) + (let ((a0-9 (the-as uint128 (-> s2-0 origin vector4h 1 long)))) + (.pw.sra a1-3 v1-12 10) + (let ((v1-13 (the-as uint128 (-> s2-0 origin vector4h 2 long)))) + (.pextlh a2-3 a2-2 0) + (.pw.sra a2-4 a2-3 16) + (.pextlh a0-10 a0-9 0) + (.mov vf4 a1-3) + (.pw.sra a0-11 a0-10 16) + (.mov vf1 a2-4) + (.pextlh v1-14 v1-13 0) + ) + ) + ) + ) + (.mov vf2 a0-11) + (.pw.sra v1-15 v1-14 16) + (.lvf vf5 (&-> s2-0 bsphere quad)) + (.mov vf3 v1-15) + (.itof.vf vf4 vf4) + (vitof12.xyzw vf1 vf1) + (vitof12.xyzw vf2 vf2) + (vitof12.xyzw vf3 vf3) + (.add.vf vf4 vf4 vf5 :mask #b111) + (.svf (&-> s1-0 instance-mat vector 0 quad) vf1) + (.svf (&-> s1-0 instance-mat vector 1 quad) vf2) + (.svf (&-> s1-0 instance-mat vector 2 quad) vf3) + (.svf (&-> s1-0 instance-mat trans quad) vf4) + + ;; invert + (matrix-4x4-inverse! s0-0 (-> s1-0 instance-mat)) + (.lvf vf7 (&-> arg2 start-pos quad)) + (.lvf vf8 (&-> arg2 move-dist quad)) + (.lvf vf1 (&-> s0-0 vector 0 quad)) + (.lvf vf2 (&-> s0-0 vector 1 quad)) + (.lvf vf3 (&-> s0-0 vector 2 quad)) + (.lvf vf4 (&-> s0-0 trans quad)) + (.add.vf vf8 vf7 vf8) + (let ((v1-16 (-> s2-0 rmin-scale))) + (.mul.x.vf acc vf1 vf7) + (let ((f2-0 (-> arg2 radius))) + (.add.mul.y.vf acc vf2 vf7 acc) + (.sll v1-17 v1-16 16) + (.add.mul.z.vf acc vf3 vf7 acc) + (let ((f1-0 (the-as float v1-17))) + (.add.mul.w.vf vf7 vf4 vf0 acc) + (.mul.x.vf acc vf1 vf8) + (let ((f2-1 (* f2-0 f1-0))) + (.add.mul.y.vf acc vf2 vf8 acc) + (.add.mul.z.vf acc vf3 vf8 acc) + (.add.mul.w.vf vf8 vf4 vf0 acc) + (.svf (&-> s1-0 start-pos quad) vf7) + (.min.vf vf5 vf7 vf8) + (set! (-> s1-0 radius) f2-1) + ) + ) + ) + ) + (.max.vf vf6 vf7 vf8) + (.lvf vf9 (&-> s1-0 exit-planes 0 quad)) + (.sub.vf vf8 vf8 vf7) + (.sub.w.vf vf5 vf5 vf9) + (.add.w.vf vf6 vf6 vf9) + (.svf (&-> s1-0 move-dist quad) vf8) + (.ftoi.vf vf10 vf5) + (.ftoi.vf vf11 vf6) + (.svf (&-> s1-0 bbox min quad) vf5) + (.svf (&-> s1-0 bbox max quad) vf6) + (.svf (&-> s1-0 bbox4w min quad) vf10) + (.svf (&-> s1-0 bbox4w max quad) vf11) + (set! (-> s1-0 rlength x) (if (= (-> s1-0 move-dist x) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist x)) + ) + ) + (set! (-> s1-0 rlength y) (if (= (-> s1-0 move-dist y) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist y)) + ) + ) + (set! (-> s1-0 rlength z) (if (= (-> s1-0 move-dist z) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist z)) + ) + ) + (let ((f0-12 1.0)) + (.lvf vf1 (&-> (-> s1-0 move-dist) 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-26 vf1) + (set! (-> s1-0 rlength w) (/ f0-12 v1-26)) + ) + (set! (-> s1-0 exit-planes 0 x) (if (< 0.0 (-> s1-0 move-dist x)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 0 y) (if (< 0.0 (-> s1-0 move-dist y)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 0 z) (if (< 0.0 (-> s1-0 move-dist z)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 x) (if (< (-> s1-0 move-dist x) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 y) (if (< (-> s1-0 move-dist y) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 z) (if (< (-> s1-0 move-dist z) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (let ((s0-1 (-> s2-0 bucket-ptr collide-hash-fragment-array))) + (set! sv-640 (-> s0-1 length)) + (set! (-> s1-0 instance-ptr) s2-0) + (dotimes (s2-1 sv-640) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 0) (the-as uint128 0)) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 1) (the-as uint128 0)) + (set! (-> (scratchpad-object collide-hash-scratch) tris) (the-as uint 0)) + (fill-bg-using-line-sphere-new arg0 (-> s0-1 fragments s2-1) s1-0) + (+! (-> *collide-stats* tris) (-> (scratchpad-object collide-hash-scratch) tris)) + ) + ) + ) + ) + ) + ) + (else + (if *collide-list-boxes* + (add-collide-debug-box (-> s2-0 bsphere) (new 'static 'rgba :r #xff :g #xff :a #x80)) + ) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 0) (the-as uint128 0)) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits 1) (the-as uint128 0)) + (set! (-> arg2 instance-ptr) #f) + (set! (-> (scratchpad-object collide-hash-scratch) tris) (the-as uint 0)) + (fill-bg-using-line-sphere-new arg0 s2-0 arg2) + (+! (-> *collide-stats* tris) (-> (scratchpad-object collide-hash-scratch) tris)) + ) + ) + ) + ) + 0 + (none) + ) + ) + +(defmethod mem-usage collide-hash ((obj collide-hash) (arg0 memory-usage-block) (arg1 int)) + "This one is a bit weird because it touches stuff in the scratchpad... + It's called from the bsp-header's mem-usage function, so it should be fine." + (set! (-> arg0 length) (max 51 (-> arg0 length))) + (set! (-> arg0 data 50 name) (symbol->string 'collision)) + (+! (-> arg0 data 50 count) 1) + (let ((v1-10 (+ (* (-> obj num-items) 8) 96 (* (-> obj num-buckets) 4)))) + (+! (-> arg0 data 50 used) v1-10) + (+! (-> arg0 data 50 total) (logand -16 (+ v1-10 15))) + ) + (dotimes (v1-14 (the-as int (-> obj qwc-id-bits))) + (set! (-> (scratchpad-object collide-hash-scratch) collidable-bits v1-14) (the-as uint128 0)) + ) + (dotimes (s3-0 (the-as int (-> obj num-items))) + (let* ((a0-12 (-> obj item-array s3-0 id)) + (v1-19 (shr a0-12 5)) + ) + (when (not (logtest? (-> (scratchpad-object collide-hash-scratch) id-bits v1-19) (ash 1 (logand a0-12 31)))) + (logior! (-> (scratchpad-object collide-hash-scratch) id-bits v1-19) (ash 1 (logand a0-12 31))) + (if (= (-> obj item-array s3-0 collidable type) collide-hash-fragment) + (mem-usage (-> obj item-array s3-0 collidable) arg0 arg1) + ) + ) + ) + ) + obj + ) + +(defmethod mem-usage collide-hash-fragment ((obj collide-hash-fragment) (arg0 memory-usage-block) (arg1 int)) + (cond + ((logtest? arg1 1) + (set! (-> arg0 length) (max 58 (-> arg0 length))) + (set! (-> arg0 data 55 name) (symbol->string 'prototype-fragment)) + (+! (-> arg0 data 55 count) 1) + (set! (-> arg0 data 56 name) (symbol->string 'prototype-poly)) + (+! (-> arg0 data 56 count) (the-as int (-> obj stats num-polys))) + (set! (-> arg0 data 57 name) (symbol->string 'prototype-vertex)) + (+! (-> arg0 data 57 count) (the-as int (-> obj stats num-verts))) + (let ((a3-0 (+ (-> obj num-indices) 112 (* (-> obj num-buckets) 4))) + (a2-9 (* (-> obj stats num-polys) 4)) + (v1-22 (* (the-as uint 6) (the-as uint (-> obj stats num-verts)))) + ) + (+! (-> arg0 data 55 used) a3-0) + (+! (-> arg0 data 55 total) (- (logand -16 (+ v1-22 15 a2-9 a3-0)) (the-as int (+ a2-9 v1-22)))) + (+! (-> arg0 data 56 used) a2-9) + (+! (-> arg0 data 56 total) a2-9) + (+! (-> arg0 data 57 used) v1-22) + (+! (-> arg0 data 57 total) v1-22) + ) + ) + (else + (set! (-> arg0 length) (max 54 (-> arg0 length))) + (set! (-> arg0 data 51 name) (symbol->string 'collision-fragment)) + (+! (-> arg0 data 51 count) 1) + (set! (-> arg0 data 52 name) (symbol->string 'collision-poly)) + (+! (-> arg0 data 52 count) (the-as int (-> obj stats num-polys))) + (set! (-> arg0 data 53 name) (symbol->string 'collision-vertex)) + (+! (-> arg0 data 53 count) (the-as int (-> obj stats num-verts))) + (let ((a3-8 (+ (-> obj num-indices) 112 (* (-> obj num-buckets) 4))) + (a2-22 (* (-> obj stats num-polys) 4)) + (v1-45 (* (the-as uint 6) (the-as uint (-> obj stats num-verts)))) + ) + (+! (-> arg0 data 51 used) a3-8) + (+! (-> arg0 data 51 total) (- (logand -16 (+ v1-45 15 a2-22 a3-8)) (the-as int (+ a2-22 v1-45)))) + (+! (-> arg0 data 52 used) a2-22) + (+! (-> arg0 data 52 total) a2-22) + (+! (-> arg0 data 53 used) v1-45) + (+! (-> arg0 data 53 total) v1-45) + ) + ) + ) + obj + ) + +(defmethod mem-usage collide-hash-fragment-array ((obj collide-hash-fragment-array) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 55 (-> arg0 length))) + (set! (-> arg0 data 54 name) (symbol->string 'prototype-collision)) + (+! (-> arg0 data 54 count) 1) + (let ((v1-8 (asize-of obj))) + (+! (-> arg0 data 54 used) v1-8) + (+! (-> arg0 data 54 total) (logand -16 (+ v1-8 15))) + ) + (dotimes (s3-0 (-> obj length)) + (mem-usage (-> obj fragments s3-0) arg0 arg1) + ) + obj + ) diff --git a/goal_src/jak2/engine/target/logic-target.gc b/goal_src/jak2/engine/target/logic-target.gc index 56c3165c4f..e2302f1a2d 100644 --- a/goal_src/jak2/engine/target/logic-target.gc +++ b/goal_src/jak2/engine/target/logic-target.gc @@ -704,7 +704,7 @@ (set! (-> gp-0 ignore-process0) self) (set! (-> gp-0 ignore-process1) #f) (set! (-> gp-0 ignore-pat) (-> self control pat-ignore-mask)) - (collide-cache-method-12 *collide-cache* gp-0) + (fill-using-bounding-box *collide-cache* gp-0) (dotimes (s5-0 3) (set! (-> gp-0 start-pos quad) (-> self control unknown-sphere-array00 s5-0 prim-core world-sphere quad)) (vector-float*! (-> gp-0 move-dist) (-> self control unknown-vector25) -8192.0) @@ -717,7 +717,7 @@ (set! (-> v1-48 action-mask) (collide-action solid)) ) (cond - ((and (>= (collide-cache-method-16 *collide-cache* gp-0) 0.0) + ((and (>= (probe-using-line-sphere *collide-cache* gp-0) 0.0) (< 0.8 (vector-dot (-> gp-0 best-other-tri normal) (-> self control unknown-vector25))) ) ) @@ -1390,7 +1390,7 @@ (set! (-> gp-0 ignore-process0) self) (set! (-> gp-0 ignore-process1) #f) (set! (-> gp-0 ignore-pat) (-> self control pat-ignore-mask)) - (collide-cache-method-12 *collide-cache* gp-0) + (fill-using-bounding-box *collide-cache* gp-0) (dotimes (s5-0 2) (let ((a1-4 (not (or (logtest? (state-flags lleg-no-ik rleg-no-ik) (-> self state-flags)) (and (logtest? (-> self control unknown-surface00 flags) (surface-flag air)) @@ -1481,7 +1481,7 @@ (set! (-> v1-66 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1)) (set! (-> v1-66 action-mask) (collide-action solid)) ) - (let ((f30-0 (collide-cache-method-16 *collide-cache* gp-0))) + (let ((f30-0 (probe-using-line-sphere *collide-cache* gp-0))) (cond ((and (>= f30-0 0.0) (< 0.5 (-> gp-0 best-other-tri normal y))) (set! (-> s4-0 quad) (-> gp-0 best-other-tri normal quad)) diff --git a/goal_src/jak2/examples/collide-hash-debug.gc b/goal_src/jak2/examples/collide-hash-debug.gc new file mode 100644 index 0000000000..3c662fcde6 --- /dev/null +++ b/goal_src/jak2/examples/collide-hash-debug.gc @@ -0,0 +1,87 @@ + + +(define *collide-hash-test-origin* (new 'global 'vector)) +(define *collide-hash-test-size* (new 'global 'vector)) +(set-vector! *collide-hash-test-size* (meters 2.0) (meters 2.0) (meters 2.0) 0.0) + + +(defun test-collide-hash ((iter int)) + ;; create a collide query + (let ((query (new 'stack 'collide-query))) + ;; set the min/max + (vector+! (-> query bbox max) *collide-hash-test-origin* *collide-hash-test-size*) + (vector-! (-> query bbox min) *collide-hash-test-origin* *collide-hash-test-size*) + + (add-debug-box #t (bucket-id debug2) (-> query bbox min) (-> query bbox max) (new 'static 'rgba :g #xff :b #xff :a #x80)) + + (set! (-> query collide-with) (collide-spec backgnd)) + (set! (-> query ignore-process0) #f) + (set! (-> query ignore-process1) #f) + (set! (-> query ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1)) + + ;; set integer box + (dotimes (i 4) + (set! (-> query bbox4w min data i) (the int (-> query bbox min data i))) + (set! (-> query bbox4w max data i) (the int (-> query bbox max data i))) + ) + + ;; first is fill-collide-list-from-box + ;; sec is collide-list-fill-bg-using-box + + (set! (-> *collide-list* num-items) 0) + (dotimes (i (-> *level* length)) + (let ((lev (-> *level* level i))) + (when (= (-> lev status) 'active) + (fill-collide-list-from-box (-> lev bsp collide-hash) 0 *collide-list* query) + ) + ) + ) + + (format *stdcon* "got ~d things in the list~%" (-> *collide-list* num-items)) + (dotimes (i (-> *collide-list* num-items)) + (let ((item (-> *collide-list* items i))) + (cond + ((= (-> item mesh type) instance-tie) + (add-debug-sphere + #t + (bucket-id debug2) + (-> (the instance-tie (-> item mesh)) bsphere) + (-> (the instance-tie (-> item mesh)) bsphere w) + (new 'static 'rgba :r #xff :g #xff :a #x80)) + ) + ((= (-> item mesh type) collide-hash-fragment) + (add-debug-sphere + #t + (bucket-id debug2) + (-> (the collide-hash-fragment (-> item mesh)) bsphere) + (-> (the collide-hash-fragment (-> item mesh)) bsphere w) + (new 'static 'rgba :r #xff :b #xff :a #x80)) + ) + ) + ) + (format *stdcon* "[~d] ~A~%" i (-> *collide-list* items i mesh)) + + ) + ) + ) + +(defun move-box-to-cam () + (vector-copy! *collide-hash-test-origin* (target-cam-pos)) + ) + +(defun launch-collide-hash-debug-process () + (set! *stats-profile-bars* #f) + (let ((proc (get-process *nk-dead-pool* process 1024))) + (activate proc *entity-pool* "test" *kernel-dram-stack*) + (run-next-time-in-process proc (lambda () + (let ((iter 0)) + (while #t + (test-collide-hash iter) + (suspend) + (+! iter 1) + ) + ) + ) + ) + proc) + ) \ No newline at end of file diff --git a/test/decompiler/reference/jak2/decompiler-macros.gc b/test/decompiler/reference/jak2/decompiler-macros.gc index d53a815e65..19e0eb8fa7 100644 --- a/test/decompiler/reference/jak2/decompiler-macros.gc +++ b/test/decompiler/reference/jak2/decompiler-macros.gc @@ -598,6 +598,10 @@ ) ) +(defmacro .sll (result in sa) + `(set! ,result (sext32 (the-as int (shl (logand ,in #xffffffff) ,sa)))) + ) + (defmacro .mfc0 (&rest stuff) `(empty) ) @@ -1037,8 +1041,8 @@ ) (defmacro sp-rnd-flt (field-name val range mult) - `(new 'static 'sp-field-init-spec - :field (sp-field-id ,field-name) + `(new 'static 'sp-field-init-spec + :field (sp-field-id ,field-name) :initial-valuef ,val :random-rangef ,range :random-multf ,mult @@ -1047,8 +1051,8 @@ ) (defmacro sp-flt (field-name val) - `(new 'static 'sp-field-init-spec - :field (sp-field-id ,field-name) + `(new 'static 'sp-field-init-spec + :field (sp-field-id ,field-name) :initial-valuef ,val :random-rangef 0.0 :random-multf 1.0 diff --git a/test/decompiler/reference/jak2/engine/collide/collide-cache-h_REF.gc b/test/decompiler/reference/jak2/engine/collide/collide-cache-h_REF.gc index aad3b8ec11..5b802e2616 100644 --- a/test/decompiler/reference/jak2/engine/collide/collide-cache-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/collide/collide-cache-h_REF.gc @@ -1,7 +1,5 @@ -;;-*-Lisp-*- (in-package goal) -;; definition of type collide-puss-sphere (deftype collide-puss-sphere (structure) ((bsphere sphere :inline :offset-assert 0) (bbox4w bounding-box4w :inline :offset-assert 16) @@ -11,7 +9,6 @@ :flag-assert #x900000030 ) -;; definition for method 3 of type collide-puss-sphere (defmethod inspect collide-puss-sphere ((obj collide-puss-sphere)) (when (not obj) (set! obj obj) @@ -24,7 +21,6 @@ obj ) -;; definition of type collide-puss-work (deftype collide-puss-work (structure) ((closest-pt vector :inline :offset-assert 0) (tri-normal vector :inline :offset-assert 16) @@ -41,7 +37,6 @@ ) ) -;; definition for method 3 of type collide-puss-work (defmethod inspect collide-puss-work ((obj collide-puss-work)) (when (not obj) (set! obj obj) @@ -57,7 +52,6 @@ obj ) -;; definition of type collide-cache-tri (deftype collide-cache-tri (structure) ((vertex vector 3 :inline :offset-assert 0) (extra-quad uint8 16 :offset-assert 48) @@ -72,7 +66,6 @@ :flag-assert #x900000040 ) -;; definition for method 3 of type collide-cache-tri (defmethod inspect collide-cache-tri ((obj collide-cache-tri)) (when (not obj) (set! obj obj) @@ -90,7 +83,6 @@ obj ) -;; definition of type collide-cache-prim (deftype collide-cache-prim (structure) ((prim-core collide-prim-core :inline :offset-assert 0) (extra-quad uint8 16 :offset-assert 32) @@ -113,7 +105,6 @@ ) ) -;; definition for method 3 of type collide-cache-prim (defmethod inspect collide-cache-prim ((obj collide-cache-prim)) (when (not obj) (set! obj obj) @@ -135,10 +126,11 @@ obj ) -;; definition of type collide-cache (deftype collide-cache (basic) ((num-tris int32 :offset-assert 4) + (num-tris-u32 uint32 :offset 4) (num-prims int32 :offset-assert 8) + (num-prims-u32 uint32 :offset 8) (ignore-mask pat-surface :offset-assert 12) (ignore-processes process 2 :offset-assert 16) (collide-box bounding-box :inline :offset-assert 32) @@ -155,16 +147,16 @@ (collide-cache-method-9 () none 9) (fill-and-probe-using-line-sphere (_type_ collide-query) float 10) (fill-and-probe-using-spheres (_type_ collide-query) symbol 11) - (collide-cache-method-12 (_type_ collide-query) none 12) + (fill-using-bounding-box (_type_ collide-query) none 12) (fill-using-line-sphere (_type_ collide-query) none 13) (fill-using-spheres (_type_ collide-query) none 14) - (collide-cache-method-15 () none 15) - (collide-cache-method-16 (_type_ collide-query) float 16) + (reset (_type_) none 15) + (probe-using-line-sphere (_type_ collide-query) float 16) (probe-using-spheres (_type_ collide-query) symbol 17) - (collide-cache-method-18 () none 18) - (collide-cache-method-19 () none 19) - (collide-cache-method-20 () none 20) - (collide-cache-method-21 () none 21) + (fill-from-bg (_type_ (function collide-hash int collide-list collide-query int) (function collide-cache collide-list collide-query none) collide-query) none 18) + (fill-from-fg-boxes (_type_) none 19) + (fill-from-fg-line-sphere (_type_) none 20) + (fill-from-water (_type_ water-control) none 21) (collide-cache-method-22 () none 22) (collide-cache-method-23 () none 23) (collide-cache-method-24 () none 24) @@ -172,7 +164,6 @@ ) ) -;; definition for method 3 of type collide-cache (defmethod inspect collide-cache ((obj collide-cache)) (when (not obj) (set! obj obj) @@ -193,10 +184,9 @@ obj ) -;; definition of type collide-list-item (deftype collide-list-item (structure) - ((mesh collide-frag-mesh :offset-assert 0) - (inst basic :offset-assert 4) + ((mesh instance-tie :offset-assert 0) + (inst basic :offset-assert 4) ) :pack-me :method-count-assert 9 @@ -204,7 +194,6 @@ :flag-assert #x900000008 ) -;; definition for method 3 of type collide-list-item (defmethod inspect collide-list-item ((obj collide-list-item)) (when (not obj) (set! obj obj) @@ -217,7 +206,6 @@ obj ) -;; definition of type collide-list (deftype collide-list (structure) ((num-items int32 :offset-assert 0) (items collide-list-item 256 :inline :offset 16) @@ -227,7 +215,6 @@ :flag-assert #x900000810 ) -;; definition for method 3 of type collide-list (defmethod inspect collide-list ((obj collide-list)) (when (not obj) (set! obj obj) @@ -240,14 +227,10 @@ obj ) -;; failed to figure out what this is: (kmemopen global "collide-cache") -;; definition (perm) for symbol *collide-cache*, type collide-cache (define-perm *collide-cache* collide-cache (new 'global 'collide-cache)) -;; definition (perm) for symbol *collide-list*, type collide-list (define-perm *collide-list* collide-list (new 'global 'collide-list)) -;; failed to figure out what this is: (kmemclose) diff --git a/test/decompiler/reference/jak2/engine/collide/collide-frag_REF.gc b/test/decompiler/reference/jak2/engine/collide/collide-frag_REF.gc new file mode 100644 index 0000000000..aa9e84cb51 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/collide/collide-frag_REF.gc @@ -0,0 +1,106 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 9 of type drawable-tree-collide-fragment +(defmethod login drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment)) + obj + ) + +;; definition for method 10 of type drawable-tree-collide-fragment +;; WARN: Return type mismatch int vs none. +(defmethod draw drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment) (arg0 drawable-tree-collide-fragment) (arg1 display-frame)) + (when *display-render-collision* + (dotimes (s4-0 (-> obj length)) + (draw (-> obj data s4-0) (-> obj data s4-0) arg1) + ) + ) + 0 + (none) + ) + +;; definition for method 15 of type drawable-tree-collide-fragment +(defmethod unpack-vis drawable-tree-collide-fragment ((obj drawable-tree-collide-fragment) (arg0 (pointer int8)) (arg1 (pointer int8))) + arg1 + ) + +;; definition for method 8 of type collide-fragment +;; WARN: Return type mismatch int vs collide-fragment. +(defmethod mem-usage collide-fragment ((obj collide-fragment) (arg0 memory-usage-block) (arg1 int)) + (let ((s5-0 (if (logtest? arg1 1) + 54 + 50 + ) + ) + (s4-0 (-> obj mesh)) + ) + (set! (-> arg0 data s5-0 name) (symbol->string 'collide-fragment)) + (+! (-> arg0 data s5-0 count) 1) + (let ((v1-11 (+ (asize-of obj) (asize-of s4-0)))) + (+! (-> arg0 data s5-0 used) v1-11) + (+! (-> arg0 data s5-0 total) (logand -16 (+ v1-11 15))) + ) + (set! (-> arg0 data (+ s5-0 1) name) "collision-poly") + (+! (-> arg0 data (+ s5-0 1) count) (-> s4-0 poly-count)) + (let ((v1-22 (+ (-> s4-0 strip-data-len) (-> s4-0 poly-count)))) + (+! (-> arg0 data (+ s5-0 1) used) v1-22) + (+! (-> arg0 data (+ s5-0 1) total) v1-22) + ) + (set! (-> arg0 data (+ s5-0 2) name) "collision-vertex") + (+! (-> arg0 data (+ s5-0 2) count) (-> s4-0 vertex-count)) + (let ((v1-31 (* (-> s4-0 vertex-data-qwc) 16))) + (+! (-> arg0 data (+ s5-0 2) used) v1-31) + (let ((v0-2 (+ (-> arg0 data (+ s5-0 2) total) v1-31))) + (set! (-> arg0 data (+ s5-0 2) total) v0-2) + (the-as collide-fragment v0-2) + ) + ) + ) + ) + +;; definition for method 9 of type drawable-inline-array-collide-fragment +(defmethod login drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment)) + obj + ) + +;; definition for method 10 of type collide-fragment +;; WARN: Return type mismatch int vs none. +(defmethod draw collide-fragment ((obj collide-fragment) (arg0 collide-fragment) (arg1 display-frame)) + 0 + (none) + ) + +;; definition for method 10 of type drawable-inline-array-collide-fragment +;; WARN: Return type mismatch int vs none. +(defmethod draw drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment) + (arg0 drawable-inline-array-collide-fragment) + (arg1 display-frame) + ) + (dotimes (s4-0 (-> obj length)) + (let ((s3-0 (-> obj data s4-0))) + (if (sphere-cull (-> s3-0 bsphere)) + (draw s3-0 s3-0 arg1) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 8 of type drawable-inline-array-collide-fragment +(defmethod mem-usage drawable-inline-array-collide-fragment ((obj drawable-inline-array-collide-fragment) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 1 (-> arg0 length))) + (set! (-> arg0 data 0 name) (symbol->string 'drawable-group)) + (+! (-> arg0 data 0 count) 1) + (let ((v1-7 32)) + (+! (-> arg0 data 0 used) v1-7) + (+! (-> arg0 data 0 total) (logand -16 (+ v1-7 15))) + ) + (dotimes (s3-0 (-> obj length)) + (mem-usage (-> obj data s3-0) arg0 arg1) + ) + obj + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/collide/collide-h_REF.gc b/test/decompiler/reference/jak2/engine/collide/collide-h_REF.gc index 0805fb3dcf..324455c2d6 100644 --- a/test/decompiler/reference/jak2/engine/collide/collide-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/collide/collide-h_REF.gc @@ -1,52 +1,51 @@ -;;-*-Lisp-*- (in-package goal) -;; definition of type collide-query (deftype collide-query (structure) - ((best-other-tri collide-tri-result :inline :offset-assert 0) - (best-my-tri collide-tri-result :inline :offset 0) - (ignore-processes process-tree 2 :offset-assert 88) - (ignore-process0 process-tree :offset 88) - (ignore-process1 process-tree :offset 92) - (ignore-pat pat-surface :offset-assert 96) - (collide-with collide-spec :offset-assert 100) - (overlay-params uint32 3 :offset 112) - (bbox bounding-box :inline :offset-assert 128) - (bbox4w bounding-box4w :inline :offset-assert 160) - (bsphere sphere :inline :offset-assert 192) - (start-pos vector :inline :offset-assert 208) - (move-dist vector :inline :offset-assert 224) - (rlength vector :inline :offset-assert 240) - (exit-planes plane 2 :offset-assert 256) - (radius float :offset 268) - (inv-mat matrix :inline :offset 288) - (spheres (inline-array sphere) :offset 112) - (num-spheres uint32 :offset 116) - (solid-only symbol :offset 120) - (best-dist float :offset 112) - (best-other-prim basic :offset 116) - (best-my-prim collide-shape-prim :offset 120) - (move-vec vector :inline :offset 224) - (best-u float :offset 112) - (action-mask collide-action :offset-assert 352) - (local-box4w bounding-box4w :inline :offset-assert 368) - (search-box bounding-box4w :inline :offset-assert 400) - (search-vector vector4w :inline :offset-assert 432) - (instance-mat matrix :inline :offset-assert 448) - (instance-ptr basic :offset-assert 512) - (x-addr uint32 :offset-assert 516) - (x-step uint32 :offset-assert 520) - (y-addr uint32 :offset-assert 524) - (y-step uint32 :offset-assert 528) - (z-addr uint32 :offset-assert 532) - (z-step uint32 :offset-assert 536) + ((best-other-tri collide-tri-result :inline :offset-assert 0) + (best-my-tri collide-tri-result :inline :offset 0) + (ignore-processes process-tree 2 :offset-assert 88) + (ignore-process0 process-tree :offset 88) + (ignore-process1 process-tree :offset 92) + (ignore-pat pat-surface :offset-assert 96) + (ignore-pat-s32 int32 :offset 96) + (collide-with collide-spec :offset-assert 100) + (collide-with-s32 int32 :offset 100) + (overlay-params uint32 3 :offset 112) + (bbox bounding-box :inline :offset-assert 128) + (bbox4w bounding-box4w :inline :offset-assert 160) + (bsphere sphere :inline :offset-assert 192) + (start-pos vector :inline :offset-assert 208) + (move-dist vector :inline :offset-assert 224) + (rlength vector :inline :offset-assert 240) + (exit-planes plane 2 :inline :offset-assert 256) + (radius float :offset 268) + (inv-mat matrix :inline :offset 288) + (spheres (inline-array sphere) :offset 112) + (num-spheres uint32 :offset 116) + (solid-only symbol :offset 120) + (best-dist float :offset 112) + (best-other-prim basic :offset 116) + (best-my-prim collide-shape-prim :offset 120) + (move-vec vector :inline :offset 224) + (best-u float :offset 112) + (action-mask collide-action :offset-assert 352) + (local-box4w bounding-box4w :inline :offset-assert 368) + (search-box bounding-box4w :inline :offset-assert 400) + (search-vector vector4w :inline :offset-assert 432) + (instance-mat matrix :inline :offset-assert 448) + (instance-ptr basic :offset-assert 512) + (x-addr uint32 :offset-assert 516) + (x-step uint32 :offset-assert 520) + (y-addr uint32 :offset-assert 524) + (y-step uint32 :offset-assert 528) + (z-addr uint32 :offset-assert 532) + (z-step uint32 :offset-assert 536) ) :method-count-assert 9 :size-assert #x21c :flag-assert #x90000021c ) -;; definition for method 3 of type collide-query (defmethod inspect collide-query ((obj collide-query)) (when (not obj) (set! obj obj) @@ -94,8 +93,6 @@ obj ) -;; definition for symbol *collide-test-flag*, type symbol (define *collide-test-flag* #f) -;; failed to figure out what this is: 0 diff --git a/test/decompiler/reference/jak2/engine/collide/collide-shape-h_REF.gc b/test/decompiler/reference/jak2/engine/collide/collide-shape-h_REF.gc index 1d2133a300..4edd5722d5 100644 --- a/test/decompiler/reference/jak2/engine/collide/collide-shape-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/collide/collide-shape-h_REF.gc @@ -212,8 +212,8 @@ (:methods (new (symbol type collide-shape uint int) _type_ 0) (collide-shape-prim-method-9 () none 9) - (collide-shape-prim-method-10 () none 10) - (collide-shape-prim-method-11 () none 11) + (add-fg-prim-using-box () none 10) + (add-fg-prim-using-line-sphere () none 11) (collide-shape-prim-method-12 () none 12) (collide-shape-prim-method-13 () none 13) (collide-shape-prim-method-14 () none 14) diff --git a/test/decompiler/reference/jak2/engine/collide/los-control_REF.gc b/test/decompiler/reference/jak2/engine/collide/los-control_REF.gc index 8f58fa6105..bd297faf49 100644 --- a/test/decompiler/reference/jak2/engine/collide/los-control_REF.gc +++ b/test/decompiler/reference/jak2/engine/collide/los-control_REF.gc @@ -1,12 +1,7 @@ -;;-*-Lisp-*- (in-package goal) -;; definition for symbol *los-time-offset*, type time-frame (define *los-time-offset* (the-as time-frame 0)) -;; definition for method 9 of type los-control -;; INFO: Used lq/sq -;; WARN: Return type mismatch time-frame vs none. (defmethod los-control-method-9 los-control ((obj los-control) (process process-focusable) (trans-vec vector) (radius float)) (when (and (>= (- (-> self clock frame-counter) (-> obj last-check-time)) (-> obj check-interval)) (-> obj src-proc) @@ -47,7 +42,7 @@ (set! (-> query action-mask) (collide-action solid)) ) (fill-using-line-sphere *collide-cache* cquery) - (let ((f30-0 (collide-cache-method-16 *collide-cache* cquery))) + (let ((f30-0 (probe-using-line-sphere *collide-cache* cquery))) (quad-copy! (the-as pointer (-> obj last-collide-result)) (the-as pointer (-> cquery best-other-tri)) 6) (if (>= 0.0 f30-0) (set! (-> obj have-no-los) (-> self clock frame-counter)) @@ -64,30 +59,24 @@ (none) ) -;; definition for method 10 of type los-control (defmethod check-los? los-control ((obj los-control) (arg0 time-frame)) (and (>= (- (-> self clock frame-counter) (-> obj have-los)) (+ (-> obj check-interval) arg0)) (< (- (-> self clock frame-counter) (-> obj have-no-los)) (-> obj check-interval)) ) ) -;; definition for method 11 of type los-control (defmethod skip-check-los? los-control ((obj los-control) (arg0 int)) (and (>= (- (-> self clock frame-counter) (-> obj have-no-los)) (+ (-> obj check-interval) arg0)) (< (- (-> self clock frame-counter) (-> obj have-los)) (-> obj check-interval)) ) ) -;; definition for method 12 of type los-control -;; WARN: Return type mismatch int vs none. (defmethod set-dst-proc! los-control ((obj los-control) (dst handle)) (set! (-> obj dst-proc) dst) 0 (none) ) -;; definition for method 13 of type los-control -;; WARN: Return type mismatch int vs none. (defmethod new-source! los-control ((obj los-control) (proc process) (check-interval time-frame) (c-spec collide-spec)) (set! (-> obj src-proc) (process->handle proc)) (set! (-> obj dst-proc) (the-as handle #f)) diff --git a/test/decompiler/reference/jak2/engine/draw/drawable-h_REF.gc b/test/decompiler/reference/jak2/engine/draw/drawable-h_REF.gc index 451df0924f..2bfa6ba74d 100644 --- a/test/decompiler/reference/jak2/engine/draw/drawable-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/draw/drawable-h_REF.gc @@ -1,7 +1,5 @@ -;;-*-Lisp-*- (in-package goal) -;; definition of type drawable (deftype drawable (basic) ((id int16 :offset-assert 4) (bsphere vector :inline :offset-assert 16) @@ -12,8 +10,8 @@ (:methods (login (_type_) _type_ 9) (draw (_type_ _type_ display-frame) none 10) - (drawable-method-11 () none 11) - (drawable-method-12 () none 12) + (fill-collide-list-from-box (_type_ int collide-list collide-query) int 11) + (fill-collide-list-from-line-sphere (_type_ int collide-list collide-query) int 12) (collect-stats (_type_) none 13) (debug-draw (_type_ drawable display-frame) none 14) (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) @@ -21,7 +19,6 @@ ) ) -;; definition for method 3 of type drawable (defmethod inspect drawable ((obj drawable)) (when (not obj) (set! obj obj) @@ -34,7 +31,6 @@ obj ) -;; definition of type drawable-error (deftype drawable-error (drawable) ((name string :offset-assert 32) ) @@ -43,7 +39,6 @@ :flag-assert #x1100000024 ) -;; definition for method 3 of type drawable-error (defmethod inspect drawable-error ((obj drawable-error)) (when (not obj) (set! obj obj) @@ -57,5 +52,4 @@ obj ) -;; failed to figure out what this is: 0 diff --git a/test/decompiler/reference/jak2/engine/gfx/background/prototype-h_REF.gc b/test/decompiler/reference/jak2/engine/gfx/background/prototype-h_REF.gc index 1315b79e36..510315b7b5 100644 --- a/test/decompiler/reference/jak2/engine/gfx/background/prototype-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/background/prototype-h_REF.gc @@ -1,7 +1,5 @@ -;;-*-Lisp-*- (in-package goal) -;; definition of type prototype-bucket (deftype prototype-bucket (basic) ((name string :offset-assert 4) (flags prototype-flags :offset-assert 8) @@ -25,7 +23,6 @@ :flag-assert #x900000040 ) -;; definition for method 3 of type prototype-bucket (defmethod inspect prototype-bucket ((obj prototype-bucket)) (when (not obj) (set! obj obj) @@ -52,7 +49,6 @@ obj ) -;; definition of type prototype-bucket-shrub (deftype prototype-bucket-shrub (prototype-bucket) ((next uint32 4 :offset-assert 64) (count uint16 4 :offset-assert 80) @@ -68,8 +64,6 @@ :flag-assert #x900000070 ) -;; definition for method 3 of type prototype-bucket-shrub -;; INFO: Used lq/sq (defmethod inspect prototype-bucket-shrub ((obj prototype-bucket-shrub)) (when (not obj) (set! obj obj) @@ -103,7 +97,6 @@ obj ) -;; definition of type prototype-inline-array-shrub (deftype prototype-inline-array-shrub (drawable) ((length int16 :offset 6) (data prototype-bucket-shrub 1 :inline :offset 32) @@ -114,7 +107,6 @@ :flag-assert #x1100000094 ) -;; definition for method 3 of type prototype-inline-array-shrub (defmethod inspect prototype-inline-array-shrub ((obj prototype-inline-array-shrub)) (when (not obj) (set! obj obj) @@ -129,7 +121,6 @@ obj ) -;; definition of type prototype-array-shrub-info (deftype prototype-array-shrub-info (basic) ((prototype-inline-array-shrub prototype-inline-array-shrub :offset-assert 4) (wind-vectors uint32 :offset-assert 8) @@ -140,7 +131,6 @@ :flag-assert #x900000010 ) -;; definition for method 3 of type prototype-array-shrub-info (defmethod inspect prototype-array-shrub-info ((obj prototype-array-shrub-info)) (when (not obj) (set! obj obj) @@ -154,95 +144,93 @@ obj ) -;; definition of type prototype-bucket-tie (deftype prototype-bucket-tie (prototype-bucket) - ((next uint32 12 :offset-assert 64) - (count uint16 12 :offset-assert 112) - (frag-count uint8 4 :offset-assert 136) - (index-start uint8 4 :offset-assert 140) - (base-qw uint16 4 :offset-assert 144) - (tie-rvanish float :offset-assert 152) - (tie-vanish-far float :offset-assert 156) - (envmap-rfade float :offset-assert 160) - (envmap-fade-far float :offset-assert 164) - (envmap-shader adgif-shader :offset-assert 168) - (tint-color uint32 :offset-assert 172) - (collide-hash-fragment-array basic :offset-assert 176) - (tie-colors time-of-day-palette :offset-assert 180) - (data uint32 :dynamic :offset-assert 184) - (color-index-qwc uint32 :dynamic :offset-assert 184) - (scissor-frag-count uint8 :offset 136) - (near-frag-count uint8 :offset 137) - (mid-frag-count uint8 :offset 138) - (far-frag-count uint8 :offset 139) - (scissor-index-start uint8 :offset 140) - (near-index-start uint8 :offset 141) - (mid-index-start uint8 :offset 142) - (far-index-start uint8 :offset 143) - (scissor-base-qw uint16 :offset 144) - (near-base-qw uint16 :offset 146) - (mid-base-qw uint16 :offset 148) - (far-base-qw uint16 :offset 150) - (tie-next uint32 4 :offset 64) - (tie-scissor-next uint32 :offset 64) - (tie-near-next uint32 :offset 68) - (tie-mid-next uint32 :offset 72) - (tie-far-next uint32 :offset 76) - (trans-next uint32 4 :offset 64) - (trans-scissor-next uint32 4 :offset 64) - (trans-near-next uint32 :offset 68) - (trans-mid-next uint32 :offset 72) - (trans-far-next uint32 :offset 76) - (water-next uint32 4 :offset 64) - (water-scissor-next uint32 4 :offset 64) - (water-near-next uint32 :offset 68) - (water-mid-next uint32 :offset 72) - (water-far-next uint32 :offset 76) - (envmap-next uint32 4 :offset 80) - (envmap-scissor-next uint32 4 :offset 80) - (envmap-near-next uint32 :offset 84) - (envmap-mid-next uint32 :offset 88) - (envmap-far-next uint32 :offset 92) - (generic-next uint32 3 :offset 96) - (generic-near-next uint32 :offset 96) - (generic-mid-next uint32 :offset 100) - (generic-far-next uint32 :offset 104) - (vanish-next uint32 :offset 108) - (tie-count uint16 4 :offset 112) - (tie-scissor-count uint16 :offset 112) - (tie-near-count uint16 :offset 114) - (tie-mid-count uint16 :offset 116) - (tie-far-count uint16 :offset 118) - (trans-count uint16 4 :offset 112) - (trans-scissor-count uint16 :offset 112) - (trans-near-count uint16 :offset 114) - (trans-mid-count uint16 :offset 116) - (trans-far-count uint16 :offset 118) - (water-count uint16 4 :offset 112) - (water-scissor-count uint16 :offset 112) - (water-near-count uint16 :offset 114) - (water-mid-count uint16 :offset 116) - (water-far-count uint16 :offset 118) - (envmap-count uint16 4 :offset 120) - (envmap-scissor-count uint16 :offset 120) - (envmap-near-count uint16 :offset 122) - (envmap-mid-count uint16 :offset 124) - (envmap-far-count uint16 :offset 126) - (generic-count uint16 3 :offset 128) - (generic-near-count uint16 :offset 128) - (generic-mid-count uint16 :offset 130) - (generic-far-count uint16 :offset 132) - (vanish-count uint16 :offset 134) - (next-clear uint128 3 :offset 64) - (count-clear uint64 3 :offset 112) - (tie-geom prototype-tie 4 :offset 16) + ((next uint32 12 :offset-assert 64) + (count uint16 12 :offset-assert 112) + (frag-count uint8 4 :offset-assert 136) + (index-start uint8 4 :offset-assert 140) + (base-qw uint16 4 :offset-assert 144) + (tie-rvanish float :offset-assert 152) + (tie-vanish-far float :offset-assert 156) + (envmap-rfade float :offset-assert 160) + (envmap-fade-far float :offset-assert 164) + (envmap-shader adgif-shader :offset-assert 168) + (tint-color uint32 :offset-assert 172) + (collide-hash-fragment-array collide-hash-fragment-array :offset-assert 176) + (tie-colors time-of-day-palette :offset-assert 180) + (data uint32 :dynamic :offset-assert 184) + (color-index-qwc uint32 :dynamic :offset-assert 184) + (scissor-frag-count uint8 :offset 136) + (near-frag-count uint8 :offset 137) + (mid-frag-count uint8 :offset 138) + (far-frag-count uint8 :offset 139) + (scissor-index-start uint8 :offset 140) + (near-index-start uint8 :offset 141) + (mid-index-start uint8 :offset 142) + (far-index-start uint8 :offset 143) + (scissor-base-qw uint16 :offset 144) + (near-base-qw uint16 :offset 146) + (mid-base-qw uint16 :offset 148) + (far-base-qw uint16 :offset 150) + (tie-next uint32 4 :offset 64) + (tie-scissor-next uint32 :offset 64) + (tie-near-next uint32 :offset 68) + (tie-mid-next uint32 :offset 72) + (tie-far-next uint32 :offset 76) + (trans-next uint32 4 :offset 64) + (trans-scissor-next uint32 4 :offset 64) + (trans-near-next uint32 :offset 68) + (trans-mid-next uint32 :offset 72) + (trans-far-next uint32 :offset 76) + (water-next uint32 4 :offset 64) + (water-scissor-next uint32 4 :offset 64) + (water-near-next uint32 :offset 68) + (water-mid-next uint32 :offset 72) + (water-far-next uint32 :offset 76) + (envmap-next uint32 4 :offset 80) + (envmap-scissor-next uint32 4 :offset 80) + (envmap-near-next uint32 :offset 84) + (envmap-mid-next uint32 :offset 88) + (envmap-far-next uint32 :offset 92) + (generic-next uint32 3 :offset 96) + (generic-near-next uint32 :offset 96) + (generic-mid-next uint32 :offset 100) + (generic-far-next uint32 :offset 104) + (vanish-next uint32 :offset 108) + (tie-count uint16 4 :offset 112) + (tie-scissor-count uint16 :offset 112) + (tie-near-count uint16 :offset 114) + (tie-mid-count uint16 :offset 116) + (tie-far-count uint16 :offset 118) + (trans-count uint16 4 :offset 112) + (trans-scissor-count uint16 :offset 112) + (trans-near-count uint16 :offset 114) + (trans-mid-count uint16 :offset 116) + (trans-far-count uint16 :offset 118) + (water-count uint16 4 :offset 112) + (water-scissor-count uint16 :offset 112) + (water-near-count uint16 :offset 114) + (water-mid-count uint16 :offset 116) + (water-far-count uint16 :offset 118) + (envmap-count uint16 4 :offset 120) + (envmap-scissor-count uint16 :offset 120) + (envmap-near-count uint16 :offset 122) + (envmap-mid-count uint16 :offset 124) + (envmap-far-count uint16 :offset 126) + (generic-count uint16 3 :offset 128) + (generic-near-count uint16 :offset 128) + (generic-mid-count uint16 :offset 130) + (generic-far-count uint16 :offset 132) + (vanish-count uint16 :offset 134) + (next-clear uint128 3 :offset 64) + (count-clear uint64 3 :offset 112) + (tie-geom prototype-tie 4 :offset 16) ) :method-count-assert 9 :size-assert #xb8 :flag-assert #x9000000b8 ) -;; definition for method 3 of type prototype-bucket-tie (defmethod inspect prototype-bucket-tie ((obj prototype-bucket-tie)) (when (not obj) (set! obj obj) @@ -348,7 +336,6 @@ obj ) -;; definition of type prototype-array-tie (deftype prototype-array-tie (array) ((array-data prototype-bucket-tie :dynamic :offset 16) ) @@ -360,7 +347,6 @@ ) ) -;; definition for method 3 of type prototype-array-tie (defmethod inspect prototype-array-tie ((obj prototype-array-tie)) (when (not obj) (set! obj obj) @@ -375,7 +361,6 @@ obj ) -;; definition of type proxy-prototype-array-tie (deftype proxy-prototype-array-tie (basic) ((prototype-array-tie prototype-array-tie :offset-assert 4) (wind-vectors uint32 :offset-assert 8) @@ -387,7 +372,6 @@ :flag-assert #x900000010 ) -;; definition for method 3 of type proxy-prototype-array-tie (defmethod inspect proxy-prototype-array-tie ((obj proxy-prototype-array-tie)) (when (not obj) (set! obj obj) @@ -402,19 +386,17 @@ obj ) -;; definition of type instance (deftype instance (drawable) - ((bucket-index uint16 :offset 6) - (origin matrix4h :inline :offset-assert 32) - (flags uint16 :offset 46) - (wind-index uint16 :offset 62) + ((bucket-index uint16 :offset 6) + (origin matrix4h :inline :offset-assert 32) + (flags instance-flags :offset 46) + (wind-index uint16 :offset 62) ) :method-count-assert 17 :size-assert #x40 :flag-assert #x1100000040 ) -;; definition for method 3 of type instance (defmethod inspect instance ((obj instance)) (when (not obj) (set! obj obj) @@ -431,5 +413,4 @@ obj ) -;; failed to figure out what this is: 0 diff --git a/test/decompiler/reference/jak2/engine/gfx/mood/weather-part_REF.gc b/test/decompiler/reference/jak2/engine/gfx/mood/weather-part_REF.gc index 2cd14e7d1a..25086bd459 100644 --- a/test/decompiler/reference/jak2/engine/gfx/mood/weather-part_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/mood/weather-part_REF.gc @@ -575,7 +575,7 @@ ) (fill-using-line-sphere *collide-cache* s4-0) (cond - ((>= (collide-cache-method-16 *collide-cache* s4-0) 0.0) + ((>= (probe-using-line-sphere *collide-cache* s4-0) 0.0) (set! (-> arg1 user-float) (-> s4-0 best-other-tri intersect y)) (let ((f0-8 (+ 65536.0 (-> *math-camera* trans y)))) (if (< (-> arg1 user-float) f0-8) diff --git a/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-h_REF.gc b/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-h_REF.gc index c0f61fce48..519e55e7a1 100644 --- a/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-h_REF.gc @@ -935,7 +935,7 @@ (ocean-method-15 () none 15) (ocean-method-16 () none 16) (ocean-method-17 () none 17) - (ocean-method-18 () none 18) + (ocean-method-18 (_type_ object object) none 18) (ocean-method-19 () none 19) (ocean-method-20 () none 20) (ocean-method-21 (_type_ float float) float 21) diff --git a/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash-h_REF.gc b/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash-h_REF.gc index 8ba9449b98..d4c7a97298 100644 --- a/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash-h_REF.gc @@ -1,22 +1,15 @@ -;;-*-Lisp-*- (in-package goal) -;; definition for symbol *collide-list-boxes*, type object (define *collide-list-boxes* (the-as object #f)) -;; definition for symbol *collide-hash-fragments*, type object (define *collide-hash-fragments* (the-as object 0)) -;; definition for symbol *collide-hash-fragments-tfrag*, type object (define *collide-hash-fragments-tfrag* (the-as object 0)) -;; definition for symbol *collide-hash-fragments-instance*, type object (define *collide-hash-fragments-instance* (the-as object 0)) -;; definition for symbol *already-printed-exeeded-max-cache-tris*, type symbol (define *already-printed-exeeded-max-cache-tris* #f) -;; definition of type collide-hash-scratch (deftype collide-hash-scratch (structure) ((collidable-bits uint128 128 :offset-assert 0) (poly-bits uint64 2 :offset 0) @@ -28,7 +21,6 @@ :flag-assert #x900000804 ) -;; definition for method 3 of type collide-hash-scratch (defmethod inspect collide-hash-scratch ((obj collide-hash-scratch)) (when (not obj) (set! obj obj) @@ -43,7 +35,6 @@ obj ) -;; definition of type collide-hash-bucket (deftype collide-hash-bucket (structure) ((index int16 :offset-assert 0) (count int16 :offset-assert 2) @@ -53,7 +44,6 @@ :flag-assert #x900000004 ) -;; definition for method 3 of type collide-hash-bucket (defmethod inspect collide-hash-bucket ((obj collide-hash-bucket)) (when (not obj) (set! obj obj) @@ -66,17 +56,16 @@ obj ) -;; definition of type collide-hash-item (deftype collide-hash-item (structure) ((id uint32 :offset-assert 0) (collidable basic :offset-assert 4) ) + :pack-me :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 ) -;; definition for method 3 of type collide-hash-item (defmethod inspect collide-hash-item ((obj collide-hash-item)) (when (not obj) (set! obj obj) @@ -89,7 +78,6 @@ obj ) -;; definition of type collide-hash-poly (deftype collide-hash-poly (structure) ((data uint8 4 :offset-assert 0) (vert-index0 uint8 :offset 0) @@ -103,7 +91,6 @@ :flag-assert #x900000004 ) -;; definition for method 3 of type collide-hash-poly (defmethod inspect collide-hash-poly ((obj collide-hash-poly)) (when (not obj) (set! obj obj) @@ -120,7 +107,6 @@ obj ) -;; definition of type collide-hash-fragment-stats (deftype collide-hash-fragment-stats (structure) ((num-verts uint16 :offset-assert 0) (num-polys uint8 :offset-assert 2) @@ -132,7 +118,6 @@ :flag-assert #x900000004 ) -;; definition for method 3 of type collide-hash-fragment-stats (defmethod inspect collide-hash-fragment-stats ((obj collide-hash-fragment-stats)) (when (not obj) (set! obj obj) @@ -146,7 +131,6 @@ obj ) -;; definition of type collide-hash-fragment (deftype collide-hash-fragment (drawable) ((num-buckets uint16 :offset 4) (num-indices uint16 :offset 6) @@ -171,7 +155,6 @@ :flag-assert #x1100000070 ) -;; definition for method 3 of type collide-hash-fragment (defmethod inspect collide-hash-fragment ((obj collide-hash-fragment)) (when (not obj) (set! obj obj) @@ -201,15 +184,14 @@ obj ) -;; definition of type collide-hash-fragment-array (deftype collide-hash-fragment-array (array) - () + ((fragments collide-hash-fragment :dynamic :offset 16) + ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -;; definition for method 3 of type collide-hash-fragment-array (defmethod inspect collide-hash-fragment-array ((obj collide-hash-fragment-array)) (when (not obj) (set! obj obj) @@ -224,28 +206,26 @@ obj ) -;; definition of type collide-hash (deftype collide-hash (drawable) - ((num-ids uint16 :offset 4) - (id-count uint16 :offset 6) - (num-buckets uint32 :offset 8) - (qwc-id-bits uint32 :offset 12) - (grid-step vector :inline :offset 16) - (bbox bounding-box :inline :offset-assert 32) - (bbox4w bounding-box4w :inline :offset-assert 64) - (axis-scale vector :inline :offset 48) - (avg-extents vector :inline :offset 64) - (bucket-array uint32 :offset 44) - (item-array uint32 :offset 60) - (dimension-array uint32 3 :offset 76) - (num-items uint32 :offset 92) + ((num-ids uint16 :offset 4) + (id-count uint16 :offset 6) + (num-buckets uint32 :offset 8) + (qwc-id-bits uint32 :offset 12) + (grid-step vector :inline :offset 16) + (bbox bounding-box :inline :offset-assert 32) + (bbox4w bounding-box4w :inline :offset-assert 64) + (axis-scale vector :inline :offset 48) + (avg-extents vector :inline :offset 64) + (bucket-array uint32 :offset 44) + (item-array (inline-array collide-hash-item) :offset 60) + (dimension-array uint32 3 :offset 76) + (num-items uint32 :offset 92) ) :method-count-assert 17 :size-assert #x60 :flag-assert #x1100000060 ) -;; definition for method 3 of type collide-hash (defmethod inspect collide-hash ((obj collide-hash)) (when (not obj) (set! obj obj) @@ -264,16 +244,11 @@ (format #t "~1Taxis-scale: #~%" (-> obj bbox max)) (format #t "~1Tavg-extents: #~%" (-> obj bbox4w)) (format #t "~1Tbucket-array: #x~X~%" (-> obj bbox min w)) - (format #t "~1Titem-array: #x~X~%" (-> obj bbox max w)) + (format #t "~1Titem-array: #x~X~%" (-> obj item-array)) (format #t "~1Tdimension-array[3] @ #x~X~%" (&-> obj bbox4w min w)) (format #t "~1Tnum-items: ~D~%" (-> obj num-items)) (label cfg-4) obj ) -;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash_REF.gc b/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash_REF.gc new file mode 100644 index 0000000000..cb60fedbe3 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/spatial-hash/collide-hash_REF.gc @@ -0,0 +1,703 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function add-collide-debug-box +;; WARN: Return type mismatch symbol vs none. +(defun add-collide-debug-box ((arg0 vector) (arg1 rgba)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (let ((a3-0 (new 'stack-no-clear 'bounding-box))) + (nop!) + (.lvf vf1 (&-> arg0 quad)) + (.sub.w.vf vf2 vf1 vf1) + (nop!) + (.add.w.vf vf3 vf1 vf1) + (nop!) + (nop!) + (.svf (&-> a3-0 min quad) vf2) + (nop!) + (.svf (&-> a3-0 max quad) vf3) + (add-debug-box #t (bucket-id debug2) (-> a3-0 min) (-> a3-0 max) arg1) + ) + (none) + ) + ) + +;; definition (debug) for function print-collide-cache-tri-count +;; WARN: Return type mismatch object vs none. +(defun-debug print-collide-cache-tri-count () + (let ((gp-0 0) + (s4-0 0) + (s5-0 0) + (s3-0 0) + ) + (let ((v1-0 *collide-cache*)) + (dotimes (a0-0 (-> v1-0 num-tris)) + (case (-> v1-0 tris a0-0 pat mode) + (((pat-mode ground)) + (+! gp-0 1) + ) + (((pat-mode wall)) + (+! s5-0 1) + ) + (((pat-mode obstacle)) + (+! s4-0 1) + ) + (else + (+! s3-0 1) + ) + ) + ) + (format *stdcon* "tris ~d (~4,,1f%) " (-> v1-0 num-tris) (* 0.2173913 (the float (-> v1-0 num-tris)))) + ) + (format *stdcon* "(ground ~d, wall ~d, obstacle ~d, other ~d)~%" gp-0 s5-0 s4-0 s3-0) + ) + (none) + ) + +;; definition (debug) for function print-exceeded-max-cache-tris +;; WARN: Return type mismatch int vs none. +(defun-debug print-exceeded-max-cache-tris () + (with-pp + (when (not *already-printed-exeeded-max-cache-tris*) + (set! *already-printed-exeeded-max-cache-tris* #t) + (if pp + (format *stdcon* "Exceeded collide cache max # of tris (~s)!~%" (-> pp name)) + (format *stdcon* "Exceeded collide cache max # of tris!~%") + ) + (print-collide-cache-tri-count) + ) + 0 + (none) + ) + ) + +;; definition for method 11 of type collide-hash +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 12 of type collide-hash +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function fill-bg-using-box-new +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function fill-bg-using-line-sphere-new +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function collide-list-fill-bg-using-box +;; INFO: Used lq/sq +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Return type mismatch int vs none. +(defun collide-list-fill-bg-using-box ((arg0 collide-cache) (arg1 collide-list) (arg2 collide-query)) + (local-vars + (v1-12 uint128) + (v1-14 uint128) + (v1-15 uint128) + (a0-10 uint128) + (a0-11 uint128) + (a1-3 uint128) + (a2-3 uint128) + (a2-4 uint128) + (sv-16 int) + (sv-20 collide-list) + (sv-640 int) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf16 :class vf) + (vf17 :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) + (set! sv-16 (-> arg1 num-items)) + (set! sv-20 arg1) + (dotimes (s4-0 sv-16) + (let ((s3-0 (-> sv-20 items s4-0 mesh))) + (cond + ((= (-> s3-0 type) instance-tie) + (let* ((v1-4 s3-0) + (s1-0 (-> v1-4 bucket-ptr)) + ) + (when (not (or (logtest? (-> s1-0 flags) (prototype-flags no-collide)) + (logtest? (-> v1-4 flags) (instance-flags no-collide)) + ) + ) + (if *collide-list-boxes* + (add-collide-debug-box (-> s3-0 bsphere) (new 'static 'rgba :r #xff :a #x80)) + ) + (let ((s0-0 (new 'stack-no-clear 'matrix)) + (s2-0 (new 'stack-no-clear 'collide-query)) + ) + (mem-copy! (the-as pointer s2-0) (the-as pointer arg2) 540) + (nop!) + (nop!) + (let ((v1-11 (the-as uint128 (-> s3-0 origin vector4h 3 long)))) + (nop!) + (let ((a2-2 (the-as uint128 (-> s3-0 origin vector4h 0 long)))) + (.pextlh v1-12 v1-11 0) + (let ((a0-9 (the-as uint128 (-> s3-0 origin vector4h 1 long)))) + (.pw.sra a1-3 v1-12 10) + (let ((v1-13 (the-as uint128 (-> s3-0 origin vector4h 2 long)))) + (.pextlh a2-3 a2-2 0) + (nop!) + (.pw.sra a2-4 a2-3 16) + (nop!) + (.pextlh a0-10 a0-9 0) + (.mov vf4 a1-3) + (.pw.sra a0-11 a0-10 16) + (.mov vf1 a2-4) + (.pextlh v1-14 v1-13 0) + ) + ) + ) + ) + (.mov vf2 a0-11) + (.pw.sra v1-15 v1-14 16) + (.lvf vf5 (&-> s3-0 bsphere quad)) + (nop!) + (.mov vf3 v1-15) + (.itof.vf vf4 vf4) + (nop!) + (vitof12.xyzw vf1 vf1) + (nop!) + (vitof12.xyzw vf2 vf2) + (nop!) + (vitof12.xyzw vf3 vf3) + (nop!) + (.add.vf vf4 vf4 vf5 :mask #b111) + (nop!) + (nop!) + (.svf (&-> s2-0 instance-mat vector 0 quad) vf1) + (nop!) + (.svf (&-> s2-0 instance-mat vector 1 quad) vf2) + (nop!) + (.svf (&-> s2-0 instance-mat vector 2 quad) vf3) + (nop!) + (.svf (&-> s2-0 instance-mat trans quad) vf4) + (matrix-4x4-inverse! s0-0 (-> s2-0 instance-mat)) + (nop!) + (nop!) + (.lvf vf7 (&-> arg2 bbox min quad)) + (nop!) + (.lvf vf14 (&-> arg2 bbox max quad)) + (nop!) + (.lvf vf1 (&-> s0-0 vector 0 quad)) + (nop!) + (.lvf vf2 (&-> s0-0 vector 1 quad)) + (nop!) + (.lvf vf3 (&-> s0-0 vector 2 quad)) + (nop!) + (.lvf vf4 (&-> s0-0 trans quad)) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf7 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf7 acc) + (nop!) + (.add.mul.z.vf vf8 vf3 vf14 acc) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf7 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf14 acc) + (nop!) + (.add.mul.z.vf vf9 vf3 vf7 acc) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf7 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf14 acc) + (nop!) + (.add.mul.z.vf vf10 vf3 vf14 acc) + (nop!) + (.min.vf vf5 vf8 vf9) + (nop!) + (.max.vf vf6 vf8 vf9) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf14 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf7 acc) + (nop!) + (.add.mul.z.vf vf11 vf3 vf7 acc) + (nop!) + (.min.vf vf5 vf5 vf10) + (nop!) + (.max.vf vf6 vf6 vf10) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf14 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf7 acc) + (nop!) + (.add.mul.z.vf vf12 vf3 vf14 acc) + (nop!) + (.min.vf vf5 vf5 vf11) + (nop!) + (.max.vf vf6 vf6 vf11) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf14 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf14 acc) + (nop!) + (.add.mul.z.vf vf13 vf3 vf7 acc) + (nop!) + (.min.vf vf5 vf5 vf12) + (nop!) + (.max.vf vf6 vf6 vf12) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf14 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf14 acc) + (nop!) + (.add.mul.z.vf vf14 vf3 vf14 acc) + (nop!) + (.min.vf vf5 vf5 vf13) + (nop!) + (.max.vf vf6 vf6 vf13) + (nop!) + (.mul.w.vf acc vf4 vf0) + (nop!) + (.add.mul.x.vf acc vf1 vf7 acc) + (nop!) + (.add.mul.y.vf acc vf2 vf7 acc) + (nop!) + (.add.mul.z.vf vf7 vf3 vf7 acc) + (nop!) + (.min.vf vf5 vf5 vf14) + (nop!) + (.max.vf vf6 vf6 vf14) + (nop!) + (.min.vf vf5 vf5 vf7) + (nop!) + (.max.vf vf6 vf6 vf7) + (nop!) + (.ftoi.vf vf16 vf5) + (nop!) + (.ftoi.vf vf17 vf6) + (nop!) + (nop!) + (.svf (&-> s2-0 bbox min quad) vf5) + (nop!) + (.svf (&-> s2-0 bbox max quad) vf6) + (nop!) + (.svf (&-> s2-0 bbox4w min quad) vf16) + (nop!) + (.svf (&-> s2-0 bbox4w max quad) vf17) + (let ((s1-1 (-> s1-0 collide-hash-fragment-array))) + (set! sv-640 (-> s1-1 length)) + (set! (-> s2-0 instance-ptr) s3-0) + (dotimes (s3-1 sv-640) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 0) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 1) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) tris) (the-as uint 0)) + (fill-bg-using-box-new arg0 (-> s1-1 fragments s3-1) s2-0) + (+! (-> *collide-stats* tris) (-> (the-as collide-hash-scratch #x70000000) tris)) + ) + ) + ) + ) + ) + ) + (else + (if *collide-list-boxes* + (add-collide-debug-box (-> s3-0 bsphere) (new 'static 'rgba :r #xff :g #xff :a #x80)) + ) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 0) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 1) (the-as uint128 0)) + (set! (-> arg2 instance-ptr) #f) + (set! (-> (the-as collide-hash-scratch #x70000000) tris) (the-as uint 0)) + (fill-bg-using-box-new arg0 s3-0 arg2) + (+! (-> *collide-stats* tris) (-> (the-as collide-hash-scratch #x70000000) tris)) + ) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for function collide-list-fill-bg-using-line-sphere +;; INFO: Used lq/sq +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Stack slot offset 640 signed mismatch +;; WARN: Stack slot offset 16 signed mismatch +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [sll v1, v1, 16] +(defun collide-list-fill-bg-using-line-sphere ((arg0 collide-cache) (arg1 collide-list) (arg2 collide-query)) + (local-vars + (v1-12 uint128) + (v1-14 uint128) + (v1-15 uint128) + (v1-17 number) + (v1-26 float) + (a0-10 uint128) + (a0-11 uint128) + (a1-3 uint128) + (a2-3 uint128) + (a2-4 uint128) + (sv-16 int) + (sv-640 int) + ) + (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) + (set! sv-16 (-> arg1 num-items)) + (dotimes (s3-0 sv-16) + (let ((s2-0 (-> arg1 items s3-0 mesh))) + (cond + ((= (-> s2-0 type) instance-tie) + (let ((v1-4 s2-0)) + (when (not (or (logtest? (-> v1-4 bucket-ptr flags) (prototype-flags no-collide)) + (logtest? (-> v1-4 flags) (instance-flags no-collide)) + ) + ) + (if *collide-list-boxes* + (add-collide-debug-box (-> s2-0 bsphere) (new 'static 'rgba :r #xff :a #x80)) + ) + (let ((s0-0 (new 'stack-no-clear 'matrix)) + (s1-0 (new 'stack-no-clear 'collide-query)) + ) + (mem-copy! (the-as pointer s1-0) (the-as pointer arg2) 540) + (nop!) + (let ((v1-11 (the-as uint128 (-> s2-0 origin vector4h 3 long)))) + (nop!) + (let ((a2-2 (the-as uint128 (-> s2-0 origin vector4h 0 long)))) + (.pextlh v1-12 v1-11 0) + (let ((a0-9 (the-as uint128 (-> s2-0 origin vector4h 1 long)))) + (.pw.sra a1-3 v1-12 10) + (let ((v1-13 (the-as uint128 (-> s2-0 origin vector4h 2 long)))) + (.pextlh a2-3 a2-2 0) + (nop!) + (.pw.sra a2-4 a2-3 16) + (nop!) + (.pextlh a0-10 a0-9 0) + (.mov vf4 a1-3) + (.pw.sra a0-11 a0-10 16) + (.mov vf1 a2-4) + (.pextlh v1-14 v1-13 0) + ) + ) + ) + ) + (.mov vf2 a0-11) + (.pw.sra v1-15 v1-14 16) + (.lvf vf5 (&-> s2-0 bsphere quad)) + (nop!) + (.mov vf3 v1-15) + (.itof.vf vf4 vf4) + (nop!) + (vitof12.xyzw vf1 vf1) + (nop!) + (vitof12.xyzw vf2 vf2) + (nop!) + (vitof12.xyzw vf3 vf3) + (nop!) + (.add.vf vf4 vf4 vf5 :mask #b111) + (nop!) + (nop!) + (.svf (&-> s1-0 instance-mat vector 0 quad) vf1) + (nop!) + (.svf (&-> s1-0 instance-mat vector 1 quad) vf2) + (nop!) + (.svf (&-> s1-0 instance-mat vector 2 quad) vf3) + (nop!) + (.svf (&-> s1-0 instance-mat trans quad) vf4) + (matrix-4x4-inverse! s0-0 (-> s1-0 instance-mat)) + (nop!) + (nop!) + (.lvf vf7 (&-> arg2 start-pos quad)) + (nop!) + (.lvf vf8 (&-> arg2 move-dist quad)) + (nop!) + (.lvf vf1 (&-> s0-0 vector 0 quad)) + (nop!) + (.lvf vf2 (&-> s0-0 vector 1 quad)) + (nop!) + (.lvf vf3 (&-> s0-0 vector 2 quad)) + (nop!) + (.lvf vf4 (&-> s0-0 trans quad)) + (.add.vf vf8 vf7 vf8) + (let ((v1-16 (-> s2-0 rmin-scale))) + (.mul.x.vf acc vf1 vf7) + (let ((f2-0 (-> arg2 radius))) + (.add.mul.y.vf acc vf2 vf7 acc) + (.sll v1-17 v1-16 16) + (.add.mul.z.vf acc vf3 vf7 acc) + (let ((f1-0 (the-as float v1-17))) + (.add.mul.w.vf vf7 vf4 vf0 acc) + (nop!) + (.mul.x.vf acc vf1 vf8) + (let ((f2-1 (* f2-0 f1-0))) + (.add.mul.y.vf acc vf2 vf8 acc) + (nop!) + (.add.mul.z.vf acc vf3 vf8 acc) + (nop!) + (.add.mul.w.vf vf8 vf4 vf0 acc) + (nop!) + (nop!) + (.svf (&-> s1-0 start-pos quad) vf7) + (.min.vf vf5 vf7 vf8) + (set! (-> s1-0 radius) f2-1) + ) + ) + ) + ) + (.max.vf vf6 vf7 vf8) + (nop!) + (nop!) + (.lvf vf9 (&-> s1-0 exit-planes 0 quad)) + (.sub.vf vf8 vf8 vf7) + (nop!) + (.sub.w.vf vf5 vf5 vf9) + (nop!) + (.add.w.vf vf6 vf6 vf9) + (nop!) + (nop!) + (.svf (&-> s1-0 move-dist quad) vf8) + (.ftoi.vf vf10 vf5) + (nop!) + (.ftoi.vf vf11 vf6) + (nop!) + (nop!) + (.svf (&-> s1-0 bbox min quad) vf5) + (nop!) + (.svf (&-> s1-0 bbox max quad) vf6) + (nop!) + (.svf (&-> s1-0 bbox4w min quad) vf10) + (nop!) + (.svf (&-> s1-0 bbox4w max quad) vf11) + (set! (-> s1-0 rlength x) (if (= (-> s1-0 move-dist x) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist x)) + ) + ) + (set! (-> s1-0 rlength y) (if (= (-> s1-0 move-dist y) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist y)) + ) + ) + (set! (-> s1-0 rlength z) (if (= (-> s1-0 move-dist z) 0.0) + 0.0 + (/ 1.0 (-> s1-0 move-dist z)) + ) + ) + (let ((f0-12 1.0)) + (.lvf vf1 (&-> (-> s1-0 move-dist) 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-26 vf1) + (set! (-> s1-0 rlength w) (/ f0-12 v1-26)) + ) + (set! (-> s1-0 exit-planes 0 x) (if (< 0.0 (-> s1-0 move-dist x)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 0 y) (if (< 0.0 (-> s1-0 move-dist y)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 0 z) (if (< 0.0 (-> s1-0 move-dist z)) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 x) (if (< (-> s1-0 move-dist x) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 y) (if (< (-> s1-0 move-dist y) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (set! (-> s1-0 exit-planes 1 z) (if (< (-> s1-0 move-dist z) 0.0) + 0.0 + 100000000000000000000000000000000000000.0 + ) + ) + (let ((s0-1 (-> s2-0 bucket-ptr collide-hash-fragment-array))) + (set! sv-640 (-> s0-1 length)) + (set! (-> s1-0 instance-ptr) s2-0) + (dotimes (s2-1 sv-640) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 0) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 1) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) tris) (the-as uint 0)) + (fill-bg-using-line-sphere-new arg0 (-> s0-1 fragments s2-1) s1-0) + (+! (-> *collide-stats* tris) (-> (the-as collide-hash-scratch #x70000000) tris)) + ) + ) + ) + ) + ) + ) + (else + (if *collide-list-boxes* + (add-collide-debug-box (-> s2-0 bsphere) (new 'static 'rgba :r #xff :g #xff :a #x80)) + ) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 0) (the-as uint128 0)) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits 1) (the-as uint128 0)) + (set! (-> arg2 instance-ptr) #f) + (set! (-> (the-as collide-hash-scratch #x70000000) tris) (the-as uint 0)) + (fill-bg-using-line-sphere-new arg0 s2-0 arg2) + (+! (-> *collide-stats* tris) (-> (the-as collide-hash-scratch #x70000000) tris)) + ) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for method 8 of type collide-hash +;; INFO: Used lq/sq +(defmethod mem-usage collide-hash ((obj collide-hash) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 51 (-> arg0 length))) + (set! (-> arg0 data 50 name) (symbol->string 'collision)) + (+! (-> arg0 data 50 count) 1) + (let ((v1-10 (+ (* (-> obj num-items) 8) 96 (* (-> obj num-buckets) 4)))) + (+! (-> arg0 data 50 used) v1-10) + (+! (-> arg0 data 50 total) (logand -16 (+ v1-10 15))) + ) + (dotimes (v1-14 (the-as int (-> obj qwc-id-bits))) + (set! (-> (the-as collide-hash-scratch #x70000000) collidable-bits v1-14) (the-as uint128 0)) + ) + (dotimes (s3-0 (the-as int (-> obj num-items))) + (let* ((a0-12 (-> obj item-array s3-0 id)) + (v1-19 (shr a0-12 5)) + ) + (when (not (logtest? (-> (the-as collide-hash-scratch #x70000000) id-bits v1-19) (ash 1 (logand a0-12 31)))) + (logior! (-> (the-as collide-hash-scratch #x70000000) id-bits v1-19) (ash 1 (logand a0-12 31))) + (if (= (-> obj item-array s3-0 collidable type) collide-hash-fragment) + (mem-usage (-> obj item-array s3-0 collidable) arg0 arg1) + ) + ) + ) + ) + obj + ) + +;; definition for method 8 of type collide-hash-fragment +(defmethod mem-usage collide-hash-fragment ((obj collide-hash-fragment) (arg0 memory-usage-block) (arg1 int)) + (cond + ((logtest? arg1 1) + (set! (-> arg0 length) (max 58 (-> arg0 length))) + (set! (-> arg0 data 55 name) (symbol->string 'prototype-fragment)) + (+! (-> arg0 data 55 count) 1) + (set! (-> arg0 data 56 name) (symbol->string 'prototype-poly)) + (+! (-> arg0 data 56 count) (the-as int (-> obj stats num-polys))) + (set! (-> arg0 data 57 name) (symbol->string 'prototype-vertex)) + (+! (-> arg0 data 57 count) (the-as int (-> obj stats num-verts))) + (let ((a3-0 (+ (-> obj num-indices) 112 (* (-> obj num-buckets) 4))) + (a2-9 (* (-> obj stats num-polys) 4)) + (v1-22 (* (the-as uint 6) (the-as uint (-> obj stats num-verts)))) + ) + (+! (-> arg0 data 55 used) a3-0) + (+! (-> arg0 data 55 total) (- (logand -16 (+ v1-22 15 a2-9 a3-0)) (the-as int (+ a2-9 v1-22)))) + (+! (-> arg0 data 56 used) a2-9) + (+! (-> arg0 data 56 total) a2-9) + (+! (-> arg0 data 57 used) v1-22) + (+! (-> arg0 data 57 total) v1-22) + ) + ) + (else + (set! (-> arg0 length) (max 54 (-> arg0 length))) + (set! (-> arg0 data 51 name) (symbol->string 'collision-fragment)) + (+! (-> arg0 data 51 count) 1) + (set! (-> arg0 data 52 name) (symbol->string 'collision-poly)) + (+! (-> arg0 data 52 count) (the-as int (-> obj stats num-polys))) + (set! (-> arg0 data 53 name) (symbol->string 'collision-vertex)) + (+! (-> arg0 data 53 count) (the-as int (-> obj stats num-verts))) + (let ((a3-8 (+ (-> obj num-indices) 112 (* (-> obj num-buckets) 4))) + (a2-22 (* (-> obj stats num-polys) 4)) + (v1-45 (* (the-as uint 6) (the-as uint (-> obj stats num-verts)))) + ) + (+! (-> arg0 data 51 used) a3-8) + (+! (-> arg0 data 51 total) (- (logand -16 (+ v1-45 15 a2-22 a3-8)) (the-as int (+ a2-22 v1-45)))) + (+! (-> arg0 data 52 used) a2-22) + (+! (-> arg0 data 52 total) a2-22) + (+! (-> arg0 data 53 used) v1-45) + (+! (-> arg0 data 53 total) v1-45) + ) + ) + ) + obj + ) + +;; definition for method 8 of type collide-hash-fragment-array +(defmethod mem-usage collide-hash-fragment-array ((obj collide-hash-fragment-array) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 55 (-> arg0 length))) + (set! (-> arg0 data 54 name) (symbol->string 'prototype-collision)) + (+! (-> arg0 data 54 count) 1) + (let ((v1-8 (asize-of obj))) + (+! (-> arg0 data 54 used) v1-8) + (+! (-> arg0 data 54 total) (logand -16 (+ v1-8 15))) + ) + (dotimes (s3-0 (-> obj length)) + (mem-usage (-> obj fragments s3-0) arg0 arg1) + ) + obj + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/target/logic-target_REF.gc b/test/decompiler/reference/jak2/engine/target/logic-target_REF.gc index e9775f1464..c231d40355 100644 --- a/test/decompiler/reference/jak2/engine/target/logic-target_REF.gc +++ b/test/decompiler/reference/jak2/engine/target/logic-target_REF.gc @@ -671,7 +671,7 @@ (set! (-> gp-0 ignore-process0) self) (set! (-> gp-0 ignore-process1) #f) (set! (-> gp-0 ignore-pat) (-> self control pat-ignore-mask)) - (collide-cache-method-12 *collide-cache* gp-0) + (fill-using-bounding-box *collide-cache* gp-0) (dotimes (s5-0 3) (set! (-> gp-0 start-pos quad) (-> self control unknown-sphere-array00 s5-0 prim-core world-sphere quad)) (vector-float*! (-> gp-0 move-dist) (-> self control unknown-vector25) -8192.0) @@ -684,7 +684,7 @@ (set! (-> v1-48 action-mask) (collide-action solid)) ) (cond - ((and (>= (collide-cache-method-16 *collide-cache* gp-0) 0.0) + ((and (>= (probe-using-line-sphere *collide-cache* gp-0) 0.0) (< 0.8 (vector-dot (-> gp-0 best-other-tri normal) (-> self control unknown-vector25))) ) ) @@ -1357,7 +1357,7 @@ (set! (-> gp-0 ignore-process0) self) (set! (-> gp-0 ignore-process1) #f) (set! (-> gp-0 ignore-pat) (-> self control pat-ignore-mask)) - (collide-cache-method-12 *collide-cache* gp-0) + (fill-using-bounding-box *collide-cache* gp-0) (dotimes (s5-0 2) (let ((a1-4 (not (or (logtest? (state-flags lleg-no-ik rleg-no-ik) (-> self state-flags)) (and (logtest? (-> self control unknown-surface00 flags) (surface-flag air)) @@ -1448,7 +1448,7 @@ (set! (-> v1-66 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1)) (set! (-> v1-66 action-mask) (collide-action solid)) ) - (let ((f30-0 (collide-cache-method-16 *collide-cache* gp-0))) + (let ((f30-0 (probe-using-line-sphere *collide-cache* gp-0))) (cond ((and (>= f30-0 0.0) (< 0.5 (-> gp-0 best-other-tri normal y))) (set! (-> s4-0 quad) (-> gp-0 best-other-tri normal quad)) diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index c44a57397d..9af2338f8b 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -584,6 +584,7 @@ int main(int argc, char* argv[]) { if (!total.compare.total_pass) { lg::error("Comparison failed."); for (auto& f : total.compare.failing_files) { + fmt::print("{}\n", f.filename); fmt::print("{}\n", f.diff); } lg::error("Failing files:");