Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit 9fac17b

Browse files
committed
Refactoring, WASM target fails to build
1 parent 811c895 commit 9fac17b

File tree

9 files changed

+248
-148
lines changed

9 files changed

+248
-148
lines changed

lib/core/src/display/mesh_registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::data::function::callback::*;
55
use crate::display::symbol::attribute as attr;
66
use crate::display::symbol::attribute::IsAttribute;
77
use crate::display::symbol::attribute::Shape;
8-
use crate::display::symbol::attribute::SharedAttribute;
98
use crate::display::symbol::mesh;
109
use crate::system::web::fmt;
1110
use crate::system::web::group;
@@ -491,6 +490,7 @@ pub struct MeshRegistry <OnDirty> {
491490
pub type MeshID = usize;
492491
pub type MeshDirty <OnDirty> = dirty::SharedSet<MeshID, OnDirty>;
493492

493+
pub type AttributeIndex <T, Callback> = mesh::AttributeIndex<T, Closure_mesh_on_dirty<Callback>>;
494494
pub type Mesh <OnDirty> = mesh::Mesh <Closure_mesh_on_dirty<OnDirty>>;
495495
pub type Geometry <OnDirty> = mesh::Geometry <Closure_mesh_on_dirty<OnDirty>>;
496496
pub type Scopes <OnDirty> = mesh::Scopes <Closure_mesh_on_dirty<OnDirty>>;

lib/core/src/display/symbol/attribute.rs

Lines changed: 105 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ type Dim <T> = <T as Shape>::Dim;
113113

114114
// === Shapes for numbers ===
115115

116+
impl Shape for i32 {
117+
type Item = Self;
118+
type Dim = U1;
119+
120+
fn empty () -> Self { 0 }
121+
fn from_buffer (buffer: & [Self::Item]) -> & [Self] { buffer }
122+
fn from_buffer_mut (buffer: &mut [Self::Item]) -> &mut [Self] { buffer }
123+
}
124+
116125
impl Shape for f32 {
117126
type Item = Self;
118127
type Dim = U1;
@@ -289,6 +298,10 @@ Attribute<T, OnSet, OnResize> {
289298
let logger = bldr._logger.unwrap_or_else(default);
290299
Self::new_from(buffer, logger, on_set, on_resize)
291300
}
301+
302+
pub fn builder() -> Builder<T> {
303+
default()
304+
}
292305
}
293306

294307
impl<T: Shape, OnSet, OnResize>
@@ -310,70 +323,64 @@ Attribute<T, OnSet, OnResize> {
310323
}
311324
}
312325

313-
impl<T: Shape>
314-
Attribute<T, NoCallback, NoCallback> {
315-
pub fn builder() -> Builder<T> {
316-
default()
317-
}
318-
}
319326

320327

321-
// =======================
322-
// === SharedAttribute ===
323-
// =======================
328+
// // =======================
329+
// // === SharedAttribute ===
330+
// // =======================
324331

325-
// === Definition ===
332+
// // === Definition ===
326333

327-
#[derive(Shrinkwrap)]
328-
#[derive(Derivative)]
329-
#[derivative(Debug(bound="T:Debug"))]
330-
pub struct SharedAttribute<T: Shape, OnSet, OnResize> {
331-
pub data: Shared<Attribute<T, OnSet, OnResize>>
332-
}
334+
// #[derive(Shrinkwrap)]
335+
// #[derive(Derivative)]
336+
// #[derivative(Debug(bound="T:Debug"))]
337+
// pub struct SharedAttribute<T: Shape, OnSet, OnResize> {
338+
// pub data: Shared<Attribute<T, OnSet, OnResize>>
339+
// }
333340

