Skip to content

Commit

Permalink
[jak2] simplify fps disclaimer (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManDude authored Oct 30, 2023
1 parent cd68cb6 commit 99cb51f
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 52 deletions.
19 changes: 19 additions & 0 deletions common/type_system/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@ Type* TypeSystem::lookup_type(const TypeSpec& ts) const {
return lookup_type(ts.base_type());
}

/*!
* Same as lookup_type, but returns null instead of throwing.
*/
Type* TypeSystem::lookup_type_no_throw(const std::string& name) const {
auto kv = m_types.find(name);
if (kv != m_types.end()) {
return kv->second.get();
}

return nullptr;
}

/*!
* Same as lookup_type, but returns null instead of throwing.
*/
Type* TypeSystem::lookup_type_no_throw(const TypeSpec& ts) const {
return lookup_type_no_throw(ts.base_type());
}

/*!
* Get type info. If the type is not fully defined (ie, we are parsing its deftype now) and its
* forward defined as a basic or structure, just get basic/structure.
Expand Down
3 changes: 3 additions & 0 deletions common/type_system/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class TypeSystem {
Type* lookup_type(const TypeSpec& ts) const;
Type* lookup_type(const std::string& name) const;

Type* lookup_type_no_throw(const TypeSpec& ts) const;
Type* lookup_type_no_throw(const std::string& name) const;

Type* lookup_type_allow_partial_def(const TypeSpec& ts) const;
Type* lookup_type_allow_partial_def(const std::string& name) const;

Expand Down
3 changes: 2 additions & 1 deletion common/type_system/deftype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ void add_field(
throw std::runtime_error(
fmt::format("Field {} not found to overlay for {}", field_name, name));
}
type_to_use = dynamic_cast<StructureType*>(ts->lookup_type(overlay_field.type()));
type_to_use =
dynamic_cast<StructureType*>(ts->lookup_type_no_throw(overlay_field.type()));
offset_override += overlay_field.offset();
}
name_it = cdr(name_it);
Expand Down
2 changes: 0 additions & 2 deletions decompiler/config/jak2/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -7426,8 +7426,6 @@
(progress-highscores-local-time #x1313)
(progress-fps-disclaimer-warning #x1314)
(progress-fps-disclaimer #x1315)
(progress-fps-disclaimer-1 #x1316)
(progress-fps-disclaimer-confirm #x1317)
)
;; ---text-id-h:text-id

Expand Down
4 changes: 1 addition & 3 deletions game/assets/jak2/text/game_custom_text_en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,5 @@
"1312": "Any% - Hero Mode",
"1313": "Local Time",
"1314": "Warning!",
"1315": "This setting is highly experimental. While the game can be completed with it, going past 60 FPS is known to cause (mostly minor) issues that may impact your experience.",
"1316": "The game may also start to lag and slow down as a result if you can't keep the selected frame rate up, so ensure your PC can handle it.",
"1317": "Confirm"
"1315": "This setting is highly experimental. When not played at 60 frames per second, visual and gameplay issues may arise as a result."
}
2 changes: 0 additions & 2 deletions goal_src/jak2/engine/ui/text-id-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,6 @@
(progress-highscores-local-time #x1313)
(progress-fps-disclaimer-warning #x1314)
(progress-fps-disclaimer #x1315)
(progress-fps-disclaimer-1 #x1316)
(progress-fps-disclaimer-confirm #x1317)
)
;; ---text-id

Expand Down
50 changes: 18 additions & 32 deletions goal_src/jak2/pc/progress/progress-draw-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -2411,51 +2411,37 @@
(defmethod draw-option menu-frame-rate-disclaimer-option ((obj menu-frame-rate-disclaimer-option) (arg0 progress) (arg1 font-context) (arg2 int) (arg3 symbol))
(set! (-> arg1 alpha) (- 1.0 (-> arg0 menu-transition)))
(set-color! arg1 (font-color red))
(set-scale! arg1 0.4)
(set-scale! arg1 0.8)
(set-flags! arg1 (font-flags kerning middle middle-vert large))

(set! (-> arg1 origin x) 90.0)
(set! (-> arg1 origin y) 55.0)
(set! (-> arg1 origin y) 72.0)
(set-width! arg1 330)
(set-height! arg1 85)
(when (not (-> *pc-settings* use-vis?))
(set! (-> arg1 origin x) (the float (adjust-game-x (-> arg1 origin x))))
(*! (-> arg1 width) (-> *pc-settings* aspect-ratio-reciprocal))
)
(when (< (mod (-> *display* real-clock frame-counter) (seconds 1.2)) (seconds 1.0))
(print-game-text (lookup-text! *common-text* (text-id progress-fps-disclaimer-warning) #f) arg1 #f 44 (bucket-id progress))
)
(+! (-> arg1 origin y) 60.0)
(set-color! arg1 (font-color progress))
(print-game-text
(lookup-text! *common-text* (text-id progress-fps-disclaimer) #f)
arg1
#f
44
(bucket-id progress)
)
(print-game-text (lookup-text! *common-text* (text-id progress-fps-disclaimer-warning) #f) arg1 #f 44 (bucket-id progress)))

(+! (-> arg1 origin y) 80.0)
(set-scale! arg1 0.45)
(set-color! arg1 (font-color progress))
(print-game-text (lookup-text! *common-text* (text-id progress-fps-disclaimer) #f) arg1 #f 44 (bucket-id progress))

(+! (-> arg1 origin y) 65.0)
(set-scale! arg1 0.55)
(set-height! arg1 95)
(print-game-text
(lookup-text! *common-text* (text-id progress-fps-disclaimer-1) #f)
arg1
#f
44
(bucket-id progress)
)
(+! (-> arg1 origin y) 95.0)
(print-game-text (lookup-text! *common-text* (text-id progress-memcard-continue?) #f) arg1 #f 44 (bucket-id progress))

(+! (-> arg1 origin y) 58.0)
(set-scale! arg1 0.5)
(set-height! arg1 50)
(set-color! arg1 (progress-selected 0))
(draw-highlight (the int (+ 13.0 (-> arg1 origin y))) 18 (-> arg1 alpha))
(print-game-text
(if (time-elapsed? (-> *progress-state-pc* frame-rate-disclaimer-time) (seconds 5))
(lookup-text! *common-text* (text-id progress-fps-disclaimer-confirm) #f)
(string-format "~Ds" (inc (/ (- (seconds 5) (- (current-time) (-> *progress-state-pc* frame-rate-disclaimer-time))) TICKS_PER_SECOND)))
)
arg1
#f
44
(bucket-id progress)
)
(when (time-elapsed? (-> *progress-state-pc* frame-rate-disclaimer-time) (seconds 3))
(draw-highlight (the int (+ 13.0 (-> arg1 origin y))) 18 (-> arg1 alpha))
(draw-yes-no arg0 arg1))
0
(none)
)
Expand Down
54 changes: 43 additions & 11 deletions goal_src/jak2/pc/progress/progress-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,15 @@
(set-progress-frame-rate-index))
((cpad-pressed? 0 confirm)
(sound-play "generic-beep")
(set-frame-rate! *pc-settings* (-> *frame-rate-options* (-> *progress-state-pc* frame-rate-choice-index)) #t)
(commit-to-file *pc-settings*)
(when (and (not (-> *progress-state-pc* frame-rate-disclaimer-seen?)) (> (-> *pc-settings* target-fps) 60))
(set-time! (-> *progress-state-pc* frame-rate-disclaimer-time))
(push-and-set-state arg0 'fps-disclaimer)
)
(cond
((not (-> *progress-state-pc* frame-rate-disclaimer-seen?))
(set-time! (-> *progress-state-pc* frame-rate-disclaimer-time))
(push-and-set-state arg0 'fps-disclaimer)
)
(else
(set-frame-rate! *pc-settings* (-> *frame-rate-options* (-> *progress-state-pc* frame-rate-choice-index)) #t)
(commit-to-file *pc-settings*)
))
)
(else
(let ((sound-beep? #f))
Expand All @@ -595,11 +598,40 @@

(defmethod respond-progress menu-frame-rate-disclaimer-option ((this menu-frame-rate-disclaimer-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (and (time-elapsed? (-> *progress-state-pc* frame-rate-disclaimer-time) (seconds 5)) (cpad-pressed? 0 confirm))
(cpad-clear! 0 confirm)
(sound-play "generic-beep")
(true! (-> *progress-state-pc* frame-rate-disclaimer-seen?))
(pop-state arg0)
(when (time-elapsed? (-> *progress-state-pc* frame-rate-disclaimer-time) (seconds 3))
(let ((choice (&-> *progress-state* yes-no-choice))
(sound? #f)
)
(cond
((cpad-pressed? 0 left l-analog-left)
(set! sound? (not (-> choice 0)))
(set! (-> choice 0) #t)
)
((cpad-pressed? 0 right l-analog-right)
(set! sound? (-> choice 0))
(set! (-> choice 0) #f)
)
((cpad-pressed? 0 confirm)
(cpad-clear! 0 confirm)
(cond
((-> *progress-state* yes-no-choice)
(true! (-> *progress-state-pc* frame-rate-disclaimer-seen?))
(sound-play "generic-beep")
(set-frame-rate! *pc-settings* (-> *frame-rate-options* (-> *progress-state-pc* frame-rate-choice-index)) #t)
(commit-to-file *pc-settings*)
(pop-state arg0)
)
(else
(sound-play "generic-beep")
(pop-state arg0)
)
)
)
)
(if sound?
(sound-play "generic-beep")
)
)
)
0
)
Expand Down
2 changes: 1 addition & 1 deletion goal_src/jak2/pc/progress/progress-static-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ This gives us more freedom to write code how we want.
)
)

(define *frame-rate-options* (new 'static 'boxed-array :type int16 30 50 60 75 120 144 165 240))
(define *frame-rate-options* (new 'static 'boxed-array :type int16 60 75 120 144 165 240))

(define *frame-rate-disclaimer-options*
(new 'static 'menu-option-list
Expand Down

0 comments on commit 99cb51f

Please sign in to comment.