forked from StudioInfinity/dyna3
Refactor: Use pointers to refer to elements and regulators (#84)
Previously, dyna3 used storage keys to refer to elements, necessitating passing around element containers to various functions so that they could access the relevant elements. These storage keys have been replaced with reference-counted pointers, used for tasks like these: - Specifying the subjects of regulators. - Collecting the regulators each element is subject to - Handling selection. - Creating interface components. Also, systematizes the handling of serial numbers for entities, through a Serial trait. And updates to rust 1.86 and institutes explicit checking of the rust version. Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo> Reviewed-on: StudioInfinity/dyna3#84 Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net> Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
parent
a2478febc1
commit
2adf4669f4
8 changed files with 288 additions and 270 deletions
|
@ -1,5 +1,6 @@
|
|||
use core::array;
|
||||
use nalgebra::{DMatrix, DVector, Rotation3, Vector3};
|
||||
use std::rc::Rc;
|
||||
use sycamore::{prelude::*, motion::create_raf};
|
||||
use web_sys::{
|
||||
console,
|
||||
|
@ -16,7 +17,7 @@ use web_sys::{
|
|||
|
||||
use crate::{
|
||||
AppState,
|
||||
assembly::{ElementKey, ElementColor, ElementMotion, Point, Sphere}
|
||||
assembly::{Element, ElementColor, ElementMotion, Point, Sphere}
|
||||
};
|
||||
|
||||
// --- scene data ---
|
||||
|
@ -362,7 +363,7 @@ pub fn Display() -> View {
|
|||
let scene_changed = create_signal(true);
|
||||
create_effect(move || {
|
||||
state.assembly.elements.with(|elts| {
|
||||
for (_, elt) in elts {
|
||||
for elt in elts {
|
||||
elt.representation().track();
|
||||
}
|
||||
});
|
||||
|
@ -548,7 +549,7 @@ pub fn Display() -> View {
|
|||
// manipulate the assembly
|
||||
if state.selection.with(|sel| sel.len() == 1) {
|
||||
let sel = state.selection.with(
|
||||
|sel| *sel.into_iter().next().unwrap()
|
||||
|sel| sel.into_iter().next().unwrap().clone()
|
||||
);
|
||||
let translate_x = translate_pos_x_val - translate_neg_x_val;
|
||||
let translate_y = translate_pos_y_val - translate_neg_y_val;
|
||||
|
@ -574,7 +575,7 @@ pub fn Display() -> View {
|
|||
assembly_for_raf.deform(
|
||||
vec![
|
||||
ElementMotion {
|
||||
key: sel,
|
||||
element: sel,
|
||||
velocity: elt_motion.as_view()
|
||||
}
|
||||
]
|
||||
|
@ -615,8 +616,8 @@ pub fn Display() -> View {
|
|||
|
||||
// set up the scene
|
||||
state.assembly.elements.with_untracked(
|
||||
|elts| for (key, elt) in elts {
|
||||
let selected = state.selection.with(|sel| sel.contains(&key));
|
||||
|elts| for elt in elts {
|
||||
let selected = state.selection.with(|sel| sel.contains(elt));
|
||||
elt.show(&mut scene, selected);
|
||||
}
|
||||
);
|
||||
|
@ -849,16 +850,16 @@ pub fn Display() -> View {
|
|||
// find the nearest element along the pointer direction
|
||||
let (dir, pixel_size) = event_dir(&event);
|
||||
console::log_1(&JsValue::from(dir.to_string()));
|
||||
let mut clicked: Option<(ElementKey, f64)> = None;
|
||||
for (key, elt) in state.assembly.elements.get_clone_untracked() {
|
||||
let mut clicked: Option<(Rc<dyn Element>, f64)> = None;
|
||||
for elt in state.assembly.elements.get_clone_untracked() {
|
||||
match assembly_to_world.with(|asm_to_world| elt.cast(dir, asm_to_world, pixel_size)) {
|
||||
Some(depth) => match clicked {
|
||||
Some((_, best_depth)) => {
|
||||
if depth < best_depth {
|
||||
clicked = Some((key, depth))
|
||||
clicked = Some((elt, depth))
|
||||
}
|
||||
},
|
||||
None => clicked = Some((key, depth))
|
||||
None => clicked = Some((elt, depth))
|
||||
}
|
||||
None => ()
|
||||
};
|
||||
|
@ -866,7 +867,7 @@ pub fn Display() -> View {
|
|||
|
||||
// if we clicked something, select it
|
||||
match clicked {
|
||||
Some((key, _)) => state.select(key, event.shift_key()),
|
||||
Some((elt, _)) => state.select(&elt, event.shift_key()),
|
||||
None => state.selection.update(|sel| sel.clear())
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue