Skip to content

Commit

Permalink
jak1: add merc version of draw-bones-hud (#3793)
Browse files Browse the repository at this point in the history
Add a version of `draw-bones-hud` that uses merc to support drawing
foreground HUD elements that use custom models.
  • Loading branch information
Hat-Kid authored Dec 6, 2024
1 parent e18dbb6 commit 8690104
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
18 changes: 18 additions & 0 deletions goal_src/jak1/engine/draw/drawable.gc
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,24 @@
0
(none))

;; og:preserve-this added
(defun dma-add-process-drawable-hud-merc ((pd process-drawable) (dc draw-control) (arg2 symbol) (buf dma-buffer))
(logclear! (-> dc status) (draw-status was-drawn))
(when (not (logtest? (-> dc status) (draw-status hidden no-anim no-skeleton-update)))
(let ((vu-lights (scratchpad-object vu-lights :offset 64))
(hud-lights *hud-lights*))
(vector-copy! (-> vu-lights direction 0) (-> hud-lights direction 0))
(vector-copy! (-> vu-lights direction 1) (-> hud-lights direction 1))
(vector-copy! (-> vu-lights direction 2) (-> hud-lights direction 2))
(vector-copy! (-> vu-lights color 0) (-> hud-lights color 0))
(vector-copy! (-> vu-lights color 1) (-> hud-lights color 1))
(vector-copy! (-> vu-lights color 2) (-> hud-lights color 2))
(vector-copy! (-> vu-lights ambient) (-> hud-lights ambient)))
(lod-set! dc 0)
(logior! (-> dc status) (draw-status was-drawn))
(draw-bones-hud-merc dc buf))
(none))

(defun add-process-drawable ((arg0 process-drawable) (arg1 draw-control) (arg2 symbol) (arg3 dma-buffer))
((-> arg1 dma-add-func) arg0 arg1 arg2 arg3)
(none))
Expand Down
101 changes: 101 additions & 0 deletions goal_src/jak1/engine/gfx/foreground/bones.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,3 +1506,104 @@
(none))

(define-extern draw-bones-hud (function draw-control dma-buffer none))

