Skip to content

Commit

Permalink
Merge pull request #82 from AryanpurTech/More-Signals
Browse files Browse the repository at this point in the history
Added 2 more Signals
  • Loading branch information
ElhamAryanpur authored Sep 10, 2024
2 parents d09e956 + 05e1b59 commit 14d969a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android_game_activity = ["winit/android-game-activity"]
[dependencies]
image = { version = "0.25.2" }
pollster = "0.3"
winit = { version = "0.30", features = ["rwh_06"] }
winit = { version = "0.30.5", features = ["rwh_06"] }
wgpu = { version = "22.1.0" }
bytemuck = { version = "1.16", features = ["derive"] }
eyre = "0.6"
Expand Down
26 changes: 25 additions & 1 deletion src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,18 @@ pub struct Instance {

/// Allows all events to be fetched directly, making it easier to add custom additions to the engine.
pub trait Signal: Any {
/// This is ran before any of the render events, it's generally used to capture raw input.
/// This is ran as soon as the engine is properly initialized and all components are ready
#[allow(clippy::too_many_arguments)]
fn init(
&mut self,
_renderer: &mut crate::Renderer,
_window: &crate::Window,
_objects: &mut ObjectStorage,
_camera: &mut crate::CameraContainer,
) {
}

/// This is ran at the device events when available
#[allow(clippy::too_many_arguments)]
fn device_events(
&mut self,
Expand All @@ -574,6 +585,19 @@ pub trait Signal: Any {
) {
}

/// This is ran at the window events when available
#[allow(clippy::too_many_arguments)]
fn window_events(
&mut self,
_renderer: &mut crate::Renderer,
_window: &crate::Window,
_objects: &mut ObjectStorage,
_events: &crate::WindowEvent,
_input: &crate::InputHelper,
_camera: &mut crate::CameraContainer,
) {
}

/// ran before the frame is rendered
#[allow(clippy::too_many_arguments)]
fn frame(
Expand Down
10 changes: 10 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl ApplicationHandler for Engine {
ref mut window,
ref mut renderer,
ref mut objects,
ref mut signals,
ref mut camera,
..
} = self;

Expand Down Expand Up @@ -216,6 +218,10 @@ impl ApplicationHandler for Engine {
window.set_cursor(self.window.default_attributes.cursor.clone());
window.set_fullscreen(self.window.default_attributes.fullscreen.clone());
}

signals.events.iter_mut().for_each(|i| {
i.1.init(renderer, &self.window, objects, camera);
});
}
}

Expand Down Expand Up @@ -258,6 +264,10 @@ impl ApplicationHandler for Engine {
..
} = self;

signals.events.iter_mut().for_each(|i| {
i.1.window_events(renderer, window, objects, &event, input_events, camera);
});

let mut _device_event: winit::event::DeviceEvent =
DeviceEvent::MouseMotion { delta: (0.0, 0.0) };

Expand Down

0 comments on commit 14d969a

Please sign in to comment.