Add debug tools for FPS

This commit is contained in:
Spencer Killen 2022-12-30 11:56:41 -07:00
parent d9e5ce4a61
commit 06542eed2c
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
5 changed files with 61 additions and 0 deletions

9
godot/DebugTools.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://FPSLabel.gd" type="Script" id=1]
[node name="DebugTools" type="Spatial"]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 128
script = ExtResource( 1 )

45
godot/FPSLabel.gd Normal file
View File

@ -0,0 +1,45 @@
# MIT License
# Copyright (c) 2019 Lupo Dharkael
class_name FpsLabel
extends CanvasLayer
enum Position {TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, NONE}
export (Position) var position = Position.TOP_LEFT
export(int) var margin : int = 5
var label : Label
func _ready() -> void:
label = Label.new()
add_child(label)
get_tree().get_root().connect("size_changed", self, "update_position")
update_position()
# pos should be of type Position
func set_position(pos : int):
position = pos
update_position()
func update_position():
var viewport_size : Vector2 = get_viewport().size
var label_size : Vector2 = label.rect_size
match position:
Position.TOP_LEFT:
offset = Vector2(margin, margin)
Position.BOTTOM_LEFT:
offset = Vector2(margin, viewport_size.y - margin - label_size.y)
Position.TOP_RIGHT:
offset = Vector2(viewport_size.x - margin - label_size.x, margin)
Position.BOTTOM_RIGHT:
offset = Vector2(viewport_size.x - margin - label_size.x, viewport_size.y - margin - label_size.y)
func _process(_delta : float) -> void:
label.text = "fps: " + str(Engine.get_frames_per_second()) + " " + str(Performance.get_monitor(Performance.TIME_FPS))

View File

@ -59,6 +59,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://addons/dialogic/Other/DialogicUtil.gd" "path": "res://addons/dialogic/Other/DialogicUtil.gd"
}, { }, {
"base": "CanvasLayer",
"class": "FpsLabel",
"language": "GDScript",
"path": "res://FPSLabel.gd"
}, {
"base": "PanelContainer", "base": "PanelContainer",
"class": "HistoryRow", "class": "HistoryRow",
"language": "GDScript", "language": "GDScript",
@ -75,6 +80,7 @@ _global_script_class_icons={
"DialogicParser": "", "DialogicParser": "",
"DialogicResources": "", "DialogicResources": "",
"DialogicUtil": "", "DialogicUtil": "",
"FpsLabel": "",
"HistoryRow": "" "HistoryRow": ""
} }
@ -88,6 +94,7 @@ config/icon="res://meat_madness_icon.png"
Util="*res://util.gd" Util="*res://util.gd"
GlobalEventBus="*res://global_event_bus.gd" GlobalEventBus="*res://global_event_bus.gd"
SavedDialogueProgress="*res://saved_dialogue_progress.gd" SavedDialogueProgress="*res://saved_dialogue_progress.gd"
DebugTools="*res://DebugTools.tscn"
[display] [display]