Files
2023-09-30 10:24:37 -04:00

479 lines
18 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: art-h.gc
;; name in dgo: art-h
;; dgos: ENGINE, GAME
(declare-type res-lump basic)
(declare-type merc-ctrl art-element)
(declare-type joint-control basic)
(declare-type effect-control basic)
(declare-type ripple-control basic)
(declare-type shadow-control basic)
(declare-type shadow-geo basic)
(declare-type merc-eye-anim-block structure)
(defenum draw-control-status
:type uint16
:bitfield #t
(close-to-screen 0) ;; 1
(no-draw 1) ;; 2
(no-draw-temp 2) ;; 4
(on-screen 3) ;; 8
(uninited 4) ;; 16
(no-draw-bounds 5) ;; 32
(no-closest-distance 6) ;; 64
(math-skel 7) ;; 128
(force-vu1 8) ;; 256
(no-draw-bounds2 9) ;; 512
(force-fade 10) ;; 1024
(warp-cross-fade 11) ;; 2048
(lod-set 12) ;; 4096
(disable-fog 13) ;; 8192
(hud 14) ;; 16384
)
(defenum draw-control-data-format
:type uint8
:bitfield #f
(pris 0)
(merc 1)
)
(defenum draw-control-global-effect
:type uint8
:bitfield #t
(bit-0 0)
(bit-1 1) ;; 2
(title-light 2) ;; 4
(disable-envmap 3) ;; 8
)
;; DECOMP BEGINS
(deftype joint-anim (basic)
((name string :offset-assert 4)
(number int16 :offset-assert 8)
(length int16 :offset-assert 10)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
(deftype joint-anim-matrix (joint-anim)
((data matrix :inline :dynamic :offset 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
(deftype joint-anim-transformq (joint-anim)
((data transformq :inline :dynamic :offset 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
(deftype joint-anim-drawable (joint-anim)
((data drawable :dynamic :offset-assert 12)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
(deftype joint-anim-frame (structure)
((matrices matrix 2 :inline :offset-assert 0)
(data transformq :inline :dynamic :offset-assert 128)
)
:method-count-assert 9
:size-assert #x80
:flag-assert #x900000080
(:methods
(new (symbol type int) _type_ 0)
)
)
;; WARN: Return type mismatch structure vs joint-anim-frame.
(defmethod new joint-anim-frame ((allocation symbol) (type-to-make type) (arg0 int))
(let ((v1-1 (max 0 (+ arg0 -2))))
(the-as
joint-anim-frame
(new-dynamic-structure allocation type-to-make (the-as int (+ (-> type-to-make size) (* 48 v1-1))))
)
)
)
(deftype joint-anim-compressed-hdr (structure)
((control-bits uint32 14 :offset-assert 0)
(num-joints uint32 :offset-assert 56)
(matrix-bits uint32 :offset-assert 60)
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
)
(deftype joint-anim-compressed-fixed (structure)
((hdr joint-anim-compressed-hdr :inline :offset-assert 0)
(offset-64 uint32 :offset-assert 64)
(offset-32 uint32 :offset-assert 68)
(offset-16 uint32 :offset-assert 72)
(reserved uint32 :offset-assert 76)
(data vector 133 :inline :offset-assert 80)
)
:method-count-assert 9
:size-assert #x8a0
:flag-assert #x9000008a0
)
(deftype joint-anim-compressed-frame (structure)
((offset-64 uint32 :offset-assert 0)
(offset-32 uint32 :offset-assert 4)
(offset-16 uint32 :offset-assert 8)
(reserved uint32 :offset-assert 12)
(data vector 133 :inline :offset-assert 16)
)
:method-count-assert 9
:size-assert #x860
:flag-assert #x900000860
)
(deftype joint-anim-compressed-control (structure)
((num-frames uint16 :offset-assert 0)
(flags uint16 :offset-assert 2)
(fixed-qwc uint32 :offset-assert 4)
(frame-qwc uint32 :offset-assert 8)
(fixed joint-anim-compressed-fixed :offset-assert 12)
(data joint-anim-compressed-frame :dynamic :offset-assert 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
(deftype art (basic)
((name string :offset 8)
(length int32 :offset-assert 12)
(extra res-lump :offset-assert 16)
)
:method-count-assert 13
:size-assert #x14
:flag-assert #xd00000014
(:methods
(login (_type_) _type_ 9)
(get-art-by-name-method (_type_ string type) basic 10)
(get-art-idx-by-name-method (_type_ string type) int 11)
(needs-link? (_type_) symbol 12)
)
)
(deftype art-element (art)
((pad uint8 12 :offset-assert 20)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
(deftype art-mesh-anim (art-element)
((data basic :dynamic :offset-assert 32)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
(deftype art-joint-anim (art-element)
((speed float :offset 20)
(artist-base float :offset 24)
(artist-step float :offset 28)
(eye-anim merc-eye-anim-block :offset 4)
(master-art-group-name string :offset-assert 32)
(master-art-group-index int32 :offset-assert 36)
(blend-shape-anim (pointer int8) :offset-assert 40)
(frames joint-anim-compressed-control :offset-assert 44)
)
:method-count-assert 13
:size-assert #x30
:flag-assert #xd00000030
)
(deftype art-group (art)
((info file-info :offset 4)
(data art-element :dynamic :offset 32)
)
:method-count-assert 15
:size-assert #x20
:flag-assert #xf00000020
(:methods
(relocate (_type_ kheap (pointer uint8)) none :replace 7)
(link-art! (_type_) art-group 13)
(unlink-art! (_type_) int 14)
)
)
(deftype art-mesh-geo (art-element)
((data basic :dynamic :offset-assert 32)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
(deftype art-joint-geo (art-element)
((data joint :dynamic :offset-assert 32)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
(deftype art-joint-anim-manager-slot (structure)
((anim art-joint-anim :offset-assert 0)
(comp-data uint32 :offset-assert 4)
(time-stamp uint64 :offset-assert 8)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
(deftype art-joint-anim-manager (basic)
((kheap kheap :inline :offset-assert 16)
(free-index int32 :offset-assert 32)
(slot art-joint-anim-manager-slot 64 :inline :offset-assert 48)
)
:method-count-assert 14
:size-assert #x430
:flag-assert #xe00000430
(:methods
(new (symbol type int) _type_ 0)
(decompress (_type_ art-joint-anim) art-joint-anim 9)
(update-time-stamp (_type_ art-joint-anim) art-joint-anim 10)
(unload-from-slot (_type_ int) art-joint-anim 11)
(used-bytes-for-slot (_type_ int) int 12)
(unload-from-level (_type_ level) none 13)
)
)
(defmethod new art-joint-anim-manager ((allocation symbol) (type-to-make type) (arg0 int))
(let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(let ((s4-0 (-> gp-0 kheap)))
(set! (-> s4-0 base) (kmalloc (the-as kheap (-> allocation value)) arg0 (kmalloc-flags) "heap"))
(set! (-> s4-0 current) (-> s4-0 base))
(set! (-> s4-0 top-base) (&+ (-> s4-0 base) arg0))
(set! (-> s4-0 top) (-> s4-0 top-base))
)
(dotimes (v1-6 64)
(set! (-> gp-0 slot v1-6 anim) #f)
)
(set! (-> gp-0 free-index) 0)
gp-0
)
)
(deftype skeleton-group (art-group)
((art-group-name string :offset-assert 32)
(jgeo int32 :offset-assert 36)
(janim int32 :offset-assert 40)
(bounds vector :inline :offset-assert 48)
(radius meters :offset 60)
(mgeo int16 6 :offset-assert 64)
(max-lod int32 :offset-assert 76)
(lod-dist float 6 :offset-assert 80)
(longest-edge meters :offset-assert 104)
(texture-level int8 :offset-assert 108)
(version int8 :offset-assert 109)
(shadow int8 :offset-assert 110)
(sort int8 :offset-assert 111)
(origin-joint-index int8 :offset-assert 112)
(shadow-joint-index int8 :offset-assert 113)
(light-index uint8 :offset-assert 114)
(pad uint8 :offset-assert 115)
)
:method-count-assert 16
:size-assert #x74
:flag-assert #x1000000074
(:methods
(add-to-loading-level (_type_) skeleton-group 15)
)
)
(deftype lod-group (structure)
((geo merc-ctrl :offset-assert 0)
(dist meters :offset-assert 4)
)
:pack-me
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
(deftype lod-set (structure)
((lod lod-group 6 :inline :offset-assert 0)
(max-lod int8 :offset-assert 48)
)
:method-count-assert 10
:size-assert #x31
:flag-assert #xa00000031
(:methods
(setup-lods! (_type_ skeleton-group art-group entity) _type_ 9)
)
)
(deftype draw-control (basic)
((process process-drawable :offset-assert 4)
(status draw-control-status :offset-assert 8)
(data-format draw-control-data-format :offset-assert 10)
(global-effect draw-control-global-effect :offset-assert 11)
(art-group art-group :offset-assert 12)
(jgeo art-joint-geo :offset-assert 16)
(mgeo merc-ctrl :offset-assert 20)
(dma-add-func (function process-drawable draw-control symbol object none) :offset-assert 24)
(skeleton skeleton :offset-assert 28)
(lod-set lod-set :inline :offset-assert 32)
(max-lod int8 :offset 80)
(force-lod int8 :offset-assert 81)
(cur-lod int8 :offset-assert 82)
(desired-lod int8 :offset-assert 83)
(ripple ripple-control :offset-assert 84)
(longest-edge meters :offset-assert 88)
(longest-edge? uint32 :offset 88)
(light-index uint8 :offset-assert 92)
(shadow-mask uint8 :offset-assert 93)
(level-index uint8 :offset-assert 94)
(death-draw-overlap uint8 :offset-assert 95)
(death-timer uint8 :offset-assert 96)
(death-timer-org uint8 :offset-assert 97)
(death-vertex-skip uint16 :offset-assert 98)
(death-effect uint32 :offset-assert 100)
(shadow shadow-geo :offset-assert 104)
(shadow-ctrl shadow-control :offset-assert 108)
(distance meters :offset-assert 112)
(origin vector :inline :offset-assert 128)
(bounds vector :inline :offset-assert 144)
(radius meters :offset 156)
(color-mult rgbaf :inline :offset-assert 160)
(color-emissive rgbaf :inline :offset-assert 176)
(effect-mask uint64 :offset-assert 192)
(seg-mask uint64 :offset-assert 200)
(origin-joint-index uint8 :offset-assert 208)
(shadow-joint-index uint8 :offset-assert 209)
(force-fade uint8 :offset-assert 210)
(default-texture-page uint8 :offset-assert 211)
(shadow-values uint32 :offset-assert 212)
)
:method-count-assert 15
:size-assert #xd8
:flag-assert #xf000000d8
(:methods
(new (symbol type process symbol) _type_ 0)
(get-skeleton-origin (_type_) vector 9)
(lod-set! (_type_ int) none 10)
(lods-assign! (_type_ lod-set) none 11)
(setup-masks (_type_ int int) none 12)
(setup-cspace-and-add (_type_ art-joint-geo symbol) cspace-array 13)
(do-joint-math (_type_ cspace-array joint-control) none 14)
)
)
(defmethod get-skeleton-origin draw-control ((this draw-control))
(-> this skeleton bones 0 transform trans)
)
;; og:preserve-this
;; look up the index of an art element in an art group.
(desfun art-elt->index (ag-name elt-name)
(if (number? elt-name)
elt-name
(let ((ag-info (hash-table-try-ref *art-info* (symbol->string ag-name))))
(if (not (car ag-info))
(error (symbol->string ag-name))
(let ((elt-info (hash-table-try-ref (cdr ag-info) (symbol->string elt-name))))
(if (not (car elt-info))
(error (symbol->string ag-name))
(cadr (cdr elt-info)))
)
)
)
)
)
(defmacro defskelgroup (name ag-name joint-geom joint-anim lods
&key (shadow 0)
&key bounds
&key (longest-edge 0.0)
&key (texture-level 0)
&key (sort 0)
&key (version 7) ;; do NOT use this!
&key (origin-joint-index 0)
&key (shadow-joint-index 0)
&key (light-index 0)
)
"define a new static skeleton group"
`(let ((skel (new 'static 'skeleton-group
:name ,(symbol->string name)
:info #f ;; all skeleton-groups seem to have these as #f
:extra #f
:art-group-name ,(symbol->string ag-name)
:bounds ,bounds
:longest-edge ,longest-edge
:version ,version
:max-lod ,(- (length lods) 1)
:shadow ,(art-elt->index (string->symbol-format "{}-ag" ag-name) shadow)
:texture-level ,texture-level
:sort ,sort
:origin-joint-index ,origin-joint-index
:shadow-joint-index ,shadow-joint-index
:light-index ,light-index
)))
;; set joint geometry and joint bones
(set! (-> skel jgeo) ,(art-elt->index (string->symbol-format "{}-ag" ag-name) joint-geom))
(set! (-> skel janim) ,(art-elt->index (string->symbol-format "{}-ag" ag-name) joint-anim))
;; set lods
,@(apply-i (lambda (x i)
`(begin
(set! (-> skel mgeo ,i) ,(art-elt->index (string->symbol-format "{}-ag" ag-name) (car x)))
(set! (-> skel lod-dist ,i) ,(cadr x))
)
) lods)
;; define skel group
(define ,name skel)
;; add to level
(add-to-loading-level ,name)
)
)
0
(import "goal_src/jak2/engine/data/art-elts.gc")