From d8181fb169d7daa2027e9afb256a97dc17394e04 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:53:29 -0500 Subject: [PATCH] [jak3] `joint-mod`, `subdivide`, `bsp` (#3371) --- decompiler/config/jak3/all-types.gc | 283 +-- .../ntsc_v1/anonymous_function_types.jsonc | 3 +- decompiler/config/jak3/ntsc_v1/hacks.jsonc | 6 +- .../config/jak3/ntsc_v1/label_types.jsonc | 3 + .../jak3/ntsc_v1/stack_structures.jsonc | 43 +- .../config/jak3/ntsc_v1/type_casts.jsonc | 65 + .../config/jak3/ntsc_v1/var_names.jsonc | 101 ++ goal_src/jak3/engine/anim/joint-mod-h.gc | 64 +- goal_src/jak3/engine/anim/joint-mod.gc | 1557 ++++++++++++++++ goal_src/jak3/engine/debug/debug-h.gc | 2 +- goal_src/jak3/engine/draw/drawable-actor-h.gc | 4 +- goal_src/jak3/engine/draw/drawable-h.gc | 10 +- .../jak3/engine/gfx/background/subdivide-h.gc | 2 + .../jak3/engine/gfx/background/subdivide.gc | 392 ++++ .../engine/gfx/background/tfrag/tfrag-h.gc | 3 + .../jak3/engine/gfx/background/tie/tie-h.gc | 3 + goal_src/jak3/engine/gfx/background/wind.gc | 37 + goal_src/jak3/engine/gfx/shrub/shrubbery-h.gc | 4 +- goal_src/jak3/engine/gfx/texture/texture-h.gc | 2 +- goal_src/jak3/engine/gfx/vu1-user-h.gc | 2 +- goal_src/jak3/engine/level/bsp-h.gc | 57 +- goal_src/jak3/engine/level/bsp.gc | 703 +++++++ goal_src/jak3/engine/level/level-h.gc | 6 +- .../process-drawable/process-drawable-h.gc | 1 + .../reference/jak3/decompiler-macros.gc | 16 + .../jak3/engine/anim/joint-mod-h_REF.gc | 44 +- .../jak3/engine/anim/joint-mod_REF.gc | 1616 +++++++++++++++++ .../jak3/engine/draw/drawable-actor-h_REF.gc | 8 +- .../jak3/engine/draw/drawable-h_REF.gc | 8 +- .../engine/gfx/background/subdivide_REF.gc | 419 +++++ .../jak3/engine/gfx/background/wind_REF.gc | 48 + .../jak3/engine/gfx/shrub/shrubbery-h_REF.gc | 8 +- .../jak3/engine/gfx/texture/texture-h_REF.gc | 3 +- .../reference/jak3/engine/level/bsp-h_REF.gc | 51 +- .../reference/jak3/engine/level/bsp_REF.gc | 735 ++++++++ .../jak3/engine/level/level-h_REF.gc | 6 +- test/offline/config/jak3/config.jsonc | 8 +- 37 files changed, 6113 insertions(+), 210 deletions(-) create mode 100644 test/decompiler/reference/jak3/engine/anim/joint-mod_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/gfx/background/subdivide_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/gfx/background/wind_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/level/bsp_REF.gc diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index 20d67cb3e5..830e58ceb9 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -4081,7 +4081,7 @@ (bucket574 574) (bucket575 575) (bucket576 576) - (bucket577 577) ;; debug? + (debug-no-zbuf1 577) ;; debug? (bucket578 578) (bucket579 579) (bucket580 580) @@ -6364,7 +6364,7 @@ (deftype texture-masks-array (inline-array-class) "Group of all texture-masks for a given tpage." - ((data texture-masks :dynamic :offset-assert 16) ;; guessed by decompiler + ((data texture-masks :dynamic :inline :offset-assert 16) ;; guessed by decompiler ) :method-count-assert 14 :size-assert #x10 @@ -7520,7 +7520,7 @@ (level-method-11 () none) ;; 11 ;; (level-method-11 () none) (level-method-12 () none) ;; 12 ;; (unload! (_type_) _type_) (level-method-13 () none) ;; 13 ;; (bsp-name (_type_) symbol) - (level-method-14 () none) ;; 14 ;; (compute-memory-usage! (_type_ symbol) memory-usage-block) + (compute-memory-usage! (_type_ symbol) memory-usage-block) ;; 14 (level-method-15 () none) ;; 15 ;; (inside-boxes-check (_type_ vector) symbol) (level-method-16 () none) ;; 16 ;; (update-vis! (_type_ level-vis-info uint (pointer uint8)) symbol) (level-method-17 () none) ;; 17 ;; (load-continue (_type_) _type_) @@ -7543,7 +7543,7 @@ (deftype level-group (basic) ((length int32 :offset-assert 4) - (unk-flag1 symbol) + (log-in-level-bsp bsp-header) (loading-level level) (entity-link entity-links :offset 16) @@ -10482,6 +10482,17 @@ :bitfield #f :type uint32 + (entity 44) + (camera 45) + + (bsp-main 59) + (bsp-misc 60) + (bsp-node 61) + (bsp-leaf-vis-self 62) + + (pat 65) + + (joint 68) (joint-anim-compressed-control 70) @@ -10496,6 +10507,8 @@ (texture 83) + (array 85) + (eye-anim 112) ) @@ -11938,7 +11951,7 @@ ) (deftype cspace-array (inline-array-class) - ((data cspace :dynamic :inline :offset-assert 16) ;; guessed by decompiler + ((data cspace :dynamic :inline :offset-assert 16 :score 1) ;; guessed by decompiler ) :method-count-assert 14 :size-assert #x10 @@ -11950,6 +11963,8 @@ ;; drawable-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(declare-type region-prim-list structure) + (deftype drawable (basic) "Base class for `drawable` scene graph system. This base class is really abused in many ways, and the meaning of the various methods differ depending @@ -11965,13 +11980,16 @@ :flag-assert #x1100000020 (:methods (login "Initialize the object after it is loaded." (_type_) _type_);; 9 - (draw (_type_ _type_ display-frame) none) ;; 10 + (draw "Draw the drawable, and typically its children. + This usually means adding stuff to a list to be drawn later, rather than expensive drawing here." (_type_) none) ;; 10 (drawable-method-11 () none) ;; 11 ;; (fill-collide-list-from-box (_type_ int collide-list collide-query) int) (drawable-method-12 () none) ;; 12 ;; (fill-collide-list-from-line-sphere (_type_ int collide-list collide-query) int) - (drawable-method-13 () none) ;; 13 ;; (collect-stats (_type_) none) - (drawable-method-14 () none) ;; 14 ;; (debug-draw (_type_ drawable display-frame) none) + (collect-stats "Collect triangle/perf statistics for rendering. + This is only called when viewing stats. + The vis-bits and culling registers are loaded during this time." (_type_) none) ;; 13 + (debug-draw "Debug-draw a drawable and its children. Typically uses the debug-draw functions." (_type_) none) ;; 14 (drawable-method-15 () none) ;; 15 ;; (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8)) - (drawable-method-16 () none) ;; 16 ;; (collect-regions (_type_ sphere int region-prim-list) none) + (collect-regions "Fill the region-prim-list with regions that intersect the sphere." (_type_ sphere int region-prim-list) none) ;; 16 ) ) @@ -19297,14 +19315,14 @@ :flag-assert #x10000000ac ;; field track-mode is likely a value type. (:methods - (new (symbol type) _type_) ;; 0 ;; (new (symbol type joint-mod-mode process-drawable int) _type_) - (joint-mod-method-9 () none) ;; 9 ;; (mode-set! (_type_ joint-mod-mode) none) - (joint-mod-method-10 () none) ;; 10 ;; (target-set! (_type_ vector) none) - (joint-mod-method-11 () none) ;; 11 ;; (look-at! (_type_ vector symbol process) none) + (new (symbol type joint-mod-mode process-drawable int) _type_) ;; 0 + (mode-set! "Set the type of joint-mod and install the right callback." (_type_ joint-mod-mode) none) ;; 9 + (target-set! "Set the target position for look-at mode." (_type_ vector) none) ;; 10 + (look-at! "Activate joint mod to look at the process." (_type_ vector symbol process) none) ;; 11 (reset-blend! "Set the blend to 0." (_type_) _type_) ;; 12 - (joint-mod-method-13 () none) ;; 13 ;; (twist-set! (_type_ float float float) vector) - (joint-mod-method-14 () none) ;; 14 ;; (trs-set! (_type_ vector quaternion vector) none) - (joint-mod-method-15 () none) ;; 15 ;; (shut-down (_type_) none) + (twist-set! "Set twist x,y,z. A value of #f will skip the set." (_type_ float float float) vector) ;; 13 + (trs-set! "Set translation, quaternion, scale. A value of #f will skip the set." (_type_ vector quaternion vector) none) ;; 14 + (shut-down "Disable the joint mod, possibly blending out depending on the type" (_type_) none) ;; 15 ) ) @@ -19486,9 +19504,9 @@ :size-assert #xe8 :flag-assert #xb000000e8 (:methods - (new (symbol type) _type_) ;; 0 ;; (new (symbol type process-drawable int float) _type_) - (joint-mod-ik-method-9 () none) ;; 9 ;; (handle-copy! (_type_ vector) none) - (joint-mod-ik-method-10 () none) ;; 10 ;; (enable-set! (_type_ symbol) none) + (new (symbol type process-drawable int float) _type_) ;; 0 + (set-ik-target! (_type_ vector) none) ;; 9 + (enable-set! (_type_ symbol) none) ;; 10 ) ) @@ -19501,8 +19519,18 @@ :flag-assert #x900000008 ) +(defenum joint-mod-polar-flags + :type uint32 + :bitfield #t + (no-z-rot 0) + (blending-to-zero 1) + (negate-nose 2) + (negate-ear 3) + (negate-up 4) + ) + (deftype joint-mod-polar-look-at (basic) - ((flags uint32 :offset-assert 4) + ((flags joint-mod-polar-flags :offset-assert 4) (ear int8 :offset-assert 8) (up int8 :offset-assert 9) (nose int8 :offset-assert 10) @@ -19515,8 +19543,8 @@ (forward-twist float :offset-assert 36) (backward-twist float :offset-assert 40) (target vector :inline :offset-assert 48) - (blend-duration uint64 :offset-assert 64) - (blend-start-time uint64 :offset-assert 72) + (blend-duration time-frame :offset-assert 64) + (blend-start-time time-frame :offset-assert 72) (blend-start-value float :offset-assert 80) (blend-max float :offset-assert 84) ) @@ -19524,12 +19552,12 @@ :size-assert #x58 :flag-assert #xf00000058 (:methods - (joint-mod-polar-look-at-method-9 () none) ;; 9 - (joint-mod-polar-look-at-method-10 () none) ;; 10 - (joint-mod-polar-look-at-method-11 () none) ;; 11 - (joint-mod-polar-look-at-method-12 () none) ;; 12 - (joint-mod-polar-look-at-method-13 () none) ;; 13 - (joint-mod-polar-look-at-method-14 () none) ;; 14 + (initialize "Attach joint-mod to process and set defaults." (_type_ process-drawable int) none) ;; 9 + (set-target! "Update the target position." (_type_ vector) none) ;; 10 + (set-both-targets! "Update the target position of this mod, and a second one." (_type_ joint-mod-polar-look-at vector) none) ;; 11 + (blend-on! "Start blending this joint mod on." (_type_ time-frame float symbol) none) ;; 12 + (blend-to-off! "Start blending to disable this joint mod." (_type_ time-frame symbol) none) ;; 13 + (get-start-blend! "Determine what blend to use when starting a new one." (_type_) float) ;; 14 ) ) @@ -21980,6 +22008,14 @@ ;; bsp-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defenum texture-page-flag + :type uint16 + :bitfield #t + (alpha-enable 0) + ) + +(declare-type entity-camera entity) + (deftype bsp-node (structure) "A node in the 'BSP' tree. This is really a bounding volume tree, where each volume is an axis-aligned box, containing 2 child boxes. This is used for precomputed visibility, based on the camera position. This is not used for collision." @@ -21990,6 +22026,7 @@ (back-box-min vector4b :inline :offset-assert 12) (back-box-max vector4b :inline :offset-assert 16) ) + :pack-me :method-count-assert 9 :size-assert #x14 :flag-assert #x900000014 @@ -21998,42 +22035,43 @@ (deftype bsp-header (drawable) "The bsp-header is really an entire level. This probably started as a very simple structure, but now it is extremely complicated." - ((all-visible-list (pointer uint16) :offset 32) ;; guessed by decompiler + ((info file-info :offset 4) + (all-visible-list (pointer uint16) :offset 32) ;; guessed by decompiler (visible-list-length int16 :offset 36) (drawable-trees drawable-tree-array :offset 40) ;; guessed by decompiler (pat pointer :offset 44) ;; guessed by decompiler (pat-length int32 :offset 48) ;; jak2: unlikely to match jak 3 exactly!! - ; (texture-remap-table (pointer uint64) :offset-assert 52) - ; (texture-remap-table-len int32 :offset-assert 56) - ; (texture-ids (pointer texture-id) :offset-assert 60) - ; (texture-page-count int32 :offset-assert 64) - ; (unknown-basic basic :offset-assert 68) ;; seems to be 0 everywhere. + (texture-remap-table (pointer uint64) :offset-assert 52) + (texture-remap-table-len int32 :offset-assert 56) + (texture-ids (pointer texture-id) :offset-assert 60) + (texture-page-count int32 :offset-assert 64) + (unknown-basic basic :offset-assert 68) ;; seems to be 0 everywhere. ; (name symbol :offset-assert 72) ; (nickname symbol :offset-assert 76) ; (vis-info level-vis-info 8 :offset-assert 80) - ; (actors drawable-inline-array-actor :offset-assert 112) - ; (cameras (array entity-camera) :offset-assert 116) + (actors drawable-inline-array-actor :offset 112) + (cameras (array entity-camera) :offset-assert 116) (nodes (inline-array bsp-node) :offset 120) ;; jak2: unlikely to match jak 3 exactly!! - ; (level level :offset-assert 124) - ; (current-leaf-idx uint16 :offset-assert 128) - ; (texture-flags texture-page-flag 10 :offset-assert 130) - ; (cam-outside-bsp uint8 :offset 152) - ; (cam-using-back uint8 :offset-assert 153) - ; (cam-box-idx uint16 :offset-assert 154) + (level level :offset-assert 124) + (current-leaf-idx uint16 :offset-assert 128) + (texture-flags texture-page-flag 10 :offset 130) + (cam-outside-bsp uint8 :offset 152) + (cam-using-back uint8 :offset-assert 153) + (cam-box-idx uint16 :offset-assert 154) ; (ambients symbol :offset-assert 156) ;; now just #t? ; (subdivide-close float :offset-assert 160) ; (subdivide-far float :offset-assert 164) ; (race-meshes (array entity-race-mesh) :offset-assert 168) - ; (actor-birth-order (pointer uint32) :offset-assert 172) + (actor-birth-order (pointer uint32) :offset 172) ; (light-hash light-hash :offset-assert 176) ; (nav-meshes (array entity-nav-mesh) :offset-assert 180) ; (actor-groups (array actor-group) :offset-assert 184) - ; (region-trees (array drawable-tree-region-prim) :offset-assert 188) + (region-trees (array drawable-tree-region-prim) :offset 188) ; (region-array region-array :offset-assert 192) - ; (collide-hash collide-hash :offset-assert 196) + (collide-hash collide-hash :offset 196) ; ;; 200 is some array ; (wind-array uint32 :offset 200) ; ;; 204 is maybe that array's length @@ -22043,24 +22081,26 @@ ; (vis-spheres-length uint32 :offset 248) ; (region-tree drawable-tree-region-prim :offset 252) - ; (tfrag-masks texture-masks-array :offset-assert 256) - ; (tfrag-closest (pointer float) :offset-assert 260) - ; (tfrag-mask-count uint32 :offset 260) + (tfrag-masks texture-masks-array :offset 256) + (tfrag-closest (pointer float) :offset-assert 260) + (tfrag-mask-count uint32 :offset 260) - ; (shrub-masks texture-masks-array :offset-assert 264) - ; (shrub-closest (pointer float) :offset-assert 268) - ; (shrub-mask-count uint32 :offset 268) + (shrub-masks texture-masks-array :offset-assert 264) + (shrub-closest (pointer float) :offset-assert 268) + (shrub-mask-count uint32 :offset 268) - ; (alpha-masks texture-masks-array :offset-assert 272) - ; (alpha-closest (pointer float) :offset-assert 276) - ; (alpha-mask-count uint32 :offset 276) + (alpha-masks texture-masks-array :offset-assert 272) + (alpha-closest (pointer float) :offset-assert 276) + (alpha-mask-count uint32 :offset 276) - ; (water-masks texture-masks-array :offset-assert 280) - ; (water-closest (pointer float) :offset-assert 284) - ; (water-mask-count uint32 :offset 284) + (water-masks texture-masks-array :offset-assert 280) + (water-closest (pointer float) :offset-assert 284) + (water-mask-count uint32 :offset 284) - ; (bsp-scale vector :inline :offset-assert 288) - ; (bsp-offset vector :inline :offset-assert 304) + (bsp-scale vector :inline :offset 288) + (bsp-offset vector :inline :offset-assert 304) + + (unk-drawable drawable :offset 320) (end uint8 :offset #x18f) @@ -22401,7 +22441,9 @@ (deftype drawable-tree-instance-shrub (drawable-tree) "Drawable-tree for the shrubs." - () + ((info prototype-array-shrub-info :offset 8) + (colors-added time-of-day-palette :offset 12) ;; added + ) :flag-assert #x1100000020 ) @@ -27667,20 +27709,21 @@ ;; joint-mod ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern joint-mod-ik-callback function) ;; (function cspace transformq none :behavior process) -;; (define-extern real-joint-mod-gun-look-at-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-gun-look-at-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-foot-rot-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern last-try-to-look-at-data object) ;; try-to-look-at-info -;; (define-extern joint-mod-look-at-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-world-look-at-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-rotate-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-scale-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-joint-set-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-joint-set-world-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-joint-set*-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-joint-set*-world-handler function) ;; (function cspace transformq none :behavior process) -;; (define-extern joint-mod-polar-look-at-callback function) +(define-extern joint-mod-ik-callback "Inverse kinematics joint mod callback. + Despite the arm-related names, can be used on legs too." (function cspace transformq none :behavior process)) +(define-extern real-joint-mod-gun-look-at-handler "Joint mod callback for pointing the gun (implementation)." (function cspace transformq none :behavior process)) +(define-extern joint-mod-gun-look-at-handler "Joint mod callback for pointing the gun (wrapper)." (function cspace transformq none :behavior process)) +(define-extern joint-mod-foot-rot-handler "Joint mod callback to pitch the foot to match the ground." (function cspace transformq none :behavior process)) +(define-extern last-try-to-look-at-data try-to-look-at-info) +(define-extern joint-mod-look-at-handler "Callback for look-at joint mod." (function cspace transformq none :behavior process)) +(define-extern joint-mod-world-look-at-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-rotate-handler "Callback for rotate joint mod." (function cspace transformq none :behavior process)) +(define-extern joint-mod-scale-handler "Callback for scale joint mod." (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set-handler "Callback for set joint mod." (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set-world-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set*-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set*-world-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-polar-look-at-callback (function cspace transformq none :behavior process)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; wind-work ;; @@ -27692,46 +27735,60 @@ ;; wind ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern update-wind function) ;; (function wind-work (array uint8) none) -;; (define-extern wind-get-hashed-index function) +(define-extern update-wind "Update the wind force for this frame. + This value will be used by level-update-wind to update tie/shrub wind values." (function wind-work (array uint8) none)) +(define-extern wind-get-hashed-index "Unused function, likely a leftover from Jak 1's different wind system." (function vector wind-work int)) ;; (define-extern level-update-wind function) ;; (function wind-work none) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; bsp ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern mem-usage-bsp-tree function) ;; (function bsp-header bsp-node memory-usage-block int none) -;; (define-extern *test-shrub* object) ;; int -;; (define-extern bsp-camera-asm function) ;; (function bsp-header vector none) -;; (define-extern print-collide-stats function) ;; (function none) -(define-extern level-remap-texture (function texture-id texture-id)) -;; (define-extern build-masks function) ;; (function bsp-header none) +(define-extern mem-usage-bsp-tree "Recursively compute memory usage of bsp-tree." (function bsp-header bsp-node memory-usage-block int none)) +(define-extern *test-shrub* int) +(define-extern bsp-camera-asm "Determine which 'bsp' leaf cell the camera is in, for precomputed vis. + The result is stored in the bsp itself." (function bsp-header vector none)) +(define-extern print-collide-stats (function none)) +(define-extern level-remap-texture "Level tpages combine the tpages of many individual actors. + Given a texture ID for a texture in an individual actor, + determine the texture ID for this texture in the level's + combined page." (function texture-id texture-id)) +(define-extern build-masks "Allocate and assign texture masks, and closest object arrays. + These are used at runtime to only upload the texture chunks and + mip levels that are actually needed." (function bsp-header none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; subdivide ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern *merc-global-stats* object) ;; merc-global-stats -;; (define-extern clear-tr-stat function) ;; (function tr-stat none) -;; (define-extern *stat-string-tfrag* object) ;; string -;; (define-extern *stat-string-tfrag-scissor* object) ;; string -;; (define-extern *stat-string-total* object) ;; string -;; (define-extern print-tr-stat function) ;; (function tr-stat string string none) -;; (define-extern print-terrain-stats function) ;; (function none) -;; (define-extern update-subdivide-settings! function) ;; (function subdivide-settings math-camera int none) -;; (define-extern *subdivide-settings* object) ;; subdivide-settings -;; (define-extern set-tfrag-dists! function) ;; (function tfrag-dists none) -;; (define-extern *terrain-context* object) ;; terrain-context -;; (define-extern GSH_ENABLE object) ;; symbol -;; (define-extern GSH_BUCKET object) ;; bucket-id -;; (define-extern GSH_WHICH_STAT object) ;; int -;; (define-extern GSH_MAX_DISPLAY object) ;; basic -;; (define-extern GSH_TIME object) ;; int -;; (define-extern *perf-stats* object) ;; perf-stat-array -;; (define-extern *gomi-stats-hack* object) ;; (inline-array perf-stat) -;; (define-extern start-perf-stat-collection function) ;; (function none) -;; (define-extern end-perf-stat-collection function) ;; (function none) -;; (define-extern print-perf-stats function) ;; (function none) +(define-extern *merc-global-stats* merc-global-stats) +(define-extern clear-tr-stat "Reset all statistics to 0." (function tr-stat none)) +(define-extern *stat-string-tfrag* string) +(define-extern *stat-string-tfrag-scissor* string) +(define-extern *stat-string-total* string) +(define-extern print-tr-stat "Print a single tr-stat to the screen." (function tr-stat string string none)) +(define-extern print-terrain-stats "Print all tr-stats for renderers to the screen." (function none)) +(define-extern update-subdivide-settings! "Update the subdivide settings from the far/close settings + This caches the settings in subdivide-settings itself, + as well as in tfrag-work, used by EE tfrag code." (function subdivide-settings math-camera int none)) +(define-extern *subdivide-settings* subdivide-settings) +(define-extern set-tfrag-dists! "Update the subdivide settings used in tfrag VU1 code. + This must be called after update-subdivide-settings!" (function tfrag-dists none)) +(define-extern *terrain-context* terrain-context) +(define-extern GSH_ENABLE symbol) +(define-extern GSH_BUCKET bucket-id) +(define-extern GSH_WHICH_STAT int) +(define-extern GSH_MAX_DISPLAY basic) +(define-extern GSH_TIME int) +(define-extern *perf-stats* perf-stat-array) +(define-extern *gomi-stats-hack* (inline-array perf-stat)) +(define-extern start-perf-stat-collection "Start the per-frame performance stats. + This automatically cycles through various stats/categories, + collecting and aggregating the latest data. + The `gomi-stats-hack` likely refers to how the stat being + collected" (function none)) +(define-extern end-perf-stat-collection "End the per-frame performance stats" (function none)) +(define-extern print-perf-stats (function none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sprite ;; @@ -28101,7 +28158,7 @@ (define-extern add-debug-text-3d (function symbol bucket-id string vector font-color vector2h symbol)) ;; (define-extern add-debug-sphere-with-transform function) ;; (function symbol bucket-id vector meters matrix rgba symbol) (define-extern add-debug-sphere (function symbol bucket-id vector meters rgba symbol)) -;; (define-extern add-debug-text-sphere function) ;; (function symbol bucket-id vector meters string rgba symbol) +(define-extern add-debug-text-sphere (function symbol bucket-id vector meters string rgba symbol)) ;; (define-extern add-debug-spheres function) ;; (function symbol bucket-id (inline-array vector) int rgba symbol) ;; (define-extern add-debug-line-sphere function) ;; (function symbol bucket-id vector vector float rgba none) ;; (define-extern add-debug-circle function) ;; (function symbol bucket-id vector float rgba matrix symbol) @@ -28962,7 +29019,7 @@ ;; tfrag-work ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern *tfrag-work* object) ;; tfrag-work +(define-extern *tfrag-work* tfrag-work) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; tie ;; @@ -29188,7 +29245,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (define-extern *instance-tie-work* object) ;; instance-tie-work -;; (define-extern *prototype-tie-work* object) ;; prototype-tie-work +(define-extern *prototype-tie-work* prototype-tie-work) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; tie-methods ;; @@ -29703,20 +29760,20 @@ ;; mood-tables2 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-extern *overide-mood-color-table* mood-color-table) ;; -(define-extern *overide-mood-fog-table* mood-fog-table) ;; -(define-extern init-overide-table +(define-extern *overide-mood-color-table* mood-color-table) ;; +(define-extern *overide-mood-fog-table* mood-fog-table) ;; +(define-extern init-overide-table "Similar to the beginning of [[init-mood-control]], does the bare minimum to setup the given [[mood-table]] @param! table The table to initialize @returns [[none]]" - (function mood-table none)) ;; + (function mood-table none)) ;; (define-extern *overide-table* mood-table) ;; mood-table (define-extern print-mood-tables "Generates the GOAL code for defining the current state of [[*overide-table*]]" (function none)) ;; ( -(define-extern desaturate-mood-colors +(define-extern desaturate-mood-colors "Unused - Generate GOAL code for a new [[*overide-mood-color-table*]] definition that desaturates the color Apply said overrides to the [[*overide-table*]]" (function float float float none)) -(define-extern desaturate-mood-fog +(define-extern desaturate-mood-fog "Unused - Generate GOAL code for a new [[*overide-mood-fog-table*]] definition that desaturates the fog color Apply said overrides to the [[*overide-table*]]" (function (pointer mood-fog-table) float float none)) @@ -31836,7 +31893,7 @@ (define-extern cspace-by-name "Get a process' [[cspace]] by name." (function process-drawable string cspace)) (define-extern cspace-index-by-name "Get the index of a process' [[cspace]] by name." (function process-drawable string int)) ;; (define-extern vector<-cspace! function) ;; (function vector cspace vector) -;; (define-extern vector<-matrix! function) ;; (function vector matrix vector) +(define-extern vector<-matrix! (function vector matrix vector)) ;; (define-extern vector<-cspace+vector! function) ;; (function vector cspace vector vector) ;; (define-extern cspace-children function) ;; (function process-drawable int pair) ;; (define-extern cspace-inspect-tree function) ;; (function process-drawable cspace int int object process-drawable) diff --git a/decompiler/config/jak3/ntsc_v1/anonymous_function_types.jsonc b/decompiler/config/jak3/ntsc_v1/anonymous_function_types.jsonc index 1ff89ee204..1154b0d7f9 100644 --- a/decompiler/config/jak3/ntsc_v1/anonymous_function_types.jsonc +++ b/decompiler/config/jak3/ntsc_v1/anonymous_function_types.jsonc @@ -14,5 +14,6 @@ [1, "(function none)"], [2, "(function none)"] ], - "gsound": [[1, "(function none)"]] + "gsound": [[1, "(function none)"]], + "joint-mod": [[21, "(function cspace transformq none)"]] } diff --git a/decompiler/config/jak3/ntsc_v1/hacks.jsonc b/decompiler/config/jak3/ntsc_v1/hacks.jsonc index 70c7ad08e0..9bb04c4ef5 100644 --- a/decompiler/config/jak3/ntsc_v1/hacks.jsonc +++ b/decompiler/config/jak3/ntsc_v1/hacks.jsonc @@ -253,7 +253,11 @@ }, "blocks_ending_in_asm_branch": { - "light-merge!": [1, 2, 3, 5, 7] + "light-merge!": [1, 2, 3, 5, 7], + "bsp-camera-asm": [1, 2, 3, 4, 6, 7], + "level-remap-texture": [2, 3, 4, 5, 6], + "start-perf-stat-collection": [26], + "end-perf-stat-collection": [0] }, // Sometimes the game might use format strings that are fetched dynamically, diff --git a/decompiler/config/jak3/ntsc_v1/label_types.jsonc b/decompiler/config/jak3/ntsc_v1/label_types.jsonc index 15633132c0..3d877a83cf 100644 --- a/decompiler/config/jak3/ntsc_v1/label_types.jsonc +++ b/decompiler/config/jak3/ntsc_v1/label_types.jsonc @@ -65,5 +65,8 @@ ["L304", "cloth-params"], ["L303", "cloth-params"], ["L296", "cloth-params"] + ], + "joint-mod": [ + ["L212", "(inline-array vector)", 3] ] } diff --git a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc index 357a957c0d..1b286080cc 100644 --- a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc +++ b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc @@ -54,5 +54,46 @@ [128, "vector"], [192, "vector"] ], - "matrix<-parented-transformq!": [[16, "vector"]] + "matrix<-parented-transformq!": [[16, "vector"]], + "joint-mod-ik-callback": [ + [16, "matrix"], + [80, "matrix"], + [144, "vector"], + [160, "vector"], + [176, "vector"], + [192, "vector"], + [208, "vector"], + [224, "vector"], + [240, "matrix"], + [272, "vector"], + [256, "vector"], + [288, "vector"], + [304, "vector"], + [320, "quaternion"], + [336, "quaternion"], + [352, "vector"], + [384, "vector"], + [448, "vector"], + [464, "vector"], + [480, "vector"], + [496, "quaternion"], + [512, "matrix"], + [576, "vector"], + [592, "matrix"], + [608, "matrix"], + [656, "matrix"], + [720, "matrix"], + [752, "matrix"] + ], + "joint-mod-look-at-handler": [ + [16, "matrix"], + [80, "quaternion"], + [96, "vector"], + [112, "vector"], + [128, "vector"] + ], + "joint-mod-joint-set-world-handler": [ + [32, "vector"], + [48, "vector"] + ] } diff --git a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc index 282ae2d240..679a2d3d87 100644 --- a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc @@ -584,5 +584,70 @@ [[48, 125], "v1", "joint-anim-frame"], [[62, 67], "t2", "(inline-array vector)"], [[67, 71], "a2", "(inline-array vector)"] + ], + "joint-mod-ik-callback": [ + [6, "gp", "joint-mod-ik"], + [9, "gp", "joint-mod-ik"], + [[1, 35], "gp", "joint-mod-ik"], + [[1, 422], "gp", "joint-mod-ik"] + ], + "real-joint-mod-gun-look-at-handler": [ + [1, "v1", "joint-mod"], + [2, "v1", "joint-mod"] + ], + "joint-mod-foot-rot-handler": [ + [[0, 7], "s5", "joint-mod"], + [[35, 152], "s5", "joint-mod"] + ], + "(method 11 joint-mod)": [ + [[0, 27], "s1", "process-drawable"], + [[19, 62], "s2", "fact-info-enemy"] + ], + "joint-mod-look-at-handler": [ + [[2, 406], "gp", "joint-mod"], + [409, "a3", "float"] + ], + "joint-mod-world-look-at-handler": [ + [[0, 217], "gp", "joint-mod"], + [220, "a3", "float"] + ], + "joint-mod-rotate-handler": [[[2, 114], "s5", "joint-mod"]], + "joint-mod-scale-handler": [[[1, 14], "s5", "joint-mod"]], + "joint-mod-joint-set-handler": [[[2, 23], "s4", "joint-mod"]], + "joint-mod-joint-set-world-handler": [[[6, 197], "s5", "joint-mod"]], + "joint-mod-joint-set*-handler": [[[2, 39], "s5", "joint-mod"]], + "joint-mod-joint-set*-world-handler": [[[4, 53], "s5", "joint-mod"]], + "joint-mod-polar-look-at-callback": [ + [[0, 363], "s5", "joint-mod-polar-look-at"] + ], + "(method 10 bsp-header)": [ + [27, "a1", "terrain-context"], + [31, "a0", "terrain-context"] + ], + "bsp-camera-asm": [ + [26, "v1", "pointer"], + [[26, 63], "t1", "bsp-node"], + [43, "t3", "uint"] + ], + "level-remap-texture": [ + [15, "t0", "(pointer uint32)"], + [21, "t0", "(pointer uint32)"], + [19, "t0", "(pointer uint64)"], + [12, "v1", "int"], + [12, "a3", "int"] + ], + "build-masks": [ + [[18, 22], "a1", "drawable-tree-tfrag"], + [24, "a2", "drawable-inline-array-tfrag"], + [[27, 31], "a2", "(inline-array tfragment)"], + [[38, 42], "a1", "drawable-tree-tfrag-trans"], + [44, "a2", "drawable-inline-array-tfrag"], + [[47, 51], "a2", "(inline-array tfragment)"], + [[58, 62], "a1", "drawable-tree-tfrag-water"], + [64, "a2", "drawable-inline-array-tfrag"], + [[67, 71], "a2", "(inline-array tfragment)"], + [[78, 79], "a1", "drawable-tree-instance-tie"], + [123, "a1", "drawable-tree-instance-shrub"], + [[129, 133], "a2", "(inline-array prototype-bucket-shrub)"] ] } diff --git a/decompiler/config/jak3/ntsc_v1/var_names.jsonc b/decompiler/config/jak3/ntsc_v1/var_names.jsonc index 4b3c0da9af..7c34c1ec64 100644 --- a/decompiler/config/jak3/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak3/ntsc_v1/var_names.jsonc @@ -1486,5 +1486,106 @@ "s2-0": "sizeof-frag", "s1-0": "sizeof-geo" } + }, + "(method 9 joint-mod-polar-look-at)": { + "args": [ + "this", + "proc", + "joint-id" + ] + }, + "(method 10 joint-mod-polar-look-at)": { + "args": [ + "this", + "pos" + ] + }, + "(method 11 joint-mod-polar-look-at)": { + "args": [ + "this", + "other", + "pos" + ] + }, + "(method 12 joint-mod-polar-look-at)": { + "args": [ + "this", + "duration", + "final-val", + "restart-if-in-progress" + ] + }, + "(method 13 joint-mod-polar-look-at)": { + "args": [ + "this", + "duration", + "restart-if-in-progress" + ] + }, + "(method 0 joint-mod-ik)": { + "args": [ + "allocation", + "type-to-make", + "proc", + "joint-id", + "hand-dist" + ] + }, + "(method 9 joint-mod-ik)": { + "args": [ + "this", + "pos" + ] + }, + "(method 10 joint-mod-ik)": { + "args": [ + "this", + "enable" + ] + }, + "(method 0 joint-mod)": { + "args": [ + "allocation", + "type-to-make", + "mode", + "proc", + "base-joint-id" + ] + }, + "(method 9 joint-mod)": { + "args": [ + "this", + "mode" + ] + }, + "(method 10 joint-mod)": { + "args": [ + "this", + "pos" + ] + }, + "(method 11 joint-mod)": { + "args": [ + "this", + "target", + "mode", + "proc" + ] + }, + "(method 13 joint-mod)": { + "args": [ + "thix", + "x", + "y", + "z" + ] + }, + "(method 14 joint-mod)": { + "args": [ + "this", + "trans", + "quat", + "scale" + ] } } diff --git a/goal_src/jak3/engine/anim/joint-mod-h.gc b/goal_src/jak3/engine/anim/joint-mod-h.gc index 737350f0ca..190f76feb3 100644 --- a/goal_src/jak3/engine/anim/joint-mod-h.gc +++ b/goal_src/jak3/engine/anim/joint-mod-h.gc @@ -5,6 +5,20 @@ ;; name in dgo: joint-mod-h ;; dgos: GAME +;; The joint-mod system is used to animate parts of a character from gameplay code. +;; For example, rotating the neck to make a character look at something. + +;; This works by installing callbacks in the cspace of the joints, which are used by process-drawable to compute bones. +;; The default callbacks just read and apply transforms from the animation. + +;; Generally, the use doesn't install the callback themselves, and uses a utility class from this file. +;; This is a little inconsistent and there's 3 patterns: +;; - using the `joint-mod` class, which can manage many different types of callbacks (no inheritance) +;; - using a class based on `joint-mod-base`, which is a new base class for new types of joint callbacks (joint-mod-blend-world) +;; - using a class that is just a standalone class (joint-mod-polar-look-at, for example) + +;; the `joint-mod-base` was added in jak 3. + (defenum joint-mod-mode :bitfield #t :type uint32 @@ -54,6 +68,16 @@ (scale 3) ) +(defenum joint-mod-polar-flags + :type uint32 + :bitfield #t + (no-z-rot 0) + (blending-to-zero 1) + (negate-nose 2) + (negate-ear 3) + (negate-up 4) + ) + (deftype joint-mod-blend-world-work (structure) ((mat1 matrix :inline) (mat2 matrix :inline) @@ -100,14 +124,14 @@ This is used to make jak look toward an enemy, for example." (parented-scale? symbol) ) (:methods - (new (symbol type) _type_) - (joint-mod-method-9 () none) - (joint-mod-method-10 () none) - (joint-mod-method-11 () none) + (new (symbol type joint-mod-mode process-drawable int) _type_) + (mode-set! (_type_ joint-mod-mode) none) + (target-set! (_type_ vector) none) + (look-at! (_type_ vector symbol process) none) (reset-blend! (_type_) _type_) - (joint-mod-method-13 () none) - (joint-mod-method-14 () none) - (joint-mod-method-15 () none) + (twist-set! (_type_ float float float) vector) + (trs-set! (_type_ vector quaternion vector) none) + (shut-down (_type_) none) ) ) @@ -122,7 +146,7 @@ This is used to make jak look toward an enemy, for example." (defun-debug joint-mod-debug-draw ((jmod joint-mod)) "Debug draw the bone transform for the associated bone of a joint-mod" - (add-debug-matrix #t (bucket-id bucket577) (-> jmod joint bone transform) (meters 2)) + (add-debug-matrix #t (bucket-id debug-no-zbuf1) (-> jmod joint bone transform) (meters 2)) 0 (none) ) @@ -627,9 +651,9 @@ Then, apply the normal parented transform." (blend-interp float) ) (:methods - (new (symbol type) _type_) - (joint-mod-ik-method-9 () none) - (joint-mod-ik-method-10 () none) + (new (symbol type process-drawable int float) _type_) + (set-ik-target! (_type_ vector) none) + (enable-set! (_type_ symbol) none) ) ) @@ -640,7 +664,7 @@ Then, apply the normal parented transform." ) (deftype joint-mod-polar-look-at (basic) - ((flags uint32) + ((flags joint-mod-polar-flags) (ear int8) (up int8) (nose int8) @@ -653,17 +677,17 @@ Then, apply the normal parented transform." (forward-twist float) (backward-twist float) (target vector :inline) - (blend-duration uint64) - (blend-start-time uint64) + (blend-duration time-frame) + (blend-start-time time-frame) (blend-start-value float) (blend-max float) ) (:methods - (joint-mod-polar-look-at-method-9 () none) - (joint-mod-polar-look-at-method-10 () none) - (joint-mod-polar-look-at-method-11 () none) - (joint-mod-polar-look-at-method-12 () none) - (joint-mod-polar-look-at-method-13 () none) - (joint-mod-polar-look-at-method-14 () none) + (initialize (_type_ process-drawable int) none) + (set-target! (_type_ vector) none) + (set-both-targets! (_type_ joint-mod-polar-look-at vector) none) + (blend-on! (_type_ time-frame float symbol) none) + (blend-to-off! (_type_ time-frame symbol) none) + (get-start-blend! (_type_) float) ) ) diff --git a/goal_src/jak3/engine/anim/joint-mod.gc b/goal_src/jak3/engine/anim/joint-mod.gc index a76439afe9..054fae950f 100644 --- a/goal_src/jak3/engine/anim/joint-mod.gc +++ b/goal_src/jak3/engine/anim/joint-mod.gc @@ -5,5 +5,1562 @@ ;; name in dgo: joint-mod ;; dgos: GAME +(define-extern joint-mod-look-at-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-world-look-at-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-rotate-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set-world-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set*-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-joint-set*-world-handler (function cspace transformq none :behavior process)) +(define-extern joint-mod-polar-look-at-callback (function cspace transformq none :behavior process)) + ;; DECOMP BEGINS +;; WARN: Return type mismatch matrix vs none. +;; WARN: Function joint-mod-ik-callback has a return type of none, but the expression builder found a return statement. +(defbehavior joint-mod-ik-callback process ((arg0 cspace) (arg1 transformq)) + "Inverse kinematics joint mod callback. + Despite the arm-related names, can be used on legs too." + (local-vars + (sv-352 vector) + (sv-356 vector) + (sv-360 vector) + (sv-364 vector) + (sv-368 quaternion) + (sv-372 quaternion) + (sv-768 matrix) + (sv-784 vector) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (let ((gp-0 (the-as joint-mod-ik (-> arg0 param1)))) + (-> arg0 param2) + (cspace<-parented-transformq-joint! arg0 arg1) + (cond + ((logtest? (-> gp-0 flags) (joint-mod-ik-flags enable)) + (+! (-> gp-0 blend) (* 4.0 (seconds-per-frame))) + (if (< 1.0 (-> gp-0 blend)) + (set! (-> gp-0 blend) 1.0) + ) + ) + (else + (set! (-> gp-0 blend) (- (-> gp-0 blend) (* 4.0 (seconds-per-frame)))) + (if (< (-> gp-0 blend) 0.0) + (set! (-> gp-0 blend) 0.0) + ) + ) + ) + (if (= (-> gp-0 blend) 0.0) + (return #f) + ) + (let ((s5-0 (-> arg0 parent bone transform)) + (s4-1 (-> arg0 bone transform)) + ) + (new 'stack-no-clear 'matrix) + (new 'stack-no-clear 'matrix) + (let ((s3-0 (new 'stack-no-clear 'vector))) + (matrix->trans s5-0 s3-0) + (set! (-> s5-0 trans quad) (-> s3-0 quad)) + (matrix->trans s4-1 s3-0) + (set! (-> s4-1 trans quad) (-> s3-0 quad)) + ) + (let* ((a2-0 (-> gp-0 shoulder-matrix-no-ik)) + (a3-0 s5-0) + (v1-22 (-> a3-0 rvec quad)) + (a0-7 (-> a3-0 uvec quad)) + (a1-3 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> a2-0 rvec quad) v1-22) + (set! (-> a2-0 uvec quad) a0-7) + (set! (-> a2-0 fvec quad) a1-3) + (set! (-> a2-0 trans quad) a3-1) + ) + (let* ((a2-1 (-> gp-0 elbow-matrix-no-ik)) + (a3-2 s4-1) + (v1-23 (-> a3-2 rvec quad)) + (a0-8 (-> a3-2 uvec quad)) + (a1-4 (-> a3-2 fvec quad)) + (a3-3 (-> a3-2 trans quad)) + ) + (set! (-> a2-1 rvec quad) v1-23) + (set! (-> a2-1 uvec quad) a0-8) + (set! (-> a2-1 fvec quad) a1-4) + (set! (-> a2-1 trans quad) a3-3) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (set! sv-784 (new 'stack-no-clear 'vector)) + (let ((s0-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + (s3-1 (new 'stack-no-clear 'vector)) + ) + 0.0 + 0.0 + (set! (-> s2-0 quad) (-> s5-0 trans quad)) + (set! (-> sv-784 quad) (-> s4-1 trans quad)) + (let ((a1-5 s0-0)) + (let ((v1-27 sv-784)) + (let ((a0-13 (-> s4-1 uvec))) + (let ((a2-2 (-> gp-0 hand-dist))) + (.mov vf7 a2-2) + ) + (.lvf vf5 (&-> a0-13 quad)) + ) + (.lvf vf4 (&-> v1-27 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf5 vf7 :mask #b111) + (.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111) + (.svf (&-> a1-5 quad) vf6) + ) + (if (-> gp-0 callback) + ((-> gp-0 callback) gp-0 s5-0 s4-1 s0-0) + ) + (set! (-> s1-0 quad) (-> gp-0 handle-pos quad)) + (let ((f30-0 (vector-vector-distance s2-0 sv-784)) + (f0-12 (vector-vector-distance sv-784 s0-0)) + ) + (set! sv-768 (new 'stack-no-clear 'matrix)) + (let ((v1-32 s1-0) + (a0-19 s2-0) + ) + (.lvf vf4 (&-> v1-32 quad)) + (.lvf vf5 (&-> a0-19 quad)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> sv-768 rvec quad) vf6) + (vector-length (the-as vector sv-768)) + (+ -4.096 f0-12 f30-0) + (let ((f0-15 (+ 4.096 (fabs (- f30-0 f0-12))))) + (cond + ((< f0-15 f0-15) + (vector-normalize! (the-as vector sv-768) f0-15) + (let ((v1-39 s1-0)) + (let ((a0-21 s2-0)) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> a0-21 quad)) + ) + (.lvf vf5 (&-> sv-768 rvec quad)) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> v1-39 quad) vf6) + ) + ) + ((< f0-15 f0-15) + (vector-normalize! (the-as vector sv-768) f0-15) + (vector+! s1-0 s2-0 (the-as vector sv-768)) + ) + ) + ) + ) + (set! sv-352 (vector-! (new 'stack-no-clear 'vector) sv-784 s2-0)) + (let ((v1-44 (new 'stack-no-clear 'vector))) + (.lvf vf4 (&-> s0-0 quad)) + (.lvf vf5 (&-> sv-784 quad)) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> v1-44 quad) vf6) + (set! sv-356 v1-44) + ) + (set! sv-360 (vector-! (new 'stack-no-clear 'vector) s0-0 s2-0)) + (set! sv-364 (vector-! (new 'stack-no-clear 'vector) s1-0 s2-0)) + (set! sv-368 (new 'stack-no-clear 'quaternion)) + (set! sv-372 (new 'stack-no-clear 'quaternion)) + (let ((f26-0 (vector-length sv-352)) + (f24-0 (vector-length sv-356)) + (f30-1 (vector-length sv-364)) + ) + (let* ((s2-1 (new 'stack-no-clear 'vector)) + (f28-0 (vector-vector-angle-safe sv-352 sv-356)) + (f0-17 (fmax -1.0 (fmin 1.0 (/ (- (- (* f30-1 f30-1) (* f26-0 f26-0)) (* f24-0 f24-0)) (* 2.0 f24-0 f26-0))))) + (f26-1 (acos f0-17)) + ) + (cond + ((= f28-0 0.0) + (set! (-> s2-1 quad) (-> (&-> s4-1 quad (-> gp-0 elbow-rotation-axis)) 0)) + (when (logtest? (-> gp-0 flags) (joint-mod-ik-flags elbow-rot-neg)) + (vector-negate! s2-1 s2-1) + (set! f26-1 (- f26-1)) + ) + (set! (-> s3-1 quad) (-> (&-> s4-1 quad (-> gp-0 elbow-pole-vector-axis)) 0)) + (if (logtest? (-> gp-0 flags) (joint-mod-ik-flags elbow-trans-neg)) + (vector-negate! s3-1 s3-1) + ) + ) + (else + (vector-cross! s2-1 sv-352 sv-356) + (vector-! + s3-1 + sv-352 + (vector-float*! + (new 'stack-no-clear 'vector) + sv-360 + (/ (vector-dot sv-360 sv-352) (vector-dot sv-360 sv-360)) + ) + ) + ) + ) + (vector-normalize! s3-1 1.0) + (vector-normalize! s2-1 1.0) + (quaternion-vector-angle! sv-368 s2-1 (- f26-1 f28-0)) + ) + (vector-orient-by-quat! sv-356 sv-356 sv-368) + (vector+! sv-360 sv-352 sv-356) + (quaternion-from-two-vectors! + sv-372 + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-360 1.0) + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-364 1.0) + ) + (vector-orient-by-quat! sv-352 sv-352 sv-372) + (let ((f0-25 (fabs (vector-dot + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-352 1.0) + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-364 1.0) + ) + ) + ) + ) + (if (< 0.98 f0-25) + (vector-orient-by-quat! sv-352 s3-1 sv-372) + ) + ) + (let ((s2-4 (new 'stack-no-clear 'vector)) + (s1-2 (new 'stack-no-clear 'quaternion)) + ) + (new 'stack-no-clear 'matrix) + (* f30-1 f30-1) + (let ((s0-2 (new 'stack-no-clear 'quaternion))) + (vector-flatten! s2-4 sv-352 sv-364) + (vector-flatten! (the-as vector s1-2) s3-1 sv-364) + (vector-normalize! s2-4 1.0) + (vector-normalize! (the-as vector s1-2) 1.0) + (quaternion-from-two-vectors! s0-2 s2-4 (the-as vector s1-2)) + (quaternion*! sv-372 s0-2 sv-372) + ) + ) + ) + ) + ) + (quaternion-pseudo-slerp! sv-368 *unity-quaternion* sv-368 (-> gp-0 blend)) + (quaternion-pseudo-slerp! sv-372 *unity-quaternion* sv-372 (-> gp-0 blend)) + (let ((a2-20 (quaternion->matrix (new 'stack-no-clear 'matrix) sv-368)) + (gp-1 (new 'stack-no-clear 'matrix)) + ) + (set! (-> gp-1 rvec quad) (-> s4-1 trans quad)) + (matrix*! s4-1 s4-1 a2-20) + (set! (-> s4-1 trans quad) (-> gp-1 rvec quad)) + ) + (let ((s3-2 (quaternion->matrix (new 'stack-no-clear 'matrix) sv-372)) + (a2-21 (matrix-4x4-inverse! (new 'stack-no-clear 'matrix) s5-0)) + (gp-2 (new 'stack-no-clear 'matrix)) + ) + (set! (-> gp-2 rvec quad) (-> s5-0 trans quad)) + (matrix*! s4-1 s4-1 a2-21) + (matrix*! s5-0 s5-0 s3-2) + (set! (-> s5-0 trans quad) (-> gp-2 rvec quad)) + ) + (matrix*! s4-1 s4-1 s5-0) + ) + ) + (none) + ) + ) + +(defmethod new joint-mod-ik ((allocation symbol) (type-to-make type) (proc process-drawable) (joint-id int) (hand-dist float)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 process) proc) + (set! (-> v0-0 hand-dist) hand-dist) + (set! (-> v0-0 elbow-pole-vector-axis) (the-as uint 0)) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags elbow-trans-neg)) + (set! (-> v0-0 elbow-rotation-axis) (the-as uint 2)) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags elbow-rot-neg)) + (set! (-> v0-0 callback) #f) + (set! (-> v0-0 blend) 0.0) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags enable)) + (let ((a0-5 (-> proc node-list data joint-id))) + (set! (-> a0-5 param0) joint-mod-ik-callback) + (set! (-> a0-5 param1) v0-0) + (set! (-> a0-5 param2) (the-as basic joint-id)) + ) + v0-0 + ) + ) + +(defmethod set-ik-target! ((this joint-mod-ik) (pos vector)) + (set! (-> this handle-pos quad) (-> pos quad)) + 0 + (none) + ) + +(defmethod enable-set! ((this joint-mod-ik) (enable symbol)) + (if enable + (logior! (-> this flags) (joint-mod-ik-flags enable)) + (logclear! (-> this flags) (joint-mod-ik-flags enable)) + ) + 0 + (none) + ) + +(defbehavior real-joint-mod-gun-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback for pointing the gun (implementation)." + (local-vars + (sv-16 joint-mod) + (sv-64 vector) + (sv-96 quaternion) + (sv-160 vector) + (sv-164 vector) + (sv-168 vector) + (sv-172 symbol) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (set! sv-16 (the-as joint-mod (-> arg0 param1))) + (let ((a0-1 (-> arg1 scale))) + (let ((v1-1 (-> arg1 scale)) + (a2-1 (-> sv-16 scale)) + ) + (.lvf vf4 (&-> v1-1 quad)) + (.lvf vf5 (&-> a2-1 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a0-1 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (-> arg0 bone transform))) + (let ((s4-0 (matrix->quat s5-0 (new 'stack-no-clear 'quaternion)))) + (set! sv-64 (matrix->trans s5-0 (new 'stack-no-clear 'vector))) + (quaternion-rotate-y! s4-0 s4-0 (-> sv-16 twist z)) + (set! sv-96 (quaternion-copy! (new 'stack-no-clear 'quaternion) s4-0)) + (when (!= (-> sv-16 flex-blend) 0.0) + (set! sv-160 (vector-y-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (set! sv-164 (vector-z-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (set! sv-168 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> sv-16 target) sv-64) 1.0)) + (set! sv-172 (the-as symbol #f)) + (let* ((f30-0 (vector-y-angle sv-164)) + (a0-13 (vector-flatten! (new 'stack-no-clear 'vector) sv-168 sv-160)) + (f0-2 (vector-y-angle a0-13)) + (f0-3 (deg-diff f30-0 f0-2)) + (f30-1 (* f0-3 (-> sv-16 blend))) + ) + (let ((f28-0 (fmax (fmin f30-1 (-> sv-16 twist-max y)) (- (-> sv-16 twist-max y))))) + (if (or (!= f30-1 f28-0) (= (-> sv-16 blend) 0.0)) + (logclear! (-> sv-16 track-mode) (track-mode lock-on)) + ) + (cond + ((or (< (-> sv-16 ignore-angle) (fabs f0-3)) + (< (-> sv-16 twist-max w) (vector-vector-distance (-> sv-16 target) sv-64)) + ) + (set! f30-1 0.0) + (set! f28-0 0.0) + (set! sv-172 #t) + ) + ((< 5461.3335 (fabs (deg-diff f30-1 f28-0))) + (set! (-> sv-16 blend) 0.0001) + ) + ((< 182.04445 (fabs (deg-diff f30-1 f28-0))) + (logclear! (-> sv-16 track-mode) (track-mode track-x)) + ) + ) + (if (or (and (logtest? (-> sv-16 track-mode) (track-mode track-y)) (= f30-1 f28-0)) + (< (-> sv-16 twist-max y) (fabs (-> sv-16 twist y))) + ) + (set! (-> sv-16 twist y) + (deg-seek (-> sv-16 twist y) f28-0 (* (fabs (deg-diff f28-0 (-> sv-16 twist y))) + (if (logtest? (-> sv-16 track-mode) (track-mode lock-on)) + 1.0 + (-> sv-16 twist-speed-y) + ) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (if (and (< (fabs (deg-diff f30-1 (-> sv-16 twist y))) 728.1778) (and (not sv-172) (!= (-> sv-16 blend) 0.0))) + (logior! (-> sv-16 track-mode) (track-mode lock-on)) + ) + ) + (quaternion-rotate-local-y! sv-96 sv-96 (-> sv-16 twist y)) + (let* ((s3-1 (vector-x-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (f30-2 (vector-x-angle sv-164)) + (s3-2 (vector-flatten! (new 'stack-no-clear 'vector) sv-168 s3-1)) + (f0-24 (vector-x-angle s3-2)) + (f30-3 (fmax + (fmin (* (- (deg-diff f30-2 f0-24)) (-> sv-16 blend)) (-> sv-16 twist-max x)) + (- (-> sv-16 twist-max x)) + ) + ) + ) + (if (or (< (vector-dot s3-2 sv-164) 0.1) + (< (-> sv-16 twist-max z) (vector-vector-distance (-> sv-16 target) sv-64)) + ) + (set! f30-3 0.0) + ) + (if (or (logtest? (-> sv-16 track-mode) (track-mode track-x)) + (< (-> sv-16 twist-max x) (fabs (-> sv-16 twist x))) + ) + (set! (-> sv-16 twist x) + (deg-seek (-> sv-16 twist x) f30-3 (* (fabs (deg-diff f30-3 (-> sv-16 twist x))) + (if (logtest? (-> sv-16 track-mode) (track-mode lock-on)) + 1.0 + (-> sv-16 twist-speed-x) + ) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (quaternion-rotate-x! sv-96 sv-96 (-> sv-16 twist x)) + (quaternion-normalize! (quaternion*! sv-96 sv-96 (-> sv-16 quat))) + ) + (let ((a1-27 (quaternion-slerp! (new 'stack-no-clear 'quaternion) s4-0 sv-96 (-> sv-16 flex-blend)))) + (matrix<-quat s5-0 a1-27) + ) + ) + (let ((f30-4 (-> sv-16 trans x)) + (s4-1 (-> s5-0 uvec)) + (v1-97 (vector<-matrix! (new 'stack-no-clear 'vector) s5-0)) + ) + (let ((f0-43 (- f30-4 (-> v1-97 y)))) + (if (< 614.4 (fabs f0-43)) + (+! (-> sv-16 trans z) (* 8.0 f0-43)) + ) + ) + (+! (-> sv-16 trans z) (* -260.0 (seconds-per-frame) (-> sv-16 trans y))) + (let ((f0-48 (-> sv-16 trans y))) + (+! (-> sv-16 trans y) (* (-> sv-16 trans z) (seconds-per-frame))) + (set! (-> sv-16 trans y) (* 0.95 (-> sv-16 trans y))) + (when (< (* f0-48 (-> sv-16 trans y)) 0.0) + (set! (-> sv-16 trans y) 0.0) + (set! (-> sv-16 trans z) 0.0) + ) + ) + (cond + ((< 409.6 (-> sv-16 trans y)) + (set! (-> sv-16 trans y) 409.6) + (set! (-> sv-16 trans z) 0.0) + ) + ((< (-> sv-16 trans y) -409.6) + (set! (-> sv-16 trans y) -409.6) + (set! (-> sv-16 trans z) 0.0) + ) + ) + (set! (-> sv-16 trans x) (-> v1-97 y)) + (let ((f0-60 (* (-> sv-16 trans y) (-> sv-16 flex-blend)))) + (if (!= f0-60 0.0) + (vector+float*! (-> s5-0 trans) v1-97 s4-1 f0-60) + ) + ) + ) + ) + (if (-> sv-16 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + 0 + (none) + ) + ) + +(defbehavior joint-mod-gun-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback for pointing the gun (wrapper)." + (real-joint-mod-gun-look-at-handler arg0 arg1) + (none) + ) + +(defbehavior joint-mod-foot-rot-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback to pitch the foot to match the ground." + (let ((s5-0 (the-as joint-mod (-> arg0 param1))) + (gp-0 (-> arg0 bone transform)) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s3-0 (-> s5-0 target)) + (s4-0 (-> s5-0 twist-max)) + ) + 1.0 + (when (< 8192.0 (vector-vector-angle-safe s3-0 s4-0)) + (let* ((a1-4 (vector-normalize! (vector-cross! (new 'stack-no-clear 'vector) s3-0 s4-0) 1.0)) + (a2-1 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) a1-4 8192.0)) + ) + (vector-orient-by-quat! s4-0 s3-0 a2-1) + ) + ) + (let* ((f0-4 + (/ (vector-dot s3-0 (-> s5-0 joint bone transform uvec)) (vector-length (-> s5-0 joint bone transform uvec))) + ) + (f30-1 (lerp-scale 0.0 1.0 f0-4 0.85 1.0)) + ) + (vector-deg-slerp (-> s5-0 twist) (-> s5-0 twist) s4-0 0.3) + (set! (-> s4-0 quad) (-> s5-0 twist quad)) + (seek! (-> s5-0 blend) (-> s5-0 flex-blend) (* 4.0 (seconds-per-frame))) + (let ((s3-1 (matrix->scale gp-0 (new 'stack-no-clear 'vector)))) + (let ((s2-0 (matrix->quat gp-0 (new 'stack-no-clear 'quaternion))) + (s0-0 (matrix->trans gp-0 (new 'stack-no-clear 'vector))) + ) + (set! (-> gp-0 uvec quad) (-> s5-0 twist-max quad)) + (vector-cross! (-> gp-0 fvec) (-> gp-0 rvec) (-> gp-0 uvec)) + (vector-cross! (-> gp-0 rvec) (-> gp-0 uvec) (-> gp-0 fvec)) + (set! (-> gp-0 rvec w) 0.0) + (set! (-> gp-0 uvec w) 0.0) + (set! (-> gp-0 fvec w) 0.0) + (let ((s1-0 (matrix->quat gp-0 (new 'stack-no-clear 'quaternion)))) + (let* ((f0-14 (vector-dot s4-0 (vector-! (new 'stack-no-clear 'vector) s0-0 (-> s5-0 trans)))) + (f0-15 (lerp-scale 1.0 0.0 f0-14 819.2 2048.0)) + ) + (seek! (-> s5-0 old-blend) (* (-> s5-0 blend) f0-15 f30-1) (* 15.0 (seconds-per-frame))) + ) + (quaternion-slerp! s1-0 s2-0 s1-0 (-> s5-0 old-blend)) + (matrix<-quat gp-0 s1-0) + ) + ) + (matrix<-scale gp-0 s3-1) + ) + ) + ) + ) + 0 + (none) + ) + +(defmethod new joint-mod ((allocation symbol) (type-to-make type) (mode joint-mod-mode) (proc process-drawable) (base-joint-id int)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> gp-0 process) proc) + (set! (-> gp-0 joint) (-> proc node-list data base-joint-id)) + (mode-set! gp-0 mode) + (set-vector! (-> gp-0 twist-max) 8192.0 11832.889 0.0 1.0) + (set! (-> gp-0 twist-speed-x) 0.1) + (set! (-> gp-0 twist-speed-y) 0.1) + (set! (-> gp-0 up) (the-as uint 1)) + (set! (-> gp-0 nose) (the-as uint 2)) + (set! (-> gp-0 ear) (the-as uint 0)) + (set! (-> gp-0 base-joint) (the-as uint base-joint-id)) + (set! (-> gp-0 base-nose) (the-as uint 2)) + (set! (-> gp-0 max-dist) 122880.0) + (set! (-> gp-0 ignore-angle) 65536.0) + (set! (-> gp-0 flex-blend) 1.0) + (set! (-> gp-0 shutting-down?) #f) + (set-vector! (-> gp-0 scale) 1.0 1.0 1.0 1.0) + (set! (-> gp-0 parented-scale?) #f) + (quaternion-identity! (-> gp-0 quat)) + gp-0 + ) + ) + +;; WARN: Return type mismatch joint-mod vs none. +(defmethod mode-set! ((this joint-mod) (mode joint-mod-mode)) + "Set the type of joint-mod and install the right callback." + (set! (-> this mode) mode) + (let ((v1-0 (-> this joint))) + (case mode + (((joint-mod-mode flex-blend)) + (set! (-> v1-0 param0) #f) + (set! (-> this blend) 0.0) + (set! (-> this flex-blend) 1.0) + ) + (((joint-mod-mode reset)) + (set! (-> v1-0 param0) #f) + (set! (-> this blend) 0.0) + (set! (-> this shutting-down?) #f) + ) + (((joint-mod-mode look-at)) + (let ((a0-4 v1-0)) + (set! (-> a0-4 param0) joint-mod-look-at-handler) + (set! (-> a0-4 param1) this) + ) + ) + (((joint-mod-mode joint-set*-world)) + (let ((a0-5 v1-0)) + (set! (-> a0-5 param0) joint-mod-gun-look-at-handler) + (set! (-> a0-5 param1) this) + ) + ) + (((joint-mod-mode gun-look-at)) + (set-vector! (-> this twist) 0.0 1.0 0.0 1.0) + (let ((a0-7 v1-0)) + (set! (-> a0-7 param0) + (lambda ((arg0 cspace) (arg1 transformq)) (joint-mod-foot-rot-handler arg0 arg1) (none)) + ) + (set! (-> a0-7 param1) this) + ) + ) + (((joint-mod-mode world-look-at)) + (let ((a0-8 v1-0)) + (set! (-> a0-8 param0) joint-mod-world-look-at-handler) + (set! (-> a0-8 param1) this) + ) + ) + (((joint-mod-mode rotate)) + (let ((a0-9 v1-0)) + (set! (-> a0-9 param0) joint-mod-rotate-handler) + (set! (-> a0-9 param1) this) + ) + (set! (-> this blend) 1.0) + ) + (((joint-mod-mode rotate2)) + (let ((a0-11 v1-0)) + (set! (-> a0-11 param0) joint-mod-rotate-handler) + (set! (-> a0-11 param1) this) + ) + (set! (-> this blend) 1.0) + ) + (((joint-mod-mode joint-set)) + (let ((a0-13 v1-0)) + (set! (-> a0-13 param0) joint-mod-joint-set-handler) + (set! (-> a0-13 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + (((joint-mod-mode foot-rot)) + (let ((a0-16 v1-0)) + (set! (-> a0-16 param0) joint-mod-joint-set-world-handler) + (set! (-> a0-16 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + (set! (-> this flex-blend) 1.0) + ) + (((joint-mod-mode joint-set*)) + (let ((a0-23 v1-0)) + (set! (-> a0-23 param0) joint-mod-joint-set*-handler) + (set! (-> a0-23 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + (((joint-mod-mode polar-look-at)) + (let ((a0-27 v1-0)) + (set! (-> a0-27 param0) joint-mod-joint-set*-world-handler) + (set! (-> a0-27 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + ) + ) + (none) + ) + +;; WARN: Return type mismatch joint-mod vs none. +(defmethod shut-down ((this joint-mod)) + "Disable the joint mod, possibly blending out depending on the type" + (set! (-> this shutting-down?) #t) + (set! (-> this blend) 0.0) + (none) + ) + +(defmethod twist-set! ((thix joint-mod) (x float) (y float) (z float)) + "Set twist x,y,z. A value of #f will skip the set." + (if x + (set! (-> thix twist x) x) + ) + (if y + (set! (-> thix twist y) y) + ) + (if z + (set! (-> thix twist z) z) + ) + (-> thix twist) + ) + +(defmethod trs-set! ((this joint-mod) (trans vector) (quat quaternion) (scale vector)) + "Set translation, quaternion, scale. A value of #f will skip the set." + (if trans + (set! (-> this trans quad) (-> trans quad)) + ) + (if quat + (quaternion-copy! (-> this quat) quat) + ) + (if scale + (set! (-> this scale quad) (-> scale quad)) + ) + 0 + (none) + ) + +(defmethod target-set! ((this joint-mod) (pos vector)) + "Set the target position for look-at mode." + (if (= (-> this mode) (joint-mod-mode reset)) + (mode-set! this (joint-mod-mode look-at)) + ) + (let ((f0-0 (vector-vector-distance (-> this process root trans) pos))) + (set! (-> this shutting-down?) #f) + (set! (-> this target quad) (-> pos quad)) + (if (< f0-0 (-> this max-dist)) + (set! (-> this blend) 1.0) + (set! (-> this blend) 0.0) + ) + ) + 0 + (none) + ) + +(define last-try-to-look-at-data (new 'global 'try-to-look-at-info)) + +(defmethod look-at! ((this joint-mod) (target vector) (mode symbol) (proc process)) + "Activate joint mod to look at the process." + (when (= mode 'attacking) + (let* ((s2-0 proc) + (s1-0 (if (type? s2-0 process-drawable) + (the-as process-drawable s2-0) + ) + ) + ) + (when s1-0 + (let* ((s0-0 (-> s1-0 fact)) + (s2-1 (if (type? s0-0 fact-info-enemy) + (the-as fact-info-enemy s0-0) + ) + ) + ) + (when s2-1 + (when (< (vector-vector-distance (-> this process root trans) (-> s1-0 root trans)) (-> s2-1 cam-notice-dist)) + (set-time! (-> this notice-time)) + (set! (-> last-try-to-look-at-data who) (process->handle proc)) + (if (< (-> last-try-to-look-at-data vert) (-> s2-1 cam-vert)) + (set! (-> last-try-to-look-at-data vert) (-> s2-1 cam-vert)) + ) + (if (< (-> last-try-to-look-at-data horz) (-> s2-1 cam-horz)) + (set! (-> last-try-to-look-at-data horz) (-> s2-1 cam-horz)) + ) + ) + ) + ) + ) + ) + ) + (let ((f30-0 (vector-vector-distance (-> this process root trans) target))) + (if (logtest? (process-mask enemy) (-> proc mask)) + (+! (-> this look-at-count) (the int (lerp-scale 256.0 0.0 f30-0 20480.0 204800.0))) + ) + (when (and (or (= (-> this blend) 0.0) + (or (< f30-0 (vector-vector-distance (-> this process root trans) (-> this target))) (= mode 'force)) + ) + (< f30-0 (-> this max-dist)) + ) + (if (= (-> this mode) (joint-mod-mode reset)) + (mode-set! this (joint-mod-mode look-at)) + ) + (set! (-> this target quad) (-> target quad)) + (set! (-> this blend) 1.0) + (set! (-> this shutting-down?) #f) + ) + ) + 0 + (none) + ) + +(defbehavior joint-mod-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for look-at joint mod." + (local-vars + (sv-144 matrix) + (sv-148 quaternion) + (sv-152 vector) + (sv-156 vector) + (sv-160 (pointer uint128)) + (sv-164 symbol) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((gp-0 (the-as joint-mod (-> arg0 param1)))) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s3-0 (-> arg0 bone transform))) + (set! sv-144 (new 'stack-no-clear 'matrix)) + (set! sv-148 (new 'stack-no-clear 'quaternion)) + (set! sv-152 (new 'stack-no-clear 'vector)) + (set! sv-156 (new 'stack-no-clear 'vector)) + (set! sv-160 + (&-> (-> gp-0 process node-list data (-> gp-0 base-joint) bone) transform quad (-> gp-0 base-nose)) + ) + (set! sv-164 + (< (vector-dot (-> s3-0 rvec) (vector-cross! (new 'stack-no-clear 'vector) (-> s3-0 uvec) (-> s3-0 fvec))) + 0.0 + ) + ) + (vector-normalize-copy! (-> sv-144 rvec) (the-as vector (&-> s3-0 quad (-> gp-0 ear))) (if sv-164 + -1.0 + 1.0 + ) + ) + (vector-normalize-copy! (-> sv-144 uvec) (the-as vector (&-> s3-0 quad (-> gp-0 up))) 1.0) + (vector-normalize-copy! (-> sv-144 fvec) (the-as vector (&-> s3-0 quad (-> gp-0 nose))) 1.0) + ) + (vector-reset! (-> sv-144 trans)) + (matrix->quaternion sv-148 sv-144) + (vector-normalize! (vector-! sv-152 (-> gp-0 target) (-> arg0 bone transform trans)) 1.0) + (vector-inv-orient-by-quat! sv-156 sv-152 sv-148) + (let ((f30-0 (vector-y-angle sv-156)) + (f0-2 (if (= (-> gp-0 base-joint) (+ (-> arg0 joint number) 1)) + 0.0 + (deg-diff (vector-y-angle (-> sv-144 fvec)) (vector-y-angle (the-as vector sv-160))) + ) + ) + ) + (if (< (-> gp-0 ignore-angle) (fabs f30-0)) + (set! f30-0 0.0) + ) + (let ((f30-1 + (fmax + (fmin (* f30-0 (-> gp-0 blend) (-> gp-0 flex-blend)) (+ (-> gp-0 twist-max y) (* f0-2 (-> gp-0 flex-blend)))) + (+ (- (-> gp-0 twist-max y)) (* f0-2 (-> gp-0 flex-blend))) + ) + ) + ) + (when (and (-> gp-0 shutting-down?) (< (fabs (- (-> gp-0 twist y) f30-1)) 18.204445)) + (if (and (= (-> gp-0 scale x) 1.0) (= (-> gp-0 scale y) 1.0) (= (-> gp-0 scale z) 1.0)) + (mode-set! gp-0 (joint-mod-mode reset)) + (mode-set! gp-0 (joint-mod-mode rotate2)) + ) + ) + (set! (-> gp-0 twist y) + (deg-seek + (-> gp-0 twist y) + f30-1 + (* (fabs (deg-diff f30-1 (-> gp-0 twist y))) (-> gp-0 twist-speed-y) (-> self clock time-adjust-ratio)) + ) + ) + ) + ) + (let ((f0-21 (if sv-164 + (- (-> gp-0 twist y)) + (-> gp-0 twist y) + ) + ) + (a1-18 (new-stack-vector0)) + ) + (set! (-> a1-18 data (-> gp-0 up)) 1.0) + (let ((a2-7 (quaternion-vector-angle! (new-stack-quaternion0) a1-18 f0-21))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) a2-7)) + ) + ) + (let ((f0-27 + (fmax + (fmin (* (- (vector-x-angle sv-156)) (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max x)) + (- (-> gp-0 twist-max x)) + ) + ) + ) + (if (< (vector-dot sv-156 *z-vector*) 0.1) + (set! f0-27 0.0) + ) + (set! (-> gp-0 twist x) + (deg-seek + (-> gp-0 twist x) + f0-27 + (* (fabs (deg-diff f0-27 (-> gp-0 twist x))) (-> gp-0 twist-speed-x) (-> self clock time-adjust-ratio)) + ) + ) + ) + (let ((a1-22 (new-stack-vector0))) + (set! (-> a1-22 data (-> gp-0 ear)) 1.0) + (let ((a2-10 (quaternion-vector-angle! (new-stack-quaternion0) a1-22 (-> gp-0 twist x)))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) a2-10)) + ) + ) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> gp-0 trans)) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) (-> gp-0 quat))) + (let ((a1-27 (-> arg1 scale))) + (let ((v1-71 (-> arg1 scale)) + (a0-36 (-> gp-0 scale)) + ) + (.lvf vf4 (&-> v1-71 quad)) + (.lvf vf5 (&-> a0-36 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-27 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> gp-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) + (add-debug-text-sphere + *display-target-marks* + (bucket-id debug-no-zbuf1) + (-> gp-0 target) + (meters 0.2) + "look" + (new 'static 'rgba :r #xff :g #xff :a #x80) + ) + ) + ) + 0 + (none) + ) + ) + +(defbehavior joint-mod-world-look-at-handler process ((arg0 cspace) (arg1 transformq)) + (local-vars (sv-48 vector) (sv-52 vector) (sv-56 vector)) + (let ((gp-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s5-0 (-> arg0 bone transform))) + (cspace<-parented-transformq-joint! arg0 arg1) + (set! sv-48 (vector-normalize-copy! + (new 'stack-no-clear 'vector) + (-> gp-0 process node-list data 0 bone transform uvec) + 1.0 + ) + ) + (set! sv-52 (vector-normalize! (the-as vector (&-> s5-0 quad (-> gp-0 nose))) 1.0)) + (set! sv-56 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> gp-0 target) (-> s5-0 trans)) 1.0)) + (let* ((f30-0 (vector-y-angle sv-52)) + (a0-7 (vector-flatten! (new-stack-vector0) sv-56 sv-48)) + (f0-0 (vector-y-angle a0-7)) + (f0-1 (deg-diff f30-0 f0-0)) + ) + (if (< (-> gp-0 ignore-angle) (fabs f0-1)) + (set! f0-1 0.0) + ) + (let ((f0-5 + (fmax (fmin (* f0-1 (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max y)) (- (-> gp-0 twist-max y))) + ) + ) + (set! (-> gp-0 twist y) (deg-seek + (-> gp-0 twist y) + f0-5 + (* (fmax 1.0 (* (fabs (deg-diff f0-5 (-> gp-0 twist y))) (-> gp-0 twist-speed-y))) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (when (!= (-> gp-0 twist y) 0.0) + (let ((a2-3 (matrix-rotate-y! (new 'stack-no-clear 'matrix) (-> gp-0 twist y))) + (s4-2 (-> s5-0 trans quad)) + ) + (matrix*! s5-0 s5-0 a2-3) + (set! (-> s5-0 trans quad) s4-2) + ) + ) + (let* ((s4-3 (vector-normalize-copy! + (new 'stack-no-clear 'vector) + (the-as vector (-> gp-0 process node-list data 0 bone transform)) + 1.0 + ) + ) + (f30-2 (vector-x-angle sv-52)) + (s4-4 (vector-flatten! (new-stack-vector0) sv-56 s4-3)) + (f0-15 (vector-x-angle s4-4)) + (f0-21 (fmax + (fmin (* (- (deg-diff f30-2 f0-15)) (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max x)) + (- (-> gp-0 twist-max x)) + ) + ) + ) + (if (< (vector-dot s4-4 sv-52) 0.1) + (set! f0-21 0.0) + ) + (set! (-> gp-0 twist x) (deg-seek + (-> gp-0 twist x) + f0-21 + (* (fmax 1.0 (* (fabs (deg-diff f0-21 (-> gp-0 twist x))) (-> gp-0 twist-speed-x))) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + (when (!= (-> gp-0 twist x) 0.0) + (let* ((v1-25 (-> gp-0 ear)) + (a1-17 ((cond + ((zero? v1-25) + matrix-rotate-x! + ) + ((= v1-25 1) + matrix-rotate-y! + ) + (else + matrix-rotate-z! + ) + ) + (new 'stack-no-clear 'matrix) + (-> gp-0 twist x) + ) + ) + ) + (matrix*! s5-0 a1-17 s5-0) + ) + ) + ) + (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) + (add-debug-text-sphere + *display-target-marks* + (bucket-id debug-no-zbuf1) + (-> gp-0 target) + (meters 0.2) + "look" + (new 'static 'rgba :r #xff :g #xff :a #x80) + ) + ) + ) + 0 + (none) + ) + +(defbehavior joint-mod-rotate-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for rotate joint mod." + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s3-0 (new 'static 'inline-array vector 3 + (new 'static 'vector :x 1.0 :w 1.0) + (new 'static 'vector :y 1.0 :w 1.0) + (new 'static 'vector :z 1.0 :w 1.0) + ) + ) + ) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-trans))) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> s5-0 trans)) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-rotate))) + (let* ((v1-9 (-> s3-0 (-> s5-0 ear))) + (a1-4 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-9 x) + (-> v1-9 y) + (-> v1-9 z) + (* (-> s5-0 twist x) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-4 (-> arg1 quat))) + ) + (let* ((v1-13 (-> s3-0 (-> s5-0 up))) + (a1-6 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-13 x) + (-> v1-13 y) + (-> v1-13 z) + (* (-> s5-0 twist y) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-6 (-> arg1 quat))) + ) + (let* ((v1-17 (-> s3-0 (-> s5-0 nose))) + (a1-8 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-17 x) + (-> v1-17 y) + (-> v1-17 z) + (* (-> s5-0 twist z) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-8 (-> arg1 quat))) + ) + ) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-scale))) + (let ((a1-9 (-> arg1 scale))) + (let ((v1-22 (-> arg1 scale)) + (a0-11 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-22 quad)) + (.lvf vf5 (&-> a0-11 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-9 quad) vf6) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +(defbehavior joint-mod-scale-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for scale joint mod." + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((a2-0 (-> arg1 scale))) + (let ((v1-0 (-> arg1 scale)) + (a0-1 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-0 quad)) + (.lvf vf5 (&-> a0-1 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a2-0 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +(defbehavior joint-mod-joint-set-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for set joint mod." + (let ((s4-0 (the-as joint-mod (-> arg0 param1)))) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-trans))) + (set! (-> arg1 trans quad) (-> s4-0 trans quad)) + ) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-rotate))) + (quaternion-copy! (-> arg1 quat) (-> s4-0 quat)) + ) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-scale))) + (set! (-> arg1 scale quad) (-> s4-0 scale quad)) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + 0 + (none) + ) + +;; WARN: Function joint-mod-joint-set-world-handler has a return type of none, but the expression builder found a return statement. +(defbehavior joint-mod-joint-set-world-handler process ((arg0 cspace) (arg1 transformq)) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (the-as joint-mod (-> arg0 param1))) + (s4-0 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector))) + ) + (let ((s3-0 (new 'stack-no-clear 'vector))) + (if (>= 0.0 (-> s5-0 flex-blend)) + (return #f) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-scale)) + (set! (-> s3-0 quad) (-> arg1 scale quad)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (set! (-> s3-0 quad) (-> s5-0 scale quad)) + ) + (else + (vector-lerp! s3-0 (-> arg1 scale) (-> s5-0 scale) (-> s5-0 flex-blend)) + ) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-rotate)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (quaternion->matrix (-> arg0 bone transform) (-> s5-0 quat)) + ) + (else + (let ((v1-15 (new 'stack-no-clear 'vector))) + (set! (-> v1-15 quad) (-> arg1 scale quad)) + (set! (-> v1-15 x) (/ 1.0 (-> v1-15 x))) + (set! (-> v1-15 y) (/ 1.0 (-> v1-15 y))) + (set! (-> v1-15 z) (/ 1.0 (-> v1-15 z))) + (vector-float*! + (the-as vector (-> arg0 bone transform)) + (the-as vector (-> arg0 bone transform)) + (-> v1-15 x) + ) + (vector-float*! (-> arg0 bone transform uvec) (-> arg0 bone transform uvec) (-> v1-15 y)) + (vector-float*! (-> arg0 bone transform fvec) (-> arg0 bone transform fvec) (-> v1-15 z)) + ) + (let ((a1-12 (matrix->quaternion (new 'stack-no-clear 'quaternion) (-> arg0 bone transform)))) + (quaternion->matrix + (-> arg0 bone transform) + (quaternion-slerp! (new 'stack-no-clear 'quaternion) a1-12 (-> s5-0 quat) (-> s5-0 flex-blend)) + ) + ) + ) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-rotate)) + (vector-normalize! (the-as vector (-> arg0 bone transform)) (-> s3-0 x)) + (vector-normalize! (-> arg0 bone transform uvec) (-> s3-0 y)) + (vector-normalize! (-> arg0 bone transform fvec) (-> s3-0 z)) + ) + (else + (vector-float*! (the-as vector (-> arg0 bone transform)) (the-as vector (-> arg0 bone transform)) (-> s3-0 x)) + (vector-float*! (-> arg0 bone transform uvec) (-> arg0 bone transform uvec) (-> s3-0 y)) + (vector-float*! (-> arg0 bone transform fvec) (-> arg0 bone transform fvec) (-> s3-0 z)) + ) + ) + ) + (set! (-> arg0 bone transform rvec w) 0.0) + (set! (-> arg0 bone transform uvec w) 0.0) + (set! (-> arg0 bone transform fvec w) 0.0) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-trans)) + (set! (-> arg0 bone transform trans quad) (-> s4-0 quad)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (set! (-> arg0 bone transform trans quad) (-> s5-0 trans quad)) + (set! (-> arg0 bone transform trans w) 1.0) + ) + (else + (vector-lerp! (-> arg0 bone transform trans) s4-0 (-> s5-0 trans) (-> s5-0 flex-blend)) + (set! (-> arg0 bone transform trans w) 1.0) + ) + ) + ) + 0 + (none) + ) + +(defbehavior joint-mod-joint-set*-handler process ((arg0 cspace) (arg1 transformq)) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-trans))) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> s5-0 trans)) + ) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-rotate))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) (-> s5-0 quat))) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-scale))) + (let ((a1-4 (-> arg1 scale))) + (let ((v1-11 (-> arg1 scale)) + (a0-4 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-11 quad)) + (.lvf vf5 (&-> a0-4 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +(defbehavior joint-mod-joint-set*-world-handler process ((arg0 cspace) (arg1 transformq)) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s3-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> s5-0 quat))) + (s4-0 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector))) + ) + (vector-reset! (-> arg0 bone transform trans)) + (set! (-> arg0 bone transform trans w) 1.0) + (vector-float*! (-> s3-0 rvec) (-> s3-0 rvec) (-> s5-0 scale x)) + (vector-float*! (-> s3-0 uvec) (-> s3-0 uvec) (-> s5-0 scale y)) + (vector-float*! (-> s3-0 fvec) (-> s3-0 fvec) (-> s5-0 scale z)) + (set! (-> s3-0 rvec w) 0.0) + (set! (-> s3-0 uvec w) 0.0) + (set! (-> s3-0 fvec w) 0.0) + (matrix*! (-> arg0 bone transform) (-> arg0 bone transform) s3-0) + (vector+! (-> arg0 bone transform trans) s4-0 (-> s5-0 trans)) + ) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch float vs none. +(defmethod initialize ((this joint-mod-polar-look-at) (proc process-drawable) (joint-id int)) + "Attach joint-mod to process and set defaults." + (let ((a1-2 (-> proc node-list data joint-id))) + (set! (-> a1-2 param0) joint-mod-polar-look-at-callback) + (set! (-> a1-2 param1) this) + ) + (set! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + (set! (-> this up) 1) + (set! (-> this nose) 2) + (set! (-> this ear) 0) + (set! (-> this polar-internal-tilt-max) 32768.0) + (set! (-> this polar-internal-radius) 32768.0) + (set! (-> this polar-external-tilt-max) 32768.0) + (set! (-> this polar-external-radius) 32768.0) + (set! (-> this upward-tilt) 16384.0) + (set! (-> this downward-tilt) 16384.0) + (set! (-> this forward-twist) 16384.0) + (set! (-> this backward-twist) 16384.0) + (set! (-> this blend-duration) 0) + (set! (-> this blend-start-value) 0.0) + (set! (-> this blend-max) 1.0) + (none) + ) + +;; WARN: Return type mismatch float vs none. +(defmethod set-both-targets! ((this joint-mod-polar-look-at) (other joint-mod-polar-look-at) (pos vector)) + "Update the target position of this mod, and a second one." + (when (nonzero? this) + (set-target! this pos) + (when (nonzero? other) + (set! (-> this polar-external-tilt-max) (-> other polar-internal-tilt-max)) + (set! (-> this polar-external-radius) (-> other polar-internal-radius)) + ) + ) + (when (nonzero? other) + (set-target! other pos) + (when (nonzero? this) + (set! (-> other polar-external-tilt-max) (-> this polar-internal-tilt-max)) + (set! (-> other polar-external-radius) (-> this polar-internal-radius)) + ) + ) + (none) + ) + +(defmethod set-target! ((this joint-mod-polar-look-at) (pos vector)) + "Update the target position." + (set! (-> this target quad) (-> pos quad)) + 0 + (none) + ) + +(defmethod blend-on! ((this joint-mod-polar-look-at) (duration time-frame) (final-val float) (restart-if-in-progress symbol)) + "Start blending this joint mod on." + (cond + ((and (not restart-if-in-progress) (not (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero)))) + ) + ((zero? duration) + (set! (-> this blend-start-value) final-val) + (set! (-> this blend-max) final-val) + (set! (-> this blend-duration) duration) + (logclear! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (else + (set-time! (-> this blend-start-time)) + (set! (-> this blend-start-value) (get-start-blend! this)) + (set! (-> this blend-max) final-val) + (set! (-> this blend-duration) duration) + (logclear! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + ) + 0 + (none) + ) + +(defmethod blend-to-off! ((this joint-mod-polar-look-at) (duration time-frame) (restart-if-in-progress symbol)) + "Start blending to disable this joint mod." + (cond + ((and (not restart-if-in-progress) (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero))) + ) + ((zero? duration) + (set! (-> this blend-start-value) 0.0) + (set! (-> this blend-duration) duration) + (logior! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (else + (set-time! (-> this blend-start-time)) + (set! (-> this blend-start-value) (get-start-blend! this)) + (set! (-> this blend-duration) duration) + (logior! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + ) + 0 + (none) + ) + +(defmethod get-start-blend! ((this joint-mod-polar-look-at)) + "Determine what blend to use when starting a new one." + (local-vars (f0-2 float)) + (cond + ((zero? (-> this blend-duration)) + (-> this blend-start-value) + ) + ((begin + (set! f0-2 (the float (- (current-time) (-> this blend-start-time)))) + (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (let ((f0-5 (lerp-scale (-> this blend-start-value) 0.0 f0-2 0.0 (the float (-> this blend-duration))))) + (when (= f0-5 0.0) + (set! (-> this blend-start-value) f0-5) + (set! (-> this blend-duration) 0) + 0 + ) + f0-5 + ) + ) + (else + (let ((f0-8 + (lerp-scale (-> this blend-start-value) (-> this blend-max) f0-2 0.0 (the float (-> this blend-duration))) + ) + ) + (when (>= f0-8 (-> this blend-max)) + (set! (-> this blend-start-value) f0-8) + (set! (-> this blend-duration) 0) + 0 + ) + f0-8 + ) + ) + ) + ) + +(defbehavior joint-mod-polar-look-at-callback process ((arg0 cspace) (arg1 transformq)) + (let* ((s5-0 (the-as joint-mod-polar-look-at (-> arg0 param1))) + (f30-0 (get-start-blend! s5-0)) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (when (< 0.0 f30-0) + (let* ((t9-2 vector-normalize-copy!) + (a0-3 (new 'stack-no-clear 'vector)) + (v1-3 (abs (-> s5-0 nose))) + (s3-0 (t9-2 a0-3 (the-as vector (&-> (-> arg0 bone) transform quad v1-3)) 1.0)) + (s1-0 (vector-normalize! + (vector-! (new 'stack-no-clear 'vector) (-> s5-0 target) (-> arg0 bone transform trans)) + 1.0 + ) + ) + (s4-1 (new 'stack-no-clear 'matrix)) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-nose)) + (vector-negate! s3-0 s3-0) + ) + (let ((t9-5 vector-normalize-copy!) + (a0-7 (-> s4-1 rvec)) + (v1-11 (abs (-> s5-0 ear))) + ) + (t9-5 a0-7 (the-as vector (&-> (-> arg0 bone) transform quad v1-11)) 1.0) + ) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-ear)) + (vector-negate! (-> s4-1 rvec) (-> s4-1 rvec)) + ) + (let ((t9-7 vector-normalize-copy!) + (a0-9 (-> s4-1 uvec)) + (v1-18 (abs (-> s5-0 up))) + ) + (t9-7 a0-9 (the-as vector (&-> (-> arg0 bone) transform quad v1-18)) 1.0) + ) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-up)) + (vector-negate! (-> s4-1 uvec) (-> s4-1 uvec)) + ) + (set! (-> s4-1 fvec quad) (-> s3-0 quad)) + (set-vector! (-> s4-1 trans) 0.0 0.0 0.0 1.0) + (matrix-transpose! s4-1 s4-1) + (set-vector! (-> s4-1 trans) 0.0 0.0 0.0 1.0) + (vector-matrix*! s2-0 s1-0 s4-1) + (let* ((t9-11 asin) + (f0-9 (-> s2-0 x)) + (f0-11 (* f0-9 f0-9)) + (f1-0 (-> s2-0 y)) + (f26-0 (t9-11 (sqrtf (+ f0-11 (* f1-0 f1-0))))) + (f28-0 (atan (-> s2-0 y) (-> s2-0 x))) + ) + (if (< (-> s2-0 z) 0.0) + (set! f26-0 (- 32768.0 f26-0)) + ) + (set! (-> s5-0 polar-internal-radius) f26-0) + (cond + ((< 16384.0 f28-0) + (set! (-> s5-0 polar-internal-tilt-max) (- 32768.0 f28-0)) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< 0.0 (-> s5-0 polar-external-tilt-max))) + (set! f28-0 (fmax f28-0 (- 32768.0 (-> s5-0 polar-external-tilt-max)))) + ) + ) + ((< f28-0 -16384.0) + (set! (-> s5-0 polar-internal-tilt-max) (- -32768.0 f28-0)) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< (-> s5-0 polar-external-tilt-max) 0.0)) + (set! f28-0 (fmin f28-0 (- -32768.0 (-> s5-0 polar-external-tilt-max)))) + ) + ) + ((< 0.0 f28-0) + (set! (-> s5-0 polar-internal-tilt-max) f28-0) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< 0.0 (-> s5-0 polar-external-tilt-max))) + (set! f28-0 (fmin f28-0 (-> s5-0 polar-external-tilt-max))) + ) + ) + (else + (set! (-> s5-0 polar-internal-tilt-max) f28-0) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< (-> s5-0 polar-external-tilt-max) 0.0)) + (set! f28-0 (fmax f28-0 (-> s5-0 polar-external-tilt-max))) + ) + ) + ) + (let* ((f0-39 (sin f28-0)) + (f24-0 (* f0-39 f0-39)) + (f0-41 (cos f28-0)) + (f0-43 (* f0-41 f0-41)) + ) + 32768.0 + (let ((f0-45 (cond + ((< 16384.0 f28-0) + (+ (* f24-0 (-> s5-0 upward-tilt)) (* f0-43 (-> s5-0 backward-twist))) + ) + ((< f28-0 -16384.0) + (+ (* f24-0 (-> s5-0 downward-tilt)) (* f0-43 (-> s5-0 backward-twist))) + ) + ((< 0.0 f28-0) + (+ (* f24-0 (-> s5-0 upward-tilt)) (* f0-43 (-> s5-0 forward-twist))) + ) + (else + (+ (* f24-0 (-> s5-0 downward-tilt)) (* f0-43 (-> s5-0 forward-twist))) + ) + ) + ) + ) + (if (< f0-45 f26-0) + (set! f26-0 f0-45) + ) + ) + ) + (let ((f26-1 (cos f26-0))) + (set-vector! s2-0 (cos f28-0) (sin f28-0) 0.0 1.0) + (let ((t9-18 vector-normalize!) + (a0-24 s2-0) + (f0-53 1.0) + (f1-22 f26-1) + ) + (t9-18 a0-24 (sqrtf (- f0-53 (* f1-22 f1-22)))) + ) + (set! (-> s2-0 z) f26-1) + ) + ) + (matrix-transpose! s4-1 s4-1) + (vector-matrix*! s2-0 s2-0 s4-1) + (if (< f30-0 1.0) + (matrix-from-two-vectors-partial-linear! s4-1 s3-0 s2-0 f30-0) + (matrix-from-two-vectors! s4-1 s3-0 s2-0) + ) + ) + (let ((s3-1 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector)))) + (set-vector! (-> arg0 bone transform trans) 0.0 0.0 0.0 1.0) + (matrix*! (-> arg0 bone transform) (-> arg0 bone transform) s4-1) + (when (logtest? (-> s5-0 flags) (joint-mod-polar-flags no-z-rot)) + (let ((a1-25 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> arg0 bone transform uvec) -1.0))) + (matrix-remove-z-rot (-> arg0 bone transform) a1-25) + ) + ) + (set! (-> arg0 bone transform trans quad) (-> s3-1 quad)) + ) + ) + ) + ) + 0 + (none) + ) diff --git a/goal_src/jak3/engine/debug/debug-h.gc b/goal_src/jak3/engine/debug/debug-h.gc index d3947d6bc4..95d6bed290 100644 --- a/goal_src/jak3/engine/debug/debug-h.gc +++ b/goal_src/jak3/engine/debug/debug-h.gc @@ -6,7 +6,7 @@ ;; dgos: GAME (define-extern add-debug-matrix (function symbol bucket-id matrix meters matrix)) - +(define-extern add-debug-text-sphere (function symbol bucket-id vector meters string rgba symbol)) ;; DECOMP BEGINS diff --git a/goal_src/jak3/engine/draw/drawable-actor-h.gc b/goal_src/jak3/engine/draw/drawable-actor-h.gc index 070aba53d6..e837c4c84c 100644 --- a/goal_src/jak3/engine/draw/drawable-actor-h.gc +++ b/goal_src/jak3/engine/draw/drawable-actor-h.gc @@ -28,7 +28,9 @@ for the entity/birth system." ) ) -(defmethod draw ((this drawable-tree-actor) (arg0 drawable-tree-actor) (arg1 display-frame)) +(defmethod draw ((this drawable-tree-actor)) + "Draw the drawable, and typically its children. + This usually means adding stuff to a list to be drawn later, rather than expensive drawing here." 0 (none) ) diff --git a/goal_src/jak3/engine/draw/drawable-h.gc b/goal_src/jak3/engine/draw/drawable-h.gc index 22582f82e4..b361613d3d 100644 --- a/goal_src/jak3/engine/draw/drawable-h.gc +++ b/goal_src/jak3/engine/draw/drawable-h.gc @@ -5,6 +5,8 @@ ;; name in dgo: drawable-h ;; dgos: GAME +(declare-type region-prim-list structure) + ;; DECOMP BEGINS (deftype drawable (basic) @@ -19,13 +21,13 @@ control over memory layout for use with DMA." ) (:methods (login (_type_) _type_) - (draw (_type_ _type_ display-frame) none) + (draw (_type_) none) (drawable-method-11 () none) (drawable-method-12 () none) - (drawable-method-13 () none) - (drawable-method-14 () none) + (collect-stats (_type_) none) + (debug-draw (_type_) none) (drawable-method-15 () none) - (drawable-method-16 () none) + (collect-regions (_type_ sphere int region-prim-list) none) ) ) diff --git a/goal_src/jak3/engine/gfx/background/subdivide-h.gc b/goal_src/jak3/engine/gfx/background/subdivide-h.gc index 755b0eec94..70bbcfd182 100644 --- a/goal_src/jak3/engine/gfx/background/subdivide-h.gc +++ b/goal_src/jak3/engine/gfx/background/subdivide-h.gc @@ -5,6 +5,8 @@ ;; name in dgo: subdivide-h ;; dgos: GAME +(define-extern *perf-stats* perf-stat-array) + ;; DECOMP BEGINS (deftype subdivide-settings (basic) diff --git a/goal_src/jak3/engine/gfx/background/subdivide.gc b/goal_src/jak3/engine/gfx/background/subdivide.gc index d9f198b5c2..ef2fe42776 100644 --- a/goal_src/jak3/engine/gfx/background/subdivide.gc +++ b/goal_src/jak3/engine/gfx/background/subdivide.gc @@ -7,3 +7,395 @@ ;; DECOMP BEGINS +(define *merc-global-stats* (new 'global 'merc-global-stats)) + +(defun clear-tr-stat ((arg0 tr-stat)) + "Reset all statistics to 0." + (set! (-> arg0 groups) (the-as uint 0)) + (set! (-> arg0 fragments) (the-as uint 0)) + (set! (-> arg0 tris) (the-as uint 0)) + (set! (-> arg0 dverts) (the-as uint 0)) + (set! (-> arg0 instances) (the-as uint 0)) + 0 + (none) + ) + +(define *stat-string-tfrag* (new 'global 'string 128 (the-as string #f))) + +(define *stat-string-tfrag-scissor* (new 'global 'string 128 (the-as string #f))) + +(define *stat-string-total* (new 'global 'string 128 (the-as string #f))) + +;; WARN: Return type mismatch uint vs none. +(defun-debug print-tr-stat ((arg0 tr-stat) (arg1 string) (arg2 string)) + "Print a single tr-stat to the screen." + (clear arg2) + (when (nonzero? (+ (-> arg0 groups) (-> arg0 fragments) (-> arg0 tris) (-> arg0 dverts) (-> arg0 instances))) + (format arg2 "~0k~4d ~5d ~6d ~6d" (-> arg0 groups) (-> arg0 fragments) (-> arg0 tris) (-> arg0 dverts)) + (format + arg2 + "~0k ~7f ~5d ~s" + (/ (* 2.0 (the float (-> arg0 tris))) (the float (- (-> arg0 dverts) (-> arg0 tris)))) + (-> arg0 instances) + arg1 + ) + (format *stdcon* "~S~%" arg2) + (+! (-> *terrain-stats* total groups) (-> arg0 groups)) + (+! (-> *terrain-stats* total fragments) (-> arg0 fragments)) + (+! (-> *terrain-stats* total tris) (-> arg0 tris)) + (+! (-> *terrain-stats* total dverts) (-> arg0 dverts)) + (+! (-> *terrain-stats* total instances) (-> arg0 instances)) + ) + (none) + ) + +(defun-debug print-terrain-stats () + "Print all tr-stats for renderers to the screen." + (dotimes (gp-0 (-> *level* length)) + (let ((s5-0 (-> *level* level gp-0))) + (when (= (-> s5-0 status) 'active) + (compute-memory-usage! s5-0 #f) + (format + *stdcon* + "~0k~D ~A ~,,2fK + textures~%" + (-> s5-0 index) + (-> s5-0 name) + (* 0.0009765625 (the float (-> s5-0 mem-usage))) + ) + ) + ) + ) + (format *stdcon* "~0k~%grps frags tris dverts strip insts~%") + (print-tr-stat (-> *terrain-stats* pris) "pris" *temp-string*) + (print-tr-stat (-> *merc-global-stats* merc) "merc" *temp-string*) + (print-tr-stat (-> *merc-global-stats* emerc) "emerc" *temp-string*) + (print-tr-stat (-> *merc-global-stats* mercneric) "mercneric" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-generic) "tie-generic" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-vanish) "tie-vanish" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie) "tie" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor) "tie-scissor" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap) "tie-envmap" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor) "tie-envmap-scissor" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-trans) "tie-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor-trans) "tie-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-trans) "tie-envmap-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor-trans) "tie-envmap-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-water) "tie-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor-water) "tie-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-water) "tie-envmap-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor-water) "tie-envmap-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* shrub-near) "shrub-near" *temp-string*) + (print-tr-stat (-> *terrain-stats* shrub) "shrub" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor) "tfrag-scissor" *stat-string-tfrag-scissor*) + (print-tr-stat (-> *terrain-stats* tfrag) "tfrag" *stat-string-tfrag*) + (print-tr-stat (-> *terrain-stats* tfrag-trans) "tfrag-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor-trans) "tfrag-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-water) "tfrag-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor-water) "tfrag-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* trans-pris) "trans-pris" *temp-string*) + (print-tr-stat (-> *terrain-stats* billboard) "billboard" *temp-string*) + (print-tr-stat (-> *terrain-stats* trans-shrub) "trans-shrub" *temp-string*) + (print-tr-stat (-> *terrain-stats* ocean-mid) "ocean-mid" *temp-string*) + (print-tr-stat (-> *terrain-stats* ocean-near) "ocean-near" *temp-string*) + (print-tr-stat (-> *terrain-stats* shadow) "shadow" *temp-string*) + (print-tr-stat (-> *terrain-stats* hfrag) "hfrag" *temp-string*) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (print-tr-stat (-> *terrain-stats* total) "total" *stat-string-total*) + (clear-tr-stat (-> *terrain-stats* pris)) + (clear-tr-stat (-> *merc-global-stats* merc)) + (clear-tr-stat (-> *merc-global-stats* emerc)) + (clear-tr-stat (-> *merc-global-stats* mercneric)) + (clear-tr-stat (-> *terrain-stats* shrub-near)) + (clear-tr-stat (-> *terrain-stats* tie-generic)) + (clear-tr-stat (-> *terrain-stats* tie-vanish)) + (clear-tr-stat (-> *terrain-stats* tie)) + (clear-tr-stat (-> *terrain-stats* tie-scissor)) + (clear-tr-stat (-> *terrain-stats* tie-envmap)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor)) + (clear-tr-stat (-> *terrain-stats* tie-trans)) + (clear-tr-stat (-> *terrain-stats* tie-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-trans)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tie-water)) + (clear-tr-stat (-> *terrain-stats* tie-scissor-water)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-water)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor-water)) + (clear-tr-stat (-> *terrain-stats* shrub)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor)) + (clear-tr-stat (-> *terrain-stats* tfrag)) + (clear-tr-stat (-> *terrain-stats* tfrag-trans)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tfrag-water)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor-water)) + (clear-tr-stat (-> *terrain-stats* trans-pris)) + (clear-tr-stat (-> *terrain-stats* billboard)) + (clear-tr-stat (-> *terrain-stats* trans-shrub)) + (clear-tr-stat (-> *terrain-stats* ocean-mid)) + (clear-tr-stat (-> *terrain-stats* ocean-near)) + (clear-tr-stat (-> *terrain-stats* shadow)) + (clear-tr-stat (-> *terrain-stats* hfrag)) + (clear-tr-stat (-> *terrain-stats* total)) + 0 + (none) + ) + +(defun update-subdivide-settings! ((arg0 subdivide-settings) (arg1 math-camera) (arg2 int)) + "Update the subdivide settings from the far/close settings + This caches the settings in subdivide-settings itself, + as well as in tfrag-work, used by EE tfrag code." + (set! (-> arg0 meters 0) (-> arg0 far arg2)) + (set! (-> arg0 meters 4) (-> arg0 close arg2)) + (let ((f0-3 (* 0.14285715 (- (-> arg0 meters 0) (-> arg0 meters 4))))) + (set! (-> arg0 meters 3) (+ (-> arg0 meters 4) (* 0.5 f0-3))) + (set! (-> arg0 meters 2) (+ (-> arg0 meters 3) f0-3)) + (set! (-> arg0 meters 1) (+ (-> arg0 meters 2) (* 2.0 f0-3))) + ) + (let ((f0-7 (* (-> arg1 fov-correction-factor) (/ (-> arg1 inv-hmge-scale w) (-> arg1 d))))) + (dotimes (v1-8 5) + (set! (-> arg0 dist v1-8) (* f0-7 (-> arg0 meters v1-8))) + ) + ) + (set! (-> *tfrag-work* frag-dists x) (- (-> arg0 meters 0))) + (set! (-> *tfrag-work* frag-dists y) (- (-> arg0 meters 1))) + (set! (-> *tfrag-work* frag-dists z) (- (-> arg0 meters 2))) + (set! (-> *tfrag-work* frag-dists w) (- (-> arg0 meters 4))) + 0 + (none) + ) + +(define *subdivide-settings* (new 'global 'subdivide-settings 122880.0 286720.0)) + +;; WARN: Return type mismatch tfrag-dists vs none. +(defun set-tfrag-dists! ((arg0 tfrag-dists)) + "Update the subdivide settings used in tfrag VU1 code. + This must be called after update-subdivide-settings!" + (let ((f2-0 (-> *subdivide-settings* dist 0)) + (f1-0 (-> *subdivide-settings* dist 1)) + (f0-0 (-> *subdivide-settings* dist 2)) + ) + (set! (-> arg0 data 3) (the-as uint f2-0)) + (set! (-> arg0 data 7) (the-as uint f1-0)) + (let ((f4-1 (/ 1.0 (- f2-0 f1-0))) + (f3-2 (/ 1.0 (- f1-0 f0-0))) + ) + (set! (-> arg0 data 1) (the-as uint (- f4-1))) + (set! (-> arg0 data 5) (the-as uint (- f3-2))) + (set! (-> arg0 data 0) (the-as uint (* 0.5 f4-1))) + (set! (-> arg0 data 4) (the-as uint (* 0.5 f3-2))) + (let ((f2-1 (* f2-0 f4-1)) + (f5-7 (* f1-0 f3-2)) + ) + (set! (-> arg0 data 9) (the-as uint f2-1)) + (set! (-> arg0 data 13) (the-as uint f5-7)) + ) + (set! (-> arg0 data 8) (the-as uint (* -0.5 f4-1 f1-0))) + (set! (-> arg0 data 12) (the-as uint (* -0.5 f3-2 f0-0))) + ) + ) + (none) + ) + +(kmemopen global "terrain-context") + +(define *terrain-context* (new 'global 'terrain-context)) + +(kmemclose) + +;; WARN: Return type mismatch perf-stat vs none. +(defmethod print-to-stream ((this perf-stat) (arg0 string) (arg1 basic)) + (format + *stdcon* + "~3d ~8d ~8d ~6d ~6d" + (-> this count) + (-> this cycles) + 0 ;; (-> this instructions) + 0 ;; (-> this icache) og:preserve-this doesn't work on PC + 0 ;; (-> this dcache) + ) + (format *stdcon* " ~2d ~2d ~2d" (-> this to-vu0-waits) (-> this to-spr-waits) (-> this from-spr-waits)) + (format *stdcon* " ~s~%" arg0) + (none) + ) + +(define GSH_ENABLE #f) + +(define GSH_BUCKET (bucket-id bucket3)) + +(define GSH_WHICH_STAT 1) + +(define GSH_MAX_DISPLAY (the-as basic #f)) + +(define GSH_TIME 64) + +(define *perf-stats* (new 'debug 'perf-stat-array 57)) + +(when *debug-segment* +(define *gomi-stats-hack* (the-as (inline-array perf-stat) (malloc 'debug (* 52 (+ GSH_TIME 1))))) + +) +(defun-debug start-perf-stat-collection () + "Start the per-frame performance stats. + This automatically cycles through various stats/categories, + collecting and aggregating the latest data." + (let ((v1-2 (+ (-> *perf-stats* data 0 frame-number) 1))) + (set! (-> *perf-stats* data 0 frame-number) v1-2) + (let ((gp-0 (mod v1-2 (the-as uint 114)))) + (when GSH_ENABLE + (let ((v1-5 GSH_BUCKET)) + (let ((a0-2 GSH_WHICH_STAT)) + (set! gp-0 (+ (* (the uint v1-5) 2) a0-2)) + ) + (when GSH_MAX_DISPLAY + (let ((a0-7 (logand (-> *perf-stats* data 0 frame-number) (+ GSH_TIME -1)))) + (set! (-> *gomi-stats-hack* a0-7 cycles) (-> *perf-stats* data (the-as int v1-5) cycles)) + (set! (-> *gomi-stats-hack* a0-7 instructions) (-> *perf-stats* data (the-as int v1-5) instructions)) + (set! (-> *gomi-stats-hack* a0-7 icache) (-> *perf-stats* data (the-as int v1-5) icache)) + (set! (-> *gomi-stats-hack* a0-7 dcache) (-> *perf-stats* data (the-as int v1-5) dcache)) + (when (zero? a0-7) + (set! (-> *gomi-stats-hack* GSH_TIME cycles) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME instructions) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME icache) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME dcache) (the-as uint 0)) + (dotimes (v1-22 GSH_TIME) + (if (< (-> *gomi-stats-hack* GSH_TIME cycles) (-> *gomi-stats-hack* v1-22 cycles)) + (set! (-> *gomi-stats-hack* GSH_TIME cycles) (-> *gomi-stats-hack* v1-22 cycles)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME instructions) (-> *gomi-stats-hack* v1-22 instructions)) + (set! (-> *gomi-stats-hack* GSH_TIME instructions) (-> *gomi-stats-hack* v1-22 instructions)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME icache) (-> *gomi-stats-hack* v1-22 icache)) + (set! (-> *gomi-stats-hack* GSH_TIME icache) (-> *gomi-stats-hack* v1-22 icache)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME dcache) (-> *gomi-stats-hack* v1-22 dcache)) + (set! (-> *gomi-stats-hack* GSH_TIME dcache) (-> *gomi-stats-hack* v1-22 dcache)) + ) + ) + ) + ) + (format *stdcon* "~%") + (print-to-stream (-> *gomi-stats-hack* GSH_TIME) "max-value" *stdcon*) + ) + ) + ) + (dotimes (v1-27 57) + (set! (-> *perf-stats* data v1-27 count) (the-as uint 0)) + (cond + ((!= v1-27 (shr gp-0 1)) + (set! (-> *perf-stats* data v1-27 ctrl) (the-as uint 0)) + 0 + ) + (else + (let ((a1-63 (logand gp-0 1)) + (a0-64 #x80004010) + ) + (cond + ((zero? a1-63) + (set! a0-64 (+ #x60020 a0-64)) + ) + ((= a1-63 1) + (set! a0-64 (+ #x300c0 a0-64)) + ) + ) + (set! (-> *perf-stats* data v1-27 select) a1-63) + (set! (-> *perf-stats* data v1-27 ctrl) a0-64) + ) + (set! (-> *perf-stats* data v1-27 accum0) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 accum1) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 to-vu0-waits) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 to-spr-waits) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 from-spr-waits) (the-as uint 0)) + 0 + ) + ) + ) + ) + ) + (let* ((v1-31 (-> *perf-stats* data)) + (a0-76 (-> v1-31 0 ctrl)) + ) + (+! (-> v1-31 0 count) 1) + (b! (zero? a0-76) cfg-28 :delay (nop!)) + (.mtc0 Perf 0) + (set! *pc-perf-stat-counter* (get-cpu-clock)) ;; og:preserve-this patched + (.sync.l) + (.sync.p) + ;(.mtpc pcr0 0) + ;(.mtpc pcr1 0) + (.sync.l) + (.sync.p) + (.mtc0 Perf a0-76) + ) + (.sync.l) + (.sync.p) + (label cfg-28) + 0 + 0 + (none) + ) + +;; og:preserve-this this part is patched +(if (not *debug-segment*) + (set! start-perf-stat-collection + (lambda () + (dotimes (v1-0 51) + (set! (-> *perf-stats* data v1-0 count) (the-as uint 0)) + ) + 0 + (none) + ) + ) + ) + +(defun-debug end-perf-stat-collection () + "End the per-frame performance stats" + (local-vars (a0-1 int) (a0-3 int)) + (let ((v1-1 (-> *perf-stats* data))) + (b! (zero? (-> v1-1 0 ctrl)) cfg-2 :delay (nop!)) + (.mtc0 Perf 0) + (.sync.l) + (.sync.p) + ;(.mfpc a0-1 pcr0) + (+! (-> v1-1 0 accum0) a0-1) + (+! (-> v1-1 0 accum0) (- (get-cpu-clock) *pc-perf-stat-counter*)) ;; og:preserve-this patched + ;(.mfpc a0-3 pcr1) + (+! (-> v1-1 0 accum1) 0) ;; og:preserve-this patched + ) + (label cfg-2) + 0 + (dotimes (v1-3 57) + (when (nonzero? (-> *perf-stats* data v1-3 ctrl)) + (let ((a2-0 (-> *perf-stats* data v1-3 select)) + (a1-8 (-> *perf-stats* data v1-3 accum0)) + (a0-15 (-> *perf-stats* data v1-3 accum1)) + ) + (cond + ((zero? a2-0) + (set! (-> *perf-stats* data v1-3 cycles) a1-8) + (set! (-> *perf-stats* data v1-3 instructions) a0-15) + ) + ((= a2-0 1) + (set! (-> *perf-stats* data v1-3 icache) a1-8) + (set! (-> *perf-stats* data v1-3 dcache) a0-15) + ) + ) + ) + ) + ) + 0 + (none) + ) + +(defun-debug print-perf-stats () + (format *stdcon* "~0k~%count cycles instr icache dcache vu0/to/from~%") + (dotimes (gp-0 57) + (if (and (nonzero? (-> *perf-stats* data gp-0 count)) (< (the-as uint 10000) (-> *perf-stats* data gp-0 cycles))) + (print-to-stream + (-> *perf-stats* data gp-0) + (perf-stat-bucket->string (the-as perf-stat-bucket gp-0)) + *stdcon* + ) + ) + ) + 0 + (none) + ) diff --git a/goal_src/jak3/engine/gfx/background/tfrag/tfrag-h.gc b/goal_src/jak3/engine/gfx/background/tfrag/tfrag-h.gc index d02d467aad..62953903a6 100644 --- a/goal_src/jak3/engine/gfx/background/tfrag/tfrag-h.gc +++ b/goal_src/jak3/engine/gfx/background/tfrag/tfrag-h.gc @@ -5,6 +5,9 @@ ;; name in dgo: tfrag-h ;; dgos: GAME +(declare-type tfrag-work structure) +(define-extern *tfrag-work* tfrag-work) + ;; DECOMP BEGINS (deftype tfragment-stats (structure) diff --git a/goal_src/jak3/engine/gfx/background/tie/tie-h.gc b/goal_src/jak3/engine/gfx/background/tie/tie-h.gc index 1e92f603e3..5553750d85 100644 --- a/goal_src/jak3/engine/gfx/background/tie/tie-h.gc +++ b/goal_src/jak3/engine/gfx/background/tie/tie-h.gc @@ -5,6 +5,9 @@ ;; name in dgo: tie-h ;; dgos: GAME +(declare-type prototype-tie-work structure) +(define-extern *prototype-tie-work* prototype-tie-work) + ;; DECOMP BEGINS (deftype tie-fragment-debug (structure) diff --git a/goal_src/jak3/engine/gfx/background/wind.gc b/goal_src/jak3/engine/gfx/background/wind.gc index eb3e3f9930..d40884621a 100644 --- a/goal_src/jak3/engine/gfx/background/wind.gc +++ b/goal_src/jak3/engine/gfx/background/wind.gc @@ -7,3 +7,40 @@ ;; DECOMP BEGINS +(defun update-wind ((arg0 wind-work) (arg1 (array uint8))) + "Update the wind force for this frame. + This value will be used by level-update-wind to update tie/shrub wind values." + (with-pp + (let* ((f0-1 (+ (-> arg0 wind-normal w) (rand-vu-float-range -1024.0 1024.0))) + (f30-1 (- f0-1 (* (the float (the int (/ f0-1 65536.0))) 65536.0))) + ) + (set! (-> arg0 wind-normal w) f30-1) + (set! (-> arg0 wind-normal x) (cos f30-1)) + (set! (-> arg0 wind-normal z) (sin f30-1)) + ) + (+! (-> arg0 wind-time) (- (-> pp clock integral-frame-counter) (-> pp clock old-integral-frame-counter))) + (let* ((s4-0 (logand (-> arg0 wind-time) 63)) + (f0-4 (rand-vu-float-range 0.0 100.0)) + (v1-7 (/ (-> arg0 wind-time) (the-as uint 120))) + (f1-6 (* 0.008333334 (the float (mod (-> arg0 wind-time) (the-as uint 120))))) + (f2-4 (* 0.0625 (the float (-> arg1 (mod (the-as int v1-7) (-> arg1 length)))))) + (f0-5 + (* (+ (* (- (* 0.0625 (the float (-> arg1 (mod (the-as int (+ v1-7 1)) (-> arg1 length))))) f2-4) f1-6) f2-4) + f0-4 + ) + ) + ) + (set! (-> *wind-work* wind-force s4-0) f0-5) + (vector-float*! (-> *wind-work* wind-array s4-0) (-> arg0 wind-normal) f0-5) + ) + 0 + (none) + ) + ) + +(defun wind-get-hashed-index ((arg0 vector) (arg1 wind-work)) + "Unused function, likely a leftover from Jak 1's different wind system." + (logand (+ (the int (-> arg0 x)) (the int (-> arg0 z)) (-> *wind-work* wind-time)) 63) + ) + +;; ERROR: function was not converted to expressions. Cannot decompile. diff --git a/goal_src/jak3/engine/gfx/shrub/shrubbery-h.gc b/goal_src/jak3/engine/gfx/shrub/shrubbery-h.gc index b6ccf2382f..de7a49b9d2 100644 --- a/goal_src/jak3/engine/gfx/shrub/shrubbery-h.gc +++ b/goal_src/jak3/engine/gfx/shrub/shrubbery-h.gc @@ -68,7 +68,9 @@ overwrites all the normal drawable fields." (deftype drawable-tree-instance-shrub (drawable-tree) "Drawable-tree for the shrubs." - () + ((info prototype-array-shrub-info :offset 8) + (colors-added time-of-day-palette :offset 12) + ) ) (deftype generic-shrub-fragment (drawable) diff --git a/goal_src/jak3/engine/gfx/texture/texture-h.gc b/goal_src/jak3/engine/gfx/texture/texture-h.gc index cf5f6e6ee8..31fea45f6b 100644 --- a/goal_src/jak3/engine/gfx/texture/texture-h.gc +++ b/goal_src/jak3/engine/gfx/texture/texture-h.gc @@ -128,7 +128,7 @@ So mask 0 is needed if segment 0 of the texture is needed, etc..." (deftype texture-masks-array (inline-array-class) "Group of all texture-masks for a given tpage." - ((data texture-masks :dynamic) + ((data texture-masks :inline :dynamic) ) ) diff --git a/goal_src/jak3/engine/gfx/vu1-user-h.gc b/goal_src/jak3/engine/gfx/vu1-user-h.gc index 4c7eebf26f..7eec64dec0 100644 --- a/goal_src/jak3/engine/gfx/vu1-user-h.gc +++ b/goal_src/jak3/engine/gfx/vu1-user-h.gc @@ -602,7 +602,7 @@ (bucket574 574) (bucket575 575) (bucket576 576) - (bucket577 577) ;; debug? + (debug-no-zbuf1 577) ;; debug? (bucket578 578) (bucket579 579) (bucket580 580) diff --git a/goal_src/jak3/engine/level/bsp-h.gc b/goal_src/jak3/engine/level/bsp-h.gc index 2921983d18..abe185f40f 100644 --- a/goal_src/jak3/engine/level/bsp-h.gc +++ b/goal_src/jak3/engine/level/bsp-h.gc @@ -7,8 +7,18 @@ (declare-type bsp-header drawable) (declare-type bsp-node structure) +(declare-type entity-camera entity) + (define-extern inspect-bsp-tree (function bsp-header bsp-node none)) (define-extern map-bsp-tree (function (function bsp-node none) bsp-header bsp-node none)) +(define-extern mem-usage-bsp-tree (function bsp-header bsp-node memory-usage-block int none)) + + +(defenum texture-page-flag + :type uint16 + :bitfield #t + (alpha-enable 0) + ) ;; DECOMP BEGINS @@ -22,19 +32,52 @@ This is used for precomputed visibility, based on the camera position. This is n (back-box-min vector4b :inline) (back-box-max vector4b :inline) ) + :pack-me ) (deftype bsp-header (drawable) "The bsp-header is really an entire level. This probably started as a very simple structure, but now it is extremely complicated." - ((all-visible-list (pointer uint16) :offset 32) - (visible-list-length int16 :offset 36) - (drawable-trees drawable-tree-array :offset 40) - (pat pointer :offset 44) - (pat-length int32 :offset 48) - (nodes (inline-array bsp-node) :offset 120) - (end uint8 :offset 399) + ((info file-info :overlay-at id) + (all-visible-list (pointer uint16) :offset 32) + (visible-list-length int16 :offset 36) + (drawable-trees drawable-tree-array :offset 40) + (pat pointer :offset 44) + (pat-length int32 :offset 48) + (texture-remap-table (pointer uint64)) + (texture-remap-table-len int32) + (texture-ids (pointer texture-id)) + (texture-page-count int32) + (unknown-basic basic) + (actors drawable-inline-array-actor :offset 112) + (cameras (array entity-camera)) + (nodes (inline-array bsp-node) :offset 120) + (level level) + (current-leaf-idx uint16) + (texture-flags texture-page-flag 10 :offset 130) + (cam-outside-bsp uint8 :offset 152) + (cam-using-back uint8) + (cam-box-idx uint16) + (actor-birth-order (pointer uint32) :offset 172) + (region-trees (array drawable-tree-region-prim) :offset 188) + (collide-hash collide-hash :offset 196) + (tfrag-masks texture-masks-array :offset 256) + (tfrag-closest (pointer float)) + (tfrag-mask-count uint32 :overlay-at tfrag-closest) + (shrub-masks texture-masks-array) + (shrub-closest (pointer float)) + (shrub-mask-count uint32 :overlay-at shrub-closest) + (alpha-masks texture-masks-array) + (alpha-closest (pointer float)) + (alpha-mask-count uint32 :overlay-at alpha-closest) + (water-masks texture-masks-array) + (water-closest (pointer float)) + (water-mask-count uint32 :overlay-at water-closest) + (bsp-scale vector :inline :offset 288) + (bsp-offset vector :inline) + (unk-drawable drawable :offset 320) + (end uint8 :offset 399) ) (:methods (birth (_type_) none) diff --git a/goal_src/jak3/engine/level/bsp.gc b/goal_src/jak3/engine/level/bsp.gc index 8c7b9b5635..799ae08ea8 100644 --- a/goal_src/jak3/engine/level/bsp.gc +++ b/goal_src/jak3/engine/level/bsp.gc @@ -7,3 +7,706 @@ ;; DECOMP BEGINS +;; WARN: Return type mismatch bsp-header vs none. +(defun mem-usage-bsp-tree ((arg0 bsp-header) (arg1 bsp-node) (arg2 memory-usage-block) (arg3 int)) + "Recursively compute memory usage of bsp-tree." + (cond + ((zero? arg1) + ) + (else + (+! (-> arg2 data 61 count) 1) + (let ((v1-3 20)) + (+! (-> arg2 data 61 used) v1-3) + (+! (-> arg2 data 61 total) v1-3) + ) + (if (zero? (-> arg1 front-box-min w)) + (mem-usage-bsp-tree arg0 (-> arg0 nodes (-> arg1 front)) arg2 arg3) + ) + (when (zero? (-> arg1 back-box-min w)) + (if (> (-> arg1 back) 0) + (mem-usage-bsp-tree arg0 (-> arg0 nodes (-> arg1 back)) arg2 arg3) + ) + ) + ) + ) + (none) + ) + +(defmethod mem-usage ((this bsp-header) (usage memory-usage-block) (flags int)) + (set! (-> usage work-bsp) this) + (when (nonzero? (-> this info)) + (set! (-> usage length) (max 86 (-> usage length))) + (set! (-> usage data 85 name) "array") + (+! (-> usage data 85 count) 1) + (let ((v1-8 (asize-of (-> this info)))) + (+! (-> usage data 85 used) v1-8) + (+! (-> usage data 85 total) (logand -16 (+ v1-8 15))) + ) + ) + (if (nonzero? (-> this drawable-trees)) + (mem-usage (-> this drawable-trees) usage flags) + ) + (if (nonzero? (-> this collide-hash)) + (mem-usage (-> this collide-hash) usage flags) + ) + (set! (-> usage length) (max 66 (-> usage length))) + (set! (-> usage data 44 name) "entity") + (set! (-> usage data 45 name) "camera") + (set! (-> usage data 65 name) "pat") + (set! (-> usage data 61 name) "bsp-node") + (set! (-> usage length) (max 60 (-> usage length))) + (set! (-> usage data 59 name) "bsp-main") + (+! (-> usage data 59 count) 1) + (let ((v1-31 400)) + (+! (-> usage data 59 used) v1-31) + (+! (-> usage data 59 total) (logand -16 (+ v1-31 15))) + ) + (set! (-> usage length) (max 63 (-> usage length))) + (set! (-> usage data 62 name) "bsp-leaf-vis-self") + (+! (-> usage data 62 count) 1) + (let ((v1-40 (-> this visible-list-length))) + (+! (-> usage data 62 used) v1-40) + (+! (-> usage data 62 total) (logand -16 (+ v1-40 15))) + ) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-50 (* (-> this texture-remap-table-len) 8))) + (+! (-> usage data 60 used) v1-50) + (+! (-> usage data 60 total) (logand -16 (+ v1-50 15))) + ) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-60 (* (-> this texture-page-count) 4))) + (+! (-> usage data 60 used) v1-60) + (+! (-> usage data 60 total) (logand -16 (+ v1-60 15))) + ) + (when (nonzero? (-> this unknown-basic)) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-72 (asize-of (-> this unknown-basic)))) + (+! (-> usage data 60 used) v1-72) + (+! (-> usage data 60 total) (logand -16 (+ v1-72 15))) + ) + ) + (when (nonzero? (-> this actor-birth-order)) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-85 (* (-> this actors length) 4))) + (+! (-> usage data 60 used) v1-85) + (+! (-> usage data 60 total) (logand -16 (+ v1-85 15))) + ) + ) + (+! (-> usage data 65 count) (-> this pat-length)) + (let ((v1-92 (* (-> this pat-length) 4))) + (+! (-> usage data 65 used) v1-92) + (+! (-> usage data 65 total) (logand -16 (+ v1-92 15))) + ) + (if (nonzero? (-> this unk-drawable)) + (mem-usage (-> this unk-drawable) usage flags) + ) + (when (nonzero? (-> this region-trees)) + (let* ((s3-0 (-> this region-trees length)) + (s2-0 0) + (a0-40 (-> this region-trees s2-0)) + ) + (while (< s2-0 s3-0) + (mem-usage a0-40 usage (logior flags 128)) + (+! s2-0 1) + (set! a0-40 (-> this region-trees s2-0)) + ) + ) + ) + (let ((s3-1 (-> this cameras))) + (when (nonzero? s3-1) + (dotimes (s2-1 (-> s3-1 length)) + (mem-usage (-> s3-1 s2-1) usage (logior flags 256)) + ) + ) + ) + (if (nonzero? (-> this nodes)) + (mem-usage-bsp-tree this (-> this nodes 0) usage flags) + ) + this + ) + +(defmethod login ((this bsp-header)) + "Initialize the object after it is loaded." + (if (nonzero? (-> this drawable-trees)) + (login (-> this drawable-trees)) + ) + (set! (-> this level tfrag-gs-test) + (if (logtest? (-> this texture-flags 0) (texture-page-flag alpha-enable)) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest greater-equal)) + (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + ) + (if (nonzero? (-> this unk-drawable)) + (login (-> this unk-drawable)) + ) + this + ) + +(define *test-shrub* 0) + +(defmethod draw ((this bsp-header)) + "Draw the drawable, and typically its children. + This usually means adding stuff to a list to be drawn later, rather than expensive drawing here." + + ;; og:preserve-this + ;; a lot re-written here. + (local-vars (a3-4 uint128) (a3-5 uint128)) + + (let ((v1-0 (-> this level))) + (when (-> v1-0 render?) + (set! *draw-index* (-> v1-0 draw-index)) + (set! (-> *prototype-tie-work* mood) (-> v1-0 mood-context)) + + ;; no more artist subdivide settings?? + + (let ((a2-0 (/ (+ (-> this visible-list-length) 15) 16))) + ;; upload vis bits, though I think nothing uses this. + (__mem-move + (-> (scratchpad-object terrain-context) work background vis-list) + (-> v1-0 vis-bits) + (the uint (* 16 a2-0))) + ; (dma-send-to-spr-no-flush + ; (the-as uint (+ #x3800 #x70000000)) + ; (the-as uint (-> v1-0 vis-bits)) + ; (the-as uint a2-0) + ; #f + ; ) + ) + + ;; debug option to flip visibilty + (when *artist-flip-visible* + (let ((v1-6 (/ (+ (-> this visible-list-length) 15) 16)) + (a0-10 (-> (scratchpad-object terrain-context) work background vis-list)) + (a1-4 (-> this all-visible-list)) + ) + (dotimes (a2-1 v1-6) + (let ((a3-3 (-> (the-as (pointer uint128) (+ (the-as uint a0-10) (* a2-1 16)))))) + (.pnor a3-4 a3-3 0) + ) + (let ((t0-2 (-> (the-as (pointer uint128) (&+ a1-4 (* a2-1 16)))))) + (.pand a3-5 a3-4 t0-2) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint a0-10) (* a2-1 16)))) a3-5) + ) + ) + ) + + ;; load registers. I believe that very very old stuff used this in Jak 1's development, + ;; but now this is mostly unused. The sphere-cull, guard-band-cull functions rely on these + ;; being loaded. The only known use is for culling the drawable-error spheres. + (let ((at-0 *math-camera*)) + (with-vf (vf16 vf17 vf18 vf19 vf20 vf21 vf22 vf23 vf24 vf25 vf26 vf27 vf28 vf29 vf30 vf31) + :rw 'write + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat vector 0 quad)) + (.lvf vf21 (&-> at-0 shrub-mat vector 1 quad)) + (.lvf vf22 (&-> at-0 shrub-mat vector 2 quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot vector 0 quad)) + (.lvf vf25 (&-> at-0 camera-rot vector 1 quad)) + (.lvf vf26 (&-> at-0 camera-rot vector 2 quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp vector 0 quad)) + (.lvf vf29 (&-> at-0 camera-temp vector 1 quad)) + (.lvf vf30 (&-> at-0 camera-temp vector 2 quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + ) + + (if (nonzero? (-> this drawable-trees)) + (draw (-> this drawable-trees)) + ) + ) + ) + 0 + (none) + ) + +(defmethod debug-draw ((this bsp-header)) + "Debug-draw a drawable and its children. Typically uses the debug-draw functions." + + ;; This is mostly useless, as almost nothing has debug-draw methods that do anything. + ;; tfrag/tie might, but they rely on "debug" data in the level that is not present. + + (let ((v1-0 (-> this level))) + (set! *draw-index* (-> v1-0 draw-index)) + (set! (-> *prototype-tie-work* mood) (-> v1-0 mood-context)) + (let ((a2-0 (/ (+ (-> this visible-list-length) 15) 16))) + (__mem-move + (-> (scratchpad-object terrain-context) work background vis-list) + (-> v1-0 vis-bits) + (the uint (* a2-0 16))) + + ; (dma-send-to-spr-no-flush + ; (the-as uint (+ #x3800 #x70000000)) + ; (the-as uint (-> v1-0 vis-bits)) + ; (the-as uint a2-0) + ; #f + ; ) + ) + ) + + (let ((at-0 *math-camera*)) + (with-vf (vf16 vf17 vf18 vf19 vf20 vf21 vf22 vf23 vf24 vf25 vf26 vf27 vf28 vf29 vf30 vf31) + :rw 'write + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat vector 0 quad)) + (.lvf vf21 (&-> at-0 shrub-mat vector 1 quad)) + (.lvf vf22 (&-> at-0 shrub-mat vector 2 quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot vector 0 quad)) + (.lvf vf25 (&-> at-0 camera-rot vector 1 quad)) + (.lvf vf26 (&-> at-0 camera-rot vector 2 quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp vector 0 quad)) + (.lvf vf29 (&-> at-0 camera-temp vector 1 quad)) + (.lvf vf30 (&-> at-0 camera-temp vector 2 quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + ) + + (if (nonzero? (-> this drawable-trees)) + (debug-draw (-> this drawable-trees)) + ) + 0 + (none) + + ) + +(defmethod collect-stats ((this bsp-header)) + "Collect triangle/perf statistics for rendering. + This is only called when viewing stats. + The vis-bits and culling registers are loaded during this time." + (let ((v1-0 (-> this level)) + (a2-0 (/ (+ (-> this visible-list-length) 15) 16)) + ) + (__mem-move + (-> (scratchpad-object terrain-context) work background vis-list) + (-> v1-0 vis-bits) + (the uint (* a2-0 16))) + ; (dma-send-to-spr-no-flush + ; (the-as uint (+ #x3800 #x70000000)) + ; (the-as uint (-> v1-0 vis-bits)) + ; (the-as uint a2-0) + ; #f + ; ) + ) + + ;; these are actually used to cull stuff for computing stats. + ;; interestingly, while tfrag/tie/shrub drawing is in the "background" system, + ;; their stat collection is still in drawable. + (let ((at-0 *math-camera*)) + (with-vf (vf16 vf17 vf18 vf19 vf20 vf21 vf22 vf23 vf24 vf25 vf26 vf27 vf28 vf29 vf30 vf31) + :rw 'write + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat vector 0 quad)) + (.lvf vf21 (&-> at-0 shrub-mat vector 1 quad)) + (.lvf vf22 (&-> at-0 shrub-mat vector 2 quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot vector 0 quad)) + (.lvf vf25 (&-> at-0 camera-rot vector 1 quad)) + (.lvf vf26 (&-> at-0 camera-rot vector 2 quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp vector 0 quad)) + (.lvf vf29 (&-> at-0 camera-temp vector 1 quad)) + (.lvf vf30 (&-> at-0 camera-temp vector 2 quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + ) + (if (nonzero? (-> this drawable-trees)) + (collect-stats (-> this drawable-trees)) + ) + (if (nonzero? (-> this unk-drawable)) + (collect-stats (-> this unk-drawable)) + ) + 0 + (none) + ) + +;; ERROR: Unsupported inline assembly instruction kind - [srl t3, t3, 24] +;; ERROR: Unsupported inline assembly instruction kind - [srl t2, t2, 24] +(defun bsp-camera-asm ((arg0 bsp-header) (arg1 vector)) + "Determine which 'bsp' leaf cell the camera is in, for precomputed vis. + The result is stored in the bsp itself." + (local-vars + (a2-1 object) + (a3-0 uint128) + (a3-1 uint128) + (a3-2 uint128) + (a3-3 uint128) + (t0-5 uint) + (t2-1 uint) + (t3-1 int) + (t4-0 uint128) + (t5-0 uint128) + (t6-0 uint128) + (t7-0 uint128) + ) + (rlet ((Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (nop!) + (.lvf vf3 (&-> arg0 bsp-scale quad)) + (let ((v1-0 (the-as object (-> arg0 nodes)))) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg0 bsp-offset quad)) + (.sub.vf vf1 vf1 vf2 :mask #b111) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b0) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b1) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b1) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b10) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b10) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b100) + (let ((a1-1 #xffffff) + (a2-0 (the-as uint 0)) + ) + (vftoi15.xyzw vf1 vf1) + (.mov a3-0 vf1) + (.pw.sra a3-1 a3-0 15) + (.ppach a3-2 (the-as uint128 0) a3-1) + (.ppacb a3-3 (the-as uint128 0) a3-2) + (let ((a3-4 (the-as uint128 (logand (the-as int a3-3) a1-1)))) + (label cfg-1) + (let ((t1-1 (the-as bsp-node (&+ (the-as pointer v1-0) (+ (* a2-0 16) (* a2-0 4)))))) + (nop!) + (let ((t3-0 (the-as uint128 (-> t1-1 front-box-min clr)))) + (.pcgtb t6-0 t3-0 a3-4) + (let ((t0-2 (the-as uint128 (-> t1-1 front-box-max clr)))) + (.pcgtb t4-0 t0-2 a3-4) + ) + (let ((t2-0 (the-as uint128 (-> t1-1 back-box-min clr)))) + (.pcgtb t7-0 t2-0 a3-4) + (let ((t0-3 (the-as uint128 (-> t1-1 back-box-max clr)))) + (.pcgtb t5-0 t0-3 a3-4) + ) + (let* ((t0-4 (-> t1-1 front)) + (t6-1 (lognot (the-as int t6-0))) + (t7-1 (lognot (the-as int t7-0))) + (t4-1 (logand t6-1 (the-as int t4-0))) + (t5-1 (logand t7-1 (the-as int t5-0))) + (t4-2 (logand t4-1 a1-1)) + (t5-2 (logand t5-1 a1-1)) + ) + ;(.srl t3-1 (the-as uint t3-0) 24) + (set! t3-1 (logand #xffffffff (shr t3-0 24))) + (let ((t1-2 (the-as bsp-node (-> t1-1 back)))) + (b! (= t4-2 a1-1) cfg-4 :delay + ;(.srl t2-1 (the-as int t2-0) 24) + (set! t2-1 (the uint (logand #xffffffff (shr t2-0 24)))) + ) + (b! (= t5-2 a1-1) cfg-7 :delay (set! t0-5 (the-as uint 1))) + (b! #t cfg-11 :delay (set! (-> arg0 cam-outside-bsp) t0-5)) + (label cfg-4) + (b! (zero? t3-1) cfg-1 :likely-delay (set! a2-0 (the uint t0-4))) + (let ((v1-1 a2-0)) + (set! (-> arg0 cam-using-back) (the-as uint 0)) + (b! #t cfg-10 :delay (set! a2-1 t0-4)) + (label cfg-7) + (b! (zero? t2-1) cfg-1 :likely-delay (set! a2-0 (the-as uint t1-2))) + (set! v1-1 a2-0) + (set! a2-1 t1-2) + (set! (-> arg0 cam-using-back) (the-as uint 1)) + (label cfg-10) + (set! (-> arg0 current-leaf-idx) (the-as uint a2-1)) + (set! (-> arg0 cam-box-idx) (the-as uint v1-1)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (set! (-> arg0 cam-outside-bsp) (the-as uint 0)) + (label cfg-11) + 0 + (none) + ) + ) + +(defmethod collect-regions ((this bsp-header) (arg0 sphere) (arg1 int) (arg2 region-prim-list)) + "Fill the region-prim-list with regions that intersect the sphere." + (let ((s3-0 (-> this region-trees))) + (dotimes (s2-0 (-> s3-0 length)) + ;; note: the use of arg1 here is a bug. it's ignored, so it doesn't matter + (collect-regions (-> s3-0 s2-0) arg0 arg1 arg2) + ) + ) + 0 + (none) + ) + +(defun print-collide-stats () + (format *stdcon* "~0k~%count cycles instr icache dcache vu0/to/from~%") + (print-to-stream (-> *perf-stats* data 3) "collide" *stdcon*) + (print-to-stream (-> *perf-stats* data 4) "collide-list" *stdcon*) + (print-to-stream (-> *perf-stats* data 5) "collide-fill" *stdcon*) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (format *stdcon* "~0kcalls = ~d~%" (-> *collide-stats* calls)) + (format + *stdcon* + "~0kspheres = ~d~256hspheres/call = ~f~%" + (-> *collide-stats* spheres) + (/ (the float (-> *collide-stats* spheres)) (the float (-> *collide-stats* calls))) + ) + (format + *stdcon* + "~0knodes = ~d~256hnodes/call = ~f~%" + (-> *collide-stats* nodes) + (/ (the float (-> *collide-stats* nodes)) (the float (-> *collide-stats* calls))) + ) + (format + *stdcon* + "~0kfrags = ~d~256hfrags/call = ~f~%" + (-> *collide-stats* frags) + (/ (the float (-> *collide-stats* frags)) (the float (-> *collide-stats* calls))) + ) + (format + *stdcon* + "~0ktris = ~d~256htris/frag = ~f~%" + (-> *collide-stats* tris) + (/ (the float (-> *collide-stats* tris)) (the float (-> *collide-stats* frags))) + ) + (format + *stdcon* + "~0koutput = ~d~256houtput/call = ~f~%" + (-> *collide-stats* output) + (/ (the float (-> *collide-stats* output)) (the float (-> *collide-stats* calls))) + ) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (let ((gp-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 1)))) + (s4-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 9)))) + (s5-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 17)))) + ) + (format *stdcon* "~0ktotal-target ~D~%" gp-0) + (format *stdcon* "~0ktarget-cache-fill ~D ~0,,2f%~%" s4-0 (/ (* 100.0 (the float s4-0)) (the float gp-0))) + (format *stdcon* "~0ktarget-ray-poly ~D ~0,,2f%~%" s5-0 (/ (* 100.0 (the float s5-0)) (the float gp-0))) + ) + (set! (-> *collide-stats* calls) (the-as uint 0)) + (set! (-> *collide-stats* spheres) (the-as uint 0)) + (set! (-> *collide-stats* nodes) (the-as uint 0)) + (set! (-> *collide-stats* frags) (the-as uint 0)) + (set! (-> *collide-stats* tris) (the-as uint 0)) + (set! (-> *collide-stats* output) (the-as uint 0)) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 1))) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 9))) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 17))) + 0 + (none) + ) + +;; WARN: Return type mismatch uint vs texture-id. +(defun level-remap-texture ((arg0 texture-id)) + "Level tpages combine the tpages of many individual actors. + Given a texture ID for a texture in an individual actor, + determine the texture ID for this texture in the level's + combined page." + (let ((v1-1 (-> *level* log-in-level-bsp))) + (when v1-1 + (let* ((a3-0 (-> v1-1 texture-remap-table-len)) + (v1-2 (the-as object (-> v1-1 texture-remap-table))) + (t0-0 (the-as (pointer uint64) v1-2)) + (a1-1 (the-as uint #xfffffff8)) + (a2-1 (logand (new 'static 'texture-id :index #xfff :page #xfff) arg0)) + (a3-2 (the-as object (&+ t0-0 (* a3-0 8)))) + ) + (label cfg-2) + (b! (= v1-2 a3-2) cfg-8 :delay (nop!)) + (let ((t0-3 (the-as object (logand (/ (+ (the-as int v1-2) (the-as int a3-2)) 2) a1-1)))) + (let ((t1-1 (- (-> (the-as (pointer uint32) t0-3) 0) a2-1))) + (b! (zero? t1-1) cfg-7 :delay (nop!)) + (b! (< (the-as int t1-1) 0) cfg-6 :delay (nop!)) + ) + (b! #t cfg-2 :delay (set! a3-2 (the-as (pointer uint64) t0-3))) + (label cfg-6) + (b! #t cfg-2 :delay (set! v1-2 (+ (the-as int t0-3) 8))) + (label cfg-7) + (set! arg0 (the-as texture-id (logior (-> (the-as (pointer uint32) t0-3) 1) 20))) + ) + ) + (label cfg-8) + 0 + ) + ) + (the-as texture-id arg0) + ) + +(defun build-masks ((arg0 bsp-header)) + "Allocate and assign texture masks, and closest object arrays. + These are used at runtime to only upload the texture chunks and + mip levels that are actually needed." + (let ((v1-0 (-> arg0 drawable-trees)) + (s2-0 (-> arg0 tfrag-mask-count)) + (s3-0 (-> arg0 shrub-mask-count)) + (s4-0 (-> arg0 alpha-mask-count)) + (gp-0 (-> arg0 water-mask-count)) + ) + (when (zero? (+ s2-0 s3-0 s4-0 gp-0)) + (dotimes (a0-5 (-> v1-0 length)) + (let ((a1-2 (-> v1-0 data a0-5))) + (cond + ((= (-> a1-2 type) drawable-tree-tfrag) + (let* ((a2-5 (-> (the-as drawable-tree-tfrag a1-2) arrays (+ (-> (the-as drawable-tree-tfrag a1-2) length) -1))) + (a1-4 (-> a2-5 length)) + (a2-6 (-> (the-as drawable-inline-array-tfrag a2-5) data)) + ) + (dotimes (a3-1 a1-4) + (set! (-> a2-6 0 texture-masks-index) (the-as uint s2-0)) + (+! s2-0 1) + (set! a2-6 (the-as (inline-array tfragment) (-> a2-6 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-tfrag-trans) + (let* ((a2-13 + (-> (the-as drawable-tree-tfrag-trans a1-2) arrays (+ (-> (the-as drawable-tree-tfrag-trans a1-2) length) -1)) + ) + (a1-7 (-> a2-13 length)) + (a2-14 (-> (the-as drawable-inline-array-tfrag a2-13) data)) + ) + (dotimes (a3-3 a1-7) + (set! (-> a2-14 0 texture-masks-index) (the-as uint s4-0)) + (+! s4-0 1) + (set! a2-14 (the-as (inline-array tfragment) (-> a2-14 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-tfrag-water) + (let* ((a2-21 + (-> (the-as drawable-tree-tfrag-water a1-2) arrays (+ (-> (the-as drawable-tree-tfrag-water a1-2) length) -1)) + ) + (a1-10 (-> a2-21 length)) + (a2-22 (-> (the-as drawable-inline-array-tfrag a2-21) data)) + ) + (dotimes (a3-5 a1-10) + (set! (-> a2-22 0 texture-masks-index) (the-as uint gp-0)) + (+! gp-0 1) + (set! a2-22 (the-as (inline-array tfragment) (-> a2-22 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-instance-tie) + (let* ((a1-13 (-> (the-as drawable-tree-instance-tie a1-2) prototypes prototype-array-tie)) + (a2-26 (-> a1-13 length)) + ) + (dotimes (a3-7 a2-26) + (cond + ((logtest? (-> a1-13 array-data a3-7 flags) (prototype-flags tpage-water)) + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint gp-0)) + (+! gp-0 1) + ) + ((logtest? (-> a1-13 array-data a3-7 flags) (prototype-flags tpage-alpha)) + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint s4-0)) + (+! s4-0 1) + ) + (else + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint s2-0)) + (+! s2-0 1) + ) + ) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-instance-shrub) + (let* ((a2-30 (-> (the-as drawable-tree-instance-shrub a1-2) info prototype-inline-array-shrub)) + (a1-16 (-> a2-30 length)) + (a2-31 (-> a2-30 data)) + ) + (dotimes (a3-9 a1-16) + (set! (-> a2-31 0 texture-masks-index) (the-as uint s3-0)) + (+! s3-0 1) + (set! a2-31 (the-as (inline-array prototype-bucket-shrub) (-> a2-31 1))) + ) + ) + ) + ) + ) + ) + ) + (when (nonzero? s2-0) + (set! (-> arg0 tfrag-masks) (new 'loading-level 'texture-masks-array (the-as int s2-0))) + (set! (-> arg0 tfrag-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s2-0 4))))) + (let ((v1-5 (-> arg0 tfrag-masks))) + (dotimes (a0-8 (the-as int s2-0)) + (let ((a1-24 (-> v1-5 data a0-8))) + (dotimes (a2-34 3) + (set! (-> a1-24 data a2-34 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? s3-0) + (set! (-> arg0 shrub-masks) (new 'loading-level 'texture-masks-array (the-as int s3-0))) + (set! (-> arg0 shrub-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s3-0 4))))) + (let ((v1-10 (-> arg0 shrub-masks))) + (dotimes (a0-11 (the-as int s3-0)) + (let ((a1-32 (-> v1-10 data a0-11))) + (dotimes (a2-36 3) + (set! (-> a1-32 data a2-36 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? s4-0) + (set! (-> arg0 alpha-masks) (new 'loading-level 'texture-masks-array (the-as int s4-0))) + (set! (-> arg0 alpha-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s4-0 4))))) + (let ((v1-15 (-> arg0 alpha-masks))) + (dotimes (a0-14 (the-as int s4-0)) + (let ((a1-40 (-> v1-15 data a0-14))) + (dotimes (a2-38 3) + (set! (-> a1-40 data a2-38 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? gp-0) + (set! (-> arg0 water-masks) (new 'loading-level 'texture-masks-array (the-as int gp-0))) + (set! (-> arg0 water-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* gp-0 4))))) + (let ((v1-20 (-> arg0 water-masks))) + (dotimes (a0-17 (the-as int gp-0)) + (let ((a1-48 (-> v1-20 data a0-17))) + (dotimes (a2-40 3) + (set! (-> a1-48 data a2-40 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) diff --git a/goal_src/jak3/engine/level/level-h.gc b/goal_src/jak3/engine/level/level-h.gc index 51f17867da..4bc98c7763 100644 --- a/goal_src/jak3/engine/level/level-h.gc +++ b/goal_src/jak3/engine/level/level-h.gc @@ -299,7 +299,7 @@ (level-method-11 () none) (level-method-12 () none) (level-method-13 () none) - (level-method-14 () none) + (compute-memory-usage! (_type_ symbol) memory-usage-block) (level-method-15 () none) (level-method-16 () none) (level-method-17 () none) @@ -321,7 +321,7 @@ (deftype level-group (basic) ((length int32) - (unk-flag1 symbol) + (log-in-level-bsp bsp-header) (loading-level level) (entity-link entity-links :offset 16) (border? symbol) @@ -389,7 +389,7 @@ (set! *level* (new 'static 'level-group :length 10 - :unk-flag1 #f + :log-in-level-bsp #f :loading-level #f :entity-link #f :border? #f diff --git a/goal_src/jak3/engine/process-drawable/process-drawable-h.gc b/goal_src/jak3/engine/process-drawable/process-drawable-h.gc index 32201eb869..3f7b9481ef 100644 --- a/goal_src/jak3/engine/process-drawable/process-drawable-h.gc +++ b/goal_src/jak3/engine/process-drawable/process-drawable-h.gc @@ -9,6 +9,7 @@ (define-extern cspace-index-by-name (function process-drawable string int)) (define-extern joint-control-reset! (function joint-control joint-control-channel none :behavior process-drawable)) (define-extern sleep-code (function symbol :behavior process)) +(define-extern vector<-matrix! (function vector matrix vector)) ;; DECOMP BEGINS diff --git a/test/decompiler/reference/jak3/decompiler-macros.gc b/test/decompiler/reference/jak3/decompiler-macros.gc index 1b1f2ced11..d55bd15557 100644 --- a/test/decompiler/reference/jak3/decompiler-macros.gc +++ b/test/decompiler/reference/jak3/decompiler-macros.gc @@ -981,4 +981,20 @@ (defmacro get-art-by-name (this name type) "Helper macro for casting the result of get-art-by-name-method. Generated by decompiler." `(the-as ,type (get-art-by-name-method ,this ,name ,type)) + ) + +(defmacro vftoi15.xyzw (dst src) + "convert to 17.15 integer. This does the multiply while the number is still + a float. This will have issues for very large floats, but it seems like this + is how PCSX2 does it as well, so maybe it's right? + NOTE: this is the only version of the instruction used in Jak 1, so we + don't need to worry about masks." + + `(begin + (rlet ((temp :class vf)) + (set! temp 32768.0) + (.mul.x.vf temp ,src temp) + (.ftoi.vf ,dst temp) + ) + ) ) \ No newline at end of file diff --git a/test/decompiler/reference/jak3/engine/anim/joint-mod-h_REF.gc b/test/decompiler/reference/jak3/engine/anim/joint-mod-h_REF.gc index 41ce9501f1..249e4dc689 100644 --- a/test/decompiler/reference/jak3/engine/anim/joint-mod-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/anim/joint-mod-h_REF.gc @@ -39,14 +39,14 @@ This is used to make jak look toward an enemy, for example." (parented-scale? symbol) ) (:methods - (new (symbol type) _type_) - (joint-mod-method-9 () none) - (joint-mod-method-10 () none) - (joint-mod-method-11 () none) + (new (symbol type joint-mod-mode process-drawable int) _type_) + (mode-set! (_type_ joint-mod-mode) none) + (target-set! (_type_ vector) none) + (look-at! (_type_ vector symbol process) none) (reset-blend! (_type_) _type_) - (joint-mod-method-13 () none) - (joint-mod-method-14 () none) - (joint-mod-method-15 () none) + (twist-set! (_type_ float float float) vector) + (trs-set! (_type_ vector quaternion vector) none) + (shut-down (_type_) none) ) ) @@ -143,7 +143,7 @@ This is used to make jak look toward an enemy, for example." ;; WARN: Return type mismatch int vs none. (defun-debug joint-mod-debug-draw ((jmod joint-mod)) "Debug draw the bone transform for the associated bone of a joint-mod" - (add-debug-matrix #t (bucket-id bucket577) (-> jmod joint bone transform) (meters 2)) + (add-debug-matrix #t (bucket-id debug-no-zbuf1) (-> jmod joint bone transform) (meters 2)) 0 (none) ) @@ -847,9 +847,9 @@ Then, apply the normal parented transform." (blend-interp float) ) (:methods - (new (symbol type) _type_) - (joint-mod-ik-method-9 () none) - (joint-mod-ik-method-10 () none) + (new (symbol type process-drawable int float) _type_) + (set-ik-target! (_type_ vector) none) + (enable-set! (_type_ symbol) none) ) ) @@ -901,7 +901,7 @@ Then, apply the normal parented transform." ;; definition of type joint-mod-polar-look-at (deftype joint-mod-polar-look-at (basic) - ((flags uint32) + ((flags joint-mod-polar-flags) (ear int8) (up int8) (nose int8) @@ -914,18 +914,18 @@ Then, apply the normal parented transform." (forward-twist float) (backward-twist float) (target vector :inline) - (blend-duration uint64) - (blend-start-time uint64) + (blend-duration time-frame) + (blend-start-time time-frame) (blend-start-value float) (blend-max float) ) (:methods - (joint-mod-polar-look-at-method-9 () none) - (joint-mod-polar-look-at-method-10 () none) - (joint-mod-polar-look-at-method-11 () none) - (joint-mod-polar-look-at-method-12 () none) - (joint-mod-polar-look-at-method-13 () none) - (joint-mod-polar-look-at-method-14 () none) + (initialize (_type_ process-drawable int) none) + (set-target! (_type_ vector) none) + (set-both-targets! (_type_ joint-mod-polar-look-at vector) none) + (blend-on! (_type_ time-frame float symbol) none) + (blend-to-off! (_type_ time-frame symbol) none) + (get-start-blend! (_type_) float) ) ) @@ -959,7 +959,3 @@ Then, apply the normal parented transform." ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/anim/joint-mod_REF.gc b/test/decompiler/reference/jak3/engine/anim/joint-mod_REF.gc new file mode 100644 index 0000000000..a63957ddae --- /dev/null +++ b/test/decompiler/reference/jak3/engine/anim/joint-mod_REF.gc @@ -0,0 +1,1616 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function joint-mod-ik-callback +;; INFO: Used lq/sq +;; WARN: Return type mismatch matrix vs none. +;; WARN: Function joint-mod-ik-callback has a return type of none, but the expression builder found a return statement. +(defbehavior joint-mod-ik-callback process ((arg0 cspace) (arg1 transformq)) + "Inverse kinematics joint mod callback. + Despite the arm-related names, can be used on legs too." + (local-vars + (sv-352 vector) + (sv-356 vector) + (sv-360 vector) + (sv-364 vector) + (sv-368 quaternion) + (sv-372 quaternion) + (sv-768 matrix) + (sv-784 vector) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (let ((gp-0 (the-as joint-mod-ik (-> arg0 param1)))) + (-> arg0 param2) + (cspace<-parented-transformq-joint! arg0 arg1) + (cond + ((logtest? (-> gp-0 flags) (joint-mod-ik-flags enable)) + (+! (-> gp-0 blend) (* 4.0 (seconds-per-frame))) + (if (< 1.0 (-> gp-0 blend)) + (set! (-> gp-0 blend) 1.0) + ) + ) + (else + (set! (-> gp-0 blend) (- (-> gp-0 blend) (* 4.0 (seconds-per-frame)))) + (if (< (-> gp-0 blend) 0.0) + (set! (-> gp-0 blend) 0.0) + ) + ) + ) + (if (= (-> gp-0 blend) 0.0) + (return #f) + ) + (let ((s5-0 (-> arg0 parent bone transform)) + (s4-1 (-> arg0 bone transform)) + ) + (new 'stack-no-clear 'matrix) + (new 'stack-no-clear 'matrix) + (let ((s3-0 (new 'stack-no-clear 'vector))) + (matrix->trans s5-0 s3-0) + (set! (-> s5-0 trans quad) (-> s3-0 quad)) + (matrix->trans s4-1 s3-0) + (set! (-> s4-1 trans quad) (-> s3-0 quad)) + ) + (let* ((a2-0 (-> gp-0 shoulder-matrix-no-ik)) + (a3-0 s5-0) + (v1-22 (-> a3-0 rvec quad)) + (a0-7 (-> a3-0 uvec quad)) + (a1-3 (-> a3-0 fvec quad)) + (a3-1 (-> a3-0 trans quad)) + ) + (set! (-> a2-0 rvec quad) v1-22) + (set! (-> a2-0 uvec quad) a0-7) + (set! (-> a2-0 fvec quad) a1-3) + (set! (-> a2-0 trans quad) a3-1) + ) + (let* ((a2-1 (-> gp-0 elbow-matrix-no-ik)) + (a3-2 s4-1) + (v1-23 (-> a3-2 rvec quad)) + (a0-8 (-> a3-2 uvec quad)) + (a1-4 (-> a3-2 fvec quad)) + (a3-3 (-> a3-2 trans quad)) + ) + (set! (-> a2-1 rvec quad) v1-23) + (set! (-> a2-1 uvec quad) a0-8) + (set! (-> a2-1 fvec quad) a1-4) + (set! (-> a2-1 trans quad) a3-3) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (set! sv-784 (new 'stack-no-clear 'vector)) + (let ((s0-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + (s3-1 (new 'stack-no-clear 'vector)) + ) + 0.0 + 0.0 + (set! (-> s2-0 quad) (-> s5-0 trans quad)) + (set! (-> sv-784 quad) (-> s4-1 trans quad)) + (let ((a1-5 s0-0)) + (let ((v1-27 sv-784)) + (let ((a0-13 (-> s4-1 uvec))) + (let ((a2-2 (-> gp-0 hand-dist))) + (.mov vf7 a2-2) + ) + (.lvf vf5 (&-> a0-13 quad)) + ) + (.lvf vf4 (&-> v1-27 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf5 vf7 :mask #b111) + (.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111) + (.svf (&-> a1-5 quad) vf6) + ) + (if (-> gp-0 callback) + ((-> gp-0 callback) gp-0 s5-0 s4-1 s0-0) + ) + (set! (-> s1-0 quad) (-> gp-0 handle-pos quad)) + (let ((f30-0 (vector-vector-distance s2-0 sv-784)) + (f0-12 (vector-vector-distance sv-784 s0-0)) + ) + (set! sv-768 (new 'stack-no-clear 'matrix)) + (let ((v1-32 s1-0) + (a0-19 s2-0) + ) + (.lvf vf4 (&-> v1-32 quad)) + (.lvf vf5 (&-> a0-19 quad)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> sv-768 rvec quad) vf6) + (vector-length (the-as vector sv-768)) + (+ -4.096 f0-12 f30-0) + (let ((f0-15 (+ 4.096 (fabs (- f30-0 f0-12))))) + (cond + ((< f0-15 f0-15) + (vector-normalize! (the-as vector sv-768) f0-15) + (let ((v1-39 s1-0)) + (let ((a0-21 s2-0)) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> a0-21 quad)) + ) + (.lvf vf5 (&-> sv-768 rvec quad)) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> v1-39 quad) vf6) + ) + ) + ((< f0-15 f0-15) + (vector-normalize! (the-as vector sv-768) f0-15) + (vector+! s1-0 s2-0 (the-as vector sv-768)) + ) + ) + ) + ) + (set! sv-352 (vector-! (new 'stack-no-clear 'vector) sv-784 s2-0)) + (let ((v1-44 (new 'stack-no-clear 'vector))) + (.lvf vf4 (&-> s0-0 quad)) + (.lvf vf5 (&-> sv-784 quad)) + (.mov.vf vf6 vf0 :mask #b1000) + (.sub.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> v1-44 quad) vf6) + (set! sv-356 v1-44) + ) + (set! sv-360 (vector-! (new 'stack-no-clear 'vector) s0-0 s2-0)) + (set! sv-364 (vector-! (new 'stack-no-clear 'vector) s1-0 s2-0)) + (set! sv-368 (new 'stack-no-clear 'quaternion)) + (set! sv-372 (new 'stack-no-clear 'quaternion)) + (let ((f26-0 (vector-length sv-352)) + (f24-0 (vector-length sv-356)) + (f30-1 (vector-length sv-364)) + ) + (let* ((s2-1 (new 'stack-no-clear 'vector)) + (f28-0 (vector-vector-angle-safe sv-352 sv-356)) + (f0-17 (fmax -1.0 (fmin 1.0 (/ (- (- (* f30-1 f30-1) (* f26-0 f26-0)) (* f24-0 f24-0)) (* 2.0 f24-0 f26-0))))) + (f26-1 (acos f0-17)) + ) + (cond + ((= f28-0 0.0) + (set! (-> s2-1 quad) (-> (&-> s4-1 quad (-> gp-0 elbow-rotation-axis)) 0)) + (when (logtest? (-> gp-0 flags) (joint-mod-ik-flags elbow-rot-neg)) + (vector-negate! s2-1 s2-1) + (set! f26-1 (- f26-1)) + ) + (set! (-> s3-1 quad) (-> (&-> s4-1 quad (-> gp-0 elbow-pole-vector-axis)) 0)) + (if (logtest? (-> gp-0 flags) (joint-mod-ik-flags elbow-trans-neg)) + (vector-negate! s3-1 s3-1) + ) + ) + (else + (vector-cross! s2-1 sv-352 sv-356) + (vector-! + s3-1 + sv-352 + (vector-float*! + (new 'stack-no-clear 'vector) + sv-360 + (/ (vector-dot sv-360 sv-352) (vector-dot sv-360 sv-360)) + ) + ) + ) + ) + (vector-normalize! s3-1 1.0) + (vector-normalize! s2-1 1.0) + (quaternion-vector-angle! sv-368 s2-1 (- f26-1 f28-0)) + ) + (vector-orient-by-quat! sv-356 sv-356 sv-368) + (vector+! sv-360 sv-352 sv-356) + (quaternion-from-two-vectors! + sv-372 + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-360 1.0) + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-364 1.0) + ) + (vector-orient-by-quat! sv-352 sv-352 sv-372) + (let ((f0-25 (fabs (vector-dot + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-352 1.0) + (vector-normalize-copy! (new 'stack-no-clear 'vector) sv-364 1.0) + ) + ) + ) + ) + (if (< 0.98 f0-25) + (vector-orient-by-quat! sv-352 s3-1 sv-372) + ) + ) + (let ((s2-4 (new 'stack-no-clear 'vector)) + (s1-2 (new 'stack-no-clear 'quaternion)) + ) + (new 'stack-no-clear 'matrix) + (* f30-1 f30-1) + (let ((s0-2 (new 'stack-no-clear 'quaternion))) + (vector-flatten! s2-4 sv-352 sv-364) + (vector-flatten! (the-as vector s1-2) s3-1 sv-364) + (vector-normalize! s2-4 1.0) + (vector-normalize! (the-as vector s1-2) 1.0) + (quaternion-from-two-vectors! s0-2 s2-4 (the-as vector s1-2)) + (quaternion*! sv-372 s0-2 sv-372) + ) + ) + ) + ) + ) + (quaternion-pseudo-slerp! sv-368 *unity-quaternion* sv-368 (-> gp-0 blend)) + (quaternion-pseudo-slerp! sv-372 *unity-quaternion* sv-372 (-> gp-0 blend)) + (let ((a2-20 (quaternion->matrix (new 'stack-no-clear 'matrix) sv-368)) + (gp-1 (new 'stack-no-clear 'matrix)) + ) + (set! (-> gp-1 rvec quad) (-> s4-1 trans quad)) + (matrix*! s4-1 s4-1 a2-20) + (set! (-> s4-1 trans quad) (-> gp-1 rvec quad)) + ) + (let ((s3-2 (quaternion->matrix (new 'stack-no-clear 'matrix) sv-372)) + (a2-21 (matrix-4x4-inverse! (new 'stack-no-clear 'matrix) s5-0)) + (gp-2 (new 'stack-no-clear 'matrix)) + ) + (set! (-> gp-2 rvec quad) (-> s5-0 trans quad)) + (matrix*! s4-1 s4-1 a2-21) + (matrix*! s5-0 s5-0 s3-2) + (set! (-> s5-0 trans quad) (-> gp-2 rvec quad)) + ) + (matrix*! s4-1 s4-1 s5-0) + ) + ) + (none) + ) + ) + +;; definition for method 0 of type joint-mod-ik +(defmethod new joint-mod-ik ((allocation symbol) (type-to-make type) (proc process-drawable) (joint-id int) (hand-dist float)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 process) proc) + (set! (-> v0-0 hand-dist) hand-dist) + (set! (-> v0-0 elbow-pole-vector-axis) (the-as uint 0)) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags elbow-trans-neg)) + (set! (-> v0-0 elbow-rotation-axis) (the-as uint 2)) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags elbow-rot-neg)) + (set! (-> v0-0 callback) #f) + (set! (-> v0-0 blend) 0.0) + (logclear! (-> v0-0 flags) (joint-mod-ik-flags enable)) + (let ((a0-5 (-> proc node-list data joint-id))) + (set! (-> a0-5 param0) joint-mod-ik-callback) + (set! (-> a0-5 param1) v0-0) + (set! (-> a0-5 param2) (the-as basic joint-id)) + ) + v0-0 + ) + ) + +;; definition for method 9 of type joint-mod-ik +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod set-ik-target! ((this joint-mod-ik) (pos vector)) + (set! (-> this handle-pos quad) (-> pos quad)) + 0 + (none) + ) + +;; definition for method 10 of type joint-mod-ik +;; WARN: Return type mismatch int vs none. +(defmethod enable-set! ((this joint-mod-ik) (enable symbol)) + (if enable + (logior! (-> this flags) (joint-mod-ik-flags enable)) + (logclear! (-> this flags) (joint-mod-ik-flags enable)) + ) + 0 + (none) + ) + +;; definition for function real-joint-mod-gun-look-at-handler +;; WARN: Return type mismatch int vs none. +(defbehavior real-joint-mod-gun-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback for pointing the gun (implementation)." + (local-vars + (sv-16 joint-mod) + (sv-64 vector) + (sv-96 quaternion) + (sv-160 vector) + (sv-164 vector) + (sv-168 vector) + (sv-172 symbol) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (set! sv-16 (the-as joint-mod (-> arg0 param1))) + (let ((a0-1 (-> arg1 scale))) + (let ((v1-1 (-> arg1 scale)) + (a2-1 (-> sv-16 scale)) + ) + (.lvf vf4 (&-> v1-1 quad)) + (.lvf vf5 (&-> a2-1 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a0-1 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (-> arg0 bone transform))) + (let ((s4-0 (matrix->quat s5-0 (new 'stack-no-clear 'quaternion)))) + (set! sv-64 (matrix->trans s5-0 (new 'stack-no-clear 'vector))) + (quaternion-rotate-y! s4-0 s4-0 (-> sv-16 twist z)) + (set! sv-96 (quaternion-copy! (new 'stack-no-clear 'quaternion) s4-0)) + (when (!= (-> sv-16 flex-blend) 0.0) + (set! sv-160 (vector-y-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (set! sv-164 (vector-z-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (set! sv-168 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> sv-16 target) sv-64) 1.0)) + (set! sv-172 (the-as symbol #f)) + (let* ((f30-0 (vector-y-angle sv-164)) + (a0-13 (vector-flatten! (new 'stack-no-clear 'vector) sv-168 sv-160)) + (f0-2 (vector-y-angle a0-13)) + (f0-3 (deg-diff f30-0 f0-2)) + (f30-1 (* f0-3 (-> sv-16 blend))) + ) + (let ((f28-0 (fmax (fmin f30-1 (-> sv-16 twist-max y)) (- (-> sv-16 twist-max y))))) + (if (or (!= f30-1 f28-0) (= (-> sv-16 blend) 0.0)) + (logclear! (-> sv-16 track-mode) (track-mode lock-on)) + ) + (cond + ((or (< (-> sv-16 ignore-angle) (fabs f0-3)) + (< (-> sv-16 twist-max w) (vector-vector-distance (-> sv-16 target) sv-64)) + ) + (set! f30-1 0.0) + (set! f28-0 0.0) + (set! sv-172 #t) + ) + ((< 5461.3335 (fabs (deg-diff f30-1 f28-0))) + (set! (-> sv-16 blend) 0.0001) + ) + ((< 182.04445 (fabs (deg-diff f30-1 f28-0))) + (logclear! (-> sv-16 track-mode) (track-mode track-x)) + ) + ) + (if (or (and (logtest? (-> sv-16 track-mode) (track-mode track-y)) (= f30-1 f28-0)) + (< (-> sv-16 twist-max y) (fabs (-> sv-16 twist y))) + ) + (set! (-> sv-16 twist y) + (deg-seek (-> sv-16 twist y) f28-0 (* (fabs (deg-diff f28-0 (-> sv-16 twist y))) + (if (logtest? (-> sv-16 track-mode) (track-mode lock-on)) + 1.0 + (-> sv-16 twist-speed-y) + ) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (if (and (< (fabs (deg-diff f30-1 (-> sv-16 twist y))) 728.1778) (and (not sv-172) (!= (-> sv-16 blend) 0.0))) + (logior! (-> sv-16 track-mode) (track-mode lock-on)) + ) + ) + (quaternion-rotate-local-y! sv-96 sv-96 (-> sv-16 twist y)) + (let* ((s3-1 (vector-x-quaternion! (new 'stack-no-clear 'vector) sv-96)) + (f30-2 (vector-x-angle sv-164)) + (s3-2 (vector-flatten! (new 'stack-no-clear 'vector) sv-168 s3-1)) + (f0-24 (vector-x-angle s3-2)) + (f30-3 (fmax + (fmin (* (- (deg-diff f30-2 f0-24)) (-> sv-16 blend)) (-> sv-16 twist-max x)) + (- (-> sv-16 twist-max x)) + ) + ) + ) + (if (or (< (vector-dot s3-2 sv-164) 0.1) + (< (-> sv-16 twist-max z) (vector-vector-distance (-> sv-16 target) sv-64)) + ) + (set! f30-3 0.0) + ) + (if (or (logtest? (-> sv-16 track-mode) (track-mode track-x)) + (< (-> sv-16 twist-max x) (fabs (-> sv-16 twist x))) + ) + (set! (-> sv-16 twist x) + (deg-seek (-> sv-16 twist x) f30-3 (* (fabs (deg-diff f30-3 (-> sv-16 twist x))) + (if (logtest? (-> sv-16 track-mode) (track-mode lock-on)) + 1.0 + (-> sv-16 twist-speed-x) + ) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (quaternion-rotate-x! sv-96 sv-96 (-> sv-16 twist x)) + (quaternion-normalize! (quaternion*! sv-96 sv-96 (-> sv-16 quat))) + ) + (let ((a1-27 (quaternion-slerp! (new 'stack-no-clear 'quaternion) s4-0 sv-96 (-> sv-16 flex-blend)))) + (matrix<-quat s5-0 a1-27) + ) + ) + (let ((f30-4 (-> sv-16 trans x)) + (s4-1 (-> s5-0 uvec)) + (v1-97 (vector<-matrix! (new 'stack-no-clear 'vector) s5-0)) + ) + (let ((f0-43 (- f30-4 (-> v1-97 y)))) + (if (< 614.4 (fabs f0-43)) + (+! (-> sv-16 trans z) (* 8.0 f0-43)) + ) + ) + (+! (-> sv-16 trans z) (* -260.0 (seconds-per-frame) (-> sv-16 trans y))) + (let ((f0-48 (-> sv-16 trans y))) + (+! (-> sv-16 trans y) (* (-> sv-16 trans z) (seconds-per-frame))) + (set! (-> sv-16 trans y) (* 0.95 (-> sv-16 trans y))) + (when (< (* f0-48 (-> sv-16 trans y)) 0.0) + (set! (-> sv-16 trans y) 0.0) + (set! (-> sv-16 trans z) 0.0) + ) + ) + (cond + ((< 409.6 (-> sv-16 trans y)) + (set! (-> sv-16 trans y) 409.6) + (set! (-> sv-16 trans z) 0.0) + ) + ((< (-> sv-16 trans y) -409.6) + (set! (-> sv-16 trans y) -409.6) + (set! (-> sv-16 trans z) 0.0) + ) + ) + (set! (-> sv-16 trans x) (-> v1-97 y)) + (let ((f0-60 (* (-> sv-16 trans y) (-> sv-16 flex-blend)))) + (if (!= f0-60 0.0) + (vector+float*! (-> s5-0 trans) v1-97 s4-1 f0-60) + ) + ) + ) + ) + (if (-> sv-16 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + 0 + (none) + ) + ) + +;; definition for function joint-mod-gun-look-at-handler +(defbehavior joint-mod-gun-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback for pointing the gun (wrapper)." + (real-joint-mod-gun-look-at-handler arg0 arg1) + (none) + ) + +;; definition for function joint-mod-foot-rot-handler +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-foot-rot-handler process ((arg0 cspace) (arg1 transformq)) + "Joint mod callback to pitch the foot to match the ground." + (let ((s5-0 (the-as joint-mod (-> arg0 param1))) + (gp-0 (-> arg0 bone transform)) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s3-0 (-> s5-0 target)) + (s4-0 (-> s5-0 twist-max)) + ) + 1.0 + (when (< 8192.0 (vector-vector-angle-safe s3-0 s4-0)) + (let* ((a1-4 (vector-normalize! (vector-cross! (new 'stack-no-clear 'vector) s3-0 s4-0) 1.0)) + (a2-1 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) a1-4 8192.0)) + ) + (vector-orient-by-quat! s4-0 s3-0 a2-1) + ) + ) + (let* ((f0-4 + (/ (vector-dot s3-0 (-> s5-0 joint bone transform uvec)) (vector-length (-> s5-0 joint bone transform uvec))) + ) + (f30-1 (lerp-scale 0.0 1.0 f0-4 0.85 1.0)) + ) + (vector-deg-slerp (-> s5-0 twist) (-> s5-0 twist) s4-0 0.3) + (set! (-> s4-0 quad) (-> s5-0 twist quad)) + (seek! (-> s5-0 blend) (-> s5-0 flex-blend) (* 4.0 (seconds-per-frame))) + (let ((s3-1 (matrix->scale gp-0 (new 'stack-no-clear 'vector)))) + (let ((s2-0 (matrix->quat gp-0 (new 'stack-no-clear 'quaternion))) + (s0-0 (matrix->trans gp-0 (new 'stack-no-clear 'vector))) + ) + (set! (-> gp-0 uvec quad) (-> s5-0 twist-max quad)) + (vector-cross! (-> gp-0 fvec) (-> gp-0 rvec) (-> gp-0 uvec)) + (vector-cross! (-> gp-0 rvec) (-> gp-0 uvec) (-> gp-0 fvec)) + (set! (-> gp-0 rvec w) 0.0) + (set! (-> gp-0 uvec w) 0.0) + (set! (-> gp-0 fvec w) 0.0) + (let ((s1-0 (matrix->quat gp-0 (new 'stack-no-clear 'quaternion)))) + (let* ((f0-14 (vector-dot s4-0 (vector-! (new 'stack-no-clear 'vector) s0-0 (-> s5-0 trans)))) + (f0-15 (lerp-scale 1.0 0.0 f0-14 819.2 2048.0)) + ) + (seek! (-> s5-0 old-blend) (* (-> s5-0 blend) f0-15 f30-1) (* 15.0 (seconds-per-frame))) + ) + (quaternion-slerp! s1-0 s2-0 s1-0 (-> s5-0 old-blend)) + (matrix<-quat gp-0 s1-0) + ) + ) + (matrix<-scale gp-0 s3-1) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 0 of type joint-mod +(defmethod new joint-mod ((allocation symbol) (type-to-make type) (mode joint-mod-mode) (proc process-drawable) (base-joint-id int)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> gp-0 process) proc) + (set! (-> gp-0 joint) (-> proc node-list data base-joint-id)) + (mode-set! gp-0 mode) + (set-vector! (-> gp-0 twist-max) 8192.0 11832.889 0.0 1.0) + (set! (-> gp-0 twist-speed-x) 0.1) + (set! (-> gp-0 twist-speed-y) 0.1) + (set! (-> gp-0 up) (the-as uint 1)) + (set! (-> gp-0 nose) (the-as uint 2)) + (set! (-> gp-0 ear) (the-as uint 0)) + (set! (-> gp-0 base-joint) (the-as uint base-joint-id)) + (set! (-> gp-0 base-nose) (the-as uint 2)) + (set! (-> gp-0 max-dist) 122880.0) + (set! (-> gp-0 ignore-angle) 65536.0) + (set! (-> gp-0 flex-blend) 1.0) + (set! (-> gp-0 shutting-down?) #f) + (set-vector! (-> gp-0 scale) 1.0 1.0 1.0 1.0) + (set! (-> gp-0 parented-scale?) #f) + (quaternion-identity! (-> gp-0 quat)) + gp-0 + ) + ) + +;; definition for method 9 of type joint-mod +;; WARN: Return type mismatch joint-mod vs none. +(defmethod mode-set! ((this joint-mod) (mode joint-mod-mode)) + "Set the type of joint-mod and install the right callback." + (set! (-> this mode) mode) + (let ((v1-0 (-> this joint))) + (case mode + (((joint-mod-mode flex-blend)) + (set! (-> v1-0 param0) #f) + (set! (-> this blend) 0.0) + (set! (-> this flex-blend) 1.0) + ) + (((joint-mod-mode reset)) + (set! (-> v1-0 param0) #f) + (set! (-> this blend) 0.0) + (set! (-> this shutting-down?) #f) + ) + (((joint-mod-mode look-at)) + (let ((a0-4 v1-0)) + (set! (-> a0-4 param0) joint-mod-look-at-handler) + (set! (-> a0-4 param1) this) + ) + ) + (((joint-mod-mode joint-set*-world)) + (let ((a0-5 v1-0)) + (set! (-> a0-5 param0) joint-mod-gun-look-at-handler) + (set! (-> a0-5 param1) this) + ) + ) + (((joint-mod-mode gun-look-at)) + (set-vector! (-> this twist) 0.0 1.0 0.0 1.0) + (let ((a0-7 v1-0)) + (set! (-> a0-7 param0) + (lambda ((arg0 cspace) (arg1 transformq)) (joint-mod-foot-rot-handler arg0 arg1) (none)) + ) + (set! (-> a0-7 param1) this) + ) + ) + (((joint-mod-mode world-look-at)) + (let ((a0-8 v1-0)) + (set! (-> a0-8 param0) joint-mod-world-look-at-handler) + (set! (-> a0-8 param1) this) + ) + ) + (((joint-mod-mode rotate)) + (let ((a0-9 v1-0)) + (set! (-> a0-9 param0) joint-mod-rotate-handler) + (set! (-> a0-9 param1) this) + ) + (set! (-> this blend) 1.0) + ) + (((joint-mod-mode rotate2)) + (let ((a0-11 v1-0)) + (set! (-> a0-11 param0) joint-mod-rotate-handler) + (set! (-> a0-11 param1) this) + ) + (set! (-> this blend) 1.0) + ) + (((joint-mod-mode joint-set)) + (let ((a0-13 v1-0)) + (set! (-> a0-13 param0) joint-mod-joint-set-handler) + (set! (-> a0-13 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + (((joint-mod-mode foot-rot)) + (let ((a0-16 v1-0)) + (set! (-> a0-16 param0) joint-mod-joint-set-world-handler) + (set! (-> a0-16 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + (set! (-> this flex-blend) 1.0) + ) + (((joint-mod-mode joint-set*)) + (let ((a0-23 v1-0)) + (set! (-> a0-23 param0) joint-mod-joint-set*-handler) + (set! (-> a0-23 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + (((joint-mod-mode polar-look-at)) + (let ((a0-27 v1-0)) + (set! (-> a0-27 param0) joint-mod-joint-set*-world-handler) + (set! (-> a0-27 param1) this) + ) + (vector-reset! (-> this trans)) + (quaternion-identity! (-> this quat)) + (set-vector! (-> this scale) 1.0 1.0 1.0 1.0) + ) + ) + ) + (none) + ) + +;; definition for method 15 of type joint-mod +;; WARN: Return type mismatch joint-mod vs none. +(defmethod shut-down ((this joint-mod)) + "Disable the joint mod, possibly blending out depending on the type" + (set! (-> this shutting-down?) #t) + (set! (-> this blend) 0.0) + (none) + ) + +;; definition for method 13 of type joint-mod +(defmethod twist-set! ((thix joint-mod) (x float) (y float) (z float)) + "Set twist x,y,z. A value of #f will skip the set." + (if x + (set! (-> thix twist x) x) + ) + (if y + (set! (-> thix twist y) y) + ) + (if z + (set! (-> thix twist z) z) + ) + (-> thix twist) + ) + +;; definition for method 14 of type joint-mod +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod trs-set! ((this joint-mod) (trans vector) (quat quaternion) (scale vector)) + "Set translation, quaternion, scale. A value of #f will skip the set." + (if trans + (set! (-> this trans quad) (-> trans quad)) + ) + (if quat + (quaternion-copy! (-> this quat) quat) + ) + (if scale + (set! (-> this scale quad) (-> scale quad)) + ) + 0 + (none) + ) + +;; definition for method 10 of type joint-mod +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod target-set! ((this joint-mod) (pos vector)) + "Set the target position for look-at mode." + (if (= (-> this mode) (joint-mod-mode reset)) + (mode-set! this (joint-mod-mode look-at)) + ) + (let ((f0-0 (vector-vector-distance (-> this process root trans) pos))) + (set! (-> this shutting-down?) #f) + (set! (-> this target quad) (-> pos quad)) + (if (< f0-0 (-> this max-dist)) + (set! (-> this blend) 1.0) + (set! (-> this blend) 0.0) + ) + ) + 0 + (none) + ) + +;; definition for symbol last-try-to-look-at-data, type try-to-look-at-info +(define last-try-to-look-at-data (new 'global 'try-to-look-at-info)) + +;; definition for method 11 of type joint-mod +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod look-at! ((this joint-mod) (target vector) (mode symbol) (proc process)) + "Activate joint mod to look at the process." + (when (= mode 'attacking) + (let* ((s2-0 proc) + (s1-0 (if (type? s2-0 process-drawable) + (the-as process-drawable s2-0) + ) + ) + ) + (when s1-0 + (let* ((s0-0 (-> s1-0 fact)) + (s2-1 (if (type? s0-0 fact-info-enemy) + (the-as fact-info-enemy s0-0) + ) + ) + ) + (when s2-1 + (when (< (vector-vector-distance (-> this process root trans) (-> s1-0 root trans)) (-> s2-1 cam-notice-dist)) + (set-time! (-> this notice-time)) + (set! (-> last-try-to-look-at-data who) (process->handle proc)) + (if (< (-> last-try-to-look-at-data vert) (-> s2-1 cam-vert)) + (set! (-> last-try-to-look-at-data vert) (-> s2-1 cam-vert)) + ) + (if (< (-> last-try-to-look-at-data horz) (-> s2-1 cam-horz)) + (set! (-> last-try-to-look-at-data horz) (-> s2-1 cam-horz)) + ) + ) + ) + ) + ) + ) + ) + (let ((f30-0 (vector-vector-distance (-> this process root trans) target))) + (if (logtest? (process-mask enemy) (-> proc mask)) + (+! (-> this look-at-count) (the int (lerp-scale 256.0 0.0 f30-0 20480.0 204800.0))) + ) + (when (and (or (= (-> this blend) 0.0) + (or (< f30-0 (vector-vector-distance (-> this process root trans) (-> this target))) (= mode 'force)) + ) + (< f30-0 (-> this max-dist)) + ) + (if (= (-> this mode) (joint-mod-mode reset)) + (mode-set! this (joint-mod-mode look-at)) + ) + (set! (-> this target quad) (-> target quad)) + (set! (-> this blend) 1.0) + (set! (-> this shutting-down?) #f) + ) + ) + 0 + (none) + ) + +;; definition for function joint-mod-look-at-handler +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-look-at-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for look-at joint mod." + (local-vars + (sv-144 matrix) + (sv-148 quaternion) + (sv-152 vector) + (sv-156 vector) + (sv-160 (pointer uint128)) + (sv-164 symbol) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((gp-0 (the-as joint-mod (-> arg0 param1)))) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s3-0 (-> arg0 bone transform))) + (set! sv-144 (new 'stack-no-clear 'matrix)) + (set! sv-148 (new 'stack-no-clear 'quaternion)) + (set! sv-152 (new 'stack-no-clear 'vector)) + (set! sv-156 (new 'stack-no-clear 'vector)) + (set! sv-160 + (&-> (-> gp-0 process node-list data (-> gp-0 base-joint) bone) transform quad (-> gp-0 base-nose)) + ) + (set! sv-164 + (< (vector-dot (-> s3-0 rvec) (vector-cross! (new 'stack-no-clear 'vector) (-> s3-0 uvec) (-> s3-0 fvec))) + 0.0 + ) + ) + (vector-normalize-copy! (-> sv-144 rvec) (the-as vector (&-> s3-0 quad (-> gp-0 ear))) (if sv-164 + -1.0 + 1.0 + ) + ) + (vector-normalize-copy! (-> sv-144 uvec) (the-as vector (&-> s3-0 quad (-> gp-0 up))) 1.0) + (vector-normalize-copy! (-> sv-144 fvec) (the-as vector (&-> s3-0 quad (-> gp-0 nose))) 1.0) + ) + (vector-reset! (-> sv-144 trans)) + (matrix->quaternion sv-148 sv-144) + (vector-normalize! (vector-! sv-152 (-> gp-0 target) (-> arg0 bone transform trans)) 1.0) + (vector-inv-orient-by-quat! sv-156 sv-152 sv-148) + (let ((f30-0 (vector-y-angle sv-156)) + (f0-2 (if (= (-> gp-0 base-joint) (+ (-> arg0 joint number) 1)) + 0.0 + (deg-diff (vector-y-angle (-> sv-144 fvec)) (vector-y-angle (the-as vector sv-160))) + ) + ) + ) + (if (< (-> gp-0 ignore-angle) (fabs f30-0)) + (set! f30-0 0.0) + ) + (let ((f30-1 + (fmax + (fmin (* f30-0 (-> gp-0 blend) (-> gp-0 flex-blend)) (+ (-> gp-0 twist-max y) (* f0-2 (-> gp-0 flex-blend)))) + (+ (- (-> gp-0 twist-max y)) (* f0-2 (-> gp-0 flex-blend))) + ) + ) + ) + (when (and (-> gp-0 shutting-down?) (< (fabs (- (-> gp-0 twist y) f30-1)) 18.204445)) + (if (and (= (-> gp-0 scale x) 1.0) (= (-> gp-0 scale y) 1.0) (= (-> gp-0 scale z) 1.0)) + (mode-set! gp-0 (joint-mod-mode reset)) + (mode-set! gp-0 (joint-mod-mode rotate2)) + ) + ) + (set! (-> gp-0 twist y) + (deg-seek + (-> gp-0 twist y) + f30-1 + (* (fabs (deg-diff f30-1 (-> gp-0 twist y))) (-> gp-0 twist-speed-y) (-> self clock time-adjust-ratio)) + ) + ) + ) + ) + (let ((f0-21 (if sv-164 + (- (-> gp-0 twist y)) + (-> gp-0 twist y) + ) + ) + (a1-18 (new-stack-vector0)) + ) + (set! (-> a1-18 data (-> gp-0 up)) 1.0) + (let ((a2-7 (quaternion-vector-angle! (new-stack-quaternion0) a1-18 f0-21))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) a2-7)) + ) + ) + (let ((f0-27 + (fmax + (fmin (* (- (vector-x-angle sv-156)) (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max x)) + (- (-> gp-0 twist-max x)) + ) + ) + ) + (if (< (vector-dot sv-156 *z-vector*) 0.1) + (set! f0-27 0.0) + ) + (set! (-> gp-0 twist x) + (deg-seek + (-> gp-0 twist x) + f0-27 + (* (fabs (deg-diff f0-27 (-> gp-0 twist x))) (-> gp-0 twist-speed-x) (-> self clock time-adjust-ratio)) + ) + ) + ) + (let ((a1-22 (new-stack-vector0))) + (set! (-> a1-22 data (-> gp-0 ear)) 1.0) + (let ((a2-10 (quaternion-vector-angle! (new-stack-quaternion0) a1-22 (-> gp-0 twist x)))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) a2-10)) + ) + ) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> gp-0 trans)) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) (-> gp-0 quat))) + (let ((a1-27 (-> arg1 scale))) + (let ((v1-71 (-> arg1 scale)) + (a0-36 (-> gp-0 scale)) + ) + (.lvf vf4 (&-> v1-71 quad)) + (.lvf vf5 (&-> a0-36 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-27 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> gp-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) + (add-debug-text-sphere + *display-target-marks* + (bucket-id debug-no-zbuf1) + (-> gp-0 target) + (meters 0.2) + "look" + (new 'static 'rgba :r #xff :g #xff :a #x80) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for function joint-mod-world-look-at-handler +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-world-look-at-handler process ((arg0 cspace) (arg1 transformq)) + (local-vars (sv-48 vector) (sv-52 vector) (sv-56 vector)) + (let ((gp-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s5-0 (-> arg0 bone transform))) + (cspace<-parented-transformq-joint! arg0 arg1) + (set! sv-48 (vector-normalize-copy! + (new 'stack-no-clear 'vector) + (-> gp-0 process node-list data 0 bone transform uvec) + 1.0 + ) + ) + (set! sv-52 (vector-normalize! (the-as vector (&-> s5-0 quad (-> gp-0 nose))) 1.0)) + (set! sv-56 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> gp-0 target) (-> s5-0 trans)) 1.0)) + (let* ((f30-0 (vector-y-angle sv-52)) + (a0-7 (vector-flatten! (new-stack-vector0) sv-56 sv-48)) + (f0-0 (vector-y-angle a0-7)) + (f0-1 (deg-diff f30-0 f0-0)) + ) + (if (< (-> gp-0 ignore-angle) (fabs f0-1)) + (set! f0-1 0.0) + ) + (let ((f0-5 + (fmax (fmin (* f0-1 (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max y)) (- (-> gp-0 twist-max y))) + ) + ) + (set! (-> gp-0 twist y) (deg-seek + (-> gp-0 twist y) + f0-5 + (* (fmax 1.0 (* (fabs (deg-diff f0-5 (-> gp-0 twist y))) (-> gp-0 twist-speed-y))) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + ) + (when (!= (-> gp-0 twist y) 0.0) + (let ((a2-3 (matrix-rotate-y! (new 'stack-no-clear 'matrix) (-> gp-0 twist y))) + (s4-2 (-> s5-0 trans quad)) + ) + (matrix*! s5-0 s5-0 a2-3) + (set! (-> s5-0 trans quad) s4-2) + ) + ) + (let* ((s4-3 (vector-normalize-copy! + (new 'stack-no-clear 'vector) + (the-as vector (-> gp-0 process node-list data 0 bone transform)) + 1.0 + ) + ) + (f30-2 (vector-x-angle sv-52)) + (s4-4 (vector-flatten! (new-stack-vector0) sv-56 s4-3)) + (f0-15 (vector-x-angle s4-4)) + (f0-21 (fmax + (fmin (* (- (deg-diff f30-2 f0-15)) (-> gp-0 blend) (-> gp-0 flex-blend)) (-> gp-0 twist-max x)) + (- (-> gp-0 twist-max x)) + ) + ) + ) + (if (< (vector-dot s4-4 sv-52) 0.1) + (set! f0-21 0.0) + ) + (set! (-> gp-0 twist x) (deg-seek + (-> gp-0 twist x) + f0-21 + (* (fmax 1.0 (* (fabs (deg-diff f0-21 (-> gp-0 twist x))) (-> gp-0 twist-speed-x))) + (-> self clock time-adjust-ratio) + ) + ) + ) + ) + (when (!= (-> gp-0 twist x) 0.0) + (let* ((v1-25 (-> gp-0 ear)) + (a1-17 ((cond + ((zero? v1-25) + matrix-rotate-x! + ) + ((= v1-25 1) + matrix-rotate-y! + ) + (else + matrix-rotate-z! + ) + ) + (new 'stack-no-clear 'matrix) + (-> gp-0 twist x) + ) + ) + ) + (matrix*! s5-0 a1-17 s5-0) + ) + ) + ) + (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) + (add-debug-text-sphere + *display-target-marks* + (bucket-id debug-no-zbuf1) + (-> gp-0 target) + (meters 0.2) + "look" + (new 'static 'rgba :r #xff :g #xff :a #x80) + ) + ) + ) + 0 + (none) + ) + +;; definition for function joint-mod-rotate-handler +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-rotate-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for rotate joint mod." + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s3-0 (new 'static 'inline-array vector 3 + (new 'static 'vector :x 1.0 :w 1.0) + (new 'static 'vector :y 1.0 :w 1.0) + (new 'static 'vector :z 1.0 :w 1.0) + ) + ) + ) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-trans))) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> s5-0 trans)) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-rotate))) + (let* ((v1-9 (-> s3-0 (-> s5-0 ear))) + (a1-4 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-9 x) + (-> v1-9 y) + (-> v1-9 z) + (* (-> s5-0 twist x) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-4 (-> arg1 quat))) + ) + (let* ((v1-13 (-> s3-0 (-> s5-0 up))) + (a1-6 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-13 x) + (-> v1-13 y) + (-> v1-13 z) + (* (-> s5-0 twist y) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-6 (-> arg1 quat))) + ) + (let* ((v1-17 (-> s3-0 (-> s5-0 nose))) + (a1-8 (quaternion-axis-angle! + (new 'stack-no-clear 'quaternion) + (-> v1-17 x) + (-> v1-17 y) + (-> v1-17 z) + (* (-> s5-0 twist z) (-> s5-0 blend) (-> s5-0 flex-blend)) + ) + ) + ) + (quaternion-normalize! (quaternion*! (-> arg1 quat) a1-8 (-> arg1 quat))) + ) + ) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-scale))) + (let ((a1-9 (-> arg1 scale))) + (let ((v1-22 (-> arg1 scale)) + (a0-11 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-22 quad)) + (.lvf vf5 (&-> a0-11 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-9 quad) vf6) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +;; definition for function joint-mod-scale-handler +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-scale-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for scale joint mod." + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((a2-0 (-> arg1 scale))) + (let ((v1-0 (-> arg1 scale)) + (a0-1 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-0 quad)) + (.lvf vf5 (&-> a0-1 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a2-0 quad) vf6) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +;; definition for function joint-mod-joint-set-handler +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-joint-set-handler process ((arg0 cspace) (arg1 transformq)) + "Callback for set joint mod." + (let ((s4-0 (the-as joint-mod (-> arg0 param1)))) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-trans))) + (set! (-> arg1 trans quad) (-> s4-0 trans quad)) + ) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-rotate))) + (quaternion-copy! (-> arg1 quat) (-> s4-0 quat)) + ) + (if (not (logtest? (-> s4-0 track-mode) (track-mode no-scale))) + (set! (-> arg1 scale quad) (-> s4-0 scale quad)) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + 0 + (none) + ) + +;; definition for function joint-mod-joint-set-world-handler +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +;; WARN: Function joint-mod-joint-set-world-handler has a return type of none, but the expression builder found a return statement. +(defbehavior joint-mod-joint-set-world-handler process ((arg0 cspace) (arg1 transformq)) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (the-as joint-mod (-> arg0 param1))) + (s4-0 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector))) + ) + (let ((s3-0 (new 'stack-no-clear 'vector))) + (if (>= 0.0 (-> s5-0 flex-blend)) + (return #f) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-scale)) + (set! (-> s3-0 quad) (-> arg1 scale quad)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (set! (-> s3-0 quad) (-> s5-0 scale quad)) + ) + (else + (vector-lerp! s3-0 (-> arg1 scale) (-> s5-0 scale) (-> s5-0 flex-blend)) + ) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-rotate)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (quaternion->matrix (-> arg0 bone transform) (-> s5-0 quat)) + ) + (else + (let ((v1-15 (new 'stack-no-clear 'vector))) + (set! (-> v1-15 quad) (-> arg1 scale quad)) + (set! (-> v1-15 x) (/ 1.0 (-> v1-15 x))) + (set! (-> v1-15 y) (/ 1.0 (-> v1-15 y))) + (set! (-> v1-15 z) (/ 1.0 (-> v1-15 z))) + (vector-float*! + (the-as vector (-> arg0 bone transform)) + (the-as vector (-> arg0 bone transform)) + (-> v1-15 x) + ) + (vector-float*! (-> arg0 bone transform uvec) (-> arg0 bone transform uvec) (-> v1-15 y)) + (vector-float*! (-> arg0 bone transform fvec) (-> arg0 bone transform fvec) (-> v1-15 z)) + ) + (let ((a1-12 (matrix->quaternion (new 'stack-no-clear 'quaternion) (-> arg0 bone transform)))) + (quaternion->matrix + (-> arg0 bone transform) + (quaternion-slerp! (new 'stack-no-clear 'quaternion) a1-12 (-> s5-0 quat) (-> s5-0 flex-blend)) + ) + ) + ) + ) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-rotate)) + (vector-normalize! (the-as vector (-> arg0 bone transform)) (-> s3-0 x)) + (vector-normalize! (-> arg0 bone transform uvec) (-> s3-0 y)) + (vector-normalize! (-> arg0 bone transform fvec) (-> s3-0 z)) + ) + (else + (vector-float*! (the-as vector (-> arg0 bone transform)) (the-as vector (-> arg0 bone transform)) (-> s3-0 x)) + (vector-float*! (-> arg0 bone transform uvec) (-> arg0 bone transform uvec) (-> s3-0 y)) + (vector-float*! (-> arg0 bone transform fvec) (-> arg0 bone transform fvec) (-> s3-0 z)) + ) + ) + ) + (set! (-> arg0 bone transform rvec w) 0.0) + (set! (-> arg0 bone transform uvec w) 0.0) + (set! (-> arg0 bone transform fvec w) 0.0) + (cond + ((logtest? (-> s5-0 track-mode) (track-mode no-trans)) + (set! (-> arg0 bone transform trans quad) (-> s4-0 quad)) + ) + ((>= (-> s5-0 flex-blend) 1.0) + (set! (-> arg0 bone transform trans quad) (-> s5-0 trans quad)) + (set! (-> arg0 bone transform trans w) 1.0) + ) + (else + (vector-lerp! (-> arg0 bone transform trans) s4-0 (-> s5-0 trans) (-> s5-0 flex-blend)) + (set! (-> arg0 bone transform trans w) 1.0) + ) + ) + ) + 0 + (none) + ) + +;; definition for function joint-mod-joint-set*-handler +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-joint-set*-handler process ((arg0 cspace) (arg1 transformq)) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-trans))) + (vector+! (-> arg1 trans) (-> arg1 trans) (-> s5-0 trans)) + ) + (if (not (logtest? (-> s5-0 track-mode) (track-mode no-rotate))) + (quaternion-normalize! (quaternion*! (-> arg1 quat) (-> arg1 quat) (-> s5-0 quat))) + ) + (when (not (logtest? (-> s5-0 track-mode) (track-mode no-scale))) + (let ((a1-4 (-> arg1 scale))) + (let ((v1-11 (-> arg1 scale)) + (a0-4 (-> s5-0 scale)) + ) + (.lvf vf4 (&-> v1-11 quad)) + (.lvf vf5 (&-> a0-4 quad)) + ) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + ) + +;; definition for function joint-mod-joint-set*-world-handler +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-joint-set*-world-handler process ((arg0 cspace) (arg1 transformq)) + (cspace<-parented-transformq-joint! arg0 arg1) + (let ((s5-0 (the-as joint-mod (-> arg0 param1)))) + (let ((s3-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> s5-0 quat))) + (s4-0 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector))) + ) + (vector-reset! (-> arg0 bone transform trans)) + (set! (-> arg0 bone transform trans w) 1.0) + (vector-float*! (-> s3-0 rvec) (-> s3-0 rvec) (-> s5-0 scale x)) + (vector-float*! (-> s3-0 uvec) (-> s3-0 uvec) (-> s5-0 scale y)) + (vector-float*! (-> s3-0 fvec) (-> s3-0 fvec) (-> s5-0 scale z)) + (set! (-> s3-0 rvec w) 0.0) + (set! (-> s3-0 uvec w) 0.0) + (set! (-> s3-0 fvec w) 0.0) + (matrix*! (-> arg0 bone transform) (-> arg0 bone transform) s3-0) + (vector+! (-> arg0 bone transform trans) s4-0 (-> s5-0 trans)) + ) + (if (-> s5-0 parented-scale?) + (set-vector! (-> arg0 bone scale) 1.0 1.0 1.0 1.0) + ) + ) + 0 + (none) + ) + +;; definition for method 9 of type joint-mod-polar-look-at +;; WARN: Return type mismatch float vs none. +(defmethod initialize ((this joint-mod-polar-look-at) (proc process-drawable) (joint-id int)) + "Attach joint-mod to process and set defaults." + (let ((a1-2 (-> proc node-list data joint-id))) + (set! (-> a1-2 param0) joint-mod-polar-look-at-callback) + (set! (-> a1-2 param1) this) + ) + (set! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + (set! (-> this up) 1) + (set! (-> this nose) 2) + (set! (-> this ear) 0) + (set! (-> this polar-internal-tilt-max) 32768.0) + (set! (-> this polar-internal-radius) 32768.0) + (set! (-> this polar-external-tilt-max) 32768.0) + (set! (-> this polar-external-radius) 32768.0) + (set! (-> this upward-tilt) 16384.0) + (set! (-> this downward-tilt) 16384.0) + (set! (-> this forward-twist) 16384.0) + (set! (-> this backward-twist) 16384.0) + (set! (-> this blend-duration) 0) + (set! (-> this blend-start-value) 0.0) + (set! (-> this blend-max) 1.0) + (none) + ) + +;; definition for method 11 of type joint-mod-polar-look-at +;; WARN: Return type mismatch float vs none. +(defmethod set-both-targets! ((this joint-mod-polar-look-at) (other joint-mod-polar-look-at) (pos vector)) + "Update the target position of this mod, and a second one." + (when (nonzero? this) + (set-target! this pos) + (when (nonzero? other) + (set! (-> this polar-external-tilt-max) (-> other polar-internal-tilt-max)) + (set! (-> this polar-external-radius) (-> other polar-internal-radius)) + ) + ) + (when (nonzero? other) + (set-target! other pos) + (when (nonzero? this) + (set! (-> other polar-external-tilt-max) (-> this polar-internal-tilt-max)) + (set! (-> other polar-external-radius) (-> this polar-internal-radius)) + ) + ) + (none) + ) + +;; definition for method 10 of type joint-mod-polar-look-at +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod set-target! ((this joint-mod-polar-look-at) (pos vector)) + "Update the target position." + (set! (-> this target quad) (-> pos quad)) + 0 + (none) + ) + +;; definition for method 12 of type joint-mod-polar-look-at +;; WARN: Return type mismatch int vs none. +(defmethod blend-on! ((this joint-mod-polar-look-at) (duration time-frame) (final-val float) (restart-if-in-progress symbol)) + "Start blending this joint mod on." + (cond + ((and (not restart-if-in-progress) (not (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero)))) + ) + ((zero? duration) + (set! (-> this blend-start-value) final-val) + (set! (-> this blend-max) final-val) + (set! (-> this blend-duration) duration) + (logclear! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (else + (set-time! (-> this blend-start-time)) + (set! (-> this blend-start-value) (get-start-blend! this)) + (set! (-> this blend-max) final-val) + (set! (-> this blend-duration) duration) + (logclear! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + ) + 0 + (none) + ) + +;; definition for method 13 of type joint-mod-polar-look-at +;; WARN: Return type mismatch int vs none. +(defmethod blend-to-off! ((this joint-mod-polar-look-at) (duration time-frame) (restart-if-in-progress symbol)) + "Start blending to disable this joint mod." + (cond + ((and (not restart-if-in-progress) (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero))) + ) + ((zero? duration) + (set! (-> this blend-start-value) 0.0) + (set! (-> this blend-duration) duration) + (logior! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (else + (set-time! (-> this blend-start-time)) + (set! (-> this blend-start-value) (get-start-blend! this)) + (set! (-> this blend-duration) duration) + (logior! (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + ) + 0 + (none) + ) + +;; definition for method 14 of type joint-mod-polar-look-at +(defmethod get-start-blend! ((this joint-mod-polar-look-at)) + "Determine what blend to use when starting a new one." + (local-vars (f0-2 float)) + (cond + ((zero? (-> this blend-duration)) + (-> this blend-start-value) + ) + ((begin + (set! f0-2 (the float (- (current-time) (-> this blend-start-time)))) + (logtest? (-> this flags) (joint-mod-polar-flags blending-to-zero)) + ) + (let ((f0-5 (lerp-scale (-> this blend-start-value) 0.0 f0-2 0.0 (the float (-> this blend-duration))))) + (when (= f0-5 0.0) + (set! (-> this blend-start-value) f0-5) + (set! (-> this blend-duration) 0) + 0 + ) + f0-5 + ) + ) + (else + (let ((f0-8 + (lerp-scale (-> this blend-start-value) (-> this blend-max) f0-2 0.0 (the float (-> this blend-duration))) + ) + ) + (when (>= f0-8 (-> this blend-max)) + (set! (-> this blend-start-value) f0-8) + (set! (-> this blend-duration) 0) + 0 + ) + f0-8 + ) + ) + ) + ) + +;; definition for function joint-mod-polar-look-at-callback +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defbehavior joint-mod-polar-look-at-callback process ((arg0 cspace) (arg1 transformq)) + (let* ((s5-0 (the-as joint-mod-polar-look-at (-> arg0 param1))) + (f30-0 (get-start-blend! s5-0)) + ) + (cspace<-parented-transformq-joint! arg0 arg1) + (when (< 0.0 f30-0) + (let* ((t9-2 vector-normalize-copy!) + (a0-3 (new 'stack-no-clear 'vector)) + (v1-3 (abs (-> s5-0 nose))) + (s3-0 (t9-2 a0-3 (the-as vector (&-> (-> arg0 bone) transform quad v1-3)) 1.0)) + (s1-0 (vector-normalize! + (vector-! (new 'stack-no-clear 'vector) (-> s5-0 target) (-> arg0 bone transform trans)) + 1.0 + ) + ) + (s4-1 (new 'stack-no-clear 'matrix)) + ) + (let ((s2-0 (new 'stack-no-clear 'vector))) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-nose)) + (vector-negate! s3-0 s3-0) + ) + (let ((t9-5 vector-normalize-copy!) + (a0-7 (-> s4-1 rvec)) + (v1-11 (abs (-> s5-0 ear))) + ) + (t9-5 a0-7 (the-as vector (&-> (-> arg0 bone) transform quad v1-11)) 1.0) + ) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-ear)) + (vector-negate! (-> s4-1 rvec) (-> s4-1 rvec)) + ) + (let ((t9-7 vector-normalize-copy!) + (a0-9 (-> s4-1 uvec)) + (v1-18 (abs (-> s5-0 up))) + ) + (t9-7 a0-9 (the-as vector (&-> (-> arg0 bone) transform quad v1-18)) 1.0) + ) + (if (logtest? (-> s5-0 flags) (joint-mod-polar-flags negate-up)) + (vector-negate! (-> s4-1 uvec) (-> s4-1 uvec)) + ) + (set! (-> s4-1 fvec quad) (-> s3-0 quad)) + (set-vector! (-> s4-1 trans) 0.0 0.0 0.0 1.0) + (matrix-transpose! s4-1 s4-1) + (set-vector! (-> s4-1 trans) 0.0 0.0 0.0 1.0) + (vector-matrix*! s2-0 s1-0 s4-1) + (let* ((t9-11 asin) + (f0-9 (-> s2-0 x)) + (f0-11 (* f0-9 f0-9)) + (f1-0 (-> s2-0 y)) + (f26-0 (t9-11 (sqrtf (+ f0-11 (* f1-0 f1-0))))) + (f28-0 (atan (-> s2-0 y) (-> s2-0 x))) + ) + (if (< (-> s2-0 z) 0.0) + (set! f26-0 (- 32768.0 f26-0)) + ) + (set! (-> s5-0 polar-internal-radius) f26-0) + (cond + ((< 16384.0 f28-0) + (set! (-> s5-0 polar-internal-tilt-max) (- 32768.0 f28-0)) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< 0.0 (-> s5-0 polar-external-tilt-max))) + (set! f28-0 (fmax f28-0 (- 32768.0 (-> s5-0 polar-external-tilt-max)))) + ) + ) + ((< f28-0 -16384.0) + (set! (-> s5-0 polar-internal-tilt-max) (- -32768.0 f28-0)) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< (-> s5-0 polar-external-tilt-max) 0.0)) + (set! f28-0 (fmin f28-0 (- -32768.0 (-> s5-0 polar-external-tilt-max)))) + ) + ) + ((< 0.0 f28-0) + (set! (-> s5-0 polar-internal-tilt-max) f28-0) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< 0.0 (-> s5-0 polar-external-tilt-max))) + (set! f28-0 (fmin f28-0 (-> s5-0 polar-external-tilt-max))) + ) + ) + (else + (set! (-> s5-0 polar-internal-tilt-max) f28-0) + (if (and (< (-> s5-0 polar-external-radius) f26-0) (< (-> s5-0 polar-external-tilt-max) 0.0)) + (set! f28-0 (fmax f28-0 (-> s5-0 polar-external-tilt-max))) + ) + ) + ) + (let* ((f0-39 (sin f28-0)) + (f24-0 (* f0-39 f0-39)) + (f0-41 (cos f28-0)) + (f0-43 (* f0-41 f0-41)) + ) + 32768.0 + (let ((f0-45 (cond + ((< 16384.0 f28-0) + (+ (* f24-0 (-> s5-0 upward-tilt)) (* f0-43 (-> s5-0 backward-twist))) + ) + ((< f28-0 -16384.0) + (+ (* f24-0 (-> s5-0 downward-tilt)) (* f0-43 (-> s5-0 backward-twist))) + ) + ((< 0.0 f28-0) + (+ (* f24-0 (-> s5-0 upward-tilt)) (* f0-43 (-> s5-0 forward-twist))) + ) + (else + (+ (* f24-0 (-> s5-0 downward-tilt)) (* f0-43 (-> s5-0 forward-twist))) + ) + ) + ) + ) + (if (< f0-45 f26-0) + (set! f26-0 f0-45) + ) + ) + ) + (let ((f26-1 (cos f26-0))) + (set-vector! s2-0 (cos f28-0) (sin f28-0) 0.0 1.0) + (let ((t9-18 vector-normalize!) + (a0-24 s2-0) + (f0-53 1.0) + (f1-22 f26-1) + ) + (t9-18 a0-24 (sqrtf (- f0-53 (* f1-22 f1-22)))) + ) + (set! (-> s2-0 z) f26-1) + ) + ) + (matrix-transpose! s4-1 s4-1) + (vector-matrix*! s2-0 s2-0 s4-1) + (if (< f30-0 1.0) + (matrix-from-two-vectors-partial-linear! s4-1 s3-0 s2-0 f30-0) + (matrix-from-two-vectors! s4-1 s3-0 s2-0) + ) + ) + (let ((s3-1 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector)))) + (set-vector! (-> arg0 bone transform trans) 0.0 0.0 0.0 1.0) + (matrix*! (-> arg0 bone transform) (-> arg0 bone transform) s4-1) + (when (logtest? (-> s5-0 flags) (joint-mod-polar-flags no-z-rot)) + (let ((a1-25 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> arg0 bone transform uvec) -1.0))) + (matrix-remove-z-rot (-> arg0 bone transform) a1-25) + ) + ) + (set! (-> arg0 bone transform trans quad) (-> s3-1 quad)) + ) + ) + ) + ) + 0 + (none) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/draw/drawable-actor-h_REF.gc b/test/decompiler/reference/jak3/engine/draw/drawable-actor-h_REF.gc index 910a5838b4..89dbf42ab3 100644 --- a/test/decompiler/reference/jak3/engine/draw/drawable-actor-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/draw/drawable-actor-h_REF.gc @@ -40,11 +40,9 @@ for the entity/birth system." ;; definition for method 10 of type drawable-tree-actor ;; WARN: Return type mismatch int vs none. -(defmethod draw ((this drawable-tree-actor) (arg0 drawable-tree-actor) (arg1 display-frame)) +(defmethod draw ((this drawable-tree-actor)) + "Draw the drawable, and typically its children. + This usually means adding stuff to a list to be drawn later, rather than expensive drawing here." 0 (none) ) - - - - diff --git a/test/decompiler/reference/jak3/engine/draw/drawable-h_REF.gc b/test/decompiler/reference/jak3/engine/draw/drawable-h_REF.gc index 62c327c7b0..c596047618 100644 --- a/test/decompiler/reference/jak3/engine/draw/drawable-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/draw/drawable-h_REF.gc @@ -14,13 +14,13 @@ control over memory layout for use with DMA." ) (:methods (login (_type_) _type_) - (draw (_type_ _type_ display-frame) none) + (draw (_type_) none) (drawable-method-11 () none) (drawable-method-12 () none) - (drawable-method-13 () none) - (drawable-method-14 () none) + (collect-stats (_type_) none) + (debug-draw (_type_) none) (drawable-method-15 () none) - (drawable-method-16 () none) + (collect-regions (_type_ sphere int region-prim-list) none) ) ) diff --git a/test/decompiler/reference/jak3/engine/gfx/background/subdivide_REF.gc b/test/decompiler/reference/jak3/engine/gfx/background/subdivide_REF.gc new file mode 100644 index 0000000000..c66f88a689 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/gfx/background/subdivide_REF.gc @@ -0,0 +1,419 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for symbol *merc-global-stats*, type merc-global-stats +(define *merc-global-stats* (new 'global 'merc-global-stats)) + +;; definition for function clear-tr-stat +;; WARN: Return type mismatch int vs none. +(defun clear-tr-stat ((arg0 tr-stat)) + "Reset all statistics to 0." + (set! (-> arg0 groups) (the-as uint 0)) + (set! (-> arg0 fragments) (the-as uint 0)) + (set! (-> arg0 tris) (the-as uint 0)) + (set! (-> arg0 dverts) (the-as uint 0)) + (set! (-> arg0 instances) (the-as uint 0)) + 0 + (none) + ) + +;; definition for symbol *stat-string-tfrag*, type string +(define *stat-string-tfrag* (new 'global 'string 128 (the-as string #f))) + +;; definition for symbol *stat-string-tfrag-scissor*, type string +(define *stat-string-tfrag-scissor* (new 'global 'string 128 (the-as string #f))) + +;; definition for symbol *stat-string-total*, type string +(define *stat-string-total* (new 'global 'string 128 (the-as string #f))) + +;; definition (debug) for function print-tr-stat +;; WARN: Return type mismatch uint vs none. +(defun-debug print-tr-stat ((arg0 tr-stat) (arg1 string) (arg2 string)) + "Print a single tr-stat to the screen." + (clear arg2) + (when (nonzero? (+ (-> arg0 groups) (-> arg0 fragments) (-> arg0 tris) (-> arg0 dverts) (-> arg0 instances))) + (format arg2 "~0k~4d ~5d ~6d ~6d" (-> arg0 groups) (-> arg0 fragments) (-> arg0 tris) (-> arg0 dverts)) + (format + arg2 + "~0k ~7f ~5d ~s" + (/ (* 2.0 (the float (-> arg0 tris))) (the float (- (-> arg0 dverts) (-> arg0 tris)))) + (-> arg0 instances) + arg1 + ) + (format *stdcon* "~S~%" arg2) + (+! (-> *terrain-stats* total groups) (-> arg0 groups)) + (+! (-> *terrain-stats* total fragments) (-> arg0 fragments)) + (+! (-> *terrain-stats* total tris) (-> arg0 tris)) + (+! (-> *terrain-stats* total dverts) (-> arg0 dverts)) + (+! (-> *terrain-stats* total instances) (-> arg0 instances)) + ) + (none) + ) + +;; definition (debug) for function print-terrain-stats +;; WARN: Return type mismatch int vs none. +(defun-debug print-terrain-stats () + "Print all tr-stats for renderers to the screen." + (dotimes (gp-0 (-> *level* length)) + (let ((s5-0 (-> *level* level gp-0))) + (when (= (-> s5-0 status) 'active) + (compute-memory-usage! s5-0 #f) + (format + *stdcon* + "~0k~D ~A ~,,2fK + textures~%" + (-> s5-0 index) + (-> s5-0 name) + (* 0.0009765625 (the float (-> s5-0 mem-usage))) + ) + ) + ) + ) + (format *stdcon* "~0k~%grps frags tris dverts strip insts~%") + (print-tr-stat (-> *terrain-stats* pris) "pris" *temp-string*) + (print-tr-stat (-> *merc-global-stats* merc) "merc" *temp-string*) + (print-tr-stat (-> *merc-global-stats* emerc) "emerc" *temp-string*) + (print-tr-stat (-> *merc-global-stats* mercneric) "mercneric" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-generic) "tie-generic" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-vanish) "tie-vanish" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie) "tie" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor) "tie-scissor" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap) "tie-envmap" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor) "tie-envmap-scissor" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-trans) "tie-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor-trans) "tie-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-trans) "tie-envmap-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor-trans) "tie-envmap-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-water) "tie-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-scissor-water) "tie-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-water) "tie-envmap-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tie-envmap-scissor-water) "tie-envmap-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* shrub-near) "shrub-near" *temp-string*) + (print-tr-stat (-> *terrain-stats* shrub) "shrub" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor) "tfrag-scissor" *stat-string-tfrag-scissor*) + (print-tr-stat (-> *terrain-stats* tfrag) "tfrag" *stat-string-tfrag*) + (print-tr-stat (-> *terrain-stats* tfrag-trans) "tfrag-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor-trans) "tfrag-scissor-trans" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-water) "tfrag-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* tfrag-scissor-water) "tfrag-scissor-water" *temp-string*) + (print-tr-stat (-> *terrain-stats* trans-pris) "trans-pris" *temp-string*) + (print-tr-stat (-> *terrain-stats* billboard) "billboard" *temp-string*) + (print-tr-stat (-> *terrain-stats* trans-shrub) "trans-shrub" *temp-string*) + (print-tr-stat (-> *terrain-stats* ocean-mid) "ocean-mid" *temp-string*) + (print-tr-stat (-> *terrain-stats* ocean-near) "ocean-near" *temp-string*) + (print-tr-stat (-> *terrain-stats* shadow) "shadow" *temp-string*) + (print-tr-stat (-> *terrain-stats* hfrag) "hfrag" *temp-string*) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (print-tr-stat (-> *terrain-stats* total) "total" *stat-string-total*) + (clear-tr-stat (-> *terrain-stats* pris)) + (clear-tr-stat (-> *merc-global-stats* merc)) + (clear-tr-stat (-> *merc-global-stats* emerc)) + (clear-tr-stat (-> *merc-global-stats* mercneric)) + (clear-tr-stat (-> *terrain-stats* shrub-near)) + (clear-tr-stat (-> *terrain-stats* tie-generic)) + (clear-tr-stat (-> *terrain-stats* tie-vanish)) + (clear-tr-stat (-> *terrain-stats* tie)) + (clear-tr-stat (-> *terrain-stats* tie-scissor)) + (clear-tr-stat (-> *terrain-stats* tie-envmap)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor)) + (clear-tr-stat (-> *terrain-stats* tie-trans)) + (clear-tr-stat (-> *terrain-stats* tie-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-trans)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tie-water)) + (clear-tr-stat (-> *terrain-stats* tie-scissor-water)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-water)) + (clear-tr-stat (-> *terrain-stats* tie-envmap-scissor-water)) + (clear-tr-stat (-> *terrain-stats* shrub)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor)) + (clear-tr-stat (-> *terrain-stats* tfrag)) + (clear-tr-stat (-> *terrain-stats* tfrag-trans)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor-trans)) + (clear-tr-stat (-> *terrain-stats* tfrag-water)) + (clear-tr-stat (-> *terrain-stats* tfrag-scissor-water)) + (clear-tr-stat (-> *terrain-stats* trans-pris)) + (clear-tr-stat (-> *terrain-stats* billboard)) + (clear-tr-stat (-> *terrain-stats* trans-shrub)) + (clear-tr-stat (-> *terrain-stats* ocean-mid)) + (clear-tr-stat (-> *terrain-stats* ocean-near)) + (clear-tr-stat (-> *terrain-stats* shadow)) + (clear-tr-stat (-> *terrain-stats* hfrag)) + (clear-tr-stat (-> *terrain-stats* total)) + 0 + (none) + ) + +;; definition for function update-subdivide-settings! +;; WARN: Return type mismatch int vs none. +(defun update-subdivide-settings! ((arg0 subdivide-settings) (arg1 math-camera) (arg2 int)) + "Update the subdivide settings from the far/close settings + This caches the settings in subdivide-settings itself, + as well as in tfrag-work, used by EE tfrag code." + (set! (-> arg0 meters 0) (-> arg0 far arg2)) + (set! (-> arg0 meters 4) (-> arg0 close arg2)) + (let ((f0-3 (* 0.14285715 (- (-> arg0 meters 0) (-> arg0 meters 4))))) + (set! (-> arg0 meters 3) (+ (-> arg0 meters 4) (* 0.5 f0-3))) + (set! (-> arg0 meters 2) (+ (-> arg0 meters 3) f0-3)) + (set! (-> arg0 meters 1) (+ (-> arg0 meters 2) (* 2.0 f0-3))) + ) + (let ((f0-7 (* (-> arg1 fov-correction-factor) (/ (-> arg1 inv-hmge-scale w) (-> arg1 d))))) + (dotimes (v1-8 5) + (set! (-> arg0 dist v1-8) (* f0-7 (-> arg0 meters v1-8))) + ) + ) + (set! (-> *tfrag-work* frag-dists x) (- (-> arg0 meters 0))) + (set! (-> *tfrag-work* frag-dists y) (- (-> arg0 meters 1))) + (set! (-> *tfrag-work* frag-dists z) (- (-> arg0 meters 2))) + (set! (-> *tfrag-work* frag-dists w) (- (-> arg0 meters 4))) + 0 + (none) + ) + +;; definition for symbol *subdivide-settings*, type subdivide-settings +(define *subdivide-settings* (new 'global 'subdivide-settings 122880.0 286720.0)) + +;; definition for function set-tfrag-dists! +;; WARN: Return type mismatch tfrag-dists vs none. +(defun set-tfrag-dists! ((arg0 tfrag-dists)) + "Update the subdivide settings used in tfrag VU1 code. + This must be called after update-subdivide-settings!" + (let ((f2-0 (-> *subdivide-settings* dist 0)) + (f1-0 (-> *subdivide-settings* dist 1)) + (f0-0 (-> *subdivide-settings* dist 2)) + ) + (set! (-> arg0 data 3) (the-as uint f2-0)) + (set! (-> arg0 data 7) (the-as uint f1-0)) + (let ((f4-1 (/ 1.0 (- f2-0 f1-0))) + (f3-2 (/ 1.0 (- f1-0 f0-0))) + ) + (set! (-> arg0 data 1) (the-as uint (- f4-1))) + (set! (-> arg0 data 5) (the-as uint (- f3-2))) + (set! (-> arg0 data 0) (the-as uint (* 0.5 f4-1))) + (set! (-> arg0 data 4) (the-as uint (* 0.5 f3-2))) + (let ((f2-1 (* f2-0 f4-1)) + (f5-7 (* f1-0 f3-2)) + ) + (set! (-> arg0 data 9) (the-as uint f2-1)) + (set! (-> arg0 data 13) (the-as uint f5-7)) + ) + (set! (-> arg0 data 8) (the-as uint (* -0.5 f4-1 f1-0))) + (set! (-> arg0 data 12) (the-as uint (* -0.5 f3-2 f0-0))) + ) + ) + (none) + ) + +;; failed to figure out what this is: +(kmemopen global "terrain-context") + +;; definition for symbol *terrain-context*, type terrain-context +(define *terrain-context* (new 'global 'terrain-context)) + +;; failed to figure out what this is: +(kmemclose) + +;; definition for method 10 of type perf-stat +;; WARN: Return type mismatch perf-stat vs none. +(defmethod print-to-stream ((this perf-stat) (arg0 string) (arg1 basic)) + (format + *stdcon* + "~3d ~8d ~8d ~6d ~6d" + (-> this count) + (-> this cycles) + (-> this instructions) + (-> this icache) + (-> this dcache) + ) + (format *stdcon* " ~2d ~2d ~2d" (-> this to-vu0-waits) (-> this to-spr-waits) (-> this from-spr-waits)) + (format *stdcon* " ~s~%" arg0) + (none) + ) + +;; definition for symbol GSH_ENABLE, type symbol +(define GSH_ENABLE #f) + +;; definition for symbol GSH_BUCKET, type bucket-id +(define GSH_BUCKET (bucket-id bucket3)) + +;; definition for symbol GSH_WHICH_STAT, type int +(define GSH_WHICH_STAT 1) + +;; definition for symbol GSH_MAX_DISPLAY, type basic +(define GSH_MAX_DISPLAY (the-as basic #f)) + +;; definition for symbol GSH_TIME, type int +(define GSH_TIME 64) + +;; definition for symbol *perf-stats*, type perf-stat-array +(define *perf-stats* (new 'debug 'perf-stat-array 57)) + +;; this part is debug only +(when *debug-segment* +;; definition for symbol *gomi-stats-hack*, type (inline-array perf-stat) +(define *gomi-stats-hack* (the-as (inline-array perf-stat) (malloc 'debug (* 52 (+ GSH_TIME 1))))) + +) +;; definition (debug) for function start-perf-stat-collection +;; INFO: this function exists in multiple non-identical object files +;; WARN: Return type mismatch int vs none. +(defun-debug start-perf-stat-collection () + "Start the per-frame performance stats. + This automatically cycles through various stats/categories, + collecting and aggregating the latest data. + The `gomi-stats-hack` likely refers to how the stat being + collected" + (let ((v1-2 (+ (-> *perf-stats* data 0 frame-number) 1))) + (set! (-> *perf-stats* data 0 frame-number) v1-2) + (let ((gp-0 (mod v1-2 (the-as uint 114)))) + (when GSH_ENABLE + (let ((v1-5 GSH_BUCKET)) + (let ((a0-2 GSH_WHICH_STAT)) + (set! gp-0 (+ (* v1-5 2) a0-2)) + ) + (when GSH_MAX_DISPLAY + (let ((a0-7 (logand (-> *perf-stats* data 0 frame-number) (+ GSH_TIME -1)))) + (set! (-> *gomi-stats-hack* a0-7 cycles) (-> *perf-stats* data (the-as int v1-5) cycles)) + (set! (-> *gomi-stats-hack* a0-7 instructions) (-> *perf-stats* data (the-as int v1-5) instructions)) + (set! (-> *gomi-stats-hack* a0-7 icache) (-> *perf-stats* data (the-as int v1-5) icache)) + (set! (-> *gomi-stats-hack* a0-7 dcache) (-> *perf-stats* data (the-as int v1-5) dcache)) + (when (zero? a0-7) + (set! (-> *gomi-stats-hack* GSH_TIME cycles) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME instructions) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME icache) (the-as uint 0)) + (set! (-> *gomi-stats-hack* GSH_TIME dcache) (the-as uint 0)) + (dotimes (v1-22 GSH_TIME) + (if (< (-> *gomi-stats-hack* GSH_TIME cycles) (-> *gomi-stats-hack* v1-22 cycles)) + (set! (-> *gomi-stats-hack* GSH_TIME cycles) (-> *gomi-stats-hack* v1-22 cycles)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME instructions) (-> *gomi-stats-hack* v1-22 instructions)) + (set! (-> *gomi-stats-hack* GSH_TIME instructions) (-> *gomi-stats-hack* v1-22 instructions)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME icache) (-> *gomi-stats-hack* v1-22 icache)) + (set! (-> *gomi-stats-hack* GSH_TIME icache) (-> *gomi-stats-hack* v1-22 icache)) + ) + (if (< (-> *gomi-stats-hack* GSH_TIME dcache) (-> *gomi-stats-hack* v1-22 dcache)) + (set! (-> *gomi-stats-hack* GSH_TIME dcache) (-> *gomi-stats-hack* v1-22 dcache)) + ) + ) + ) + ) + (format *stdcon* "~%") + (print-to-stream (-> *gomi-stats-hack* GSH_TIME) "max-value" *stdcon*) + ) + ) + ) + (dotimes (v1-27 57) + (set! (-> *perf-stats* data v1-27 count) (the-as uint 0)) + (cond + ((!= v1-27 (shr gp-0 1)) + (set! (-> *perf-stats* data v1-27 ctrl) (the-as uint 0)) + 0 + ) + (else + (let ((a1-63 (logand gp-0 1)) + (a0-64 (the-as uint #x80004010)) + ) + (cond + ((zero? a1-63) + (set! a0-64 (+ #x60020 a0-64)) + ) + ((= a1-63 1) + (set! a0-64 (+ #x300c0 a0-64)) + ) + ) + (set! (-> *perf-stats* data v1-27 select) a1-63) + (set! (-> *perf-stats* data v1-27 ctrl) a0-64) + ) + (set! (-> *perf-stats* data v1-27 accum0) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 accum1) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 to-vu0-waits) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 to-spr-waits) (the-as uint 0)) + (set! (-> *perf-stats* data v1-27 from-spr-waits) (the-as uint 0)) + 0 + ) + ) + ) + ) + ) + (let* ((v1-31 (-> *perf-stats* data)) + (a0-76 (-> v1-31 0 ctrl)) + ) + (+! (-> v1-31 0 count) 1) + (b! (zero? a0-76) cfg-28 :delay (nop!)) + (.mtc0 Perf 0) + (.sync.l) + (.sync.p) + (.mtpc pcr0 0) + (.mtpc pcr1 0) + (.sync.l) + (.sync.p) + (.mtc0 Perf a0-76) + ) + (.sync.l) + (.sync.p) + (label cfg-28) + 0 + 0 + (none) + ) + +;; failed to figure out what this is: +(if (not *debug-segment*) + (set! start-perf-stat-collection L1) + ) + +;; definition (debug) for function end-perf-stat-collection +;; WARN: Return type mismatch int vs none. +(defun-debug end-perf-stat-collection () + "End the per-frame performance stats" + (local-vars (a0-1 int) (a0-3 int)) + (let ((v1-1 (-> *perf-stats* data))) + (b! (zero? (-> v1-1 0 ctrl)) cfg-2 :delay (nop!)) + (.mtc0 Perf 0) + (.sync.l) + (.sync.p) + (.mfpc a0-1 pcr0) + (+! (-> v1-1 0 accum0) a0-1) + (.mfpc a0-3 pcr1) + (+! (-> v1-1 0 accum1) a0-3) + ) + (label cfg-2) + 0 + (dotimes (v1-3 57) + (when (nonzero? (-> *perf-stats* data v1-3 ctrl)) + (let ((a2-0 (-> *perf-stats* data v1-3 select)) + (a1-8 (-> *perf-stats* data v1-3 accum0)) + (a0-15 (-> *perf-stats* data v1-3 accum1)) + ) + (cond + ((zero? a2-0) + (set! (-> *perf-stats* data v1-3 cycles) a1-8) + (set! (-> *perf-stats* data v1-3 instructions) a0-15) + ) + ((= a2-0 1) + (set! (-> *perf-stats* data v1-3 icache) a1-8) + (set! (-> *perf-stats* data v1-3 dcache) a0-15) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition (debug) for function print-perf-stats +;; WARN: Return type mismatch int vs none. +(defun-debug print-perf-stats () + (format *stdcon* "~0k~%count cycles instr icache dcache vu0/to/from~%") + (dotimes (gp-0 57) + (if (and (nonzero? (-> *perf-stats* data gp-0 count)) (< (the-as uint 10000) (-> *perf-stats* data gp-0 cycles))) + (print-to-stream + (-> *perf-stats* data gp-0) + (perf-stat-bucket->string (the-as perf-stat-bucket gp-0)) + *stdcon* + ) + ) + ) + 0 + (none) + ) diff --git a/test/decompiler/reference/jak3/engine/gfx/background/wind_REF.gc b/test/decompiler/reference/jak3/engine/gfx/background/wind_REF.gc new file mode 100644 index 0000000000..ee97fc391d --- /dev/null +++ b/test/decompiler/reference/jak3/engine/gfx/background/wind_REF.gc @@ -0,0 +1,48 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function update-wind +;; WARN: Return type mismatch int vs none. +(defun update-wind ((arg0 wind-work) (arg1 (array uint8))) + "Update the wind force for this frame. + This value will be used by level-update-wind to update tie/shrub wind values." + (with-pp + (let* ((f0-1 (+ (-> arg0 wind-normal w) (rand-vu-float-range -1024.0 1024.0))) + (f30-1 (- f0-1 (* (the float (the int (/ f0-1 65536.0))) 65536.0))) + ) + (set! (-> arg0 wind-normal w) f30-1) + (set! (-> arg0 wind-normal x) (cos f30-1)) + (set! (-> arg0 wind-normal z) (sin f30-1)) + ) + (+! (-> arg0 wind-time) (- (-> pp clock integral-frame-counter) (-> pp clock old-integral-frame-counter))) + (let* ((s4-0 (logand (-> arg0 wind-time) 63)) + (f0-4 (rand-vu-float-range 0.0 100.0)) + (v1-7 (/ (-> arg0 wind-time) (the-as uint 120))) + (f1-6 (* 0.008333334 (the float (mod (-> arg0 wind-time) (the-as uint 120))))) + (f2-4 (* 0.0625 (the float (-> arg1 (mod (the-as int v1-7) (-> arg1 length)))))) + (f0-5 + (* (+ (* (- (* 0.0625 (the float (-> arg1 (mod (the-as int (+ v1-7 1)) (-> arg1 length))))) f2-4) f1-6) f2-4) + f0-4 + ) + ) + ) + (set! (-> *wind-work* wind-force s4-0) f0-5) + (vector-float*! (-> *wind-work* wind-array s4-0) (-> arg0 wind-normal) f0-5) + ) + 0 + (none) + ) + ) + +;; definition for function wind-get-hashed-index +(defun wind-get-hashed-index ((arg0 vector) (arg1 wind-work)) + "Unused function, likely a leftover from Jak 1's different wind system." + (logand (+ (the int (-> arg0 x)) (the int (-> arg0 z)) (-> *wind-work* wind-time)) 63) + ) + +;; definition for function level-update-wind +;; ERROR: function was not converted to expressions. Cannot decompile. + + + + diff --git a/test/decompiler/reference/jak3/engine/gfx/shrub/shrubbery-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/shrub/shrubbery-h_REF.gc index 880db4759a..d7c615c679 100644 --- a/test/decompiler/reference/jak3/engine/gfx/shrub/shrubbery-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/gfx/shrub/shrubbery-h_REF.gc @@ -144,7 +144,9 @@ overwrites all the normal drawable fields." ;; definition of type drawable-tree-instance-shrub (deftype drawable-tree-instance-shrub (drawable-tree) "Drawable-tree for the shrubs." - () + ((info prototype-array-shrub-info :offset 8) + (colors-added time-of-day-palette :offset 12) + ) ) ;; definition of type generic-shrub-fragment @@ -476,7 +478,3 @@ This requires storing the data for all shrubs prototype twice!" ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/gfx/texture/texture-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/texture/texture-h_REF.gc index 431ce4e5fb..b87359650d 100644 --- a/test/decompiler/reference/jak3/engine/gfx/texture/texture-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/gfx/texture/texture-h_REF.gc @@ -162,7 +162,7 @@ So mask 0 is needed if segment 0 of the texture is needed, etc..." ;; definition of type texture-masks-array (deftype texture-masks-array (inline-array-class) "Group of all texture-masks for a given tpage." - ((data texture-masks :dynamic) + ((data texture-masks :inline :dynamic) ) ) @@ -494,6 +494,7 @@ of the texture." ) ;; definition for method 3 of type adgif-shader-array +;; INFO: this function exists in multiple non-identical object files (defmethod inspect ((this adgif-shader-array)) (when (not this) (set! this this) diff --git a/test/decompiler/reference/jak3/engine/level/bsp-h_REF.gc b/test/decompiler/reference/jak3/engine/level/bsp-h_REF.gc index f490ede060..cf6ea2b6df 100644 --- a/test/decompiler/reference/jak3/engine/level/bsp-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/level/bsp-h_REF.gc @@ -12,6 +12,7 @@ This is used for precomputed visibility, based on the camera position. This is n (back-box-min vector4b :inline) (back-box-max vector4b :inline) ) + :pack-me ) ;; definition for method 3 of type bsp-node @@ -35,13 +36,45 @@ This is used for precomputed visibility, based on the camera position. This is n (deftype bsp-header (drawable) "The bsp-header is really an entire level. This probably started as a very simple structure, but now it is extremely complicated." - ((all-visible-list (pointer uint16) :offset 32) - (visible-list-length int16 :offset 36) - (drawable-trees drawable-tree-array :offset 40) - (pat pointer :offset 44) - (pat-length int32 :offset 48) - (nodes (inline-array bsp-node) :offset 120) - (end uint8 :offset 399) + ((info file-info :overlay-at id) + (all-visible-list (pointer uint16) :offset 32) + (visible-list-length int16 :offset 36) + (drawable-trees drawable-tree-array :offset 40) + (pat pointer :offset 44) + (pat-length int32 :offset 48) + (texture-remap-table (pointer uint64)) + (texture-remap-table-len int32) + (texture-ids (pointer texture-id)) + (texture-page-count int32) + (unknown-basic basic) + (actors drawable-inline-array-actor :offset 112) + (cameras (array entity-camera)) + (nodes (inline-array bsp-node) :offset 120) + (level level) + (current-leaf-idx uint16) + (texture-flags texture-page-flag 10 :offset 130) + (cam-outside-bsp uint8 :offset 152) + (cam-using-back uint8) + (cam-box-idx uint16) + (actor-birth-order (pointer uint32) :offset 172) + (region-trees (array drawable-tree-region-prim) :offset 188) + (collide-hash collide-hash :offset 196) + (tfrag-masks texture-masks-array :offset 256) + (tfrag-closest (pointer float)) + (tfrag-mask-count uint32 :overlay-at tfrag-closest) + (shrub-masks texture-masks-array) + (shrub-closest (pointer float)) + (shrub-mask-count uint32 :overlay-at shrub-closest) + (alpha-masks texture-masks-array) + (alpha-closest (pointer float)) + (alpha-mask-count uint32 :overlay-at alpha-closest) + (water-masks texture-masks-array) + (water-closest (pointer float)) + (water-mask-count uint32 :overlay-at water-closest) + (bsp-scale vector :inline :offset 288) + (bsp-offset vector :inline) + (unk-drawable drawable :offset 320) + (end uint8 :offset 399) ) (:methods (birth (_type_) none) @@ -199,7 +232,3 @@ The final stopwatch is cut off. For jak 3, I just fixed it." ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/level/bsp_REF.gc b/test/decompiler/reference/jak3/engine/level/bsp_REF.gc new file mode 100644 index 0000000000..bbc44d1d9b --- /dev/null +++ b/test/decompiler/reference/jak3/engine/level/bsp_REF.gc @@ -0,0 +1,735 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function mem-usage-bsp-tree +;; WARN: Return type mismatch bsp-header vs none. +(defun mem-usage-bsp-tree ((arg0 bsp-header) (arg1 bsp-node) (arg2 memory-usage-block) (arg3 int)) + "Recursively compute memory usage of bsp-tree." + (cond + ((zero? arg1) + ) + (else + (+! (-> arg2 data 61 count) 1) + (let ((v1-3 20)) + (+! (-> arg2 data 61 used) v1-3) + (+! (-> arg2 data 61 total) v1-3) + ) + (if (zero? (-> arg1 front-box-min w)) + (mem-usage-bsp-tree arg0 (-> arg0 nodes (-> arg1 front)) arg2 arg3) + ) + (when (zero? (-> arg1 back-box-min w)) + (if (> (-> arg1 back) 0) + (mem-usage-bsp-tree arg0 (-> arg0 nodes (-> arg1 back)) arg2 arg3) + ) + ) + ) + ) + (none) + ) + +;; definition for method 8 of type bsp-header +(defmethod mem-usage ((this bsp-header) (usage memory-usage-block) (flags int)) + (set! (-> usage work-bsp) this) + (when (nonzero? (-> this info)) + (set! (-> usage length) (max 86 (-> usage length))) + (set! (-> usage data 85 name) "array") + (+! (-> usage data 85 count) 1) + (let ((v1-8 (asize-of (-> this info)))) + (+! (-> usage data 85 used) v1-8) + (+! (-> usage data 85 total) (logand -16 (+ v1-8 15))) + ) + ) + (if (nonzero? (-> this drawable-trees)) + (mem-usage (-> this drawable-trees) usage flags) + ) + (if (nonzero? (-> this collide-hash)) + (mem-usage (-> this collide-hash) usage flags) + ) + (set! (-> usage length) (max 66 (-> usage length))) + (set! (-> usage data 44 name) "entity") + (set! (-> usage data 45 name) "camera") + (set! (-> usage data 65 name) "pat") + (set! (-> usage data 61 name) "bsp-node") + (set! (-> usage length) (max 60 (-> usage length))) + (set! (-> usage data 59 name) "bsp-main") + (+! (-> usage data 59 count) 1) + (let ((v1-31 400)) + (+! (-> usage data 59 used) v1-31) + (+! (-> usage data 59 total) (logand -16 (+ v1-31 15))) + ) + (set! (-> usage length) (max 63 (-> usage length))) + (set! (-> usage data 62 name) "bsp-leaf-vis-self") + (+! (-> usage data 62 count) 1) + (let ((v1-40 (-> this visible-list-length))) + (+! (-> usage data 62 used) v1-40) + (+! (-> usage data 62 total) (logand -16 (+ v1-40 15))) + ) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-50 (* (-> this texture-remap-table-len) 8))) + (+! (-> usage data 60 used) v1-50) + (+! (-> usage data 60 total) (logand -16 (+ v1-50 15))) + ) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-60 (* (-> this texture-page-count) 4))) + (+! (-> usage data 60 used) v1-60) + (+! (-> usage data 60 total) (logand -16 (+ v1-60 15))) + ) + (when (nonzero? (-> this unknown-basic)) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-72 (asize-of (-> this unknown-basic)))) + (+! (-> usage data 60 used) v1-72) + (+! (-> usage data 60 total) (logand -16 (+ v1-72 15))) + ) + ) + (when (nonzero? (-> this actor-birth-order)) + (set! (-> usage length) (max 61 (-> usage length))) + (set! (-> usage data 60 name) "bsp-misc") + (+! (-> usage data 60 count) 1) + (let ((v1-85 (* (-> this actors length) 4))) + (+! (-> usage data 60 used) v1-85) + (+! (-> usage data 60 total) (logand -16 (+ v1-85 15))) + ) + ) + (+! (-> usage data 65 count) (-> this pat-length)) + (let ((v1-92 (* (-> this pat-length) 4))) + (+! (-> usage data 65 used) v1-92) + (+! (-> usage data 65 total) (logand -16 (+ v1-92 15))) + ) + (if (nonzero? (-> this unk-drawable)) + (mem-usage (-> this unk-drawable) usage flags) + ) + (when (nonzero? (-> this region-trees)) + (let* ((s3-0 (-> this region-trees length)) + (s2-0 0) + (a0-40 (-> this region-trees s2-0)) + ) + (while (< s2-0 s3-0) + (mem-usage a0-40 usage (logior flags 128)) + (+! s2-0 1) + (set! a0-40 (-> this region-trees s2-0)) + ) + ) + ) + (let ((s3-1 (-> this cameras))) + (when (nonzero? s3-1) + (dotimes (s2-1 (-> s3-1 length)) + (mem-usage (-> s3-1 s2-1) usage (logior flags 256)) + ) + ) + ) + (if (nonzero? (-> this nodes)) + (mem-usage-bsp-tree this (-> this nodes 0) usage flags) + ) + this + ) + +;; definition for method 9 of type bsp-header +(defmethod login ((this bsp-header)) + "Initialize the object after it is loaded." + (if (nonzero? (-> this drawable-trees)) + (login (-> this drawable-trees)) + ) + (set! (-> this level tfrag-gs-test) + (if (logtest? (-> this texture-flags 0) (texture-page-flag alpha-enable)) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest greater-equal)) + (new 'static 'gs-test + :ate #x1 + :atst (gs-atest greater-equal) + :aref #x26 + :zte #x1 + :ztst (gs-ztest greater-equal) + ) + ) + ) + (if (nonzero? (-> this unk-drawable)) + (login (-> this unk-drawable)) + ) + this + ) + +;; definition for symbol *test-shrub*, type int +(define *test-shrub* 0) + +;; definition for method 10 of type bsp-header +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod draw ((this bsp-header)) + "Draw the drawable, and typically its children. + This usually means adding stuff to a list to be drawn later, rather than expensive drawing here." + (local-vars (a3-4 uint128) (a3-5 uint128)) + (rlet ((vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf20 :class vf) + (vf21 :class vf) + (vf22 :class vf) + (vf23 :class vf) + (vf24 :class vf) + (vf25 :class vf) + (vf26 :class vf) + (vf27 :class vf) + (vf28 :class vf) + (vf29 :class vf) + (vf30 :class vf) + (vf31 :class vf) + ) + (let ((v1-0 (-> this level))) + (when (-> v1-0 render?) + (set! *draw-index* (-> v1-0 draw-index)) + (set! (-> *prototype-tie-work* mood) (-> v1-0 mood-context)) + (let ((a2-0 (/ (+ (-> this visible-list-length) 15) 16))) + (dma-send-to-spr-no-flush + (the-as uint (+ #x3800 #x70000000)) + (the-as uint (-> v1-0 vis-bits)) + (the-as uint a2-0) + #f + ) + ) + (when *artist-flip-visible* + (let ((v1-6 (/ (+ (-> this visible-list-length) 15) 16)) + (a0-10 (-> (the-as terrain-context #x70000000) work background vis-list)) + (a1-4 (-> this all-visible-list)) + ) + (dotimes (a2-1 v1-6) + (let ((a3-3 (-> (the-as (pointer uint128) (+ (the-as uint a0-10) (* a2-1 16)))))) + (.pnor a3-4 a3-3 0) + ) + (let ((t0-2 (-> (the-as (pointer uint128) (&+ a1-4 (* a2-1 16)))))) + (.pand a3-5 a3-4 t0-2) + ) + (set! (-> (the-as (pointer uint128) (+ (the-as uint a0-10) (* a2-1 16)))) a3-5) + ) + ) + ) + (let ((at-0 *math-camera*)) + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat rvec quad)) + (.lvf vf21 (&-> at-0 shrub-mat uvec quad)) + (.lvf vf22 (&-> at-0 shrub-mat fvec quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot rvec quad)) + (.lvf vf25 (&-> at-0 camera-rot uvec quad)) + (.lvf vf26 (&-> at-0 camera-rot fvec quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp rvec quad)) + (.lvf vf29 (&-> at-0 camera-temp uvec quad)) + (.lvf vf30 (&-> at-0 camera-temp fvec quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + (if (nonzero? (-> this drawable-trees)) + (draw (-> this drawable-trees)) + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for method 14 of type bsp-header +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw ((this bsp-header)) + "Debug-draw a drawable and its children. Typically uses the debug-draw functions." + (rlet ((vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf20 :class vf) + (vf21 :class vf) + (vf22 :class vf) + (vf23 :class vf) + (vf24 :class vf) + (vf25 :class vf) + (vf26 :class vf) + (vf27 :class vf) + (vf28 :class vf) + (vf29 :class vf) + (vf30 :class vf) + (vf31 :class vf) + ) + (let ((v1-0 (-> this level))) + (set! *draw-index* (-> v1-0 draw-index)) + (set! (-> *prototype-tie-work* mood) (-> v1-0 mood-context)) + (let ((a2-0 (/ (+ (-> this visible-list-length) 15) 16))) + (dma-send-to-spr-no-flush + (the-as uint (+ #x3800 #x70000000)) + (the-as uint (-> v1-0 vis-bits)) + (the-as uint a2-0) + #f + ) + ) + ) + (let ((at-0 *math-camera*)) + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat rvec quad)) + (.lvf vf21 (&-> at-0 shrub-mat uvec quad)) + (.lvf vf22 (&-> at-0 shrub-mat fvec quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot rvec quad)) + (.lvf vf25 (&-> at-0 camera-rot uvec quad)) + (.lvf vf26 (&-> at-0 camera-rot fvec quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp rvec quad)) + (.lvf vf29 (&-> at-0 camera-temp uvec quad)) + (.lvf vf30 (&-> at-0 camera-temp fvec quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + (if (nonzero? (-> this drawable-trees)) + (debug-draw (-> this drawable-trees)) + ) + 0 + (none) + ) + ) + +;; definition for method 13 of type bsp-header +;; WARN: Return type mismatch int vs none. +(defmethod collect-stats ((this bsp-header)) + "Collect triangle/perf statistics for rendering. + This is only called when viewing stats. + The vis-bits and culling registers are loaded during this time." + (rlet ((vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf20 :class vf) + (vf21 :class vf) + (vf22 :class vf) + (vf23 :class vf) + (vf24 :class vf) + (vf25 :class vf) + (vf26 :class vf) + (vf27 :class vf) + (vf28 :class vf) + (vf29 :class vf) + (vf30 :class vf) + (vf31 :class vf) + ) + (let ((v1-0 (-> this level)) + (a2-0 (/ (+ (-> this visible-list-length) 15) 16)) + ) + (dma-send-to-spr-no-flush + (the-as uint (+ #x3800 #x70000000)) + (the-as uint (-> v1-0 vis-bits)) + (the-as uint a2-0) + #f + ) + ) + (let ((at-0 *math-camera*)) + (.lvf vf16 (&-> at-0 plane 0 quad)) + (.lvf vf17 (&-> at-0 plane 1 quad)) + (.lvf vf18 (&-> at-0 plane 2 quad)) + (.lvf vf19 (&-> at-0 plane 3 quad)) + (.lvf vf20 (&-> at-0 shrub-mat rvec quad)) + (.lvf vf21 (&-> at-0 shrub-mat uvec quad)) + (.lvf vf22 (&-> at-0 shrub-mat fvec quad)) + (.lvf vf23 (&-> at-0 shrub-mat trans quad)) + (.lvf vf24 (&-> at-0 camera-rot rvec quad)) + (.lvf vf25 (&-> at-0 camera-rot uvec quad)) + (.lvf vf26 (&-> at-0 camera-rot fvec quad)) + (.lvf vf27 (&-> at-0 camera-rot trans quad)) + (.lvf vf28 (&-> at-0 camera-temp rvec quad)) + (.lvf vf29 (&-> at-0 camera-temp uvec quad)) + (.lvf vf30 (&-> at-0 camera-temp fvec quad)) + (.lvf vf31 (&-> at-0 camera-temp trans quad)) + ) + (if (nonzero? (-> this drawable-trees)) + (collect-stats (-> this drawable-trees)) + ) + (if (nonzero? (-> this unk-drawable)) + (collect-stats (-> this unk-drawable)) + ) + 0 + (none) + ) + ) + +;; definition for function bsp-camera-asm +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [srl t3, t3, 24] +;; ERROR: Unsupported inline assembly instruction kind - [srl t2, t2, 24] +(defun bsp-camera-asm ((arg0 bsp-header) (arg1 vector)) + "Determine which 'bsp' leaf cell the camera is in, for precomputed vis. + The result is stored in the bsp itself." + (local-vars + (a2-1 object) + (a3-0 uint128) + (a3-1 uint128) + (a3-2 uint128) + (a3-3 uint128) + (t0-5 uint) + (t2-1 uint) + (t3-1 int) + (t4-0 uint128) + (t5-0 uint128) + (t6-0 uint128) + (t7-0 uint128) + ) + (rlet ((Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (nop!) + (.lvf vf3 (&-> arg0 bsp-scale quad)) + (let ((v1-0 (the-as object (-> arg0 nodes)))) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg0 bsp-offset quad)) + (.sub.vf vf1 vf1 vf2 :mask #b111) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b0) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b1) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b1) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b10) + (.div.vf Q vf0 vf3 :fsf #b11 :ftf #b10) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b100) + (let ((a1-1 #xffffff) + (a2-0 (the-as object 0)) + ) + (vftoi15.xyzw vf1 vf1) + (.mov a3-0 vf1) + (.pw.sra a3-1 a3-0 15) + (.ppach a3-2 (the-as uint128 0) a3-1) + (.ppacb a3-3 (the-as uint128 0) a3-2) + (let ((a3-4 (the-as uint128 (logand (the-as int a3-3) a1-1)))) + (label cfg-1) + (let ((t1-1 (the-as bsp-node (&+ (the-as pointer v1-0) (+ (* a2-0 16) (* a2-0 4)))))) + (nop!) + (let ((t3-0 (the-as uint128 (-> t1-1 front-box-min clr)))) + (.pcgtb t6-0 t3-0 a3-4) + (let ((t0-2 (the-as uint128 (-> t1-1 front-box-max clr)))) + (.pcgtb t4-0 t0-2 a3-4) + ) + (let ((t2-0 (the-as uint128 (-> t1-1 back-box-min clr)))) + (.pcgtb t7-0 t2-0 a3-4) + (let ((t0-3 (the-as uint128 (-> t1-1 back-box-max clr)))) + (.pcgtb t5-0 t0-3 a3-4) + ) + (let* ((t0-4 (-> t1-1 front)) + (t6-1 (lognot (the-as int t6-0))) + (t7-1 (lognot (the-as int t7-0))) + (t4-1 (logand t6-1 (the-as int t4-0))) + (t5-1 (logand t7-1 (the-as int t5-0))) + (t4-2 (logand t4-1 a1-1)) + (t5-2 (logand t5-1 a1-1)) + ) + (.srl t3-1 (the-as uint t3-0) 24) + (let ((t1-2 (the-as bsp-node (-> t1-1 back)))) + (b! (= t4-2 a1-1) cfg-4 :delay (.srl t2-1 (the-as int t2-0) 24)) + (b! (= t5-2 a1-1) cfg-7 :delay (set! t0-5 (the-as uint 1))) + (b! #t cfg-11 :delay (set! (-> arg0 cam-outside-bsp) t0-5)) + (label cfg-4) + (b! (zero? t3-1) cfg-1 :likely-delay (set! a2-0 t0-4)) + (let ((v1-1 a2-0)) + (set! (-> arg0 cam-using-back) (the-as uint 0)) + (b! #t cfg-10 :delay (set! a2-1 t0-4)) + (label cfg-7) + (b! (zero? t2-1) cfg-1 :likely-delay (set! a2-0 t1-2)) + (set! v1-1 a2-0) + (set! a2-1 t1-2) + (set! (-> arg0 cam-using-back) (the-as uint 1)) + (label cfg-10) + (set! (-> arg0 current-leaf-idx) (the-as uint a2-1)) + (set! (-> arg0 cam-box-idx) (the-as uint v1-1)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (set! (-> arg0 cam-outside-bsp) (the-as uint 0)) + (label cfg-11) + 0 + (none) + ) + ) + +;; definition for method 16 of type bsp-header +;; WARN: Return type mismatch int vs none. +(defmethod collect-regions ((this bsp-header) (arg0 sphere) (arg1 int) (arg2 region-prim-list)) + "Fill the region-prim-list with regions that intersect the sphere." + (let ((s3-0 (-> this region-trees))) + (dotimes (s2-0 (-> s3-0 length)) + (collect-regions (-> s3-0 s2-0) arg0 arg1 arg2) + ) + ) + 0 + (none) + ) + +;; definition for function print-collide-stats +;; WARN: Return type mismatch int vs none. +;; ERROR: Function may read a register that is not set: t0 +(defun print-collide-stats () + (local-vars (t0-0 none)) + (format *stdcon* "~0k~%count cycles instr icache dcache vu0/to/from~%") + (print-to-stream (-> *perf-stats* data 3) "collide" *stdcon*) + (print-to-stream (-> *perf-stats* data 4) "collide-list" *stdcon*) + (print-to-stream (-> *perf-stats* data 5) "collide-fill" *stdcon*) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (format *stdcon* "~0kcalls = ~d~%" (-> *collide-stats* calls)) + (format + *stdcon* + "~0kspheres = ~d~256hspheres/call = ~f~%" + (-> *collide-stats* spheres) + (/ (the float (-> *collide-stats* spheres)) (the float (-> *collide-stats* calls))) + t0-0 + ) + (format + *stdcon* + "~0knodes = ~d~256hnodes/call = ~f~%" + (-> *collide-stats* nodes) + (/ (the float (-> *collide-stats* nodes)) (the float (-> *collide-stats* calls))) + t0-0 + ) + (format + *stdcon* + "~0kfrags = ~d~256hfrags/call = ~f~%" + (-> *collide-stats* frags) + (/ (the float (-> *collide-stats* frags)) (the float (-> *collide-stats* calls))) + t0-0 + ) + (format + *stdcon* + "~0ktris = ~d~256htris/frag = ~f~%" + (-> *collide-stats* tris) + (/ (the float (-> *collide-stats* tris)) (the float (-> *collide-stats* frags))) + t0-0 + ) + (format + *stdcon* + "~0koutput = ~d~256houtput/call = ~f~%" + (-> *collide-stats* output) + (/ (the float (-> *collide-stats* output)) (the float (-> *collide-stats* calls))) + t0-0 + ) + (format *stdcon* "~0k---------------------------------------------------------------~%") + (let ((gp-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 1)))) + (s4-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 9)))) + (s5-0 (stopwatch-elapsed-ticks (the-as stopwatch (&-> *collide-stats* junk 17)))) + ) + (format *stdcon* "~0ktotal-target ~D~%" gp-0) + (format *stdcon* "~0ktarget-cache-fill ~D ~0,,2f%~%" s4-0 (/ (* 100.0 (the float s4-0)) (the float gp-0))) + (format *stdcon* "~0ktarget-ray-poly ~D ~0,,2f%~%" s5-0 (/ (* 100.0 (the float s5-0)) (the float gp-0))) + ) + (set! (-> *collide-stats* calls) (the-as uint 0)) + (set! (-> *collide-stats* spheres) (the-as uint 0)) + (set! (-> *collide-stats* nodes) (the-as uint 0)) + (set! (-> *collide-stats* frags) (the-as uint 0)) + (set! (-> *collide-stats* tris) (the-as uint 0)) + (set! (-> *collide-stats* output) (the-as uint 0)) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 1))) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 9))) + (stopwatch-init (the-as stopwatch (&-> *collide-stats* junk 17))) + 0 + (none) + ) + +;; definition for function level-remap-texture +;; WARN: Return type mismatch uint vs texture-id. +(defun level-remap-texture ((arg0 texture-id)) + "Level tpages combine the tpages of many individual actors. + Given a texture ID for a texture in an individual actor, + determine the texture ID for this texture in the level's + combined page." + (let ((v1-1 (-> *level* log-in-level-bsp))) + (when v1-1 + (let* ((a3-0 (-> v1-1 texture-remap-table-len)) + (v1-2 (the-as object (-> v1-1 texture-remap-table))) + (t0-0 (the-as (pointer uint64) v1-2)) + (a1-1 (the-as uint #xfffffff8)) + (a2-1 (logand (new 'static 'texture-id :index #xfff :page #xfff) arg0)) + (a3-2 (the-as object (&+ t0-0 (* a3-0 8)))) + ) + (label cfg-2) + (b! (= v1-2 a3-2) cfg-8 :delay (nop!)) + (let ((t0-3 (the-as object (logand (/ (+ (the-as int v1-2) (the-as int a3-2)) 2) a1-1)))) + (let ((t1-1 (- (-> (the-as (pointer uint32) t0-3) 0) a2-1))) + (b! (zero? t1-1) cfg-7 :delay (nop!)) + (b! (< (the-as int t1-1) 0) cfg-6 :delay (nop!)) + ) + (b! #t cfg-2 :delay (set! a3-2 (the-as (pointer uint64) t0-3))) + (label cfg-6) + (b! #t cfg-2 :delay (set! v1-2 (+ (the-as int t0-3) 8))) + (label cfg-7) + (set! arg0 (the-as texture-id (logior (-> (the-as (pointer uint32) t0-3) 1) 20))) + ) + ) + (label cfg-8) + 0 + ) + ) + (the-as texture-id arg0) + ) + +;; definition for function build-masks +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun build-masks ((arg0 bsp-header)) + "Allocate and assign texture masks, and closest object arrays. + These are used at runtime to only upload the texture chunks and + mip levels that are actually needed." + (let ((v1-0 (-> arg0 drawable-trees)) + (s2-0 (-> arg0 tfrag-closest)) + (s3-0 (-> arg0 shrub-closest)) + (s4-0 (-> arg0 alpha-closest)) + (gp-0 (-> arg0 water-closest)) + ) + (when (zero? (&+ (+ (&+ s2-0 s3-0) (the-as int s4-0)) gp-0)) + (dotimes (a0-5 (-> v1-0 length)) + (let ((a1-2 (-> v1-0 data a0-5))) + (cond + ((= (-> a1-2 type) drawable-tree-tfrag) + (let* ((a2-5 (-> (the-as drawable-tree-tfrag a1-2) arrays (+ (-> (the-as drawable-tree-tfrag a1-2) length) -1))) + (a1-4 (-> a2-5 length)) + (a2-6 (-> (the-as drawable-inline-array-tfrag a2-5) data)) + ) + (dotimes (a3-1 a1-4) + (set! (-> a2-6 0 texture-masks-index) (the-as uint s2-0)) + (&+! s2-0 1) + (set! a2-6 (the-as (inline-array tfragment) (-> a2-6 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-tfrag-trans) + (let* ((a2-13 + (-> (the-as drawable-tree-tfrag-trans a1-2) arrays (+ (-> (the-as drawable-tree-tfrag-trans a1-2) length) -1)) + ) + (a1-7 (-> a2-13 length)) + (a2-14 (-> (the-as drawable-inline-array-tfrag a2-13) data)) + ) + (dotimes (a3-3 a1-7) + (set! (-> a2-14 0 texture-masks-index) (the-as uint s4-0)) + (&+! s4-0 1) + (set! a2-14 (the-as (inline-array tfragment) (-> a2-14 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-tfrag-water) + (let* ((a2-21 + (-> (the-as drawable-tree-tfrag-water a1-2) arrays (+ (-> (the-as drawable-tree-tfrag-water a1-2) length) -1)) + ) + (a1-10 (-> a2-21 length)) + (a2-22 (-> (the-as drawable-inline-array-tfrag a2-21) data)) + ) + (dotimes (a3-5 a1-10) + (set! (-> a2-22 0 texture-masks-index) (the-as uint gp-0)) + (&+! gp-0 1) + (set! a2-22 (the-as (inline-array tfragment) (-> a2-22 1))) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-instance-tie) + (let* ((a1-13 (-> (the-as drawable-tree-instance-tie a1-2) prototypes prototype-array-tie)) + (a2-26 (-> a1-13 length)) + ) + (dotimes (a3-7 a2-26) + (cond + ((logtest? (-> a1-13 array-data a3-7 flags) (prototype-flags tpage-water)) + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint gp-0)) + (&+! gp-0 1) + ) + ((logtest? (-> a1-13 array-data a3-7 flags) (prototype-flags tpage-alpha)) + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint s4-0)) + (&+! s4-0 1) + ) + (else + (set! (-> a1-13 array-data a3-7 texture-masks-index) (the-as uint s2-0)) + (&+! s2-0 1) + ) + ) + ) + ) + ) + ((= (-> a1-2 type) drawable-tree-instance-shrub) + (let* ((a2-30 (-> (the-as drawable-tree-instance-shrub a1-2) info prototype-inline-array-shrub)) + (a1-16 (-> a2-30 length)) + (a2-31 (-> a2-30 data)) + ) + (dotimes (a3-9 a1-16) + (set! (-> a2-31 0 texture-masks-index) (the-as uint s3-0)) + (&+! s3-0 1) + (set! a2-31 (the-as (inline-array prototype-bucket-shrub) (-> a2-31 1))) + ) + ) + ) + ) + ) + ) + ) + (when (nonzero? s2-0) + (set! (-> arg0 tfrag-masks) (new 'loading-level 'texture-masks-array (the-as int s2-0))) + (set! (-> arg0 tfrag-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s2-0 4))))) + (let ((v1-5 (-> arg0 tfrag-masks))) + (dotimes (a0-8 (the-as int s2-0)) + (let ((a1-24 (-> v1-5 data a0-8))) + (dotimes (a2-34 3) + (set! (-> a1-24 data a2-34 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? s3-0) + (set! (-> arg0 shrub-masks) (new 'loading-level 'texture-masks-array (the-as int s3-0))) + (set! (-> arg0 shrub-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s3-0 4))))) + (let ((v1-10 (-> arg0 shrub-masks))) + (dotimes (a0-11 (the-as int s3-0)) + (let ((a1-32 (-> v1-10 data a0-11))) + (dotimes (a2-36 3) + (set! (-> a1-32 data a2-36 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? s4-0) + (set! (-> arg0 alpha-masks) (new 'loading-level 'texture-masks-array (the-as int s4-0))) + (set! (-> arg0 alpha-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* s4-0 4))))) + (let ((v1-15 (-> arg0 alpha-masks))) + (dotimes (a0-14 (the-as int s4-0)) + (let ((a1-40 (-> v1-15 data a0-14))) + (dotimes (a2-38 3) + (set! (-> a1-40 data a2-38 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + (when (nonzero? gp-0) + (set! (-> arg0 water-masks) (new 'loading-level 'texture-masks-array (the-as int gp-0))) + (set! (-> arg0 water-closest) (the-as (pointer float) (malloc 'loading-level (the-as int (* gp-0 4))))) + (let ((v1-20 (-> arg0 water-masks))) + (dotimes (a0-17 (the-as int gp-0)) + (let ((a1-48 (-> v1-20 data a0-17))) + (dotimes (a2-40 3) + (set! (-> a1-48 data a2-40 mask quad) (the-as uint128 0)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) diff --git a/test/decompiler/reference/jak3/engine/level/level-h_REF.gc b/test/decompiler/reference/jak3/engine/level/level-h_REF.gc index bd925ac597..60c0c9ab3d 100644 --- a/test/decompiler/reference/jak3/engine/level/level-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/level/level-h_REF.gc @@ -439,7 +439,7 @@ (level-method-11 () none) (level-method-12 () none) (level-method-13 () none) - (level-method-14 () none) + (compute-memory-usage! (_type_ symbol) memory-usage-block) (level-method-15 () none) (level-method-16 () none) (level-method-17 () none) @@ -617,7 +617,7 @@ ;; definition of type level-group (deftype level-group (basic) ((length int32) - (unk-flag1 symbol) + (log-in-level-bsp bsp-header) (loading-level level) (entity-link entity-links :offset 16) (border? symbol) @@ -743,7 +743,7 @@ (set! *level* (new 'static 'level-group :length 10 - :unk-flag1 #f + :log-in-level-bsp #f :loading-level #f :entity-link #f :border? #f diff --git a/test/offline/config/jak3/config.jsonc b/test/offline/config/jak3/config.jsonc index 315bbec9c2..f956bfeb6b 100644 --- a/test/offline/config/jak3/config.jsonc +++ b/test/offline/config/jak3/config.jsonc @@ -7,7 +7,8 @@ "skip_compile_files": [ "types-h", // weird array of types. "hfrag-h", // weird duplicate type - "joint" + "joint", + "subdivide" ], "skip_compile_functions": [ @@ -67,7 +68,10 @@ "(method 3 hfrag-poly25)", "(method 3 hfrag-mip-packet)", // transformq - "(method 17 trsqv)" + "(method 17 trsqv)", + // bsp + "bsp-camera-asm", + "build-masks" ],