mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 14:54:53 -04:00
b74399ed57
* move files * update game.gp
212 lines
8.4 KiB
Common Lisp
212 lines
8.4 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: bsp-h.gc
|
|
;; name in dgo: bsp-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
;; Each level has a bsp file. There is a bsp-header, and a list of bsp-nodes.
|
|
;; The bsp-nodes make up a tree. Each node has a plane and two child nodes.
|
|
;; The bsp-header also contains (or references) all of the static level information.
|
|
;; The file containing the bsp-header is called the "bt" and is loaded in a special
|
|
;; way because that allows it to use all of the remaining level heap memory.
|
|
;; This file is very large (>8 MB), and always the last file in a level DGO.
|
|
;; The bsp file also contains all the drawable trees and lots of other level data,
|
|
;; so the "bsp-header" name isn't very accurate.
|
|
|
|
;; Typically, the "bsp" refers to the static level data, and the "level" to the runtime level info.
|
|
|
|
;; In the game, all of these bsp-header files have -vis after their name
|
|
;; I believe this means that this is a version of a level that has an associated vis file
|
|
;; for precomputed visibility.
|
|
|
|
|
|
(declare-type entity-camera basic)
|
|
|
|
;; flags: 1 = load
|
|
;; 2 = display
|
|
|
|
;; a node in the bsp tree
|
|
(deftype bsp-node (structure)
|
|
((front int32 :offset-assert 0) ;; if > 0, is a pointer to another bsp-node
|
|
(back int32 :offset-assert 4) ;; if > 0, is a pointer to another bsp-node
|
|
(front-flags uint32 :offset-assert 8) ;; ?
|
|
(back-flags uint32 :offset-assert 12) ;; ?
|
|
(plane vector :inline :offset-assert 16) ;; the partitioning plane
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x20
|
|
:flag-assert #x900000020
|
|
)
|
|
|
|
;; This is the object stored first in the level bt (-vis)
|
|
;; It is also a drawable, and drawing it will draw the level.
|
|
(deftype bsp-header (drawable)
|
|
((info file-info :offset 4)
|
|
(all-visible-list (pointer uint16) :offset-assert 32)
|
|
(visible-list-length int32 :offset-assert 36)
|
|
(drawable-trees drawable-tree-array :offset-assert 40)
|
|
(pat pointer :offset-assert 44)
|
|
(pat-length int32 :offset-assert 48)
|
|
(texture-remap-table (pointer uint64) :offset-assert 52)
|
|
(texture-remap-table-len int32 :offset-assert 56)
|
|
(texture-ids (pointer texture-id) :offset-assert 60)
|
|
(texture-page-count int32 :offset-assert 64)
|
|
(unk-zero-0 basic :offset-assert 68)
|
|
(name symbol :offset-assert 72)
|
|
(nickname symbol :offset-assert 76)
|
|
(vis-info level-vis-info 8 :offset-assert 80) ;; note: 0 when not present.
|
|
(actors drawable-inline-array-actor :offset-assert 112)
|
|
(cameras (array entity-camera) :offset-assert 116)
|
|
(nodes (inline-array bsp-node) :offset-assert 120)
|
|
(level level :offset-assert 124)
|
|
(current-leaf-idx uint16 :offset-assert 128)
|
|
(unk-data-2 uint16 9 :offset-assert 130)
|
|
(boxes box8s-array :offset-assert 148)
|
|
(current-bsp-back-flags uint32 :offset-assert 152)
|
|
(ambients drawable-inline-array-ambient :offset-assert 156)
|
|
(unk-data-4 float :offset-assert 160)
|
|
(unk-data-5 float :offset-assert 164)
|
|
(adgifs adgif-shader-array :offset-assert 168)
|
|
(actor-birth-order (pointer uint32) :offset-assert 172)
|
|
(split-box-indices (pointer uint16) :offset-assert 176)
|
|
(unk-data-8 uint32 55 :offset-assert 180)
|
|
)
|
|
:method-count-assert 20
|
|
:size-assert #x190
|
|
:flag-assert #x1400000190
|
|
(:methods
|
|
(relocate (_type_ kheap (pointer uint8)) none :replace 7)
|
|
(birth (_type_) none 18)
|
|
(deactivate-entities (_type_) none 19)
|
|
)
|
|
)
|
|
|
|
;; seems to be unused?
|
|
;; In practice, a normal bsp-header is a game-level.
|
|
(deftype game-level (basic)
|
|
((master-bsp basic :offset-assert 4)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x8
|
|
:flag-assert #x900000008
|
|
)
|
|
|
|
(deftype view-frustum (structure)
|
|
((hither-top-left vector :inline :offset-assert 0)
|
|
(hither-top-right vector :inline :offset-assert 16)
|
|
(hither-bottom-left vector :inline :offset-assert 32)
|
|
(hither-bottom-right vector :inline :offset-assert 48)
|
|
(yon-top-left vector :inline :offset-assert 64)
|
|
(yon-top-right vector :inline :offset-assert 80)
|
|
(yon-bottom-left vector :inline :offset-assert 96)
|
|
(yon-bottom-right vector :inline :offset-assert 112)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x80
|
|
:flag-assert #x900000080
|
|
)
|
|
(define-extern inspect-bsp-tree (function bsp-header bsp-node none))
|
|
|
|
(defmethod inspect bsp-header ((obj bsp-header))
|
|
(format #t "[~8x] ~A~%" obj (-> obj type))
|
|
(format #t "~Tall-visible-list: #x~X~%" (-> obj all-visible-list))
|
|
(format #t "~Tvisible-list-length: ~D~%" (-> obj visible-list-length))
|
|
(format #t "~Tdrawable-trees: ~A~%" (-> obj drawable-trees))
|
|
(format #t "~Tpat: #x~X~%" (-> obj pat))
|
|
(format #t "~Tpat-length: ~D~%" (-> obj pat-length))
|
|
;; putting this stuff here for debugging!
|
|
(format #t "~Ttexture-remap-table-len: ~D~%" (-> obj texture-remap-table-len))
|
|
(dotimes (i (-> obj texture-remap-table-len))
|
|
(let* ((tex-id-array (the (pointer texture-id) (&-> obj texture-remap-table i)))
|
|
(tex-id-from (-> tex-id-array 0))
|
|
(tex-id-to (-> tex-id-array 1))
|
|
)
|
|
(format #t "~T~Ttex-remap[~D]: #<texture-id :page ~D :index ~D> --> #<texture-id :page ~D :index ~D>~%"
|
|
i
|
|
(-> tex-id-from page) (-> tex-id-from index)
|
|
(-> tex-id-to page) (-> tex-id-to index)
|
|
)
|
|
)
|
|
)
|
|
;;(inspect-bsp-tree obj (the-as bsp-node (-> obj nodes)))
|
|
obj
|
|
)
|
|
|
|
(defun-debug inspect-bsp-tree ((arg0 bsp-header) (arg1 bsp-node))
|
|
"Recursively print all nodes in a bsp tree. This makes a huge mess"
|
|
(cond
|
|
((zero? arg1)
|
|
)
|
|
(else
|
|
(format #t "_#x~X________________~%" arg1)
|
|
(inspect arg1)
|
|
(let ((s4-0 *print-column*))
|
|
(set! *print-column* (+ *print-column* 8))
|
|
(if (> (-> arg1 front) 0)
|
|
(inspect-bsp-tree arg0 (the-as bsp-node (-> arg1 front)))
|
|
(format #t "_#x~X________________~%" arg1)
|
|
)
|
|
(if (> (-> arg1 back) 0)
|
|
(inspect-bsp-tree arg0 (the-as bsp-node (-> arg1 back)))
|
|
(format #t "_#x~X________________~%" arg1)
|
|
)
|
|
(set! *print-column* s4-0)
|
|
)
|
|
)
|
|
)
|
|
(none)
|
|
)
|
|
|
|
(defun-recursive map-bsp-tree none ((arg0 (function bsp-node none)) (arg1 bsp-header) (arg2 bsp-node))
|
|
"Recursively apply arg0 to all nodes in the bsp tree"
|
|
(cond
|
|
((zero? arg2)
|
|
)
|
|
(else
|
|
(if (> (-> arg2 front) 0)
|
|
(map-bsp-tree arg0 arg1 (the-as bsp-node (-> arg2 front)))
|
|
(arg0 arg2)
|
|
)
|
|
(if (> (-> arg2 back) 0)
|
|
(map-bsp-tree arg0 arg1 (the-as bsp-node (-> arg2 back)))
|
|
(arg0 arg2)
|
|
)
|
|
)
|
|
)
|
|
(none)
|
|
)
|
|
|
|
(deftype cl-stat (structure)
|
|
((fragments uint32 :offset-assert 0)
|
|
(tris uint32 :offset-assert 4)
|
|
(output uint32 :offset-assert 8)
|
|
)
|
|
:pack-me
|
|
:method-count-assert 9
|
|
:size-assert #xc
|
|
:flag-assert #x90000000c
|
|
)
|
|
|
|
(deftype collide-stats (structure)
|
|
((other cl-stat :inline :offset-assert 0)
|
|
(total cl-stat :inline :offset-assert 12)
|
|
(nodes uint32 :offset-assert 24)
|
|
(calls uint32 :offset-assert 28)
|
|
(total-target stopwatch :inline :offset-assert 32)
|
|
(target-cache-fill stopwatch :inline :offset-assert 64)
|
|
(target-ray-poly stopwatch :inline :offset-assert 96)
|
|
(pad uint32 :offset-assert 124)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x80
|
|
:flag-assert #x900000080
|
|
)
|
|
|
|
;; offsets of stuff in the scratchpad during bsp draw.
|
|
(defconstant TERRAIN_BSP_SCRATCHPAD #x0)
|
|
(defconstant VISIBLE_LIST_SCRATCHPAD #x38b0)
|
|
|
|
;; TODO - for cam-update
|
|
(define-extern bsp-camera-asm (function bsp-header vector none))
|