Skip to content

Commit

Permalink
[jak2] scalable debug font + fix debug menu widescreen bugs (#3044)
Browse files Browse the repository at this point in the history
also hides empty (no commands) regions from the viewers by default now.
  • Loading branch information
ManDude authored Sep 30, 2023
1 parent 0e31a9c commit e130244
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 30 deletions.
40 changes: 30 additions & 10 deletions game/mips2c/jak2_functions/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,16 @@ u64 execute(void* ctxt) {

block_60:
c->vsub(DEST::xyzw, vf23, vf23, vf24); // vsub.xyzw vf23, vf23, vf24
c->load_symbol2(v1, cache.video_params); // lw v1, *video-params*(s7)
c->mov64(v1, v1); // or v1, v1, r0
c->lqc2(vf1, 16, v1); // lqc2 vf1, 16(v1)
c->vmul(DEST::x, vf23, vf23, vf1); // vmul.x vf23, vf23, vf1
// pc-hack
c->lw(v1, 64, a1); // lw v1, 64(a1)
if (!(c->gprs[v1].du32[0] & (1 << 6))) {
// pc-hack flag
c->load_symbol2(v1, cache.video_params); // lw v1, *video-params*(s7)
c->mov64(v1, v1); // or v1, v1, r0
c->lqc2(vf1, 16, v1); // lqc2 vf1, 16(v1)
c->vmul(DEST::x, vf23, vf23, vf1); // vmul.x vf23, vf23, vf1
}
// pc-hack end
c->lqc2(vf1, 44, a1); // lqc2 vf1, 44(a1)
c->vmul_bc(DEST::x, BC::w, vf23, vf23, vf1); // vmulw.x vf23, vf23, vf1
c->mov128_gpr_vf(v0, vf23); // qmfc2.i v0, vf23
Expand All @@ -427,7 +433,8 @@ void link() {
cache.font12_table = intern_from_c("*font12-table*").c();
cache.font24_table = intern_from_c("*font24-table*").c();
cache.video_params = intern_from_c("*video-params*").c();
gLinkedFunctionTable.reg("get-string-length", execute, 512);
// gLinkedFunctionTable.reg("get-string-length", execute, 512);
gLinkedFunctionTable.reg("get-string-length-asm", execute, 512);
}

} // namespace get_string_length
Expand Down Expand Up @@ -457,10 +464,6 @@ u64 execute(void* ctxt) {
c->lqc2(vf26, 812, v1); // lqc2 vf26, 812(v1)
c->lqc2(vf27, 812, v1); // lqc2 vf27, 812(v1)
// shadow hack begin
c->load_symbol2(v1, cache.video_params);
c->lw(t0, 16, v1);
c->vfs[vf26].f[0] += c->gprs[t0].f[0] * 2;
c->vfs[vf26].f[1] += 1;
// c->vadd_bc(DEST::xy, BC::w, vf26, vf26, vf0); // vaddw.xy vf26, vf26, vf0
// c->vadd_bc(DEST::x, BC::w, vf26, vf26, vf0); // vaddw.x vf26, vf26, vf0
// shadow hack end
Expand All @@ -474,12 +477,29 @@ u64 execute(void* ctxt) {
c->lqc2(vf31, 48, v1); // lqc2 vf31, 48(v1)
c->load_symbol2(v1, cache.video_params); // lw v1, *video-params*(s7)
c->mov64(v1, v1); // or v1, v1, r0
// shadow hack begin
c->lw(t0, 16, v1); // lw t0, 16(v1)
// mmultiply shadow offset by font scale and screen x scale
c->vfs[vf26].f[0] += c->gprs[t0].f[0] * 2;
c->vfs[vf26].f[1] += 1;
// shadow hack end
c->lqc2(vf1, 32, v1); // lqc2 vf1, 32(v1)
c->vdiv(vf0, BC::w, vf25, BC::w); // vdiv Q, vf0.w, vf25.w
c->lqc2(vf2, 16, v1); // lqc2 vf2, 16(v1)
c->vmul(DEST::x, vf25, vf25, vf1); // vmul.x vf25, vf25, vf1
c->vmul(DEST::x, vf23, vf23, vf1); // vmul.x vf23, vf23, vf1
c->vmul(DEST::x, vf24, vf24, vf1); // vmul.x vf24, vf24, vf1
// pc-hack
c->lw(v1, 64, a2); // lw v1, 64(a2)
if (!(c->gprs[v1].du32[0] & (1 << 6))) {
// pc-hack flag
c->vmul(DEST::x, vf24, vf24, vf1); // vmul.x vf24, vf24, vf1
}
if (!(c->gprs[v1].du32[0] & (1 << 5))) {
// small font, readjust shadow
c->vfs[vf26].f[0] -= (c->gprs[t0].f[0] * 2) - (c->vfs[vf25].f[3] * c->gprs[t0].f[0] * 2);
c->vfs[vf26].f[1] -= 1 - (c->vfs[vf25].f[3] * 1);
}
// pc-hack end
c->vwaitq(); // vwaitq
c->vmulq(DEST::xy, vf25, vf25); // vmulq.xy vf25, vf25, Q
c->vmulq(DEST::xy, vf23, vf23); // vmulq.xy vf23, vf23, Q
Expand Down
7 changes: 4 additions & 3 deletions goal_src/jak1/pc/debug/default-menu-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,10 @@
(debug-menu-append-item menu (new-dm-bool "Wireframe" *collision-wireframe* dm-boolean-toggle-pick-func))
(debug-menu-append-item menu (new-dm-submenu "Mode"
(let ((mode-menu (new 'debug 'debug-menu ctx "Collision renderer mode menu")))
(doenum (name val pc-collision-mode)
(debug-menu-append-item mode-menu (new-dm-flag name val dm-collision-mode-pick-func))
)
(debug-menu-append-item mode-menu (new-dm-flag "none" (pc-collision-mode none) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "mode" (pc-collision-mode mode) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "event" (pc-collision-mode event) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "material" (pc-collision-mode material) dm-collision-mode-pick-func))
mode-menu)))
(debug-menu-append-item menu (new-dm-submenu "Filter mode"
(let ((filter-menu (new 'debug 'debug-menu ctx "Collision renderer filter mode menu")))
Expand Down
16 changes: 15 additions & 1 deletion goal_src/jak1/pc/pckernel-common.gc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
(update-video-hacks obj)
)
(cond
((not (-> *pc-settings* ps2-actor-vis?))
((not (-> obj ps2-actor-vis?))
;; kinda overkill.
(set! (-> *ACTOR-bank* birth-dist) (meters 10000))
(set! (-> *ACTOR-bank* pause-dist) (meters 10000))
Expand Down Expand Up @@ -392,6 +392,14 @@
(none))


(defmethod debug-font-scale-factor pc-settings ((this pc-settings))
"return the debug font scale factor to be used."
(declare (inline))
(if (-> this debug-font-scale-auto?)
(/ (-> this debug-font-scale) (max 1.0 (/ (the float (get-current-game-height this)) PC_BASE_HEIGHT)))
(-> this debug-font-scale)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; file IO
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -693,6 +701,10 @@
(("controller-led-brightness") (set! (-> obj controller-led-brightness) (file-stream-read-float file)))
(("controller-led-min-brightness") (set! (-> obj controller-led-min-brightness) (file-stream-read-float file)))
(("controller-led-max-brightness") (set! (-> obj controller-led-max-brightness) (file-stream-read-float file)))

;; debug
(("debug-font-scale") (set! (-> obj debug-font-scale) (file-stream-read-float file)))
(("debug-font-scale-auto?") (set! (-> obj debug-font-scale-auto?) (file-stream-read-symbol file)))
(("panic")
(when (file-stream-read-symbol file)
(reset obj #t)
Expand All @@ -718,6 +730,8 @@
(format file " (letterbox ~A)~%" (-> obj letterbox?))
(format file " (vsync ~A)~%" (-> obj vsync?))
;(format file " (font-scale ~f)~%" (-> obj font-scale))
(format file " (debug-font-scale ~f)~%" (-> obj debug-font-scale))
(format file " (debug-font-scale-auto? ~A)~%" (-> obj debug-font-scale-auto?))

;(format file " (audio-latency-ms ~D)~%" (-> obj audio-latency-ms))
;(format file " (audio-pan-override ~f)~%" (-> obj audio-pan-override))
Expand Down
16 changes: 16 additions & 0 deletions goal_src/jak1/pc/pckernel-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
(os symbol) ;; windows, linux, macos
(user symbol) ;; username. not system username, just debug thing.
(debug? symbol) ;; more debug stuff just in case.
(debug-font-scale float) ;; debug font scaling factor.
(debug-font-scale-auto? symbol) ;; auto-scale debug font by screen height.

;; device settings
(ignore-controller-win-unfocused? symbol)
Expand Down Expand Up @@ -257,6 +259,7 @@
(set-ignore-controller-in-bg! (_type_ symbol) none)
(set-enable-keyboard! (_type_ symbol) none)
(update-mouse-controls! (_type_) none)
(debug-font-scale-factor (_type_) float)
)
)

Expand Down Expand Up @@ -310,6 +313,8 @@
(set! (-> obj aspect-custom-y) 3)
(set! (-> obj discord-rpc?) #t)
(set! (-> obj speedrunner-mode?) #f)
(set! (-> obj debug-font-scale) 1.0)
(set! (-> obj debug-font-scale-auto?) #t)

(reset-gfx obj call-handlers)
(reset-audio obj call-handlers)
Expand Down Expand Up @@ -436,6 +441,17 @@
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; quick helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defmacro get-debug-font-scale-factor ()
"return the debug font scale factor to be used."
`(debug-font-scale-factor *pc-settings*))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; cheats
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
3 changes: 2 additions & 1 deletion goal_src/jak2/engine/debug/debug.gc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ Most functions take a boolean as their first argument. If the boolean is set to
(set! (-> *debug-text-3d-trk* allocated-length) 512)

(dotimes (gp-0 (-> *debug-text-3d-trk* allocated-length))
(set! (-> *debug-text-3ds* gp-0 str) (new 'debug 'string 80 (the-as string #f)))
;; og:preserve-this PC port note : allocated larger strings for 3D text
(set! (-> *debug-text-3ds* gp-0 str) (new 'debug 'string (#if PC_BIG_MEMORY 255 80) (the-as string #f)))
)

)
Expand Down
5 changes: 3 additions & 2 deletions goal_src/jak2/engine/debug/menu.gc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(set! (-> gp-0 joypad-func) #f)
(set! (-> gp-0 joypad-item) #f)
(set! (-> gp-0 font)
(new 'debug 'font-context *font-default-matrix* 0 0 0.0 (font-color default) (font-flags shadow kerning))
(new 'debug 'font-context *font-default-matrix* 0 0 0.0 (font-color default) (font-flags shadow kerning pc-hack))
)
(set! (-> gp-0 joypad-number) 0)
gp-0
Expand Down Expand Up @@ -937,7 +937,8 @@
(with-dma-buffer-add-bucket ((s0-0 (-> *display* frames (-> *display* on-screen) debug-buf))
(bucket-id debug3)
)
(draw-sprite2d-xy s0-0 arg1 arg2 (-> arg0 pix-width) (-> arg0 pix-height) (new 'static 'rgba :a #x40))
;; og:preserve-this fixed for widescreen
(draw-sprite2d-xy s0-0 (correct-x-int arg1) arg2 (correct-x-int (-> arg0 pix-width)) (-> arg0 pix-height) (static-rgba #x00 #x00 #x00 #x40))
)
(let* ((s3-1 (+ arg1 3))
(s2-1 (+ arg2 5))
Expand Down
28 changes: 26 additions & 2 deletions goal_src/jak2/engine/gfx/font.gc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
;; dgos: ENGINE, GAME

(def-mips2c draw-string-asm (function string dma-buffer font-context draw-string-result))
(def-mips2c get-string-length (function string font-context draw-string-result))
; (def-mips2c get-string-length (function string font-context draw-string-result))
(def-mips2c get-string-length-asm (function string font-context draw-string-result))

;; DECOMP BEGINS

Expand Down Expand Up @@ -146,7 +147,14 @@
;; ERROR: function was not converted to expressions. Cannot decompile.

(defun draw-string ((arg0 string) (arg1 dma-buffer) (arg2 font-context))
(local-vars (result draw-string-result))
;; og:preserve-this modified a bit for debug font scaling.
(let ((result (the draw-string-result #f))
(orig-scale (-> arg2 scale)))
(#when PC_PORT
;; debug font scaling.
(unless (logtest? (-> arg2 flags) (font-flags large pc-hack))
(*! (-> arg2 scale) (get-debug-font-scale-factor))))

(let ((v1-1 (the int (* 128.0 (-> arg2 alpha)))))
(-> arg2 origin quad)
(dotimes (a0-2 40)
Expand All @@ -166,9 +174,25 @@
)
)
(set! (-> *font-work* color-shadow w) 128)
(set! (-> arg2 scale) orig-scale)

result
))

(#when PC_PORT
;; og:preserve-this get-string-length is an asm function, but for PC port we use a trampoline in order to inject hacks more easily
(defun get-string-length ((text string) (ctx font-context))
"return the length of a string, in gs framebuffer units"
(let ((orig-scale (-> ctx scale))
(result (begin (#when PC_PORT ;; debug font scaling.
(unless (logtest? (-> ctx flags) (font-flags large pc-hack))
(*! (-> ctx scale) (get-debug-font-scale-factor))))
(get-string-length-asm text ctx))))
(set! (-> ctx scale) orig-scale)
result)
)

)
;; ERROR: function was not converted to expressions. Cannot decompile.

(defun draw-string-xy ((arg0 string) (arg1 dma-buffer) (arg2 int) (arg3 int) (arg4 font-color) (arg5 font-flags))
Expand Down
4 changes: 4 additions & 0 deletions goal_src/jak2/engine/gfx/hw/video-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@

(define-extern set-graphics-mode (function none))
(define-extern get-video-mode (function symbol))

(defmacro correct-x-int (pos)
`(the int (* (-> *video-params* relative-x-scale) (the float ,pos)))
)
16 changes: 16 additions & 0 deletions goal_src/jak2/engine/level/region.gc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
)

(defmethod debug-draw-region drawable-region-prim ((this drawable-region-prim) (arg0 int))
(#when PC_PORT
(when (and *debug-region-hide-empty* (not (or (-> this region on-enter) (-> this region on-exit) (-> this region on-inside))))
;; no scripts to run means the region is "empty" so do not render (unless enabled)
(return 0)))
(local-vars (sv-32 vector2h) (sv-36 vector))
(set! sv-32 (new 'stack 'vector2h))
(set! sv-36 (-> this bsphere))
Expand Down Expand Up @@ -242,6 +246,10 @@ otherwise, add the [[drawable-region-sphere]] to `region-start-prim-list` and in
)

(defmethod debug-draw-region drawable-region-sphere ((this drawable-region-sphere) (arg0 int))
(#when PC_PORT
(when (and *debug-region-hide-empty* (not (or (-> this region on-enter) (-> this region on-exit) (-> this region on-inside))))
;; no scripts to run means the region is "empty" so do not render (unless enabled)
(return 0)))
(let ((t9-0 (method-of-type drawable-region-prim debug-draw-region)))
(t9-0 this arg0)
)
Expand Down Expand Up @@ -285,6 +293,10 @@ otherwise, add the [[drawable-region-sphere]] to `region-start-prim-list` and in
)

(defmethod debug-draw-region drawable-region-face ((this drawable-region-face) (arg0 int))
(#when PC_PORT
(when (and *debug-region-hide-empty* (not (or (-> this region on-enter) (-> this region on-exit) (-> this region on-inside))))
;; no scripts to run means the region is "empty" so do not render (unless enabled)
(return 0)))
(when (zero? arg0)
(let ((t9-0 (method-of-type drawable-region-prim debug-draw-region)))
(t9-0 this arg0)
Expand Down Expand Up @@ -408,6 +420,10 @@ otherwise, add the [[drawable-region-sphere]] to `region-start-prim-list` and in
)

(defmethod debug-draw-region drawable-region-volume ((this drawable-region-volume) (arg0 int))
(#when PC_PORT
(when (and *debug-region-hide-empty* (not (or (-> this region on-enter) (-> this region on-exit) (-> this region on-inside))))
;; no scripts to run means the region is "empty" so do not render (unless enabled)
(return 0)))
(let ((t9-0 (method-of-type drawable-region-prim debug-draw-region)))
(t9-0 this arg0)
)
Expand Down
32 changes: 24 additions & 8 deletions goal_src/jak2/pc/debug/default-menu-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@

(defmacro dm-lambda-float-var (val)
"helper macro for making float buttons"
`(lambda (arg (msg debug-menu-msg) (newval float))
`,(lambda (arg (msg debug-menu-msg) (newval float))
(cond
((= msg (debug-menu-msg press))
(set! ,val newval)
Expand Down Expand Up @@ -357,11 +357,11 @@
(cond
((-> arg value)
(false! (-> arg value))
(logior! (-> *display* vu1-enable-user-menu) (vu1-renderer-mask shrubbery tfrag tfrag-trans tie tie-envmap))
(logior! (-> *display* vu1-enable-user-menu) (vu1-renderer-mask shrubbery tfrag tfrag-trans tfrag-water tie tie-envmap))
)
(else
(true! (-> arg value))
(logclear! (-> *display* vu1-enable-user-menu) (vu1-renderer-mask shrubbery tfrag tfrag-trans tie tie-envmap))
(logclear! (-> *display* vu1-enable-user-menu) (vu1-renderer-mask shrubbery tfrag tfrag-trans tfrag-water tie tie-envmap))
)
)
)
Expand Down Expand Up @@ -417,9 +417,10 @@
(debug-menu-append-item menu (new-dm-bool "Wireframe" *collision-wireframe* dm-boolean-toggle-pick-func))
(debug-menu-append-item menu (new-dm-submenu "Mode"
(let ((mode-menu (new 'debug 'debug-menu ctx "OpenGOAL collision renderer mode menu")))
(doenum (name val pc-collision-mode)
(debug-menu-append-item mode-menu (new-dm-flag name val dm-collision-mode-pick-func))
)
(debug-menu-append-item mode-menu (new-dm-flag "none" (pc-collision-mode none) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "mode" (pc-collision-mode mode) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "event" (pc-collision-mode event) dm-collision-mode-pick-func))
(debug-menu-append-item mode-menu (new-dm-flag "material" (pc-collision-mode material) dm-collision-mode-pick-func))
mode-menu)))
(debug-menu-append-item menu (new-dm-submenu "Filter mode"
(let ((filter-menu (new 'debug 'debug-menu ctx "OpenGOAL collision renderer filter mode menu")))
Expand Down Expand Up @@ -547,13 +548,25 @@
)
0)

(defun dm-anim-tester-x-speed-var-func (arg (msg debug-menu-msg) (newval float))
(if (= msg (debug-menu-msg press))
(set! (-> *ATX-settings* speed) newval)
(-> *ATX-settings* speed))
)

(defun dm-anim-tester-x-frame-num-var-func (arg (msg debug-menu-msg) (newval float))
(if (= msg (debug-menu-msg press))
(set! (-> *ATX-settings* frame-num) newval)
(-> *ATX-settings* frame-num))
)

(defun debug-menu-make-anim-tester-x-menu ((ctx debug-menu-context))
(let ((menu (new 'debug 'debug-menu ctx "Anim Tester X menu")))
;; master toggle
(debug-menu-append-item menu (new-dm-func "Start" #f atx-start))
(debug-menu-append-item menu (new-dm-func "Stop" #f atx-stop))
(debug-menu-append-item menu (new-dm-var-float "Speed" (the int #f) (dm-lambda-float-var (-> *ATX-settings* speed)) 0.01 -10.0 10.0))
(debug-menu-append-item menu (new-dm-var-float "Frame Num" (the int #f) (dm-lambda-float-var (-> *ATX-settings* frame-num)) 0.1 0.0 99999.0))
(debug-menu-append-item menu (new-dm-var-float "Speed" (the int #f) dm-anim-tester-x-speed-var-func 0.01 -10.0 10.0))
(debug-menu-append-item menu (new-dm-var-float "Frame Num" (the int #f) dm-anim-tester-x-frame-num-var-func 0.1 0.0 99999.0))
(debug-menu-append-item menu (new-dm-func "Refresh" #f dm-anim-tester-x-refresh))
(debug-menu-append-item menu (new-dm-func "Pick Art Group" 'pick-art-group dm-anim-tester-x-func))
(debug-menu-append-item menu (new-dm-func "Pick Anim" 'at-pick-joint-anim dm-anim-tester-x-func))
Expand Down Expand Up @@ -714,6 +727,7 @@
(debug-menu-append-item regions-menu (new-dm-bool "Display region inside" *display-region-inside* dm-boolean-toggle-pick-func))
(debug-menu-append-item regions-menu (new-dm-bool "Show non-sphere bsphere" *debug-region-show-bsphere* dm-boolean-toggle-pick-func))
(debug-menu-append-item regions-menu (new-dm-bool "Hide water regions" *debug-region-hide-water* dm-boolean-toggle-pick-func))
(debug-menu-append-item regions-menu (new-dm-bool "Hide empty regions" *debug-region-hide-empty* dm-boolean-toggle-pick-func))
(debug-menu-append-item regions-menu (new-dm-bool "Region Marks" *display-region-marks* dm-boolean-toggle-pick-func))
(debug-menu-append-item regions-menu (new-dm-bool "region-mode" #f
(lambda (arg (msg debug-menu-msg))
Expand Down Expand Up @@ -957,6 +971,8 @@
(flag "Joint names" *display-joint-names* dm-boolean-toggle-pick-func)
(flag "Bone lines" *display-bones* dm-boolean-toggle-pick-func)
(flag "Entity Lights" *display-lights* dm-boolean-toggle-pick-func)
(flag "Debug Font Auto-Scale" #f ,(dm-lambda-boolean-flag (-> *pc-settings* debug-font-scale-auto?)))
(float-var "Debug Font Scale" #f ,(dm-lambda-float-var (-> *pc-settings* debug-font-scale)) 2 (new 'static 'bfloat :data 0.01) #t (new 'static 'bfloat :data 0.1) 2 0)
)
)
)
Expand Down
Loading

0 comments on commit e130244

Please sign in to comment.