Files
jak-project/goal_src/jak1/engine/draw/drawable-tree.gc
T
Tyler Wilding d1ece445d4 Dependency graph work - Part 1 - Preliminary work (#3505)
Relates to #1353 

This adds no new functionality or overhead to the compiler, yet. This is
the preliminary work that has:
- added code to the compiler in several spots to flag when something is
used without being properly required/imported/whatever (disabled by
default)
- that was used to generate project wide file dependencies (some
circulars were manually fixed)
- then that graph underwent a transitive reduction and the result was
written to all `jak1` source files.

The next step will be making this actually produce and use a dependency
graph. Some of the reasons why I'm working on this:
- eliminates more `game.gp` boilerplate. This includes the `.gd` files
to some extent (`*-ag` files and `tpage` files will still need to be
handled) this is the point of the new `bundles` form. This should make
it even easier to add a new file into the source tree.
- a build order that is actually informed from something real and
compiler warnings that tell you when you are using something that won't
be available at build time.
- narrows the search space for doing LSP actions -- like searching for
references. Since it would be way too much work to store in the compiler
every location where every symbol/function/etc is used, I have to do
ad-hoc searches. By having a dependency graph i can significantly reduce
that search space.
- opens the doors for common shared code with a legitimate pattern.
Right now jak 2 shares code from the jak 1 folder. This is basically a
hack -- but by having an explicit require syntax, it would be possible
to reference arbitrary file paths, such as a `common` folder.

Some stats:
- Jak 1 has about 2500 edges between files, including transitives
- With transitives reduced at the source code level, each file seems to
have a modest amount of explicit requirements.

Known issues:
- Tracking the location for where `defmacro`s and virtual state
definitions were defined (and therefore the file) is still problematic.
Because those forms are in a macro environment, the reader does not
track them. I'm wondering if a workaround could be to search the
reader's text_db by not just the `goos::Object` but by the text
position. But for the purposes of finishing this work, I just statically
analyzed and searched the code with throwaway python code.
2024-05-12 12:37:59 -04:00

129 lines
4.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/level/bsp.gc")
(require "engine/draw/draw-node-h.gc")
;; 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.
;; DECOMP BEGINS
(defmethod draw ((this 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 (-> this length))
(draw (-> this trees s3-0) (-> arg0 trees s3-0) arg1)
)
)
)
)
0
(none)
)
(defmethod collect-stats ((this drawable-tree-array))
(dotimes (s5-0 (-> this length))
(collect-stats (-> this trees s5-0))
)
0
(none)
)
(defmethod debug-draw ((this drawable-tree-array) (arg0 drawable) (arg1 display-frame))
(dotimes (s3-0 (-> this length))
(debug-draw (-> this trees s3-0) (-> (the-as drawable-tree-array arg0) trees s3-0) arg1)
)
0
(none)
)
(defmethod unpack-vis ((this 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 (-> this 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 (+ (-> this length) -1)))
(when (nonzero? v1-5)
(dotimes (a3-5 v1-5)
;; pointer to this array
(let* ((t0-4 (-> this data a3-5))
;; pointer to next depth array
(t2-0 (-> this 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
)