Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Transform serialization and Transform system event loop. #1564

Merged
merged 2 commits into from May 4, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -36,6 +36,7 @@ thread_profiler = { version = "0.3" , optional = true }

[dev-dependencies]
amethyst = { path = "..", version = "0.10.0" }
ron = "0.5.1"

[features]
profiler = [ "thread_profiler/thread_profiler" ]
@@ -1,11 +1,12 @@
//! Local transform component.
use std::fmt;
use std::marker::PhantomData;

use crate::ecs::prelude::{Component, DenseVecStorage, FlaggedStorage};
use crate::math::{
self as na, Isometry3, Matrix4, Quaternion, RealField, Translation3, Unit, UnitQuaternion,
Vector3,
use std::{fmt, marker::PhantomData};

use crate::{
ecs::prelude::{Component, DenseVecStorage, FlaggedStorage},
math::{
self as na, Isometry3, Matrix4, Quaternion, RealField, Translation3, Unit, UnitQuaternion,
Vector3,
},
};
use serde::{
de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor},
@@ -596,10 +597,10 @@ impl<'de, N: RealField + Deserialize<'de>> Deserialize<'de> for Transform<N> {
let isometry = Isometry3::from_parts(
Translation3::new(translation[0], translation[1], translation[2]),
Unit::new_normalize(Quaternion::new(
rotation[3],
rotation[0],
rotation[1],
rotation[2],
rotation[3],
)),
);
let scale = scale.into();
@@ -649,10 +650,10 @@ impl<'de, N: RealField + Deserialize<'de>> Deserialize<'de> for Transform<N> {
let isometry = Isometry3::from_parts(
Translation3::new(translation[0], translation[1], translation[2]),
Unit::new_normalize(Quaternion::new(
rotation[3],
rotation[0],
rotation[1],
rotation[2],
rotation[3],
)),
);
let scale = scale.into();
@@ -750,6 +751,22 @@ mod tests {
);
}

#[test]
fn ser_deser() {
let mut transform = Transform::<f32>::default();
transform.set_translation_xyz(1.0, 2.0, 3.0);
transform.set_scale(Vector3::new(4.0, 5.0, 6.0));
transform.set_rotation(
UnitQuaternion::rotation_between(&Vector3::new(-1., 1., 2.), &Vector3::new(1., 0., 0.))
.unwrap(),
);
let s: String =
ron::ser::to_string_pretty(&transform, ron::ser::PrettyConfig::default()).unwrap();
let transform2: Transform<f32> = ron::de::from_str(&s).unwrap();

assert_eq!(transform, transform2);
}

#[test]
fn is_finite() {
let mut transform = Transform::default();
@@ -8,8 +8,10 @@ use crate::ecs::prelude::{
};
use hibitset::BitSet;

use crate::math::RealField;
use crate::transform::{HierarchyEvent, Parent, ParentHierarchy, Transform};
use crate::{
math::RealField,
transform::{HierarchyEvent, Parent, ParentHierarchy, Transform},
};

#[cfg(feature = "profiler")]
use thread_profiler::profile_scope;
@@ -121,6 +123,11 @@ impl<'a, N: RealField> System<'a> for TransformSystem<N> {
}
}
}

// Clear the local event reader.
locals
.channel()
.read(self.locals_events_id.as_mut().expect("unreachable"));
}

fn setup(&mut self, res: &mut Resources) {
@@ -471,4 +478,50 @@ mod tests {
assert_eq!(world.is_alive(e4), false);
assert_eq!(world.is_alive(e5), false);
}

#[test]
fn events() {
let (mut world, mut hs, mut system) = transform_world();

let e1 = world
.create_entity()
.with(Transform::<f32>::default())
.build();

let e2 = world
.create_entity()
.with(Transform::<f32>::default())
.with(Parent { entity: e1 })
.build();

world
.create_entity()
.with(Transform::<f32>::default())
.with(Parent { entity: e2 })
.build();

let mut transform_reader = {
let mut transforms = world.write_storage::<Transform<f32>>();
transforms.register_reader()
};

hs.run_now(&mut world.res);
system.run_now(&mut world.res);
world.maintain();

{
let transforms = world.write_storage::<Transform<f32>>();
for _component_event in transforms.channel().read(&mut transform_reader) {}
}

hs.run_now(&mut world.res);
system.run_now(&mut world.res);
world.maintain();
{
let transforms = world.write_storage::<Transform<f32>>();
for _component_event in transforms.channel().read(&mut transform_reader) {
panic!("Found transform event when there should not be.")
}
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.