Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmatrix committed Jul 3, 2024
1 parent e0c4fb0 commit 0d77a65
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 0 additions & 2 deletions examples/shared/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ impl Application {
}

pub fn matrix(&self, page_size: impl Into<SizeI>) -> Matrix4 {
// let mut shapes = Vec::new();

let page_size = page_size.into();

let page_x_center: f64 = -((page_size.width / 2) as f64);
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Scene {
let mut map: HashMap<Id, Vec<&[Shape]>> = HashMap::new();

for visual in self.visuals.iter_some() {
let visual_id = visual.position;
let visual_id = visual.location;
map.entry(visual_id).or_default().push(&visual.shapes);
}

Expand Down
6 changes: 4 additions & 2 deletions scene/src/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{any::TypeId, mem};

use massive_geometry as geometry;

use crate::{Id, LocationRenderObj, Object, Visual, VisualRenderObj};
use crate::{Id, Location, LocationRenderObj, Object, Visual, VisualRenderObj};

#[derive(Debug)]
pub enum Change<T> {
Expand All @@ -25,7 +25,9 @@ impl SceneChange {
Some((TypeId::of::<geometry::Matrix4>(), *id))
}
SceneChange::Visual(Change::Delete(id)) => Some((TypeId::of::<Visual>(), *id)),
_ => None,
SceneChange::Location(Change::Delete(id)) => Some((TypeId::of::<Location>(), *id)),
// .. to prevent missing new cases:
SceneChange::Matrix(_) | SceneChange::Location(_) | SceneChange::Visual(_) => None,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion scene/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ pub trait Object: Sized {
fn split(self) -> (Self::Keep, Self::Change);
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct Handle<T: Object> {
inner: Rc<InnerHandle<T>>,
}

impl<T: Object> Clone for Handle<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}

impl<T: Object> Handle<T> {
pub(crate) fn new(id: Id, value: T, change_tracker: Rc<RefCell<ChangeTracker>>) -> Self {
let (pinned, uploaded) = T::split(value);
Expand Down
13 changes: 5 additions & 8 deletions scene/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,23 @@ pub struct Visual {

#[derive(Debug)]
pub struct VisualRenderObj {
pub position: Id,
pub location: Id,
pub shapes: Vec<Shape>,
}

impl Object for Visual {
// We keep the position handle here.
// We keep the location handle here.
type Keep = Handle<Location>;
// And upload the render shape.
type Change = VisualRenderObj;

fn split(self) -> (Self::Keep, Self::Change) {
let Visual {
location: position,
shapes,
} = self;
let Visual { location, shapes } = self;
let shape = VisualRenderObj {
position: position.id(),
location: location.id(),
shapes,
};
(position, shape)
(location, shape)
}

fn promote_change(change: Change<Self::Change>) -> SceneChange {
Expand Down

0 comments on commit 0d77a65

Please sign in to comment.