From 319e17d711fd1c0285ec27143dfa923179418fef Mon Sep 17 00:00:00 2001 From: Issac332 <119879937+Issac8658@users.noreply.github.com> Date: Tue, 14 Jul 2026 18:03:52 +0300 Subject: [PATCH] dynamic resolution --- binding-mri/graphics-binding.cpp | 31 ++++++++++++++++-- binding-mri/oneshot-binding.cpp | 9 ++++++ changelogs/0.1.1.txt | 4 ++- scripts/Data_Settings_Classes.rb | 3 +- scripts/DynamicLight.rb | 2 +- scripts/Game_Player.rb | 32 ++++++++++++------- scripts/Puzzle_Film.rb | 2 ++ scripts/Spriteset_Map.rb | 2 +- scripts/Window_Help.rb | 11 +++++++ scripts/Window_Item.rb | 5 +++ scripts/Window_MainMenu.rb | 9 ++++++ scripts/Window_Message.rb | 3 +- scripts/Window_Settings.rb | 54 ++++++++++++++++++++++++++------ src/graphics.cpp | 6 ++-- src/graphics.h | 2 +- src/oneshot.cpp | 12 +++---- src/oneshot.h | 3 +- src/sharedstate.h | 1 + 18 files changed, 152 insertions(+), 39 deletions(-) diff --git a/binding-mri/graphics-binding.cpp b/binding-mri/graphics-binding.cpp index 176a0ea..7d60359 100644 --- a/binding-mri/graphics-binding.cpp +++ b/binding-mri/graphics-binding.cpp @@ -173,9 +173,10 @@ RB_METHOD(graphicsResizeScreen){ RB_UNUSED_PARAM; int width, height; - rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END); + bool emitSignal = true; + rb_get_args(argc, argv, "ii|b", &width, &height, &emitSignal RB_ARG_END); - shState->graphics().resizeScreen(width, height); + shState->graphics().resizeScreen(width, height, emitSignal); return Qnil; } @@ -218,6 +219,11 @@ static VALUE graphicsWindowMoved(VALUE self){ RUBY_CONNECTION conn->connection = shState->windowSignals.moved.Connect([conn](int x, int y){ shState->rubyDispatcher().invoke([conn, x, y]{ + if (NIL_P(conn->proc)){ + Debug() << "Unable to call non-existent proc! (Graphics.window_moved connection, disconnecting)"; + conn->connection.Disconnect(); + return; + } rb_funcall(conn->proc, rb_intern("call"), 2, INT2NUM(x), INT2NUM(y)); }); }); @@ -228,12 +234,32 @@ static VALUE graphicsWindowResized(VALUE self){ RUBY_CONNECTION conn->connection = shState->windowSignals.resized.Connect([conn](int w, int h){ shState->rubyDispatcher().invoke([conn, w, h]{ + if (NIL_P(conn->proc)){ + Debug() << "Unable to call non-existent proc! (Graphics.window_resized connection, disconnecting)"; + conn->connection.Disconnect(); + return; + } rb_funcall(conn->proc, rb_intern("call"), 2, INT2NUM(w), INT2NUM(h)); }); }); return TypedData_Wrap_Struct(rb_cRubyConnection, &rubyConnection_type, conn); } +static VALUE graphicsViewportResized(VALUE self){ + RUBY_CONNECTION + conn->connection = shState->graphicsSignals.resized.Connect([conn](int w, int h){ + //shState->rubyDispatcher().invoke([conn, w, h]{ + if (NIL_P(conn->proc)){ + Debug() << "Unable to call non-existent proc! (Graphics.viewport_resized connection, disconnecting)"; + conn->connection.Disconnect(); + return; + } + rb_funcall(conn->proc, rb_intern("call"), 2, INT2NUM(w), INT2NUM(h)); + //}); + }); + return TypedData_Wrap_Struct(rb_cRubyConnection, &rubyConnection_type, conn); +} + void graphicsBindingInit(){ VALUE module = rb_define_module("Graphics"); @@ -241,6 +267,7 @@ void graphicsBindingInit(){ rb_define_module_function(module, "window_moved", RUBY_METHOD_FUNC(graphicsWindowMoved), 0); rb_define_module_function(module, "window_resized", RUBY_METHOD_FUNC(graphicsWindowResized), 0); + rb_define_module_function(module, "viewport_resized", RUBY_METHOD_FUNC(graphicsViewportResized), 0); // Functions _rb_define_module_function(module, "x", graphicsPosX); diff --git a/binding-mri/oneshot-binding.cpp b/binding-mri/oneshot-binding.cpp index ae01836..5133899 100644 --- a/binding-mri/oneshot-binding.cpp +++ b/binding-mri/oneshot-binding.cpp @@ -92,6 +92,13 @@ RB_METHOD(oneshotCRC32){ return UINT2NUM(result.checksum()); } +static VALUE oneshotSetObscuredUpdating(VALUE self, VALUE rb_bool){ + bool value; + rb_bool_arg(rb_bool, &value); + shState->oneshot().setObscuredUpdating(value); + return Qnil; +} + void oneshotBindingInit(){ VALUE module = rb_define_module("Oneshot"); VALUE msg = rb_define_module_under(module, "Msg"); @@ -122,4 +129,6 @@ void oneshotBindingInit(){ _rb_define_module_function(module, "exiting", oneshotExiting); _rb_define_module_function(module, "shake", oneshotShake); _rb_define_module_function(module, "crc32", oneshotCRC32); + + rb_define_module_function(module, "obscured_updating=", RUBY_METHOD_FUNC(oneshotSetObscuredUpdating), 1); } diff --git a/changelogs/0.1.1.txt b/changelogs/0.1.1.txt index 3b07878..916f1f4 100644 --- a/changelogs/0.1.1.txt +++ b/changelogs/0.1.1.txt @@ -62,4 +62,6 @@ SecurityManager can detect Flatpak and Snap now Added 3:2 support Modloader settings supported gamepads can now change LED color based on map -sigc is wrapped in signal.h, added the ability to move window from ruby \ No newline at end of file +sigc is wrapped in signal.h, added the ability to move window from ruby +main viewport resize, main window resize and move signals bindings for ruby +Dynamic resolution support (WIP) \ No newline at end of file diff --git a/scripts/Data_Settings_Classes.rb b/scripts/Data_Settings_Classes.rb index ed3bf75..ebc1278 100644 --- a/scripts/Data_Settings_Classes.rb +++ b/scripts/Data_Settings_Classes.rb @@ -37,7 +37,6 @@ class Window_Settings @selection_sprite.bitmap.fill_rect(Rect.new(0, 0, PARAMETER_WIDTH + 16, PARAMETER_HEIGHT), Color.new(255, 255, 255, 64)) @selection_sprite.x = @x - 8 @selection_sprite.y = @offset - @selection_sprite.opacity = 0 @selection_sprite.blend_type = 1 @selection_sprite.z = 1 @@ -82,6 +81,8 @@ class Window_Settings @screen_panels.each do |screen_panel| screen_panel.dispose end + @switch_panels_hint_left.dispose + @switch_panels_hint_right.dispose end # registering diff --git a/scripts/DynamicLight.rb b/scripts/DynamicLight.rb index bc6560c..35fec7a 100644 --- a/scripts/DynamicLight.rb +++ b/scripts/DynamicLight.rb @@ -16,7 +16,7 @@ class DynamicLight # end #end - @update_connection = Graphics.window_resized do |w, h| + @update_connection = Graphics.viewport_resized do |w, h| @debug_sprite.bitmap.rect.width = w; @debug_sprite.bitmap.rect.height = h; #@debug_sprite.bitmap.dispose diff --git a/scripts/Game_Player.rb b/scripts/Game_Player.rb index 5c71efe..4dc443e 100644 --- a/scripts/Game_Player.rb +++ b/scripts/Game_Player.rb @@ -9,11 +9,11 @@ class Game_Player < Game_Character attr_reader :move_speed - #-------------------------------------------------------------------------- - # * Invariables - #-------------------------------------------------------------------------- - CENTER_X = ((Graphics.width / 2) - 16) * 4 # Center screen x-coordinate * 4 - CENTER_Y = ((Graphics.height / 2) - 16) * 4 # Center screen y-coordinate * 4 + def initialize + @center_x = ((Graphics.width / 2) - 16) * 4 # Center screen x-coordinate * 4 + @center_y = ((Graphics.height / 2) - 16) * 4 # Center screen y-coordinate * 4 + super + end #-------------------------------------------------------------------------- # * Passable Determinants # x : x-coordinate @@ -41,8 +41,8 @@ class Game_Player < Game_Character def center(x, y) max_x = ($game_map.width - (Graphics.width / 32)) * 128 max_y = ($game_map.height - (Graphics.height / 28)) * 128 - $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max - $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max + $game_map.display_x = [0, [x * 128 - @center_x, max_x].min].max + $game_map.display_y = [0, [y * 128 - @center_y, max_y].min].max end #-------------------------------------------------------------------------- # * Move to Designated Position @@ -164,6 +164,16 @@ class Game_Player < Game_Character # * Frame Update #-------------------------------------------------------------------------- def update + old_center_x = @center_x + old_center_y = @center_y + @center_x = ((Graphics.width / 2) - 16) * 4 # Center screen x-coordinate * 4 + @center_y = ((Graphics.height / 2) - 16) * 4 # Center screen y-coordinate * 4 + if (@center_x != old_center_x) + $game_map.display_x = @real_x - @center_x + end + if (@center_y != old_center_y) + $game_map.display_y = @real_y - @center_y + end # Remember whether or not moving in local variables last_moving = moving? # If moving, event running, move route forcing, and message window @@ -217,25 +227,25 @@ class Game_Player < Game_Character if !$game_switches[100] # If character moves down and is positioned lower than the center # of the screen - if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y + if @real_y > last_real_y and @real_y - $game_map.display_y > @center_y # Scroll map down $game_map.scroll_down(@real_y - last_real_y) end # If character moves left and is positioned more let on-screen than # center - if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X + if @real_x < last_real_x and @real_x - $game_map.display_x < @center_x # Scroll map left $game_map.scroll_left(last_real_x - @real_x) end # If character moves right and is positioned more right on-screen than # center - if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X + if @real_x > last_real_x and @real_x - $game_map.display_x > @center_x # Scroll map right $game_map.scroll_right(@real_x - last_real_x) end # If character moves up and is positioned higher than the center # of the screen - if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y + if @real_y < last_real_y and @real_y - $game_map.display_y < @center_y # Scroll map up $game_map.scroll_up(last_real_y - @real_y) end diff --git a/scripts/Puzzle_Film.rb b/scripts/Puzzle_Film.rb index 51de2c9..4a86ffb 100644 --- a/scripts/Puzzle_Film.rb +++ b/scripts/Puzzle_Film.rb @@ -6,9 +6,11 @@ def film_puzzle_begin filmsprite.z = 9999 filmsprite.obscured = true $game_temp.filmsprite = filmsprite + Oneshot.obscured_updating = true end def film_puzzle_end + Oneshot.obscured_updating = false $game_temp.filmsprite.dispose if $game_temp.filmsprite $game_temp.filmsprite = nil end diff --git a/scripts/Spriteset_Map.rb b/scripts/Spriteset_Map.rb index 6d3813c..c7d9be9 100644 --- a/scripts/Spriteset_Map.rb +++ b/scripts/Spriteset_Map.rb @@ -19,7 +19,7 @@ class Spriteset_Map @viewport_lights = Viewport.new(0, 0, Graphics.width, Graphics.height) @viewport_flash = Viewport.new(0, 0, Graphics.width, Graphics.height) - @update_connection = Graphics.window_resized do |w, h| + @update_connection = Graphics.viewport_resized do |w, h| @viewport.rect.width = w @viewport.rect.height = h diff --git a/scripts/Window_Help.rb b/scripts/Window_Help.rb index b6dee63..a63765c 100644 --- a/scripts/Window_Help.rb +++ b/scripts/Window_Help.rb @@ -15,6 +15,12 @@ class Window_Help < Window_Base self.visible = false self.back_opacity = 230 self.z = 9998 + + @update_connection = Graphics.viewport_resized do |w, h| + self.x = Graphics.width / 2 - 304 + self.y = Graphics.height > 600 ? Graphics.height / 2 - 160 : 16 + end + RPG::Mod.exec_hooks("hooks/Window_Help/init", binding) end #-------------------------------------------------------------------------- @@ -31,4 +37,9 @@ class Window_Help < Window_Base @align = align @actor = nil end + + def dispose + super + @update_connection.disconnect + end end diff --git a/scripts/Window_Item.rb b/scripts/Window_Item.rb index 897268b..f499b8a 100644 --- a/scripts/Window_Item.rb +++ b/scripts/Window_Item.rb @@ -20,6 +20,10 @@ class Window_Item < Window_Selectable self.z = 9998 self.visible = false self.active = false + @update_connection = Graphics.viewport_resized do |w, h| + self.x = w / 2 - 304 + self.y = h > 600 ? h / 2 - 80 : 96 + end @fade_in = false @fade_out = false @@ -230,5 +234,6 @@ class Window_Item < Window_Selectable def dispose super @help_window.dispose + @update_connection.disconnect end end diff --git a/scripts/Window_MainMenu.rb b/scripts/Window_MainMenu.rb index 843ee8f..1abd36c 100644 --- a/scripts/Window_MainMenu.rb +++ b/scripts/Window_MainMenu.rb @@ -2,6 +2,10 @@ class Window_MainMenu < Window_Selectable def initialize super(Graphics.width / 2 - 304, 16, 608, 64) + + @update_connection = Graphics.viewport_resized do |w, h| + self.x = w / 2 - 304 + end # Set up menu options @commands = Array.new @@ -158,4 +162,9 @@ class Window_MainMenu < Window_Selectable return end end + + def dispose + super + @update_connection.disconnect + end end diff --git a/scripts/Window_Message.rb b/scripts/Window_Message.rb index bfb8d9e..03f52d5 100644 --- a/scripts/Window_Message.rb +++ b/scripts/Window_Message.rb @@ -18,7 +18,7 @@ class Window_Message < Window_Selectable self.z = 9999 self.back_opacity = 210 - @update_connection = Graphics.window_resized do |w, h| + @update_connection = Graphics.viewport_resized do |w, h| self.x = Graphics.width / 2 - 304 case $game_system.message_position when 0 # up @@ -60,6 +60,7 @@ class Window_Message < Window_Selectable # * Dispose #-------------------------------------------------------------------------- def dispose + @update_connection.disconnect terminate_message $game_temp.message_window_showing = false if @input_number_window != nil diff --git a/scripts/Window_Settings.rb b/scripts/Window_Settings.rb index a72b180..e35d49f 100644 --- a/scripts/Window_Settings.rb +++ b/scripts/Window_Settings.rb @@ -21,6 +21,39 @@ class Window_Settings @title.opacity = 0 Language.register_text_sprite(self.class.name + "_title", @title) + @resized = false + + @update_connection = Graphics.viewport_resized do |w, h| + if self.visible + @viewport.rect.width = w + @viewport.rect.height = h + @bg.bitmap.dispose + @bg.bitmap = Bitmap.new(w, h) + @bg.bitmap.fill_rect(0, 0, w, h, Color.new(0, 0, 0, 196)) + @title.x = (w - @title.bitmap.width) / 2 + init_content + else + @resized = true + end + end + + init_content + + @left_hold_timer = 0 + @right_hold_timer = 0 + + @up_hold_timer = 0 + @down_hold_timer = 0 + + @visible = self.visible = false + RPG::Mod.exec_hooks("hooks/Window_Settings/init", binding) + end + + def init_content + if (@content) + @content.dispose + end + @content = SettingsContent.new(@viewport, TITLE_TOP_MARGIN + TITLE_MARGIN + 100) DATA.each_with_index do |(screen_title, parameters_info), screen_index| @@ -66,21 +99,13 @@ class Window_Settings end end @content.redraw_all - - @left_hold_timer = 0 - @right_hold_timer = 0 - - @up_hold_timer = 0 - @down_hold_timer = 0 - - @visible = self.visible = false - RPG::Mod.exec_hooks("hooks/Window_Settings/init", binding) end def dispose @bg.dispose @title.dispose @content.dispose + @update_connection.disconnect end def open @@ -102,6 +127,17 @@ class Window_Settings end def update + if @resized + @viewport.rect.width = Graphics.width + @viewport.rect.height = Graphics.height + @bg.bitmap.dispose + @bg.bitmap = Bitmap.new(Graphics.width, Graphics.height) + @bg.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0, 196)) + @title.x = (Graphics.width - @title.bitmap.width) / 2 + init_content + @resized = false + end + if Input.key_press?(Input.key_from_name("F1")) if Oneshot.msgbox(Oneshot::Msg::YESNO, tr("Are you sure you want to reset the control settings?")) Settings.reset_controls! diff --git a/src/graphics.cpp b/src/graphics.cpp index 3d9df5f..b4bb164 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -645,8 +645,6 @@ void Graphics::update(bool limitFps){ return; } - shState->oneshot().update(); - p->checkResize(); p->redrawScreen(); p->scPos = shState->rtData().ethread->getWindowPosition(); @@ -888,7 +886,7 @@ void Graphics::moveScreen(int x, int y){ shState->eThread().requestWindowMove(x, y); } -void Graphics::resizeScreen(int width, int height){ +void Graphics::resizeScreen(int width, int height, bool emitSignal){ width = clamp(width, 1, 65000); height = clamp(height, 1, 65000); @@ -908,6 +906,8 @@ void Graphics::resizeScreen(int width, int height){ glState.scissorBox.set(IntRect(0, 0, width, height)); shState->eThread().requestWindowResize(width, height); + if (emitSignal) + shState->graphicsSignals.resized.Emit(width, height); } DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) diff --git a/src/graphics.h b/src/graphics.h index 0948aa1..2e18885 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -53,7 +53,7 @@ public: int y() const; int width() const; int height() const; - void resizeScreen(int width, int height); + void resizeScreen(int width, int height, bool emitSignal = true); void moveScreen(int x, int y); void reset(); diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 38d8104..1ad6df7 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -360,11 +360,6 @@ Oneshot::~Oneshot() delete p; } -void Oneshot::update() -{ - p->obscuredNeedToUpdate = true; -} - const std::string &Oneshot::os() const { return p->os; @@ -589,11 +584,16 @@ std::string Oneshot::textinput(const char *prompt, int char_limit, const char *f return threadData.inputText; } +void Oneshot::setObscuredUpdating(bool enabled){ + p->obscuredNeedToUpdate = enabled; +} + void Oneshot::updateObscured(int winX, int winY) { + SDL_LockMutex(p->winMutex); p->winX = winX; p->winY = winY; - + SDL_UnlockMutex(p->winMutex); if (!p->obscuredNeedToUpdate) return; // Map of unobscured pixels in this frame diff --git a/src/oneshot.h b/src/oneshot.h index 3d1ee7e..607ce86 100644 --- a/src/oneshot.h +++ b/src/oneshot.h @@ -42,8 +42,6 @@ public: GRADIENT_VERTICAL, }; - void update(); - //Accessors const std::string &os() const; const std::string &lang() const; @@ -61,6 +59,7 @@ public: void setYesNo(const char *yes, const char *no); void setExiting(bool exiting); void setAllowExit(bool allowExit); + void setObscuredUpdating(bool enabled); void updateObscured(int winX, int winY); void resetObscured(); diff --git a/src/sharedstate.h b/src/sharedstate.h index e4f7a7f..9a46670 100644 --- a/src/sharedstate.h +++ b/src/sharedstate.h @@ -64,6 +64,7 @@ struct WindowSignals{ struct GraphicsSignals{ Signal prepareDraw; + Signal resized; }; struct SharedState{