Skip to content

Commit

Permalink
feat: boolean input state
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Dec 7, 2024
1 parent a2a5ad0 commit c67de88
Show file tree
Hide file tree
Showing 43 changed files with 398 additions and 333 deletions.
13 changes: 6 additions & 7 deletions ivy-assets/src/handle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::{self};

use std::hash::Hash;

use std::sync::{Arc, Weak};
use std::{
cmp::Ordering,
hash::Hash,
sync::{Arc, Weak},
{self},
};

use super::AssetId;

Expand Down Expand Up @@ -103,7 +103,6 @@ impl<T: ?Sized> Asset<T> {
pub fn id(&self) -> AssetId {
self.id
}

}

impl<T: ?Sized> Hash for Asset<T> {
Expand Down
3 changes: 1 addition & 2 deletions ivy-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,8 @@ impl<T, E> Future for AssetLoadFuture<T, E> {
mod tests {
use std::{convert::Infallible, path::Path};

use crate::service::FsAssetError;

use super::*;
use crate::service::FsAssetError;

#[test]
fn asset_cache() {
Expand Down
10 changes: 6 additions & 4 deletions ivy-assets/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::convert::Infallible;
use std::fs::File;
use std::io::{self, BufReader, Read};
use std::path::{Path, PathBuf};
use std::{
convert::Infallible,
fs::File,
io::{self, BufReader, Read},
path::{Path, PathBuf},
};

use futures::AsyncReadExt;
use thiserror::Error;
Expand Down
1 change: 0 additions & 1 deletion ivy-core/src/app/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use self::driver::{DefaultDriver, Driver};

use super::*;

pub struct AppBuilder {
Expand Down
7 changes: 2 additions & 5 deletions ivy-core/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ use std::time::Duration;

pub use builder::*;
pub use event::*;

use flax::World;
use ivy_assets::{service::FileSystemMapService, AssetCache};

use self::driver::Driver;
use crate::{
components::{self, engine},
layer::events::{Event, EventRegistry},
Layer, LayerDyn,
};

use ivy_assets::{service::FileSystemMapService, AssetCache};

use self::driver::Driver;

pub struct App {
name: String,

Expand Down
1 change: 1 addition & 0 deletions ivy-core/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ flax::component! {

pub gizmos: Gizmos,
pub async_commandbuffer: AsyncCommandBuffer,
pub request_capture_mouse: bool,

pub time: Time,
pub delta_time: Duration,
Expand Down
3 changes: 2 additions & 1 deletion ivy-core/src/dir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Context;
use std::env;

use anyhow::Context;

// Set directory to nth parent of current executable
pub fn normalize_dir(nth: usize) -> anyhow::Result<()> {
let current_exe = env::current_exe()?
Expand Down
3 changes: 2 additions & 1 deletion ivy-core/src/extent.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use glam::Vec2;
use std::{
fmt::Display,
ops::{Add, Mul},
};

use glam::Vec2;

/// Represents a width and height.
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
3 changes: 1 addition & 2 deletions ivy-core/src/gizmos/traits.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use glam::Vec3;

use crate::{Color, ColorExt};

use super::{GizmosSection, Line, Sphere, DEFAULT_RADIUS};
use crate::{Color, ColorExt};

pub trait DrawGizmos {
/// Draw a set of gizmos using the current section
Expand Down
16 changes: 10 additions & 6 deletions ivy-core/src/layer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#![allow(non_snake_case)]
use std::time::{Duration, Instant};

use crate::components::{async_commandbuffer, engine, gizmos, time};
use crate::gizmos::Gizmos;
use crate::systems::update_transform_system;
use crate::time::Time;
use crate::AsyncCommandBuffer;
use crate::{app::TickEvent, systems::apply_async_commandbuffers};
use downcast_rs::{impl_downcast, Downcast};
use flax::{Entity, Schedule, World};
use ivy_assets::AssetCache;

use crate::{
app::TickEvent,
components::{async_commandbuffer, engine, gizmos, request_capture_mouse, time},
gizmos::Gizmos,
systems::{apply_async_commandbuffers, update_transform_system},
time::Time,
AsyncCommandBuffer,
};

pub mod events;

use self::events::{EventRegisterContext, EventRegistry};
Expand Down Expand Up @@ -101,6 +104,7 @@ impl Layer for EngineLayer {
.set(async_commandbuffer(), self.cmd.clone())
.set(gizmos(), Gizmos::new())
.set(time(), Time::new(Instant::now(), Duration::ZERO))
.set(request_capture_mouse(), false)
.append_to(world, engine())?;

events.subscribe(|this, world, _, _: &TickEvent| {
Expand Down
2 changes: 1 addition & 1 deletion ivy-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pub mod layer;
pub mod macros;
pub mod subscribers;
mod systems;
pub mod time;
mod updatable;
pub mod update_layer;
pub mod time;

use std::f32::consts::PI;

Expand Down
8 changes: 8 additions & 0 deletions ivy-core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ impl Time {
elapsed,
}
}

pub fn start_time(&self) -> Instant {
self.start_time
}

pub fn elapsed(&self) -> Duration {
self.elapsed
}
}
38 changes: 22 additions & 16 deletions ivy-game/src/free_camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use flax::{BoxedSystem, Component, Entity, FetchExt, ComponentMut, Query, QueryBorrow, System, World};
use flax::{
BoxedSystem, Component, ComponentMut, Entity, FetchExt, Query, QueryBorrow, System, World,
};
use glam::{vec3, EulerRot, Quat, Vec2, Vec3};
use ivy_assets::AssetCache;
use ivy_core::{
Expand All @@ -9,8 +11,8 @@ use ivy_core::{
use ivy_input::{
components::input_state,
types::{Key, NamedKey},
Action, Axis2D, BindingExt, CursorMoveBinding, InputState, KeyBinding, MouseButtonBinding,
ScrollBinding,
Action, Axis2D, Axis3D, BindingExt, CursorMoveBinding, InputState, KeyBinding,
MouseButtonBinding, ScrollBinding,
};
use ivy_physics::{
components::{angular_velocity, velocity},
Expand All @@ -23,7 +25,7 @@ use ivy_wgpu::{
};

flax::component! {
pub pan_active: i32,
pub pan_active: bool,
pub rotation_input: Vec2,
pub euler_rotation: Vec3,
pub camera_movement: Vec3,
Expand Down Expand Up @@ -59,38 +61,42 @@ pub fn setup_camera() -> flax::EntityBuilder {
move_action.add(
KeyBinding::new(Key::Character("w".into()))
.analog()
.compose(Vec3::Z),
.compose(Axis3D::Z),
);
move_action.add(
KeyBinding::new(Key::Character("a".into()))
.analog()
.compose(-Vec3::X),
.compose(Axis3D::X)
.amplitude(-1.0),
);
move_action.add(
KeyBinding::new(Key::Character("s".into()))
.analog()
.compose(-Vec3::Z),
.compose(Axis3D::Z)
.amplitude(-1.0),
);
move_action.add(
KeyBinding::new(Key::Character("d".into()))
.analog()
.compose(Vec3::X),
.compose(Axis3D::X),
);

move_action.add(
KeyBinding::new(Key::Character("c".into()))
.analog()
.compose(-Vec3::Y),
.compose(Axis3D::Y)
.amplitude(-1.0),
);
move_action.add(
KeyBinding::new(Key::Named(NamedKey::Control))
.analog()
.compose(-Vec3::Y),
.compose(Axis3D::Y)
.amplitude(-1.0),
);
move_action.add(
KeyBinding::new(Key::Named(NamedKey::Space))
.analog()
.compose(Vec3::Y),
.compose(Axis3D::Y),
);

let mut rotate_action = Action::new();
Expand Down Expand Up @@ -138,11 +144,11 @@ fn cursor_lock_system() -> BoxedSystem {
.with_query(Query::new(pan_active()))
.with_query(Query::new(window().as_mut()).with(main_window()))
.build(
|mut query: QueryBorrow<Component<i32>>,
|mut query: QueryBorrow<Component<bool>>,
mut window: QueryBorrow<ComponentMut<WindowHandle>, _>| {
query.iter().for_each(|&pan_active| {
if let Some(window) = window.first() {
window.set_cursor_lock(pan_active > 0);
window.set_cursor_lock(pan_active);
}
});
},
Expand Down Expand Up @@ -170,10 +176,10 @@ fn camera_rotation_input_system() -> BoxedSystem {
rotation().as_mut(),
euler_rotation().as_mut(),
rotation_input(),
pan_active(),
pan_active().eq(true),
)))
.for_each(|(rotation, euler_rotation, rotation_input, &pan_active)| {
*euler_rotation += pan_active as f32 * vec3(rotation_input.y, rotation_input.x, 0.0);
.for_each(|(rotation, euler_rotation, rotation_input, _)| {
*euler_rotation += vec3(rotation_input.y, rotation_input.x, 0.0);
*rotation = Quat::from_euler(EulerRot::YXZ, -euler_rotation.y, -euler_rotation.x, 0.0);
})
.boxed()
Expand Down
24 changes: 16 additions & 8 deletions ivy-game/src/ray_picker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use flax::{
component,
fetch::{entity_refs, EntityRefs, Source},
system, BoxedSystem, CommandBuffer, Component, Entity, Fetch, FetchExt, ComponentMut, Query,
system, BoxedSystem, CommandBuffer, Component, ComponentMut, Entity, Fetch, FetchExt, Query,
QueryBorrow, System, World,
};
use glam::{vec2, vec4, Mat4, Vec2, Vec3, Vec4Swizzles};
Expand Down Expand Up @@ -100,7 +100,11 @@ impl PickingState {
))
.build();

cmd.set(self.manipulator, impulse_joint(hit.collider_id), joint.into());
cmd.set(
self.manipulator,
impulse_joint(hit.collider_id),
joint.into(),
);

self.picked_object = Some((hit.collider_id, anchor, distance));
}
Expand Down Expand Up @@ -136,10 +140,10 @@ impl PickingState {
}

component! {
pick_ray_action: i32,
pick_ray_action: bool,
cursor_position_action: Vec2,
picking_state: PickingState,
ray_distance_modifier: i32,
ray_distance_modifier: f32,
}

pub struct RayPickingPlugin;
Expand All @@ -158,8 +162,12 @@ impl Plugin for RayPickingPlugin {
cursor_position.add(CursorPositionBinding::new(true));

let mut ray_distance_action = Action::new();
ray_distance_action.add(KeyBinding::new(Key::Named(NamedKey::ArrowUp)));
ray_distance_action.add(KeyBinding::new(Key::Named(NamedKey::ArrowDown)).amplitude(-1));
ray_distance_action.add(KeyBinding::new(Key::Named(NamedKey::ArrowUp)).analog());
ray_distance_action.add(
KeyBinding::new(Key::Named(NamedKey::ArrowDown))
.analog()
.amplitude(-1.0),
);

let manipulator = Entity::builder()
.mount(TransformBundle::default())
Expand Down Expand Up @@ -220,7 +228,7 @@ impl Default for CameraQuery {

type PickingQuery = (
EntityRefs,
Component<i32>,
Component<bool>,
Component<Vec2>,
ComponentMut<PickingState>,
);
Expand Down Expand Up @@ -268,7 +276,7 @@ pub fn pick_ray_system() -> BoxedSystem {
{
let world = entity.world();

if *pick_ray_activation < 1 {
if !pick_ray_activation {
state.stop_manipulating(cmd);
return Ok(());
}
Expand Down
38 changes: 10 additions & 28 deletions ivy-gltf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
pub mod animation;
pub mod components;

use std::{borrow::Cow, collections::HashMap, fs, future::Future, io, path::Path, sync::Arc};

use animation::skin::Skin;
use anyhow::Context;
use futures::StreamExt;
use futures::TryStreamExt;
use glam::Mat4;
use glam::Quat;
use glam::U16Vec4;
use glam::Vec2;
use glam::Vec3;
use glam::Vec4;
use gltf::buffer;
use image::DynamicImage;
use image::ImageFormat;
use futures::{StreamExt, TryStreamExt};
use glam::{Mat4, Quat, U16Vec4, Vec2, Vec3, Vec4};
use gltf::{buffer, Gltf};
use image::{DynamicImage, ImageFormat};
use itertools::Itertools;
use ivy_assets::fs::AsyncAssetFromPath;
use ivy_assets::AssetDesc;
use ivy_assets::{fs::AsyncAssetFromPath, Asset, AssetCache, AssetDesc};
use ivy_core::components::TransformBundle;
use ivy_graphics::mesh::MeshData;
use ivy_graphics::mesh::TANGENT_ATTRIBUTE;
use ivy_profiling::profile_function;
use ivy_profiling::profile_scope;
use rayon::iter::ParallelBridge;
use rayon::iter::ParallelIterator;
use std::borrow::Cow;
use std::fs;
use std::future::Future;
use std::io;
use std::sync::Arc;
use std::{collections::HashMap, path::Path};

use gltf::Gltf;
use ivy_assets::{Asset, AssetCache};
use ivy_graphics::mesh::{MeshData, TANGENT_ATTRIBUTE};
use ivy_profiling::{profile_function, profile_scope};
use rayon::iter::{ParallelBridge, ParallelIterator};

/// An in memory representation of a gltf document and binary buffer data
pub struct DocumentData {
Expand Down
Loading

0 comments on commit c67de88

Please sign in to comment.