From 790e65a78cc16fb4f709fd10f1b375b8cbdcc6b7 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 13 May 2021 20:46:37 -0400 Subject: [PATCH] decomp: Decompile `wind` (#480) * decomp: Decompile `wind` * include `` --- Taskfile.yml | 4 +- decompiler/analysis/insert_lets.cpp | 3 +- decompiler/config/all-types.gc | 6 +- .../jak1_ntsc_black_label/label_types.jsonc | 9 +- goal_src/engine/gfx/wind-h.gc | 2 + goal_src/engine/gfx/wind.gc | 75 +++++++++++++ scripts/next-decomp-file.py | 4 +- .../reference/all_forward_declarations.gc | 7 +- .../reference/engine/gfx/wind-h_REF.gc | 104 ++++++++++++++++++ .../reference/engine/gfx/wind_REF.gc | 82 ++++++++++++++ 10 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 test/decompiler/reference/engine/gfx/wind-h_REF.gc create mode 100644 test/decompiler/reference/engine/gfx/wind_REF.gc diff --git a/Taskfile.yml b/Taskfile.yml index ba9afa2ec9..61c3b1354d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -29,7 +29,9 @@ tasks: - task: decomp decomp-list: cmds: - - python ./scripts/next-decomp-file.py --list + - python ./scripts/next-decomp-file.py --list "{{.LIST}}" + vars: + LIST: '{{default "0" .LIST}}' cleanup-all-types: cmds: - python ./scripts/cleanup-all-types.py diff --git a/decompiler/analysis/insert_lets.cpp b/decompiler/analysis/insert_lets.cpp index 7cabeee1b0..536dfcd372 100644 --- a/decompiler/analysis/insert_lets.cpp +++ b/decompiler/analysis/insert_lets.cpp @@ -1,4 +1,5 @@ #include +#include #include "insert_lets.h" #include "decompiler/IR2/GenericElementMatcher.h" @@ -605,4 +606,4 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l return stats; } -} // namespace decompiler \ No newline at end of file +} // namespace decompiler diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index ed7d4fb192..8c40279d42 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -33575,8 +33575,8 @@ (define-extern game-info type) (define-extern *GAME-bank* game-bank) ;; unknown type (define-extern wind-get-hashed-index (function vector int)) -(define-extern *wind-scales* (array uint8)) ;; unknown type -(define-extern *wind-work* wind-work) ;; unknown type +(define-extern *wind-scales* (array uint8)) +(define-extern *wind-work* wind-work) (define-extern prototype-bucket-tie type) (define-extern proxy-prototype-array-tie type) (define-extern prototype-array-tie type) @@ -34046,7 +34046,7 @@ ;;(define-extern cylinder-flat-verts object) ;; unknown type (define-extern ray-arbitrary-circle-intersect function) (define-extern camera-line function) -(define-extern update-wind function) +(define-extern update-wind (function wind-work (array uint8) none)) (define-extern print-collide-stats function) (define-extern mem-usage-bsp-tree function) ;;(define-extern *test-shrub* object) ;; unknown type diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index 428f42dc8d..7aa5ee95f4 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -275,7 +275,7 @@ ["L373", "uint64", true], ["L371", "uint64", true] ], - + "fact-h": [ ["L36", "float", true], ["L37", "float", true], @@ -294,6 +294,13 @@ "hud-h": [["L1", "hud-parts", true]], + "wind": [ + ["L5", "float", true], + ["L6", "float", true], + ["L7", "float", true], + ["L9", "float", true] + ], + "mood-tables": [ ["L12", "mood-sun-table", true], ["L13", "mood-lights-table", true], diff --git a/goal_src/engine/gfx/wind-h.gc b/goal_src/engine/gfx/wind-h.gc index 28c35e8ec2..a556adcde5 100644 --- a/goal_src/engine/gfx/wind-h.gc +++ b/goal_src/engine/gfx/wind-h.gc @@ -38,6 +38,8 @@ :flag-assert #x900000534 ) +; This was likely originally defined inside `wind-h` +; but the decompiler won't output it, so we have to manually define it (define-extern *wind-work* wind-work) (defun wind-get-hashed-index ((arg0 vector)) diff --git a/goal_src/engine/gfx/wind.gc b/goal_src/engine/gfx/wind.gc index 64ca040a86..6e8ab23a55 100644 --- a/goal_src/engine/gfx/wind.gc +++ b/goal_src/engine/gfx/wind.gc @@ -5,3 +5,78 @@ ;; name in dgo: wind ;; dgos: GAME, ENGINE +;; definition for symbol *wind-work*, type wind-work +(define *wind-work* (new 'global 'wind-work)) + +;; definition for function update-wind +;; INFO: Return type mismatch int vs none. +(defun update-wind ((arg0 wind-work) (arg1 (array uint8))) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) + (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)) + ) + (set! (-> arg0 wind-time) (+ (-> arg0 wind-time) 1)) + (let* ((s4-0 (logand (-> arg0 wind-time) 63)) + (f0-4 (rand-vu-float-range 0.0 100.0)) + (v1-5 (/ (-> 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-5) (-> arg1 length)))) + ) + ) + (f0-5 + (* + (+ + (* + (- + (* + 0.0625 + (the + float + (-> arg1 (mod (the-as int (+ v1-5 1)) (-> arg1 length))) + ) + ) + f2-4 + ) + f1-6 + ) + f2-4 + ) + f0-4 + ) + ) + ) + (set! (-> *wind-work* wind-force s4-0) f0-5) + (let ((v1-14 (-> *wind-work* wind-array s4-0))) + (let ((a0-15 (-> arg0 wind-normal))) + (.lvf vf1 (&-> a0-15 quad)) + ) + (let ((a0-16 f0-5)) + (.mov vf2 a0-16) + ) + (.add.x.vf vf1 vf0 vf0 :mask #b1000) + (.mul.x.vf vf1 vf1 vf2 :mask #b111) + (.svf (&-> v1-14 quad) vf1) + ) + ) + (let ((v0-4 0)) + ) + (none) + ) + ) diff --git a/scripts/next-decomp-file.py b/scripts/next-decomp-file.py index 2fd8bf33c9..698bc532b5 100644 --- a/scripts/next-decomp-file.py +++ b/scripts/next-decomp-file.py @@ -5,7 +5,7 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument("--skip", type=int) parser.add_argument("--file") -parser.add_argument("--list", action="store_true") +parser.add_argument("--list", type=int) args = parser.parse_args() skip_count = 0 @@ -41,7 +41,7 @@ else: if skip_count <= 0 and len(lines) <= 7: if args.list: list_of_eligible.append(file[0]) - if len(list_of_eligible) >= 10: + if len(list_of_eligible) >= args.list: break else: update_file(file) diff --git a/test/decompiler/reference/all_forward_declarations.gc b/test/decompiler/reference/all_forward_declarations.gc index a74bb13ab0..58f2e1d866 100644 --- a/test/decompiler/reference/all_forward_declarations.gc +++ b/test/decompiler/reference/all_forward_declarations.gc @@ -578,4 +578,9 @@ (:methods (dummy-9 () none 9) ) - ) \ No newline at end of file + ) + +; This was likely originally defined inside `wind-h` +; but the decompiler won't output it, so we have to manually define it +(define-extern wind-work type) +(define-extern *wind-work* wind-work) diff --git a/test/decompiler/reference/engine/gfx/wind-h_REF.gc b/test/decompiler/reference/engine/gfx/wind-h_REF.gc new file mode 100644 index 0000000000..a81c5a5cd1 --- /dev/null +++ b/test/decompiler/reference/engine/gfx/wind-h_REF.gc @@ -0,0 +1,104 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type wind-vector +(deftype wind-vector (structure) + ((wind-pos vector2w :inline :offset-assert 0) + (wind-vel vector2w :inline :offset-assert 8) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; definition for method 3 of type wind-vector +(defmethod inspect wind-vector ((obj wind-vector)) + (format #t "[~8x] ~A~%" obj 'wind-vector) + (format #t "~Twind-pos: #~%" (-> obj wind-pos)) + (format #t "~Twind-vel: #~%" (-> obj wind-vel)) + obj + ) + +;; definition for symbol *wind-scales*, type (array uint8) +(define + *wind-scales* + (the-as (array uint8) + (new + 'static + 'boxed-array + uint8 + 32 + #x2 + #x5 + #x2 + #x3 + #x2 + #x2 + #x3 + #x10 + #xa + #x2 + #x4 + #x2 + #x8 + #x2 + #x2 + #x10 + #x2 + #x2 + #x8 + #x2 + #x10 + #x2 + #x4 + #x10 + #xa + #x2 + #x4 + #x2 + #x8 + #x2 + #x2 + #x10 + ) + ) + ) + +;; definition of type wind-work +(deftype wind-work (basic) + ((wind-array vector 64 :inline :offset-assert 16) + (wind-normal vector :inline :offset-assert 1040) + (wind-temp vector :inline :offset-assert 1056) + (wind-force float 64 :offset-assert 1072) + (wind-time uint32 :offset-assert 1328) + ) + :method-count-assert 9 + :size-assert #x534 + :flag-assert #x900000534 + ) + +;; definition for method 3 of type wind-work +(defmethod inspect wind-work ((obj wind-work)) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~Twind-array[64] @ #x~X~%" (-> obj wind-array)) + (format #t "~Twind-normal: ~`vector`P~%" (-> obj wind-normal)) + (format #t "~Twind-temp: ~`vector`P~%" (-> obj wind-temp)) + (format #t "~Twind-force[64] @ #x~X~%" (-> obj wind-force)) + (format #t "~Twind-time: ~D~%" (-> obj wind-time)) + obj + ) + +;; definition for function wind-get-hashed-index +(defun wind-get-hashed-index ((arg0 vector)) + (logand + (+ + (+ (the int (-> arg0 x)) (the int (-> arg0 z))) + (the-as int (-> *wind-work* wind-time)) + ) + 63 + ) + ) + + + + diff --git a/test/decompiler/reference/engine/gfx/wind_REF.gc b/test/decompiler/reference/engine/gfx/wind_REF.gc new file mode 100644 index 0000000000..6f3e150e3f --- /dev/null +++ b/test/decompiler/reference/engine/gfx/wind_REF.gc @@ -0,0 +1,82 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for symbol *wind-work*, type wind-work +(define *wind-work* (new 'global 'wind-work)) + +;; definition for function update-wind +;; INFO: Return type mismatch int vs none. +(defun update-wind ((arg0 wind-work) (arg1 (array uint8))) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) + (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)) + ) + (set! (-> arg0 wind-time) (+ (-> arg0 wind-time) 1)) + (let* ((s4-0 (logand (-> arg0 wind-time) 63)) + (f0-4 (rand-vu-float-range 0.0 100.0)) + (v1-5 (/ (-> 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-5) (-> arg1 length)))) + ) + ) + (f0-5 + (* + (+ + (* + (- + (* + 0.0625 + (the + float + (-> arg1 (mod (the-as int (+ v1-5 1)) (-> arg1 length))) + ) + ) + f2-4 + ) + f1-6 + ) + f2-4 + ) + f0-4 + ) + ) + ) + (set! (-> *wind-work* wind-force s4-0) f0-5) + (let ((v1-14 (-> *wind-work* wind-array s4-0))) + (let ((a0-15 (-> arg0 wind-normal))) + (.lvf vf1 (&-> a0-15 quad)) + ) + (let ((a0-16 f0-5)) + (.mov vf2 a0-16) + ) + (.add.x.vf vf1 vf0 vf0 :mask #b1000) + (.mul.x.vf vf1 vf1 vf2 :mask #b111) + (.svf (&-> v1-14 quad) vf1) + ) + ) + (let ((v0-4 0)) + ) + (none) + ) + ) + + + +