jak-project/goal_src/jak1/engine/data/art-h.gc

445 lines
15 KiB
Common Lisp
Raw Normal View History

;;-*-Lisp-*-
2020-09-04 14:44:23 -04:00
(in-package goal)
;; name: art-h.gc
;; name in dgo: art-h
;; dgos: GAME, ENGINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; joint animation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; base type for all joint animations
;; note that this refers to an animation for a single joint.
(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
)
;; unused? joint-anims
(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) ;; guess
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
;; joint-anim-compressed is the only type of joint-anim actually used.
;; the actual data isn't in here, this is just some metadata
;; again, this refers to a single joint
(deftype joint-anim-compressed (joint-anim)
((data uint32 :dynamic :offset-assert 12) ;; seems to always just be 1 zero.
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
;; a single "frame" in an animation, consists of matrices for each joint.
;; unlike the previous types, this is for all of the joints involved in an animation.
(deftype joint-anim-frame (structure)
((matrices matrix 2 :inline :offset-assert 0) ;; everybody has at least 2 matrices
(data matrix :inline :dynamic :offset-assert 128) ;; rest are dynamically sized.
)
:method-count-assert 9
:size-assert #x80
:flag-assert #x900000080
(:methods
(new (symbol type int) _type_ 0)
)
)
(defmethod new joint-anim-frame ((allocation symbol) (type-to-make type) (arg0 int))
"Create a new joint-anim-frame with enough room for arg0 matrices"
(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) (the-as uint (* 48 v1-1)))))
)
)
)
;; compression header - has info used by decompression algorithm
(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
)
;; this has the data needed to initialize the decompressor - I believe this
;; contains the starting poisition of the joints.
(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) ;; length here can be shorter!
)
:method-count-assert 9
:size-assert #x8a0
:flag-assert #x9000008a0
)
;; these are the actual compressed data frames.
;; dynamically sized, depends on the number of joints and the decompression.
(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) ;; guess
)
:method-count-assert 9
:size-assert #x860
:flag-assert #x900000860
)
;; table of frames
(deftype joint-anim-compressed-control (structure)
((num-frames uint32 :offset-assert 0)
(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 1 :offset-assert 16) ;; guess
)
:method-count-assert 9
:size-assert #x14
:flag-assert #x900000014
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ART
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; "art" is an overly general parent class of all art data.
;; it can be either a container of arts (art-group) or a single art (art-element)
(declare-type res-lump basic)
(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
2021-08-14 23:15:10 -04:00
(login (_type_) _type_ 9)
(lookup-art (_type_ string type) joint 10) ;; art or joint.
(lookup-idx-of-art (_type_ string type) int 11)
(needs-link? (_type_) symbol 12)
)
)
;; parent class of all single art things.
(deftype art-element (art)
((pad uint8 12))
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; unused. all animations use joints/skeletons.
(deftype art-mesh-anim (art-element)
((data basic :dynamic :offset-assert 32))
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; joint animation.
(declare-type merc-eye-anim-block structure)
(deftype art-joint-anim (art-element)
;; figured out manually from custom inspect.
((eye-anim-data merc-eye-anim-block :offset 4) ;; guessed on the name here, it's not in the inspect.
(speed float :offset 20)
(artist-base float :offset 24)
(artist-step float :offset 28)
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
;; facial animation
2021-08-14 23:31:17 -04:00
(blerc-data (pointer uint8) :offset 40) ;; todo, this is probably something else
;; compressed animation data
(frames joint-anim-compressed-control :offset 44)
;; per-joint info for each joint in the animation.
(data joint-anim-compressed :dynamic)
)
:method-count-assert 13
:size-assert #x30
:flag-assert #xd00000030
)
;; a collection of arts.
;; this is often stored as a -ag file in static level data.
(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
;; linker will call this one when it's loaded
(relocate (_type_ kheap (pointer uint8)) none :replace 7)
(link-art! (_type_) art-group 13)
(unlink-art! (_type_) int 14)
)
)
;; unused
(deftype art-mesh-geo (art-element)
((data basic :dynamic :offset-assert 32)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; unused
(deftype art-joint-geo (art-element)
((data joint :dynamic :offset-assert 32)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; the "skeleton group" is defined in code and tells the engine
;; how to actually use the art from the level data for this object.
(deftype skeleton-group (basic)
((art-group-name string :offset-assert 4)
(jgeo int32 :offset-assert 8)
(janim int32 :offset-assert 12)
(bounds vector :inline :offset-assert 16)
(radius meters :offset 28)
(mgeo int16 4 :offset-assert 32)
(max-lod int32 :offset-assert 40)
(lod-dist float 4 :offset-assert 44)
(longest-edge meters :offset-assert 60)
(texture-level int8 :offset-assert 64)
(version int8 :offset-assert 65)
(shadow int8 :offset-assert 66)
(sort int8 :offset-assert 67)
(_pad uint8 4 :offset-assert 68)
)
:method-count-assert 9
:size-assert #x48
:flag-assert #x900000048
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw Control
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the draw-control has settings for drawing a foreground object.
(declare-type merc-ctrl basic)
;; a merc level of detail
(deftype lod-group (structure)
((geo merc-ctrl :offset-assert 0) ;; the actual geometry to draw
(dist meters :offset-assert 4) ;; the distance from camera for this lod
)
:pack-me
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
;; the 4 levels of detail. the max-lod is the index of the highest lod that's actually used.
;; it is the lowest detail.
(deftype lod-set (structure)
((lod lod-group 4 :inline :offset-assert 0)
(max-lod int8 :offset-assert 32)
)
:pack-me
:method-count-assert 10
:size-assert #x21
:flag-assert #xa00000021
(:methods
(setup-lods! (_type_ skeleton-group art-group entity) _type_ 9)
)
)
;; the draw statuses are somewhat confusing, as some are set by the engine
;; and some are set by the game object code.
(defenum draw-status
:type uint8
:bitfield #t
(needs-clip 0) ;; set by engine, determines if object should be clipped
(hidden 1) ;; set by user, can disable drawing and animation codes
(no-anim 2) ;; set by engine, if there is no active joint animation
(was-drawn 3) ;; set by engine, if we were drawn (passed cull checks)
(no-skeleton-update 4) ;; set by engine, if our transforms are not valid
(skip-bones 5) ;; set by user, skips call to draw-bones but does everything else
(do-not-check-distance 6) ;; set by user, ignore in finding closest object for texture calcs
(has-joint-channels 7) ;; set by engine, if the object has joint channels.
)
;; only title seems to be used?
(defenum draw-effect
:type uint8
(drweff0 0)
(drweff1 1)
(drweff2 2)
(title 3)
(drweff4 4)
(drweff5 5)
(drweff6 6)
(drweff7 7)
)
(declare-type ripple-control basic)
(declare-type shadow-geo basic)
(declare-type shadow-control basic)
;; the actual draw-control - this is just a collection of references to all info
;; needed to do drawing.
(deftype draw-control (basic)
((status draw-status :offset-assert 4)
(matrix-type uint8 :offset-assert 5)
(data-format uint8 :offset-assert 6)
(global-effect draw-effect :offset-assert 7)
(art-group art-group :offset-assert 8)
(jgeo art-joint-geo :offset-assert 12)
(mgeo merc-ctrl :offset-assert 16)
(dma-add-func (function process-drawable draw-control symbol object none) :offset-assert 20)
(skeleton skeleton :offset-assert 24) ;; or cspace-array or shadow-control
(lod-set lod-set :inline :offset-assert 28)
(lod lod-group 4 :inline :offset 28)
(max-lod int8 :offset 60)
(force-lod int8 :offset-assert 61)
(cur-lod int8 :offset-assert 62)
(desired-lod int8 :offset-assert 63)
(ripple ripple-control :offset-assert 64)
(longest-edge meters :offset-assert 68)
(longest-edge? uint32 :offset 68)
(light-index uint8 :offset-assert 72)
(dummy uint8 2 :offset-assert 73)
(death-draw-overlap uint8 :offset-assert 75)
(death-timer uint8 :offset-assert 76)
(death-timer-org uint8 :offset-assert 77)
(death-vertex-skip uint16 :offset-assert 78)
(death-effect uint32 :offset-assert 80)
(sink-group dma-foreground-sink-group :offset-assert 84) ;; dma-foreground-sink-group?
(process process :offset-assert 88)
(shadow shadow-geo :offset-assert 92)
(shadow-ctrl shadow-control :offset-assert 96)
(origin vector :inline :offset-assert 112)
(bounds vector :inline :offset-assert 128)
(radius meters :offset 140)
(color-mult rgbaf :inline :offset-assert 144)
(color-emissive rgbaf :inline :offset-assert 160)
(secondary-interp float :offset-assert 176)
(current-secondary-interp float :offset-assert 180)
(shadow-mask uint8 :offset-assert 184)
(level-index uint8 :offset-assert 185)
(origin-joint-index uint8 :offset-assert 186)
(shadow-joint-index uint8 :offset-assert 187)
)
:method-count-assert 12
:size-assert #xbc
:flag-assert #xc000000bc
(:methods
(new (symbol type process art-joint-geo) _type_ 0)
(get-skeleton-origin (_type_) vector 9)
(lod-set! (_type_ int) none 10)
(lods-assign! (_type_ lod-set) none 11)
)
)
(defmethod get-skeleton-origin draw-control ((obj draw-control))
"Get the origin of the skeleton. Must have up-to-date bones."
(-> obj skeleton bones 0 position)
)
;; 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))
-1
(let ((elt-info (hash-table-try-ref (cdr ag-info) (symbol->string elt-name))))
(if (not (car elt-info))
-1
(cadr (cdr elt-info)))
)
)
)
)
)
(defmacro defskelgroup (name art-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 6) ;; do NOT use this!
)
"define a new static skeleton group"
`(let ((skel (new 'static 'skeleton-group
:art-group-name ,(symbol->string art-name)
:bounds ,bounds
:longest-edge ,longest-edge
:version ,version
:max-lod ,(- (length lods) 1)
:shadow ,(art-elt->index (string->symbol-format "{}-ag" art-name) shadow)
:texture-level ,texture-level
:sort ,sort
)))
;; set joint geometry and joint bones
(set! (-> skel jgeo) ,(art-elt->index (string->symbol-format "{}-ag" art-name) joint-geom))
(set! (-> skel janim) ,(art-elt->index (string->symbol-format "{}-ag" art-name) joint-anim))
;; set lods
,@(apply-i (lambda (x i)
`(begin
(set! (-> skel mgeo ,i) ,(art-elt->index (string->symbol-format "{}-ag" art-name) (car x)))
(set! (-> skel lod-dist ,i) ,(cadr x))
)
) lods)
;; define skel group
(define ,name skel)
)
)