feat: runtime-configurable VSync via config.toml

[display]
vsync = "mailbox"   # "vsync" | "mailbox" | "uncapped"

VsyncMode enum with custom Deserialize — accepts string values in toml.
apply_vsync_setting system reads GameConfig on every frame, updates
Window.present_mode immediately on change. No restart needed.
This commit is contained in:
2026-03-20 17:10:54 +00:00
parent 11d4b6a8a0
commit eac787be3f
3 changed files with 51 additions and 1 deletions
+31
View File
@@ -8,6 +8,37 @@ use std::sync::OnceLock;
pub struct GameConfig {
pub initial_chunk_radius: i32,
pub spawn_counts: SpawnCounts,
#[serde(default)]
pub display: DisplaySettings,
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct DisplaySettings {
#[serde(default)]
pub vsync: VsyncMode,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum VsyncMode {
#[default]
Vsync,
Mailbox,
Uncapped,
}
impl<'de> Deserialize<'de> for VsyncMode {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
match s.as_str() {
"vsync" => Ok(VsyncMode::Vsync),
"mailbox" => Ok(VsyncMode::Mailbox),
"uncapped" => Ok(VsyncMode::Uncapped),
_ => Ok(VsyncMode::Vsync),
}
}
}
#[derive(Debug, Deserialize, Clone)]