Files
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

164 lines
5.4 KiB
Common Lisp
Vendored
Generated

;;-*-Lisp-*-
(in-package goal)
;; definition of type path-control
(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)
)
)
;; definition for method 3 of type path-control
(defmethod inspect ((this path-control))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tflags: #x~X~%" (-> this flags))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tprocess: ~A~%" (-> this process))
(format #t "~Tcurve: #<curve @ #x~X>~%" (&-> this cverts))
(format #t "~Tnum-cverts: ~D~%" (-> this curve num-cverts))
(format #t "~Tcverts: #x~X~%" (-> this cverts))
this
)
;; definition of type curve-control
(deftype curve-control (path-control)
()
(:methods
(new (symbol type process symbol float) _type_)
)
)
;; definition for method 3 of type curve-control
(defmethod inspect ((this curve-control))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tflags: #x~X~%" (-> this flags))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tprocess: ~A~%" (-> this process))
(format #t "~Tcurve: #<curve @ #x~X>~%" (&-> this cverts))
(format #t "~Tnum-cverts: ~D~%" (-> this curve num-cverts))
(format #t "~Tcverts: #x~X~%" (-> this cverts))
this
)
;; definition for method 0 of type path-control
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs path-control.
(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)
(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)
(let ((lookup-entity (entity-actor-lookup ent 'path-actor 0)))
(if lookup-entity
(set! ent lookup-entity)
)
)
)
(set! tag (new 'static 'res-tag))
(let ((data (res-lump-data ent name pointer :tag-ptr (& tag) :time time)))
(cond
(data
(set! (-> this cverts) (the-as (inline-array vector) data))
(set! (-> this curve num-cverts) (the-as int (-> tag elt-count)))
)
(else
(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)
)
)
;; definition for method 18 of type path-control
(defmethod should-display? ((this path-control))
(and *display-path-marks* (logtest? (-> this flags) (path-control-flag display)))
)
;; definition for method 15 of type path-control
(defmethod length-as-float ((this path-control))
(the float (+ (-> this curve num-cverts) -1))
)
;; definition for method 17 of type path-control
(defmethod get-num-verts ((this path-control))
(-> this curve num-cverts)
)
;; definition for method 0 of type curve-control
(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
)
(else
(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 (the-as curve (&-> this cverts)) name s2-0 time))
(cond
((> (-> this curve num-cverts) 0)
(set! (-> this type) path-control)
)
(else
(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
)
)
;; failed to figure out what this is:
0