From 3ed72dab75c1b6bca55f961dd21813e4bb3f9eae Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 21 Jun 2022 00:07:48 +0100 Subject: [PATCH] add window lock toggle and update settings ver --- game/graphics/display.h | 23 ++++++++++------------- game/graphics/gfx.cpp | 6 ++++++ game/graphics/gfx.h | 1 + game/graphics/pipelines/opengl.cpp | 5 +++++ game/graphics/pipelines/opengl.h | 1 + game/kernel/kmachine.cpp | 5 +++++ goal_src/kernel-defs.gc | 1 + goal_src/pc/pckernel-h.gc | 9 ++++++--- goal_src/pc/pckernel.gc | 6 ++++++ 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/game/graphics/display.h b/game/graphics/display.h index 6c66795892..76a36aa538 100644 --- a/game/graphics/display.h +++ b/game/graphics/display.h @@ -10,10 +10,6 @@ #include "common/util/Assert.h" #include "gfx.h" -// lol hax -#define __NYI_DEF \ - { ASSERT_MSG(false, "nyi"); } - // a GfxDisplay class is equivalent to a window that displays stuff. This holds an actual internal // window pointer used by whichever renderer. It also contains functions for setting and // retrieving certain window parameters. @@ -40,15 +36,16 @@ class GfxDisplay { public: virtual ~GfxDisplay() {} - virtual void* get_window() const __NYI_DEF; - virtual void set_size(int w, int h) __NYI_DEF; - virtual void update_fullscreen(GfxDisplayMode mode, int screen) __NYI_DEF; - virtual void get_scale(float* x, float* y) __NYI_DEF; - virtual void get_screen_size(int vmode_idx, s32* w, s32* h, s32* c) __NYI_DEF; - virtual void get_position(int* x, int* y) __NYI_DEF; - virtual void get_size(int* w, int* h) __NYI_DEF; - virtual GfxDisplayMode get_fullscreen() __NYI_DEF; - virtual void render() __NYI_DEF; + virtual void* get_window() const = 0; + virtual void set_size(int w, int h) = 0; + virtual void update_fullscreen(GfxDisplayMode mode, int screen) = 0; + virtual void get_scale(float* x, float* y) = 0; + virtual void get_screen_size(int vmode_idx, s32* w, s32* h, s32* c) = 0; + virtual void get_position(int* x, int* y) = 0; + virtual void get_size(int* w, int* h) = 0; + virtual GfxDisplayMode get_fullscreen() = 0; + virtual void render() = 0; + virtual void set_lock(bool lock) = 0; bool is_active() const { return get_window() != nullptr; } void set_title(const char* title); const char* title() const { return m_title; } diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 889932c8b8..ceb3018883 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -242,6 +242,12 @@ void set_fullscreen(GfxDisplayMode mode, int screen) { } } +void set_window_lock(bool lock) { + if (Display::GetMainDisplay()) { + Display::GetMainDisplay()->set_lock(lock); + } +} + void input_mode_set(u32 enable) { if (enable == s7.offset + jak1_symbols::FIX_SYM_TRUE) { // #t Pad::g_input_mode_mapping = g_settings.pad_mapping_info; diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 5556cd2689..92380474b5 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -115,6 +115,7 @@ GfxDisplayMode get_fullscreen(); void get_screen_size(s64 vmode_idx, s32* w, s32* h, s32* c); void set_letterbox(int w, int h); void set_fullscreen(GfxDisplayMode mode, int screen); +void set_window_lock(bool lock); void input_mode_set(u32 enable); void input_mode_save(); s64 get_mapped_button(s64 pad, s64 button); diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 2249232b4b..38e14532ba 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -135,6 +135,7 @@ static int gl_init(GfxSettings& settings) { } glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_SAMPLES, 1); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); return 0; } @@ -420,6 +421,10 @@ void GLDisplay::get_screen_size(int vmode_idx, s32* w_out, s32* h_out, s32* coun } } +void GLDisplay::set_lock(bool lock) { + glfwSetWindowAttrib(m_window, GLFW_RESIZABLE, lock ? GLFW_TRUE : GLFW_FALSE); +} + void update_global_profiler() { if (g_gfx_data->debug_gui.dump_events) { prof().set_enable(false); diff --git a/game/graphics/pipelines/opengl.h b/game/graphics/pipelines/opengl.h index 318abc36f5..2dd13f6a81 100644 --- a/game/graphics/pipelines/opengl.h +++ b/game/graphics/pipelines/opengl.h @@ -34,6 +34,7 @@ class GLDisplay : public GfxDisplay { void set_size(int w, int h); void update_fullscreen(GfxDisplayMode mode, int screen); void render(); + void set_lock(bool lock); }; extern const GfxRendererModule gRendererOpenGL; diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 574c55709c..b1d11a8956 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -964,6 +964,10 @@ void set_fullscreen(u32 symptr, s64 screen) { } } +void set_window_lock(u32 symptr) { + Gfx::set_window_lock(symptr == s7.offset); +} + void set_collision(u32 symptr) { Gfx::g_global_settings.collision_enable = symptr != s7.offset; } @@ -1012,6 +1016,7 @@ void InitMachine_PCPort() { make_function_symbol_from_c("pc-get-screen-size", (void*)get_screen_size); make_function_symbol_from_c("pc-set-window-size", (void*)Gfx::set_window_size); make_function_symbol_from_c("pc-set-fullscreen", (void*)set_fullscreen); + make_function_symbol_from_c("pc-set-window-lock", (void*)set_window_lock); // graphics things make_function_symbol_from_c("pc-set-letterbox", (void*)Gfx::set_letterbox); diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index b5da9d5879..9294b3b37e 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -353,6 +353,7 @@ (define-extern pc-mkdir-file-path (function string none)) (define-extern pc-sound-set-flava-hack (function int none)) (define-extern pc-sound-set-fade-hack (function int none)) +(define-extern pc-set-window-lock (function symbol none)) (defenum pc-prof-event (begin 0) diff --git a/goal_src/pc/pckernel-h.gc b/goal_src/pc/pckernel-h.gc index 9e9f1b5aa1..0435de59e8 100644 --- a/goal_src/pc/pckernel-h.gc +++ b/goal_src/pc/pckernel-h.gc @@ -31,7 +31,7 @@ (defglobalconstant PC_KERNEL_VERSION_BUILD #x0001) (defglobalconstant PC_KERNEL_VERSION_REVISION #x0005) -(defglobalconstant PC_KERNEL_VERSION_MINOR #x0004) +(defglobalconstant PC_KERNEL_VERSION_MINOR #x0005) (defglobalconstant PC_KERNEL_VERSION_MAJOR #x0001) (defglobalconstant PC_KERNEL_VERSION (logior (ash PC_KERNEL_VERSION_MAJOR 48) @@ -213,6 +213,7 @@ (letterbox? symbol) ;; letterbox. #f = stretched (vsync? symbol) ;; vsync. (font-scale float) ;; font scaling. + (window-lock? symbol) ;; whether the window can be resized by the user or not. ;; debug settings (os symbol) ;; windows, linux, macos @@ -320,6 +321,7 @@ (set-size! (_type_ int int) none) (set-aspect! (_type_ int int) none) (set-aspect-ratio! (_type_ float) none) + (set-window-lock! (_type_ symbol) symbol) (read-from-file (_type_ string) symbol) (write-to-file (_type_ string) symbol) (update-cheats (_type_) int) @@ -389,9 +391,10 @@ (set! (-> obj mood-override?) #f) (set! (-> obj movie?) #f) (set! (-> obj font-scale) 1.0) - (set! (-> obj aspect-custom-x) 1) - (set! (-> obj aspect-custom-y) 1) + (set! (-> obj aspect-custom-x) 4) + (set! (-> obj aspect-custom-y) 3) (set! (-> obj discord-rpc?) #t) + (set! (-> obj window-lock?) #t) (reset-gfx obj) (reset-audio obj) diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index 7ec1b6ba84..431d0af1ff 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -91,6 +91,11 @@ (set! (-> obj aspect-ratio-reciprocal) (/ ASPECT_4X3 aspect)) (none)) +(defmethod set-window-lock! pc-settings ((obj pc-settings) (lock symbol)) + "set the aspect ratio used for rendering." + (pc-set-window-lock lock) + (set! (-> obj window-lock?) lock)) + (defmethod commit-to-file pc-settings ((obj pc-settings)) "commits the current settings to the file" ;; auto load settings if available @@ -157,6 +162,7 @@ (pc-set-fullscreen (-> obj display-mode) 0) (if (and (= 'windowed (-> obj display-mode)) + (-> obj window-lock?) (or (!= (-> obj win-width) (-> obj real-width)) (!= (-> obj win-height) (-> obj real-height)))) (pc-set-window-size (max 320 (-> obj win-width)) (max 240 (-> obj win-height))))