-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
heuristic for camera frustum length is now based on scene size (#1433)
Introduces `EditableAutoValue` and per-frame heuristic updates on properties. In the future we can build more properties on top of this and update them in a central place like done here
- Loading branch information
Showing
8 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// A value that is either determined automatically by some heuristic, or specified by the user. | ||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Eq, PartialEq)] | ||
#[serde(bound = "T: serde::Serialize, for<'de2> T: serde::Deserialize<'de2>")] | ||
pub enum EditableAutoValue<T> | ||
where | ||
T: std::fmt::Debug + Eq + PartialEq + Clone + Default + serde::Serialize, | ||
for<'de2> T: serde::Deserialize<'de2>, | ||
{ | ||
/// The user explicitly specified what they wanted | ||
UserEdited(T), | ||
|
||
/// The value is determined automatically. | ||
/// | ||
/// We may update this at any time or interpret the value stored here differently under certain circumstances. | ||
Auto(T), | ||
} | ||
|
||
impl<T> Default for EditableAutoValue<T> | ||
where | ||
T: std::fmt::Debug + Eq + PartialEq + Clone + Default + serde::Serialize, | ||
for<'de2> T: serde::Deserialize<'de2>, | ||
{ | ||
fn default() -> Self { | ||
EditableAutoValue::Auto(T::default()) | ||
} | ||
} | ||
|
||
impl<T> EditableAutoValue<T> | ||
where | ||
T: std::fmt::Debug + Eq + PartialEq + Clone + Default + serde::Serialize, | ||
for<'de2> T: serde::Deserialize<'de2>, | ||
{ | ||
pub fn is_auto(&self) -> bool { | ||
matches!(self, EditableAutoValue::Auto(_)) | ||
} | ||
|
||
/// Gets the value, disregarding if it was user edited or determined by a heuristic. | ||
pub fn get(&self) -> &T { | ||
match self { | ||
EditableAutoValue::Auto(v) | EditableAutoValue::UserEdited(v) => v, | ||
} | ||
} | ||
|
||
/// Returns other if self is auto, self otherwise. | ||
pub fn or<'a>(&'a self, other: &'a EditableAutoValue<T>) -> &'a EditableAutoValue<T> { | ||
if self.is_auto() { | ||
other | ||
} else { | ||
self | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters