feat: fps counter and limiter

This commit is contained in:
DottsGit
2026-06-06 01:06:43 -04:00
parent 33f5c7cb82
commit 6dceab46db
3 changed files with 211 additions and 3 deletions
+46 -1
View File
@@ -26,6 +26,22 @@ var current_bindings = {}
var show_debug_ui: bool = false
var mouse_sensitivity: float = 0.002
# Video Settings
var display_mode: int = DisplayServer.WINDOW_MODE_WINDOWED
var resolution_index: int = 2 # Default to 1920x1080
var fps_cap: int = 0
var show_fps: bool = false
var resolutions = [
Vector2i(640, 480), # 480p
Vector2i(1280, 720), # 720p
Vector2i(1920, 1080), # 1080p
Vector2i(2560, 1080), # UW-1080p
Vector2i(2560, 1440), # 1440p
Vector2i(3440, 1440), # UW-1440p
Vector2i(3840, 2160) # 4K
]
func _ready() -> void:
# Initialize defaults
current_bindings = default_bindings.duplicate(true)
@@ -35,6 +51,9 @@ func _ready() -> void:
# Apply to InputMap
_apply_all_bindings()
# Apply Video Settings
apply_video_settings()
func _apply_all_bindings() -> void:
for action in current_bindings:
@@ -78,7 +97,11 @@ func _save_settings() -> void:
var save_data = {
"bindings": current_bindings,
"show_debug_ui": show_debug_ui,
"mouse_sensitivity": mouse_sensitivity
"mouse_sensitivity": mouse_sensitivity,
"display_mode": display_mode,
"resolution_index": resolution_index,
"fps_cap": fps_cap,
"show_fps": show_fps
}
var json_string = JSON.stringify(save_data)
var file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
@@ -107,3 +130,25 @@ func _load_settings() -> void:
show_debug_ui = data["show_debug_ui"]
if data.has("mouse_sensitivity"):
mouse_sensitivity = data["mouse_sensitivity"]
if data.has("display_mode"): display_mode = data["display_mode"]
if data.has("resolution_index"): resolution_index = data["resolution_index"]
if data.has("fps_cap"): fps_cap = data["fps_cap"]
if data.has("show_fps"): show_fps = data["show_fps"]
func apply_video_settings() -> void:
if display_mode == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
elif display_mode == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
if resolution_index >= 0 and resolution_index < resolutions.size():
DisplayServer.window_set_size(resolutions[resolution_index])
# Center window on primary screen
var screen = DisplayServer.window_get_current_screen()
var screen_size = DisplayServer.screen_get_size(screen)
var window_size = DisplayServer.window_get_size()
# Simple centering heuristic
DisplayServer.window_set_position((screen_size - window_size) / 2)
Engine.max_fps = fps_cap