Skip to content

Commit

Permalink
Updated orchestrator and rendering architecture. Added resource state…
Browse files Browse the repository at this point in the history
… tracking.
  • Loading branch information
facundo-villa committed Dec 18, 2023
1 parent 182518a commit 11fe75e
Show file tree
Hide file tree
Showing 18 changed files with 1,172 additions and 1,134 deletions.
64 changes: 62 additions & 2 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"
license = "MIT"
rust-version = "1.73.0"

[features]
multithreading = []

[dependencies]
component_derive = { path = "component_derive" }

Expand All @@ -31,6 +34,8 @@ log = "0.4.20"
simple_logger = "4.2.0"
meshopt = "0.1.9"
colored = "2.0.4"
downcast-rs = "1.2.0"
intertrait = "0.2.2"

[profile.dev]
incremental = true
Expand Down
16 changes: 8 additions & 8 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Application for BaseApplication {
use log::{info, trace};
use maths_rs::prelude::Base;

use crate::{orchestrator, rendering::render_system, window_system, input_manager, Vector2, rendering::{self}, resource_manager, file_tracker};
use crate::{orchestrator::{self, EntityHandle}, rendering::render_system, window_system, input_manager, Vector2, rendering::{self}, resource_manager, file_tracker};

/// An orchestrated application is an application that uses the orchestrator to manage systems.
/// It is the recommended way to create a simple application.
Expand Down Expand Up @@ -128,7 +128,7 @@ pub struct GraphicsApplication {
mouse_device_handle: input_manager::DeviceHandle,
input_system_handle: orchestrator::EntityHandle<input_manager::InputManager>,
renderer_handle: orchestrator::EntityHandle<rendering::renderer::Renderer>,
render_system_handle: orchestrator::EntityHandle<render_system::RenderSystemImplementation>,
render_system_handle: orchestrator::EntityHandle<dyn render_system::RenderSystem>,
}

impl Application for GraphicsApplication {
Expand All @@ -139,7 +139,7 @@ impl Application for GraphicsApplication {

let orchestrator = application.get_mut_orchestrator();

orchestrator.spawn_entity(resource_manager::resource_manager::ResourceManager::new_as_system());
let resource_manager_handle = orchestrator.spawn_entity(resource_manager::resource_manager::ResourceManager::new_as_system()).unwrap();

let window_system_handle = orchestrator.spawn_entity(window_system::WindowSystem::new_as_system()).unwrap();
let input_system_handle = orchestrator.spawn_entity(input_manager::InputManager::new_as_system()).unwrap();
Expand All @@ -165,7 +165,7 @@ impl Application for GraphicsApplication {

let render_system_handle = rendering::create_render_system(&orchestrator);

let renderer_handle = orchestrator.spawn_entity(rendering::renderer::Renderer::new_as_system()).unwrap();
let renderer_handle = EntityHandle::spawn(orchestrator, rendering::renderer::Renderer::new_as_system(render_system_handle.clone(), window_system_handle.clone(), resource_manager_handle)).unwrap();

orchestrator.spawn_entity(rendering::render_orchestrator::RenderOrchestrator::new());

Expand Down Expand Up @@ -205,7 +205,7 @@ impl Application for GraphicsApplication {
true
});

self.application.get_orchestrator().invoke_mut(self.input_system_handle.copy(), input_manager::InputManager::update);
self.application.get_orchestrator().invoke_mut(&self.input_system_handle, input_manager::InputManager::update);

// self.application.get_orchestrator().get_2_mut_and(&self.render_system_handle, &self.visibility_render_domain_handle, |render_system, visibility_render_domain| {
// // let files = changed_files.iter().filter(|event| {
Expand All @@ -224,7 +224,7 @@ impl Application for GraphicsApplication {
// visibility_render_domain.render(self.get_orchestrator(), render_system, self.tick_count as u32);
// });

self.application.get_orchestrator().invoke_mut(self.renderer_handle.copy(), rendering::renderer::Renderer::render);
self.application.get_orchestrator().invoke_mut(&self.renderer_handle, rendering::renderer::Renderer::render);

if !window_res {
self.application.close();
Expand All @@ -244,8 +244,8 @@ impl GraphicsApplication {
pub fn get_orchestrator(&self) -> &orchestrator::Orchestrator { self.application.get_orchestrator() }
pub fn get_mut_orchestrator(&mut self) -> &mut orchestrator::Orchestrator { self.application.get_mut_orchestrator() }

pub fn get_input_system_handle(&self) -> orchestrator::EntityHandle<crate::input_manager::InputManager> {
self.input_system_handle.copy()
pub fn get_input_system_handle_ref(&self) -> &orchestrator::EntityHandle<crate::input_manager::InputManager> {
&self.input_system_handle
}

pub fn do_loop(&mut self) {
Expand Down
4 changes: 2 additions & 2 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl Camera {

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::Component { getter: Self::get_orientation, setter: Self::set_orientation } }
pub const fn orientation() -> Property<Camera, Vec3f> { Property { 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::Component { getter: Self::get_position, setter: Self::set_position } }
pub const fn position() -> Property<Camera, Vec3f> { Property { getter: Self::get_position, setter: Self::set_position } }
}

impl Entity for Camera {}
Expand Down
16 changes: 6 additions & 10 deletions src/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ impl InputManager {

match value {
Value::Vector2(v) => {
orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector2>::value, v);
// orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector2>::value, v);
}
Value::Vector3(v) => {
orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector3>::value, v);
// orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector3>::value, v);
}
_ => {}
}
Expand Down Expand Up @@ -1309,12 +1309,12 @@ impl InputManager {
orchestrator::InternalId(handle.0)
}

pub fn get_action_value<T: GetType + Clone>(&self, action_handle: &EntityHandle<Action<T>>) -> T where Value: Extract<T> {
pub fn get_action_value<T: GetType + Clone + 'static>(&self, action_handle: &EntityHandle<Action<T>>) -> T where Value: Extract<T> {
let state = self.get_action_state(ActionHandle(action_handle.get_external_key()), &DeviceHandle(0));
state.value.extract()
}

pub fn set_action_value<T: Clone>(&mut self, _action_handle: &EntityHandle<Action<T>>, _value: T) {
pub fn set_action_value<T: GetType + Clone + 'static>(&mut self, _action_handle: &EntityHandle<Action<T>>, _value: T) {

}
}
Expand All @@ -1329,7 +1329,7 @@ pub struct Action<T: Clone> {
pub phantom: std::marker::PhantomData<T>,
}

impl <T: GetType + Clone + Send + 'static> orchestrator::Entity for Action<T> {}
impl <T: GetType + Clone + 'static> orchestrator::Entity for Action<T> {}

pub trait GetType {
fn get_type() -> Types;
Expand All @@ -1347,10 +1347,6 @@ impl GetType for Vector3 {
fn get_type() -> Types { Types::Vector3 }
}

impl <T: Clone + Send + GetType + 'static> orchestrator::Component for Action<T> {
impl <T: Clone + GetType + 'static> orchestrator::Component for Action<T> {
// type Parameters<'a> = ActionParameters<'a>;
}

impl <T: Clone + Send + GetType> Action<T> {
pub const fn value() -> Property<InputManager, Self, T> where T: GetType, Value: Extract<T> { Property::System { getter: InputManager::get_action_value, setter: InputManager::set_action_value } }
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(is_sorted)]
#![feature(iter_map_windows)]
#![feature(pointer_is_aligned)]
#![feature(coerce_unsized, unsize)]
// #![warn(missing_docs)] # Disable now because we are writing a lot of code
// #![warn(missing_doc_code_examples)] # Disable now because we are writing a lot of code

Expand Down
Loading

0 comments on commit 11fe75e

Please sign in to comment.