;;-*-Lisp-*-
(in-package goal)

;; name: joint-h.gc
;; name in dgo: joint-h
;; dgos: ENGINE, GAME

(declare-type joint-control basic)

(defenum joint-control-status
  :type uint16
  :bitfield #t

  (sync-math               0) ;; 1
  (spooling                1) ;; 2
  (spooling-not-last-block 2) ;; 4
  (blend-shape             3) ;; 8
  (math-when-off-screen    4) ;; 16
  (valid-spooled-frame     5) ;; 32
  (blend-shape-valid       6) ;; 64
  (eye-anim-valid          7) ;; 128
  (eye-anim                8) ;; 256
  )
;; +++joint-control-command
(defenum joint-control-command
  :type int64
  (zero 0)
  (push 1)
  (blend 2)
  (joint-control-command-4 4)
  (eight 8)
  (push1 19)
  (thirty-two 32)
  (stack 36)
  (float 42)
  (stack1 52)
  )
;; ---joint-control-command


;; DECOMP BEGINS

(deftype joint-control-channel (structure)
  ((parent            joint-control)
   (frame-group       art-joint-anim)
   (frame-num         float)
   (dist              meters)
   (num-func          (function joint-control-channel float float float float))
   (param             float  3)
   (frame-interp      float  2)
   (inspector-amount  uint8)
   (command           joint-control-command)
   (group-sub-index   int8)
   (group-size        int8)
   (eval-time         uint32)
   )
  )


(deftype top-anim-joint-control (basic)
  ((process              (pointer process-drawable))
   (interp-select        uint64  2)
   (base-anim            basic)
   (base-anim-speed      float)
   (base-anim-blend      float)
   (interp               float)
   (frame-group          art-joint-anim)
   (frame-group-push     art-joint-anim)
   (frame-num            float)
   (frame-targ           art-joint-anim)
   (frame-speed          float)
   (frame-blend          float)
   (frame-cur-blend      float)
   (frame-start          float)
   (frame-post-blend     float)
   (frame-post-end       float)
   (frame-push-time      time-frame)
   (frame-post-put-away  basic)
   (update-time          time-frame)
   )
  (:methods
    (new (symbol type process-drawable) _type_)
    (reset (_type_) none)
    (update (_type_) none)
    (get-channel (_type_ int) joint-control-channel)
    (push-anim-to-targ (_type_ art-joint-anim float int int float float symbol) none)
    )
  )


(deftype joint-control (basic)
  ((status                   joint-control-status)
   (allocated-length         uint8)
   (active-channels          uint8)
   (root-channel             (inline-array joint-control-channel)  :offset  16)
   (blend-index              uint8)
   (active-frame-interp      uint8)
   (float-channels           uint8)
   (generate-frame-function  (function joint-anim-frame int joint-control int))
   (prebind-function         (function joint-anim-frame int joint-control int))
   (postbind-function        (function draw-control cspace-array joint-control none))
   (effect                   effect-control)
   (interp-select            int64                                 2)
   (top-anim                 top-anim-joint-control)
   (override                 (array float))
   (channel                  joint-control-channel                 :inline :dynamic)
   )
  (:methods
    (new (symbol type int) _type_)
    (current-cycle-distance (_type_) float)
    (update-anim-data (_type_) none)
    (debug-print-channels (_type_ symbol) int)
    )
  )


(deftype matrix-stack (structure)
  ((top   matrix)
   (data  matrix  24 :inline)
   )
  )


(deftype channel-upload-info (structure)
  ((fixed      joint-anim-compressed-fixed)
   (fixed-qwc  int32)
   (frame      joint-anim-compressed-frame)
   (frame-qwc  int32)
   (amount     float)
   (interp     float)
   )
  :pack-me
  )


(deftype joint-work (structure)
  ((temp-mtx        matrix                       :inline)
   (joint-stack     matrix-stack                 :inline)
   (fix-jmp-table   (function none)              16)
   (frm-jmp-table   (function none)              16)
   (pair-jmp-table  (function none)              16)
   (uploads         channel-upload-info          24 :inline)
   (num-uploads     int32)
   (mtx-acc         matrix                       2 :inline)
   (tq-acc          transformq                   100 :inline)
   (jacp-hdr        joint-anim-compressed-hdr    :inline)
   (fixed-data      joint-anim-compressed-fixed  :inline)
   (frame-data      joint-anim-compressed-frame  2 :inline)
   (flatten-array   float                        576 :overlay-at mtx-acc)
   (flattened       vector                       24  :overlay-at mtx-acc)
   )
  )
