mirror of
https://github.com/open-goal/jak-project
synced 2026-07-03 21:10:50 -04:00
cd68cb671e
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>
115 lines
3.6 KiB
Common Lisp
115 lines
3.6 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: trajectory.gc
|
|
;; name in dgo: trajectory
|
|
;; dgos: GAME, ENGINE
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(defmethod eval-position! ((this trajectory) (time float) (result vector))
|
|
"Evaluate the position of the object at a give time"
|
|
(set! (-> result quad) (-> this initial-position quad))
|
|
(+! (-> result x) (* time (-> this initial-velocity x)))
|
|
(+! (-> result y) (* time (-> this initial-velocity y)))
|
|
(+! (-> result z) (* time (-> this initial-velocity z)))
|
|
(+! (-> result y) (* 0.5 time time (-> this gravity)))
|
|
result
|
|
)
|
|
|
|
(defmethod eval-velocity! ((this trajectory) (time float) (result vector))
|
|
"Evaluate the velocity of the object at a given time"
|
|
(set! (-> result quad) (-> this initial-velocity quad))
|
|
(+! (-> result y) (* time (-> this gravity)))
|
|
result
|
|
)
|
|
|
|
(defmethod setup-from-to-duration! ((this trajectory) (from vector) (to vector) (duration float) (grav float))
|
|
"Set up a trajectory that goes from->to in the given duration"
|
|
(set! (-> this initial-position quad) (-> from quad))
|
|
(set! (-> this gravity) grav)
|
|
(set! (-> this time) duration)
|
|
;; the velocity we need in xz to make it in time
|
|
(let ((xz-vel (/ (vector-vector-xz-distance to from) duration)))
|
|
;; our velocity will point along from -> to
|
|
(vector-! (-> this initial-velocity) to from)
|
|
;; but have magnitude that we calculated above.
|
|
(vector-xz-normalize! (-> this initial-velocity) xz-vel)
|
|
)
|
|
;; solve for the y velocity that makes us land at the right height.
|
|
(set! (-> this initial-velocity y)
|
|
(- (/ (- (-> to y) (-> from y)) duration) (* 0.5 duration (-> this gravity)))
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod setup-from-to-xz-vel! ((this trajectory) (from vector) (to vector) (xz-vel float) (grav float))
|
|
"Set up a trajectory that goes from->to with the given velocity"
|
|
;; just solve for the duration and use the previous
|
|
(let ((duration (/ (vector-vector-xz-distance to from) xz-vel)))
|
|
(setup-from-to-duration! this from to duration grav)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod setup-from-to-y-vel! ((this trajectory) (from vector) (to vector) (y-vel float) (grav float))
|
|
"Set up a trajectory with the given initial y velocity."
|
|
(let* ((f0-0 y-vel)
|
|
(f1-3 (- (* f0-0 f0-0) (* 2.0 (- (-> from y) (-> to y)) grav)))
|
|
(f0-3 900.0)
|
|
)
|
|
(when (>= f1-3 0.0)
|
|
(let ((f0-4 (sqrtf f1-3)))
|
|
(set! f0-3 (fmax (/ (- (- y-vel) f0-4) grav) (/ (+ (- y-vel) f0-4) grav)))
|
|
)
|
|
)
|
|
(setup-from-to-duration! this from to f0-3 grav)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod setup-from-to-height! ((this trajectory) (arg0 vector) (arg1 vector) (arg2 float) (arg3 float))
|
|
"Setup a trajectory that reaches a given height"
|
|
(let* ((f1-2 (+ arg2 (fmax (-> arg0 y) (-> arg1 y))))
|
|
(f1-5 (* 2.0 (- (-> arg0 y) f1-2) arg3))
|
|
(f0-3 4096.0)
|
|
)
|
|
(if (< 0.0 f1-5)
|
|
(set! f0-3 (sqrtf f1-5))
|
|
)
|
|
(setup-from-to-y-vel! this arg0 arg1 f0-3 arg3)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod debug-draw! ((this trajectory))
|
|
"Draw the trajectory"
|
|
(let ((prev-pos (new 'stack-no-clear 'vector))
|
|
(pos (new 'stack-no-clear 'vector))
|
|
(num-segments 10)
|
|
)
|
|
(set! (-> pos quad) (-> this initial-position quad))
|
|
(dotimes (s2-0 num-segments)
|
|
(set! (-> prev-pos quad) (-> pos quad))
|
|
(let ((t-eval (* (-> this time) (/ (+ 1.0 (the float s2-0)) (the float num-segments)))))
|
|
(eval-position! this t-eval pos)
|
|
)
|
|
(add-debug-line
|
|
#t
|
|
(bucket-id debug-no-zbuf)
|
|
prev-pos
|
|
pos
|
|
(new 'static 'rgba :r #xff :a #x80)
|
|
#f
|
|
(the-as rgba -1)
|
|
)
|
|
)
|
|
)
|
|
0
|
|
(none)
|
|
)
|