Skip to content

Commit

Permalink
Fix draw reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed May 8, 2024
1 parent c0eace0 commit c9b39bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions bevy_nannou_draw/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl State {
self.last_draw_context = None;
self.background_color = None;
self.drawing.clear();
// self.materials.clear();
self.materials.clear();
self.draw_commands.clear();
self.intermediary_state.write().unwrap().reset();
}
Expand Down Expand Up @@ -253,16 +253,18 @@ where
/// Resets all state within the `Draw` instance.
pub fn reset(&mut self) {
self.state.write().unwrap().reset();
self.insert_default_material();
}

fn insert_default_material(&self) {
fn insert_default_material(&mut self) {
let mut state = self.state.write().unwrap();
let material = M::default();
let material_id = UntypedAssetId::Uuid {
type_id: TypeId::of::<M>(),
uuid: Uuid::new_v4(),
};
state.materials.insert(material_id, Box::new(material));
self.material = material_id;
}

// Context changes.
Expand Down
10 changes: 7 additions & 3 deletions nannou/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use bevy_nannou::NannouPlugin;

use crate::prelude::bevy_ecs::system::lifetimeless::Read;
use crate::prelude::bevy_ecs::system::SystemState;
use crate::prelude::bevy_reflect::{ReflectMut, ReflectOwned, ReflectRef, TypeInfo};
use crate::prelude::bevy_reflect::{ApplyError, ReflectMut, ReflectOwned, ReflectRef, TypeInfo};
use crate::prelude::render::{NannouMaterial, NannouMesh, NannouPersistentMesh};
use crate::window::WindowUserFunctions;
use crate::{geom, window};
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct SketchBuilder {
#[derive(Debug, Clone)]
enum DefaultWindowSize {
/// Default window size in logical coordinates.
Logical([f32; 2]),
Logical([u32; 2]),
/// Fullscreen on whatever the primary monitor is at the time of window creation.
Fullscreen,
}
Expand Down Expand Up @@ -257,7 +257,7 @@ where
/// If a window is created and its size is not specified, this size will be used.
pub fn size(mut self, width: u32, height: u32) -> Self {
self.config.default_window_size =
Some(DefaultWindowSize::Logical([width as f32, height as f32]));
Some(DefaultWindowSize::Logical([width, height]));
self
}

Expand Down Expand Up @@ -437,6 +437,10 @@ where
self.0.apply(value)
}

fn try_apply(&mut self, value: &dyn Reflect) -> Result<(), ApplyError> {
self.0.try_apply(value)
}

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
self.0.set(value)
}
Expand Down
4 changes: 2 additions & 2 deletions nannou/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ where
///
/// This describes to the "inner" part of the window, not including desktop decorations like the
/// title bar.
pub fn size(self, width: f32, height: f32) -> Self {
pub fn size(self, width: u32, height: u32) -> Self {
self.map_window(|mut w| {
w.resolution.set(width, height);
w.resolution.set(width as f32, height as f32);
w
})
}
Expand Down

0 comments on commit c9b39bf

Please sign in to comment.