diff --git a/Cargo.lock b/Cargo.lock index 1f92d54..69511fe 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,16 +886,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "hecs" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d2711ad60b74f2f3d0c0ac338a58410a5249da44005971ae806d2925e6b5167" -dependencies = [ - "hashbrown 0.13.2", - "spin", -] - [[package]] name = "hermit-abi" version = "0.3.2" @@ -1113,7 +1103,6 @@ dependencies = [ "edict", "gilrs-core", "glam", - "hecs", "image", "instant", "petgraph", @@ -1782,12 +1771,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "spirv" version = "0.2.0+1.5.4" diff --git a/Cargo.toml b/Cargo.toml index 2641531..9863aa3 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ tobj = { version = "3.2.1", features = [ ]} instant = "0.1" async-trait = "0.1.65" -hecs = "0.10.3" glam = { version = "0.24.0", features = ["bytemuck"] } petgraph = "0.6.3" gilrs-core = "0.5.6" diff --git a/src/ecs/resources/mod.rs b/src/castable_any.rs old mode 100755 new mode 100644 similarity index 64% rename from src/ecs/resources/mod.rs rename to src/castable_any.rs index ed82625..f1d4727 --- a/src/ecs/resources/mod.rs +++ b/src/castable_any.rs @@ -1,15 +1,4 @@ -use std::{any::Any, collections::VecDeque}; - -use winit::event::WindowEvent; - -pub mod window_state; -pub use window_state::*; - -pub mod events; -pub use events::*; - -pub mod event_queue; -pub use event_queue::*; +use std::any::Any; pub trait CastableAny: Send + Sync + 'static { fn as_any(&self) -> &dyn Any; diff --git a/src/ecs/components/camera.rs b/src/ecs/components/camera.rs index 32191bb..07b7b8a 100755 --- a/src/ecs/components/camera.rs +++ b/src/ecs/components/camera.rs @@ -1,7 +1,6 @@ use edict::Component; -use winit::dpi::PhysicalSize; -use crate::{math::{Angle, OPENGL_TO_WGPU_MATRIX, Transform}, render::camera::CameraProjectionMode}; +use crate::{math::{Angle, Transform}, render::camera::CameraProjectionMode}; #[derive(Clone, Component)] pub struct CameraComponent { diff --git a/src/ecs/resources/event_queue.rs b/src/ecs/events.rs similarity index 91% rename from src/ecs/resources/event_queue.rs rename to src/ecs/events.rs index 63ed76d..df4e06a 100644 --- a/src/ecs/resources/event_queue.rs +++ b/src/ecs/events.rs @@ -1,6 +1,11 @@ use std::{collections::{HashMap, VecDeque}, any::{TypeId, Any}, cell::{RefCell, Ref, RefMut}}; -use super::{CastableAny, Events, Event}; +use crate::castable_any::CastableAny; + +pub trait Event: Clone + Send + Sync + 'static {} +impl Event for T {} + +pub type Events = VecDeque; pub struct EventQueue { events: HashMap>>, diff --git a/src/ecs/mod.rs b/src/ecs/mod.rs index f90d624..ee6333b 100755 --- a/src/ecs/mod.rs +++ b/src/ecs/mod.rs @@ -6,7 +6,8 @@ use tracing::warn; use crate::game::Controls; pub mod components; -pub mod resources; +pub mod events; +pub use events::*; /// A trait that represents a simple system pub trait SimpleSystem { diff --git a/src/ecs/resources/events.rs b/src/ecs/resources/events.rs deleted file mode 100755 index d6ce8a9..0000000 --- a/src/ecs/resources/events.rs +++ /dev/null @@ -1,6 +0,0 @@ -use std::collections::VecDeque; - -pub trait Event: Clone + Send + Sync + 'static {} -impl Event for T {} - -pub type Events = VecDeque; \ No newline at end of file diff --git a/src/ecs/resources/window_state.rs b/src/ecs/resources/window_state.rs deleted file mode 100755 index fcd66c8..0000000 --- a/src/ecs/resources/window_state.rs +++ /dev/null @@ -1,15 +0,0 @@ -use std::any::Any; - -use super::CastableAny; - -#[derive(Clone, Default)] -pub struct WindowState { - pub is_focused: bool, - pub is_cursor_inside_window: bool, -} - -impl WindowState { - pub fn new() -> Self { - Self::default() - } -} \ No newline at end of file diff --git a/src/game.rs b/src/game.rs index 1a880fd..b4aaa8a 100755 --- a/src/game.rs +++ b/src/game.rs @@ -14,67 +14,24 @@ use tracing_subscriber::{ use winit::{window::{WindowBuilder, Window}, event::{Event, WindowEvent, KeyboardInput, ElementState, VirtualKeyCode, DeviceEvent}, event_loop::{EventLoop, ControlFlow}}; -use crate::{render::renderer::{Renderer, BasicRenderer}, input_event::InputEvent, ecs::{SimpleSystem, SystemDispatcher, resources::{WindowState, Events, EventQueue}}, input::InputSystem}; +use crate::{render::renderer::{Renderer, BasicRenderer}, input_event::InputEvent, ecs::{SimpleSystem, SystemDispatcher, EventQueue, Events}, input::InputSystem}; pub struct Controls<'a> { pub world: &'a mut edict::World, } -struct TickCounter { - counter: u32, - last_second: Instant, - changed: bool, - tps: f32, - /// the time (in seconds) that passes between each tick - tick_time: f32 +#[derive(Clone, Default)] +pub struct WindowState { + pub is_focused: bool, + pub is_cursor_inside_window: bool, } -impl TickCounter { - fn new() -> Self { - Self { - counter: 0, - last_second: Instant::now(), - tps: 0.0, - changed: false, - tick_time: 0.0, - } - } - - /// Returns true if the tps changed - fn tick(&mut self) -> bool { - self.counter += 1; - - if self.last_second.elapsed().as_secs() > 0 { - self.tick_time = 1000.0 / self.counter as f32; - self.tps = self.counter as f32; - - self.changed = true; - self.counter = 0; - self.last_second = Instant::now(); - } - - self.changed - } - - /// Gets the change in ticks per second - fn get_change(&mut self) -> Option { - match self.changed { - true => { - self.changed = false; - - Some(self.tps) - }, - false => None, - } - } - - /// Get the time (in seconds) between ticks - fn get_tick_time(&self) -> f32 { - self.tick_time +impl WindowState { + pub fn new() -> Self { + Self::default() } } - struct GameLoop { window: Arc, renderer: Box, @@ -83,7 +40,6 @@ struct GameLoop { /// higher priority systems engine_sys_dispatcher: SystemDispatcher, user_sys_dispatcher: SystemDispatcher, - fps_counter: TickCounter, } impl GameLoop { @@ -95,7 +51,6 @@ impl GameLoop { world, engine_sys_dispatcher: SystemDispatcher::new(), user_sys_dispatcher: user_systems, - fps_counter: TickCounter::new(), } } diff --git a/src/input.rs b/src/input.rs index 3cc9d84..95b9410 100755 --- a/src/input.rs +++ b/src/input.rs @@ -5,7 +5,7 @@ use glam::Vec2; use tracing::{warn, debug}; use winit::event::{ElementState, MouseScrollDelta}; -use crate::{ecs::{SimpleSystem, resources::EventQueue}, input_event::InputEvent}; +use crate::{ecs::{SimpleSystem, EventQueue}, input_event::InputEvent}; pub type KeyCode = winit::event::VirtualKeyCode; diff --git a/src/input_event.rs b/src/input_event.rs index dfeabbc..3a2c7e9 100755 --- a/src/input_event.rs +++ b/src/input_event.rs @@ -1,7 +1,5 @@ use winit::{event::{DeviceId, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, MouseButton, AxisId, Touch, WindowEvent, ElementState}, dpi::PhysicalPosition}; -use crate::ecs::resources::CastableAny; - /// Wrapper around events from `winit::WindowEvent` that are specific to input related events. /// /// The `winit::WindowEvent` enum has many values that are related to inputs. diff --git a/src/main.rs b/src/main.rs index 7822948..da82627 100755 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod resources; mod ecs; mod math; mod input; +mod castable_any; use atomicell::Ref; use ecs::components::mesh::MeshComponent;