Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Sep 9, 2024
1 parent b467f83 commit 2ca53e5
Show file tree
Hide file tree
Showing 20 changed files with 777 additions and 722 deletions.
1,316 changes: 707 additions & 609 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bevy_nannou_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, parse_quote, Attribute, ItemStruct, Lit, Meta, NestedMeta};
use quote::quote;
use syn::{parse_macro_input, parse_quote, ItemStruct, Lit, Meta, NestedMeta};

#[proc_macro_attribute]
pub fn shader_model(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand Down
13 changes: 6 additions & 7 deletions bevy_nannou_draw/src/draw/drawing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::any::TypeId;
use std::marker::PhantomData;

use bevy::asset::{AsyncWriteExt, UntypedAssetId};
use bevy::asset::UntypedAssetId;
use bevy::pbr::{ExtendedMaterial, MaterialExtension};
use bevy::prelude::*;
use lyon::path::PathEvent;
Expand All @@ -13,7 +13,6 @@ use crate::draw::properties::{
SetColor, SetDimensions, SetFill, SetOrientation, SetPosition, SetStroke,
};
use crate::draw::{Draw, DrawCommand, DrawRef};
use crate::render::{ExtendedNannouMaterial, NannouMaterial};

/// A **Drawing** in progress.
///
Expand Down Expand Up @@ -876,35 +875,35 @@ where
T: Into<Primitive>,
M: MaterialExtension + Default,
{
pub fn roughness(mut self, roughness: f32) -> Self {
pub fn roughness(self, roughness: f32) -> Self {
self.map_material(|mut material| {
material.base.perceptual_roughness = roughness;
material
})
}

pub fn metallic(mut self, metallic: f32) -> Self {
pub fn metallic(self, metallic: f32) -> Self {
self.map_material(|mut material| {
material.base.metallic = metallic;
material
})
}

pub fn base_color<C: Into<Color>>(mut self, color: C) -> Self {
pub fn base_color<C: Into<Color>>(self, color: C) -> Self {
self.map_material(|mut material| {
material.base.base_color = color.into();
material
})
}

pub fn emissive<C: Into<Color>>(mut self, color: C) -> Self {
pub fn emissive<C: Into<Color>>(self, color: C) -> Self {
self.map_material(|mut material| {
material.base.emissive = color.into().to_linear();
material
})
}

pub fn texture(mut self, texture: &Handle<Image>) -> Self {
pub fn texture(self, texture: &Handle<Image>) -> Self {
self.map_material(|mut material| {
material.base.base_color_texture = Some(texture.clone());
material
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_draw/src/draw/instanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bevy::{
render_asset::RenderAssets,
render_phase::{
AddRenderCommand, DrawFunctions, PhaseItem, PhaseItemExtraIndex, RenderCommand,
RenderCommandResult, SetItemPipeline, SortedRenderPhase, TrackedRenderPass,
RenderCommandResult, SetItemPipeline, TrackedRenderPass,
},
render_resource::*,
renderer::RenderDevice,
Expand Down
2 changes: 0 additions & 2 deletions bevy_nannou_draw/src/draw/mesh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Items related to the custom mesh type used by the `Draw` API.

use std::ops::{Deref, DerefMut};

use bevy::prelude::*;
use bevy::render::mesh::{Indices, PrimitiveTopology, VertexAttributeValues};
use bevy::render::render_asset::RenderAssetUsages;
Expand Down
11 changes: 4 additions & 7 deletions bevy_nannou_draw/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@

use std::any::{Any, TypeId};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::ops::Deref;
use std::sync::{Arc, RwLock};

use bevy::asset::UntypedAssetId;
use bevy::ecs::world::Command;
use bevy::prelude::*;
use bevy::render::render_resource as wgpu;
use bevy::render::render_resource::{BlendComponent, BlendState};
use bevy::utils::{HashMap, HashSet};
use lyon::path::PathEvent;
use uuid::Uuid;

use crate::draw::instanced::{InstanceMaterialData, Instanced};
use crate::draw::mesh::MeshExt;
use crate::draw::render::RenderPrimitive;
use crate::render::DefaultNannouMaterial;

pub use self::background::Background;
pub use self::drawing::{Drawing, DrawingContext};
use self::primitive::Primitive;
pub use self::theme::Theme;
use crate::draw::instanced::{InstanceMaterialData, Instanced};
use crate::draw::mesh::MeshExt;
use crate::render::DefaultNannouMaterial;

pub mod background;
mod drawing;
Expand Down
34 changes: 2 additions & 32 deletions bevy_nannou_draw/src/draw/primitive/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ pub struct PrimitiveMesh {
#[derive(Clone, Debug, Default)]
struct FillColor(Option<Color>);

// A simple iterator for flattening a fixed-size array of indices.
struct FlattenIndices<I> {
iter: I,
index: usize,
vertex_start_index: usize,
current: [usize; 3],
}

pub type DrawingMesh<'a, M> = Drawing<'a, PrimitiveMesh, M>;

impl Vertexless {
Expand Down Expand Up @@ -311,7 +303,8 @@ impl PrimitiveMesh {
fn new(
vertex_range: ops::Range<usize>,
index_range: ops::Range<usize>,
texture_handle: Option<Handle<Image>>,
// TODO: remove this?
_texture_handle: Option<Handle<Image>>,
) -> Self {
let orientation = Default::default();
let position = Default::default();
Expand Down Expand Up @@ -553,29 +546,6 @@ impl draw::render::RenderPrimitive for PrimitiveMesh {
}
}

impl<I> Iterator for FlattenIndices<I>
where
I: Iterator<Item = [usize; 3]>,
{
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
loop {
if self.index < self.current.len() {
let ix = self.current[self.index];
self.index += 1;
return Some(self.vertex_start_index + ix);
}
match self.iter.next() {
None => return None,
Some(trio) => {
self.current = trio;
self.index = 0;
}
}
}
}
}

impl SetOrientation for PrimitiveMesh {
fn properties(&mut self) -> &mut orientation::Properties {
SetOrientation::properties(&mut self.orientation)
Expand Down
1 change: 1 addition & 0 deletions bevy_nannou_draw/src/draw/primitive/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct Path {
orientation: orientation::Properties,
path_event_src: PathEventSource,
options: Options,
// TODO: remove this?
texture_handle: Option<Handle<Image>>,
}

Expand Down
2 changes: 0 additions & 2 deletions bevy_nannou_draw/src/draw/render/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::hash::Hash;

use bevy::prelude::*;
use lyon::path::PathEvent;
use lyon::tessellation::{FillTessellator, StrokeTessellator};
Expand Down
4 changes: 1 addition & 3 deletions bevy_nannou_draw/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::any::TypeId;
use std::hash::Hash;
use std::ops::{Deref, DerefMut};

use bevy::asset::Asset;
use bevy::asset::UntypedAssetId;
Expand All @@ -23,7 +22,6 @@ use bevy::render::view::{NoFrustumCulling, RenderLayers};
use bevy::window::WindowRef;
use lyon::lyon_tessellation::{FillTessellator, StrokeTessellator};


use crate::draw::instanced::InstancingPlugin;
use crate::draw::mesh::MeshExt;
use crate::draw::render::{RenderContext, RenderPrimitive};
Expand Down Expand Up @@ -226,7 +224,7 @@ fn update_draw_mesh(
let mut curr_ctx: DrawContext = Default::default();

let draw_cmds = draw.drain_commands();
let mut draw_state = draw.state.read().unwrap();
let draw_state = draw.state.read().unwrap();
let intermediary_state = draw_state.intermediary_state.read().unwrap();

for cmd in draw_cmds {
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rustPlatform.buildRustPackage rec {
lockFile = ./Cargo.lock;
outputHashes = {
"skeptic-0.13.8" = "sha256-LLVrpuyQsMdbp8OYcHN0nq+uKC8xgJzpNy+gyXxTYbo=";
"bevy-0.15.0-dev" = "sha256-hVXJdAZLxsmLGt7ZDPg7vmsimz5j8GZhW5lKR93+Kzs=";
"bevy-0.15.0-dev" = "sha256-68Jwn6QEt3F24j6WmPAZz6D5gN8BYE706TRx3FE/6qs=";
"bevy-inspector-egui-0.25.2" = "sha256-yjzmnHAxkejNtW8+cOV85IiGRM0614D7WtiauE6KWMA=";
"bevy_egui-0.29.0" = "sha256-3UiUBpDhpud42ZcDwPHhSzmnlXkd9rH14lqXeRHdLlU=";
};
Expand Down
24 changes: 12 additions & 12 deletions nannou/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bevy::core::FrameCount;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
use bevy::ecs::system::SystemParam;
use bevy::ecs::world::unsafe_world_cell::UnsafeWorldCell;
use bevy::input::keyboard::KeyboardInput;
use bevy::input::keyboard::{Key, KeyboardInput};
use bevy::input::mouse::{MouseButtonInput, MouseWheel};
use bevy::input::ButtonState;
use bevy::prelude::*;
Expand All @@ -32,7 +32,6 @@ use bevy::reflect::{
TypeInfo,
};
use bevy::render::extract_resource::ExtractResource;
use bevy::render::render_graph::ViewNodeRunner;
use bevy::window::{
ExitCondition, Monitor, PrimaryMonitor, PrimaryWindow, WindowClosed, WindowEvent,
WindowFocused, WindowResized,
Expand All @@ -48,15 +47,14 @@ use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_inspector_egui::DefaultInspectorConfigPlugin;
use find_folder;

use bevy_nannou::prelude::render::ExtendedNannouMaterial;
use bevy_nannou::prelude::{draw, DrawHolder};
use bevy_nannou::NannouPlugin;

use crate::frame::{Frame, FramePlugin};
use crate::prelude::bevy_ecs::system::SystemState;
use crate::prelude::render::{NannouMesh, ShaderModel};
use crate::prelude::NannouMaterialPlugin;
use crate::render::{NannouRenderNode, RenderApp, RenderPlugin};
use crate::render::{RenderApp, RenderPlugin};
use crate::window::WindowUserFunctions;
use crate::{camera, geom, light, window};

Expand Down Expand Up @@ -297,7 +295,6 @@ where
pub fn render(mut self, render: RenderFn<M>) -> Self
where
M: Send + Sync + Clone + 'static,
ViewNodeRunner<NannouRenderNode<M>>: FromWorld,
{
self.render = Some(render);
self.app
Expand Down Expand Up @@ -727,7 +724,7 @@ impl<'w> App<'w> {
}

pub(crate) fn resource_world_mut(&self) -> RefMut<'_, World> {
let world = unsafe { self.resource_world.borrow_mut() };
let world = self.resource_world.borrow_mut();
RefMut::map(world, |world| unsafe { world.world_mut() })
}

Expand All @@ -737,7 +734,7 @@ impl<'w> App<'w> {
}

pub(crate) fn component_world_mut(&self) -> RefMut<'_, World> {
let world = unsafe { self.component_world.borrow_mut() };
let world = self.component_world.borrow_mut();
RefMut::map(world, |world| unsafe { world.world_mut() })
}

Expand Down Expand Up @@ -1126,14 +1123,13 @@ fn events<M, E>(
state: &mut SystemState<(
EventReader<E>,
Res<EventFnRes<M, E>>,
Query<&WindowUserFunctions<M>>,
ResMut<ModelHolder<M>>,
)>,
) where
M: Send + Sync + 'static,
E: Event,
{
let (app, (mut events, event_fn, user_fns, mut model)) = get_app_and_state(world, state);
let (app, (mut events, event_fn, mut model)) = get_app_and_state(world, state);
for evt in events.read() {
if let Some(f) = event_fn.0.as_ref() {
f(&app, &mut model, evt);
Expand Down Expand Up @@ -1178,7 +1174,7 @@ fn key_events<M>(
fn received_char_events<M>(
world: &mut World,
state: &mut SystemState<(
EventReader<ReceivedCharacter>,
EventReader<KeyboardInput>,
Query<&WindowUserFunctions<M>>,
ResMut<ModelHolder<M>>,
)>,
Expand All @@ -1192,8 +1188,12 @@ fn received_char_events<M>(
if let Ok(user_fns) = user_fns.get(evt.window) {
if let Some(f) = user_fns.received_character {
app.current_view = Some(evt.window);
let char = evt.char.chars().next().unwrap();
f(&app, &mut model, char);
let key = &evt.logical_key;
if let Key::Character(char) = key {
for char in char.chars() {
f(&app, &mut model, char);
}
}
}
}
}
Expand Down
Loading

0 comments on commit 2ca53e5

Please sign in to comment.