CORE/misc.gd
JeremyStarTM 99703cf03e CORE rewrite (#1)
Reviewed-on: StarOpenSource/core#1

Rewrote CORE and improved the startup process and startup time significantly. The documentation has been beefed up too and is now much better. Existing projects may need major refactoring however.
Co-authored-by: JeremyStarTM <jeremystartm@staropensource.de>
Co-committed-by: JeremyStarTM <jeremystartm@staropensource.de>
2023-08-25 14:34:57 +02:00

68 lines
2 KiB
GDScript

######################################
# THE CORE FRAMEWORK #
# MADE BY THE STAROPENSOURCE PROJECT #
# AND CONTRIBUTERS (THANK YOU!) #
# #
# COPYRIGHT 2023 THE STAROPENSOURCE #
# PROJECT AND CONTRIBUTERS #
# #
# LICENSED UNDER THE GNU GENERAL #
# PUBLIC LICENSE VERSION 3 (ONLY) #
######################################
extends Node
# CORE modules
var core: Node = null
# Delta value, used for get_fps() and get_delta()
var delta: float = 0.0
# Updates delta variable
func _process(delta_process) -> void:
delta = delta_process
# Returns the title of the main window
## Included as DisplayServer.window_get_title() (for some
## reason) does not exist and not many know that /root/
## is a Window node (which does have a "title" variable)
func get_title() -> String:
if core.protection_mode: return ""
return get_tree().root.title
# Returns the current FPS (Frames Per Second) value
func get_fps(flatten:bool = false) -> float:
if core.protection_mode: return 0.0
if str(delta) == "0":
# In the rare case where delta is zero, return INF
return INF
else:
if flatten:
# Removes decimal numbers
return float(int(1/delta))
else:
# Yes, it's weird but 1/delta does return the FPS value.
return 1/delta
# Returns the time it took Godot to render a frame
func get_rendertime() -> float:
if core.protection_mode: return 0.0
return Performance.get_monitor(Performance.TIME_PROCESS)
# Returns the delta time
func get_delta() -> float:
if core.protection_mode: return 0.0
return delta
# Converts a number of bytes to a number of mebibytes
func byte_to_mib(bytes:int,flatten:bool = true) -> float:
if flatten:
@warning_ignore("integer_division")
return bytes/1048576
return bytes/float(1048576)
# Flattens a floating point number
func flat_float(number:float) -> float:
return float(int(number))
func flat_float_int(number:float) -> int:
return int(number)