bevy_convars/types.rs
1use bevy_reflect::Reflect;
2use std::ops;
3
4/// Flags that can be applied to CVars.
5/// # Remarks
6/// Every flag above the 32nd bit is reserved for the user and will not be used without a major version update.
7///
8/// Every flag below is reserved to implementation.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Reflect)]
10pub struct CVarFlags(pub u64);
11
12impl CVarFlags {
13 /// The no-op/default flag set. You don't need to specify this if you have other flags, it's just null.
14 pub const LOCAL: CVarFlags = CVarFlags(0);
15 /// Indicates this cvar should be saved to disk as part of the user's settings.
16 ///
17 /// This is respected by [CVarSaveContext](crate::save::CVarSaveContext).
18 pub const SAVED: CVarFlags = CVarFlags(0b0000_0001);
19 /// Indicates this cvar is for mirrored to and from peers for replication. Peers will know the value of this CVar for this client.
20 pub const MIRRORED: CVarFlags = CVarFlags(0b0000_0010);
21 /// Indicates this cvar is respected at runtime if modified. This is a hint of intent!
22 /// CVars without this flag set should warn the user to restart the game when modified.
23 pub const RUNTIME: CVarFlags = CVarFlags(0b0000_0100);
24}
25
26impl ops::BitOr for CVarFlags {
27 type Output = CVarFlags;
28
29 fn bitor(self, rhs: Self) -> Self::Output {
30 Self(self.0 | rhs.0)
31 }
32}
33
34impl ops::BitAnd for CVarFlags {
35 type Output = CVarFlags;
36
37 fn bitand(self, rhs: Self) -> Self::Output {
38 Self(self.0 & rhs.0)
39 }
40}
41
42impl CVarFlags {
43 /// Returns true if the left flags contain (i.e. `a&b = b`) the right flags.
44 #[must_use]
45 pub fn contains(&self, other: CVarFlags) -> bool {
46 let and = *self & other;
47
48 and.0 == other.0
49 }
50}