Files
jak-project/goal_src/engine/game/settings-h.gc
T
ManDude df991470f7 cleanup settings stuff (#1444)
* rename `setting-control` methods

* macros around settings stuff

* fix some `process-spawn`s

* update source 1

* update remaining stuff + fix silly bug

* clang

* AGH
2022-06-12 12:23:08 -04:00

236 lines
9.7 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: settings-h.gc
;; name in dgo: settings-h
;; dgos: GAME, ENGINE
;; The settings system manages the state of settings like volume, language, and some other game state.
;; There are two special features of settings:
;; - To avoid changing a setting and forgetting to restore it, all changes must have an associated process. When that process dies, the settings is reverted.
;; - If there are no processes trying to set a setting, it will go to a "default" setting.
;; - We must catch the actual changing of settings once per frame, and possibly call functions for certains settings.
;; The full setting state.
(deftype setting-data (structure)
((border-mode symbol :offset-assert 0)
(sfx-volume float :offset-assert 4)
(music-volume float :offset-assert 8)
(dialog-volume float :offset-assert 12)
(process-mask process-mask :offset-assert 16)
(common-page int32 :offset-assert 20)
(language language-enum :offset-assert 24)
(screenx int32 :offset-assert 32)
(screeny int32 :offset-assert 36)
(vibration symbol :offset-assert 40)
(play-hints symbol :offset-assert 44)
(movie (pointer process) :offset-assert 48)
(talking (pointer process) :offset-assert 52)
(spooling (pointer process) :offset-assert 56)
(hint (pointer process) :offset-assert 60)
(ambient (pointer process) :offset-assert 64)
(video-mode symbol :offset-assert 68)
(aspect-ratio symbol :offset-assert 72)
(sound-flava uint8 :offset-assert 76)
(auto-save symbol :offset-assert 80)
(music-volume-movie float :offset-assert 84)
(sfx-volume-movie float :offset-assert 88)
(music symbol :offset-assert 92)
(bg-r float :offset-assert 96)
(bg-g float :offset-assert 100)
(bg-b float :offset-assert 104)
(bg-a float :offset-assert 108)
(bg-a-speed float :offset-assert 112)
(bg-a-force float :offset-assert 116)
(allow-progress symbol :offset-assert 120)
(allow-pause symbol :offset-assert 124)
(sound-flava-priority float :offset-assert 128)
(ocean-off symbol :offset-assert 132)
(allow-look-around symbol :offset-assert 136)
(ambient-volume float :offset-assert 140)
(ambient-volume-movie float :offset-assert 144)
(dialog-volume-hint float :offset-assert 148)
(dummy uint32 11 :offset-assert 152)
)
:method-count-assert 10
:size-assert #xc4
:flag-assert #xa000000c4
(:methods
(update-from-engine (_type_ engine) setting-data 9)
)
)
(defmethod inspect setting-data ((obj setting-data))
(format #t "[~8x] ~A~%" obj 'setting-data)
(format #t "~Tborder-mode: ~A~%" (-> obj border-mode))
(format #t "~Tsfx-volume: ~f~%" (-> obj sfx-volume))
(format #t "~Tmusic-volume: ~f~%" (-> obj music-volume))
(format #t "~Tdialog-volume: ~f~%" (-> obj dialog-volume))
(format #t "~Tprocess-mask: ~D~%" (-> obj process-mask))
(format #t "~Tcommon-page: ~D~%" (-> obj common-page))
(format #t "~Tlanguage: ~D~%" (-> obj language))
(format #t "~Tscreenx: ~D~%" (-> obj screenx))
(format #t "~Tscreeny: ~D~%" (-> obj screeny))
(format #t "~Tvibration: ~A~%" (-> obj vibration))
(format #t "~Tplay-hints: ~A~%" (-> obj play-hints))
(format #t "~Tmovie: ~A~%" (ppointer->process (-> obj movie)))
(format #t "~Ttalking: ~A~%" (ppointer->process (-> obj talking)))
(format #t "~Tspooling: ~A~%" (ppointer->process (-> obj spooling)))
(format #t "~Thint: ~A~%" (ppointer->process (-> obj hint)))
(format #t "~Tambient: ~A~%" (ppointer->process (-> obj ambient)))
(format #t "~Tvideo-mode: ~A~%" (-> obj video-mode))
(format #t "~Taspect-ratio: ~A~%" (-> obj aspect-ratio))
(format #t "~Tsound-flava: ~D~%" (-> obj sound-flava))
(format #t "~Tauto-save: ~A~%" (-> obj auto-save))
(format #t "~Tmusic-volume-movie: ~f~%" (-> obj music-volume-movie))
(format #t "~Tsfx-volume-movie: ~f~%" (-> obj sfx-volume-movie))
(format #t "~Tmusic: ~A~%" (-> obj music))
(format #t "~Tbg-r: ~f~%" (-> obj bg-r))
(format #t "~Tbg-g: ~f~%" (-> obj bg-g))
(format #t "~Tbg-b: ~f~%" (-> obj bg-b))
(format #t "~Tbg-a: ~f~%" (-> obj bg-a))
(format #t "~Tbg-a-speed: ~f~%" (-> obj bg-a-speed))
(format #t "~Tbg-a-force: ~f~%" (-> obj bg-a-force))
(format #t "~Tallow-progress: ~A~%" (-> obj allow-progress))
(format #t "~Tallow-pause: ~A~%" (-> obj allow-pause))
(format #t "~Tsound-flava-priority: ~f~%" (-> obj sound-flava-priority))
(format #t "~Tocean-off: ~A~%" (-> obj ocean-off))
(format #t "~Tallow-look-around: ~A~%" (-> obj allow-look-around))
(format #t "~Tambient-volume: ~f~%" (-> obj ambient-volume))
(format #t "~Tambient-volume-movie: ~f~%" (-> obj ambient-volume-movie))
(format #t "~Tdialog-volume-hint: ~f~%" (-> obj dialog-volume-hint))
(format #t "~Tdummy[11] @ #x~X~%" (-> obj dummy))
obj
)
;; There are three copies of setting data:
;; - default - if nothing is requesting a setting to be set, you end up with this value.
;; - target - the default settings, plus the changes from all processes
;; - current - the actual settings. gets set to target on each frame.
;; The setting-control manages the current/target/default system.
;; The setting requests are managed by the engine.
(deftype setting-control (basic)
((current setting-data :inline :offset-assert 16)
(target setting-data :inline :offset-assert 224)
(default setting-data :inline :offset-assert 432)
(engine engine :offset-assert 628)
)
:method-count-assert 14
:size-assert #x278
:flag-assert #xe00000278
(:methods
(new (symbol type int) _type_ 0)
(add-setting (_type_ process symbol object object object) none 9)
(set-setting (_type_ process symbol object object object) none 10)
(remove-setting (_type_ process symbol) none 11)
(apply-settings (_type_) setting-data 12)
(update (_type_) setting-data 13)
)
)
(defmethod new setting-control ((allocation symbol) (type-to-make type) (max-connections int))
"Allocate a new setting-control and its engine"
(let ((s4-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> s4-0 engine) ((method-of-type engine new) allocation engine 'setting-control max-connections))
s4-0
)
)
(defmacro setting-control-func! (func s &rest args)
(let ((argb #f)
(argi 0)
(argf 0.0)
(setting (car s)))
(cond
; ((or (eq? setting 'border-mode)
; (eq? setting 'allow-look-around)
; (eq? setting 'ocean-off)
; (eq? setting 'music)
; (eq? setting 'vibration)
; (eq? setting 'auto-save)
; (eq? setting 'allow-pause)
; (eq? setting 'allow-progress)
; (eq? setting 'play-hints)
; (eq? setting 'movie)
; (eq? setting 'talking)
; (eq? setting 'spooling)
; (eq? setting 'hint)
; (eq? setting 'ambient)
; )
; (set! argb (car args))
; )
; ((or (eq? setting 'bg-r)
; (eq? setting 'bg-g)
; (eq? setting 'bg-b)
; (eq? setting 'bg-a)
; (eq? setting 'bg-a-speed)
; (eq? setting 'bg-a-force)
; )
; (set! argf (car args))
; )
; ((or (eq? setting 'language)
; )
; (set! argi (car args))
; )
; ((or (eq? setting 'sound-flava)
; )
; (set! argi (car args))
; (set! argf (cadr args))
; )
; ((or (eq? setting 'process-mask)
; (eq? setting 'common-page)
; )
; (set! argb (car args))
; (set! argi (cadr args))
; )
; ((or (eq? setting 'sfx-volume)
; (eq? setting 'music-volume)
; (eq? setting 'ambient-volume)
; (eq? setting 'dialog-volume)
; (eq? setting 'sfx-volume-movie)
; (eq? setting 'music-volume-movie)
; (eq? setting 'ambient-volume-movie)
; (eq? setting 'dialog-volume-hint)
; )
; (set! argb (car args))
; (set! argf (cadr args))
; )
(#t
(set! argb (car args))
(set! argf (cadr args))
(set! argi (caddr args))
)
)
`(,func *setting-control* (with-pp pp) ,s ,argb ,argf ,argi)
)
)
(defmacro add-setting! (s &rest args)
`(setting-control-func! add-setting ,s ,@args)
)
(defmacro set-setting! (s &rest args)
`(setting-control-func! set-setting ,s ,@args)
)
(defmacro remove-setting! (s)
`(remove-setting *setting-control* (with-pp pp) ,s)
)
;; used for memory card time information
(deftype scf-time (structure)
((stat uint8 :offset-assert 0)
(second uint8 :offset-assert 1)
(minute uint8 :offset-assert 2)
(hour uint8 :offset-assert 3)
(week uint8 :offset-assert 4)
(day uint8 :offset-assert 5)
(month uint8 :offset-assert 6)
(year uint8 :offset-assert 7)
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
(define-extern *setting-control* setting-control)