jak-project/goal_src/jak1/engine/draw/drawable-tree.gc

121 lines
4 KiB
Common Lisp
Raw Normal View History

;;-*-Lisp-*-
2020-09-04 14:44:23 -04:00
(in-package goal)
;; name: drawable-tree.gc
;; name in dgo: drawable-tree
;; dgos: GAME, ENGINE
;; The "drawable tree" represents a BVH for a specific render.
;; Typically, levels will have ~10 drawable trees. There will be a tree for
;; tfrag, a tree for actors, a tree for tie,
;; This file contains common functions for all drawable trees.
(defmethod draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable-tree-array) (arg1 display-frame))
"Draw a drawable tree array. If the current level is set to special or special-vis, the draw is skipped."
(let ((v1-1 (-> (scratchpad-object terrain-context) bsp lev-index)))
(case (-> *level* level v1-1 display?)
(('special 'special-vis #f)
)
(else
(dotimes (s3-0 (-> obj length))
(draw (-> obj trees s3-0) (-> arg0 trees s3-0) arg1)
)
)
)
)
0
(none)
)
(defmethod collect-stats drawable-tree-array ((obj drawable-tree-array))
(dotimes (s5-0 (-> obj length))
(collect-stats (-> obj trees s5-0))
)
(none)
)
(defmethod debug-draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable) (arg1 display-frame))
(dotimes (s3-0 (-> obj length))
(debug-draw (-> obj trees s3-0) (-> (the-as drawable-tree-array arg0) trees s3-0) arg1)
)
(none)
)
(defmethod unpack-vis drawable-tree ((obj drawable-tree) (arg0 (pointer int8)) (arg1 (pointer int8)))
"Copy our visibility data from arg1 to arg0, unpacking it."
(local-vars (t5-1 int))
;; grab the first array
(let* ((v1-0 (the-as drawable-inline-array-node (-> obj data 0)))
;; first elt in top array
(a3-1 (/ (-> v1-0 data 0 id) 8))
;; number in first array (8 or fewer)
(t0-0 (-> v1-0 length))
;; offset in destination
(v1-1 (&+ arg0 a3-1))
;; number of bytes
(a3-3 (/ (+ t0-0 7) 8))
)
;; copy the data!
;;(mem-print (the (pointer uint32) arg1) 10)
(dotimes (t0-1 a3-3)
(let ((t1-0 (-> arg1 0)))
;;(format 0 "top-copy: #x~X~%" t1-0)
(set! arg1 (&-> arg1 1))
(set! (-> v1-1 0) t1-0)
)
(set! v1-1 (&-> v1-1 1))
)
)
;; now, the remaining arrays, excluding the final which isn't a draw node array.
(let ((v1-5 (+ (-> obj length) -1)))
(when (nonzero? v1-5)
(dotimes (a3-5 v1-5)
;; pointer to this array
(let* ((t0-4 (-> obj data a3-5))
;; pointer to next depth array
(t2-0 (-> obj data (+ a3-5 1)))
;; id of first in prev
(t1-5 (/ (-> (the-as drawable-inline-array-node t0-4) data 0 id) 8))
;; id of first in next
(t2-2 (/ (-> (the-as drawable-inline-array-node t2-0) data 0 id) 8))
;; number of nodes in this one
(t0-5 (-> (the-as drawable-inline-array-node t0-4) length))
;; output for prev level
(t1-6 (&+ arg0 t1-5))
;; output for next level
(t2-3 (&+ arg0 t2-2))
)
(while #t
;; load the vis byte for the one in this array
(let ((t3-0 (-> t1-6 0)))
;; inc vis ptr.
(set! t1-6 (&-> t1-6 1))
;; vis mask bit. (init at highest)
(let ((t4-0 128))
(label cfg-7)
;; check if we're visible
(b! (zero? (logand t3-0 t4-0)) cfg-9 :delay (set! t5-1 (-> arg1 0)))
;; we are visible. write 8 in the output
(set! arg1 (&-> arg1 1))
(set! (-> t2-3 0) t5-1)
(label cfg-9)
(+! t0-5 -1)
;; check if we've done all nodes
(b! (zero? t0-5) cfg-12 :delay (.sra t4-0 t4-0 1))
;; check if we're done with this byte and inc output.
(b! (nonzero? t4-0) cfg-7 :delay (set! t2-3 (&-> t2-3 1)))
)
)
)
)
(label cfg-12)
(nop!)
0
)
)
)
arg1
)