Skip to content

Commit

Permalink
Rendy UI pass without text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Frizi committed May 11, 2019
1 parent 8512fa5 commit 80edba6
Show file tree
Hide file tree
Showing 85 changed files with 1,338 additions and 1,319 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ profiler = [
"amethyst_controls/profiler",
"amethyst_input/profiler",
"amethyst_locale/profiler",
"amethyst_renderer/profiler",
"amethyst_rendy/profiler",
"amethyst_ui/profiler",
"amethyst_utils/profiler",
Expand All @@ -75,7 +74,6 @@ nightly = [
"amethyst_core/nightly",
"amethyst_controls/nightly",
"amethyst_network/nightly",
"amethyst_renderer/nightly",
"amethyst_rendy/nightly",
"amethyst_input/nightly",
"amethyst_ui/nightly",
Expand Down Expand Up @@ -116,7 +114,6 @@ amethyst_gltf = { path = "amethyst_gltf", version = "0.5.0", optional = true }
amethyst_network = { path = "amethyst_network", version = "0.3.0", optional = true }
amethyst_locale = { path = "amethyst_locale", version = "0.4.0", optional = true }
amethyst_rendy = { path = "amethyst_rendy", optional = true }
amethyst_renderer = { path = "amethyst_renderer" }
amethyst_input = { path = "amethyst_input", version = "0.6.0" }
amethyst_ui = { path = "amethyst_ui", version = "0.5.0" }
amethyst_utils = { path = "amethyst_utils", version = "0.5.0" }
Expand Down
2 changes: 1 addition & 1 deletion amethyst_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ amethyst_assets = { path = "../amethyst_assets/", version = "0.6.0" }
amethyst_core = { path = "../amethyst_core/", version = "0.5.0" }
amethyst_error = { path = "../amethyst_error/", version = "0.1.0" }
amethyst_derive = { path = "../amethyst_derive", version = "0.3.0" }
amethyst_rendy = { path = "../amethyst_rendy/", version = "0.10.1" }
amethyst_rendy = { path = "../amethyst_rendy/", version = "0.1.0" }
derivative = "1.0"
fnv = "1"
hibitset = { version = "0.5.1", features = ["parallel"] }
Expand Down
2 changes: 1 addition & 1 deletion amethyst_assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ err-derive = "0.1"
objekt = "0.1.2"
erased-serde = "0.3.9"
inventory = "0.1.3"
lazy_static = "1.3.0"
lazy_static = "1.3"

[dev-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion amethyst_controls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ amethyst_assets = { path = "../amethyst_assets", version = "0.6.0" }
amethyst_core = { path = "../amethyst_core", version = "0.5.0" }
amethyst_error = { path = "../amethyst_error", version = "0.1.0" }
amethyst_input = { path = "../amethyst_input", version = "0.6.0" }
amethyst_renderer = { path = "../amethyst_renderer", version = "0.10.0" }
serde = { version = "1.0", features = ["derive"] }
winit = { version = "0.18", features = ["serde"] }
log = "0.4.6"

thread_profiler = { version = "0.3", optional = true }

Expand Down
50 changes: 20 additions & 30 deletions amethyst_controls/src/bundles.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::{hash::Hash, marker::PhantomData};
use std::marker::PhantomData;

use amethyst_core::{bundle::SystemBundle, ecs::prelude::DispatcherBuilder, math::one, Float};
use amethyst_error::Error;
use amethyst_input::BindingTypes;

use super::*;

/// The bundle that creates a flying movement system.
///
/// Note: Will not actually create a moving entity. It will only register the needed resources and
/// systems. The generic parameters `A` and `B` are the ones used in `InputHandler<A,B>`.
/// systems.
///
/// You might want to add `"fly_movement"` and `"free_rotation"` as dependencies of the
/// `TransformSystem` in order to apply changes made by these systems in the same frame.
/// Adding this bundle will grab the mouse, hide it and keep it centered.
///
/// # Type parameters
///
/// * `A`: This is the key the `InputHandler` is using for axes. Often, this is a `String`.
/// * `B`: This is the key the `InputHandler` is using for actions. Often, this is a `String`.
/// * `T`: This are the keys the `InputHandler` is using for axes and actions. Often, this is a `StringBindings`.
///
/// # Systems
///
Expand All @@ -27,22 +27,21 @@ use super::*;
/// * `FreeRotationSystem`
/// * `MouseFocusUpdateSystem`
/// * `CursorHideSystem`
pub struct FlyControlBundle<A, B> {
pub struct FlyControlBundle<T: BindingTypes> {
sensitivity_x: f32,
sensitivity_y: f32,
speed: Float,
right_input_axis: Option<A>,
up_input_axis: Option<A>,
forward_input_axis: Option<A>,
_marker: PhantomData<B>,
right_input_axis: Option<T::Axis>,
up_input_axis: Option<T::Axis>,
forward_input_axis: Option<T::Axis>,
}

impl<A, B> FlyControlBundle<A, B> {
impl<T: BindingTypes> FlyControlBundle<T> {
/// Builds a new fly control bundle using the provided axes as controls.
pub fn new(
right_input_axis: Option<A>,
up_input_axis: Option<A>,
forward_input_axis: Option<A>,
right_input_axis: Option<T::Axis>,
up_input_axis: Option<T::Axis>,
forward_input_axis: Option<T::Axis>,
) -> Self {
FlyControlBundle {
sensitivity_x: 1.0,
Expand All @@ -51,7 +50,6 @@ impl<A, B> FlyControlBundle<A, B> {
right_input_axis,
up_input_axis,
forward_input_axis,
_marker: PhantomData,
}
}

Expand All @@ -69,14 +67,10 @@ impl<A, B> FlyControlBundle<A, B> {
}
}

impl<'a, 'b, A, B> SystemBundle<'a, 'b> for FlyControlBundle<A, B>
where
A: Send + Sync + Hash + Eq + Clone + 'static,
B: Send + Sync + Hash + Eq + Clone + 'static,
{
impl<'a, 'b, T: BindingTypes> SystemBundle<'a, 'b> for FlyControlBundle<T> {
fn build(self, builder: &mut DispatcherBuilder<'a, 'b>) -> Result<(), Error> {
builder.add(
FlyMovementSystem::<A, B>::new(
FlyMovementSystem::<T>::new(
self.speed,
self.right_input_axis,
self.up_input_axis,
Expand All @@ -86,7 +80,7 @@ where
&[],
);
builder.add(
FreeRotationSystem::<A, B>::new(self.sensitivity_x, self.sensitivity_y),
FreeRotationSystem::new(self.sensitivity_x, self.sensitivity_y),
"free_rotation",
&[],
);
Expand All @@ -107,13 +101,13 @@ where
/// Adding this bundle will grab the mouse, hide it and keep it centered.
///
/// See the `arc_ball_camera` example to see how to use the arc ball camera.
pub struct ArcBallControlBundle<A, B> {
pub struct ArcBallControlBundle<T: BindingTypes> {
sensitivity_x: f32,
sensitivity_y: f32,
_marker: PhantomData<(A, B)>,
_marker: PhantomData<T>,
}

impl<A, B> ArcBallControlBundle<A, B> {
impl<T: BindingTypes> ArcBallControlBundle<T> {
/// Builds a new `ArcBallControlBundle` with a default sensitivity of 1.0
pub fn new() -> Self {
ArcBallControlBundle {
Expand All @@ -131,15 +125,11 @@ impl<A, B> ArcBallControlBundle<A, B> {
}
}

impl<'a, 'b, A, B> SystemBundle<'a, 'b> for ArcBallControlBundle<A, B>
where
A: Send + Sync + Hash + Eq + Clone + 'static,
B: Send + Sync + Hash + Eq + Clone + 'static,
{
impl<'a, 'b, T: BindingTypes> SystemBundle<'a, 'b> for ArcBallControlBundle<T> {
fn build(self, builder: &mut DispatcherBuilder<'a, 'b>) -> Result<(), Error> {
builder.add(ArcBallRotationSystem::default(), "arc_ball_rotation", &[]);
builder.add(
FreeRotationSystem::<A, B>::new(self.sensitivity_x, self.sensitivity_y),
FreeRotationSystem::new(self.sensitivity_x, self.sensitivity_y),
"free_rotation",
&[],
);
Expand Down
104 changes: 42 additions & 62 deletions amethyst_controls/src/systems.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,64 @@
use std::{hash::Hash, marker::PhantomData};

use winit::{DeviceEvent, Event, WindowEvent};

use crate::{
components::{ArcBallControlTag, FlyControlTag},
resources::{HideCursor, WindowFocus},
};
use amethyst_core::{
ecs::prelude::{Join, Read, ReadStorage, Resources, System, Write, WriteStorage},
ecs::prelude::{Join, Read, ReadExpect, ReadStorage, Resources, System, Write, WriteStorage},
math::{convert, Unit, Vector3},
shrev::{EventChannel, ReaderId},
timing::Time,
transform::Transform,
Float,
};
use amethyst_input::{get_input_axis_simple, InputHandler};
use amethyst_renderer::WindowMessages;
use amethyst_input::{get_input_axis_simple, BindingTypes, InputHandler};
use std::sync::Arc;
use winit::{DeviceEvent, Event, Window, WindowEvent};

/// The system that manages the fly movement.
///
/// # Type parameters
///
/// * `A`: This is the key the `InputHandler` is using for axes. Often, this is a `String`.
/// * `B`: This is the key the `InputHandler` is using for actions. Often, this is a `String`.
pub struct FlyMovementSystem<A, B> {
/// * `T`: This are the keys the `InputHandler` is using for axes and actions. Often, this is a `StringBindings`.
pub struct FlyMovementSystem<T: BindingTypes> {
/// The movement speed of the movement in units per second.
speed: Float,
/// The name of the input axis to locally move in the x coordinates.
right_input_axis: Option<A>,
right_input_axis: Option<T::Axis>,
/// The name of the input axis to locally move in the y coordinates.
up_input_axis: Option<A>,
up_input_axis: Option<T::Axis>,
/// The name of the input axis to locally move in the z coordinates.
forward_input_axis: Option<A>,
_marker: PhantomData<B>,
forward_input_axis: Option<T::Axis>,
}

impl<A, B> FlyMovementSystem<A, B>
where
A: Send + Sync + Hash + Eq + Clone + 'static,
B: Send + Sync + Hash + Eq + Clone + 'static,
{
impl<T: BindingTypes> FlyMovementSystem<T> {
/// Builds a new `FlyMovementSystem` using the provided speeds and axis controls.
pub fn new<N: Into<Float>>(
speed: N,
right_input_axis: Option<A>,
up_input_axis: Option<A>,
forward_input_axis: Option<A>,
right_input_axis: Option<T::Axis>,
up_input_axis: Option<T::Axis>,
forward_input_axis: Option<T::Axis>,
) -> Self {
FlyMovementSystem {
speed: speed.into(),
right_input_axis,
up_input_axis,
forward_input_axis,
_marker: PhantomData,
}
}
}

impl<'a, A, B> System<'a> for FlyMovementSystem<A, B>
where
A: Send + Sync + Hash + Eq + Clone + 'static,
B: Send + Sync + Hash + Eq + Clone + 'static,
{
impl<'a, T: BindingTypes> System<'a> for FlyMovementSystem<T> {
type SystemData = (
Read<'a, Time>,
WriteStorage<'a, Transform>,
Read<'a, InputHandler<A, B>>,
Read<'a, InputHandler<T>>,
ReadStorage<'a, FlyControlTag>,
);

fn run(&mut self, (time, mut transform, input, tag): Self::SystemData) {
let x = get_input_axis_simple(&self.right_input_axis, &input);
let y = get_input_axis_simple(&self.up_input_axis, &input);
let z = get_input_axis_simple(&self.forward_input_axis, &input);
let x: Float = get_input_axis_simple(&self.right_input_axis, &input).into();
let y: Float = get_input_axis_simple(&self.up_input_axis, &input).into();
let z: Float = get_input_axis_simple(&self.forward_input_axis, &input).into();

if let Some(dir) = Unit::try_new(Vector3::new(x, y, z), convert(1.0e-6)) {
for (transform, _) in (&mut transform, &tag).join() {
Expand Down Expand Up @@ -129,34 +115,25 @@ impl<'a> System<'a> for ArcBallRotationSystem {
///
/// # Type parameters
///
/// * `A`: This is the key the `InputHandler` is using for axes. Often, this is a `String`.
/// * `B`: This is the key the `InputHandler` is using for actions. Often, this is a `String`.
pub struct FreeRotationSystem<A, B> {
/// * `T`: This are the keys the `InputHandler` is using for axes and actions. Often, this is a `StringBindings`.
pub struct FreeRotationSystem {
sensitivity_x: f32,
sensitivity_y: f32,
_marker1: PhantomData<A>,
_marker2: PhantomData<B>,
event_reader: Option<ReaderId<Event>>,
}

impl<A, B> FreeRotationSystem<A, B> {
impl FreeRotationSystem {
/// Builds a new `FreeRotationSystem` with the specified mouse sensitivity values.
pub fn new(sensitivity_x: f32, sensitivity_y: f32) -> Self {
FreeRotationSystem {
sensitivity_x,
sensitivity_y,
_marker1: PhantomData,
_marker2: PhantomData,
event_reader: None,
}
}
}

impl<'a, A, B> System<'a> for FreeRotationSystem<A, B>
where
A: Send + Sync + Hash + Eq + Clone + 'static,
B: Send + Sync + Hash + Eq + Clone + 'static,
{
impl<'a> System<'a> for FreeRotationSystem {
type SystemData = (
Read<'a, EventChannel<Event>>,
WriteStorage<'a, Transform>,
Expand Down Expand Up @@ -246,37 +223,40 @@ impl CursorHideSystem {

impl<'a> System<'a> for CursorHideSystem {
type SystemData = (
Write<'a, WindowMessages>,
ReadExpect<'a, Arc<Window>>,
Read<'a, HideCursor>,
Read<'a, WindowFocus>,
);

fn run(&mut self, (mut msg, hide, focus): Self::SystemData) {
use amethyst_renderer::mouse::*;
if focus.is_focused {
if !self.is_hidden && hide.hide {
grab_cursor(&mut msg);
hide_cursor(&mut msg);
self.is_hidden = true;
} else if self.is_hidden && !hide.hide {
release_cursor(&mut msg);
self.is_hidden = false;
fn run(&mut self, (win, hide, focus): Self::SystemData) {
let should_be_hidden = focus.is_focused && hide.hide;
if !self.is_hidden && should_be_hidden {
if let Err(err) = win.grab_cursor(true) {
log::error!("Unable to grab the cursor. Error: {:?}", err);
}
win.hide_cursor(true);
self.is_hidden = true;
} else if self.is_hidden && !should_be_hidden {
if let Err(err) = win.grab_cursor(false) {
log::error!("Unable to release the cursor. Error: {:?}", err);
}
} else if self.is_hidden {
release_cursor(&mut msg);
win.hide_cursor(false);
self.is_hidden = false;
}
}

fn setup(&mut self, res: &mut Resources) {
use amethyst_core::ecs::prelude::SystemData;
use amethyst_renderer::mouse::*;

Self::SystemData::setup(res);

let mut msg = res.fetch_mut::<WindowMessages>();
grab_cursor(&mut msg);
hide_cursor(&mut msg);
let win = res.fetch::<Arc<Window>>();

if let Err(err) = win.grab_cursor(true) {
log::error!("Unable to grab the cursor. Error: {:?}", err);
}
win.hide_cursor(true);

self.is_hidden = true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use amethyst_core::ecs::{
use crate::ecs::{
prelude::Component,
storage::{FlaggedStorage, NullStorage},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use amethyst_core::{
use crate::{
ecs::prelude::{
BitSet, ComponentEvent, ReadExpect, ReadStorage, ReaderId, Resources, System, WriteStorage,
},
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<'a> System<'a> for HideHierarchySystem {
}

fn setup(&mut self, res: &mut Resources) {
use amethyst_core::ecs::prelude::SystemData;
use crate::ecs::prelude::SystemData;
Self::SystemData::setup(res);
// This fetch_mut panics if `ParentHierarchy` is not set up yet, hence the dependency on "parent_hierarchy_system"
self.parent_events_id = Some(res.fetch_mut::<ParentHierarchy>().track());
Expand Down
Loading

0 comments on commit 80edba6

Please sign in to comment.