49 lines
1.2 KiB
GDScript
49 lines
1.2 KiB
GDScript
extends Control
|
|
|
|
export var scale = 4 setget set_scale
|
|
export var upThreshold = 1.0/59.0
|
|
export var downThreshold = 1.0/30.0
|
|
|
|
export var delay = 1.0
|
|
|
|
onready var viewport = $Viewport
|
|
onready var background = $Background
|
|
|
|
func _ready():
|
|
set_scale(scale)
|
|
$"/root/Music/BGM".play()
|
|
|
|
func _process(delta):
|
|
# Give the system time to adjust
|
|
if delay > 0:
|
|
delay -= delta
|
|
return
|
|
if delta > downThreshold:
|
|
print("GPU is taking too much (", delta, "s < ", downThreshold, "s), adjusting shader scale")
|
|
set_scale(scale+1)
|
|
elif delta < upThreshold and scale > 2:
|
|
print("GPU is taking it easy (", delta, "s < ", upThreshold, "s), adjusting shader scale")
|
|
set_scale(scale-1)
|
|
|
|
func set_scale(val):
|
|
scale = val
|
|
if viewport:
|
|
viewport.size = rect_size / scale
|
|
background.update()
|
|
|
|
func _on_resized():
|
|
if viewport:
|
|
viewport.size = rect_size / scale
|
|
background.update()
|
|
|
|
func _host_pressed():
|
|
$"/root/Music/BGM".stop()
|
|
$"/root/Multiplayer".host()
|
|
|
|
func _join_pressed():
|
|
$"/root/Music/BGM".stop()
|
|
var addr = $CenterContainer/PanelContainer/HBoxContainer/ServerAddr
|
|
$"/root/Multiplayer".join(addr.text)
|
|
|
|
func _server_addr_changed(new_text: String):
|
|
$CenterContainer/PanelContainer/HBoxContainer/JoinButton.disabled = new_text.length() < 1
|