[jak3] More headers, up to load-dgo (#3363)

path-h, sparticle-h, load-dgo, nav-control-h, nav-mesh-h, rigid-body-h,
actor-hash-h, spatial-hash-h
This commit is contained in:
water111
2024-02-03 15:03:10 -05:00
committed by GitHub
parent af2fa6acbc
commit 8b1c7759ea
25 changed files with 5273 additions and 252 deletions
@@ -6,6 +6,7 @@
;; dgos: GAME
(define-extern math-camera-matrix (function matrix))
(define-extern camera-pos (function vector))
;; DECOMP BEGINS
+1 -1
View File
@@ -5,7 +5,7 @@
;; name in dgo: game-h
;; dgos: GAME
(declare-type nav-control basic)
(declare-type nav-control structure)
(declare-type path-control basic)
(declare-type vol-control basic)
(declare-type fact-info basic)
+225
View File
@@ -5,5 +5,230 @@
;; name in dgo: path-h
;; dgos: GAME
(defenum path-control-flag
:bitfield #t
:type uint32
(display 0)
(draw-line 1) ;; TODO - only seen it used to control debug drawing so far
(draw-point 2) ;; TODO - only seen it used to control debug drawing so far
(draw-text 3) ;; TODO - only seen it used to control debug drawing so far
(not-found 4)
)
;; DECOMP BEGINS
(deftype path-control (basic)
"The path-control is a reference a path data, which is just a list of points.
Although it contains a `curve`, the knot part is not populated, so it's just treated as
a bunch of line segments from the control points.
The child class curve-control does fill out the knot data and is a proper b-spline.
These path-controls are typically allocated on a process heap."
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
(num-cverts int32 :overlay-at (-> curve num-cverts))
(cverts uint32 :overlay-at (-> curve cverts))
)
(:methods
(new (symbol type process symbol float entity symbol) _type_)
(path-control-method-9 () none)
(path-control-method-10 () none)
(path-control-method-11 () none)
(path-control-method-12 () none)
(path-control-method-13 () none)
(path-control-method-14 () none)
(path-control-method-15 () none)
(path-control-method-16 () none)
(get-num-segments (_type_) float)
(path-control-method-18 () none)
(get-num-verts (_type_) int)
(segement-duration->path-duration (_type_ float) float)
(path-duration->segment-duration (_type_ float) float)
(path-control-method-22 () none)
(path-control-method-23 () none)
(path-control-method-24 () none)
(path-control-method-25 () none)
(path-control-method-26 () none)
(path-control-method-27 () none)
(path-control-method-28 () none)
(path-control-method-29 () none)
(should-display-marks? (_type_) symbol)
(path-control-method-31 () none)
)
)
(set! (-> path-control method-table 9) nothing)
(deftype curve-control (path-control)
"A curve-control is like a path control, but it has both control points and knot points."
()
(:methods
(new (symbol type process symbol float) _type_)
)
)
;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16
;; WARN: Return type mismatch object vs path-control.
(defmethod new path-control ((allocation symbol)
(type-to-make type)
(proc process)
(lump-name symbol)
(lump-time float)
(lump-actor entity)
(must-exist symbol)
)
"Allocate a new path-control, set up the curve to point to the specified lump data."
(local-vars (v0-3 object) (sv-16 res-tag) (sv-32 float))
(set! sv-32 lump-time)
(let ((s0-0 lump-actor)
(s1-0 must-exist)
)
(if (not s0-0)
(set! s0-0 (-> proc entity))
)
(when (= lump-name 'path)
(let ((v0-0 (entity-actor-lookup s0-0 'path-actor 0)))
(if v0-0
(set! s0-0 v0-0)
)
)
)
(let ((s2-0 (the-as object 0)))
(set! sv-16 (new 'static 'res-tag))
(let* ((t9-1 (method-of-type res-lump get-property-data))
(a1-2 lump-name)
(a2-2 'interp)
(t0-1 #f)
(t1-1 (the-as (pointer res-tag) (& sv-16)))
(t2-1 *res-static-buf*)
(s0-1 (t9-1 s0-0 a1-2 a2-2 sv-32 (the-as pointer t0-1) t1-1 t2-1))
)
(cond
(s0-1
(set! s2-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))
(set! v0-3 (cond
((nonzero? (the-as path-control s2-0))
(set! (-> (the-as path-control s2-0) process) (the-as process-drawable proc))
(set! (-> (the-as path-control s2-0) name) lump-name)
(set! (-> (the-as path-control s2-0) curve cverts) (the-as (inline-array vector) s0-1))
(set! v0-3 (-> sv-16 elt-count))
(set! (-> (the-as path-control s2-0) curve num-cverts) (the-as int v0-3))
v0-3
)
(else
(go process-drawable-art-error "memory")
)
)
)
)
(else
(when (not s1-0)
(set! s2-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))
(cond
((nonzero? (the-as path-control s2-0))
(logior! (-> (the-as path-control s2-0) flags) (path-control-flag not-found))
(set! (-> (the-as path-control s2-0) process) (the-as process-drawable proc))
(set! (-> (the-as path-control s2-0) name) lump-name)
(set! (-> (the-as path-control s2-0) curve cverts) (the-as (inline-array vector) #f))
(set! (-> (the-as path-control s2-0) curve num-cverts) 0)
0
)
(else
(go process-drawable-art-error "memory")
)
)
)
)
)
)
(the-as path-control s2-0)
)
)
)
(defmethod should-display-marks? ((this path-control))
(and *display-path-marks* (logtest? (-> this flags) (path-control-flag display)))
)
(defmethod get-num-segments ((this path-control))
(the float (+ (-> this curve num-cverts) -1))
)
(defmethod get-num-verts ((this path-control))
(-> this curve num-cverts)
)
(defmethod segement-duration->path-duration ((this path-control) (arg0 float))
(* arg0 (get-num-segments this))
)
(defmethod path-duration->segment-duration ((this path-control) (arg0 float))
(/ arg0 (get-num-segments this))
)
(defmethod new curve-control ((allocation symbol) (type-to-make type) (proc process) (lump-name symbol) (lump-time float))
(let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> gp-0 process) (the-as process-drawable proc))
(set! (-> gp-0 name) lump-name)
(let* ((s3-1 (-> proc entity))
(v1-2 lump-name)
(s2-0
(cond
((= v1-2 'path)
'path-k
)
((= v1-2 'flow)
'flow-k
)
((= v1-2 'intro)
'intro-k
)
((= v1-2 'pathshort)
'pathshort-k
)
((= v1-2 'patha)
'patha-k
)
((= v1-2 'pathb)
'pathb-k
)
(else
(format
0
"WARNING: curve-control is being asked to look up an unknown name '~A', it will have to do so by string.~%"
lump-name
)
(let ((s2-1 string->symbol))
(format (clear *temp-string*) "~A-k" lump-name)
(s2-1 *temp-string*)
)
)
)
)
)
(let ((v1-3 (entity-actor-lookup s3-1 'path-actor 0)))
(if v1-3
(set! s3-1 v1-3)
)
)
(when (not (get-curve-data! s3-1 (-> gp-0 curve) lump-name s2-0 lump-time))
(cond
((> (-> gp-0 curve num-cverts) 0)
(set! (-> gp-0 type) path-control)
)
(else
(logior! (-> gp-0 flags) (path-control-flag not-found))
(set! (-> gp-0 curve cverts) (the-as (inline-array vector) #f))
(set! (-> gp-0 curve num-cverts) 0)
0
)
)
)
)
gp-0
)
)
@@ -5,5 +5,88 @@
;; name in dgo: sparticle-h
;; dgos: GAME
(declare-type sprite-vec-data-2d structure)
(defenum sp-cpuinfo-flag
:bitfield #t
:type uint32
)
;; DECOMP BEGINS
(define *sp-60-hz* #t)
(deftype sparticle-cpuinfo (structure)
"The per-particle information. This stays on the CPU, and isn't uploaded to the VU."
((sprite sprite-vec-data-2d)
(adgif adgif-shader)
(radius float)
(omega float)
(vel-sxvel vector :inline)
(rot-syvel vector :inline)
(fade rgbaf :inline)
(acc vector :inline)
(rotvel3d quaternion :inline)
(vel vector3s :inline :overlay-at (-> vel-sxvel data 0))
(accel vector3s :inline :overlay-at (-> acc data 0))
(scalevelx float :overlay-at (-> vel-sxvel data 3))
(scalevely float :overlay-at (-> rot-syvel data 3))
(friction float)
(timer int32)
(flags sp-cpuinfo-flag)
(user-int32 int32)
(user-uint32 uint32 :overlay-at user-int32)
(user-float float :overlay-at user-int32)
(user-pntr uint32 :overlay-at user-int32)
(user-object basic :overlay-at user-int32)
(user-sprite sprite-vec-data-2d :overlay-at user-int32)
(sp-func (function sparticle-system sparticle-cpuinfo sprite-vec-data-3d uint none))
(next-time uint32)
(next-launcher basic)
(cache-alpha float)
(valid uint8)
(clock-index uint8)
(user1-int16 uint16)
(key sparticle-launch-control)
(binding sparticle-launch-state)
(data uint32 1 :overlay-at omega)
(datab int8 4 :overlay-at omega)
(dataf float 1 :overlay-at omega)
(datac uint8 1 :overlay-at omega)
)
)
(deftype sparticle-launchinfo (structure)
"Settings for launching a particle. These are a temporary thing consumed by the assembly particle code, and modified by particle callbacks."
((launchrot vector :inline)
(conerot vector :inline)
(rotate-x float)
(rotate-y float)
(rotate-z float)
(coneradius float)
(rotate vector :inline :overlay-at rotate-x)
(scale-x float)
(scale-y float)
(scale-z float)
(dummy float)
(scale vector :inline :overlay-at scale-x)
(data uint8 1 :overlay-at (-> launchrot data 0))
)
)
(deftype sparticle-system (basic)
"An entire particle 'system', which is a pipeline for spawning, updating, and generating sprite-renderer DMA data.
There are separate systems for different modes of sprite rendering: 2D/billboard, full 3D, and screen-space (HUD)"
((blocks int32 2)
(length int32 2)
(num-alloc int32 2)
(is-3d basic)
(flags uint32)
(alloc-table (pointer uint64))
(cpuinfo-table (inline-array sparticle-cpuinfo))
(vecdata-table pointer)
(adgifdata-table (inline-array adgif-shader))
)
)
+377
View File
@@ -5,5 +5,382 @@
;; name in dgo: load-dgo
;; dgos: GAME
(defenum load-msg-result
:type uint16
:bitfield #f
(done 0)
(error 1)
(more 2)
(aborted 3)
(invalid 666)
)
(define-extern *load-dgo-rpc* rpc-buffer-pair)
(define-extern *load-str-rpc* rpc-buffer-pair)
(define-extern *play-str-rpc* rpc-buffer-pair)
(define-extern *load-str-lock* symbol)
(define-extern *que-str-lock* symbol)
(define-extern *dgo-name* string)
;; DECOMP BEGINS
(deftype load-dgo-msg (structure)
"IOP RPC message for loading a dgo."
((rsvd uint16)
(result load-msg-result)
(b1 pointer)
(b2 pointer)
(bt pointer)
(name uint128)
(address uint32 :overlay-at b1)
(id uint128)
(pad uint32 7)
)
)
(deftype load-chunk-msg (structure)
"IOP RPC message for loading a chunk of a chunked animation"
((rsvd uint16)
(result load-msg-result)
(address pointer)
(section uint32)
(maxlen uint32)
(dummy uint32 4)
(basename sound-stream-name :inline)
)
)
(deftype play-chunk-msg (structure)
"IOP RPC message for playing some streamed audio."
((rsvd uint16)
(result uint16)
(address pointer)
(section uint32)
(volume int32 :overlay-at section)
(maxlen uint32)
(group uint8 :overlay-at maxlen)
(id uint32 4)
(basename sound-stream-name 4 :inline)
)
)
(when (zero? *load-dgo-rpc*)
(set! *load-dgo-rpc* (new 'global 'rpc-buffer-pair (the-as uint 64) (the-as uint 1) 3))
(set! *load-str-rpc* (new 'global 'rpc-buffer-pair (the-as uint 80) (the-as uint 1) 4))
(set! *play-str-rpc* (new 'global 'rpc-buffer-pair (the-as uint 256) (the-as uint 4) 5))
(set! *load-str-lock* #f)
(set! *que-str-lock* #f)
(set! *dgo-name* (new 'global 'string 64 (the-as string #f)))
)
(defun str-load ((name string) (chunk-idx int) (dest-addr pointer) (max-len int))
"Send a message to the IOP to start loading a chunk of a .STR file to the EE."
(if (or (check-busy *load-str-rpc*) *load-str-lock*)
(return #f)
)
(let ((s2-0 (the-as load-chunk-msg (add-element *load-str-rpc*))))
(set! (-> s2-0 result) (load-msg-result invalid))
(set! (-> s2-0 address) dest-addr)
(set! (-> s2-0 section) (the-as uint chunk-idx))
(set! (-> s2-0 maxlen) (the-as uint max-len))
(copyn-charp<-string (the-as (pointer uint8) (-> s2-0 basename)) name 48)
(call *load-str-rpc* (the-as uint 0) (the-as pointer s2-0) (the-as uint 32))
)
(set! *load-str-lock* #t)
(set! *que-str-lock* #t)
#t
)
(defun str-load-status ((maxlen-out (pointer int32)))
"Get the status of the most recent load.
Return 'busy if in progress, 'error if failed, or 'complete.
If 'complete, returns the maxlen value from the IOP."
(if (check-busy *load-str-rpc*)
(return 'busy)
)
(set! *load-str-lock* #f)
(set! *que-str-lock* #t)
(let ((v1-7 (the-as load-chunk-msg (pop-last-received *load-str-rpc*))))
(if (= (-> v1-7 result) (load-msg-result error))
(return 'error)
)
(set! (-> maxlen-out 0) (the-as int (-> v1-7 maxlen)))
)
'complete
)
(defun str-load-cancel ()
"Cancel a streaming load. Note that this does not actually stop the transfer, so the IOP may continue writing to the buffer."
(set! *load-str-lock* #f)
(set! *que-str-lock* #t)
0
(none)
)
(defun str-play-async ((name string) (id sound-id) (chunk-idx int) (group int))
"Start playing a streaming audio."
(set! *que-str-lock* #t)
(let ((s2-0 (the-as play-chunk-msg (add-element *play-str-rpc*))))
(copyn-charp<-string (the-as (pointer uint8) (-> s2-0 basename)) name 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s2-0 basename 1)) "" 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s2-0 basename 2)) "" 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s2-0 basename 3)) "" 48)
(set! (-> s2-0 id 0) (the-as uint id))
(set! (-> s2-0 id 1) (the-as uint 0))
(set! (-> s2-0 id 2) (the-as uint 0))
(set! (-> s2-0 id 3) (the-as uint 0))
(set! (-> s2-0 section) (the-as uint chunk-idx))
(set! (-> s2-0 maxlen) (the-as uint 0))
(set! (-> s2-0 group) (the-as uint group))
(set! (-> s2-0 result) (the-as uint 0))
)
0
0
(none)
)
(defun str-play-stop ((name string) (id sound-id))
"Stop playing streaming audio."
(set! *que-str-lock* #t)
(let ((s4-0 (the-as play-chunk-msg (add-element *play-str-rpc*))))
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename)) name 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 1)) "" 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 2)) "" 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 3)) "" 48)
(set! (-> s4-0 id 0) (the-as uint id))
(set! (-> s4-0 id 1) (the-as uint 0))
(set! (-> s4-0 id 2) (the-as uint 0))
(set! (-> s4-0 id 3) (the-as uint 0))
(set! (-> s4-0 result) (the-as uint 1))
)
0
(none)
)
(defun str-play-queue ((name0 string) (name1 string) (name2 string) (name3 string) (ids (pointer uint32)) (mask pointer))
"Queue up streaming data, allowing it to start playing without delay."
(when (and (not (check-busy *play-str-rpc*)) (not *que-str-lock*))
(let ((s4-0 (the-as play-chunk-msg (add-element *play-str-rpc*))))
(if name0
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename)) name0 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename)) "" 48)
)
(if name1
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 1)) name1 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 1)) "" 48)
)
(if name2
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 2)) name2 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 2)) "" 48)
)
(if name3
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 3)) name3 48)
(copyn-charp<-string (the-as (pointer uint8) (-> s4-0 basename 3)) "" 48)
)
(dotimes (v1-14 4)
(set! (-> s4-0 id v1-14) (-> ids v1-14))
)
(set! (-> s4-0 address) mask)
(set! (-> s4-0 result) (the-as uint 2))
)
)
(set! *que-str-lock* #f)
0
(none)
)
(defun str-ambient-play ((name string))
"Start playing ambient (unused?)."
(set! *que-str-lock* #t)
(let ((s5-0 (the-as play-chunk-msg (add-element *play-str-rpc*))))
(set! (-> s5-0 basename 0 name 0) (the-as uint 36))
(copyn-charp<-string (&-> s5-0 basename 0 name 1) name 48)
(set! (-> s5-0 result) (the-as uint 0))
)
0
0
(none)
)
(defun str-ambient-stop ((name string))
"Stop playing ambient (unused?)."
(set! *que-str-lock* #t)
(let ((s5-0 (the-as play-chunk-msg (add-element *play-str-rpc*))))
(set! (-> s5-0 basename 0 name 0) (the-as uint 36))
(copyn-charp<-string (&-> s5-0 basename 0 name 1) name 48)
(set! (-> s5-0 result) (the-as uint 1))
)
0
(none)
)
(defun str-play-kick ()
"Do an empty RPC on play so the IOP code runs and can update buffers."
(cond
((check-busy *play-str-rpc*)
)
(else
(call *play-str-rpc* (the-as uint 0) (the-as pointer 0) (the-as uint 0))
)
)
0
(none)
)
(define *dgo-time* (the-as time-frame 0))
(defun dgo-load-begin ((name string) (buffer1 uint128) (buffer2 pointer) (buffer-top pointer) (arg4 pointer))
"Start a DGO load!"
(set! *dgo-time* (-> *display* real-clock integral-frame-counter))
(format 0 "Starting level load clock~%")
(sync *load-dgo-rpc* #t)
(let ((s1-0 (the-as load-dgo-msg (add-element *load-dgo-rpc*))))
(set! (-> s1-0 result) (load-msg-result invalid))
(set! (-> s1-0 b1) buffer2)
(set! (-> s1-0 b2) buffer-top)
(set! (-> s1-0 bt) arg4)
(set! (-> s1-0 name) (string->sound-name name))
(set! (-> s1-0 id) buffer1)
(call *load-dgo-rpc* (the-as uint 0) (the-as pointer s1-0) (the-as uint 32))
s1-0
)
)
(defun dgo-load-get-next ((done-out (pointer symbol)))
"Get the address of the most recently loaded object. #f is there is none. Returns if this is the last by arg0."
(set! (-> done-out 0) #f)
(let ((gp-0 (the-as pointer #f)))
(when (not (check-busy *load-dgo-rpc*))
(let ((v1-4 (the-as load-dgo-msg (pop-last-received *load-dgo-rpc*))))
(when v1-4
(when (or (= (-> v1-4 result) (load-msg-result done)) (= (-> v1-4 result) (load-msg-result more)))
(set! gp-0 (-> v1-4 b1))
(set! (-> done-out 0) #t)
)
(if (= (-> v1-4 result) (load-msg-result more))
(set! (-> done-out 0) #f)
)
(if (= (-> v1-4 result) (load-msg-result done))
(format
0
"Elapsed time for level = ~Fs~%"
(* 0.016666668 (the float (- (-> *display* real-clock integral-frame-counter) *dgo-time*)))
)
)
)
)
)
gp-0
)
)
(defun dgo-load-continue ((buffer1 pointer) (buffer2 pointer) (buffer-top pointer))
"Inform the IOP that it is safe to start loading the next object."
(let ((gp-0 (the-as load-dgo-msg (add-element *load-dgo-rpc*))))
(set! (-> gp-0 result) (load-msg-result invalid))
(set! (-> gp-0 b1) buffer1)
(set! (-> gp-0 b2) buffer2)
(set! (-> gp-0 bt) buffer-top)
(set! (-> gp-0 name) (the-as uint128 0))
(call *load-dgo-rpc* (the-as uint 1) (the-as pointer gp-0) (the-as uint 32))
gp-0
)
)
(defun dgo-load-cancel ((arg0 int))
"Abort a DGO load."
(let ((v1-0 (the-as sound-rpc-cancel-dgo (get-sound-buffer-entry))))
(set! (-> v1-0 command) (the-as uint 49))
(set! (-> v1-0 id) (the-as uint arg0))
)
0
(none)
)
(defun find-temp-buffer ((size int))
"Unused function to find some temporary leftover space in DMA buffer.
Unused since jak 1, and checks the same buffer twice??"
(let ((gp-0 (+ (/ size 16) 2)))
(cond
((< (the-as uint gp-0)
(the-as uint (dma-buffer-free (-> *display* frames (-> *display* on-screen) global-buf)))
)
(logand -16 (&+ (-> *display* frames (-> *display* on-screen) global-buf base) 15))
)
((< (the-as uint gp-0)
(the-as uint (dma-buffer-free (-> *display* frames (-> *display* on-screen) global-buf)))
)
(logand -16 (&+ (-> *display* frames (-> *display* on-screen) global-buf base) 15))
)
)
)
)
(defun dgo-load-link ((object-file dgo-header) (heap kheap) (end-of-buffer uint) (print-login symbol) (loaded-from-top symbol))
"Start the async linker on a GOAL object file that was just loaded."
(let ((s4-0 (the-as object (&+ object-file 64))))
(let ((v1-0 end-of-buffer))
(cond
((>= (the-as int (+ (the-as uint s4-0) (-> object-file length))) (the-as int (-> heap top-base)))
(format
0
"ERROR: -----> dgo file header ~g #x~X has overrun heap #x~X by ~D bytes. This is very bad!~%"
(-> object-file rootname)
object-file
heap
(- (+ (the-as uint s4-0) (-> object-file length)) (the-as uint (-> heap top-base)))
)
)
((and (< (the-as int object-file) (the-as int v1-0))
(>= (the-as int (+ (the-as uint s4-0) (-> object-file length))) (the-as int v1-0))
)
(format
0
"ERROR: -----> dgo file header ~g #x~X has overrun heap #x~X by ~D bytes. This is very bad!~%"
(-> object-file rootname)
object-file
heap
(- (+ (the-as uint s4-0) (-> object-file length)) v1-0)
)
)
)
)
(if loaded-from-top
(format
0
"NOTICE: loaded ~g, ~D bytes (~f K) at top ~D at #x~X - #x~X~%"
(-> object-file rootname)
(-> object-file length)
(* 0.0009765625 (the float (-> object-file length)))
(- (+ (the-as uint s4-0) (-> object-file length)) (the-as uint (-> heap base)))
object-file
(&+ (the-as pointer s4-0) (-> object-file length))
)
)
(string<-charp (clear *dgo-name*) (-> object-file rootname))
(nonzero? (link-begin
(the-as pointer s4-0)
(-> *dgo-name* data)
(the-as int (-> object-file length))
heap
(if print-login
(link-flag output-load-msg output-load-true-msg execute-login print-login fast-link)
(link-flag output-load-msg output-load-true-msg execute-login fast-link)
)
)
)
)
)
(defun destroy-mem ((start (pointer uint32)) (end (pointer uint32)))
"Overwrite memory with #xffffffff for debugging."
(while (< (the-as int start) (the-as int end))
(set! (-> start 0) (the-as uint #xffffffff))
(set! start (&-> start 1))
)
0
(none)
)
+210
View File
@@ -5,5 +5,215 @@
;; name in dgo: nav-control-h
;; dgos: GAME
(defenum nav-state-flag
:type uint32
:bitfield #t
(display-marks 0)
(recovery-mode 1)
(initialized 2)
(debug 3)
(directional-mode 4)
(trapped-by-sphere 5)
(target-poly-dirty 6)
(blocked 7)
(in-target-poly 8)
(at-target 9)
(target-inside 10)
(in-mesh 11)
(avoiding-sphere 12)
(touching-sphere 13)
(at-gap 14)
(use-position 15)
)
(defenum nav-control-flag
:type uint32
:bitfield #t
(display-marks 0) ;; 1
(debug 1) ;; 2
(no-redirect-in-clamp 2) ;; 4
(limit-rotation-rate 3) ;; 8
(update-heading-from-facing 4) ;; 16
(use-momentum 5) ;; 32
(momentum-ignore-heading 6) ;; 64
(output-sphere-hash 7) ;; 128
(kernel-run 8) ;; 256
)
;; DECOMP BEGINS
(deftype check-vector-collision-with-nav-spheres-info (structure)
((u float)
(intersect vector :inline)
(normal vector :inline)
)
)
(deftype nav-gap-info (structure)
((dest vector :inline)
(poly nav-poly)
)
)
(deftype nav-avoid-spheres-params (structure)
((current-pos vector :inline)
(travel vector :inline)
(pref-dir vector :inline)
(out-travel vector 2 :inline)
(closest-sphere-dist2 float)
(avoiding-sphere? symbol)
)
)
(deftype nav-callback-info (structure)
((callback-count int32)
(callback-array (function object nav-control none) 10)
)
)
(deftype nav-state (structure)
((flags nav-state-flag)
(nav nav-control)
(user-poly nav-poly)
(mesh nav-mesh)
(current-poly nav-poly)
(virtual-current-poly nav-poly)
(next-poly nav-poly)
(target-poly nav-poly)
(rotation-rate float)
(speed meters)
(prev-speed meters)
(pad0 uint32 1)
(travel vector :inline)
(target-pos vector :inline)
(current-pos vector :inline)
(current-pos-local vector :inline)
(virtual-current-pos-local vector :inline)
(velocity vector :inline)
(heading vector :inline)
(target-dir vector :inline)
(accel vector :inline :overlay-at target-dir)
(user-position vector :inline :overlay-at virtual-current-pos-local)
)
(:methods
(nav-state-method-9 () none)
(nav-state-method-10 () none)
(nav-state-method-11 () none)
(nav-state-method-12 () none)
(nav-state-method-13 () none)
(nav-state-method-14 () none)
(nav-state-method-15 () none)
(nav-state-method-16 () none)
(nav-state-method-17 () none)
(nav-state-method-18 () none)
(nav-state-method-19 () none)
(nav-state-method-20 () none)
(nav-state-method-21 () none)
(nav-state-method-22 () none)
(nav-state-method-23 () none)
(nav-state-method-24 () none)
(nav-state-method-25 () none)
(nav-state-method-26 () none)
(nav-state-method-27 () none)
(nav-state-method-28 () none)
(nav-state-method-29 () none)
(nav-state-method-30 () none)
(nav-state-method-31 () none)
(nav-state-method-32 () none)
(nav-state-method-33 () none)
(nav-state-method-34 () none)
(nav-state-method-35 () none)
(nav-state-method-36 () none)
(nav-state-method-37 () none)
(nav-state-method-38 () none)
(nav-state-method-39 () none)
(nav-state-method-40 () none)
(nav-state-method-41 () none)
(nav-state-method-42 () none)
(nav-state-method-43 () none)
(nav-state-method-44 () none)
(nav-state-method-45 () none)
(nav-state-method-46 () none)
(nav-state-method-47 () none)
(nav-state-method-48 () none)
(nav-state-method-49 () none)
(nav-state-method-50 () none)
(nav-state-method-51 () none)
(nav-state-method-52 () none)
(nav-state-method-53 () none)
(nav-state-method-54 () none)
(nav-state-method-55 () none)
)
)
(deftype nav-control (structure)
((flags nav-control-flag)
(callback-info nav-callback-info)
(process process)
(pad0 uint32)
(shape collide-shape)
(nearest-y-threshold meters)
(nav-cull-radius meters)
(sec-per-frame float)
(target-speed meters)
(acceleration meters)
(turning-acceleration meters)
(max-rotation-rate float)
(speed-scale float)
(sphere-count int32)
(sphere-array (inline-array sphere))
(root-sphere-id uint8)
(sphere-mask uint8)
(pad1 uint8 2)
(sphere-id-array uint8 16)
(extra-nav-sphere vector :inline)
(root-nav-sphere vector :inline)
(state nav-state :inline)
(mesh basic :overlay-at (-> state mesh))
)
(:methods
(nav-control-method-9 () none)
(nav-control-method-10 () none)
(nav-control-method-11 () none)
(nav-control-method-12 () none)
(nav-control-method-13 () none)
(nav-control-method-14 () none)
(nav-control-method-15 () none)
(nav-control-method-16 () none)
(nav-control-method-17 () none)
(nav-control-method-18 () none)
(nav-control-method-19 () none)
(nav-control-method-20 () none)
(nav-control-method-21 () none)
(nav-control-method-22 () none)
(nav-control-method-23 () none)
(nav-control-method-24 () none)
(nav-control-method-25 () none)
(nav-control-method-26 () none)
(nav-control-method-27 () none)
(nav-control-method-28 () none)
(nav-control-method-29 () none)
(nav-control-method-30 () none)
(nav-control-method-31 () none)
(nav-control-method-32 () none)
(nav-control-method-33 () none)
(nav-control-method-34 () none)
(nav-control-method-35 () none)
(nav-control-method-36 () none)
(nav-control-method-37 () none)
(nav-control-method-38 () none)
(nav-control-method-39 () none)
(nav-control-method-40 () none)
(nav-control-method-41 () none)
(nav-control-method-42 () none)
(nav-control-method-43 () none)
(nav-control-method-44 () none)
(nav-control-method-45 () none)
(nav-control-method-46 () none)
)
)
+540
View File
@@ -5,5 +5,545 @@
;; name in dgo: nav-mesh-h
;; dgos: GAME
(declare-type grid-hash structure)
(declare-type sphere-hash structure)
(defenum nav-mesh-flag
:type uint8
:bitfield #t
(water 0)
(dummy 1)
)
;; DECOMP BEGINS
(deftype nav-mesh-work-debug (structure)
"Debug outputs for the nav-mesh assembly functions"
((debug-vec1 vector :inline)
(debug-vec2 vector :inline)
(debug-vec3 vector :inline)
(debug-vec4 vector :inline)
(debug-vec5 vector :inline)
(debug-vec6 vector :inline)
(debug-vec7 vector :inline)
(debug-vec8 vector :inline)
(debug-vec9 vector :inline)
(debug-vec10 vector :inline)
(debug-vec11 vector :inline)
(debug-vec12 vector :inline)
(sphere-array sphere 16 :inline)
)
)
(deftype nav-mesh-work (structure)
"Workspace for nav-mesh processing functions."
((vert0-table int8 4)
(vert1-table int8 4)
(edge-mask-table uint8 3)
(pad0 uint32)
(deg-to-rad float)
(rad-to-deg float)
(nav-poly-min-dist float)
(nav-poly-epsilon float)
(sphere-array sphere 16 :inline)
(debug nav-mesh-work-debug)
(work-struct-in-scratch int8)
(mesh-struct-in-scratch int8)
(polys-in-scratch int8)
(mesh nav-mesh)
(nav basic)
(poly0 nav-poly)
(poly1 nav-poly)
(poly-id int32)
)
)
(deftype nav-mesh-link (structure)
"Link between two different meshes"
((id uint32)
(dest-mesh-id uint32)
(src-link-poly-id uint8)
(src-switch-poly-id uint8)
(dest-link-poly-id uint8)
(dest-switch-poly-id uint8)
(dest-mesh nav-mesh)
)
)
(deftype nav-poly (structure)
"Polygon within a nav-mesh. Can be a tri or quad.
Based on the implementation of point-poly-intersection?, these should likely be convex."
((data uint8 64 :offset 0)
(vertex vector 4 :inline :overlay-at (-> data 0))
(vertex0 vector :inline :overlay-at (-> vertex 0))
(vertex1 vector :inline :overlay-at (-> vertex 1))
(vertex2 vector :inline :overlay-at (-> vertex 2))
(vertex3 vector :inline :overlay-at (-> vertex 3))
(id uint8 :overlay-at (-> data 12))
(pat uint8 :overlay-at (-> data 13))
(vertex-count uint8 :overlay-at (-> data 14))
(link uint8 :overlay-at (-> data 15))
(adj-poly uint8 4 :overlay-at (-> data 28))
(adj-poly0 uint8 :overlay-at (-> adj-poly 0))
(adj-poly1 uint8 :overlay-at (-> adj-poly 1))
(adj-poly2 uint8 :overlay-at (-> adj-poly 2))
(adj-poly3 uint8 :overlay-at (-> adj-poly 3))
(min-y float :overlay-at (-> data 44))
(max-y float :overlay-at (-> data 60))
)
)
(deftype nav-vertex (vector)
()
)
(deftype nav-sphere (structure)
((trans sphere :inline)
)
)
(deftype nav-ray (structure)
((current-pos vector :inline)
(dir vector :inline)
(dest-pos vector :inline)
(current-poly nav-poly)
(next-poly nav-poly)
(len meters)
(last-edge int8)
(ignore uint8)
(terminated symbol)
(reached-dest symbol)
(hit-boundary symbol)
(hit-gap symbol)
)
)
(deftype nav-route-portal (structure)
((vertex nav-vertex 2 :inline)
(next-poly nav-poly)
(edge-index int8)
)
)
(deftype nav-find-poly-parms (structure)
((point vector :inline)
(y-threshold float)
(ignore uint8)
(poly nav-poly)
(dist float)
(point-inside? symbol)
)
)
(deftype clamp-travel-vector-to-mesh-return-info (structure)
((found-boundary symbol)
(intersection vector :inline)
(boundary-normal vector :inline)
(prev-normal vector :inline)
(next-normal vector :inline)
(poly nav-poly)
(gap-poly nav-poly)
(edge int8)
(ignore uint8)
(vert-prev vector :inline)
(vert-0 vector :inline)
(vert-1 vector :inline)
(vert-next vector :inline)
)
)
(deftype nav-mesh (basic)
"Mesh used for creature/enemy navigation."
((work nav-mesh-work)
(poly-array (inline-array nav-poly))
(static-sphere-count uint8)
(poly-count uint8)
(nav-control-count uint8)
(max-nav-control-count uint8)
(route (pointer uint8))
(poly-hash grid-hash)
(nav-control-array (inline-array nav-control))
(sphere-hash sphere-hash)
(static-sphere (inline-array sphere))
(user-list engine)
(next-nav-mesh surface)
(prev-nav-mesh surface)
(bounds sphere :inline)
(origin vector :inline :overlay-at (-> bounds data 0))
(entity entity)
(link-array (inline-array nav-mesh-link))
(link-count uint8)
(flags nav-mesh-flag)
(pad1 uint8 2)
(nearest-y-threshold meters)
(water-max-height meters)
(pad2 uint32 7)
)
(:methods
(nav-mesh-method-9 () none)
(nav-mesh-method-10 () none)
(nav-mesh-method-11 () none)
(nav-mesh-method-12 () none)
(nav-mesh-method-13 () none)
(nav-mesh-method-14 () none)
(nav-mesh-method-15 () none)
(nav-mesh-method-16 () none)
(nav-mesh-method-17 () none)
(advance-ray-to-nearest-poly-edge-or-dest! (_type_ nav-ray) none)
(nav-mesh-method-19 () none)
(nav-mesh-method-20 () none)
(nav-mesh-method-21 () none)
(nav-mesh-method-22 () none)
(nav-mesh-method-23 () none)
(nav-mesh-method-24 () none)
(nav-mesh-method-25 () none)
(nav-mesh-method-26 () none)
(nav-mesh-method-27 () none)
(nav-mesh-method-28 () none)
(nav-mesh-method-29 () none)
(nav-mesh-method-30 () none)
(nav-mesh-method-31 () none)
(nav-mesh-method-32 () none)
(nav-mesh-method-33 () none)
(nav-mesh-method-34 () none)
(nav-mesh-method-35 () none)
(nav-mesh-method-36 () none)
(nav-mesh-method-37 () none)
(nav-mesh-method-38 () none)
(nav-mesh-method-39 () none)
(point-in-poly? (_type_ nav-poly vector) symbol)
(nav-mesh-method-41 () none)
(closest-point-on-boundary (_type_ nav-poly vector vector) vector)
(nav-mesh-method-43 () none)
(project-point-into-poly-2d (_type_ nav-poly vector vector) vector)
(nav-mesh-method-45 () none)
(nav-mesh-method-46 () none)
(nav-mesh-method-47 () none)
(nav-mesh-method-48 () none)
(nav-mesh-method-49 () none)
)
)
(defun vector-normalize-unity! ((arg0 vector))
"Normalize a vector (xyz only) in place."
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
)
(init-vf0-vector)
(let ((v0-0 arg0))
(let ((f0-0 1.0))
(.lvf vf1 (&-> v0-0 quad))
(.mul.vf vf2 vf1 vf1 :mask #b111)
(let ((v1-1 f0-0))
(.mov vf3 v1-1)
)
)
(.mul.x.vf acc vf0 vf2 :mask #b1000)
(.add.mul.y.vf acc vf0 vf2 acc :mask #b1000)
(.add.mul.z.vf vf2 vf0 vf2 acc :mask #b1000)
(.isqrt.vf Q vf3 vf2 :fsf #b0 :ftf #b11)
(.wait.vf)
(.mul.vf vf1 vf1 Q :mask #b111)
(.nop.vf)
(.nop.vf)
(.nop.vf)
(.svf (&-> v0-0 quad) vf1)
v0-0
)
)
)
(defun vector-normalize-unity-copy! ((arg0 vector) (arg1 vector))
"Normalize a vector (xyz only)"
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
)
(init-vf0-vector)
(set! (-> arg0 quad) (-> arg1 quad))
(let ((v0-0 arg0))
(let ((f0-0 1.0))
(.lvf vf1 (&-> v0-0 quad))
(.mul.vf vf2 vf1 vf1 :mask #b111)
(let ((v1-2 f0-0))
(.mov vf3 v1-2)
)
)
(.mul.x.vf acc vf0 vf2 :mask #b1000)
(.add.mul.y.vf acc vf0 vf2 acc :mask #b1000)
(.add.mul.z.vf vf2 vf0 vf2 acc :mask #b1000)
(.isqrt.vf Q vf3 vf2 :fsf #b0 :ftf #b11)
(.wait.vf)
(.mul.vf vf1 vf1 Q :mask #b111)
(.nop.vf)
(.nop.vf)
(.nop.vf)
(.svf (&-> v0-0 quad) vf1)
v0-0
)
)
)
(defun-debug debug-validate-current-poly ()
"Not implemented."
#f
)
(defun init-ray ((arg0 nav-ray))
"Set up a nav-ray. Assumes that dest-pos and current-pos are set."
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
)
(init-vf0-vector)
(vector-! (-> arg0 dir) (-> arg0 dest-pos) (-> arg0 current-pos))
(set! (-> arg0 dir y) 0.0)
(let ((v1-1 (-> arg0 dir)))
(let ((f0-1 1.0))
(.lvf vf1 (&-> v1-1 quad))
(.mul.vf vf2 vf1 vf1 :mask #b111)
(let ((a1-2 f0-1))
(.mov vf3 a1-2)
)
)
(.mul.x.vf acc vf0 vf2 :mask #b1000)
(.add.mul.y.vf acc vf0 vf2 acc :mask #b1000)
(.add.mul.z.vf vf2 vf0 vf2 acc :mask #b1000)
(.isqrt.vf Q vf3 vf2 :fsf #b0 :ftf #b11)
(.wait.vf)
(.mul.vf vf1 vf1 Q :mask #b111)
(.nop.vf)
(.nop.vf)
(.nop.vf)
(.svf (&-> v1-1 quad) vf1)
)
(set! (-> arg0 next-poly) #f)
(set! (-> arg0 len) 0.0)
(set! (-> arg0 last-edge) -1)
(set! (-> arg0 terminated) #f)
(set! (-> arg0 reached-dest) #f)
(set! (-> arg0 hit-boundary) #f)
(set! (-> arg0 hit-gap) #f)
(set! (-> arg0 ignore) (the-as uint 3))
0
(none)
)
)
(defun point-poly-intersection? ((mesh nav-mesh) (pt vector) (num-verts int) (verts (inline-array vector)))
"Check if a point is inside a poly."
(let ((v1-1 (-> mesh work vert0-table))
(a0-2 (-> mesh work vert1-table))
)
(dotimes (t0-0 num-verts)
(let* ((t1-3 (-> verts (-> v1-1 t0-0)))
(t2-3 (-> verts (-> a0-2 t0-0)))
(f0-1 (- (-> t1-3 z) (-> t2-3 z)))
(f1-2 (- (-> t2-3 x) (-> t1-3 x)))
(f2-2 (- (-> pt x) (-> t1-3 x)))
(f3-2 (- (-> pt z) (-> t1-3 z)))
(f0-3 (+ (* f2-2 f0-1) (* f3-2 f1-2)))
)
(if (< 0.0 f0-3)
(return #f)
)
)
)
)
#t
)
(defmethod point-in-poly? ((this nav-mesh) (arg0 nav-poly) (arg1 vector))
"Check if a point is inside a poly of this mesh"
(let* ((a3-0 this)
(v1-0 arg1)
(a0-1 (-> arg0 vertex-count))
(a1-1 (-> arg0 vertex))
(a2-2 (-> a3-0 work vert0-table))
(a3-2 (-> a3-0 work vert1-table))
)
(dotimes (t0-0 (the-as int a0-1))
(let* ((t1-3 (-> a1-1 (-> a2-2 t0-0)))
(t2-3 (-> a1-1 (-> a3-2 t0-0)))
(f0-1 (- (-> t1-3 z) (-> t2-3 z)))
(f1-2 (- (-> t2-3 x) (-> t1-3 x)))
(f2-2 (- (-> v1-0 x) (-> t1-3 x)))
(f3-2 (- (-> v1-0 z) (-> t1-3 z)))
(f0-3 (+ (* f2-2 f0-1) (* f3-2 f1-2)))
)
(if (< 0.0 f0-3)
(return #f)
)
)
)
)
#t
)
(defmethod closest-point-on-boundary ((this nav-mesh) (arg0 nav-poly) (arg1 vector) (arg2 vector))
"Find the point on the polygon edge that is closest to the query point."
(local-vars (sv-48 vector) (sv-52 vector) (sv-56 number))
(set! sv-48 (new 'stack-no-clear 'vector))
(set! sv-52 (new 'stack-no-clear 'vector))
(set! sv-56 10000000000000000000000000000000000000.0)
(let* ((s3-0 (-> arg0 vertex-count))
(v1-3 (the-as int (+ s3-0 -1)))
)
(dotimes (s2-0 (the-as int s3-0))
(let ((f0-1 (vector-segment-distance-point! arg2 (-> arg0 vertex v1-3) (-> arg0 vertex s2-0) sv-48)))
(when (< f0-1 (the-as float sv-56))
(set! sv-56 f0-1)
(set! (-> sv-52 quad) (-> sv-48 quad))
)
)
(set! v1-3 s2-0)
)
)
(set! (-> arg1 quad) (-> sv-52 quad))
arg1
)
(defmethod project-point-into-poly-2d ((this nav-mesh) (arg0 nav-poly) (arg1 vector) (arg2 vector))
"Find the point in the polygon closest to the query point."
(local-vars (sv-48 vector) (sv-52 vector) (sv-56 number))
(cond
((point-in-poly? this arg0 arg2)
(set! (-> arg1 quad) (-> arg2 quad))
)
(else
(let ((s5-1 arg1))
(set! sv-48 (new 'stack-no-clear 'vector))
(set! sv-52 (new 'stack-no-clear 'vector))
(set! sv-56 10000000000000000000000000000000000000.0)
(let* ((s2-0 (-> arg0 vertex-count))
(v1-6 (the-as int (+ s2-0 -1)))
)
(dotimes (s1-0 (the-as int s2-0))
(let ((f0-1 (vector-segment-distance-point! arg2 (-> arg0 vertex v1-6) (-> arg0 vertex s1-0) sv-48)))
(when (< f0-1 (the-as float sv-56))
(set! sv-56 f0-1)
(set! (-> sv-52 quad) (-> sv-48 quad))
)
)
(set! v1-6 s1-0)
)
)
(set! (-> s5-1 quad) (-> sv-52 quad))
)
)
)
arg1
)
(defmethod advance-ray-to-nearest-poly-edge-or-dest! ((this nav-mesh) (arg0 nav-ray))
(local-vars
(sv-16 int)
(sv-24 nav-mesh-work)
(sv-28 nav-poly)
(sv-32 uint)
(sv-36 (pointer int8))
(sv-40 (pointer int8))
(sv-44 float)
(sv-48 float)
(sv-52 vector)
(sv-56 vector)
(sv-60 float)
(sv-64 float)
(sv-68 uint)
)
(set! sv-16 -1)
(set! sv-24 (-> this work))
(set! sv-28 (-> arg0 current-poly))
(set! sv-32 (-> arg0 current-poly vertex-count))
(set! sv-36 (-> this work vert0-table))
(set! sv-40 (-> this work vert1-table))
(set! sv-44 (- (-> arg0 dest-pos x) (-> arg0 current-pos x)))
(set! sv-48 (- (-> arg0 dest-pos z) (-> arg0 current-pos z)))
(dotimes (v1-9 (the-as int sv-32))
(set! sv-52 (-> sv-28 vertex (-> sv-36 v1-9)))
(set! sv-56 (-> sv-28 vertex (-> sv-40 v1-9)))
(set! sv-60 (- (-> sv-52 z) (-> sv-56 z)))
(set! sv-64 (- (-> sv-56 x) (-> sv-52 x)))
(let ((f0-10 (+ (* sv-44 sv-60) (* sv-48 sv-64))))
(when (< 0.0 f0-10)
(let ((f1-10
(+ (* sv-60 (- (-> sv-52 x) (-> arg0 current-pos x))) (* sv-64 (- (-> sv-52 z) (-> arg0 current-pos z))))
)
)
(when (< f1-10 f0-10)
(set! sv-16 v1-9)
(let ((f0-12 (fmax 0.0 (/ f1-10 f0-10))))
(set! sv-44 (* sv-44 f0-12))
(set! sv-48 (* sv-48 f0-12))
)
)
)
)
)
)
(let ((f0-16 (+ (* sv-44 (-> arg0 dir x)) (* sv-48 (-> arg0 dir z)))))
(+! (-> arg0 len) f0-16)
)
0
(set! (-> arg0 next-poly) #f)
(cond
((= sv-16 -1)
(set! (-> arg0 current-pos quad) (-> arg0 dest-pos quad))
(set! (-> arg0 reached-dest) #t)
(set! (-> arg0 terminated) #t)
)
(else
(+! (-> arg0 current-pos x) sv-44)
(+! (-> arg0 current-pos z) sv-48)
(set! sv-68 (-> sv-28 adj-poly sv-16))
(if (!= sv-68 255)
(set! (-> arg0 next-poly) (-> this poly-array sv-68))
)
(cond
((and (-> arg0 next-poly) (not (logtest? (-> arg0 next-poly pat) (-> arg0 ignore))))
(set! (-> arg0 current-poly) (-> arg0 next-poly))
)
(else
(set! (-> arg0 last-edge) sv-16)
(if (-> arg0 next-poly)
(set! (-> arg0 hit-gap) #t)
(set! (-> arg0 hit-boundary) #t)
)
(set! (-> arg0 terminated) #t)
)
)
)
)
0
(none)
)
(defun-debug nav-sphere-from-cam ()
"Print out a SPHEREM from the current camera position, possibly used by their level-building tool."
(let ((v1-0 (camera-pos)))
(format #t "SPHEREM(~4,,1M, ~4,,1M, ~4,,1M, 1.0)~%" (-> v1-0 x) (-> v1-0 y) (-> v1-0 z))
)
0
(none)
)
@@ -5,5 +5,249 @@
;; name in dgo: rigid-body-h
;; dgos: GAME
;; +++rigid-body-h:rigid-body-flag
(defenum rigid-body-flag
:bitfield #t
:type uint32
(display-marks 0)
(enable-physics 1)
(enable-collision 2)
(active 3)
(debug 4)
(blocker 5)
)
;; ---rigid-body-h:rigid-body-flag
;; +++rigid-body-h:rigid-body-object-flag
(defenum rigid-body-object-flag
:bitfield #t
:type uint64
(enable-collision 0)
(disturbed 1)
(damaged 2)
(dead 3)
(player-touching 4)
(player-edge-grabbing 5)
(player-standing-on 6)
(player-impulse-force 7)
(player-contact-force 8)
(persistent 9)
(in-air 10)
(on-ground 11)
(on-flight-level 12)
(riding 13)
(player-driving 14)
(waiting-for-player 15)
(ignition 16)
(turbo-boost 17)
(reverse-gear 18)
(slide 19)
(hard-turn 20)
(jump 21)
(jump-sound 22)
(ai-driving 23)
(traffic-managed 24)
(flight-level-transition 25)
(flight-level-transition-ending 26)
(camera-bike-mode 27)
(camera-rapid-track-mode 28)
(camera 29)
(alert 30)
(in-pursuit 31)
(target-in-sight 32)
(rammed-target 33)
(draw-marks 34)
(hack-edit-graph-mode 35)
(measure-control-parameters 36)
(lights-on 37)
(lights-update 38)
(lights-dead 39)
(no-hijack 40)
(player-grabbed 41)
(nav-spheres 42)
(idle-sound 43)
)
;; ---rigid-body-h:rigid-body-object-flag
;; DECOMP BEGINS
(deftype rigid-body-info (structure)
((mass float)
(inv-mass float)
(linear-damping float)
(angular-damping float)
(bounce-factor float)
(friction-factor float)
(bounce-mult-factor float)
(cm-offset-joint vector :inline)
(inv-inertial-tensor matrix :inline)
(inertial-tensor matrix :inline)
(inertial-tensor-box meters 3)
)
(:methods
(rigid-body-info-method-9 () none)
)
)
(deftype rigid-body-object-extra-info (structure)
((max-time-step float)
(gravity meters)
(idle-distance meters)
(attack-force-scale float)
)
:pack-me
)
(deftype rigid-body-object-constants (structure)
((info rigid-body-info :inline)
(mass float :overlay-at (-> info mass))
(inv-mass float :overlay-at (-> info inv-mass))
(cm-joint-x meters :overlay-at (-> info cm-offset-joint data 0))
(cm-joint-y meters :overlay-at (-> info cm-offset-joint data 1))
(cm-joint-z meters :overlay-at (-> info cm-offset-joint data 2))
(linear-damping float :overlay-at (-> info linear-damping))
(angular-damping float :overlay-at (-> info angular-damping))
(bounce-factor float :overlay-at (-> info bounce-factor))
(friction-factor float :overlay-at (-> info friction-factor))
(inertial-tensor-x meters :overlay-at (-> info inertial-tensor-box 0))
(inertial-tensor-y meters :overlay-at (-> info inertial-tensor-box 1))
(inertial-tensor-z meters :overlay-at (-> info inertial-tensor-box 2))
(extra rigid-body-object-extra-info :inline)
(max-time-step float :overlay-at (-> extra max-time-step))
(gravity meters :overlay-at (-> extra gravity))
(idle-distance meters :overlay-at (-> extra idle-distance))
(attack-force-scale float :overlay-at (-> extra attack-force-scale))
(name symbol)
)
)
(deftype rigid-body-impact (structure)
((point vector :inline)
(normal vector :inline)
(velocity vector :inline)
(impulse float)
(pat pat-surface)
(process basic)
(prim-id uint32)
)
)
(deftype rigid-body-control (basic)
((flags rigid-body-flag)
(info rigid-body-info)
(force-callback basic)
(process process)
(blocked-by basic)
(time-remaining float)
(step-count int16)
(linear-damping float)
(angular-damping float)
(bounce-factor float)
(friction-factor float)
(position vector :inline)
(rot vector :inline)
(rotation quaternion :inline :overlay-at (-> rot data 0))
(lin-momentum vector :inline)
(ang-momentum vector :inline)
(force vector :inline)
(torque vector :inline)
(lin-velocity vector :inline)
(ang-velocity vector :inline)
(matrix matrix :inline)
(inv-i-world matrix :inline)
)
(:methods
(new (symbol type) _type_)
(rigid-body-control-method-9 () none)
(rigid-body-control-method-10 () none)
(rigid-body-control-method-11 () none)
(rigid-body-control-method-12 () none)
(rigid-body-control-method-13 () none)
(rigid-body-control-method-14 () none)
(rigid-body-control-method-15 () none)
(rigid-body-control-method-16 () none)
(rigid-body-control-method-17 () none)
(rigid-body-control-method-18 () none)
(rigid-body-control-method-19 () none)
(rigid-body-control-method-20 () none)
(rigid-body-control-method-21 () none)
(rigid-body-control-method-22 () none)
(rigid-body-control-method-23 () none)
(rigid-body-control-method-24 () none)
(rigid-body-control-method-25 () none)
(rigid-body-control-method-26 () none)
(rigid-body-control-method-27 () none)
(rigid-body-control-method-28 () none)
(rigid-body-control-method-29 () none)
(rigid-body-control-method-30 () none)
(rigid-body-control-method-31 () none)
(rigid-body-control-method-32 () none)
(rigid-body-control-method-33 () none)
)
)
(deftype rigid-body-object (process-focusable)
((info rigid-body-object-constants)
(flags rigid-body-object-flag)
(max-time-step float)
(incoming-attack-id uint32)
(player-touch-time time-frame)
(disturbed-time time-frame)
(player-force-position vector :inline)
(player-force vector :inline)
)
(:methods
(rigid-body-object-method-28 () none)
(rigid-body-object-method-29 () none)
(rigid-body-object-method-30 () none)
(rigid-body-object-method-31 () none)
(rigid-body-object-method-32 () none)
(rigid-body-object-method-33 () none)
(rigid-body-object-method-34 () none)
(rigid-body-object-method-35 () none)
(rigid-body-object-method-36 () none)
(rigid-body-object-method-37 () none)
(rigid-body-object-method-38 () none)
(rigid-body-object-method-39 () none)
(rigid-body-object-method-40 () none)
(rigid-body-object-method-41 () none)
(rigid-body-object-method-42 () none)
(rigid-body-object-method-43 () none)
(rigid-body-object-method-44 () none)
(rigid-body-object-method-45 () none)
(rigid-body-object-method-46 () none)
(rigid-body-object-method-47 () none)
(rigid-body-object-method-48 () none)
(rigid-body-object-method-49 () none)
(rigid-body-object-method-50 () none)
(rigid-body-object-method-51 () none)
(rigid-body-object-method-52 () none)
(rigid-body-object-method-53 () none)
(rigid-body-object-method-54 () none)
(rigid-body-object-method-55 () none)
)
)
(deftype rigid-body-queue (structure)
((count int8)
(manager uint64)
(array handle 128)
)
(:methods
(rigid-body-queue-method-9 () none)
(rigid-body-queue-method-10 () none)
(rigid-body-queue-method-11 () none)
(rigid-body-queue-method-12 () none)
(rigid-body-queue-method-13 () none)
(rigid-body-queue-method-14 () none)
(rigid-body-queue-method-15 () none)
(rigid-body-queue-method-16 () none)
)
)
+189
View File
@@ -7,3 +7,192 @@
;; DECOMP BEGINS
(deftype rpc-buffer (basic)
"Buffer for storing input/output data for a remote procedure call to the overlord driver on the IOP."
((elt-size uint32)
(elt-count uint32)
(elt-used uint32)
(busy symbol)
(base pointer)
(data uint8 :dynamic :offset 32)
)
(:methods
(new (symbol type uint uint) _type_)
)
)
(defmethod new rpc-buffer ((allocation symbol) (type-to-make type) (elt-size uint) (elt-count uint))
(let* ((a2-2 (+ (-> type-to-make size) 63 (* (the-as int elt-size) (the-as int elt-count))))
(v0-0 (object-new allocation type-to-make (the-as int a2-2)))
)
(set! (-> v0-0 elt-size) elt-size)
(set! (-> v0-0 elt-count) elt-count)
(set! (-> v0-0 elt-used) (the-as uint 0))
(set! (-> v0-0 busy) #f)
(set! (-> v0-0 base) (logand -64 (&-> (-> v0-0 data) 63)))
v0-0
)
)
(deftype rpc-buffer-pair (basic)
"A double buffer of RPC buffers. This is used to let the game queue up data in one buffer while
the other is being read/written by overlord."
((buffer rpc-buffer 2)
(current rpc-buffer)
(last-recv-buffer pointer)
(rpc-port int32)
)
(:methods
(new (symbol type uint uint int) rpc-buffer-pair)
(call (rpc-buffer-pair uint pointer uint) int)
(add-element (rpc-buffer-pair) pointer)
(decrement-elt-used (rpc-buffer-pair) int)
(sync (rpc-buffer-pair symbol) int)
(check-busy (rpc-buffer-pair) symbol)
(pop-last-received (rpc-buffer-pair) pointer)
)
)
(defmethod new rpc-buffer-pair ((allocation symbol) (type-to-make type) (elt-size uint) (elt-count uint) (rpc-port int))
(let ((s3-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> s3-0 buffer 0) (new 'global 'rpc-buffer elt-size elt-count))
(set! (-> s3-0 buffer 1) (new 'global 'rpc-buffer elt-size elt-count))
(set! (-> s3-0 current) (-> s3-0 buffer 0))
(set! (-> s3-0 last-recv-buffer) (the-as pointer #f))
(set! (-> s3-0 rpc-port) rpc-port)
s3-0
)
)
(defmethod sync ((this rpc-buffer-pair) (print-stall-warning symbol))
"Wait for an in-progress rpc to finish."
(let ((s5-0 (if (= (-> this current) (-> this buffer 0))
(-> this buffer 1)
(-> this buffer 0)
)
)
)
(when (-> s5-0 busy)
(when (nonzero? (rpc-busy? (-> this rpc-port)))
(if print-stall-warning
(format 0 "STALL: waiting for IOP on RPC port #~D~%" (-> this rpc-port))
)
(while (nonzero? (rpc-busy? (-> this rpc-port)))
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
)
)
(set! (-> s5-0 busy) #f)
(set! (-> s5-0 elt-used) (the-as uint 0))
0
)
)
0
)
(defmethod check-busy ((this rpc-buffer-pair))
"Check to see if an rpc is in progress."
(let ((gp-0 (if (= (-> this current) (-> this buffer 0))
(-> this buffer 1)
(-> this buffer 0)
)
)
)
(when (-> gp-0 busy)
(if (nonzero? (rpc-busy? (-> this rpc-port)))
(return #t)
)
(set! (-> gp-0 busy) #f)
(set! (-> gp-0 elt-used) (the-as uint 0))
0
)
)
#f
)
(defmethod call ((this rpc-buffer-pair) (fno uint) (recv-buffer pointer) (recv-buffer-size uint))
"Start an async RPC call. If there is already one in progress, stall and wait for it to finish."
(when (nonzero? (-> this current elt-used))
(let ((s2-0 (if (= (-> this current) (-> this buffer 0))
(-> this buffer 1)
(-> this buffer 0)
)
)
)
(when (-> s2-0 busy)
(when (nonzero? (rpc-busy? (-> this rpc-port)))
(format 0 "STALL: waiting for IOP on RPC port #~D~%" (-> this rpc-port))
(while (nonzero? (rpc-busy? (-> this rpc-port)))
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
(nop!)
)
)
(set! (-> s2-0 busy) #f)
(set! (-> s2-0 elt-used) (the-as uint 0))
0
)
(let ((s1-0 (-> this current)))
(rpc-call
(-> this rpc-port)
fno
(the-as uint 1)
(the-as uint (-> s1-0 base))
(the-as int (* (-> s1-0 elt-size) (-> s1-0 elt-used)))
(the-as uint recv-buffer)
(the-as int recv-buffer-size)
)
(set! (-> s1-0 busy) #t)
)
(set! (-> this last-recv-buffer) recv-buffer)
(set! (-> this current) s2-0)
)
)
0
)
(defmethod pop-last-received ((this rpc-buffer-pair))
"Pop the response from the most recently completed rpc call."
(let ((v0-0 (-> this last-recv-buffer)))
(set! (-> this last-recv-buffer) (the-as pointer #f))
v0-0
)
)
(defmethod add-element ((this rpc-buffer-pair))
"Add an element. If the buffer is full, flush it!"
(let ((v1-0 (-> this current)))
(when (= (-> v1-0 elt-used) (-> v1-0 elt-count))
(if (zero? (-> this rpc-port))
(format 0 "WARNING: too many sound commands queued~%")
)
(call this (the-as uint 0) (the-as pointer 0) (the-as uint 0))
(set! v1-0 (-> this current))
)
(let ((v0-2 (&+ (-> v1-0 base) (* (-> v1-0 elt-used) (-> v1-0 elt-size)))))
(+! (-> v1-0 elt-used) 1)
v0-2
)
)
)
(defmethod decrement-elt-used ((this rpc-buffer-pair))
"Remove the most recently queued element."
(if (> (-> this current elt-used) 0)
(+! (-> this current elt-used) -1)
)
0
)
+4
View File
@@ -24,6 +24,8 @@
:bitfield #t
)
(define-extern get-sound-buffer-entry (function pointer))
;; DECOMP BEGINS
(deftype sound-stream-name (structure)
@@ -47,6 +49,8 @@
()
)
(define-extern string->sound-name (function string sound-name))
(deftype sound-rpc-cmd (structure)
((rsvd1 uint16)
(command uint16)
@@ -7,3 +7,6 @@
;; DECOMP BEGINS
(define *actor-list* (the-as (pointer collide-shape) (malloc 'global 1024)))
(define *actor-list-length* 0)
@@ -5,5 +5,120 @@
;; name in dgo: spatial-hash-h
;; dgos: GAME
(declare-type grid-hash-work structure)
;; DECOMP BEGINS
(deftype grid-hash-word (uint8)
()
)
(deftype grid-hash-box (structure)
"Integer coordinate box for the spatial hash grid."
((min int8 3)
(max int8 3)
)
:pack-me
)
(deftype grid-hash (basic)
"The grid-hash is the basic 3D grid used in the spatial-hash, which is used for runtime
actor collision dectection by hashing actor spheres into grid cells, and avoiding the typical
O(n^2) 'check everybody against everybody' collision loop."
((work grid-hash-work)
(search-box grid-hash-box :inline)
(bucket-size int16)
(axis-scale float 3)
(dimension-array int8 3)
(vertical-cell-count int8)
(bucket-array (pointer grid-hash-word))
(box-min float 3)
(box-max float 3)
(object-count int16)
(bucket-count int16)
(min-cell-size float)
(bucket-memory-size int32)
(mem-bucket-array (pointer grid-hash-word))
(spr-bucket-array (pointer grid-hash-word))
(debug-draw symbol)
(use-scratch-ram symbol)
)
(:methods
(new (symbol type int) _type_)
(update-grid-for-objects-in-box (_type_ int vector vector) none)
(clear-bucket-array (_type_) none)
(setup-search-box (_type_ int vector vector vector) none)
(search-for-point (_type_ vector) (pointer uint8))
(search-for-sphere (_type_ vector float) (pointer uint8))
(draw (_type_ rgba) none)
(dump-grid-info (_type_) none)
(verify-bits-in-bucket (_type_ grid-hash-box grid-hash-box) none)
(box-of-everything (_type_ object grid-hash-box) none)
(grid-hash-method-18 (_type_ grid-hash-box int) none)
(grid-hash-method-19 (_type_ grid-hash-box int) none)
(do-search! (_type_ grid-hash-box (pointer uint8)) none)
(set-up-box (_type_ grid-hash-box vector vector) none)
(sphere-to-grid-box (_type_ grid-hash-box sphere) none)
(line-sphere-to-grid-box (_type_ grid-hash-box vector vector float) none)
(update-grid (_type_) none)
)
)
(deftype find-nav-sphere-ids-params (structure)
((bsphere sphere :inline)
(y-threshold float)
(len int16)
(max-len int16)
(mask uint8)
(array (pointer uint8))
)
)
(deftype sphere-hash (grid-hash)
"An extension of grid hash that holds spheres inside of the grid."
((sphere-array (inline-array sphere))
(max-object-count int16)
(pad int16)
(mem-sphere-array uint32)
(spr-sphere-array uint32)
)
(:methods
(new (symbol type int int) _type_)
(clear-objects! (_type_) none)
(add-a-sphere (_type_ vector) int)
(add-a-sphere-with-flag (_type_ vector int) int)
(update-from-spheres (_type_) none)
(sphere-hash-method-29 (_type_ find-nav-sphere-ids-params int int int) none)
(find-nav-sphere-ids (_type_ find-nav-sphere-ids-params) none)
(add-sphere-with-mask-and-id (_type_ vector int int) symbol)
(sphere-hash-method-32 (_type_ vector vector float int) symbol)
)
)
(deftype hash-object-info (structure)
((object basic)
)
)
(deftype spatial-hash (sphere-hash)
"An extension of sphere-hash that associates an object with each sphere."
((object-array (inline-array hash-object-info))
(mem-object-array (inline-array hash-object-info))
(spr-object-array (inline-array hash-object-info))
)
(:methods
(new (symbol type int int) _type_)
(spatial-hash-method-33 () none)
(add-an-object (_type_ vector hash-object-info) int)
(fill-actor-list-for-box (_type_ bounding-box (pointer collide-shape) int) int)
(fill-actor-list-for-sphere (_type_ sphere (pointer collide-shape) int) int)
(fill-actor-list-for-line-sphere (_type_ vector vector float (pointer collide-shape) int int) int)
(fill-actor-list-for-vec+r (_type_ vector (pointer collide-shape) int) int)
(spatial-hash-method-39 (_type_ object hash-object-info) int)
)
)