Files
jak-project/test/decompiler/reference/jak2/engine/game/idle-control_REF.gc
T
ManDude cd68cb671e deftype and defmethod syntax major changes (#3094)
Major change to how `deftype` shows up in our code:
- the decompiler will no longer emit the `offset-assert`,
`method-count-assert`, `size-assert` and `flag-assert` parameters. There
are extremely few cases where having this in the decompiled code is
helpful, as the types there come from `all-types` which already has
those parameters. This also doesn't break type consistency because:
  - the asserts aren't compared.
- the first step of the test uses `all-types`, which has the asserts,
which will throw an error if they're bad.
- the decompiler won't emit the `heap-base` parameter unless necessary
now.
- the decompiler will try its hardest to turn a fixed-offset field into
an `overlay-at` field. It falls back to the old offset if all else
fails.
- `overlay-at` now supports field "dereferencing" to specify the offset
that's within a field that's a structure, e.g.:
```lisp
(deftype foobar (structure)
  ((vec    vector  :inline)
   (flags  int32   :overlay-at (-> vec w))
   )
  )
```
in this structure, the offset of `flags` will be 12 because that is the
final offset of `vec`'s `w` field within this structure.
- **removed ID from all method declarations.** IDs are only ever
automatically assigned now. Fixes #3068.
- added an `:overlay` parameter to method declarations, in order to
declare a new method that goes on top of a previously-defined method.
Syntax is `:overlay <method-name>`. Please do not ever use this.
- added `state-methods` list parameter. This lets you quickly specify a
list of states to be put in the method table. Same syntax as the
`states` list parameter. The decompiler will try to put as many states
in this as it can without messing with the method ID order.

Also changes `defmethod` to make the first type definition (before the
arguments) optional. The type can now be inferred from the first
argument. Fixes #3093.

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-10-30 03:20:02 +00:00

163 lines
4.9 KiB
Common Lisp
Vendored
Generated

;;-*-Lisp-*-
(in-package goal)
;; definition of type idle-control-frame
(deftype idle-control-frame (uint32)
((command ic-cmd :offset 0 :size 8)
(anim uint8 :offset 8 :size 8)
(param0 uint8 :offset 16 :size 8)
(param1 uint8 :offset 24 :size 8)
)
)
;; definition for method 3 of type idle-control-frame
(defmethod inspect ((this idle-control-frame))
(local-vars (a2-4 int))
(when (not this)
(set! this this)
(goto cfg-11)
)
(format #t "[~8x] ~A~%" this 'idle-control-frame)
(let ((t9-1 format)
(a0-2 #t)
(a1-1 "~1Tcommand: #x~X : ~S~%")
(a2-1 (-> this command))
(v1-4 (-> this command))
)
(t9-1 a0-2 a1-1 a2-1 (cond
((= v1-4 (ic-cmd play))
"play"
)
((= v1-4 (ic-cmd push))
"push"
)
((= v1-4 (ic-cmd restart))
"restart"
)
(else
"*unknown*"
)
)
)
)
(format #t "~1Tanim: ~D~%" (-> this anim))
(format #t "~1Tparam0: ~D~%" (-> this param0))
(let ((t9-4 format)
(a0-5 #t)
(a1-4 "~1Tparam1: ~D~%")
)
(shift-arith-right-32 a2-4 this 24)
(t9-4 a0-5 a1-4 a2-4)
)
(label cfg-11)
this
)
;; definition of type idle-control
(deftype idle-control (structure)
((anim (pointer idle-control-frame))
(current (pointer idle-control-frame))
(counter int32)
(target int32)
)
(:methods
(idle-control-method-9 (_type_ (pointer idle-control-frame)) none)
(idle-control-method-10 (_type_ process-drawable) none :behavior process-drawable)
)
)
;; definition for method 3 of type idle-control
(defmethod inspect ((this idle-control))
(when (not this)
(set! this this)
(goto cfg-4)
)
(format #t "[~8x] ~A~%" this 'idle-control)
(format #t "~1Tanim: #x~X~%" (-> this anim))
(format #t "~1Tcurrent: #x~X~%" (-> this current))
(format #t "~1Tcounter: ~D~%" (-> this counter))
(format #t "~1Ttarget: ~D~%" (-> this target))
(label cfg-4)
this
)
;; definition for method 9 of type idle-control
;; WARN: Return type mismatch idle-control vs none.
(defmethod idle-control-method-9 ((this idle-control) (arg0 (pointer idle-control-frame)))
(set! (-> this anim) arg0)
(set! (-> this current) arg0)
(set! (-> this counter) 0)
(set! (-> this target) 0)
(none)
)
;; definition for method 10 of type idle-control
;; WARN: Return type mismatch int vs none.
;; WARN: Function (method 10 idle-control) has a return type of none, but the expression builder found a return statement.
(defmethod idle-control-method-10 ((this idle-control) (arg0 process-drawable))
(local-vars (a1-1 int))
(when (nonzero? (-> this anim))
(let ((s5-0 self))
(set! self arg0)
(loop
(let ((s4-0 (-> this current 0)))
(case (-> s4-0 command)
(((ic-cmd play))
(if (< (-> s4-0 anim) 0)
(return #f)
)
(when (zero? (-> this target))
(let ((t9-0 rand-vu-int-range)
(a0-3 (-> s4-0 param0))
)
(shift-arith-right-32 a1-1 s4-0 24)
(set! (-> this target) (t9-0 (the-as int a0-3) a1-1))
)
(ja :group! (-> (the-as process-drawable self) draw art-group data (-> s4-0 anim)) :num! min)
(return #f)
)
(ja :group! (-> (the-as process-drawable self) draw art-group data (-> s4-0 anim)) :num! (seek!))
(cond
((ja-done? 0)
(+! (-> this counter) 1)
(cond
((>= (-> this counter) (-> this target))
(set! (-> this current) (&-> (-> this current) 1))
(set! (-> this counter) 0)
(set! (-> this target) 0)
0
)
(else
(ja :num-func num-func-identity :frame-num 0.0)
(return #f)
)
)
)
(else
(return #f)
)
)
)
(((ic-cmd push))
(ja-channel-push! 1 (the-as time-frame (-> s4-0 param0)))
(set! (-> this current) (&-> (-> this current) 1))
(set! (-> this counter) 0)
(set! (-> this target) 0)
0
)
(((ic-cmd restart))
(set! (-> this current) (-> this anim))
(set! (-> this counter) 0)
(set! (-> this target) 0)
0
)
)
)
)
(set! self s5-0)
)
)
0
(none)
)