forked from StudioInfinity/dyna3
Add more test assemblies (#103)
This PR helps probe the capabilities of the engine. Also adjusts the realization triggering system to reduce redundant realizations as we set an assembly's regulators during loading. Specificially, consolidates all calls to `realize()` into a single effect, which is triggered by the `needs_realization` signal. Also introduces a `keep_realized` signal and use it to pause realization while loading assemblies, but this signal is planned for removal as ultimately we do not want a separate "mode" of interpreting commands during loading, for maximal reproducibility of results (and simplicity of system). Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo> Reviewed-on: StudioInfinity/dyna3#103 Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net> Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
parent
5864017e6f
commit
0801200210
13 changed files with 1045 additions and 277 deletions
|
@ -13,7 +13,7 @@ use sycamore::prelude::*;
|
|||
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||
|
||||
use crate::{
|
||||
display::DisplayItem,
|
||||
components::{display::DisplayItem, outline::OutlineItem},
|
||||
engine::{
|
||||
Q,
|
||||
change_half_curvature,
|
||||
|
@ -29,7 +29,6 @@ use crate::{
|
|||
DescentHistory,
|
||||
Realization
|
||||
},
|
||||
outline::OutlineItem,
|
||||
specified::SpecifiedValue
|
||||
};
|
||||
|
||||
|
@ -552,6 +551,10 @@ pub struct Assembly {
|
|||
// indexing
|
||||
pub elements_by_id: Signal<BTreeMap<String, Rc<dyn Element>>>,
|
||||
|
||||
// realization control
|
||||
pub keep_realized: Signal<bool>,
|
||||
pub needs_realization: Signal<bool>,
|
||||
|
||||
// realization diagnostics
|
||||
pub realization_status: Signal<Result<(), String>>,
|
||||
pub descent_history: Signal<DescentHistory>
|
||||
|
@ -559,14 +562,30 @@ pub struct Assembly {
|
|||
|
||||
impl Assembly {
|
||||
pub fn new() -> Assembly {
|
||||
Assembly {
|
||||
// create an assembly
|
||||
let assembly = Assembly {
|
||||
elements: create_signal(BTreeSet::new()),
|
||||
regulators: create_signal(BTreeSet::new()),
|
||||
tangent: create_signal(ConfigSubspace::zero(0)),
|
||||
elements_by_id: create_signal(BTreeMap::default()),
|
||||
keep_realized: create_signal(true),
|
||||
needs_realization: create_signal(false),
|
||||
realization_status: create_signal(Ok(())),
|
||||
descent_history: create_signal(DescentHistory::new())
|
||||
}
|
||||
};
|
||||
|
||||
// realize the assembly whenever it becomes simultaneously true that
|
||||
// we're trying to keep it realized and it needs realization
|
||||
let assembly_for_effect = assembly.clone();
|
||||
create_effect(move || {
|
||||
let should_realize = assembly_for_effect.keep_realized.get()
|
||||
&& assembly_for_effect.needs_realization.get();
|
||||
if should_realize {
|
||||
assembly_for_effect.realize();
|
||||
}
|
||||
});
|
||||
|
||||
assembly
|
||||
}
|
||||
|
||||
// --- inserting elements and regulators ---
|
||||
|
@ -627,7 +646,7 @@ impl Assembly {
|
|||
regulators.update(|regs| regs.insert(regulator.clone()));
|
||||
}
|
||||
|
||||
// update the realization when the regulator becomes a constraint, or is
|
||||
// request a realization when the regulator becomes a constraint, or is
|
||||
// edited while acting as a constraint
|
||||
let self_for_effect = self.clone();
|
||||
create_effect(move || {
|
||||
|
@ -636,7 +655,7 @@ impl Assembly {
|
|||
console_log!("Updated regulator with subjects {:?}", regulator.subjects());
|
||||
|
||||
if regulator.try_activate() {
|
||||
self_for_effect.realize();
|
||||
self_for_effect.needs_realization.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -731,6 +750,9 @@ impl Assembly {
|
|||
|
||||
// save the tangent space
|
||||
self.tangent.set_silent(tangent);
|
||||
|
||||
// clear the realization request flag
|
||||
self.needs_realization.set(false);
|
||||
},
|
||||
Err(message) => {
|
||||
// report the realization status. the `Err(message)` we're
|
||||
|
@ -826,10 +848,10 @@ impl Assembly {
|
|||
});
|
||||
}
|
||||
|
||||
// bring the configuration back onto the solution variety. this also
|
||||
// gets the elements' column indices and the saved tangent space back in
|
||||
// sync
|
||||
self.realize();
|
||||
// request a realization to bring the configuration back onto the
|
||||
// solution variety. this also gets the elements' column indices and the
|
||||
// saved tangent space back in sync
|
||||
self.needs_realization.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue