Expand description
Provides an implementation of ConVars (henceforth CVars), a form of global configuration for an application.
Intended for full applications, not for libraries! If you’re a library author, the easiest and best way to integrate is simply to make your library configurable, and allow the end user to create convars themselves.
§Examples
§Create and use CVars
bevy_convars::cvar_collection! {
pub struct RenderCVars & RenderCVarsMut {
enable_xr = cvar EnableXr("render.enable_xr", CVarFlags::SAVED): bool = false,
enable_renderdoc = cvar EnableRenderdoc("render.enable_renderdoc", CVarFlags::LOCAL): bool = false,
/*
* Anti-aliasing
*/
aa_method = cvar AaMethod("render.aa.method", CVarFlags::SAVED | CVarFlags::RUNTIME): AntialiasMethod = AntialiasMethod::Fxaa,
fxaa_sensitivity = cvar FxaaSensitivty("render.aa.fxaa_sensitivity", CVarFlags::SAVED | CVarFlags::RUNTIME): FxaaSensitivity = FxaaSensitivity::Medium,
msaa_samples = cvar MsaaSamples("render.aa.msaa_samples", CVarFlags::SAVED | CVarFlags::RUNTIME): MsaaSamplingConfig = MsaaSamplingConfig::Msaa4,
/*
* SSAO.
*/
enable_ssao = cvar EnableSsao("render.ssao.enabled", CVarFlags::SAVED | CVarFlags::RUNTIME): bool = true,
ssao_quality = cvar RenderSsaoQuality("render.ssao.quality", CVarFlags::SAVED | CVarFlags::RUNTIME): SsaoQuality = SsaoQuality::High,
ssao_object_thickness = cvar SsaoObjectThickness("render.ssao.object_thickness", CVarFlags::SAVED | CVarFlags::RUNTIME): f32 = 0.25
}
pub struct RenderCVarsPlugin;
}
fn my_system(
cvars: RenderCVars,
enable_ssao: Res<EnableSsao>,
mut commands: Commands,
) {
// Can read directly out of the RenderCVars param..
let aa_method = **cvars.aa_method;
// or from a specific cvar resource.
// All CVar types implement Deref and DerefMut for their inner type to make them easy to unpack and modify.
let ssao_on = **enable_ssao;
// ...
}§Load configuration files
// Add all your CVar plugins first, then:
// Bring your own implementation, I recommend the `directories` crate.
let mut user_data_directory: PathBuf = get_user_directory();
// Consider making this file name itself a CVar so users can specify an
// override on the command line.
user_data_directory.push("user_config.toml");
let cvar_loader =
CVarLoaderPluginBuilder::fancy()
// Load dev tooling config if we have them enabled.
.add_asset_layer_if(cfg!(feature = "dev_tools"), "dev_tools.toml")
// And load the user's config file.
.with_user_config_file(user_data_directory)
.build();
// Add the plugin, loading all layers and user configuration in one go.
app.add_plugins(cvar_loader);§Apply command-line overrides
// Through one means or another, get yourself a list of CVarOverride.
// CVarOverride implements FromStr, so most command-line parsing libraries
// like clap can do it for you.
let overrides: Vec<CVarOverride> = todo!();
let world = app.world_mut();
for cvar in overrides.iter() {
world.set_cvar_with_override(cvar);
}Modules§
- builtin
- Builtin CVars that are automatically registered in any application.
- defaults
- Helpers for working with the default values of CVars.
- loader
- Provides the ability to load TOML configuration files as a collection of CVars.
- parse
- Provides tools for parsing CVar overrides (CVarOverride) and config files.
- prelude
- The bevy-convars prelude with the most common types.
- reflect
- Contains types for reflecting over CVars statically and dynamically.
- save
- Provides support for saving CVars to a TOML config file.
Macros§
- cvar_
collection - Declares a collection of CVars.
Structs§
- CVar
Flags - Flags that can be applied to CVars.
- CVar
Management - App resource that provides management information and functionality for CVars.
- CVars
Plugin - Core plugin for providing CVars.
Enums§
- CVar
Error - Errors that can occur when manipulating CVars.
Traits§
- World
Extensions - Provides extensions to the world for CVars.