Reorganize project structure
This commit is contained in:
parent
be8ac84e36
commit
8cc1f7bf3e
13 changed files with 178 additions and 134 deletions
9
src/modules/config/components.rs
Normal file
9
src/modules/config/components.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use flax::component;
|
||||
|
||||
use super::Config;
|
||||
|
||||
component! {
|
||||
pub config: Config,
|
||||
pub notify_file_event: notify::Event,
|
||||
pub resources,
|
||||
}
|
||||
54
src/modules/config/mod.rs
Normal file
54
src/modules/config/mod.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use flax::{Schedule, World};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::core::module::Module;
|
||||
|
||||
use self::systems::first_read_config_system;
|
||||
|
||||
pub mod components;
|
||||
pub mod systems;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
pub struct Config {
|
||||
pub asset_path: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct ConfigModule {
|
||||
// watcher: INotifyWatcher,
|
||||
// watcher_rx: std::sync::mpsc::Receiver<Result<notify::Event, notify::Error>>,
|
||||
}
|
||||
|
||||
impl ConfigModule {
|
||||
pub fn new(
|
||||
schedule: &mut Schedule,
|
||||
_world: &mut World,
|
||||
_events: &mut crate::core::events::Events,
|
||||
) -> Self {
|
||||
let schedule_r = Schedule::builder()
|
||||
// .with_system(read_config_system())
|
||||
.with_system(first_read_config_system())
|
||||
.build();
|
||||
|
||||
schedule.append(schedule_r);
|
||||
|
||||
Self {
|
||||
// schedule,
|
||||
// watcher,
|
||||
// watcher_rx: rx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Module for ConfigModule {
|
||||
fn on_update(
|
||||
&mut self,
|
||||
_world: &mut World,
|
||||
_events: &mut crate::core::events::Events,
|
||||
_frame_time: std::time::Duration,
|
||||
) -> anyhow::Result<()> {
|
||||
// println!("ConfigModule on_update");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
53
src/modules/config/systems.rs
Normal file
53
src/modules/config/systems.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use flax::{BoxedSystem, CommandBuffer, EntityBorrow, Query, System};
|
||||
use serde_lexpr::from_str;
|
||||
|
||||
use super::{components::{config, notify_file_event, resources}, Config};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn read_config_system() -> BoxedSystem {
|
||||
let query = Query::new(notify_file_event()).entity(resources());
|
||||
System::builder()
|
||||
.with_name("read_config")
|
||||
.with_cmd_mut()
|
||||
.with_query(query)
|
||||
.build(|cmd: &mut CommandBuffer, mut _q: EntityBorrow<_>| {
|
||||
// if let Ok(n_event) = q.get() {
|
||||
// println!("here");
|
||||
// if (n_event as ¬ify::Event).kind.is_modify() {
|
||||
// println!("file modified: {:?}", (n_event as ¬ify::Event).paths);
|
||||
cmd.set(resources(), config(), read_engine_config());
|
||||
// }
|
||||
// }
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn read_engine_config() -> Config {
|
||||
let config_path = Path::new("engine_config.scm");
|
||||
|
||||
let config_file = fs::read_to_string(config_path).unwrap();
|
||||
let config: Config = from_str::<Config>(&config_file).expect("Failed to parse config file");
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn first_read_config_system() -> BoxedSystem {
|
||||
let query = Query::new(config().as_mut()).entity(resources());
|
||||
System::builder()
|
||||
.with_name("first_read_config")
|
||||
.with_cmd_mut()
|
||||
.with_query(query)
|
||||
.build(|cmd: &mut CommandBuffer, mut q: EntityBorrow<_>| {
|
||||
if let Ok(_config) = q.get() {
|
||||
return;
|
||||
} else {
|
||||
println!("read_notify_events_system: config read");
|
||||
cmd.set(resources(), config(), read_engine_config());
|
||||
}
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
7
src/modules/graphics/events.rs
Normal file
7
src/modules/graphics/events.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[allow(dead_code)]
|
||||
pub enum GraphicsEvent {
|
||||
/// Signifies that the swapchain was recreated. This requires images that
|
||||
/// reference the old swapchain to be recreated.
|
||||
SwapchainRecreation,
|
||||
}
|
||||
51
src/modules/graphics/mod.rs
Normal file
51
src/modules/graphics/mod.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use flax::{entity_ids, BoxedSystem, Query, QueryBorrow, Schedule, System, World};
|
||||
|
||||
use crate::core::module::Module;
|
||||
|
||||
pub mod events;
|
||||
|
||||
pub struct RenderModule {
|
||||
}
|
||||
|
||||
impl RenderModule {
|
||||
pub fn new(
|
||||
schedule: &mut Schedule,
|
||||
_world: &mut World,
|
||||
_events: &mut crate::core::events::Events,
|
||||
) -> Self {
|
||||
let schedule_r = Schedule::builder()
|
||||
.with_system(add_distance_system())
|
||||
.build();
|
||||
schedule.append(schedule_r);
|
||||
Self {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Module for RenderModule {
|
||||
fn on_update(
|
||||
&mut self,
|
||||
_world: &mut World,
|
||||
_events: &mut crate::core::events::Events,
|
||||
_frame_time: std::time::Duration,
|
||||
) -> anyhow::Result<()> {
|
||||
// println!("RenderModule on_update");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_distance_system() -> BoxedSystem {
|
||||
let query = Query::new(entity_ids());
|
||||
|
||||
System::builder()
|
||||
.with_query(query)
|
||||
.build(|mut query: QueryBorrow<'_, flax::EntityIds, _>| {
|
||||
for _id in &mut query {
|
||||
// println!("entity id: {}", id.index());
|
||||
}
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
2
src/modules/mod.rs
Normal file
2
src/modules/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod config;
|
||||
pub mod graphics;
|
||||
Loading…
Add table
Add a link
Reference in a new issue