Skip to content

Commit

Permalink
Updated render tests to not use presentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Jun 25, 2023
1 parent 468d4fc commit 74dccd6
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
rustflags = ["-Clink-arg=-fuse-ld=mold", "-Ctarget-feature=+avx2"]
6 changes: 2 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@ jobs:
vulkan-query-version: latest
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-use-cache: true
- name: Build
run: cargo build
- name: Run tests
run: cargo test --verbose -- --test-threads 1
- name: Build & Run tests
run: cargo test --verbose -- --test-threads 1
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
xcb = { version = "1.2.1", features=['xtest'] }
# ash = { version = "0.37.2", features=['linked'] }
# ash = { version = "0.37.3", features=['linked'] }
ash = { git = "https://github.com/ash-rs/ash", branch = "master", features=['linked'] }
futures = "0.3.28"
shaderc = "0.8.2"
Expand All @@ -22,6 +22,13 @@ notify = "6.0.0"
serde_json = "1.0.96"
dual_quaternion = "0.2.0"
cgmath = "0.18.0"
maths-rs = "0.2.3"

[profile.dev]
incremental = true
lto="off"

[profile.release]
lto="fat"
panic="abort"
codegen-units = 1
18 changes: 16 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ pub trait Application {
/// Returns the name of the application.
fn get_name(&self) -> String;

/// Performs a tick of the application.
fn tick(&mut self);

/// Deinitializes the application.
fn deinitialize(&mut self);
}

