Skip to content

Commit

Permalink
Added basic reactivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Dec 26, 2023
1 parent 0f01211 commit eee9701
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 116 deletions.
42 changes: 22 additions & 20 deletions src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
use crate::{Vec3f, orchestrator::{Property, self, Component, Entity}};
use crate::{Vec3f, orchestrator::{Property2, self, Component, Entity}};

#[derive(component_derive::Component)]
/// Camera struct
pub struct Camera {
pub position: Vec3f,
pub direction: Vec3f,
pub fov: f32,
pub aspect_ratio: f32,
pub aperture: f32,
pub focus_distance: f32,
}

pub struct CameraParameters {
pub position: Vec3f,
pub direction: Vec3f,
pub fov: f32,
pub aspect_ratio: f32,
pub aperture: f32,
pub focus_distance: f32,
position: Vec3f,
direction: Vec3f,
fov: f32,
aspect_ratio: f32,
aperture: f32,
focus_distance: f32,
}

impl Camera {
pub fn new(position: Vec3f) -> Self {
Self {
position,
direction: Vec3f::new(0.0, 0.0, 1.0),
fov: 90.0,
aspect_ratio: 1.0,
aperture: 0.0,
focus_distance: 0.0,
}
}

/// Returns the field of view of the camera
fn get_fov(&self) -> f32 { self.fov }

Expand All @@ -34,12 +36,12 @@ impl Camera {
fn get_focus_distance(&self) -> f32 { self.focus_distance }

fn get_orientation(&self) -> Vec3f { self.direction }
fn set_orientation(&mut self, _orchestrator: orchestrator::OrchestratorReference, orientation: Vec3f) { self.direction = orientation; }
pub const fn orientation() -> Property<Camera, Vec3f> { Property { getter: Self::get_orientation, setter: Self::set_orientation } }
fn set_orientation(&mut self, orientation: Vec3f) { self.direction = orientation; }
pub const fn orientation() -> Property2<Camera, Vec3f> { Property2 { getter: Self::get_orientation, setter: Self::set_orientation } }

fn get_position(&self) -> Vec3f { self.position }
fn set_position(&mut self, _orchestrator: orchestrator::OrchestratorReference, position: Vec3f) { self.position = position; }
pub const fn position() -> Property<Camera, Vec3f> { Property { getter: Self::get_position, setter: Self::set_position } }
fn set_position(&mut self, position: Vec3f) { self.position = position; }
pub const fn position() -> Property2<Camera, Vec3f> { Property2 { getter: Self::get_position, setter: Self::set_position } }
}

impl Entity for Camera {}
Expand Down
14 changes: 7 additions & 7 deletions src/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{f32::consts::PI, collections::HashMap};

use log::warn;

use crate::{RGBA, Vector2, Vector3, insert_return_length, Quaternion, orchestrator::{EntityHandle, Property, System, self, Entity, EntitySubscriber, EntityHash}};
use crate::{RGBA, Vector2, Vector3, insert_return_length, Quaternion, orchestrator::{EntityHandle, Property2, System, self, Entity, EntitySubscriber, EntityHash}};

/// A device class represents a type of device. Such as a keyboard, mouse, or gamepad.
/// It can have associated input sources, such as the UP key on a keyboard or the left trigger on a gamepad.
Expand Down Expand Up @@ -487,12 +487,12 @@ impl InputManager {
name: name.to_string(),
type_,
input_event_descriptions: input_events.iter().map(|input_event| {
InputSourceMapping {
input_source_handle: self.to_input_source_handle(&input_event.input_source).unwrap(),
Some(InputSourceMapping {
input_source_handle: self.to_input_source_handle(&input_event.input_source)?,
mapping: input_event.mapping,
function: input_event.function,
}
}).collect::<Vec<_>>(),
})
}).filter_map(|input_event| input_event).collect::<Vec<_>>(),
stack: Vec::new(),
};

Expand Down Expand Up @@ -1427,6 +1427,6 @@ impl <T: InputValue + Clone + 'static> Action<T> {
}

pub fn get_value(&self) -> T { self.value }
pub fn set_value(&mut self, _: orchestrator::OrchestratorReference, value: T) { self.value = value; }
pub const fn value() -> orchestrator::Property<Action<T>, T> { return orchestrator::Property { getter: Self::get_value, setter: Self::set_value } }
pub fn set_value(&mut self, value: T) { self.value = value; }
pub const fn value() -> orchestrator::Property2<Action<T>, T> { return orchestrator::Property2 { getter: Self::get_value, setter: Self::set_value } }
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod file_tracker;
pub mod executor;
pub mod camera;
pub mod audio;
pub mod ui;

pub mod ghi;
pub mod ahi;
Expand Down
Loading

0 comments on commit eee9701

Please sign in to comment.