jak-project/goal_src/jak2/engine/collide/los-control.gc
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

100 lines
3.7 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: los-control.gc
;; name in dgo: los-control
;; dgos: GAME, COMMON
;; DECOMP BEGINS
(define *los-time-offset* (the-as time-frame 0))
;; WARN: Return type mismatch time-frame vs none.
(defmethod los-control-method-9 ((this los-control) (process process-focusable) (trans-vec vector) (radius float))
(when (and (time-elapsed? (-> this last-check-time) (-> this check-interval))
(-> this src-proc)
(or process (-> this dst-proc))
)
(let* ((process-source (handle->process (-> this src-proc)))
(process-focus (if (type? process-source process-focusable)
(the-as process-focusable process-source)
)
)
)
(when process-focus
(when (not process)
(let ((process-dest (handle->process (-> this dst-proc))))
(set! process (if (type? process-dest process-focusable)
(the-as process-focusable process-dest)
)
)
)
)
(when process
(let ((start-pos (new 'stack-no-clear 'vector)))
(set! (-> start-pos quad) (-> (get-trans process-focus 3) quad))
(if (not trans-vec)
(set! trans-vec (get-trans process 3))
)
(let ((distance (vector-! (new 'stack-no-clear 'vector) trans-vec start-pos))
(cquery (new 'stack-no-clear 'collide-query))
)
(set! (-> cquery start-pos quad) (-> start-pos quad))
(set! (-> cquery move-dist quad) (-> distance quad))
(let ((query cquery))
(set! (-> query radius) radius)
(set! (-> query collide-with) (-> this collide-with))
(set! (-> query ignore-process0) process-focus)
(set! (-> query ignore-process1) process)
(set! (-> query ignore-pat) (-> process-focus root pat-ignore-mask))
(set! (-> query action-mask) (collide-action solid))
)
(fill-using-line-sphere *collide-cache* cquery)
(let ((f30-0 (probe-using-line-sphere *collide-cache* cquery)))
(quad-copy! (the-as pointer (-> this last-collide-result)) (the-as pointer (-> cquery best-other-tri)) 6)
(if (>= 0.0 f30-0)
(set-time! (-> this have-no-los))
(set-time! (-> this have-los))
)
)
)
)
(set-time! (-> this last-check-time))
)
)
)
)
(none)
)
(defmethod check-los? ((this los-control) (arg0 time-frame))
(and (time-elapsed? (-> this have-los) (+ (-> this check-interval) arg0))
(not (time-elapsed? (-> this have-no-los) (-> this check-interval)))
)
)
(defmethod skip-check-los? ((this los-control) (arg0 int))
(and (time-elapsed? (-> this have-no-los) (+ (-> this check-interval) arg0))
(not (time-elapsed? (-> this have-los) (-> this check-interval)))
)
)
(defmethod set-dst-proc! ((this los-control) (dst handle))
(set! (-> this dst-proc) dst)
0
(none)
)
(defmethod new-source! ((this los-control) (proc process) (check-interval time-frame) (c-spec collide-spec))
(set! (-> this src-proc) (process->handle proc))
(set! (-> this dst-proc) (the-as handle #f))
(set! (-> this have-los) 0)
(set! (-> this have-no-los) 0)
(set! (-> this last-check-time) *los-time-offset*)
(set! (-> this check-interval) check-interval)
(set! (-> this collide-with) c-spec)
(set! *los-time-offset* (+ *los-time-offset* 1))
0
(none)
)