Skip to content

Commit

Permalink
Adaptive FPS
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Sep 21, 2024
1 parent fbd62e6 commit a544a70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const PALETTES_PATH := "user://palettes.cfg"
const STATE_PATH := "user://state.cfg"
const MAX_PALETTE_SIZE := 40
const MIN_PALETTE_SIZE := 1
const BACKGROUND_IDLE_TIME_THRESHOLD := 250 # in ms
const MIN_WINDOW_SIZE := Vector2(320, 256)
const DEFAULT_CANVAS_COLOR := Color("202124")
const DEFAULT_BRUSH_COLOR := Color.WHITE
Expand Down
10 changes: 10 additions & 0 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extends Control
@onready var _edit_palette_window: Window = $EditPaletteWindow
@onready var _edit_palette_dialog: EditPaletteDialog = $EditPaletteWindow/EditPaletteDialog

var _last_input_time := 0
var _ui_visible := true
var _exit_requested := false
var _dirty_project_to_close: Project = null
Expand Down Expand Up @@ -122,6 +123,11 @@ func _exit_tree() -> void:

# -------------------------------------------------------------------------------------------------
func _process(delta: float) -> void:
# Lower fps if user is idle
if (Time.get_ticks_msec() - _last_input_time) > Config.BACKGROUND_IDLE_TIME_THRESHOLD:
Engine.max_fps = Settings.get_value(Settings.RENDERING_BACKGROUND_FPS, Config.DEFAULT_BACKGROUND_FPS)

# Upate statusbar
_statusbar.set_stroke_count(_canvas.info.stroke_count)
_statusbar.set_point_count(_canvas.info.point_count)
_statusbar.set_pressure(_canvas.info.current_pressure)
Expand All @@ -136,6 +142,10 @@ func _process(delta: float) -> void:

# -------------------------------------------------------------------------------------------------
func _unhandled_input(event: InputEvent) -> void:
# Idle time over; let's set the fps high again
_last_input_time = Time.get_ticks_msec()
Engine.max_fps = Settings.get_value(Settings.RENDERING_FOREGROUND_FPS, Config.DEFAULT_FOREGROUND_FPS)

if !is_dialog_open():
if Utils.is_action_pressed("toggle_player", event):
_toggle_player()
Expand Down

0 comments on commit a544a70

Please sign in to comment.