Skip to content

Commit

Permalink
Lower fps to 10 if program is in background to reduce CPU/GPU load an…
Browse files Browse the repository at this point in the history
…d save energy
  • Loading branch information
mbrlabs committed Jun 11, 2021
1 parent 17b133d commit a29fb45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

### Changed
- Disabled VSync and set the fixed target FPS to 144, which results in much smoother brush strokes and a better feeling on low Hz monitors
- Lower the FPS to 10 if the window is unfocused to reduce the CPU/GPU load and save energy

## [0.2.0] - 2021-06-03

Expand Down
14 changes: 10 additions & 4 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends Control

const TARGET_FPS_FOREGROUND := 144
const TARGET_FPS_BACKGROUND := 10

# -------------------------------------------------------------------------------------------------
onready var _canvas: InfiniteCanvas = $InfiniteCanvas
onready var _statusbar: Statusbar = $Statusbar
Expand Down Expand Up @@ -69,12 +72,15 @@ func _notification(what):
else:
get_tree().quit()

elif NOTIFICATION_WM_FOCUS_IN == what && _canvas != null:
if !_is_mouse_on_ui():
elif NOTIFICATION_WM_FOCUS_IN == what:
Engine.target_fps = TARGET_FPS_FOREGROUND
if !_is_mouse_on_ui() && _canvas != null:
yield(get_tree().create_timer(0.12), "timeout")
_canvas.enable()
elif NOTIFICATION_WM_FOCUS_OUT == what && _canvas != null:
_canvas.disable()
elif NOTIFICATION_WM_FOCUS_OUT == what:
Engine.target_fps = TARGET_FPS_BACKGROUND
if _canvas != null:
_canvas.disable()

# -------------------------------------------------------------------------------------------------
func _exit_tree():
Expand Down

0 comments on commit a29fb45

Please sign in to comment.