Files
jak-project/goal_src/jak2/engine/target/board/board-util.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

209 lines
6.5 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: board-util.gc
;; name in dgo: board-util
;; dgos: ENGINE, GAME
(define-extern ja-post (function none :behavior process-drawable))
(define-extern ja-channel-set! (function int int :behavior process-drawable))
(define-extern ja-channel-push! (function int time-frame int :behavior process-drawable))
(define-extern ja-done? (function int symbol :behavior process-drawable))
(define-extern *target-shadow-control* shadow-control)
;; DECOMP BEGINS
;; WARN: Return type mismatch process-drawable vs board.
(defmethod relocate ((this board) (arg0 int))
(if (nonzero? (-> this main))
(&+! (-> this main) arg0)
)
(the-as board ((method-of-type process-drawable relocate) this arg0))
)
(defbehavior board-post board ()
(let* ((a0-0 (-> self parent))
(v1-0 (if a0-0
(-> (the-as target (-> a0-0 0)) self)
)
)
)
(set! (-> self root trans quad) (-> v1-0 board board-trans quad))
(let ((a0-4 (-> v1-0 board board-quat quad)))
(set! (-> self root quat quad) a0-4)
)
(set! (-> self root scale quad) (-> v1-0 board board-scale quad))
(set! (-> self draw light-index) (-> v1-0 draw light-index))
(let ((a0-10 (-> v1-0 draw color-mult quad)))
(set! (-> self draw color-mult quad) a0-10)
)
(let ((a0-12 (-> v1-0 draw color-emissive quad)))
(set! (-> self draw color-emissive quad) a0-12)
)
(set! (-> self draw force-fade) (-> v1-0 draw force-fade))
(set! (-> self draw death-vertex-skip) (-> (the-as target (-> self parent 0)) draw death-vertex-skip))
(set! (-> self draw death-effect) (-> (the-as target (-> self parent 0)) draw death-effect))
(set! (-> self draw death-timer) (-> (the-as target (-> self parent 0)) draw death-timer))
(set! (-> self draw death-timer-org) (-> (the-as target (-> self parent 0)) draw death-timer-org))
(set! (-> self draw death-draw-overlap) (-> (the-as target (-> self parent 0)) draw death-draw-overlap))
(let ((a0-37 (-> v1-0 draw shadow-ctrl settings shadow-dir quad)))
(set! (-> self draw shadow-ctrl settings shadow-dir quad) a0-37)
)
(if (or (logtest? (-> v1-0 draw status) (draw-control-status no-draw no-draw-temp no-draw-bounds no-draw-bounds2))
(zero? (-> v1-0 skel active-channels))
)
(logior! (-> self draw status) (draw-control-status no-draw))
(logclear! (-> self draw status) (draw-control-status no-draw))
)
(if (logtest? (-> v1-0 draw status) (draw-control-status force-fade))
(logior! (-> self draw status) (draw-control-status force-fade))
(logclear! (-> self draw status) (draw-control-status force-fade))
)
)
(ja-post)
0
(none)
)
(defstate hidden (board)
:virtual #t
:trans (behavior ()
(let ((v1-0 (-> self parent)))
(if (not (focus-test?
(the-as target (if v1-0
(the-as target (-> v1-0 0 self))
)
)
in-head
)
)
(go-virtual idle #f)
)
)
)
:code (behavior ()
(ja-channel-set! 0)
(ja-post)
(logior! (-> self mask) (process-mask sleep-code))
(suspend)
0
)
)
(defstate idle (board)
:virtual #t
:event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
(case message
(('open)
(go-virtual use)
)
)
)
:trans (behavior ()
(let ((v1-0 (-> self parent)))
(if (focus-test?
(the-as target (if v1-0
(the-as target (-> v1-0 0 self))
)
)
in-head
)
(go-virtual hidden)
)
)
)
:code (behavior ((arg0 symbol))
(ja-channel-push! 1 (seconds 0.1))
(cond
(arg0
(ja :group! board-close-ja :num! max)
)
(else
(ja-no-eval :group! board-close-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))
)
)
)
(set! (-> self draw shadow) #f)
(sleep-code)
)
:post board-post
)
(defstate use (board)
:virtual #t
:event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
(case message
(('close)
(go-virtual idle #f)
)
)
)
:trans (behavior ()
(let ((v1-0 (-> self parent)))
(if v1-0
(-> v1-0 0 self)
)
)
(let ((v1-2 (-> self parent)))
(cond
((focus-test?
(the-as target (if v1-2
(the-as target (-> v1-2 0 self))
)
)
in-head
)
(go-virtual hidden)
)
((let ((v1-9 #x40000)
(a0-3 (-> self parent))
)
(not (logtest? (the-as focus-status v1-9) (-> (the-as target (if a0-3
(the-as target (-> a0-3 0 self))
)
)
focus-status
)
)
)
)
(go-virtual idle #f)
)
)
)
)
:code (behavior ()
(set! (-> self draw shadow) (-> self shadow-backup))
(ja-channel-push! 1 (seconds 0.1))
(ja-no-eval :group! board-open-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))
)
(sleep-code)
)
:post board-post
)
;; WARN: Return type mismatch object vs none.
(defbehavior board-init board ()
(set! (-> self root) (new 'process 'trsqv))
(initialize-skeleton
self
(the-as skeleton-group (art-group-get-by-name *level* "skel-board" (the-as (pointer uint32) #f)))
(the-as pair 0)
)
(let ((v1-5 (-> *target-shadow-control* settings shadow-dir quad)))
(set! (-> *board-shadow-control* settings shadow-dir quad) v1-5)
)
(set! (-> self draw shadow-ctrl) *board-shadow-control*)
(set! (-> self shadow-backup) (-> self draw shadow))
(set! (-> self main) (new 'process 'joint-mod (joint-mod-mode flex-blend) self 3))
(ja-channel-set! 0)
(go-virtual idle #t)
(none)
)