334-
impl<T: Shape, OnSet: Callback0, OnResize: Callback0> SharedAttribute<T, OnSet, OnResize> {
335-
pub fn new(logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
336-
Self::new_from(default(), logger, on_set, on_resize)
337-
}
341+
// impl<T: Shape, OnSet: Callback0, OnResize: Callback0> SharedAttribute<T, OnSet, OnResize> {
342+
// pub fn new(logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
343+
// Self::new_from(default(), logger, on_set, on_resize)
344+
// }
338345

339-
pub fn new_from(buffer: Vec<T>, logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
340-
let data = Shared::new(Attribute::new_from(buffer, logger, on_set, on_resize));
341-
Self { data }
342-
}
346+
// pub fn new_from(buffer: Vec<T>, logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
347+
// let data = Shared::new(Attribute::new_from(buffer, logger, on_set, on_resize));
348+
// Self { data }
349+
// }
343350

344-
pub fn build(builder: Builder<T>, on_set: OnSet, on_resize: OnResize) -> Self {
345-
let data = Shared::new(Attribute::build(builder, on_set, on_resize));
346-
Self { data }
347-
}
351+
// pub fn build(builder: Builder<T>, on_set: OnSet, on_resize: OnResize) -> Self {
352+
// let data = Shared::new(Attribute::build(builder, on_set, on_resize));
353+
// Self { data }
354+
// }
348355

349-
pub fn builder() -> Builder<T> {
350-
default()
351-
}
352-
}
356+
// pub fn builder() -> Builder<T> {
357+
// default()
358+
// }
359+
// }
353360

354-
impl<T: Shape, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
355-
pub fn clone_ref(&self) -> Self {
356-
Self { data: self.data.clone_ref() }
357-
}
361+
// impl<T: Shape, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
362+
// pub fn clone_ref(&self) -> Self {
363+
// Self { data: self.data.clone_ref() }
364+
// }
358365

359-
pub fn len(&self) -> usize {
360-
self.data.borrow().len()
361-
}
362-
}
366+
// pub fn len(&self) -> usize {
367+
// self.data.borrow().len()
368+
// }
369+
// }
363370

364-
impl<T: AddElementCtx, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
365-
pub fn add_element(&self) {
366-
self.data.borrow_mut().add_element()
367-
}
368-
}
371+
// impl<T: AddElementCtx, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
372+
// pub fn add_element(&self) {
373+
// self.data.borrow_mut().add_element()
374+
// }
375+
// }
369376

370-
impl<T: Shape, OnSet, OnResize, I: SliceIndex<[T]>> Index<I> for SharedAttribute<T, OnSet, OnResize> {
371-
type Output = I::Output;
372-
#[inline]
373-
fn index(&self, index: I) -> &Self::Output {
374-
&self.data[index]
375-
}
376-
}
377+
// impl<T: Shape, OnSet, OnResize, I: SliceIndex<[T]>> Index<I> for SharedAttribute<T, OnSet, OnResize> {
378+
// type Output = I::Output;
379+
// #[inline]
380+
// fn index(&self, index: I) -> &Self::Output {
381+
// &self.data[index]
382+
// }
383+
// }
377384

378385
// impl<T: Shape, OnDirty> Deref for SharedAttribute<T, OnDirty> {
379386
// type Target = Ref<Attribute<T, OnDirty>>;
@@ -420,6 +427,9 @@ impl<T: Shape, OnSet, OnResize, I: SliceIndex<[T]>> Index<I> for SharedAttribute
420427

421428
use enum_dispatch::*;
422429

430+
#[derive(Debug)]
431+
pub struct BadVariant;
432+
423433