;; og:preserve-this added
(defun draw-bones-hud-merc ((draw draw-control) (dma-buf dma-buffer))
(local-vars (at-2 int) (t2-10 vu-lights) (t3-3 uint128) (t3-4 uint128) (t3-5 uint128) (t3-6 uint128))
(let ((buf dma-buf))
(let* ((dma-start (-> buf base))
(joints (+ (-> draw mgeo num-joints) 3))
(bone-calc (the bone-calculation (&+ dma-start 16)))
(bone-calc-size (* joints 128))
(mat-data (the object (&+ dma-start 64)))
(spr-work (scratchpad-object terrain-context)))
;; align the matrix data to 64 bytes (we know it is at least 16 byte aligned)
(let ((mat-aligned (logand (the int mat-data) 48)))
(when (nonzero? mat-aligned)
(set! mat-data (&- (&+ (the pointer mat-data) 64) (the uint mat-aligned)))))
(let ((regs (scratchpad-object bone-regs :offset 240)))
(set! (-> regs joint-ptr) (the (inline-array joint) (-> draw jgeo data 0)))
(set! (-> regs bone-ptr) (-> draw skeleton bones))
(set! (-> regs num-bones) joints))
(let ((t2-0 mat-data)
(bone-mem (scratchpad-object bone-memory :offset 16))
(bone-list *bone-calculation-list*)
(t1-6 bone-calc))
(let ((t4-0 (-> bone-mem work regs joint-ptr))
(t5-0 (-> bone-mem work regs bone-ptr))
(t6-1 (-> bone-mem work regs num-bones))
(t7-0 t1-6))
(set! (-> t7-0 flags) (bone-calc-flags bncfl01))
(set! (-> t7-0 num-bones) t6-1)
(set! (-> t7-0 matrix-area) (the (inline-array matrix) t2-0))
(set! (-> t7-0 joints) t4-0)
(set! (-> t7-0 bones) t5-0)
(set! (-> t7-0 next) (the bone-calculation 0)))
(if (nonzero? (-> bone-list next)) (set! (-> bone-list next next) t1-6))
(if (zero? (-> bone-list first)) (set! (-> bone-list first) t1-6))
(set! (-> bone-list next) t1-6))
(&+ (the pointer bone-calc) 48)
(let ((a2-2 (the object (+ (the uint mat-data) bone-calc-size))))
(set! (-> (the (pointer uint128) dma-start))
(logior (-> spr-work work foreground bone-mem work next-tag quad) (shl (the-as int a2-2) 32)))
(when (= (-> draw data-format) 1)
(let ((mgeo (-> draw lod-set lod 0 geo)))
(dotimes (effect-idx (the-as int (-> mgeo header effect-count)))
(cond
((nonzero? (-> mgeo effect effect-idx envmap-usage))
(let* ((t1-7 (-> *merc-bucket-info* light))
(lights (scratchpad-object vu-lights :offset 64))
(t0-10 7)
(t1-8 (the-as object t1-7)))
(b! (< (+ t0-10 -4) 0) cfg-9 :delay (set! t2-10 lights))
(nop!)
(label cfg-8)
(let ((t6-2 (-> t2-10 direction 0 quad)))
(nop!)
(let ((t3-2 (-> t2-10 direction 1 quad)))
(+! t0-10 -4)
(let ((t4-1 (-> t2-10 direction 2 quad)))
(set! t1-8 (&+ (the pointer t1-8) 64))
(let ((t5-1 (-> t2-10 color 0 quad)))
(set! t2-10 (the vu-lights (-> t2-10 color 1)))
(store-qw (&+ (the pointer t1-8) -64) t6-2)
(let ((t6-3 (+ t0-10 -4)))
(store-qw (&+ (the pointer t1-8) -48) t3-2)
(nop!)
(store-qw (&+ (the-as pointer t1-8) -32) t4-1)
(b! (>= t6-3 0) cfg-8 :delay (store-qw (&+ (the-as pointer t1-8) -16) t5-1)))))))
(label cfg-9)
(b! (zero? t0-10) cfg-14 :delay (set! t3-3 (-> t2-10 direction 0 quad)))
(let ((t2-11 (-> t2-10 direction 1))
(t1-9 (-> (the vu-lights t1-8) direction 1))
(t0-11 (+ t0-10 -1)))
(store-qw (&+ t1-9 -16) t3-3)
(b! (zero? t0-11) cfg-14 :delay (set! t3-4 (-> t2-11 quad)))
(let ((t2-12 (&+ t2-11 16))
(t1-10 (&+ t1-9 16))
(t0-12 (+ t0-11 -1)))
(store-qw (&+ t1-10 -16) t3-4)
(b! (zero? t0-12) cfg-14 :delay (set! t3-5 (-> t2-12 quad)))
(let ((t2-13 (&+ t2-12 16))
(t1-11 (&+ t1-10 16))
(t0-13 (+ t0-12 -1)))
(store-qw (&+ t1-11 -16) t3-5)
(b! (zero? t0-13) cfg-14 :delay (set! t3-6 (-> t2-13 quad)))
(&+ t2-13 16)
(let ((t1-12 (&+ t1-11 16))) (+ t0-13 -1) (store-qw (&+ t1-12 -16) t3-6))))))
(label cfg-14)
(set! (-> *merc-bucket-info* effect effect-idx color-fade) (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80))
(set! (-> *merc-bucket-info* effect effect-idx use-mercneric) (the-as uint 0))
(set! (-> *merc-bucket-info* effect effect-idx ignore-alpha) (the-as uint 1)))
(else (set! (-> *merc-bucket-info* effect effect-idx use-mercneric) (the-as uint 1))))))
(when (logtest? *vu1-enable-user* (vu1-renderer-mask merc))
(set! (-> buf base) (pc-merc-draw-request draw (the pointer a2-2) (the pointer mat-data) #f (the (pointer float) 0)))
(set! a2-2 (-> buf base))))
(let ((a0-17 (logand (the int a2-2) 48)))
(b! (zero? a0-17) cfg-22 :delay (set! at-2 #x20000000))
(set! (-> (the (pointer int128) a2-2)) (the int128 at-2))
(let ((v1-2 (the pointer a2-2)))
(set! a2-2 (+ (&- (the pointer a2-2) (the uint a0-17)) 64))
(store-u32 (&+ v1-2 4) (the int a2-2))))
(label cfg-22)
(set! (-> buf base) (the pointer a2-2))))))

0 comments on commit 8690104

Please sign in to comment.