Created
December 16, 2018 22:32
-
-
Save Einlander/7c2fc9b6e77de7920a8d52817f972e4f to your computer and use it in GitHub Desktop.
Draws a Histogram of your last 300 fps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
# Declare memr variables here. Examples: | |
# var a = 2 | |
# var b = "text" | |
# Called when the node enters the scene tree for the first time. | |
var _fps_ticker_data = [] | |
var fpskeydown = false | |
export var draw_graph = false | |
func _ready(): | |
pass # Replace with function body. | |
func _draw(): | |
if draw_graph: | |
_setup_chart() | |
pass | |
# Called every frame. 'delta' is the elapsed time since the previous frame. | |
#func _process(delta): | |
# pass | |
func _input(event): | |
#print(!draw_graph) | |
#if (event.scancode == KEY_F10) == false: | |
# fpskeydown = false | |
# print("done") | |
pass | |
func _process(delta): | |
if Input.is_key_pressed(KEY_F10) == true and fpskeydown == false: | |
fpskeydown = true | |
_fps_ticker_data = [] | |
draw_graph = !draw_graph | |
print(!draw_graph) | |
if Input.is_key_pressed(KEY_F10) == false and fpskeydown == true: | |
fpskeydown = false | |
#draw_rect(Rect2(Vector2(0,0),Vector2(300,60)),Color(0,0,0)) | |
print("done") | |
update() | |
if draw_graph: | |
update() | |
pass | |
func _setup_chart(): | |
for i in range(6): | |
draw_line(Vector2(60 * i,0),Vector2(60*i,60),Color.gray) | |
pass | |
draw_line(Vector2(0,30),Vector2(300,30),Color.yellow) | |
draw_line(Vector2(0,60),Vector2(300,60),Color.red) | |
_fps_ticker_data.append(Engine.get_frames_per_second()) | |
if _fps_ticker_data.size() > 300: | |
_fps_ticker_data.pop_front() | |
for i in range(1,_fps_ticker_data.size()): | |
draw_line(Vector2(i-1, 60 - _fps_ticker_data[i-1]+1),Vector2(i,60-_fps_ticker_data[i]+1),Color.cyan) | |
#draw_line(Vector2(i+1, 60 - _fps_ticker_data[i]+2),Vector2(i+1,60-_fps_ticker_data[i]+2),Color.white) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment