mirror of
https://github.com/open-goal/jak-project
synced 2026-08-10 03:06:18 -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>
161 lines
5.1 KiB
Common Lisp
161 lines
5.1 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: path-h.gc
|
|
;; name in dgo: path-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
(defenum path-control-flag
|
|
:bitfield #t
|
|
:type uint32
|
|
(display 0)
|
|
(draw-line 1) ;; TODO - only seen it used to control debug drawing so far
|
|
(draw-point 2) ;; TODO - only seen it used to control debug drawing so far
|
|
(draw-text 3) ;; TODO - only seen it used to control debug drawing so far
|
|
(not-found 4)
|
|
)
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
;; A path-control is a curve that can be loaded from res-lump/entities.
|
|
(deftype path-control (basic)
|
|
((flags path-control-flag)
|
|
(name symbol)
|
|
(process process-drawable)
|
|
(curve curve :inline)
|
|
(num-cverts int32 :overlay-at (-> curve num-cverts))
|
|
(cverts (inline-array vector) :overlay-at (-> curve cverts))
|
|
)
|
|
(:methods
|
|
(new (symbol type process symbol float) _type_)
|
|
(debug-draw (_type_) none)
|
|
(eval-path-curve-div! (_type_ vector float symbol) vector)
|
|
(get-random-point (_type_ vector) vector)
|
|
(path-control-method-12 (_type_ vector float) vector)
|
|
(eval-path-curve! (_type_ vector float symbol) vector)
|
|
(path-control-method-14 (_type_ vector float) vector)
|
|
(length-as-float (_type_) float)
|
|
(path-distance (_type_) float)
|
|
(get-num-verts (_type_) int)
|
|
(should-display? (_type_) symbol)
|
|
(path-control-method-19 (_type_) float)
|
|
(path-control-method-20 (_type_) float)
|
|
)
|
|
)
|
|
|
|
;; A curve-control is very similar, but also gets knots.
|
|
(deftype curve-control (path-control)
|
|
()
|
|
(:methods
|
|
(new (symbol type process symbol float) _type_)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod new path-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
|
|
(local-vars (tag res-tag))
|
|
(let ((this (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
|
|
|
|
(when (zero? this)
|
|
;; allocation failed.
|
|
(go process-drawable-art-error "memory")
|
|
(set! this (the-as path-control 0))
|
|
(goto cfg-9)
|
|
)
|
|
|
|
(set! (-> this process) (the-as process-drawable proc))
|
|
(set! (-> this name) name)
|
|
(let ((ent (-> proc entity)))
|
|
(when (= name 'path)
|
|
;; if we are a path, try to look up the path-actor.
|
|
(let ((lookup-entity (entity-actor-lookup (the-as res-lump ent) 'path-actor 0)))
|
|
(if lookup-entity
|
|
(set! ent lookup-entity)
|
|
)
|
|
)
|
|
)
|
|
|
|
;; look up the curve data
|
|
(set! tag (new 'static 'res-tag))
|
|
(let ((data (res-lump-data ent name pointer :tag-ptr (& tag) :time time)))
|
|
(cond
|
|
(data
|
|
;; success, we got some data
|
|
(set! (-> this cverts) (the-as (inline-array vector) data))
|
|
(set! (-> this curve num-cverts) (the-as int (-> tag elt-count)))
|
|
)
|
|
(else
|
|
;; did not find the data. Set flags and zero stuff
|
|
(logior! (-> this flags) (path-control-flag not-found))
|
|
(set! (-> this cverts) (the-as (inline-array vector) #f))
|
|
(set! (-> this curve num-cverts) 0)
|
|
0
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(label cfg-9)
|
|
(the-as path-control this)
|
|
)
|
|
)
|
|
|
|
(defmethod should-display? ((this path-control))
|
|
"Should we display path marks?"
|
|
(and *display-path-marks* (logtest? (-> this flags) (path-control-flag display)))
|
|
)
|
|
|
|
(defmethod length-as-float ((this path-control))
|
|
"Get the number of edges as a float"
|
|
(the float (+ (-> this curve num-cverts) -1))
|
|
)
|
|
|
|
(defmethod get-num-verts ((this path-control))
|
|
"Get the number of vertices"
|
|
(-> this curve num-cverts)
|
|
)
|
|
|
|
(defmethod new curve-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
|
|
(let ((this (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
|
|
(set! (-> this process) (the-as process-drawable proc))
|
|
(set! (-> this name) name)
|
|
(let* ((ent (-> proc entity))
|
|
(v1-2 name)
|
|
(s2-0 (cond
|
|
((= v1-2 'path)
|
|
'path-k ;; for knots?
|
|
)
|
|
(else
|
|
;; appends a -k to the symbol name.
|
|
(let ((s2-1 string->symbol))
|
|
(format (clear *temp-string*) "~A-k" name)
|
|
(s2-1 *temp-string*)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(let ((lookup-entity (entity-actor-lookup ent 'path-actor 0)))
|
|
(if lookup-entity
|
|
(set! ent lookup-entity)
|
|
)
|
|
)
|
|
(when (not (get-curve-data! ent (-> this curve) name s2-0 time))
|
|
(cond
|
|
((> (-> this curve num-cverts) 0)
|
|
;; downgrade us to a path-control, we got cverts but no knots.
|
|
(set! (-> this type) path-control)
|
|
)
|
|
(else
|
|
;; couldn't get anything, mark as bad.
|
|
(logior! (-> this flags) (path-control-flag not-found))
|
|
(set! (-> this cverts) (the-as (inline-array vector) #f))
|
|
(set! (-> this curve num-cverts) 0)
|
|
0
|
|
)
|
|
)
|
|
)
|
|
)
|
|
this
|
|
)
|
|
)
|