Add config and basic architecture for QUIC
This commit is contained in:
49
substrate/src/config.rs
Normal file
49
substrate/src/config.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use bevy::prelude::Resource;
|
||||
use figment::Figment;
|
||||
use figment::providers::{Env, Format, Serialized, Toml};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Resource, Serialize, Deserialize)]
|
||||
pub struct AppConfig {
|
||||
pub network: QuicConfig,
|
||||
pub simulation: SimulationConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SimulationConfig {
|
||||
pub tick_rate_hz: u32,
|
||||
pub max_entities: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct QuicConfig {
|
||||
pub server_port: u16,
|
||||
pub server_interface: String,
|
||||
pub server_cert: String,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
network : QuicConfig {
|
||||
server_port: 9000,
|
||||
server_interface: "0.0.0.0".to_string(),
|
||||
server_cert: "cert.pem".to_string(),
|
||||
},
|
||||
simulation: SimulationConfig {
|
||||
tick_rate_hz: 60,
|
||||
max_entities: 10000,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load(config_file: &str) -> Result<Self, figment::Error> {
|
||||
Figment::new()
|
||||
.merge(Serialized::defaults(Self::default())) // compiled-in defaults
|
||||
.merge(Toml::file(config_file)) // config file
|
||||
.merge(Env::prefixed("APP_")) // env overrides, e.g. APP_NETWORK__PORT=9000
|
||||
.extract()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user