Skip to content

Commit

Permalink
jak3 pc: math-camera, letterbox, led and auto-save (#3479)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManDude authored Apr 22, 2024
1 parent 9d359ed commit 728cb4b
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 78 deletions.
16 changes: 8 additions & 8 deletions goal_src/jak2/engine/entity/entity.gc
Original file line number Diff line number Diff line change
Expand Up @@ -2270,14 +2270,14 @@
(not (logtest? (-> sv-48 perm status) (entity-perm-status bit-9 bit-10)))
(not (logtest? (-> sv-48 kill-mask) sv-32))
(or (-> s4-1 vis-info 0) (< (vector-vector-distance (-> sv-48 trans) sv-16) (-> sv-48 vis-dist)))
;; og:preserve-this PC port note: added this extra check to fix level types being used after deloaded because of bad entity placement
(#if PC_PORT
(or (not (type-type? (-> sv-48 entity type) entity-actor)) (and (valid? (-> (the-as entity-actor (-> sv-48 entity)) etype) type "entity-type-check etype" #f *stdcon*)
(valid? (-> (the-as entity-actor (-> sv-48 entity)) etype symbol) symbol "entity-type-check symbol" #f *stdcon*)
(valid? (-> (the-as entity-actor (-> sv-48 entity)) etype symbol value) type "entity-type-check value" #f *stdcon*)
(= (-> (the-as entity-actor (-> sv-48 entity)) etype) (-> (the-as entity-actor (-> sv-48 entity)) etype symbol value))
))
#f)
;; og:preserve-this PC port note: added this extra check to fix level types being used after deloaded because of bad entity placement
(#if PC_PORT
(or (not (type-type? (-> sv-48 entity type) entity-actor)) (and (valid? (-> (the-as entity-actor (-> sv-48 entity)) etype) type "entity-type-check etype" #f *stdcon*)
(valid? (-> (the-as entity-actor (-> sv-48 entity)) etype symbol) symbol "entity-type-check symbol" #f *stdcon*)
(valid? (-> (the-as entity-actor (-> sv-48 entity)) etype symbol value) type "entity-type-check value" #f *stdcon*)
(= (-> (the-as entity-actor (-> sv-48 entity)) etype) (-> (the-as entity-actor (-> sv-48 entity)) etype symbol value))
))
#f)
)
(when (not (or (-> sv-48 process) (logtest? (-> sv-48 perm status) (entity-perm-status bit-0 dead)) s0-0))
(birth! (-> sv-48 entity))
Expand Down
10 changes: 5 additions & 5 deletions goal_src/jak2/engine/ui/minimap.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@
(set! sv-220 (new 'stack-no-clear 'matrix))
(set! sv-224 (new 'stack-no-clear 'matrix))
(set! sv-228 (new 'stack-no-clear 'matrix))
(set! (-> sv-216 quad) (-> (matrix-world->local #f #f) vector 2 quad))
(set! (-> sv-216 quad) (-> (#if PC_PORT (if (-> *pc-settings* minimap-force-north) *matrix-minimap-north* (matrix-world->local #f #f)) (matrix-world->local #f #f)) vector 2 quad))
(set! (-> sv-216 y) 0.0)
(vector-normalize! sv-216 1.0)
(vector-z-quaternion! (the-as vector sv-220) (-> (the-as process-drawable sv-16) root quat))
Expand Down Expand Up @@ -1635,7 +1635,7 @@
(set! sv-228 (new 'stack-no-clear 'matrix))
(set! sv-232 (new 'stack-no-clear 'matrix))
(when sv-212
(set! (-> sv-220 quad) (-> (matrix-world->local #f #f) vector 2 quad))
(set! (-> sv-220 quad) (-> (#if PC_PORT (if (-> *pc-settings* minimap-force-north) *matrix-minimap-north* (matrix-world->local #f #f)) (matrix-world->local #f #f)) vector 2 quad))
(set! (-> sv-220 y) 0.0)
(vector-normalize! sv-220 1.0)
(vector-z-quaternion! (the-as vector sv-224) (-> (the-as process-drawable sv-16) root quat))
Expand Down Expand Up @@ -1784,7 +1784,7 @@
(set! sv-228 (new 'stack-no-clear 'matrix))
(set! sv-232 (new 'stack-no-clear 'matrix))
(when sv-212
(set! (-> sv-220 quad) (-> (matrix-world->local #f #f) vector 2 quad))
(set! (-> sv-220 quad) (-> (#if PC_PORT (if (-> *pc-settings* minimap-force-north) *matrix-minimap-north* (matrix-world->local #f #f)) (matrix-world->local #f #f)) vector 2 quad))
(set! (-> sv-220 y) 0.0)
(vector-normalize! sv-220 1.0)
(vector-z-quaternion! (the-as vector sv-224) (-> (the-as process-drawable sv-16) root quat))
Expand Down Expand Up @@ -1914,7 +1914,7 @@
(set! (-> (the-as (pointer uint128) s3-1) 1) (-> this draw2-tmpl quad 1))
(let ((s2-0 (new-stack-vector0)))
(let ((s1-0 (new-stack-vector0)))
(set! (-> s1-0 quad) (-> (matrix-local->world #f #f) vector 2 quad))
(set! (-> s1-0 quad) (-> (#if PC_PORT (if (-> *pc-settings* minimap-force-north) *matrix-minimap-north* (matrix-local->world #f #f)) (matrix-local->world #f #f)) vector 2 quad))
(set! (-> s1-0 y) 0.0)
(vector-normalize! s1-0 1.0)
(let ((v1-16 (-> arg0 mat)))
Expand Down Expand Up @@ -2126,7 +2126,7 @@
(set! sv-52 v1-29)
)
(set! sv-56 (target-pos 0))
(set! (-> sv-52 quad 0) (-> (matrix-world->local #f #f) vector 2 quad))
(set! (-> sv-52 quad 0) (-> (#if PC_PORT (if (-> *pc-settings* minimap-force-north) *matrix-minimap-north* (matrix-world->local #f #f)) (matrix-world->local #f #f)) vector 2 quad))
(set! (-> sv-52 vector 0 y) 0.0)
(vector-normalize! (the-as vector sv-52) 1.0)
(cond
Expand Down
4 changes: 4 additions & 0 deletions goal_src/jak2/pc/debug/default-menu-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@
(flag "GAME_TERRITORY_SCEI" (the binteger GAME_TERRITORY_SCEI) dm-territory-pick-func)
(flag "GAME_TERRITORY_SCEK" (the binteger GAME_TERRITORY_SCEK) dm-territory-pick-func)
)
(menu "Minimap"
(flag "Non-PS2 coordinates" #f ,(dm-lambda-boolean-flag (-> *pc-settings* smooth-minimap?)))
(flag "Always face north" #f ,(dm-lambda-boolean-flag (-> *pc-settings* minimap-force-north)))
)
(flag "V-sync" #f ,(dm-lambda-boolean-flag (-> *pc-settings* vsync?)))
(flag "PS2 actor vis" #f ,(dm-lambda-boolean-flag (-> *pc-settings* ps2-actor-vis?)))
(flag "Display actor counts" *display-actor-counts* dm-boolean-toggle-pick-func)
Expand Down
3 changes: 3 additions & 0 deletions goal_src/jak2/pc/pckernel-impl.gc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
(fast-airlock? symbol)
(fast-elevator? symbol)
(fast-progress? symbol)
(minimap-force-north symbol)

(stats statistics)

Expand All @@ -112,6 +113,7 @@
)

(define *pc-settings* (the pc-settings-jak2 #f))
(define *matrix-minimap-north* (quaternion->matrix (new 'static 'matrix) (quaternion-vector-angle! (new 'static 'quaternion) *y-vector* (degrees 180))))


;; jak 2 discord rpc structure
Expand Down Expand Up @@ -143,6 +145,7 @@
(true! (-> obj fast-elevator?))
(false! (-> obj fast-progress?))
(true! (-> obj smooth-minimap?))
(false! (-> obj minimap-force-north))
(false! (-> obj hires-clouds?))
(set! (-> obj speedrunner-mode-custom-bind) 0)

Expand Down
2 changes: 2 additions & 0 deletions goal_src/jak2/pc/pckernel.gc
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@
(("fast-elevator?") (set! (-> obj fast-elevator?) (file-stream-read-symbol file)))
(("fast-progress?") (set! (-> obj fast-progress?) (file-stream-read-symbol file)))
(("smooth-minimap?") (set! (-> obj smooth-minimap?) (file-stream-read-symbol file)))
(("minimap-force-north") (set! (-> obj minimap-force-north) (file-stream-read-symbol file)))
(("hires-clouds?") (set! (-> obj hires-clouds?) (file-stream-read-symbol file)))
(("text-language") (set! (-> obj text-language) (the-as pc-language (file-stream-read-int file))))
(("controller-led-status?") (set! (-> obj controller-led-status?) (file-stream-read-symbol file)))
Expand Down Expand Up @@ -797,6 +798,7 @@
(format file " (fast-elevator? ~A)~%" (-> obj fast-elevator?))
(format file " (fast-progress? ~A)~%" (-> obj fast-progress?))
(format file " (smooth-minimap? ~A)~%" (-> obj smooth-minimap?))
(format file " (minimap-force-north ~A)~%" (-> obj minimap-force-north))
(format file " (hires-clouds? ~A)~%" (-> obj hires-clouds?))
(format file " (text-language ~D)~%" (-> obj text-language))
(format file " (controller-led-status? ~A)~%" (-> obj controller-led-status?))
Expand Down
41 changes: 33 additions & 8 deletions goal_src/jak3/engine/draw/drawable.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,10 @@
(cond
((>= (-> arg1 force-lod) 0)
(set! s4-1 (-> arg1 force-lod))
(if (< (-> arg1 lod-set lod (-> arg1 lod-set max-lod) dist) f30-0)
;; og:preserve-this force high lods
(if (#if (not PC_PORT)
(< (-> arg1 lod-set lod (-> arg1 lod-set max-lod) dist) f30-0)
(and (-> *pc-settings* ps2-lod-dist?) (< (-> arg1 lod-set lod (-> arg1 lod-set max-lod) dist) f30-0)))
(return #f)
)
)
Expand All @@ -1201,7 +1204,19 @@
)
)
)
(if (and (< (-> arg1 lod-set lod s4-1 dist) f30-0) (< (-> arg1 force-lod) 0))
;; og:preserve-this lod hacks!
(with-pc
(when (not (-> *pc-settings* ps2-lod-dist?))
(set! s4-1 (minmax (-> *pc-settings* lod-force-actor) 0 (-> arg1 lod-set max-lod)))
(when (> (-> arg1 force-lod) -1)
(set! s4-1 (-> arg1 force-lod))
)
)
)
(if (#if (not PC_PORT)
(and (< (-> arg1 lod-set lod s4-1 dist) f30-0) (< (-> arg1 force-lod) 0))
(and (-> *pc-settings* ps2-lod-dist?) (< (-> arg1 lod-set lod s4-1 dist) f30-0) (< (-> arg1 force-lod) 0))
)
(return #f)
)
(let ((v1-49 (-> *level* level (-> arg1 level-index)))
Expand Down Expand Up @@ -1246,8 +1261,16 @@
(return #f)
)
(set! (-> pp clock) (-> sv-16 clock))
(if (or (= s4-1 (-> arg1 cur-lod)) (logtest? (-> arg1 status) (draw-control-status lod-set)))
(foreground-draw arg1 arg3 f30-0)
;; og:preserve-this PC port note: we ALWAYS disable the envmap hack when a process-drawable has warp effect enabled
(when (or (= s4-1 (-> arg1 cur-lod)) (logtest? (-> arg1 status) (draw-control-status lod-set)))
(protect ((-> *pc-settings* force-envmap?))
(when (not (movie?))
(dotimes (eff-i (-> arg1 mgeo header effect-count))
(if (and (zero? (logand (ash 1 eff-i) (-> arg1 effect-mask)))
(logtest? (effect-bits cross-fade) (-> arg1 mgeo effect eff-i effect-bits)))
(false! (-> *pc-settings* force-envmap?)))))
(foreground-draw arg1 arg3 f30-0)
)
)
)
(when (and (< s4-1 (-> arg1 cur-lod)) (logtest? (-> arg1 status) (draw-control-status math-skel)))
Expand Down Expand Up @@ -2153,10 +2176,12 @@
(set! s3-0 (the uint (+ #x10000 s3-0)))
)

;; track previous frame's run time. This is used to disable some extra effects if the game
;; is close to lagging. We disable this.
; (set! (-> arg0 frames s4-0 run-time) s3-0)
(set! (-> arg0 frames s4-0 run-time) 0)
;; store the amount of ticks that the frame took.
;; og:preserve-this
;; PC PORT NOTE : the originaly game reads this field in places to check if frames are taking too long and avoid doing potentially laggy things.
;; those numbers are hardcoded for 60fps, they would be a pain to adjust, and the effects in the pc port are negligible.
;; so, we just pretend frames rendered in planck time.
(set! (-> arg0 frames s4-0 run-time) (#if PC_PORT 0 (the int s3-0)))

;; disable their vsync logic:
; (set! f30-1 (cond
Expand Down
2 changes: 2 additions & 0 deletions goal_src/jak3/engine/game/game-save.gc
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,8 @@
(else
(case *kernel-boot-message*
(('play 'preview)
(#when PC_PORT
(pc-settings-save))
(auto-save-command 'auto-save 0 0 *default-pool* #f)
)
)
Expand Down
49 changes: 37 additions & 12 deletions goal_src/jak3/engine/game/main.gc
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,43 @@

(defun letterbox ((arg0 bucket-id) (arg1 float))
"Draw letterbox"
(with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf))
arg0
)
(draw-sprite2d-xy-absolute s4-0 0 0 512 (the int (* 46.0 arg1)) (new 'static 'rgba :a #x80) #x3fffff)
(draw-sprite2d-xy-absolute
s4-0
0
(- 416 (the int (* 46.0 arg1)))
512
(+ (the int (* 46.0 arg1)) 1)
(new 'static 'rgba :a #x80)
#x3fffff
(with-dma-buffer-add-bucket ((dma-buf (-> (current-frame) global-buf))
arg0)
(#cond
((not PC_PORT)
(draw-sprite2d-xy-absolute dma-buf 0 0 512 (the int (* 46.0 arg1)) (new 'static 'rgba :a #x80) #x3fffff)
(draw-sprite2d-xy-absolute dma-buf 0 (- 416 (the int (* 46.0 arg1))) 512 (+ (the int (* 46.0 arg1)) 1) (new 'static 'rgba :a #x80) #x3fffff)
)
(#t
(if (-> *pc-settings* use-vis?)
;; original game mode. dont do anything.
(begin
(draw-sprite2d-xy-absolute dma-buf 0 0 512 (the int (* 46.0 arg1)) (new 'static 'rgba :a #x80) #x3fffff)
(draw-sprite2d-xy-absolute dma-buf 0 (- 416 (the int (* 46.0 arg1))) 512 (+ (the int (* 46.0 arg1)) 1) (new 'static 'rgba :a #x80) #x3fffff))
;; native mode. force 16x9 letterboxing always.
(begin
(cond
((< (-> *pc-settings* aspect-ratio) ASPECT_16X9)
;; too tall. needs vertical letterboxing.
(let ((lbx-h (the int (* 208.0 (- 1.0 (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9))))))
(set! lbx-h (the int (* arg1 lbx-h)))
;(format 0 "using new letterbox! size: ~D~%" lbx-h)
(draw-sprite2d-xy dma-buf 0 0 512 lbx-h (new 'static 'rgba :a #x80) #x3fffff)
(draw-sprite2d-xy dma-buf 0 (- 416 lbx-h) 512 lbx-h (new 'static 'rgba :a #x80) #x3fffff)
)
)
((> (-> *pc-settings* aspect-ratio) ASPECT_16X9)
;; too wide. needs horizontal letterboxing.
(let ((lbx-w (the int (* 256.0 (- 1.0 (/ ASPECT_16X9 (-> *pc-settings* aspect-ratio)))))))
;(format 0 "using new pillarbox! size: ~D~%" lbx-w)
(draw-sprite2d-xy dma-buf 0 0 lbx-w 416 (new 'static 'rgba :a #x80) #x3fffff)
(draw-sprite2d-xy dma-buf (- 512 lbx-w) 0 lbx-w 416 (new 'static 'rgba :a #x80) #x3fffff)
)
)
)
)
)
)
)
)
0
Expand Down
51 changes: 25 additions & 26 deletions goal_src/jak3/engine/gfx/math-camera.gc
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,32 @@ Without this corrector, the fogginess of the world would change as the FOV chang
(set! (-> arg0 y-ratio) (* 0.75 (-> arg0 x-ratio)))
(set! (-> arg0 y-ratio) (* 0.5625 (-> arg0 x-ratio)))
)
;; TODO pckernel
;; og:preserve-this
;; (with-pc
;; (cond
;; ((-> *pc-settings* use-vis?)
;; ;; using game vis, cannot allow seeing more of the view
;; ;; crops excess aspect ratio at the top and bottom
;; ;(set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
;; )
;; ((real-movie?)
;; ;; this mess is just so that we can force the original 16x9 cropping during cutscenes.
;; (if (<= (-> *pc-settings* aspect-ratio) ASPECT_16X9)
;; (set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
;; (begin
;; (set! (-> arg0 y-ratio) (* (1/ ASPECT_16X9) (-> arg0 x-ratio)))
;; (*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9))
;; )
;; )
;; )
;; (else
;; ;; not using game vis, allow *extended* aspect ratios
;; ;; there is no vertical cropping, and you can see more of the sides
;; (set! (-> arg0 y-ratio) (* (1/ ASPECT_4X3) (-> arg0 x-ratio))) ;; same cropping as 4x3
;; (*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_4X3)) ;; extend fov! shows more on the sides.
;; )
;; )
;; )
(with-pc
(cond
((-> *pc-settings* use-vis?)
;; using game vis, cannot allow seeing more of the view
;; crops excess aspect ratio at the top and bottom
;(set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
)
((real-movie?)
;; this mess is just so that we can force the original 16x9 cropping during cutscenes.
(if (<= (-> *pc-settings* aspect-ratio) ASPECT_16X9)
(set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
(begin
(set! (-> arg0 y-ratio) (* (1/ ASPECT_16X9) (-> arg0 x-ratio)))
(*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9))
)
)
)
(else
;; not using game vis, allow *extended* aspect ratios
;; there is no vertical cropping, and you can see more of the sides
(set! (-> arg0 y-ratio) (* (1/ ASPECT_4X3) (-> arg0 x-ratio))) ;; same cropping as 4x3
(*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_4X3)) ;; extend fov! shows more on the sides.
)
)
)
(let ((f1-3 (-> arg0 x-ratio))
(f0-7 (-> arg0 y-ratio))
(v1-6 (-> arg0 cull-info))
Expand Down
12 changes: 12 additions & 0 deletions goal_src/jak3/engine/ps2/pad.gc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
(define-extern get-real-current-time (function time-frame))
(define-extern get-current-language (function language-enum))


(#when PC_PORT

;; redefined from C kernel
(defun scf-get-territory ()
"redefined from C kernel for convenience"
(if (= (-> *pc-settings* territory) -1)
*default-territory*
(-> *pc-settings* territory))
)
)

;; DECOMP BEGINS

(deftype scf-time (structure)
Expand Down
Loading

0 comments on commit 728cb4b

Please sign in to comment.