From bdf63b9048e81d62e38a76ec18b7423fcf4593b7 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Mon, 26 Sep 2022 19:40:46 -0400 Subject: [PATCH] [decomp] sync-info, fix some looping type pass bugs (#1925) --- decompiler/IR2/Env.cpp | 6 + decompiler/config/jak2/all-types.gc | 45 +- decompiler/config/jak2/type_casts.jsonc | 12 + decompiler/types2/ForwardProp.cpp | 24 +- goal_src/jak2/engine/util/sync-info-h.gc | 45 +- goal_src/jak2/engine/util/sync-info.gc | 614 ++++++++++++++++ .../jak2/engine/util/sync-info-h_REF.gc | 44 +- .../jak2/engine/util/sync-info_REF.gc | 662 ++++++++++++++++++ 8 files changed, 1374 insertions(+), 78 deletions(-) create mode 100644 test/decompiler/reference/jak2/engine/util/sync-info_REF.gc diff --git a/decompiler/IR2/Env.cpp b/decompiler/IR2/Env.cpp index 5b681bc4ba..a8efa145a1 100644 --- a/decompiler/IR2/Env.cpp +++ b/decompiler/IR2/Env.cpp @@ -519,6 +519,12 @@ void Env::add_stack_structure_hint(const StackStructureHint& hint) { case StackStructureHint::ContainerType::NONE: { // parse the type spec. TypeSpec base_typespec = dts->parse_type_spec(hint.element_type); + if (base_typespec.base_type() == "object") { + throw std::runtime_error( + fmt::format("Got a stack structure hint for type object at offset {}. This is usually " + "a sign that stack structure guessing got inconsistent types.", + hint.stack_offset)); + } auto type_info = dts->ts.lookup_type(base_typespec); // just a plain object on the stack. if (!type_info->is_reference()) { diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index 7515d922df..96a94980e4 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -14305,6 +14305,7 @@ (defenum sync-flags :type uint64 :bitfield #t + (pong 0) ) (deftype sync-info-params (structure) @@ -14332,13 +14333,13 @@ :size-assert #x10 :flag-assert #x1000000010 (:methods - (sync-info-method-9 (_type_) none 9) ;; (get-current-value (_type_ float) float 9) + (get-current-phase-no-mod "Get the current value, with no fancy modifications." (_type_) float 9) (get-phase-offset "Get the offset, as a fraction of period" (_type_) float 10) - (get-norm! "Abstract method, stubbed" (_type_) float 11) - (multiply-norm! "Multiples result of `get-norm!` by the provided float" (_type_ float object) float 12) - (initialize! "Abstract method, stubbed" () none 13) - (sync-info-method-14 (_type_ time-frame) time-frame 14) - (sync-info-method-15 (_type_ float) none 15) ;; (load-params! (_type_ process uint float float float) symbol 15) + (get-norm! "Get the current value, from 0 to 1." (_type_ int) float 11) + (get-scaled-val! "Multiples result of `get-norm!` by the provided float" (_type_ float int) float 12) + (initialize! "Set up a sync-info from params." (_type_ sync-info-params) none 13) + (get-timeframe-offset! "Get the difference between the given time-frame and when this sync-info is at 0." (_type_ time-frame) time-frame 14) + (sync-now! "Adjust our offset so our current phase is the given phase." (_type_ float) none 15) ;; (load-params! (_type_ process uint float float float) symbol 15) ) ) @@ -14390,10 +14391,10 @@ :size-assert #x1c :flag-assert #xd0000001c (:methods - (delayed-rand-float-method-9 () none 9) ;; (set-params! (_type_ int int float) float 9) - (delayed-rand-float-method-10 () none 10) ;; (update! (_type_) float 10) - (delayed-rand-float-method-11 () none 11) - (delayed-rand-float-method-12 () none 12) + (set-params! (_type_ int int float) float 9) + (reset! (_type_) float 10) + (update! (_type_) float 11) + (update-and-clear! (_type_) none 12) ) ) @@ -14409,8 +14410,8 @@ :size-assert #x18 :flag-assert #xb00000018 (:methods - (oscillating-float-method-9 () none 9) ;; (set-params! (_type_ float float float float) float 9) - (oscillating-float-method-10 () none 10) ;; (update! (_type_ float) float 10) + (set-params! (_type_ float float float float) float 9) + (update! (_type_ float) float 10) ) ) @@ -14425,10 +14426,10 @@ :size-assert #x28 :flag-assert #xd00000028 (:methods - (bouncing-float-method-9 () none 9) ;; (set-params! (_type_ float float float float float float float) float 9) - (bouncing-float-method-10 () none 10) ;; (update! (_type_ float) float 10) - (bouncing-float-method-11 () none 11) ;; (at-min? (_type_) symbol 11) - (bouncing-float-method-12 () none 12) ;; (at-max? (_type_) symbol 12) + (set-params! (_type_ float float float float float float float) float 9) + (update! (_type_ float) float 10) + (at-min? (_type_) symbol 11) + (at-max? (_type_) symbol 12) ) ) @@ -14445,10 +14446,10 @@ :size-assert #x30 :flag-assert #xd00000030 (:methods - (delayed-rand-vector-method-9 () none 9) ;; (set-params! (_type_ int int float float) vector 9) - (delayed-rand-vector-method-10 () none 10) ;; (update-now! (_type_) vector 10) - (delayed-rand-vector-method-11 () none 11) ;; (update-with-delay! (_type_) vector 11) - (delayed-rand-vector-method-12 () none 12) ;; (update-with-delay-or-reset! (_type_) vector 12) + (set-params! (_type_ int int float float) vector 9) + (update-now! (_type_) vector 10) + (update-with-delay! (_type_) vector 11) + (update-with-delay-or-reset! (_type_) vector 12) ) ) @@ -14464,8 +14465,8 @@ :size-assert #x3c :flag-assert #xb0000003c (:methods - (oscillating-vector-method-9 () none 9) ;; (set-params! (_type_ vector float float float) vector 9) - (oscillating-vector-method-10 () none 10) ;; (update! (_type_ vector) vector 10) + (set-params! (_type_ vector float float float) vector 9) + (update! (_type_ vector) vector 10) ) ) diff --git a/decompiler/config/jak2/type_casts.jsonc b/decompiler/config/jak2/type_casts.jsonc index b5e5ecbda1..47e1247bb7 100644 --- a/decompiler/config/jak2/type_casts.jsonc +++ b/decompiler/config/jak2/type_casts.jsonc @@ -2672,6 +2672,18 @@ [46, "s5", "collide-shape"], [107, "v1", "manipy"] ], + "(method 13 sync-linear)": [ + ["_stack_", 16, "res-tag"], + [35, "v1", "(pointer float)"] + ], + "(method 13 sync-eased)": [ + ["_stack_", 16, "res-tag"], + [[31, 54], "v1", "(pointer float)"] + ], + "(method 13 sync-paused)": [ + ["_stack_", 16, "res-tag"], + [[29, 45], "v1", "(pointer float)"] + ], // placeholder "placeholder-do-not-add-below": [] } diff --git a/decompiler/types2/ForwardProp.cpp b/decompiler/types2/ForwardProp.cpp index fd20a6aeac..25babbd6ad 100644 --- a/decompiler/types2/ForwardProp.cpp +++ b/decompiler/types2/ForwardProp.cpp @@ -265,16 +265,20 @@ bool backprop_tagged_type(const TP_Type& expected_type, if (actual_type.tag.block_entry->selected_type == expected_type) { return false; } - if (actual_type.tag.block_entry->selected_type->typespec().base_type() == "vector" && - expected_type.typespec().base_type() == "vector4") { - return false; - } } { - actual_type.tag.block_entry->updated = true; - actual_type.tag.block_entry->selected_type = expected_type; - return true; + if (!actual_type.tag.block_entry->selected_type) { + actual_type.tag.block_entry->selected_type = expected_type; + actual_type.tag.block_entry->updated = true; + return true; + } else { + bool changed = false; + actual_type.tag.block_entry->selected_type = dts.tp_lca( + actual_type.tag.block_entry->selected_type.value(), expected_type, &changed); + actual_type.tag.block_entry->updated = changed; + return changed; + } } case types2::Tag::UNKNOWN_LABEL: @@ -284,8 +288,6 @@ bool backprop_tagged_type(const TP_Type& expected_type, } else { auto& tag = actual_type.tag.unknown_label; actual_type.tag.unknown_label->selected_type = expected_type.typespec(); - fmt::print("Label Guess: {} is a {}\n", tag->label_name, - actual_type.tag.unknown_label->selected_type->print()); return true; } @@ -296,8 +298,6 @@ bool backprop_tagged_type(const TP_Type& expected_type, } else { auto& tag = actual_type.tag.unknown_stack_structure; actual_type.tag.unknown_stack_structure->selected_type = expected_type.typespec(); - fmt::print("Stack Guess: {} is a {}\n", tag->stack_offset, - actual_type.tag.unknown_stack_structure->selected_type->print()); return true; } @@ -1438,7 +1438,7 @@ void types2_for_vector_float_product(types2::Type& type_out, auto& arg = expr.get_arg(i); auto& arg_type = input_types[arg.var().reg()]; if (arg_type->tag.has_tag()) { - if (types2::backprop_tagged_type(TP_Type::make_from_ts(i == 0 ? "vector" : "float"), + if (types2::backprop_tagged_type(TP_Type::make_from_ts(i == 2 ? "float" : "vector"), *arg_type, dts)) { extras.needs_rerun = true; } diff --git a/goal_src/jak2/engine/util/sync-info-h.gc b/goal_src/jak2/engine/util/sync-info-h.gc index 73b0636d4d..66ff356920 100644 --- a/goal_src/jak2/engine/util/sync-info-h.gc +++ b/goal_src/jak2/engine/util/sync-info-h.gc @@ -8,6 +8,7 @@ (defenum sync-flags :type uint64 :bitfield #t + (pong 0) ) ;; DECOMP BEGINS @@ -36,13 +37,13 @@ :size-assert #x10 :flag-assert #x1000000010 (:methods - (sync-info-method-9 (_type_) none 9) + (get-current-phase-no-mod (_type_) float 9) (get-phase-offset (_type_) float 10) - (get-norm! (_type_) float 11) - (multiply-norm! (_type_ float object) float 12) - (initialize! () none 13) - (sync-info-method-14 (_type_ time-frame) time-frame 14) - (sync-info-method-15 (_type_ float) none 15) + (get-norm! (_type_ int) float 11) + (get-scaled-val! (_type_ float int) float 12) + (initialize! (_type_ sync-info-params) none 13) + (get-timeframe-offset! (_type_ time-frame) time-frame 14) + (sync-now! (_type_ float) none 15) ) ) @@ -88,10 +89,10 @@ :size-assert #x1c :flag-assert #xd0000001c (:methods - (delayed-rand-float-method-9 () none 9) - (delayed-rand-float-method-10 () none 10) - (delayed-rand-float-method-11 () none 11) - (delayed-rand-float-method-12 () none 12) + (set-params! (_type_ int int float) float 9) + (reset! (_type_) float 10) + (update! (_type_) float 11) + (update-and-clear! (_type_) none 12) ) ) @@ -107,8 +108,8 @@ :size-assert #x18 :flag-assert #xb00000018 (:methods - (oscillating-float-method-9 () none 9) - (oscillating-float-method-10 () none 10) + (set-params! (_type_ float float float float) float 9) + (update! (_type_ float) float 10) ) ) @@ -123,10 +124,10 @@ :size-assert #x28 :flag-assert #xd00000028 (:methods - (bouncing-float-method-9 () none 9) - (bouncing-float-method-10 () none 10) - (bouncing-float-method-11 () none 11) - (bouncing-float-method-12 () none 12) + (set-params! (_type_ float float float float float float float) float 9) + (update! (_type_ float) float 10) + (at-min? (_type_) symbol 11) + (at-max? (_type_) symbol 12) ) ) @@ -143,10 +144,10 @@ :size-assert #x30 :flag-assert #xd00000030 (:methods - (delayed-rand-vector-method-9 () none 9) - (delayed-rand-vector-method-10 () none 10) - (delayed-rand-vector-method-11 () none 11) - (delayed-rand-vector-method-12 () none 12) + (set-params! (_type_ int int float float) vector 9) + (update-now! (_type_) vector 10) + (update-with-delay! (_type_) vector 11) + (update-with-delay-or-reset! (_type_) vector 12) ) ) @@ -162,7 +163,7 @@ :size-assert #x3c :flag-assert #xb0000003c (:methods - (oscillating-vector-method-9 () none 9) - (oscillating-vector-method-10 () none 10) + (set-params! (_type_ vector float float float) vector 9) + (update! (_type_ vector) vector 10) ) ) diff --git a/goal_src/jak2/engine/util/sync-info.gc b/goal_src/jak2/engine/util/sync-info.gc index b5fefe1362..fc192b67bb 100644 --- a/goal_src/jak2/engine/util/sync-info.gc +++ b/goal_src/jak2/engine/util/sync-info.gc @@ -7,3 +7,617 @@ ;; DECOMP BEGINS +(defmethod initialize! sync-info ((obj sync-info) (arg0 sync-info-params)) + "Set up a sync-info from params." + (format 0 "ERROR: Invalid call to sync-info::initialize!~%") + (none) + ) + +(defmethod get-current-phase-no-mod sync-info ((obj sync-info)) + "Get the current value, with no fancy modifications." + (with-pp + (let* ((v1-0 (-> obj period)) + (f0-1 (the float v1-0)) + (f1-2 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) v1-0)) (-> obj offset))) + ) + (/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1) + ) + ) + ) + +(defmethod get-phase-offset sync-info ((obj sync-info)) + "Get the offset, as a fraction of period" + (/ (-> obj offset) (the float (-> obj period))) + ) + +(defmethod sync-now! sync-info ((obj sync-info) (arg0 float)) + "Adjust our offset so our current phase is the given phase." + (with-pp + (let* ((a2-0 (-> obj period)) + (f0-1 (the float a2-0)) + (v1-0 (- arg0 (* (the float (the int (/ arg0 f0-1))) f0-1))) + (f1-4 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) a2-0)) (-> obj offset))) + (f1-6 (/ (- f1-4 (* (the float (the int (/ f1-4 f0-1))) f0-1)) f0-1)) + (f1-10 (+ (* (- v1-0 f1-6) f0-1) f0-1 (-> obj offset))) + ) + (set! (-> obj offset) (- f1-10 (* (the float (the int (/ f1-10 f0-1))) f0-1))) + ) + 0 + (none) + ) + ) + +(defmethod get-norm! sync-info ((obj sync-info) (arg0 int)) + "Get the current value, from 0 to 1." + (format 0 "ERROR: Unsupported sync-info::get-norm!~%") + 0.0 + ) + +(defmethod get-scaled-val! sync-info ((obj sync-info) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +(defmethod get-timeframe-offset! sync-info ((obj sync-info) (arg0 time-frame)) + "Get the difference between the given time-frame and when this sync-info is at 0." + (with-pp + (if (zero? arg0) + (set! arg0 (-> pp clock frame-counter)) + ) + (let* ((v1-4 (-> obj period)) + (f0-1 (the float v1-4)) + (f1-2 (+ (the float (mod arg0 (the-as time-frame v1-4))) (-> obj offset))) + ) + (+ arg0 (the int (- f0-1 (* (/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1) f0-1)))) + ) + ) + ) + +(defmethod initialize! sync-linear ((obj sync-linear) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-linear) + (format + 0 + "ERROR: Using wrong sync params in sync-linear::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s4-0 (the-as int (-> arg0 period))) + (f30-0 (-> arg0 percent)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync pointer :tag-ptr (& sv-16)))) + (when v1-6 + (set! s4-0 (the int (* 300.0 (-> (the-as (pointer float) v1-6))))) + (set! f30-0 (-> (the-as (pointer float) v1-6) 1)) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s4-0)) + (let* ((f0-4 (the float s4-0)) + (f1-1 (* f30-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + ) + (none) + ) + +(defmethod get-norm! sync-linear ((obj sync-linear) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f0-1 (the float v1-4)) + ) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f1-0 2.0) + (f2-2 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f0-3 (* f1-0 (/ (- f2-2 (* (the float (the int (/ f2-2 f0-1))) f0-1)) f0-1))) + ) + (if (>= f0-3 1.0) + (set! f0-3 (- 2.0 f0-3)) + ) + f0-3 + ) + ) + (else + (let ((f1-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))) + (/ (- f1-5 (* (the float (the int (/ f1-5 f0-1))) f0-1)) f0-1) + ) + ) + ) + ) + ) + ) + +(defmethod get-scaled-val! sync-linear ((obj sync-linear) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +(defmethod initialize! sync-eased ((obj sync-eased) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-eased) + (format + 0 + "ERROR: Using wrong sync params in sync-eased::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s5-0 (the-as int (-> arg0 period))) + (f22-0 (-> arg0 percent)) + (f24-0 (-> arg0 pause-in)) + (f26-0 (-> arg0 pause-out)) + (f30-0 (-> arg0 ease-in)) + (f28-0 (-> arg0 ease-out)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16)))) + (when v1-6 + (set! s5-0 (the int (* 300.0 (-> v1-6 0)))) + (set! f22-0 (-> v1-6 1)) + (when (>= (-> sv-16 elt-count) (the-as uint 4)) + (set! f30-0 (-> v1-6 2)) + (set! f28-0 (-> v1-6 3)) + (when (>= (-> sv-16 elt-count) (the-as uint 6)) + (set! f24-0 (-> v1-6 4)) + (set! f26-0 (-> v1-6 5)) + ) + ) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s5-0)) + (let* ((f0-4 (the float s5-0)) + (f1-1 (* f22-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + (cond + ((< f26-0 0.0) + (set! f26-0 0.0) + ) + ((< 1.0 f26-0) + (set! f26-0 1.0) + ) + ) + (cond + ((< f24-0 0.0) + (set! f24-0 0.0) + ) + ((< (- 1.0 f26-0) f24-0) + (set! f24-0 (- 1.0 f26-0)) + ) + ) + (let ((f0-14 (the float s5-0))) + (set! (-> obj pause-in) (* f24-0 f0-14)) + (set! (-> obj pause-out) (* f26-0 f0-14)) + ) + (if (< f30-0 0.0) + (set! f30-0 0.0) + ) + (if (< 1.0 f30-0) + (set! f30-0 1.0) + ) + (if (< f28-0 0.001) + (set! f28-0 0.001) + ) + (if (< 1.0 f28-0) + (set! f28-0 1.0) + ) + (let ((f0-20 (+ f30-0 f28-0))) + (when (< 1.0 f0-20) + (set! f0-20 1.0) + (set! f30-0 (- 1.0 f28-0)) + ) + (let* ((f1-6 (- 1.0 f0-20)) + (f0-21 f30-0) + (f1-7 (+ f30-0 f1-6)) + (f2-3 (* f0-21 f0-21)) + (f3-3 (+ (* 2.0 f0-21 (- f1-7 f0-21)) f2-3)) + (f4-3 (/ f0-21 (- 1.0 f1-7))) + (f3-4 (+ (* (- 1.0 f1-7) (- 1.0 f1-7) f4-3) f3-3)) + ) + (set! (-> obj tlo) f0-21) + (set! (-> obj thi) f1-7) + (set! (-> obj ylo) f2-3) + (set! (-> obj m2) f4-3) + (set! (-> obj yend) f3-4) + ) + ) + ) + (none) + ) + +(defmethod get-norm! sync-eased ((obj sync-eased) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f3-0 (the float v1-4)) + (f0-1 (-> obj pause-in)) + (f2-0 (-> obj pause-out)) + (f1-1 (* 0.5 (- f3-0 (+ f0-1 f2-0)))) + ) + (the int (+ f0-1 f2-0 f3-0)) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f4-7 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-2 (- f4-7 (* (the float (the int (/ f4-7 f3-0))) f3-0))) + (v1-6 #f) + ) + (when (>= f3-2 (+ f1-1 f0-1)) + (set! v1-6 #t) + (set! f3-2 (- f3-2 (+ f1-1 f0-1))) + f0-1 + (set! f0-1 f2-0) + ) + (cond + ((< f3-2 f0-1) + (set! f3-2 f0-1) + ) + ((< (+ f0-1 f1-1) f3-2) + (set! f3-2 (+ f0-1 f1-1)) + ) + ) + (let* ((f0-3 (/ (- f3-2 f0-1) f1-1)) + (f1-2 (-> obj tlo)) + (f0-8 (/ (cond + ((< f0-3 f1-2) + (* f0-3 f0-3) + ) + ((< f0-3 (-> obj thi)) + (+ (* 2.0 f1-2 (- f0-3 f1-2)) (-> obj ylo)) + ) + (else + (let ((f1-5 (- 1.0 f0-3))) + (- (-> obj yend) (* f1-5 f1-5 (-> obj m2))) + ) + ) + ) + (-> obj yend) + ) + ) + ) + (if v1-6 + (set! f0-8 (- 1.0 f0-8)) + ) + f0-8 + ) + ) + ) + (else + (format 0 "ERROR: Attempting to use sync-eased in unsupported non-pong mode.~%") + 0.0 + ) + ) + ) + ) + ) + +(defmethod get-scaled-val! sync-eased ((obj sync-eased) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +(defmethod initialize! sync-paused ((obj sync-paused) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-paused) + (format + 0 + "ERROR: Using wrong sync params in sync-paused::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s5-0 (the-as int (-> arg0 period))) + (f26-0 (-> arg0 percent)) + (f28-0 (-> arg0 pause-in)) + (f30-0 (-> arg0 pause-out)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16)))) + (when v1-6 + (set! s5-0 (the int (* 300.0 (-> v1-6 0)))) + (set! f26-0 (-> v1-6 1)) + (when (>= (-> sv-16 elt-count) (the-as uint 4)) + (set! f28-0 (-> v1-6 2)) + (set! f30-0 (-> v1-6 3)) + ) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s5-0)) + (let* ((f0-4 (the float s5-0)) + (f1-1 (* f26-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + (cond + ((< f30-0 0.0) + (set! f30-0 0.0) + ) + ((< 1.0 f30-0) + (set! f30-0 1.0) + ) + ) + (cond + ((< f28-0 0.0) + (set! f28-0 0.0) + ) + ((< (- 1.0 f30-0) f28-0) + (set! f28-0 (- 1.0 f30-0)) + ) + ) + (let ((f0-14 (the float s5-0))) + (set! (-> obj pause-in) (* f28-0 f0-14)) + (set! (-> obj pause-out) (* f30-0 f0-14)) + ) + ) + (none) + ) + +(defmethod get-norm! sync-paused ((obj sync-paused) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f2-0 (the float v1-4)) + (f0-1 (-> obj pause-in)) + (f1-0 (-> obj pause-out)) + ) + (the int (+ f0-1 f1-0 f2-0)) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f3-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-6 (- f3-5 (* (the float (the int (/ f3-5 f2-0))) f2-0))) + (f2-2 (* 0.5 (- f2-0 (+ f0-1 f1-0)))) + (v1-7 #f) + ) + (when (>= f3-6 (+ f2-2 f0-1)) + (set! v1-7 #t) + (set! f3-6 (- f3-6 (+ f2-2 f0-1))) + (set! f0-1 f1-0) + ) + (let* ((f1-1 (/ (- f3-6 f0-1) f2-2)) + (f0-5 (fmax 0.0 (fmin 1.0 f1-1))) + ) + (if v1-7 + (set! f0-5 (- 1.0 f0-5)) + ) + f0-5 + ) + ) + ) + (else + (let* ((f3-9 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-10 (- f3-9 (* (the float (the int (/ f3-9 f2-0))) f2-0))) + (f1-5 (- f2-0 (+ f0-1 f1-0))) + (f1-6 (/ (- f3-10 f0-1) f1-5)) + ) + (fmax 0.0 (fmin 1.0 f1-6)) + ) + ) + ) + ) + ) + ) + +(defmethod get-scaled-val! sync-paused ((obj sync-paused) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +(defmethod set-params! delayed-rand-float ((obj delayed-rand-float) (arg0 int) (arg1 int) (arg2 float)) + (set! (-> obj min-time) arg0) + (set! (-> obj max-time) arg1) + (set! (-> obj max-val) (* 0.5 arg2)) + (set! (-> obj start-time) 0) + (set! (-> obj timer) 0) + (set! (-> obj value) 0.0) + (-> obj value) + ) + +(defmethod reset! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (set! (-> obj start-time) (-> pp clock frame-counter)) + (set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time))) + (set! (-> obj value) (rand-vu-float-range (- (-> obj max-val)) (-> obj max-val))) + ) + ) + +(defmethod update! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (reset! obj) + ) + (-> obj value) + ) + ) + +(defmethod update-and-clear! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (reset! obj) + (set! (-> obj value) 0.0) + ) + (-> obj value) + (none) + ) + ) + +(defmethod set-params! oscillating-float ((obj oscillating-float) (arg0 float) (arg1 float) (arg2 float) (arg3 float)) + (set! (-> obj value) arg0) + (set! (-> obj target) arg0) + (set! (-> obj vel) 0.0) + (set! (-> obj max-vel) arg2) + (set! (-> obj damping) arg3) + (set! (-> obj accel) arg1) + (-> obj value) + ) + +(defmethod update! oscillating-float ((obj oscillating-float) (arg0 float)) + (with-pp + (let ((f0-3 (* (- (+ (-> obj target) arg0) (-> obj value)) (* (-> obj accel) (-> pp clock time-adjust-ratio))))) + (+! (-> obj vel) f0-3) + ) + (set! (-> obj vel) (fmin (-> obj max-vel) (fmax (- (-> obj max-vel)) (-> obj vel)))) + (set! (-> obj vel) (* (-> obj vel) (-> obj damping))) + (+! (-> obj value) (* (-> obj vel) (-> pp clock time-adjust-ratio))) + (-> obj value) + ) + ) + +(defmethod set-params! bouncing-float ((obj bouncing-float) + (arg0 float) + (arg1 float) + (arg2 float) + (arg3 float) + (arg4 float) + (arg5 float) + (arg6 float) + ) + (set-params! (-> obj osc) arg0 arg4 arg5 arg6) + (set! (-> obj max-value) arg1) + (set! (-> obj min-value) arg2) + (set! (-> obj elasticity) arg3) + (set! (-> obj state) 0) + (-> obj osc value) + ) + +(defmethod update! bouncing-float ((obj bouncing-float) (arg0 float)) + (update! (-> obj osc) arg0) + (set! (-> obj state) 0) + (when (>= (-> obj osc value) (-> obj max-value)) + (set! (-> obj osc value) (-> obj max-value)) + (if (< 0.0 (-> obj osc vel)) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) + ) + (set! (-> obj state) 1) + ) + (when (>= (-> obj min-value) (-> obj osc value)) + (set! (-> obj osc value) (-> obj min-value)) + (if (< (-> obj osc vel) 0.0) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) + ) + (set! (-> obj state) -1) + ) + (-> obj osc value) + ) + +(defmethod at-min? bouncing-float ((obj bouncing-float)) + (= (-> obj state) -1) + ) + +(defmethod at-max? bouncing-float ((obj bouncing-float)) + (= (-> obj state) 1) + ) + +(defmethod set-params! delayed-rand-vector ((obj delayed-rand-vector) (arg0 int) (arg1 int) (arg2 float) (arg3 float)) + (set! (-> obj min-time) arg0) + (set! (-> obj max-time) arg1) + (set! (-> obj xz-max) (* 0.5 arg2)) + (set! (-> obj y-max) (* 0.5 arg3)) + (set! (-> obj start-time) 0) + (set! (-> obj timer) 0) + (vector-reset! (-> obj value)) + (-> obj value) + ) + +(defmethod update-now! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (set! (-> obj start-time) (-> pp clock frame-counter)) + (set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time))) + (set! (-> obj value x) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max))) + (set! (-> obj value y) (rand-vu-float-range (- (-> obj y-max)) (-> obj y-max))) + (set! (-> obj value z) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max))) + (-> obj value) + ) + ) + +(defmethod update-with-delay! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (update-now! obj) + ) + (-> obj value) + ) + ) + +(defmethod update-with-delay-or-reset! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (update-now! obj) + (vector-reset! (-> obj value)) + ) + (-> obj value) + ) + ) + +(defmethod set-params! oscillating-vector ((obj oscillating-vector) (arg0 vector) (arg1 float) (arg2 float) (arg3 float)) + (cond + (arg0 + (set! (-> obj value quad) (-> arg0 quad)) + (set! (-> obj target quad) (-> arg0 quad)) + ) + (else + (vector-reset! (-> obj value)) + (vector-reset! (-> obj target)) + ) + ) + (vector-reset! (-> obj vel)) + (set! (-> obj max-vel) arg2) + (set! (-> obj damping) arg3) + (set! (-> obj accel) arg1) + (-> obj value) + ) + +(defmethod update! oscillating-vector ((obj oscillating-vector) (arg0 vector)) + (with-pp + (let ((v1-0 (new 'stack-no-clear 'vector))) + (cond + (arg0 + (vector+! v1-0 (-> obj target) arg0) + (vector-! v1-0 v1-0 (-> obj value)) + ) + (else + (vector-! v1-0 (-> obj target) (-> obj value)) + ) + ) + (vector-float*! v1-0 v1-0 (* (-> obj accel) (-> pp clock time-adjust-ratio))) + (vector+! (-> obj vel) (-> obj vel) v1-0) + (let ((f0-2 (vector-length (-> obj vel)))) + (if (< (-> obj max-vel) f0-2) + (vector-float*! (-> obj vel) (-> obj vel) (/ (-> obj max-vel) f0-2)) + ) + ) + (vector-float*! (-> obj vel) (-> obj vel) (-> obj damping)) + (vector-float*! v1-0 (-> obj vel) (-> pp clock time-adjust-ratio)) + (vector+! (-> obj value) (-> obj value) v1-0) + ) + (-> obj value) + ) + ) + diff --git a/test/decompiler/reference/jak2/engine/util/sync-info-h_REF.gc b/test/decompiler/reference/jak2/engine/util/sync-info-h_REF.gc index 63df5a36d4..0ba2e69027 100644 --- a/test/decompiler/reference/jak2/engine/util/sync-info-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/util/sync-info-h_REF.gc @@ -48,13 +48,13 @@ :size-assert #x10 :flag-assert #x1000000010 (:methods - (sync-info-method-9 (_type_) none 9) + (get-current-phase-no-mod (_type_) float 9) (get-phase-offset (_type_) float 10) - (get-norm! (_type_) float 11) - (multiply-norm! (_type_ float object) float 12) - (initialize! () none 13) - (sync-info-method-14 (_type_ time-frame) time-frame 14) - (sync-info-method-15 (_type_ float) none 15) + (get-norm! (_type_ int) float 11) + (get-scaled-val! (_type_ float int) float 12) + (initialize! (_type_ sync-info-params) none 13) + (get-timeframe-offset! (_type_ time-frame) time-frame 14) + (sync-now! (_type_ float) none 15) ) ) @@ -169,10 +169,10 @@ :size-assert #x1c :flag-assert #xd0000001c (:methods - (delayed-rand-float-method-9 () none 9) - (delayed-rand-float-method-10 () none 10) - (delayed-rand-float-method-11 () none 11) - (delayed-rand-float-method-12 () none 12) + (set-params! (_type_ int int float) float 9) + (reset! (_type_) float 10) + (update! (_type_) float 11) + (update-and-clear! (_type_) none 12) ) ) @@ -206,8 +206,8 @@ :size-assert #x18 :flag-assert #xb00000018 (:methods - (oscillating-float-method-9 () none 9) - (oscillating-float-method-10 () none 10) + (set-params! (_type_ float float float float) float 9) + (update! (_type_ float) float 10) ) ) @@ -240,10 +240,10 @@ :size-assert #x28 :flag-assert #xd00000028 (:methods - (bouncing-float-method-9 () none 9) - (bouncing-float-method-10 () none 10) - (bouncing-float-method-11 () none 11) - (bouncing-float-method-12 () none 12) + (set-params! (_type_ float float float float float float float) float 9) + (update! (_type_ float) float 10) + (at-min? (_type_) symbol 11) + (at-max? (_type_) symbol 12) ) ) @@ -277,10 +277,10 @@ :size-assert #x30 :flag-assert #xd00000030 (:methods - (delayed-rand-vector-method-9 () none 9) - (delayed-rand-vector-method-10 () none 10) - (delayed-rand-vector-method-11 () none 11) - (delayed-rand-vector-method-12 () none 12) + (set-params! (_type_ int int float float) vector 9) + (update-now! (_type_) vector 10) + (update-with-delay! (_type_) vector 11) + (update-with-delay-or-reset! (_type_) vector 12) ) ) @@ -315,8 +315,8 @@ :size-assert #x3c :flag-assert #xb0000003c (:methods - (oscillating-vector-method-9 () none 9) - (oscillating-vector-method-10 () none 10) + (set-params! (_type_ vector float float float) vector 9) + (update! (_type_ vector) vector 10) ) ) diff --git a/test/decompiler/reference/jak2/engine/util/sync-info_REF.gc b/test/decompiler/reference/jak2/engine/util/sync-info_REF.gc new file mode 100644 index 0000000000..1a173c070b --- /dev/null +++ b/test/decompiler/reference/jak2/engine/util/sync-info_REF.gc @@ -0,0 +1,662 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 13 of type sync-info +;; WARN: Return type mismatch object vs none. +(defmethod initialize! sync-info ((obj sync-info) (arg0 sync-info-params)) + "Set up a sync-info from params." + (format 0 "ERROR: Invalid call to sync-info::initialize!~%") + (none) + ) + +;; definition for method 9 of type sync-info +(defmethod get-current-phase-no-mod sync-info ((obj sync-info)) + "Get the current value, with no fancy modifications." + (with-pp + (let* ((v1-0 (-> obj period)) + (f0-1 (the float v1-0)) + (f1-2 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) v1-0)) (-> obj offset))) + ) + (/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1) + ) + ) + ) + +;; definition for method 10 of type sync-info +(defmethod get-phase-offset sync-info ((obj sync-info)) + "Get the offset, as a fraction of period" + (/ (-> obj offset) (the float (-> obj period))) + ) + +;; definition for method 15 of type sync-info +;; WARN: Return type mismatch int vs none. +(defmethod sync-now! sync-info ((obj sync-info) (arg0 float)) + "Adjust our offset so our current phase is the given phase." + (with-pp + (let* ((a2-0 (-> obj period)) + (f0-1 (the float a2-0)) + (v1-0 (- arg0 (* (the float (the int (/ arg0 f0-1))) f0-1))) + (f1-4 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) a2-0)) (-> obj offset))) + (f1-6 (/ (- f1-4 (* (the float (the int (/ f1-4 f0-1))) f0-1)) f0-1)) + (f1-10 (+ (* (- v1-0 f1-6) f0-1) f0-1 (-> obj offset))) + ) + (set! (-> obj offset) (- f1-10 (* (the float (the int (/ f1-10 f0-1))) f0-1))) + ) + 0 + (none) + ) + ) + +;; definition for method 11 of type sync-info +(defmethod get-norm! sync-info ((obj sync-info) (arg0 int)) + "Get the current value, from 0 to 1." + (format 0 "ERROR: Unsupported sync-info::get-norm!~%") + 0.0 + ) + +;; definition for method 12 of type sync-info +(defmethod get-scaled-val! sync-info ((obj sync-info) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +;; definition for method 14 of type sync-info +(defmethod get-timeframe-offset! sync-info ((obj sync-info) (arg0 time-frame)) + "Get the difference between the given time-frame and when this sync-info is at 0." + (with-pp + (if (zero? arg0) + (set! arg0 (-> pp clock frame-counter)) + ) + (let* ((v1-4 (-> obj period)) + (f0-1 (the float v1-4)) + (f1-2 (+ (the float (mod arg0 (the-as time-frame v1-4))) (-> obj offset))) + ) + (+ arg0 (the int (- f0-1 (* (/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1) f0-1)))) + ) + ) + ) + +;; definition for method 13 of type sync-linear +;; INFO: Used lq/sq +;; WARN: Return type mismatch float vs none. +(defmethod initialize! sync-linear ((obj sync-linear) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-linear) + (format + 0 + "ERROR: Using wrong sync params in sync-linear::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s4-0 (the-as int (-> arg0 period))) + (f30-0 (-> arg0 percent)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync pointer :tag-ptr (& sv-16)))) + (when v1-6 + (set! s4-0 (the int (* 300.0 (-> (the-as (pointer float) v1-6))))) + (set! f30-0 (-> (the-as (pointer float) v1-6) 1)) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s4-0)) + (let* ((f0-4 (the float s4-0)) + (f1-1 (* f30-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + ) + (none) + ) + +;; definition for method 11 of type sync-linear +(defmethod get-norm! sync-linear ((obj sync-linear) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f0-1 (the float v1-4)) + ) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f1-0 2.0) + (f2-2 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f0-3 (* f1-0 (/ (- f2-2 (* (the float (the int (/ f2-2 f0-1))) f0-1)) f0-1))) + ) + (if (>= f0-3 1.0) + (set! f0-3 (- 2.0 f0-3)) + ) + f0-3 + ) + ) + (else + (let ((f1-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))) + (/ (- f1-5 (* (the float (the int (/ f1-5 f0-1))) f0-1)) f0-1) + ) + ) + ) + ) + ) + ) + +;; definition for method 12 of type sync-linear +(defmethod get-scaled-val! sync-linear ((obj sync-linear) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +;; definition for method 13 of type sync-eased +;; INFO: Used lq/sq +;; WARN: Return type mismatch float vs none. +(defmethod initialize! sync-eased ((obj sync-eased) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-eased) + (format + 0 + "ERROR: Using wrong sync params in sync-eased::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s5-0 (the-as int (-> arg0 period))) + (f22-0 (-> arg0 percent)) + (f24-0 (-> arg0 pause-in)) + (f26-0 (-> arg0 pause-out)) + (f30-0 (-> arg0 ease-in)) + (f28-0 (-> arg0 ease-out)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16)))) + (when v1-6 + (set! s5-0 (the int (* 300.0 (-> v1-6 0)))) + (set! f22-0 (-> v1-6 1)) + (when (>= (-> sv-16 elt-count) (the-as uint 4)) + (set! f30-0 (-> v1-6 2)) + (set! f28-0 (-> v1-6 3)) + (when (>= (-> sv-16 elt-count) (the-as uint 6)) + (set! f24-0 (-> v1-6 4)) + (set! f26-0 (-> v1-6 5)) + ) + ) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s5-0)) + (let* ((f0-4 (the float s5-0)) + (f1-1 (* f22-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + (cond + ((< f26-0 0.0) + (set! f26-0 0.0) + ) + ((< 1.0 f26-0) + (set! f26-0 1.0) + ) + ) + (cond + ((< f24-0 0.0) + (set! f24-0 0.0) + ) + ((< (- 1.0 f26-0) f24-0) + (set! f24-0 (- 1.0 f26-0)) + ) + ) + (let ((f0-14 (the float s5-0))) + (set! (-> obj pause-in) (* f24-0 f0-14)) + (set! (-> obj pause-out) (* f26-0 f0-14)) + ) + (if (< f30-0 0.0) + (set! f30-0 0.0) + ) + (if (< 1.0 f30-0) + (set! f30-0 1.0) + ) + (if (< f28-0 0.001) + (set! f28-0 0.001) + ) + (if (< 1.0 f28-0) + (set! f28-0 1.0) + ) + (let ((f0-20 (+ f30-0 f28-0))) + (when (< 1.0 f0-20) + (set! f0-20 1.0) + (set! f30-0 (- 1.0 f28-0)) + ) + (let* ((f1-6 (- 1.0 f0-20)) + (f0-21 f30-0) + (f1-7 (+ f30-0 f1-6)) + (f2-3 (* f0-21 f0-21)) + (f3-3 (+ (* 2.0 f0-21 (- f1-7 f0-21)) f2-3)) + (f4-3 (/ f0-21 (- 1.0 f1-7))) + (f3-4 (+ (* (- 1.0 f1-7) (- 1.0 f1-7) f4-3) f3-3)) + ) + (set! (-> obj tlo) f0-21) + (set! (-> obj thi) f1-7) + (set! (-> obj ylo) f2-3) + (set! (-> obj m2) f4-3) + (set! (-> obj yend) f3-4) + ) + ) + ) + (none) + ) + +;; definition for method 11 of type sync-eased +(defmethod get-norm! sync-eased ((obj sync-eased) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f3-0 (the float v1-4)) + (f0-1 (-> obj pause-in)) + (f2-0 (-> obj pause-out)) + (f1-1 (* 0.5 (- f3-0 (+ f0-1 f2-0)))) + ) + (the int (+ f0-1 f2-0 f3-0)) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f4-7 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-2 (- f4-7 (* (the float (the int (/ f4-7 f3-0))) f3-0))) + (v1-6 #f) + ) + (when (>= f3-2 (+ f1-1 f0-1)) + (set! v1-6 #t) + (set! f3-2 (- f3-2 (+ f1-1 f0-1))) + f0-1 + (set! f0-1 f2-0) + ) + (cond + ((< f3-2 f0-1) + (set! f3-2 f0-1) + ) + ((< (+ f0-1 f1-1) f3-2) + (set! f3-2 (+ f0-1 f1-1)) + ) + ) + (let* ((f0-3 (/ (- f3-2 f0-1) f1-1)) + (f1-2 (-> obj tlo)) + (f0-8 (/ (cond + ((< f0-3 f1-2) + (* f0-3 f0-3) + ) + ((< f0-3 (-> obj thi)) + (+ (* 2.0 f1-2 (- f0-3 f1-2)) (-> obj ylo)) + ) + (else + (let ((f1-5 (- 1.0 f0-3))) + (- (-> obj yend) (* f1-5 f1-5 (-> obj m2))) + ) + ) + ) + (-> obj yend) + ) + ) + ) + (if v1-6 + (set! f0-8 (- 1.0 f0-8)) + ) + f0-8 + ) + ) + ) + (else + (format 0 "ERROR: Attempting to use sync-eased in unsupported non-pong mode.~%") + 0.0 + ) + ) + ) + ) + ) + +;; definition for method 12 of type sync-eased +(defmethod get-scaled-val! sync-eased ((obj sync-eased) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +;; definition for method 13 of type sync-paused +;; INFO: Used lq/sq +;; WARN: Return type mismatch float vs none. +(defmethod initialize! sync-paused ((obj sync-paused) (arg0 sync-info-params)) + "Set up a sync-info from params." + (local-vars (sv-16 res-tag)) + (if (!= (-> arg0 sync-type) 'sync-paused) + (format + 0 + "ERROR: Using wrong sync params in sync-paused::initialize (got ~A)! Fix this!~%" + (-> arg0 sync-type) + ) + ) + (set! (-> obj sync-flags) (-> arg0 sync-flags)) + (let ((s5-0 (the-as int (-> arg0 period))) + (f26-0 (-> arg0 percent)) + (f28-0 (-> arg0 pause-in)) + (f30-0 (-> arg0 pause-out)) + ) + (let ((a0-3 (-> arg0 entity))) + (when a0-3 + (set! sv-16 (new 'static 'res-tag)) + (let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16)))) + (when v1-6 + (set! s5-0 (the int (* 300.0 (-> v1-6 0)))) + (set! f26-0 (-> v1-6 1)) + (when (>= (-> sv-16 elt-count) (the-as uint 4)) + (set! f28-0 (-> v1-6 2)) + (set! f30-0 (-> v1-6 3)) + ) + ) + ) + ) + ) + (set! (-> obj period) (the-as uint s5-0)) + (let* ((f0-4 (the float s5-0)) + (f1-1 (* f26-0 f0-4)) + ) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4))) + ) + (cond + ((< f30-0 0.0) + (set! f30-0 0.0) + ) + ((< 1.0 f30-0) + (set! f30-0 1.0) + ) + ) + (cond + ((< f28-0 0.0) + (set! f28-0 0.0) + ) + ((< (- 1.0 f30-0) f28-0) + (set! f28-0 (- 1.0 f30-0)) + ) + ) + (let ((f0-14 (the float s5-0))) + (set! (-> obj pause-in) (* f28-0 f0-14)) + (set! (-> obj pause-out) (* f30-0 f0-14)) + ) + ) + (none) + ) + +;; definition for method 11 of type sync-paused +(defmethod get-norm! sync-paused ((obj sync-paused) (arg0 int)) + "Get the current value, from 0 to 1." + (with-pp + (if (zero? arg0) + (set! arg0 (the-as int (-> pp clock frame-counter))) + ) + (let* ((v1-4 (-> obj period)) + (f2-0 (the float v1-4)) + (f0-1 (-> obj pause-in)) + (f1-0 (-> obj pause-out)) + ) + (the int (+ f0-1 f1-0 f2-0)) + (cond + ((logtest? (-> obj sync-flags) (sync-flags pong)) + (let* ((f3-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-6 (- f3-5 (* (the float (the int (/ f3-5 f2-0))) f2-0))) + (f2-2 (* 0.5 (- f2-0 (+ f0-1 f1-0)))) + (v1-7 #f) + ) + (when (>= f3-6 (+ f2-2 f0-1)) + (set! v1-7 #t) + (set! f3-6 (- f3-6 (+ f2-2 f0-1))) + (set! f0-1 f1-0) + ) + (let* ((f1-1 (/ (- f3-6 f0-1) f2-2)) + (f0-5 (fmax 0.0 (fmin 1.0 f1-1))) + ) + (if v1-7 + (set! f0-5 (- 1.0 f0-5)) + ) + f0-5 + ) + ) + ) + (else + (let* ((f3-9 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))) + (f3-10 (- f3-9 (* (the float (the int (/ f3-9 f2-0))) f2-0))) + (f1-5 (- f2-0 (+ f0-1 f1-0))) + (f1-6 (/ (- f3-10 f0-1) f1-5)) + ) + (fmax 0.0 (fmin 1.0 f1-6)) + ) + ) + ) + ) + ) + ) + +;; definition for method 12 of type sync-paused +(defmethod get-scaled-val! sync-paused ((obj sync-paused) (arg0 float) (arg1 int)) + "Multiples result of `get-norm!` by the provided float" + (* (get-norm! obj arg1) arg0) + ) + +;; definition for method 9 of type delayed-rand-float +(defmethod set-params! delayed-rand-float ((obj delayed-rand-float) (arg0 int) (arg1 int) (arg2 float)) + (set! (-> obj min-time) arg0) + (set! (-> obj max-time) arg1) + (set! (-> obj max-val) (* 0.5 arg2)) + (set! (-> obj start-time) 0) + (set! (-> obj timer) 0) + (set! (-> obj value) 0.0) + (-> obj value) + ) + +;; definition for method 10 of type delayed-rand-float +(defmethod reset! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (set! (-> obj start-time) (-> pp clock frame-counter)) + (set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time))) + (set! (-> obj value) (rand-vu-float-range (- (-> obj max-val)) (-> obj max-val))) + ) + ) + +;; definition for method 11 of type delayed-rand-float +(defmethod update! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (reset! obj) + ) + (-> obj value) + ) + ) + +;; definition for method 12 of type delayed-rand-float +;; WARN: Return type mismatch float vs none. +(defmethod update-and-clear! delayed-rand-float ((obj delayed-rand-float)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (reset! obj) + (set! (-> obj value) 0.0) + ) + (-> obj value) + (none) + ) + ) + +;; definition for method 9 of type oscillating-float +(defmethod set-params! oscillating-float ((obj oscillating-float) (arg0 float) (arg1 float) (arg2 float) (arg3 float)) + (set! (-> obj value) arg0) + (set! (-> obj target) arg0) + (set! (-> obj vel) 0.0) + (set! (-> obj max-vel) arg2) + (set! (-> obj damping) arg3) + (set! (-> obj accel) arg1) + (-> obj value) + ) + +;; definition for method 10 of type oscillating-float +(defmethod update! oscillating-float ((obj oscillating-float) (arg0 float)) + (with-pp + (let ((f0-3 (* (- (+ (-> obj target) arg0) (-> obj value)) (* (-> obj accel) (-> pp clock time-adjust-ratio))))) + (+! (-> obj vel) f0-3) + ) + (set! (-> obj vel) (fmin (-> obj max-vel) (fmax (- (-> obj max-vel)) (-> obj vel)))) + (set! (-> obj vel) (* (-> obj vel) (-> obj damping))) + (+! (-> obj value) (* (-> obj vel) (-> pp clock time-adjust-ratio))) + (-> obj value) + ) + ) + +;; definition for method 9 of type bouncing-float +(defmethod set-params! bouncing-float ((obj bouncing-float) + (arg0 float) + (arg1 float) + (arg2 float) + (arg3 float) + (arg4 float) + (arg5 float) + (arg6 float) + ) + (set-params! (-> obj osc) arg0 arg4 arg5 arg6) + (set! (-> obj max-value) arg1) + (set! (-> obj min-value) arg2) + (set! (-> obj elasticity) arg3) + (set! (-> obj state) 0) + (-> obj osc value) + ) + +;; definition for method 10 of type bouncing-float +(defmethod update! bouncing-float ((obj bouncing-float) (arg0 float)) + (update! (-> obj osc) arg0) + (set! (-> obj state) 0) + (when (>= (-> obj osc value) (-> obj max-value)) + (set! (-> obj osc value) (-> obj max-value)) + (if (< 0.0 (-> obj osc vel)) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) + ) + (set! (-> obj state) 1) + ) + (when (>= (-> obj min-value) (-> obj osc value)) + (set! (-> obj osc value) (-> obj min-value)) + (if (< (-> obj osc vel) 0.0) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) + ) + (set! (-> obj state) -1) + ) + (-> obj osc value) + ) + +;; definition for method 11 of type bouncing-float +(defmethod at-min? bouncing-float ((obj bouncing-float)) + (= (-> obj state) -1) + ) + +;; definition for method 12 of type bouncing-float +(defmethod at-max? bouncing-float ((obj bouncing-float)) + (= (-> obj state) 1) + ) + +;; definition for method 9 of type delayed-rand-vector +(defmethod set-params! delayed-rand-vector ((obj delayed-rand-vector) (arg0 int) (arg1 int) (arg2 float) (arg3 float)) + (set! (-> obj min-time) arg0) + (set! (-> obj max-time) arg1) + (set! (-> obj xz-max) (* 0.5 arg2)) + (set! (-> obj y-max) (* 0.5 arg3)) + (set! (-> obj start-time) 0) + (set! (-> obj timer) 0) + (vector-reset! (-> obj value)) + (-> obj value) + ) + +;; definition for method 10 of type delayed-rand-vector +(defmethod update-now! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (set! (-> obj start-time) (-> pp clock frame-counter)) + (set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time))) + (set! (-> obj value x) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max))) + (set! (-> obj value y) (rand-vu-float-range (- (-> obj y-max)) (-> obj y-max))) + (set! (-> obj value z) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max))) + (-> obj value) + ) + ) + +;; definition for method 11 of type delayed-rand-vector +(defmethod update-with-delay! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (update-now! obj) + ) + (-> obj value) + ) + ) + +;; definition for method 12 of type delayed-rand-vector +(defmethod update-with-delay-or-reset! delayed-rand-vector ((obj delayed-rand-vector)) + (with-pp + (if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer)) + (update-now! obj) + (vector-reset! (-> obj value)) + ) + (-> obj value) + ) + ) + +;; definition for method 9 of type oscillating-vector +;; INFO: Used lq/sq +(defmethod set-params! oscillating-vector ((obj oscillating-vector) (arg0 vector) (arg1 float) (arg2 float) (arg3 float)) + (cond + (arg0 + (set! (-> obj value quad) (-> arg0 quad)) + (set! (-> obj target quad) (-> arg0 quad)) + ) + (else + (vector-reset! (-> obj value)) + (vector-reset! (-> obj target)) + ) + ) + (vector-reset! (-> obj vel)) + (set! (-> obj max-vel) arg2) + (set! (-> obj damping) arg3) + (set! (-> obj accel) arg1) + (-> obj value) + ) + +;; definition for method 10 of type oscillating-vector +(defmethod update! oscillating-vector ((obj oscillating-vector) (arg0 vector)) + (with-pp + (let ((v1-0 (new 'stack-no-clear 'vector))) + (cond + (arg0 + (vector+! v1-0 (-> obj target) arg0) + (vector-! v1-0 v1-0 (-> obj value)) + ) + (else + (vector-! v1-0 (-> obj target) (-> obj value)) + ) + ) + (vector-float*! v1-0 v1-0 (* (-> obj accel) (-> pp clock time-adjust-ratio))) + (vector+! (-> obj vel) (-> obj vel) v1-0) + (let ((f0-2 (vector-length (-> obj vel)))) + (if (< (-> obj max-vel) f0-2) + (vector-float*! (-> obj vel) (-> obj vel) (/ (-> obj max-vel) f0-2)) + ) + ) + (vector-float*! (-> obj vel) (-> obj vel) (-> obj damping)) + (vector-float*! v1-0 (-> obj vel) (-> pp clock time-adjust-ratio)) + (vector+! (-> obj value) (-> obj value) v1-0) + ) + (-> obj value) + ) + ) + + + +