g/j2: Speedrunner mode improvements for Jak 2 (#3182)

This commit is contained in:
Tyler Wilding 2023-11-10 18:25:55 -05:00 committed by GitHub
parent a150e59e38
commit 55611169ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 26 deletions

View file

@ -921,19 +921,25 @@
) )
) )
(process-entity-status! self (entity-perm-status no-kill) #t) (process-entity-status! self (entity-perm-status no-kill) #t)
(until (not (or (-> *setting-control* user-current talking) ;; og:preserve-this
(-> *setting-control* user-current spooling) ;; NOTE - for speedrunner mode, allows the game to continue
(-> *setting-control* user-current hint) ;; even if there is a dialogue in progress
(-> *setting-control* user-current ambient) (until (not (or (-> *setting-control* user-current spooling)
) (when (not (-> *pc-settings* speedrunner-mode?))
) (or (-> *setting-control* user-current talking)
(-> *setting-control* user-current hint)
(-> *setting-control* user-current ambient)))))
(set-setting! 'allow-progress #f 0.0 0) (set-setting! 'allow-progress #f 0.0 0)
(apply-settings *setting-control*) (apply-settings *setting-control*)
(dotimes (s4-0 2) (dotimes (s4-0 2)
(while (or (-> *setting-control* user-current talking) ;; og:preserve-this
(-> *setting-control* user-current spooling) ;; NOTE - for speedrunner mode, allows the game to continue
(-> *setting-control* user-current hint) ;; even if there is a dialogue in progress
(-> *setting-control* user-current ambient) (while (or (-> *setting-control* user-current spooling)
(when (not (-> *pc-settings* speedrunner-mode?))
(or (-> *setting-control* user-current talking)
(-> *setting-control* user-current hint)
(-> *setting-control* user-current ambient)))
(or (and (-> *setting-control* user-current movie) (or (and (-> *setting-control* user-current movie)
(!= (-> *setting-control* user-current movie) (process->ppointer self)) (!= (-> *setting-control* user-current movie) (process->ppointer self))
) )

View file

@ -538,11 +538,19 @@
(and (-> self continue) (and (-> self continue)
(not (focus-test? *target* in-head edge-grab pole flut tube board pilot mech indax)) (not (focus-test? *target* in-head edge-grab pole flut tube board pilot mech indax))
(-> *setting-control* user-current airlock) (-> *setting-control* user-current airlock)
(not (-> *setting-control* user-current hint)) ;; og:preserve-this
;; For speedrunner mode, always allow warp-gates to be used
;; even when dialogues are playing
(or (-> *pc-settings* speedrunner-mode?)
(not (-> *setting-control* user-current hint)))
) )
) )
(talker-surpress!) (talker-surpress!)
(when (and (can-display-query? self (the-as string #f) -99.0) ;; og:preserve-this
;; For speedrunner mode, always allow warp-gates to be used
;; even when dialogues are playing
(when (and (or (-> *pc-settings* speedrunner-mode?)
(can-display-query? self (the-as string #f) -99.0))
(cond (cond
((and (-> *target* next-state) (let ((v1-30 (-> *target* next-state name))) ((and (-> *target* next-state) (let ((v1-30 (-> *target* next-state name)))
(or (= v1-30 'target-warp-in) (= v1-30 'target-warp-out)) (or (= v1-30 'target-warp-in) (= v1-30 'target-warp-out))

View file

@ -11,6 +11,8 @@
;; there's no point in adding categories that just start from a new-game and have later restrictions ;; there's no point in adding categories that just start from a new-game and have later restrictions
;; because we aren't going to modify the code to make that possible ;; because we aren't going to modify the code to make that possible
;; ie. removing mars tomb skip if you pick "all missions" ;; ie. removing mars tomb skip if you pick "all missions"
;; Random one for experimentation
(all-cheats-allowed 999)
) )
(deftype speedrun-info (structure) (deftype speedrun-info (structure)

View file

@ -13,14 +13,15 @@
;; turn on speedrun verification display ;; turn on speedrun verification display
(set! (-> this display-run-info?) #t) (set! (-> this display-run-info?) #t)
;; ensure any required settings are enabled ;; ensure any required settings are enabled
(set! (-> *setting-control* user-default dialog-volume) 0.0) ;; disable dialog volume
(enforce-settings! this) (enforce-settings! this)
;; finalize any category specific setup code ;; finalize any category specific setup code
(case (-> this category) (case (-> this category)
(((speedrun-category newgame-normal)) (((speedrun-category newgame-normal))
(initialize! *game-info* 'game (the-as game-save #f) "game-start")) (initialize! *game-info* 'game (the-as game-save #f) "game-start"))
(((speedrun-category newgame-heromode)) (((speedrun-category newgame-heromode))
(initialize! *game-info* 'game (the-as game-save #f) "game-start-hero"))) (initialize! *game-info* 'game (the-as game-save #f) "game-start-hero"))
(((speedrun-category all-cheats-allowed))
(initialize! *game-info* 'game (the-as game-save #f) "game-start")))
(if (!= -1 (-> *game-info* auto-save-which)) (if (!= -1 (-> *game-info* auto-save-which))
(set! (-> *setting-control* user-default auto-save) #t)) (set! (-> *setting-control* user-default auto-save) #t))
@ -30,7 +31,16 @@
(defmethod enforce-settings! ((this speedrun-info)) (defmethod enforce-settings! ((this speedrun-info))
(set! (-> *pc-settings* ps2-actor-vis?) #t) ;; force PS2 actor visibility (set! (-> *pc-settings* ps2-actor-vis?) #t) ;; force PS2 actor visibility
(set-frame-rate! *pc-settings* 60 #t) ;; force FPS to `60` (set-frame-rate! *pc-settings* 60 #t) ;; force FPS to `60`
(set! (-> *pc-settings* cheats) (the-as pc-cheats #x0)) ;; disable any active cheats ;; For posterity, the main reason why changing the cheats is useful is for two main reasons:
;; - If you are playing a category that requires cheats (ie. a turbo jetboard one) you'd
;; probably like the game to automatically set the appropriate ones for you
;; - If you are playing a category that forbids cheats, you wouldn't want your run invalidated because you forgot
;;
;; However, the pc-settings stores a backup of your cheats whenever you manually modify them (NYI - no menus yet)
;; and when speedrunner mode is first enabled. They are restored when speedrunner mode is disabled.
(when (!= (-> this category) (speedrun-category all-cheats-allowed))
;; disable any active cheats
(set! (-> *pc-settings* cheats) (the-as pc-cheats #x0)))
(none)) (none))
(defmethod hide-run-info! ((this speedrun-info)) (defmethod hide-run-info! ((this speedrun-info))
@ -66,7 +76,8 @@
(-> this display-run-info?)) (-> this display-run-info?))
(clear *temp-string*) (clear *temp-string*)
(clear *pc-encoded-temp-string*) (clear *pc-encoded-temp-string*)
(format *temp-string* "<COLOR_WHITE>PC Cheats: <COLOR_GREEN>~D~%<COLOR_WHITE>Frame Rate: <COLOR_GREEN>~D~%<COLOR_WHITE>PS2 Actor Vis?: <COLOR_GREEN>~S~%<COLOR_WHITE>Version: <COLOR_GREEN>~S~%" (format *temp-string* "<COLOR_WHITE>Category: <COLOR_GREEN>~S~%<COLOR_WHITE>PC Cheats: <COLOR_GREEN>~D~%<COLOR_WHITE>Frame Rate: <COLOR_GREEN>~D~%<COLOR_WHITE>PS2 Actor Vis?: <COLOR_GREEN>~S~%<COLOR_WHITE>Version: <COLOR_GREEN>~S~%"
(enum->string speedrun-category (-> this category))
(the-as int (-> *pc-settings* cheats)) (the-as int (-> *pc-settings* cheats))
(-> *pc-settings* target-fps) (-> *pc-settings* target-fps)
(if (-> *pc-settings* ps2-actor-vis?) "true" "false") (if (-> *pc-settings* ps2-actor-vis?) "true" "false")
@ -76,7 +87,7 @@
;; reset bucket settings prior to drawing - font won't do this for us, and ;; reset bucket settings prior to drawing - font won't do this for us, and
;; draw-raw-image can sometimes mess them up. (intro sequence) ;; draw-raw-image can sometimes mess them up. (intro sequence)
(dma-buffer-add-gs-set-flusha buf (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1))) (dma-buffer-add-gs-set-flusha buf (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)))
(let ((font-ctx (new 'stack 'font-context *font-default-matrix* 510 375 0.0 (font-color default) (font-flags right shadow kerning large)))) (let ((font-ctx (new 'stack 'font-context *font-default-matrix* 510 365 0.0 (font-color default) (font-flags right shadow kerning large))))
(set! (-> font-ctx scale) 0.325) (set! (-> font-ctx scale) 0.325)
(draw-string-adv *pc-encoded-temp-string* buf font-ctx)))) (draw-string-adv *pc-encoded-temp-string* buf font-ctx))))
(none)) (none))
@ -87,6 +98,16 @@
(new 'static 'popup-menu (new 'static 'popup-menu
:entries (new 'static 'boxed-array :type popup-menu-entry :entries (new 'static 'boxed-array :type popup-menu-entry
(new 'static 'popup-menu-button :label "Reset" :on-press (lambda () (send-event (ppointer->process *speedrun-menu*) 'invoke (speedrun-menu-command reset)))) (new 'static 'popup-menu-button :label "Reset" :on-press (lambda () (send-event (ppointer->process *speedrun-menu*) 'invoke (speedrun-menu-command reset))))
(new 'static 'popup-menu-label :label "Categories")
(new 'static 'popup-menu-flag :label "Normal"
:on-press (lambda () (set-category! *speedrun-info* (speedrun-category newgame-normal)))
:is-toggled? (lambda () (= (-> *speedrun-info* category) (speedrun-category newgame-normal))))
(new 'static 'popup-menu-flag :label "Hero Mode"
:on-press (lambda () (set-category! *speedrun-info* (speedrun-category newgame-heromode)))
:is-toggled? (lambda () (= (-> *speedrun-info* category) (speedrun-category newgame-heromode))))
(new 'static 'popup-menu-flag :label "All Cheats Allowed"
:on-press (lambda () (set-category! *speedrun-info* (speedrun-category all-cheats-allowed)))
:is-toggled? (lambda () (= (-> *speedrun-info* category) (speedrun-category all-cheats-allowed))))
(new 'static 'popup-menu-button :label "Exit" :on-press (lambda () (send-event (ppointer->process *speedrun-menu*) 'invoke (speedrun-menu-command exit)))) (new 'static 'popup-menu-button :label "Exit" :on-press (lambda () (send-event (ppointer->process *speedrun-menu*) 'invoke (speedrun-menu-command exit))))
) )
) )
@ -159,7 +180,7 @@
(when (-> this draw-menu?) (when (-> this draw-menu?)
;; handle any inputs for within the menu ;; handle any inputs for within the menu
(cond (cond
((cpad-pressed? 0 triangle select) ((cpad-pressed? 0 triangle select circle)
(set! (-> this draw-menu?) #f)) (set! (-> this draw-menu?) #f))
((cpad-pressed? 0 up) ((cpad-pressed? 0 up)
(move-up! (-> this popup-menu))) (move-up! (-> this popup-menu)))

View file

@ -79,6 +79,7 @@
(cheats pc-cheats) (cheats pc-cheats)
(cheats-revealed pc-cheats) (cheats-revealed pc-cheats)
(cheats-purchased pc-cheats) (cheats-purchased pc-cheats)
(cheats-backup pc-cheats) ;; backup for 'cheats', persisted to disk to be restored when disabling speedrunner mode
;; music ;; music
(music-unlocked bit-array) (music-unlocked bit-array)
(flava-unlocked symbol 6) (flava-unlocked symbol 6)

View file

@ -563,6 +563,7 @@
(("cheats") (set! (-> obj cheats) (the-as pc-cheats (file-stream-read-int file)))) (("cheats") (set! (-> obj cheats) (the-as pc-cheats (file-stream-read-int file))))
(("cheats-revealed") (set! (-> obj cheats-revealed) (the-as pc-cheats (file-stream-read-int file)))) (("cheats-revealed") (set! (-> obj cheats-revealed) (the-as pc-cheats (file-stream-read-int file))))
(("cheats-purchased") (set! (-> obj cheats-purchased) (the-as pc-cheats (file-stream-read-int file)))) (("cheats-purchased") (set! (-> obj cheats-purchased) (the-as pc-cheats (file-stream-read-int file))))
(("cheats-backup") (set! (-> obj cheats-backup) (the-as pc-cheats (file-stream-read-int file))))
(("music-unlocked") (("music-unlocked")
(dotimes (i (/ (align64 (-> obj music-unlocked length)) 64)) (dotimes (i (/ (align64 (-> obj music-unlocked length)) 64))
(bit-array<-int64 (-> obj music-unlocked) (* i 64) (file-stream-read-int file)) (bit-array<-int64 (-> obj music-unlocked) (* i 64) (file-stream-read-int file))
@ -591,6 +592,7 @@
(format file " (cheats #x~x)~%" (-> obj cheats)) (format file " (cheats #x~x)~%" (-> obj cheats))
(format file " (cheats-revealed #x~x)~%" (-> obj cheats-revealed)) (format file " (cheats-revealed #x~x)~%" (-> obj cheats-revealed))
(format file " (cheats-purchased #x~x)~%" (-> obj cheats-purchased)) (format file " (cheats-purchased #x~x)~%" (-> obj cheats-purchased))
(format file " (cheats-backup #x~x)~%" (-> obj cheats-backup))
(format file " (music-unlocked") (format file " (music-unlocked")
(dotimes (i (/ (align64 (-> obj music-unlocked length)) 64)) (dotimes (i (/ (align64 (-> obj music-unlocked length)) 64))
(format file " #x~x" (int64<-bit-array (-> obj music-unlocked) (* i 64))) (format file " #x~x" (int64<-bit-array (-> obj music-unlocked) (* i 64)))

View file

@ -364,6 +364,11 @@ This gives us more freedom to write code how we want.
:get-value-fn (lambda () (-> *pc-settings* speedrunner-mode?)) :get-value-fn (lambda () (-> *pc-settings* speedrunner-mode?))
:on-confirm (lambda ((val symbol)) :on-confirm (lambda ((val symbol))
(set! (-> *pc-settings* speedrunner-mode?) val) (set! (-> *pc-settings* speedrunner-mode?) val)
;; store and restore pc-settings cheats
;; TODO - when cheats menus are actually added, update the backup whenever one is changed
(if (-> *pc-settings* speedrunner-mode?)
(set! (-> *pc-settings* cheats-backup) (-> *pc-settings* cheats))
(set! (-> *pc-settings* cheats) (-> *pc-settings* cheats-backup)))
(commit-to-file *pc-settings*))) (commit-to-file *pc-settings*)))
(new 'static 'menu-generic-boolean-option (new 'static 'menu-generic-boolean-option
:name (text-id progress-fast-progress) :name (text-id progress-fast-progress)

View file

@ -12,8 +12,13 @@
(:methods (:methods
(draw! (_type_ font-context dma-buffer) none))) (draw! (_type_ font-context dma-buffer) none)))
(deftype popup-menu-label (popup-menu-entry) ())
(deftype popup-menu-button (popup-menu-entry) ()) (deftype popup-menu-button (popup-menu-entry) ())
(deftype popup-menu-flag (popup-menu-entry)
((is-toggled? (function symbol))))
(deftype popup-menu (basic) (deftype popup-menu (basic)
((entries (array popup-menu-entry)) ((entries (array popup-menu-entry))
(curr-entry-index int32)) (curr-entry-index int32))

View file

@ -2,9 +2,6 @@
(in-package goal) (in-package goal)
(defmethod draw! ((this popup-menu-entry) (font-ctx font-context) (dma-buf dma-buffer)) (defmethod draw! ((this popup-menu-entry) (font-ctx font-context) (dma-buf dma-buffer))
(none))
(defmethod draw! ((this popup-menu-button) (font-ctx font-context) (dma-buf dma-buffer))
(let ((old-x (-> font-ctx origin x)) (let ((old-x (-> font-ctx origin x))
(old-y (-> font-ctx origin y))) (old-y (-> font-ctx origin y)))
(pc-encode-utf8-string (-> this label) *pc-encoded-temp-string*) (pc-encode-utf8-string (-> this label) *pc-encoded-temp-string*)
@ -31,20 +28,37 @@
(new 'static 'rgba :r 0 :g 0 :b 0 :a 255)) (new 'static 'rgba :r 0 :g 0 :b 0 :a 255))
;; menu contents ;; menu contents
(dotimes (i (-> this entries length)) (dotimes (i (-> this entries length))
(if (= i (-> this curr-entry-index)) (cond
(set! (-> font-ctx color) (font-color cyan)) ;; TODO - probably just handle this in the draw methods
(set! (-> font-ctx color) (font-color default))) ((type? (-> this entries i) popup-menu-label)
(set! (-> font-ctx color) (font-color progress-option-off)))
((type? (-> this entries i) popup-menu-flag)
(set! (-> font-ctx color)
(if (or ((-> (the-as popup-menu-flag (-> this entries i)) is-toggled?))
(= i (-> this curr-entry-index)))
(font-color cyan)
(font-color default))))
(else
(set! (-> font-ctx color)
(if (= i (-> this curr-entry-index))
(font-color cyan)
(font-color default)))))
(draw! (-> this entries i) font-ctx buf) (draw! (-> this entries i) font-ctx buf)
(set! (-> font-ctx origin y) (+ 15.0 (-> font-ctx origin y))))) (set! (-> font-ctx origin y) (+ 15.0 (-> font-ctx origin y))))))
)
(none)) (none))
(defmethod move-up! ((this popup-menu)) (defmethod move-up! ((this popup-menu))
(set! (-> this curr-entry-index) (max 0 (dec (-> this curr-entry-index)))) (set! (-> this curr-entry-index) (max 0 (dec (-> this curr-entry-index))))
;; skip labels
(when (type? (-> this entries (-> this curr-entry-index)) popup-menu-label)
(set! (-> this curr-entry-index) (max 0 (dec (-> this curr-entry-index)))))
(none)) (none))
(defmethod move-down! ((this popup-menu)) (defmethod move-down! ((this popup-menu))
(set! (-> this curr-entry-index) (min (dec (-> this entries length)) (inc (-> this curr-entry-index)))) (set! (-> this curr-entry-index) (min (dec (-> this entries length)) (inc (-> this curr-entry-index))))
;; skip labels
(when (type? (-> this entries (-> this curr-entry-index)) popup-menu-label)
(set! (-> this curr-entry-index) (min (dec (-> this entries length)) (inc (-> this curr-entry-index)))))
(none)) (none))
(defmethod press! ((this popup-menu)) (defmethod press! ((this popup-menu))