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

218 lines
5.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: entity-h.gc
;; name in dgo: entity-h
;; dgos: ENGINE, GAME
(defenum entity-perm-status
:bitfield #t
:type uint16
(bit-0 0) ;; blocks birth
(error 1)
(dead 2)
(no-kill 3)
(bit-4 4)
(bit-5 5)
(subtask-complete 6)
(bit-7 7)
(complete 8)
(bit-9 9)
(bit-10 10)
(save 11)
(bit-12 12)
)
(defenum vehicle-type
:type int32
(bikea 0)
(bikeb 1)
(bikec 2)
(cara 3)
(carb 4)
(carc 5)
(guard-bike 6)
(hellcat 7)
(evan-test-bike 8)
(test-bike 9)
(test-car 10)
)
(declare-type race-mesh basic)
;; NOTE - for cam-start
(define-extern reset-cameras (function none))
;; NOTE - for airlock
(define-extern process-entity-status! (function process entity-perm-status symbol entity-perm-status))
(define-extern process-drawable-from-entity! (function process-drawable entity-actor none))
(declare-type nav-poly structure)
(define-extern *compact-actors* symbol)
(define-extern *spawn-actors* symbol)
(define-extern debug-actor (function string none))
(define-extern reset-actors (function symbol none))
;; NOTE - for projectile
(define-extern process-entity-set! (function process entity entity))
(define-extern process-by-ename (function string process))
(define-extern entity-birth-no-kill (function entity process))
;; DECOMP BEGINS
(define *generate-actor-vis* #f)
(define *generate-actor-vis-start* #f)
(define *generate-actor-vis-output* #f)
(deftype entity-perm (structure)
((user-object object 2)
(user-uint64 uint64 :overlay-at (-> user-object 0))
(user-float float 2 :overlay-at (-> user-object 0))
(user-int32 int32 2 :overlay-at (-> user-object 0))
(user-uint32 uint32 2 :overlay-at (-> user-object 0))
(user-int16 int16 4 :overlay-at (-> user-object 0))
(user-uint16 uint16 4 :overlay-at (-> user-object 0))
(user-int8 int8 8 :overlay-at (-> user-object 0))
(user-uint8 uint8 8 :overlay-at (-> user-object 0))
(status entity-perm-status :offset 8)
(dummy uint8 1 :offset 10)
(task game-task :offset 11)
(aid actor-id :offset 12)
(quad uint128 :overlay-at (-> user-object 0))
)
(:methods
(update (_type_ symbol entity-perm-status) _type_)
)
)
(deftype entity-links (structure)
((prev-link entity-links)
(next-link entity-links)
(entity entity)
(process process)
(level level)
(vis-id int32)
(kill-mask task-mask)
(vis-dist meters)
(trans vector :inline)
(perm entity-perm :inline)
(status uint16 :overlay-at (-> perm status))
(aid uint32 :overlay-at (-> perm aid))
(task uint8 :overlay-at (-> perm task))
)
(:methods
(birth? (_type_ vector) symbol)
)
)
(deftype entity-perm-array (inline-array-class)
((data entity-perm :inline :dynamic)
)
)
(set! (-> entity-perm-array heap-base) (the-as uint 16))
(deftype entity-links-array (inline-array-class)
((data entity-links :inline :dynamic)
)
)
(set! (-> entity-links-array heap-base) (the-as uint 64))
(deftype entity (res-lump)
((trans vector :inline)
(aid uint32)
)
(:methods
(birth! (_type_) _type_)
(kill! (_type_) _type_)
(add-to-level! (_type_ level-group level actor-id) none)
(remove-from-level! (_type_ level-group) _type_)
(get-level (_type_) level)
)
)
(deftype entity-camera (entity)
((connect connectable :inline)
)
)
(deftype entity-nav-mesh (entity)
((nav-mesh nav-mesh)
)
(:methods
(initialize-nav-mesh! (_type_) none)
(debug-draw (_type_) none)
)
)
(deftype entity-race-mesh (entity)
((race-mesh race-mesh)
)
(:methods
(entity-race-mesh-method-27 () none)
(entity-race-mesh-method-28 () none)
)
)
(deftype entity-actor (entity)
((etype type :offset 56)
(task game-task)
(kill-mask task-mask :offset 52)
(vis-id int16)
(quat quaternion :inline)
)
(:methods
(next-actor (_type_) entity-actor)
(prev-actor (_type_) entity-actor)
(debug-print (_type_ symbol type) none)
(toggle-status (_type_ entity-perm-status symbol) none)
(get-simple-travel-vector (_type_ vector vector vector object float) nav-mesh)
(project-point-to-nav-mesh (_type_ vector vector nav-poly float) nav-poly)
)
)
(deftype actor-reference (structure)
((actor entity)
(id uint32)
)
:pack-me
)
(deftype actor-group (inline-array-class)
((data actor-reference :inline :dynamic)
)
)
(set! (-> actor-group heap-base) (the-as uint 8))
(deftype entity-info (basic)
((ptype type)
(package string)
(art-group pair)
(pool symbol)
(heap-size int32)
)
)
(deftype actor-bank (basic)
((pause-dist meters)
(birth-dist meters)
(birth-max int32)
)
)
(define *ACTOR-bank* (new 'static 'actor-bank :pause-dist (meters 50) :birth-dist (meters 220) :birth-max 10))