Files
jak-project/goal_src/jak1/engine/game/settings.gc
2024-07-09 01:24:03 +02:00

297 lines
16 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/ps2/pad.gc")
(require "engine/gfx/ocean/ocean-h.gc")
(#when PC_PORT
(define *progress-flava* -1))
;; DECOMP BEGINS
(defmethod update-from-engine ((this setting-data) (arg0 engine))
"this goes through the list of desired setting changes in
the engine/connection list and updates the setting-data"
(let ((conn (the-as connection (-> arg0 alive-list-end)))
(s4-0 (-> arg0 alive-list-end prev0)))
(while (!= (the-as connectable conn) (-> arg0 alive-list))
(case (-> conn param0)
(('border-mode) (set! (-> this border-mode) (the-as symbol (-> conn param1))))
(('allow-look-around) (set! (-> this allow-look-around) (the-as symbol (-> conn param1))))
(('ocean-off) (set! (-> this ocean-off) (the-as symbol (-> conn param1))))
(('music) (set! (-> this music) (the-as symbol (-> conn param1))))
(('process-mask)
(case (the-as object (-> conn param1))
(('set) (logior! (-> this process-mask) (the-as int (-> conn param3))))
(('clear) (logclear! (-> this process-mask) (the-as uint (-> conn param3))))
(('abs) (set! (-> this process-mask) (the-as process-mask (the-as int (-> conn param3)))))))
(('sfx-volume)
(when (or (not (logtest? (-> *kernel-context* prevent-from-run) (process-mask progress)))
(= (get-process conn) (ppointer->process *progress-process*)))
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this sfx-volume) (* 0.01 (the-as float (-> conn param2)) (-> this sfx-volume))))
(else (set! (-> this sfx-volume) (the-as float (-> conn param2)))))))
(('music-volume)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this music-volume) (* 0.01 (the-as float (-> conn param2)) (-> this music-volume))))
(else (set! (-> this music-volume) (the-as float (-> conn param2))))))
(('ambient-volume)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this ambient-volume) (* 0.01 (the-as float (-> conn param2)) (-> this ambient-volume))))
(else (set! (-> this ambient-volume) (the-as float (-> conn param2))))))
(('dialog-volume)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this dialog-volume) (* 0.01 (the-as float (-> conn param2)) (-> this dialog-volume))))
(else (set! (-> this dialog-volume) (the-as float (-> conn param2))))))
(('sfx-volume-movie)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this sfx-volume-movie) (* 0.01 (the-as float (-> conn param2)) (-> this sfx-volume-movie))))
(else (set! (-> this sfx-volume-movie) (the-as float (-> conn param2))))))
(('music-volume-movie)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this music-volume-movie) (* 0.01 (the-as float (-> conn param2)) (-> this music-volume-movie))))
(else (set! (-> this music-volume-movie) (the-as float (-> conn param2))))))
(('ambient-volume-movie)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this ambient-volume-movie) (* 0.01 (the-as float (-> conn param2)) (-> this ambient-volume-movie))))
(else (set! (-> this ambient-volume-movie) (the-as float (-> conn param2))))))
(('dialog-volume-hint)
(case (the-as symbol (-> conn param1))
(('rel) (set! (-> this dialog-volume-hint) (* 0.01 (the-as float (-> conn param2)) (-> this dialog-volume-hint))))
(else (set! (-> this dialog-volume-hint) (the-as float (-> conn param2))))))
(('sound-flava)
(when (>= (the-as float (-> conn param2)) (-> this sound-flava-priority))
(set! (-> this sound-flava) (the-as uint (the-as int (-> conn param3))))
(set! (-> this sound-flava-priority) (the-as float (-> conn param2)))))
(('bg-r) (set! (-> this bg-r) (the-as float (-> conn param2))))
(('bg-g) (set! (-> this bg-g) (the-as float (-> conn param2))))
(('bg-b) (set! (-> this bg-b) (the-as float (-> conn param2))))
(('bg-a) (set! (-> this bg-a) (the-as float (-> conn param2))))
(('bg-a-speed) (set! (-> this bg-a-speed) (the-as float (-> conn param2))))
(('bg-a-force) (set! (-> this bg-a-force) (the-as float (-> conn param2))))
(('language) (set! (-> this language) (the-as language-enum (the-as int (-> conn param3)))))
(('vibration) (set! (-> this vibration) (the-as symbol (-> conn param1))))
(('auto-save) (set! (-> this auto-save) (the-as symbol (-> conn param1))))
(('allow-pause) (set! (-> this allow-pause) (the-as symbol (-> conn param1))))
(('allow-progress) (set! (-> this allow-progress) (the-as symbol (-> conn param1))))
(('play-hints) (set! (-> this play-hints) (the-as symbol (-> conn param1))))
(('movie) (set! (-> this movie) (the-as (pointer progress) (-> conn param1))))
(('talking) (set! (-> this talking) (the-as (pointer progress) (-> conn param1))))
(('spooling) (set! (-> this spooling) (the-as (pointer progress) (-> conn param1))))
(('hint) (set! (-> this hint) (the-as (pointer process) (-> conn param1))))
(('ambient) (set! (-> this ambient) (the-as (pointer progress) (-> conn param1))))
(('common-page)
(case (the-as object (-> conn param1))
(('set) (logior! (-> this common-page) (the-as int (-> conn param3))))
(('clear) (logclear! (-> this common-page) (the-as uint (-> conn param3)))))))
(set! conn (the-as connection s4-0))
(set! s4-0 (-> (the-as connectable conn) prev0))))
this)
(defmethod add-setting ((this setting-control) (arg0 process) (arg1 symbol) (arg2 object) (arg3 object) (arg4 object))
"add a setting for the process."
(add-connection (-> this engine) arg0 arg1 arg2 arg3 arg4)
0
(none))
(defmethod set-setting ((this setting-control) (arg0 process) (arg1 symbol) (arg2 object) (arg3 object) (arg4 object))
"(re-)sets a setting for the process."
(remove-setting this arg0 arg1)
(add-connection (-> this engine) arg0 arg1 arg2 arg3 arg4)
0
(none))
(defmethod remove-setting ((this setting-control) (arg0 process) (arg1 symbol))
"remove a setting from the specified process.
if arg1 = #t then remove ALL settings for that process"
(when arg0
(let ((s5-0 (-> this engine))
(s4-0 (-> arg0 connection-list next1)))
(while s4-0
(if (and (belongs-to-engine? (the-as connection s4-0) s5-0) (or (= arg1 #t) (= arg1 (-> (the-as connection s4-0) param0))))
(move-to-dead (the-as connection s4-0)))
(set! s4-0 (-> s4-0 next1)))))
0
(none))
(defmethod apply-settings ((this setting-control))
"Update the current settings. This only updates settings that are 'safe' to do multiple times per frame."
(let ((gp-0 (-> this current)))
(let ((s5-0 (-> this target)))
;; set the settings to default
(mem-copy! (the-as pointer s5-0) (the-as pointer (-> this default)) 196)
;; hack
(set! (-> s5-0 ambient-volume) (* (* 0.01 (-> this default ambient-volume)) (-> this default sfx-volume)))
;; apply requesting changes
(update-from-engine s5-0 (-> this engine))
;; copy those settings to current.
(set! (-> gp-0 border-mode) (-> s5-0 border-mode))
(set! (-> gp-0 common-page) (-> s5-0 common-page))
(set! (-> gp-0 vibration) (-> s5-0 vibration))
(set! (-> gp-0 auto-save) (-> s5-0 auto-save))
(set! (-> gp-0 play-hints) (-> s5-0 play-hints))
(set! (-> gp-0 movie) (-> s5-0 movie))
(set! (-> gp-0 talking) (-> s5-0 talking))
(set! (-> gp-0 spooling) (-> s5-0 spooling))
(set! (-> gp-0 hint) (-> s5-0 hint))
(set! (-> gp-0 ambient) (-> s5-0 ambient))
(set! (-> gp-0 allow-pause) (-> s5-0 allow-pause))
(set! (-> gp-0 allow-progress) (-> s5-0 allow-progress))
(set! (-> gp-0 allow-look-around) (-> s5-0 allow-look-around))
(set! (-> gp-0 ocean-off) (-> s5-0 ocean-off))
(set! (-> gp-0 ambient-volume-movie) (-> s5-0 ambient-volume-movie))
(set! (-> gp-0 music-volume-movie) (-> s5-0 music-volume-movie))
(set! (-> gp-0 sfx-volume-movie) (-> s5-0 sfx-volume-movie))
(set! (-> gp-0 dialog-volume-hint) (-> s5-0 dialog-volume-hint))
(set! (-> gp-0 process-mask) (-> s5-0 process-mask)))
(set! (-> *kernel-context* prevent-from-run) (-> gp-0 process-mask))
gp-0))
(defmethod update ((this setting-control))
"Do a per-frame update of all settings"
;; compute all settings
(apply-settings this)
;; now handle the special ones.
(let ((gp-0 (-> this current)))
(let ((s5-1 (-> this target)))
;; the volume change is done slowly
(when *sound-player-enable*
(when (!= (-> gp-0 sfx-volume) (-> s5-1 sfx-volume))
(seek! (-> gp-0 sfx-volume) (-> s5-1 sfx-volume) (* 100.0 (seconds-per-frame)))
(sound-set-volume (sound-group sfx) (-> gp-0 sfx-volume))
;; og:preserve-this Fix for menu-close
(sound-set-volume (sound-group sog3) (-> gp-0 sfx-volume)))
(when (!= (-> gp-0 music-volume) (-> s5-1 music-volume))
(seek! (-> gp-0 music-volume) (-> s5-1 music-volume) (* 100.0 (seconds-per-frame)))
(sound-set-volume (sound-group music) (-> gp-0 music-volume)))
(when (!= (-> gp-0 dialog-volume) (-> s5-1 dialog-volume))
(seek! (-> gp-0 dialog-volume) (-> s5-1 dialog-volume) (* 100.0 (seconds-per-frame)))
(sound-set-volume (sound-group dialog) (-> gp-0 dialog-volume)))
(when (!= (-> gp-0 ambient-volume) (-> s5-1 ambient-volume))
(seek! (-> gp-0 ambient-volume) (-> s5-1 ambient-volume) (* 100.0 (seconds-per-frame)))
(sound-set-volume (sound-group ambient) (-> gp-0 ambient-volume))))
;; send language change to the IOP.
(when (!= (-> gp-0 language) (-> s5-1 language))
;; og:preserve-this pc port added this
(#when PC_PORT
(cond
((not *jak1-full-game*))
((= (language-enum japanese) (-> s5-1 language)) ;; old lang wasnt japanese
(sound-bank-unload (static-sound-name "common"))
(sound-bank-load (static-sound-name "commonj")))
((= (language-enum japanese) (-> gp-0 language)) ;; old lang was japanese
(sound-bank-unload (static-sound-name "commonj"))
(sound-bank-load (static-sound-name "common")))))
(set! (-> gp-0 language) (-> s5-1 language))
(set-language (-> gp-0 language)))
;; try to load music
(when (and (!= (-> s5-1 music) (-> gp-0 music))
(and (< 0.0 (-> *setting-control* current music-volume)) (zero? (rpc-busy? 1)) *sound-bank-1* *sound-bank-2*))
(cond
((-> s5-1 music)
(format 0 "Load music ~A~%" (-> s5-1 music))
(sound-music-load (string->sound-name (symbol->string (-> s5-1 music)))))
(else (format 0 "Unload music~%") (sound-music-unload)))
(set! (-> gp-0 music) (-> s5-1 music)))
;; set sound flava
(set! (-> s5-1 sound-flava) (the-as uint (flava-lookup (-> gp-0 music) (the-as music-flava (-> s5-1 sound-flava)))))
(set! (-> gp-0 sound-flava) (-> s5-1 sound-flava))
(if *sound-player-enable*
(#if PC_PORT
(sound-set-flava (if (>= *progress-flava* 0) (the uint *progress-flava*) (-> gp-0 sound-flava)))
(sound-set-flava (-> gp-0 sound-flava))))
;; update display settings
(when (!= (-> gp-0 aspect-ratio) (-> s5-1 aspect-ratio))
(set! (-> gp-0 aspect-ratio) (-> s5-1 aspect-ratio))
(set-aspect-ratio (-> gp-0 aspect-ratio)))
(when (!= (-> gp-0 video-mode) (-> s5-1 video-mode))
(set! (-> gp-0 video-mode) (-> s5-1 video-mode))
(set-video-mode (-> gp-0 video-mode)))
(when (!= (-> gp-0 screenx) (-> s5-1 screenx))
(set! (-> gp-0 screenx) (-> s5-1 screenx))
(set! (-> *video-parms* display-dx) (/ (-> s5-1 screenx) 2))
(set! (-> *video-parms* set-video-mode) #t))
(when (!= (-> gp-0 screeny) (-> s5-1 screeny))
(set! (-> gp-0 screeny) (-> s5-1 screeny))
(set! (-> *video-parms* display-dy) (* (/ (-> s5-1 screeny) 2) 2))
(set! (-> *video-parms* set-video-mode) #t))
;; update display bg color
(set! (-> gp-0 bg-a-speed) (-> s5-1 bg-a-speed))
(set! (-> gp-0 bg-a-force) (-> s5-1 bg-a-force))
(set! (-> gp-0 bg-r) (-> s5-1 bg-r))
(set! (-> gp-0 bg-g) (-> s5-1 bg-g))
(set! (-> gp-0 bg-b) (-> s5-1 bg-b))
(seek! (-> gp-0 bg-a) (-> s5-1 bg-a) (* (-> s5-1 bg-a-speed) (seconds-per-frame))))
(let ((v1-60 (-> *display* frames (-> *display* on-screen) display))
(f0-39 (-> gp-0 bg-a)))
(if (!= (-> gp-0 bg-a-force) 0.0) (set! f0-39 (-> gp-0 bg-a-force)))
(set! (-> v1-60 bgcolor r) (the int (* 255.0 (-> gp-0 bg-r))))
(set! (-> v1-60 bgcolor g) (the int (* 255.0 (-> gp-0 bg-g))))
(set! (-> v1-60 bgcolor b) (the int (* 255.0 (-> gp-0 bg-b))))
(set! (-> v1-60 pmode alp) (the int (* 255.0 (- 1.0 f0-39)))))
;; ??
(set! (-> *level* border?) (-> gp-0 border-mode))
;; common pool texture page mask
(set! (-> *texture-pool* common-page-mask) (-> gp-0 common-page))
(set! (-> *cpad-list* cpads 0 buzz) (-> gp-0 vibration))
(case (-> gp-0 ocean-off)
((#t) (set! *ocean-off* #t))
(('mid) (set! *ocean-mid-off* #t))
(('near) (set! *ocean-near-off* #t)))
gp-0))
(when (zero? *setting-control*)
(set! *setting-control* (new 'global 'setting-control 32))
(let ((gp-0 (-> *setting-control* default))
(s5-0 (-> *setting-control* current)))
(let ((f0-2 (* 0.01 (the float (scf-get-volume)))))
(set! (-> gp-0 ocean-off) #f)
(set! (-> gp-0 allow-look-around) #t)
(set! (-> gp-0 border-mode) #f)
(set! (-> gp-0 sfx-volume) (the float (* 5 (the int (+ 0.5 (* 15.0 f0-2))))))
(set! (-> gp-0 music-volume) (the float (* 5 (the int (+ 0.5 (* 13.0 f0-2))))))
(set! (-> gp-0 dialog-volume) (the float (* 5 (the int (+ 0.5 (* 20.0 f0-2))))))
(set! (-> gp-0 ambient-volume) (the float (* 5 (the int (+ 0.5 (* 15.0 f0-2))))))
(set! (-> gp-0 sfx-volume-movie) (the float (* 5 (the int (+ 0.5 (* 11.0 f0-2))))))
(set! (-> gp-0 music-volume-movie) (the float (* 5 (the int (+ 0.5 (* 13.0 f0-2))))))
(set! (-> gp-0 ambient-volume-movie) (the float (* 5 (the int (+ 0.5 (* 11.0 f0-2))))))
(set! (-> gp-0 dialog-volume-hint) (the float (* 5 (the int (+ 0.5 (* 16.0 f0-2)))))))
(set! (-> gp-0 language) (scf-get-language))
(set! (-> gp-0 process-mask) (process-mask execute sleep))
(set! (-> gp-0 screenx) 0)
(set! (-> gp-0 screeny) 0)
(set! (-> gp-0 vibration) #t)
(set! (-> gp-0 auto-save) #f)
(set! (-> gp-0 play-hints) #t)
(set! (-> gp-0 movie) (the-as (pointer process) #f))
(set! (-> gp-0 talking) (the-as (pointer process) #f))
(set! (-> gp-0 spooling) (the-as (pointer process) #f))
(set! (-> gp-0 hint) (the-as (pointer process) #f))
(set! (-> gp-0 ambient) (the-as (pointer process) #f))
(set! (-> gp-0 sound-flava) (the-as uint 49))
(set! (-> gp-0 sound-flava-priority) 0.0)
(set! (-> gp-0 music) #f)
(set! (-> gp-0 bg-a-speed) 8.0)
(set! (-> gp-0 allow-pause) #t)
(set! (-> gp-0 allow-progress) #t)
(case (scf-get-aspect)
((2) (set! (-> gp-0 aspect-ratio) 'aspect16x9))
(else (set! (-> gp-0 aspect-ratio) 'aspect4x3)))
(if (zero? *boot-video-mode*) (set! (-> gp-0 video-mode) 'ntsc) (set! (-> gp-0 video-mode) 'pal))
(set! (-> s5-0 sfx-volume) (+ -1.0 (-> gp-0 sfx-volume)))
(set! (-> s5-0 music-volume) (+ -1.0 (-> gp-0 music-volume)))
(set! (-> s5-0 dialog-volume) (+ -1.0 (-> gp-0 dialog-volume)))
(set! (-> s5-0 ambient-volume) (+ -1.0 (-> gp-0 ambient-volume)))
(set! (-> s5-0 sfx-volume-movie) (-> gp-0 sfx-volume-movie))
(set! (-> s5-0 music-volume-movie) (-> gp-0 music-volume-movie))
(set! (-> s5-0 ambient-volume-movie) (-> gp-0 ambient-volume-movie))
(set! (-> s5-0 dialog-volume-hint) (-> gp-0 dialog-volume-hint))
(set! (-> s5-0 language) (+ (-> gp-0 language) -1))
(set! (-> s5-0 aspect-ratio) #f)
(set! (-> s5-0 video-mode) #f)
(set! (-> s5-0 music) #f)
(set! (-> s5-0 bg-a-speed) (-> gp-0 bg-a-speed))
(set! (-> s5-0 allow-pause) (-> gp-0 allow-pause))
(set! (-> s5-0 allow-progress) (-> gp-0 allow-progress))
(set! (-> s5-0 allow-look-around) (-> gp-0 allow-look-around))
(set! (-> s5-0 ocean-off) (-> gp-0 ocean-off))))