Module: Graphics
- Extended by:
- Hooks
- Includes:
- Hooks
- Defined in:
- scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb,
scripts/00700 Ajout_PSDK/00002 FPSBalancer.rb,
scripts/00700 Ajout_PSDK/00001 Graphics Icon.rb,
scripts/00700 Ajout_PSDK/00001 Graphics Debug.rb,
scripts/00700 Ajout_PSDK/00001 Graphics FPS+Mouse.rb
Overview
Module responsive of showing graphics into the main window
Defined Under Namespace
Classes: FPSBalancer
Constant Summary collapse
- TRANSITION_FRAG_SHADER =
Shader used to perform transition
<<~EOFRAGMENT uniform float param; uniform sampler2D texture; uniform sampler2D transition; uniform sampler2D nextFrame; const float sensibilite = 0.05; const float scale = 1.0 + sensibilite; void main() { vec4 frag = texture2D(texture, gl_TexCoord[0].xy); vec4 tran = texture2D(transition, gl_TexCoord[0].xy); float pixel = max(max(tran.r, tran.g), tran.b); pixel -= (param * scale); if(pixel < sensibilite) { vec4 nextFrag = texture2D(nextFrame, gl_TexCoord[0].xy); frag = mix(frag, nextFrag, max(0.0, sensibilite + pixel / sensibilite)); } gl_FragColor = frag; } EOFRAGMENT
- STATIC_TRANSITION_FRAG_SHADER =
Shader used to perform static transition
<<~EOFRAGMENT uniform float param; uniform sampler2D texture; uniform sampler2D nextFrame; void main() { vec4 frag = texture2D(texture, gl_TexCoord[0].xy); vec4 nextFrag = texture2D(nextFrame, gl_TexCoord[0].xy); frag = mix(frag, nextFrag, max(0.0, param)); gl_FragColor = frag; } EOFRAGMENT
Class Attribute Summary collapse
-
.current_time ⇒ Time
readonly
Get the current time.
-
.frame_count ⇒ Integer
Get the global frame count.
-
.frame_rate ⇒ Integer
Get the framerate.
-
.fullscreen_toggle_enabled
Tell if it is allowed to go fullscreen with ALT+ENTER.
-
.last_time ⇒ Time
readonly
Get the time when the last frame was executed.
-
.window ⇒ LiteRGSS::DisplayWindow
readonly
Get the game window.
Class Method Summary collapse
-
.brightness ⇒ Integer
Get the brightness of the main game window.
-
.brightness=(brightness)
Set the brightness of the main game window.
-
.delta ⇒ Float
Tell how much time there was since last frame.
-
.focus? ⇒ Boolean
Tell if the graphics window has focus.
-
.frame_reset
Reset frame counter (for FPS reason).
-
.freeze
Freeze the graphics.
-
.frozen? ⇒ Boolean
Tell if the graphics are frozen.
-
.height ⇒ Integer
Get the height of the graphics.
-
.init_sprite
Init the Sprite used by the Graphics module.
-
.load_icon
Load the window icon.
-
.on_start(&block)
Register an event on start of graphics.
- .original_swap_fullscreen
- .original_update
-
.register_viewport(viewport) ⇒ self
Register a viewport to the graphics (for special handling).
-
.reset_mouse_viewport
Function that resets the mouse viewport.
-
.resize_screen(width, height)
Resize the window screen.
- .screen_scale=(scale)
-
.shader ⇒ Shader
Get the shader of the graphics.
-
.shader=(shader)
Set the shader of the graphics.
-
.snap_to_bitmap ⇒ LiteRGSS::Bitmap
Snap the graphics to bitmap.
-
.sort_z
Sort the graphics in z.
-
.start
Start the graphics.
-
.stop
Stop the graphics.
-
.swap_fullscreen
Swap the fullscreen state.
-
.transition(frame_count_or_sec = 8, texture = nil)
Transition the graphics between a scene to another.
-
.unregitser_viewport(viewport) ⇒ self
Unregister a viewport.
-
.update
Update graphics window content & events.
-
.update_no_input
Update the graphics window content.
-
.update_only_input
Update the graphics window event without drawing anything.
-
.wait(frame_count_or_sec) { ... }
Make the graphics wait for an amout of time.
-
.width ⇒ Integer
Get the width of the graphics.
Methods included from Hooks
exec_hooks, force_return, included, register, remove, remove_without_name
Class Attribute Details
.current_time ⇒ Time (readonly)
Get the current time
35 36 37 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 35 def current_time @current_time end |
.frame_count ⇒ Integer
Get the global frame count
29 30 31 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 29 def frame_count @frame_count end |
.frame_rate ⇒ Integer
Get the framerate
32 33 34 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 32 def frame_rate @frame_rate end |
.fullscreen_toggle_enabled
Tell if it is allowed to go fullscreen with ALT+ENTER
40 41 42 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 40 def fullscreen_toggle_enabled @fullscreen_toggle_enabled end |
.last_time ⇒ Time (readonly)
Get the time when the last frame was executed
38 39 40 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 38 def last_time @last_time end |
.window ⇒ LiteRGSS::DisplayWindow (readonly)
Get the game window
26 27 28 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 26 def window @window end |
Class Method Details
.brightness ⇒ Integer
Get the brightness of the main game window
62 63 64 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 62 def brightness return window&.brightness || 0 end |
.brightness=(brightness)
Set the brightness of the main game window
68 69 70 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 68 def brightness=(brightness) window&.brightness = brightness end |
.delta ⇒ Float
Tell how much time there was since last frame
56 57 58 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 56 def delta return @current_time - @last_time end |
.focus? ⇒ Boolean
Tell if the graphics window has focus
44 45 46 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 44 def focus? return @has_focus end |
.frame_reset
Reset frame counter (for FPS reason)
269 270 271 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 269 def frame_reset exec_hooks(Graphics, :frame_reset, binding) end |
.freeze
Freeze the graphics
97 98 99 100 101 102 103 104 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 97 def freeze return unless @window @frozen_sprite.dispose if @frozen_sprite && !@frozen_sprite.disposed? @frozen_sprite = LiteRGSS::ShaderedSprite.new(window) @frozen_sprite.bitmap = snap_to_bitmap @frozen = 10 end |
.frozen? ⇒ Boolean
Tell if the graphics are frozen
50 51 52 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 50 def frozen? @frozen > 0 end |
.height ⇒ Integer
Get the height of the graphics
74 75 76 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 74 def height return window.height end |
.init_sprite
Init the Sprite used by the Graphics module
274 275 276 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 274 def init_sprite exec_hooks(Graphics, :init_sprite, binding) end |
.load_icon
Load the window icon
8 9 10 11 12 13 14 15 16 17 18 |
# File 'scripts/00700 Ajout_PSDK/00001 Graphics Icon.rb', line 8 def load_icon return unless RPG::Cache.icon_exist?('game') # @type [Yuki::VD, nil] windowskin_vd = RPG::Cache.instance_variable_get(:@icon_data) data = windowskin_vd&.read_data('game') # @type [Image] image = data ? Image.new(data, true) : Image.new('graphics/icons/game.png') window.icon = image image.dispose end |
.on_start(&block)
Register an event on start of graphics
246 247 248 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 246 def on_start(&block) @on_start << block end |
.original_swap_fullscreen
20 |
# File 'scripts/00700 Ajout_PSDK/00001 Graphics Icon.rb', line 20 alias original_swap_fullscreen swap_fullscreen |
.original_update
88 |
# File 'scripts/00700 Ajout_PSDK/00002 FPSBalancer.rb', line 88 alias original_update update |
.register_viewport(viewport) ⇒ self
Register a viewport to the graphics (for special handling)
253 254 255 256 257 258 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 253 def () return self unless .is_a?(Viewport) @viewports << unless @viewports.include?() return self end |
.reset_mouse_viewport
Function that resets the mouse viewport
4 5 6 |
# File 'scripts/00700 Ajout_PSDK/00001 Graphics FPS+Mouse.rb', line 4 def @mouse_fps_viewport&.rect&.set(0, 0, width, height) end |
.resize_screen(width, height)
Resize the window screen
109 110 111 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 109 def resize_screen(width, height) window&.resize_screen(width, height) end |
.screen_scale=(scale)
290 291 292 293 294 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 290 def screen_scale=(scale) settings = window.settings settings[3] = scale window.settings = settings end |
.shader ⇒ Shader
Get the shader of the graphics
86 87 88 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 86 def shader return window&.shader end |
.shader=(shader)
Set the shader of the graphics
92 93 94 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 92 def shader=(shader) window&.shader = shader end |
.snap_to_bitmap ⇒ LiteRGSS::Bitmap
Snap the graphics to bitmap
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 115 def snap_to_bitmap = .select(&:visible) tmp = LiteRGSS::Viewport.new(window, 0, 0, width, height) bk = Image.new(width, height) bk.fill_rect(0, 0, width, height, Color.new(0, 0, 0, 255)) sp = LiteRGSS::Sprite.new(tmp) sp.bitmap = LiteRGSS::Bitmap.new(width, height) bk.copy_to_bitmap(sp.bitmap) texture_to_dispose = .map do |vp| shader = vp.shader vp.shader = nil texture = vp.snap_to_bitmap vp.shader = shader sprite = LiteRGSS::ShaderedSprite.new(tmp) sprite.shader = shader sprite.bitmap = texture sprite.set_position(vp.rect.x, vp.rect.y) next texture end texture_to_dispose << bk texture_to_dispose << sp.bitmap result_texture = tmp.snap_to_bitmap texture_to_dispose.each(&:dispose) tmp.dispose return result_texture end |
.sort_z
Sort the graphics in z
279 280 281 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 279 def sort_z @window&.sort_z end |
.start
Start the graphics
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 143 def start return if @window @window = LiteRGSS::DisplayWindow.new( Configs.infos.game_title, *PSDK_CONFIG.choose_best_resolution, PSDK_CONFIG.window_scale, 32, 0, PSDK_CONFIG.vsync_enabled, PSDK_CONFIG.running_in_full_screen, !Configs.devices.mouse_skin ) @on_start.each(&:call) @on_start.clear @last_time = @current_time = Time.new Input.register_events(@window) Mouse.register_events(@window) @window.on_lost_focus = proc { @has_focus = false } @window.on_gained_focus = proc { @has_focus = true } @window.on_closed = proc do @window = nil next true end init_sprite end |
.stop
Stop the graphics
165 166 167 168 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 165 def stop window&.dispose @window = nil end |
.swap_fullscreen
Swap the fullscreen state
22 23 24 25 |
# File 'scripts/00700 Ajout_PSDK/00001 Graphics Icon.rb', line 22 def swap_fullscreen original_swap_fullscreen load_icon end |
.transition(frame_count_or_sec = 8, texture = nil)
Transition the graphics between a scene to another
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 173 def transition(frame_count_or_sec = 8, texture = nil) return unless @window exec_hooks(Graphics, :transition, binding) return if frame_count_or_sec <= 0 || !@frozen_sprite transition_internal(frame_count_or_sec, texture) exec_hooks(Graphics, :post_transition, binding) rescue Hooks::ForceReturn => e return e.data ensure @frozen_sprite&.bitmap&.dispose @frozen_sprite&.shader = nil @frozen_sprite&.dispose @frozen_sprite = nil @frozen = 0 end |
.unregitser_viewport(viewport) ⇒ self
Unregister a viewport
263 264 265 266 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 263 def () @viewports.delete() return self end |
.update
Update graphics window content & events. This method might wait for vsync before updating events
90 91 92 93 94 95 96 97 98 99 |
# File 'scripts/00700 Ajout_PSDK/00002 FPSBalancer.rb', line 90 def update FPSBalancer.global.update if FPSBalancer.global.skipping? && !frozen? && $scene.is_a?(FPSBalancer::Marker) fps_update if respond_to?(:fps_update, true) update_no_input fps_gpu_update if respond_to?(:fps_gpu_update, true) else original_update end end |
.update_no_input
Update the graphics window content. This method might wait for vsync before returning
210 211 212 213 214 215 216 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 210 def update_no_input return unless @window window.update_no_input @last_time = @current_time @current_time = Time.new end |
.update_only_input
Update the graphics window event without drawing anything.
219 220 221 222 223 224 225 226 227 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 219 def update_only_input return unless @window Input.swap_states Mouse.swap_states window.update_only_input @last_time = @current_time @current_time = Time.new end |
.wait(frame_count_or_sec) { ... }
Make the graphics wait for an amout of time
232 233 234 235 236 237 238 239 240 241 242 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 232 def wait(frame_count_or_sec) return unless @window total_time = frame_count_or_sec.is_a?(Float) ? frame_count_or_sec : frame_count_or_sec.to_f / frame_rate initial_time = Graphics.current_time next_time = initial_time + total_time while Graphics.current_time < next_time Graphics.update yield if block_given? end end |
.width ⇒ Integer
Get the width of the graphics
80 81 82 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Graphics.rb', line 80 def width return window.width end |