2
0
Fork 0

Update to 708913ae7efa96ff584b76ad1d167bfe9d9ef71c

This commit is contained in:
JeremyStar™ 2024-04-24 01:42:11 +02:00
parent ea1a361112
commit 4aa2943d29
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 44 additions and 3 deletions

View file

@ -19,6 +19,8 @@ class_name CoreConfiguration
@export var custom_modules: bool
## If [method Core.quit_safely] (and by extension [method Core.cleanup]) should be called when pressing the X.
@export var automatic_shutdown: bool
## Hides the window during engine shutdown. Useful when your game and the framework will take longer to cleanup.
@export var hide_window_on_shutdown: bool
@export_category("Logger")
## The minimum log level you want to be displayed.
@ -26,8 +28,7 @@ class_name CoreConfiguration
## Determines if the logger's output should be colored.
@export var logger_colored: bool
## Determines if the logger should check if running in verbose mode (see [method OS.is_stdout_verbose]).[br]
## Comes with a huge performance penalty on startup, delaying startup by about one to two seconds.[br]
## Update [code]verbose_mode[/code] accordingly yourself if you've disabled this, or diagnostic log messages might appear messed up.[br]
## Update [code]verbose_mode[/code] yourself accordingly if you've set this to [code]false[/code], or face messed up diagnostic log messages.[br]
## [b]Warning: [i]Updating this during runtime does nothing.[/i][/b]
@export var logger_detect_verbose_mode: bool
## The template for all log messages.[br]
@ -68,10 +69,12 @@ func _init() -> void:
development = false
custom_modules = false
automatic_shutdown = true
hide_window_on_shutdown = true
# Logger
logger_level = CoreTypes.LoggerLevel.INFO
logger_colored = true
logger_detect_verbose_mode = true
logger_format = "%color%[%time%] [%level% %origin%] %message%"
logger_newlines_override = true
logger_newlines_sizelimit = 40

View file

@ -75,8 +75,22 @@ var disabled: bool = false
# Displays the ✨ special ✨ welcome message if true
var welcomed: bool = false
## Contains the amount of time it took to preinitialize the framework, measured in milliseconds.[br]
## Captured in [method _init].[br]
## [b]Danger: [i]Don't modify this.[/i][/b]
var initduration_preinitialization: int = 0
## Contains the amount of time it took to initialize the framework, measured in milliseconds.[br]
## Captured in [method _ready].[br]
## [b]Danger: [i]Don't modify this.[/i][/b]
var initduration_initialization: int = 0
## Contains the amount of time it took to completely initialize the framework, measured in milliseconds.[br]
## Captured in [method complete_init].[br]
## [b]Danger: [i]Don't modify this.[/i][/b]
var initduration_complete_initialization: int = 0
# +++ initialization +++
func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
var inittime: int = Time.get_ticks_msec()
name = "CORE"
if !check_godot_version(): return
if !determine_basepath(): queue_free()
@ -85,14 +99,17 @@ func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
initialize_modules()
apply_configuration()
initialize_scheduler()
initduration_preinitialization = Time.get_ticks_msec() - inittime
func _ready() -> void:
var inittime: int = Time.get_ticks_msec()
inject_modules()
custom_modules_node.name = "Custom Modules"
add_child(custom_modules_node)
loggeri = logger.get_instance(basepath.replace("res://", "") + "src/core.gd", self)
add_child(scheduler)
get_tree().auto_accept_quit = false
initduration_initialization = Time.get_ticks_msec() - inittime
# Initializes all built-in modules during the preinitialization phase.
## Internal, don't call.
@ -130,6 +147,7 @@ func initialize_scheduler() -> void:
## This ensures that all modules are fully initialized and ready for usage.[br]
## [i][b]Not calling this function during startup may lead to runtime issues.[/b][/i]
func complete_init() -> void:
var inittime: int = Time.get_ticks_msec()
var modsinit_builtin: Array[String] = ["workaround"]
var modsinit_custom: Array[String] = ["workaround"]
@ -152,6 +170,8 @@ func complete_init() -> void:
if modsinit_custom.size() != 0: print(" Custom: " + str(modsinit_custom))
await get_tree().create_timer(1).timeout
initduration_complete_initialization = Time.get_ticks_msec() - inittime
# Initialization complete
await get_tree().process_frame
if !welcomed:
@ -168,6 +188,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Consider contributing to the CORE Framework to make it even better... and remember: #TransRightsAreHumanRights
Thank you for using the CORE Framework to develop your application or game!""")
loggeri.info("Framework initialization took " + str(initduration_preinitialization + initduration_initialization + initduration_complete_initialization) + "ms (pre " + str(initduration_preinitialization) + "ms, init " + str(initduration_initialization) + "ms, complete " + str(initduration_complete_initialization) + "ms)")
if is_devmode(): loggeri.warn("The CORE Framework is running in development mode.\nThis may cause bugs and issues inside the framework. Here be dragons!")
if logger.verbose_mode: loggeri.warn("Godot is running in verbose stdout mode.\nDue to a bug in the engine that prevents displaying truecolor ANSI escape\nsequences CORE changed the color of all diagnostic log messages.\nTo prevent this, set 'logger_detect_verbose_mode' in the configuration to 'false'.")
# +++ configuration +++
## Loads a (new) configuration object and applies it to all modules.
@ -195,7 +218,7 @@ func apply_configuration() -> void:
custom_modules[module]._pull_config()
# Workaround
logger.verbose_mode = OS.is_stdout_verbose()
if config.logger_detect_verbose_mode: logger.verbose_mode = OS.is_stdout_verbose()
# +++ custom module support +++
## Registers a new custom module.
@ -413,6 +436,21 @@ func check_godot_version() -> bool:
## [b]Note: [i]Using the [code]await[/code] keyword is required for this function.[/i][/b]
func quit_safely(exitcode: int = 0) -> void:
loggeri.info("Shutting down (code " + str(exitcode) + ")")
if config.hide_window_on_shutdown:
loggeri.verb("Hiding window")
Engine.max_fps = -1 # a higher framerate seems to make the shutdown process muuuuch faster
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) # we don't want to cook the cpu tho
DisplayServer.window_set_exclusive(0, false)
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
DisplayServer.window_set_min_size(Vector2.ZERO)
DisplayServer.window_set_size(Vector2i.ZERO)
DisplayServer.window_set_max_size(Vector2.ZERO)
DisplayServer.window_set_position(Vector2i(9999999, 9999999))
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true)
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_ALWAYS_ON_TOP, false)
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, false)
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_NO_FOCUS, true)
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED, true)
await get_tree().create_timer(0.25).timeout
await cleanup()
get_tree().quit(exitcode)