Skip to content

Commit

Permalink
WindowBehavior::render unit return
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Oct 7, 2024
1 parent 7cc2e4b commit 0df62c7
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Users who are using Kludgine directly should invoke `Kludgine::resize` to
apply the new size.
- `Window::winit` now returns an `Arc`-wrapped winit Window.
- `WindowBehavior::render` no longer returns a `bool`. Closing the window can be
done through the `RunningWindow` parameter.

### Added

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions examples/clipping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl WindowBehavior for Test {
&'pass mut self,
mut window: Window<'_>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
window.redraw_in(Duration::from_millis(16));
self.angle += window.elapsed().as_secs_f32() / 5.;

Expand All @@ -69,7 +69,5 @@ impl WindowBehavior for Test {
.translate_by(Point::from(graphics.size().into_px(graphics.scale())) / 4 * 3)
.rotate_by(self.angle)
.render(graphics);

true
}
}
4 changes: 1 addition & 3 deletions examples/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ impl WindowBehavior for Test {
&'pass mut self,
_window: Window<'_>,
graphics: &mut RenderingGraphics<'_, 'pass>,
) -> bool {
) {
self.prepared.render(graphics);

true
}
}
3 changes: 1 addition & 2 deletions examples/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl WindowBehavior for Test {
&'pass mut self,
mut window: Window<'_>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
window.redraw_in(Duration::from_millis(16));
self.angle += Angle::degrees(180) * window.elapsed();
self.dips_square
Expand All @@ -66,6 +66,5 @@ impl WindowBehavior for Test {
.translate_by(Point::new(BLUE_TRIANGLE_SIZE / 2, BLUE_TRIANGLE_SIZE / 2))
.rotate_by(self.angle)
.render(graphics);
true
}
}
3 changes: 1 addition & 2 deletions examples/sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl WindowBehavior for Sprites {
&'pass mut self,
mut window: kludgine::app::Window<'_, ()>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
if let Some(frame) = &self.current_frame {
frame.render(graphics);
}
Expand All @@ -161,7 +161,6 @@ impl WindowBehavior for Sprites {
.expect("valid tag")
.unwrap_or_default(),
);
true
}

fn keyboard_input(
Expand Down
3 changes: 1 addition & 2 deletions examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ impl WindowBehavior for Test {
&'pass mut self,
mut window: Window<'_>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
window.redraw_in(Duration::from_millis(16));
self.angle += Angle::degrees(180) * window.elapsed() / 5;
self.prepared
.translate_by(Point::from_vec(graphics.size().into_px(graphics.scale())) / 2)
.rotate_by(self.angle)
.render(graphics);
true
}
}
3 changes: 1 addition & 2 deletions examples/texture-collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl WindowBehavior for Test {
&'pass mut self,
mut window: Window<'_>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
window.redraw_in(Duration::from_millis(16));
self.angle += Angle::degrees(180) * window.elapsed();
self.k
Expand All @@ -78,7 +78,6 @@ impl WindowBehavior for Test {
.cast(),
)
.render(graphics);
true
}

fn clear_color(&self) -> Option<Color> {
Expand Down
3 changes: 1 addition & 2 deletions examples/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ impl WindowBehavior for Test {
&'pass mut self,
mut window: Window<'_>,
graphics: &mut kludgine::RenderingGraphics<'_, 'pass>,
) -> bool {
) {
window.redraw_in(Duration::from_millis(16));
self.angle += Angle::degrees(180) * window.elapsed();
self.texture
.translate_by(Point::inches(1, 1))
.rotate_by(self.angle)
.render(graphics);
true
}
}
16 changes: 7 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,11 @@ where
fn prepare(&mut self, window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_>) {}

/// Render the contents of the window.
// TODO refactor away from bool return.
fn render<'pass>(
&'pass mut self,
window: Window<'_, WindowEvent>,
graphics: &mut RenderingGraphics<'_, 'pass>,
) -> bool;
);

/// Returns the swap chain present mode to use for this window.
#[must_use]
Expand Down Expand Up @@ -1281,7 +1280,7 @@ impl<Behavior> KludgineWindow<Behavior> {
&self.device,
&self.queue,
);
let close_after_frame = !self.behavior.render(
self.behavior.render(
Window::new_in_frame(
window,
elapsed,
Expand All @@ -1297,9 +1296,6 @@ impl<Behavior> KludgineWindow<Behavior> {
if let Some(id) = id {
self.device.poll(wgpu::Maintain::WaitForSubmissionIndex(id));
}
if close_after_frame {
window.close();
}
pending_inner_size
}
}
Expand Down Expand Up @@ -1917,11 +1913,13 @@ where

fn render<'pass>(
&'pass mut self,
_window: Window<'_>,
mut window: Window<'_>,
graphics: &mut RenderingGraphics<'_, 'pass>,
) -> bool {
) {
self.rendering.render(1., graphics);
self.keep_running
if !self.keep_running {
window.close();
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ impl Sprite {
///
/// Returns an error when `raw_json` does not match the expected format.
#[allow(clippy::too_many_lines)]
// TODO refactor. Now that I know more about serde, this probably can be parsed
// with a complex serde type.
pub fn load_aseprite_json(
raw_json: &str,
texture: impl Into<ShareableTexture>,
Expand Down

0 comments on commit 0df62c7

Please sign in to comment.