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

;; name: lights-h.gc
;; name in dgo: lights-h
;; dgos: GAME

;; DECOMP BEGINS

(deftype vu-lights (structure)
  ((direction   vector  3 :inline)
   (color       vector  3 :inline)
   (ambient     vector  :inline)
   (fade-int    uint32  :offset  44)
   (fade-flags  uint32  :offset  28)
   )
  )


(deftype light (structure)
  "extra: {?, shadow, ?, ?}"
  ((direction      vector  :inline)
   (color          rgbaf   :inline)
   (extra          vector  :inline)
   (level          float     :overlay-at (-> extra data 0))
   (luminance      float     :overlay-at (-> extra data 2))
   (priority       float     :overlay-at (-> extra data 3))
   (bytes          uint8   4 :overlay-at (-> extra data 1))
   (mask           uint16    :overlay-at (-> extra data 1))
   (palette-index  int8      :overlay-at (-> bytes 3))
   )
  )


(deftype light-shadow-mask (uint32)
  ()
  )

(deftype light-sphere (structure)
  ((name                 string)
   (bsphere              vector  :inline)
   (direction            vector  :inline)
   (color                vector  :inline)
   (decay-start          float     :offset   4)
   (ambient-point-ratio  float     :offset   8)
   (brightness           float     :offset  12)
   (bytes                uint8   4 :overlay-at (-> color data 3))
   (mask                 uint16    :overlay-at (-> color data 3))
   (palette-index        int8      :overlay-at (-> bytes 3))
   (shadow               uint32    :overlay-at (-> direction data 0))
   )
  )


(deftype light-hash-bucket (structure)
  ((index  uint16)
   (count  uint16)
   )
  :pack-me
  )


(deftype light-hash (basic)
  ((num-lights          uint16)
   (num-indices         uint16)
   (num-buckets         uint16)
   (bucket-step         uint8     2)
   (base-trans          vector    :inline)
   (axis-scale          vector    :inline)
   (dimension-array     vector4w  :inline)
   (bucket-array        (inline-array light-hash-bucket))
   (index-array         pointer)
   (light-sphere-array  (inline-array light-sphere))
   )
  )


(deftype light-hash-work (structure)
  ((ones  vector4w  :inline)
   )
  )


(define *light-hash* (the-as light-hash #f))

(defmethod print ((this light))
  (format
    #t
    "#<light [~F] ~F ~F ~F  "
    (-> this extra x)
    (-> this direction x)
    (-> this direction y)
    (-> this direction z)
    )
  (format #t "~F ~F ~F @ #x~X>" (-> this color x) (-> this color y) (-> this color z) this)
  this
  )

(deftype light-group (structure)
  ((dir0    light  :inline)
   (dir1    light  :inline)
   (dir2    light  :inline)
   (ambi    light  :inline)
   (lights  light  4 :inline :overlay-at dir0)
   )
  )
