Add debug tools for FPS
This commit is contained in:
parent
d9e5ce4a61
commit
06542eed2c
|
@ -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 )
|
|
@ -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))
|
Binary file not shown.
Binary file not shown.
|
@ -59,6 +59,11 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://addons/dialogic/Other/DialogicUtil.gd"
|
||||
}, {
|
||||
"base": "CanvasLayer",
|
||||
"class": "FpsLabel",
|
||||
"language": "GDScript",
|
||||
"path": "res://FPSLabel.gd"
|
||||
}, {
|
||||
"base": "PanelContainer",
|
||||
"class": "HistoryRow",
|
||||
"language": "GDScript",
|
||||
|
@ -75,6 +80,7 @@ _global_script_class_icons={
|
|||
"DialogicParser": "",
|
||||
"DialogicResources": "",
|
||||
"DialogicUtil": "",
|
||||
"FpsLabel": "",
|
||||
"HistoryRow": ""
|
||||
}
|
||||
|
||||
|
@ -88,6 +94,7 @@ config/icon="res://meat_madness_icon.png"
|
|||
Util="*res://util.gd"
|
||||
GlobalEventBus="*res://global_event_bus.gd"
|
||||
SavedDialogueProgress="*res://saved_dialogue_progress.gd"
|
||||
DebugTools="*res://DebugTools.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
Loading…
Reference in New Issue