424434
macro_rules! cartesian_impl {
425435
($out:tt [] $b:tt $init_b:tt, $f:ident) => {
@@ -443,17 +453,47 @@ macro_rules! cartesian {
443453
}
444454

445455
macro_rules! mk_any_shape_impl {
446-
([$(($base:ident, $param:ident)),*,]) => {
447-
paste::item! {
448-
#[enum_dispatch(IsAttribute)]
449-
#[derive(Derivative)]
450-
#[derivative(Debug(bound=""))]
451-
pub enum AnyAttribute<OnSet, OnResize> {
452-
$([<Variant $base For $param>](SharedAttribute<$base<$param>, OnSet, OnResize>),)*
453-
}
456+
([$(($base:ident, $param:ident)),*,]) => { paste::item! {
457+
#[enum_dispatch(IsAttribute)]
458+
#[derive(Derivative)]
459+
#[derivative(Debug(bound=""))]
460+
pub enum AnyAttribute<OnSet, OnResize> {
461+
$( [<Variant $base For $param>]
462+
(Attribute<$base<$param>, OnSet, OnResize>),
463+
)*
464+
}
465+
466+
$( /////////////////////////////////////////////////////////////////////
467+
468+
impl<'t, T, S>
469+
TryFrom<&'t AnyAttribute<T, S>>
470+
for &'t Attribute<$base<$param>, T, S> {
471+
type Error = BadVariant;
472+
fn try_from(v: &'t AnyAttribute<T, S>)
473+
-> Result <&'t Attribute<$base<$param>, T, S>, Self::Error> {
474+
match v {
475+
AnyAttribute::[<Variant $base For $param>](a) => Ok(a),
476+
_ => Err(BadVariant)
477+
}
478+
}
479+
}
480+
481+
impl<'t, T, S>
482+
TryFrom<&'t mut AnyAttribute<T, S>>
483+
for &'t mut Attribute<$base<$param>, T, S> {
484+
type Error = BadVariant;
485+
fn try_from(v: &'t mut AnyAttribute<T, S>)
486+
-> Result <&'t mut Attribute<$base<$param>, T, S>, Self::Error> {
487+
match v {
488+
AnyAttribute::[<Variant $base For $param>](a) => Ok(a),
489+
_ => Err(BadVariant)
490+
}
491+
}
454492
}
493+
494+
)* /////////////////////////////////////////////////////////////////////
455495
}
456-
}
496+
}}
457497

458498
macro_rules! mk_any_shape {
459499
($bases:tt, $params:tt) => {
@@ -462,20 +502,19 @@ macro_rules! mk_any_shape {
462502
}
463503

464504
type Identity<T> = T;
465-
mk_any_shape!([Identity, Vector2, Vector3, Vector4], [f32]);
505+
mk_any_shape!([Identity, Vector2, Vector3, Vector4], [f32, i32]);
506+
507+
466508

467509

468510

469511
#[enum_dispatch]
470512
pub trait IsAttribute<OnSet, OnResize> {
471-
fn add_element(&self);
513+
fn add_element(&mut self);
472514
fn len(&self) -> usize;
473515
}
474516

475517

476-
// impl IsShape for Vector2<f32>{}
477-
// impl IsShape for Vector3<f32>{}
478-
479518

480519

481520

lib/core/src/display/symbol/geometry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct ScopesDirtyStatus {
5656

5757
// === Types ===
5858

59+
pub type AttributeIndex <T, Callback> = scope::AttributeIndex<T, Closure_scope_on_change<Callback>>;
5960
pub type ScopesDirty <Callback> = SharedCustom<ScopesDirtyStatus, Callback>;
6061
pub type AttributeScope <Callback> = Scope<Closure_scope_on_change<Callback>>;
6162
pub type UniformScope <Callback> = Scope<Closure_scope_on_change<Callback>>; // FIXME

lib/core/src/display/symbol/mesh.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct Mesh<OnDirty> {
3636

3737
// === Types ===
3838

39+
pub type AttributeIndex <T, Callback> = geometry::AttributeIndex<T, Closure_geometry_on_change<Callback>>;
3940
pub type GeometryDirty <Callback> = SharedBool<Callback>;
4041
pub type Geometry <Callback> = geometry::Geometry <Closure_geometry_on_change<Callback>>;
4142
pub type Scopes <Callback> = geometry::Scopes <Closure_geometry_on_change<Callback>>;

0 commit comments

Comments
 (0)