Godot's Compatibility renderer draws a shadowed directional light in a pass of its own and adds it after the frame is in sRGB, so sunlit pixels come out as srgb(ambient) + srgb(sun) (measured to within 1/255 on llvmpipe) and ground and rocks wash out. No environment or project setting avoids it, so Look.sun_shadows_supported() is false under gl_compatibility and the sun casts no shadows there on any preset. Adds the sun_probe and sun_shadow_probe capture scenarios to recheck after an engine upgrade, a test, and the explanation in PLAY.md and the README. Closes #81 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
212 lines
9.2 KiB
GDScript
212 lines
9.2 KiB
GDScript
extends TestCase
|
|
|
|
## A10: settings saved between launches, and corrupt files falling back to defaults.
|
|
|
|
const PATH: String = "user://test_game_settings.cfg"
|
|
|
|
|
|
func after_each() -> void:
|
|
super.after_each()
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
|
|
|
|
|
|
func test_everything_round_trips() -> void:
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.mouse.mouse_sensitivity = 2.5
|
|
settings.mouse.invert_y = true
|
|
assert_eq(settings.bindings.bind("jump", KEY_F), "")
|
|
settings.quality = GameSettings.QUALITY_LOW
|
|
settings.print_pass = false
|
|
settings.master_volume = 0.3
|
|
settings.music_volume = 0.0
|
|
settings.effects_volume = 0.55
|
|
settings.window_mode = 1
|
|
settings.vsync = false
|
|
settings.max_fps = 144
|
|
settings.player_name = " Wren of the Point "
|
|
settings.last_server = "example.org:24650"
|
|
settings.practice_bots = 7
|
|
settings.practice_difficulty = 2
|
|
assert_eq(settings.save(PATH), OK)
|
|
var loaded: GameSettings = GameSettings.load_from(PATH)
|
|
assert_near(loaded.mouse.mouse_sensitivity, 2.5, 0.0001)
|
|
assert_true(loaded.mouse.invert_y)
|
|
assert_eq(loaded.bindings.code_of("jump"), KEY_F)
|
|
assert_eq(loaded.quality, GameSettings.QUALITY_LOW)
|
|
assert_false(loaded.print_pass)
|
|
assert_near(loaded.master_volume, 0.3, 0.0001)
|
|
assert_near(loaded.music_volume, 0.0, 0.0001)
|
|
assert_near(loaded.effects_volume, 0.55, 0.0001)
|
|
assert_eq(loaded.window_mode, 1)
|
|
assert_false(loaded.vsync)
|
|
assert_eq(loaded.max_fps, 144)
|
|
assert_eq(loaded.player_name, "Wren of the Point")
|
|
assert_eq(loaded.last_server, "example.org:24650")
|
|
assert_eq(loaded.practice_bots, 7)
|
|
assert_eq(loaded.practice_difficulty, 2)
|
|
assert_eq(loaded.shadow_distance(), 0.0, "low has no shadows")
|
|
|
|
|
|
func test_a_missing_file_gives_defaults() -> void:
|
|
var loaded: GameSettings = GameSettings.load_from("user://no_such_settings.cfg")
|
|
_assert_defaults(loaded)
|
|
|
|
|
|
func test_a_corrupt_file_gives_defaults() -> void:
|
|
# The engine reports each file it can't parse; that's expected here.
|
|
expect_error("ConfigFile parse error")
|
|
expect_error("ConfigFile parse error")
|
|
for garbage: PackedByteArray in [
|
|
"[graphics\nquality=???\n".to_utf8_buffer() + PackedByteArray([0, 1]),
|
|
PackedByteArray([0xFF, 0xFE, 0x00, 0x13, 0x37, 0x80, 0x81]),
|
|
"quality = 2 = 3 [[[".to_utf8_buffer(),
|
|
]:
|
|
var file: FileAccess = FileAccess.open(PATH, FileAccess.WRITE)
|
|
file.store_buffer(garbage)
|
|
file.close()
|
|
_assert_defaults(GameSettings.load_from(PATH))
|
|
|
|
|
|
func test_wrong_types_and_ranges_fall_back_value_by_value() -> void:
|
|
var config: ConfigFile = ConfigFile.new()
|
|
config.set_value("graphics", "quality", 99)
|
|
config.set_value("graphics", "print_pass", "yes")
|
|
config.set_value("audio", "master", 7.0)
|
|
config.set_value("audio", "music", NAN)
|
|
config.set_value("audio", "effects", [1, 2])
|
|
config.set_value("display", "window_mode", -4)
|
|
config.set_value("display", "max_fps", 77)
|
|
config.set_value("player", "name", 12)
|
|
config.set_value("practice", "bots", 400)
|
|
config.set_value("input", "mouse_sensitivity", INF)
|
|
config.set_value("keys", "forward", KEY_UP)
|
|
assert_eq(config.save(PATH), OK)
|
|
var loaded: GameSettings = GameSettings.load_from(PATH)
|
|
assert_eq(loaded.quality, GameSettings.QUALITY_HIGH, "clamped to the top preset")
|
|
assert_true(loaded.print_pass, "not a bool: the default")
|
|
assert_near(loaded.master_volume, 1.0, 0.0001, "clamped")
|
|
assert_near(loaded.music_volume, GameSettings.new().music_volume, 0.0001, "NaN: the default")
|
|
assert_near(loaded.effects_volume, GameSettings.new().effects_volume, 0.0001)
|
|
assert_eq(loaded.window_mode, 0)
|
|
assert_eq(loaded.max_fps, 0, "not an offered cap")
|
|
assert_eq(loaded.player_name, ClientConfig.DEFAULT_NAME)
|
|
assert_eq(loaded.practice_bots, Tuning.SOLO_PLAYERS - 1)
|
|
assert_near(loaded.mouse.mouse_sensitivity, 1.0, 0.0001)
|
|
assert_eq(loaded.bindings.code_of("forward"), KEY_UP, "the one good value is kept")
|
|
|
|
|
|
func test_old_mouse_only_files_still_load() -> void:
|
|
var old: InputSettings = InputSettings.new()
|
|
old.mouse_sensitivity = 3.0
|
|
assert_eq(old.save(PATH), OK)
|
|
var loaded: GameSettings = GameSettings.load_from(PATH)
|
|
assert_near(loaded.mouse.mouse_sensitivity, 3.0, 0.0001)
|
|
assert_eq(loaded.bindings.code_of("jump"), KEY_SPACE)
|
|
|
|
|
|
func test_applying_settings_sets_the_audio_buses() -> void:
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.music_volume = 0.0
|
|
settings.effects_volume = 0.5
|
|
settings.apply_to_program(null)
|
|
var music: int = AudioServer.get_bus_index("Music")
|
|
var effects: int = AudioServer.get_bus_index("Effects")
|
|
assert_true(music > 0 and effects > 0, "made the buses")
|
|
assert_true(AudioServer.is_bus_mute(music))
|
|
assert_near(AudioServer.get_bus_volume_db(effects), linear_to_db(0.5), 0.01)
|
|
settings.apply_to_program(null)
|
|
assert_eq(AudioServer.bus_count, 3, "no extra buses the second time")
|
|
|
|
|
|
func _assert_defaults(loaded: GameSettings) -> void:
|
|
var fresh: GameSettings = GameSettings.new()
|
|
assert_eq(loaded.quality, fresh.quality)
|
|
assert_eq(loaded.print_pass, fresh.print_pass)
|
|
assert_eq(loaded.master_volume, fresh.master_volume)
|
|
assert_eq(loaded.window_mode, fresh.window_mode)
|
|
assert_eq(loaded.player_name, fresh.player_name)
|
|
assert_eq(loaded.mouse.mouse_sensitivity, fresh.mouse.mouse_sensitivity)
|
|
for action: Dictionary in KeyBindings.ACTIONS:
|
|
assert_eq(loaded.bindings.code_of(action["id"]), int(action["default"]))
|
|
|
|
|
|
func test_presets_rise_from_low_to_high() -> void:
|
|
var settings: GameSettings = GameSettings.new()
|
|
var previous: Dictionary = {}
|
|
for quality: int in GameSettings.QUALITY_NAMES.size():
|
|
settings.quality = quality
|
|
var preset: Dictionary = GameSettings.QUALITY[quality]
|
|
assert_true([1, 2, 4].has(settings.shadow_splits()), "%s has 1, 2 or 4 shadow splits" % GameSettings.QUALITY_NAMES[quality])
|
|
assert_true(preset["msaa"] == Viewport.MSAA_DISABLED or not preset["fxaa"], "no preset pays for both MSAA and FXAA")
|
|
if not previous.is_empty():
|
|
assert_true(float(preset["shadow_distance"]) >= float(previous["shadow_distance"]))
|
|
assert_true(int(preset["shadow_splits"]) >= int(previous["shadow_splits"]))
|
|
assert_true(float(preset["render_scale"]) >= float(previous["render_scale"]))
|
|
previous = preset
|
|
settings.quality = GameSettings.QUALITY_HIGH
|
|
assert_eq(settings.shadow_splits(), 4)
|
|
|
|
|
|
func test_a_preset_sets_the_viewport_and_the_sun() -> void:
|
|
var viewport: SubViewport = SubViewport.new()
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.quality = GameSettings.QUALITY_LOW
|
|
settings.apply_to_viewport(viewport)
|
|
assert_near(viewport.scaling_3d_scale, 0.75, 0.001)
|
|
assert_eq(viewport.msaa_3d, Viewport.MSAA_DISABLED)
|
|
assert_eq(viewport.screen_space_aa, Viewport.SCREEN_SPACE_AA_FXAA)
|
|
settings.quality = GameSettings.QUALITY_HIGH
|
|
settings.apply_to_viewport(viewport)
|
|
assert_near(viewport.scaling_3d_scale, 1.0, 0.001)
|
|
assert_eq(viewport.msaa_3d, Viewport.MSAA_2X)
|
|
assert_eq(viewport.screen_space_aa, Viewport.SCREEN_SPACE_AA_DISABLED)
|
|
viewport.free()
|
|
var view: MatchView = MatchView.new()
|
|
view.sun = Look.sun()
|
|
view.add_child(view.sun)
|
|
settings.quality = GameSettings.QUALITY_MEDIUM
|
|
view.apply_settings(settings)
|
|
assert_true(view.sun.shadow_enabled)
|
|
assert_eq(view.sun.directional_shadow_mode, DirectionalLight3D.SHADOW_PARALLEL_2_SPLITS)
|
|
settings.quality = GameSettings.QUALITY_LOW
|
|
view.apply_settings(settings)
|
|
assert_false(view.sun.shadow_enabled, "low has no shadows")
|
|
view.free()
|
|
|
|
|
|
func test_no_sun_shadows_under_the_opengl_fallback() -> void:
|
|
# H14: Compatibility adds a shadowed sun's pass in sRGB, which washes out sunlit
|
|
# ground, so the sun casts no shadows there whatever the preset.
|
|
assert_true(Look.sun_shadows_supported("forward_plus"))
|
|
assert_true(Look.sun_shadows_supported("mobile"))
|
|
assert_false(Look.sun_shadows_supported("gl_compatibility"))
|
|
var expected: bool = Look.sun_shadows_supported()
|
|
var sun: DirectionalLight3D = Look.sun()
|
|
assert_eq(sun.shadow_enabled, expected, "Look.sun follows the renderer")
|
|
sun.free()
|
|
var view: MatchView = MatchView.new()
|
|
view.sun = Look.sun()
|
|
view.add_child(view.sun)
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.quality = GameSettings.QUALITY_HIGH
|
|
view.apply_settings(settings)
|
|
assert_eq(view.sun.shadow_enabled, expected, "presets don't turn them back on")
|
|
view.free()
|
|
|
|
|
|
func test_presets_never_change_how_far_cover_is_drawn() -> void:
|
|
# A lower preset must never let a player see through trees and rocks it stopped
|
|
# drawing: nothing about props is in the presets.
|
|
for preset: Dictionary in GameSettings.QUALITY:
|
|
for key: String in preset:
|
|
assert_false(key.contains("range") or key.contains("detail") or (key.contains("distance") and key != "shadow_distance"), "preset key %s" % key)
|
|
|
|
|
|
func test_renderer_fallback_notice() -> void:
|
|
var none: PackedStringArray = PackedStringArray()
|
|
assert_eq(RendererCheck.notice_for("forward_plus", "forward_plus", none), "", "the renderer asked for")
|
|
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", none), RendererCheck.NOTICE, "fell back to OpenGL")
|
|
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", PackedStringArray(["--rendering-method", "gl_compatibility"])), "", "the player chose OpenGL")
|
|
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", PackedStringArray(["--rendering-driver=opengl3"])), "", "the player chose OpenGL")
|
|
assert_eq(RendererCheck.fallback_notice(), "", "nothing to say headless")
|