第一次启动检测是否启用 opengl3
This commit is contained in:
parent
0dac449034
commit
3ef06dc1b3
@ -67,6 +67,7 @@ signal auto_save_seconds_changed
|
||||
|
||||
@export var version: int #存档版本
|
||||
@export var debug_mode := false # 开启 debug 模式
|
||||
@export_enum("unspecified", "checking", "opengl3", "non-opengl3") var compatibility_mode := 0
|
||||
@export var skip_trailer := false # 跳过 trailer
|
||||
@export var game_launched_times := 0 # 启动游戏次数
|
||||
@export var game_total_seconds := 0 # 游戏总时长
|
||||
|
@ -7,7 +7,7 @@ const TIMER_LOG_INTERVAL := 6 # 30秒打印一次 (6 * 5秒)
|
||||
const TIMER_EDITOR_LOG_INTERVAL := 120 # 编辑器中600秒打印一次
|
||||
|
||||
# Static config
|
||||
static var config: GlobalConfig:
|
||||
var config: GlobalConfig:
|
||||
set = _set_config
|
||||
|
||||
# Timer for tracking game time
|
||||
@ -27,23 +27,49 @@ func _setup_timer() -> void:
|
||||
timer.start()
|
||||
|
||||
|
||||
static func _set_config(val: GlobalConfig) -> void:
|
||||
func _set_config(val: GlobalConfig) -> void:
|
||||
config = val
|
||||
if not config or Engine.is_editor_hint():
|
||||
return
|
||||
_apply_compatibility()
|
||||
_apply_debug_mode()
|
||||
_apply_window_settings()
|
||||
_apply_audio_settings()
|
||||
_apply_locale_settings()
|
||||
|
||||
|
||||
static func _apply_debug_mode() -> void:
|
||||
func _apply_compatibility() -> void:
|
||||
# ("unspecified", "checking", "opengl3", "non-opengl3")
|
||||
if config.compatibility_mode == 0:
|
||||
config.compatibility_mode = 1
|
||||
ResourceSaver.save(config)
|
||||
elif config.compatibility_mode == 1:
|
||||
config.compatibility_mode = 2
|
||||
print("[Compatibility] Compatibility mode set to 'opengl3' for checking launch.")
|
||||
|
||||
if config.compatibility_mode == 2:
|
||||
# 检测是否已经启用 opengl3
|
||||
if RenderingServer.get_current_rendering_driver_name().begins_with("opengl3"):
|
||||
print("[Compatibility] Compatibility mode is already 'opengl3'. No action needed.")
|
||||
return
|
||||
print("[Compatibility] Switching to 'opengl3' rendering driver.")
|
||||
# 重启游戏以应用新渲染器
|
||||
var args = ["--rendering-driver", "opengl3"]
|
||||
# 启动新实例
|
||||
var executable_path = OS.get_executable_path()
|
||||
OS.create_process(executable_path, args)
|
||||
get_tree().quit()
|
||||
elif config.compatibility_mode == 3:
|
||||
print("[Compatibility] Running on 'non-opengl3' rendering driver.")
|
||||
|
||||
|
||||
func _apply_debug_mode() -> void:
|
||||
if config.debug_mode:
|
||||
GlobalConfig.DEBUG = true
|
||||
print_rich("[color=orange]Debug mode enabled[/color]")
|
||||
|
||||
|
||||
static func _apply_window_settings() -> void:
|
||||
func _apply_window_settings() -> void:
|
||||
var window = Engine.get_main_loop().root.get_window()
|
||||
if config.window_fullscreen:
|
||||
window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN
|
||||
@ -52,7 +78,7 @@ static func _apply_window_settings() -> void:
|
||||
window.always_on_top = config.window_top
|
||||
|
||||
|
||||
static func _apply_audio_settings() -> void:
|
||||
func _apply_audio_settings() -> void:
|
||||
AudioServer.set_bus_volume_db(
|
||||
AudioServer.get_bus_index(GlobalConfig.BUS_MASTER), config.db_master
|
||||
)
|
||||
@ -70,7 +96,7 @@ static func _apply_audio_settings() -> void:
|
||||
)
|
||||
|
||||
|
||||
static func _apply_locale_settings() -> void:
|
||||
func _apply_locale_settings() -> void:
|
||||
var locale = config.get_locale()
|
||||
print("set language to: ", locale)
|
||||
TranslationServer.set_locale(locale)
|
||||
@ -136,7 +162,7 @@ func print_global_info() -> void:
|
||||
)
|
||||
|
||||
|
||||
static func _format_game_time(total_seconds: int) -> String:
|
||||
func _format_game_time(total_seconds: int) -> String:
|
||||
@warning_ignore("integer_division")
|
||||
var hours := total_seconds / 3600
|
||||
@warning_ignore("integer_division")
|
||||
@ -145,14 +171,14 @@ static func _format_game_time(total_seconds: int) -> String:
|
||||
return "game:%d:%02d:%02d" % [hours, minutes, seconds]
|
||||
|
||||
|
||||
static func _get_round_info() -> String:
|
||||
func _get_round_info() -> String:
|
||||
# 0:未开始游戏;1:序章;2-5:一~四章;6:结尾
|
||||
var chapter := EventManager.get_chapter_stage()
|
||||
return "r%d_c%d" % [config.game_rounds, chapter]
|
||||
|
||||
|
||||
@warning_ignore_start("integer_division")
|
||||
static func _format_tick_time() -> String:
|
||||
func _format_tick_time() -> String:
|
||||
var ticks = Time.get_ticks_msec()
|
||||
var hours := ticks / 3600000 as int
|
||||
var minutes := (ticks % 3600000) / 60000 as int
|
||||
|
@ -40,6 +40,13 @@ func _ready() -> void:
|
||||
_setup_video_player()
|
||||
_setup_language_settings(game_launched_times)
|
||||
_connect_button_signals()
|
||||
# 第一次启动成功, 设置 compatibility_mode
|
||||
var config = GlobalConfigManager.config
|
||||
# ("unspecified", "checking", "opengl3", "non-opengl3")
|
||||
if config.compatibility_mode < 2:
|
||||
config.compatibility_mode = 3
|
||||
ResourceSaver.save(config)
|
||||
print("[FirstLaunch] Compatibility mode set to 'non-opengl3' for first launch.")
|
||||
|
||||
|
||||
func _setup_video_player() -> void:
|
||||
@ -48,7 +55,7 @@ func _setup_video_player() -> void:
|
||||
|
||||
|
||||
func _setup_language_settings(game_launched_times: int) -> void:
|
||||
if game_launched_times == 0:
|
||||
if game_launched_times == 1:
|
||||
_read_system_locale()
|
||||
_update_language_display()
|
||||
|
||||
@ -119,7 +126,6 @@ func _on_earplug_notice_finished() -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if not event.is_action_pressed("escape") or first_launching_game:
|
||||
return
|
||||
|
||||
if video_player.is_playing():
|
||||
_skip_video()
|
||||
elif earplug_notice_tween and earplug_notice_tween.is_running():
|
||||
|
Loading…
Reference in New Issue
Block a user