2024-02-04 21:36:30 +01:00
|
|
|
##############################################################################
|
|
|
|
### CORE FRAMEWORK SOURCE FILE ###
|
|
|
|
### Copyright (c) 2024 The StarOpenSource Project & Contributors ###
|
|
|
|
### Licensed under the GNU General Public License v3 ###
|
|
|
|
### ###
|
|
|
|
### This program is free software: you can redistribute it and/or modify ###
|
|
|
|
### it under the terms of the GNU General Public License as published by ###
|
|
|
|
### the Free Software Foundation, either version 3 of the License, or ###
|
|
|
|
### (at your option) any later version. ###
|
|
|
|
### ###
|
|
|
|
### This program is distributed in the hope that it will be useful, ###
|
|
|
|
### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
|
|
|
|
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
|
|
|
|
### GNU General Public License for more details. ###
|
|
|
|
### ###
|
|
|
|
### You should have received a copy of the GNU General Public License ###
|
|
|
|
### along with this program. If not, see <https://www.gnu.org/licenses/>. ###
|
|
|
|
##############################################################################
|
|
|
|
### src/misc.gd (Miscellaneous) ###
|
|
|
|
### ###
|
|
|
|
### Contains various functions that don't fit into other modules. ###
|
|
|
|
##############################################################################
|
|
|
|
extends CoreBaseModule
|
|
|
|
|
|
|
|
func quit_safely(exitcode: int = 0) -> void:
|
|
|
|
logger.info("Shutting down (code " + str(exitcode) + ")")
|
|
|
|
logger.diag("Waiting for log messages to be flushed")
|
|
|
|
await get_tree().create_timer(0.25).timeout
|
|
|
|
get_tree().quit(exitcode)
|
2024-02-09 15:28:42 +01:00
|
|
|
|
|
|
|
@warning_ignore("integer_division")
|
|
|
|
func byte2mib(bytes: int, flatten: bool = true) -> float:
|
|
|
|
if flatten: return bytes/1048576
|
|
|
|
return bytes/float(1048576)
|
|
|
|
|
2024-02-10 18:48:37 +01:00
|
|
|
func mib2byte(mib: float, flatten: bool = true) -> float:
|
|
|
|
if flatten: return int(mib*1048576)
|
|
|
|
return mib*1048576
|
2024-02-09 15:28:42 +01:00
|
|
|
|
|
|
|
func mib2gib(mib: float, flatten: bool = true) -> float:
|
2024-02-10 18:48:37 +01:00
|
|
|
if flatten: return int(mib/1024)
|
|
|
|
return mib/1024
|
2024-02-09 15:28:42 +01:00
|
|
|
|
2024-02-10 18:48:37 +01:00
|
|
|
func gib2mib(gib: float, flatten: bool = true) -> float:
|
|
|
|
if flatten: return int(gib*1024)
|
|
|
|
return gib*1024
|