/// The most basic implementation of the application trait.
/// It has no functionality and is only used as a base for other implementations.
/// It just stores the name of the application.
pub struct BaseApplication {
name: String,
}
Expand Down Expand Up @@ -54,6 +58,8 @@ impl Application for BaseApplication {

use crate::{orchestrator, window_system, render_system};

/// An orchestrated application is an application that uses the orchestrator to manage systems.
/// It is the recommended way to create a simple application.
pub struct OrchestratedApplication {
application: BaseApplication,
orchestrator: orchestrator::Orchestrator,
Expand Down Expand Up @@ -96,16 +102,20 @@ impl Application for OrchestratedApplication {
}

impl OrchestratedApplication {
/// Flags the application for closing.
pub fn close(&mut self) {
self.close = true;
}

pub fn get_name(&self) -> String { self.application.get_name() }

/// Returns a reference to the orchestrator.
pub fn get_orchestrator(&self) -> &orchestrator::Orchestrator { &self.orchestrator }

/// Returns a mutable reference to the orchestrator.
pub fn get_mut_orchestrator(&mut self) -> &mut orchestrator::Orchestrator { &mut self.orchestrator }
}

/// A graphics application is the base for all applications that use the graphics functionality of the engine.
/// It uses the orchestrated application as a base and adds rendering and windowing functionality.
pub struct GraphicsApplication {
application: OrchestratedApplication,
file_tracker: crate::file_tracker::FileTracker,
Expand Down Expand Up @@ -149,9 +159,13 @@ impl Application for GraphicsApplication {
}

impl GraphicsApplication {
/// Flags the application for closing.
pub fn close(&mut self) {
self.application.close();
}

/// Returns a reference to the orchestrator.
pub fn get_orchestrator(&self) -> &orchestrator::Orchestrator { &self.application.get_orchestrator() }
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/beshader_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
//! # Example beShader
//!
//! ```glsl
//! struct Light {
//! Light: struct {
//! position: vec3,
//! color: vec3,
//! }
//!
//! fn main() -> void {
//! main: fn () -> void {
//! gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
//! }
//! ```
Expand Down
75 changes: 28 additions & 47 deletions src/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//! An input source is a source of input on a device class/type. Such as the UP key on a keyboard or the left trigger on a gamepad.
//! ## Input Destination
//! An input destination is a destination of input on a device. Such as the rumble motors on a gamepad.
//! ## Input Event
//! An input event is an application specific event that is triggered by a combination of input sources.
//! ## Action
//! An action is an application specific event that is triggered by a combination of input sources.
//! For example move sideways is triggered by the left and right keys being pressed.
//!
//! # Usage
Expand Down Expand Up @@ -160,7 +160,8 @@ pub enum Function {
Linear,
}

pub struct InputEventDescription {
/// An action binding description is a description of how an input source is mapped to a value for an action.
pub struct ActionBindingDescription {
pub input_source: InputSourceAction,
pub mapping: Value,
pub function: Option<Function>
Expand Down Expand Up @@ -214,8 +215,6 @@ enum Types {
struct InputEvent {
name: String,
type_: Types,
min: Value,
max: Value,
input_event_descriptions: Vec<InputSourceMapping>,
/// The stack is a list of input source records that simultaneous, connected, and currently active.
/// The stack is used to determine the value of the input event.
Expand Down Expand Up @@ -255,7 +254,7 @@ pub struct InputEventState {
/// The device that triggered the input event.
device_handle: DeviceHandle,
/// The handle to the input event.
input_event_handle: InputEventHandle,
input_event_handle: ActionHandle,
/// The value of the input event.
value: Value,
}
Expand All @@ -274,15 +273,15 @@ pub struct DeviceHandle(u32);

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
/// Handle to an input event.
pub struct InputEventHandle(u32);
pub struct ActionHandle(u32);

/// The input manager is responsible for managing input devices and input events.
pub struct InputManager {
device_classes: Vec<DeviceClass>,
input_sources: Vec<InputSource>,
devices: Vec<Device>,
records: Vec<InputSourceRecord>,
input_events: Vec<InputEvent>,
actions: Vec<InputEvent>,
}

impl InputManager {
Expand All @@ -293,7 +292,7 @@ impl InputManager {
input_sources: Vec::new(),
devices: Vec::new(),
records: Vec::new(),
input_events: Vec::new(),
actions: Vec::new(),
}
}

Expand Down Expand Up @@ -491,23 +490,10 @@ impl InputManager {
/// - 3D: Returns a 3D point when the RGBA color is reached.
/// - Quaternion: Returns a quaternion when the RGBA color is reached.
/// - RGBA: Returns the RGBA color.
fn register_input_event(&mut self, name: &str, min: Value, max: Value, input_events: &[InputEventDescription]) -> InputEventHandle {
let type_ = match (min, max) {
(Value::Bool(_), Value::Bool(_)) => Types::Bool,
(Value::Unicode(_), Value::Unicode(_)) => Types::Unicode,
(Value::Float(_), Value::Float(_)) => Types::Float,
(Value::Int(_), Value::Int(_)) => Types::Int,
(Value::Rgba(_), Value::Rgba(_)) => Types::Rgba,
(Value::Vector2(_), Value::Vector2(_)) => Types::Vector2,
(Value::Vector3(_), Value::Vector3(_)) => Types::Vector3,
(Value::Quaternion(_), Value::Quaternion(_)) => Types::Quaternion,
_ => panic!("Min and max value types do not match!"),
};

fn create_action(&mut self, name: &str, type_: Types, input_events: &[ActionBindingDescription]) -> ActionHandle {
let input_event = InputEvent {
name: name.to_string(),
type_,
min, max,
input_event_descriptions: input_events.iter().map(|input_event| {
InputSourceMapping {
input_source_handle: self.to_input_source_handle(&input_event.input_source),
Expand All @@ -518,7 +504,7 @@ impl InputManager {
stack: Vec::new(),
};

InputEventHandle(insert_return_length(&mut self.input_events, input_event) as u32)
ActionHandle(insert_return_length(&mut self.actions, input_event) as u32)
}

/// Records an input source action.
Expand Down Expand Up @@ -570,7 +556,7 @@ impl InputManager {
self.records.push(record);

if let Value::Bool(boo) = value {
let input_events = self.input_events.iter_mut().filter(|ie| ie.input_event_descriptions.iter().any(|ied| ied.input_source_handle == input_source_handle));
let input_events = self.actions.iter_mut().filter(|ie| ie.input_event_descriptions.iter().any(|ied| ied.input_source_handle == input_source_handle));

if boo {
for input_event in input_events {
Expand Down Expand Up @@ -621,8 +607,8 @@ impl InputManager {
}

/// Gets the value of an input event.
pub fn get_input_event_value(&self, input_event_handle: InputEventHandle, device_handle: &DeviceHandle) -> InputEventState {
let input_event = &self.input_events[input_event_handle.0 as usize];
pub fn get_action_value(&self, input_event_handle: ActionHandle, device_handle: &DeviceHandle) -> InputEventState {
let input_event = &self.actions[input_event_handle.0 as usize];

let input_sources_values = input_event.input_event_descriptions.iter().map(|input_event_description| {
(self.get_input_source_record(device_handle, InputSourceAction::Handle(input_event_description.input_source_handle)), input_event_description.input_source_handle, input_event_description)
Expand All @@ -632,11 +618,6 @@ impl InputManager {

let value = match input_event.type_ {
Types::Float => {
let (min, max) = match (input_event.min, input_event.max) {
(Value::Float(min), Value::Float(max)) => (min, max),
_ => panic!("Min and max value types do not match!"),
};

let (input_source_value, input_source_mapping_value) = if let Some(last) = input_event.stack.last() {
if let Value::Bool(value) = last.value {
let event_description_for_input_source = input_event.input_event_descriptions.iter().find(|description| description.input_source_handle == last.input_source_handle).unwrap();
Expand Down Expand Up @@ -1098,13 +1079,13 @@ mod tests {

declare_keyboard_input_device_class(&mut input_manager);

let input_event = input_manager.register_input_event("MoveLongitudinally", Value::Float(-1f32), Value::Float(1f32), &[
InputEventDescription {
input_manager.create_action("MoveLongitudinally", Types::Float, &[
ActionBindingDescription {
input_source: InputSourceAction::Name("Keyboard.Up"),
mapping: Value::Float(1.0),
function: Some(Function::Linear),
},
InputEventDescription {
ActionBindingDescription {
input_source: InputSourceAction::Name("Keyboard.Down"),
mapping: Value::Float(-1.0),
function: Some(Function::Linear),
Expand All @@ -1117,76 +1098,76 @@ mod tests {

let device_class_handle = declare_keyboard_input_device_class(&mut input_manager);

let input_event = input_manager.register_input_event("MoveLongitudinally", Value::Float(-1f32), Value::Float(1f32), &[
InputEventDescription {
let input_event = input_manager.create_action("MoveLongitudinally", Types::Float, &[
ActionBindingDescription {
input_source: InputSourceAction::Name("Keyboard.Up"),
mapping: Value::Float(1.0),
function: Some(Function::Linear),
},
InputEventDescription {
ActionBindingDescription {
input_source: InputSourceAction::Name("Keyboard.Down"),
mapping: Value::Float(-1.0),
function: Some(Function::Linear),
},]);

let device_handle = input_manager.create_device(&device_class_handle);

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.device_handle, device_handle);
assert_eq!(value.value, Value::Float(0f32)); // Default value must be 0.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(true));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(1.0)); // Must be 1.0 after recording.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(false));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(0.0)); // Must be 0.0 after recording.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(true));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(-1.0)); // Must be -1.0 after recording.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(false));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(0.0)); // Must be 0.0 after recording.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(true));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(true));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(-1.0)); // Must be -1.0 after recording down after up while up is still pressed.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(false));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(false));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(0.0)); // Must be 0.0 after recording

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(true));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(true));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(false));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(-1.0)); // Must be -1.0 after releasing up while down down is still pressed.

input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Up"), Value::Bool(true));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(true));
input_manager.record_input_source_action(&device_handle, InputSourceAction::Name("Keyboard.Down"), Value::Bool(false));

let value = input_manager.get_input_event_value(input_event, &device_handle);
let value = input_manager.get_action_value(input_event, &device_handle);

assert_eq!(value.value, Value::Float(1.0)); // Must be 1.0 after releasing down while up is still pressed.
}
Expand Down
Loading

0 comments on commit 74dccd6

Please sign in to comment.