Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Update the following examples to work with the winit and rendy upgrades: rendy, renderable, sprite_animation, sprite_camera_follow, sprites_ordered, tiles
  • Loading branch information
valkum committed Dec 11, 2019
1 parent 5293bda commit bf2058f
Show file tree
Hide file tree
Showing 38 changed files with 415 additions and 338 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -147,7 +147,7 @@ log = { version = "0.4.6", features = ["serde"] }
rayon = "1.1.0"
rustc_version_runtime = "0.1"
sentry = { version = "0.17.0", optional = true }
winit = { version = "0.20.0-alpha4", features = ["serde"] }
winit = { version = "0.20.0-alpha5", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
palette = { version = "0.4", features = ["serde"] }
failure = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion amethyst_controls/Cargo.toml
Expand Up @@ -22,7 +22,7 @@ amethyst_error = { path = "../amethyst_error", version = "0.3.0" }
amethyst_input = { path = "../amethyst_input", version = "0.9.0" }
derive-new = "0.5"
serde = { version = "1.0", features = ["derive"] }
winit = { version = "0.20.0-alpha4", features = ["serde"] }
winit = { version = "0.20.0-alpha5", features = ["serde"] }
log = "0.4.6"

thread_profiler = { version = "0.3", optional = true }
Expand Down
8 changes: 2 additions & 6 deletions amethyst_controls/src/bundles.rs
Expand Up @@ -95,12 +95,8 @@ impl<'a, 'b, T: BindingTypes> SystemBundle<'a, 'b> for FlyControlBundle<T> {
"free_rotation",
&[],
);
builder.add_thread_local(
MouseFocusUpdateSystemDesc::default().build(world)
);
builder.add_thread_local(
CursorHideSystemDesc::default().build(world)
);
builder.add_thread_local(MouseFocusUpdateSystemDesc::default().build(world));
builder.add_thread_local(CursorHideSystemDesc::default().build(world));
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion amethyst_controls/src/systems.rs
@@ -1,6 +1,6 @@
use derive_new::new;
use winit::{
event::{DeviceEvent, Event, WindowEvent},
event::{DeviceEvent, Event, WindowEvent},
window::Window,
};

Expand Down
2 changes: 1 addition & 1 deletion amethyst_gltf/src/format/material.rs
Expand Up @@ -158,7 +158,7 @@ fn load_texture(
..Default::default()
};

load_from_image(std::io::Cursor::new(&data), metadata).map_err(|e| Error::new(e))
load_from_image(std::io::Cursor::new(&data), metadata).map_err(Error::new)
}

fn load_sampler_info(sampler: &gltf::texture::Sampler<'_>) -> hal::image::SamplerDesc {
Expand Down
2 changes: 1 addition & 1 deletion amethyst_input/Cargo.toml
Expand Up @@ -23,7 +23,7 @@ derivative = "1.0"
derive-new = "0.5"
fnv = "1"
serde = { version = "1", features = ["derive"] }
winit = { version = "0.20.0-alpha4", features = ["serde"] }
winit = { version = "0.20.0-alpha5", features = ["serde"] }
sdl2 = { version = "0.32.2", optional = true }

thread_profiler = { version = "0.3", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions amethyst_input/src/input_handler.rs
Expand Up @@ -11,11 +11,11 @@ use derivative::Derivative;
use smallvec::SmallVec;
use std::{borrow::Borrow, hash::Hash};
use winit::{
dpi::LogicalPosition,
dpi::LogicalPosition,
event::{
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton,
MouseScrollDelta, VirtualKeyCode, WindowEvent,
}
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseScrollDelta,
VirtualKeyCode, WindowEvent,
},
};

/// This struct holds state information about input devices.
Expand Down
4 changes: 3 additions & 1 deletion amethyst_input/src/system.rs
Expand Up @@ -32,7 +32,9 @@ where
fn build(self, world: &mut World) -> InputSystem<T> {
<InputSystem<T> as System<'_>>::SystemData::setup(world);

let reader = world.fetch_mut::<EventChannel<Event<()>>>().register_reader();
let reader = world
.fetch_mut::<EventChannel<Event<()>>>()
.register_reader();
if let Some(bindings) = self.bindings.as_ref() {
world.fetch_mut::<InputHandler<T>>().bindings = bindings.clone();
}
Expand Down
5 changes: 3 additions & 2 deletions amethyst_rendy/Cargo.toml
Expand Up @@ -25,7 +25,8 @@ glsl-layout = "0.3"
lazy_static = "1.3"
log = "0.4"
palette = { version = "0.4", features = ["serde"] }
rendy = {git = "https://github.com/valkum/rendy", branch = "error_impl", version = "0.5.1", default-features = false, features = ["base", "mesh-obj", "texture-image", "texture-palette", "serde-1", "init"] }
# rendy = {version = "0.5.1", default-features = false, features = ["base", "mesh-obj", "texture-image", "texture-palette", "serde-1", "init"] }
rendy = {git = "https://github.com/amethyst/rendy.git", rev = "cae226ff5988eee6debdfc520e34023368858b9b", version = "0.5.1", default-features = false, features = ["base", "mesh-obj", "texture-image", "texture-palette", "serde-1", "init"] }
ron = "0.5"
serde = { version = "1", features = ["serde_derive"] }
fnv = "1"
Expand All @@ -40,7 +41,7 @@ approx = "0.3.2"
rayon = "1.1.0"
more-asserts = "0.2.1"
criterion = "0.3.0"
winit = "0.20.0-alpha4"
winit = "0.20.0-alpha5"
approx = "0.3"

[features]
Expand Down
39 changes: 22 additions & 17 deletions amethyst_rendy/src/bundle.rs
Expand Up @@ -22,9 +22,12 @@ use amethyst_core::{
SystemBundle,
};
use amethyst_error::{format_err, Error};
use amethyst_window::{DisplayConfig, ScreenDimensions, EventLoop, Window};
use amethyst_window::{DisplayConfig, EventLoop, ScreenDimensions, Window};
use std::collections::HashMap;

#[cfg(feature = "profiler")]
use thread_profiler::profile_scope;

/// A bundle of systems used for rendering using `Rendy` render graph.
///
/// Provides a mechanism for registering rendering plugins.
Expand All @@ -46,19 +49,19 @@ pub struct RenderingBundle<B: Backend> {
impl<B: Backend> RenderingBundle<B> {
/// Create empty `RenderingBundle`. You must register a plugin using
/// [`with_plugin`] in order to actually display anything.
pub fn new<'a>(display_config: DisplayConfig, event_loop: &'a EventLoop<()>) -> Self {
pub fn new(display_config: DisplayConfig, event_loop: &EventLoop<()>) -> Self {
log::debug!("Intializing Rendy");
let config: rendy::factory::Config = Default::default();
let window_builder = display_config
.into_window_builder();
let rendy = rendy::init::WindowedRendy::init(&config, window_builder, event_loop).expect("Failed to initialize graphics backend.");
let window_builder = display_config.into_window_builder();
let rendy = rendy::init::WindowedRendy::init(&config, window_builder, event_loop)
.expect("Failed to initialize graphics backend.");

Self {
plugins: Vec::new(),
factory: Some(rendy.factory),
families: Some(rendy.families),
surface: Some(rendy.surface),
window: Some(rendy.window)
window: Some(rendy.window),
}
}

Expand Down Expand Up @@ -88,20 +91,18 @@ impl<'a, 'b, B: Backend> SystemBundle<'a, 'b> for RenderingBundle<B> {
world: &mut World,
builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
#[cfg(feature = "profiler")]
profile_scope!("build_rendering_bundle");
if let Some(window) = self.window.take() {
let hidpi = window.hidpi_factor();
let (width, height) = window
.inner_size()
.to_physical(hidpi)
.into();
let (width, height) = window.inner_size().to_physical(hidpi).into();
world.insert(ScreenDimensions::new(width, height, hidpi));
world.insert(window);
}
if let Some(factory) = self.factory.take() {

if let Some(factory) = self.factory.take() {
world.insert(factory);
}


if let Some(families) = self.families.as_ref() {
let queue_id = QueueId {
Expand All @@ -110,7 +111,6 @@ impl<'a, 'b, B: Backend> SystemBundle<'a, 'b> for RenderingBundle<B> {
};
world.insert(queue_id);
}


builder.add(MeshProcessorSystem::<B>::default(), "mesh_processor", &[]);
builder.add(
Expand All @@ -124,7 +124,6 @@ impl<'a, 'b, B: Backend> SystemBundle<'a, 'b> for RenderingBundle<B> {
"sprite_sheet_processor",
&[],
);


// make sure that all renderer-specific systems run after game code
builder.add_barrier();
Expand All @@ -133,7 +132,10 @@ impl<'a, 'b, B: Backend> SystemBundle<'a, 'b> for RenderingBundle<B> {
plugin.on_build(world, builder)?;
}
if let Some(families) = self.families.take() {
builder.add_thread_local(RenderingSystem::<B, _>::new(self.into_graph_creator(), families));
builder.add_thread_local(RenderingSystem::<B, _>::new(
self.into_graph_creator(),
families,
));
}
Ok(())
}
Expand Down Expand Up @@ -690,7 +692,10 @@ impl<B: Backend> TargetPlan<B> {
match color {
OutputColor::Surface(surface, clear) => {
let target_metadata = ctx.target_metadata[&self.key];
let suggested_extend = hal::window::Extent2D { width: target_metadata.width, height: target_metadata.height };
let suggested_extend = hal::window::Extent2D {
width: target_metadata.width,
height: target_metadata.height,
};
subpass.add_color_surface();
pass.add_surface(surface, suggested_extend, clear);
}
Expand Down
2 changes: 1 addition & 1 deletion amethyst_rendy/src/formats/mesh.rs
Expand Up @@ -33,7 +33,7 @@ impl Format<MeshData> for ObjFormat {
}
builder.0.into()
})
.map_err(|e| Error::new(e))
.map_err(Error::new)
}
}

Expand Down
2 changes: 1 addition & 1 deletion amethyst_rendy/src/formats/texture.rs
Expand Up @@ -96,7 +96,7 @@ impl Format<TextureData> for ImageFormat {
fn import_simple(&self, bytes: Vec<u8>) -> Result<TextureData, Error> {
load_from_image(std::io::Cursor::new(&bytes), self.0.clone())
.map(|builder| builder.into())
.map_err(|e| Error::new(e))
.map_err(Error::new)
}
}

Expand Down
9 changes: 6 additions & 3 deletions amethyst_rendy/src/pass/base_3d.rs
Expand Up @@ -118,7 +118,8 @@ impl<B: Backend, T: Base3DPassDef> RenderGroupDesc<B, World> for DrawBase3DDesc<
hal::pso::ShaderStageFlags::VERTEX,
hal::pso::ShaderStageFlags::FRAGMENT,
],
).map_err(|_| pso::CreationError::Other)?;
)
.map_err(|_| pso::CreationError::Other)?;
let materials = MaterialSub::new(factory).map_err(|_| pso::CreationError::Other)?;
let skinning = SkinningSub::new(factory).map_err(|_| pso::CreationError::Other)?;

Expand Down Expand Up @@ -438,7 +439,8 @@ impl<B: Backend, T: Base3DPassDef> RenderGroupDesc<B, World> for DrawBase3DTrans
hal::pso::ShaderStageFlags::VERTEX,
hal::pso::ShaderStageFlags::FRAGMENT,
],
).map_err(|_| pso::CreationError::Other)?;
)
.map_err(|_| pso::CreationError::Other)?;

let materials = MaterialSub::new(factory).map_err(|_| pso::CreationError::Other)?;
let skinning = SkinningSub::new(factory).map_err(|_| pso::CreationError::Other)?;
Expand Down Expand Up @@ -788,7 +790,8 @@ fn build_pipelines<B: Backend, T: Base3DPassDef>(
} else {
PipelinesBuilder::new()
.with_pipeline(pipe_desc)
.build(factory, None).map_err(|_| pso::CreationError::Other)
.build(factory, None)
.map_err(|_| pso::CreationError::Other)
};

unsafe {
Expand Down
9 changes: 6 additions & 3 deletions amethyst_rendy/src/pass/debug_lines.rs
Expand Up @@ -57,8 +57,10 @@ impl<B: Backend> RenderGroupDesc<B, World> for DrawDebugLinesDesc {
#[cfg(feature = "profiler")]
profile_scope!("build");

let env = DynamicUniform::new(factory, pso::ShaderStageFlags::VERTEX).map_err(|_| pso::CreationError::Other)?;
let args = DynamicUniform::new(factory, pso::ShaderStageFlags::VERTEX).map_err(|_| pso::CreationError::Other)?;
let env = DynamicUniform::new(factory, pso::ShaderStageFlags::VERTEX)
.map_err(|_| pso::CreationError::Other)?;
let args = DynamicUniform::new(factory, pso::ShaderStageFlags::VERTEX)
.map_err(|_| pso::CreationError::Other)?;
let vertex = DynamicVertexBuffer::new();

let (pipeline, pipeline_layout) = build_lines_pipeline(
Expand Down Expand Up @@ -226,7 +228,8 @@ fn build_lines_pipeline<B: Backend>(
write: true,
}),
)
.build(factory, None).map_err(|_| pso::CreationError::Other);
.build(factory, None)
.map_err(|_| pso::CreationError::Other);

unsafe {
factory.destroy_shader_module(shader_vertex);
Expand Down
3 changes: 2 additions & 1 deletion amethyst_rendy/src/pass/flat2d.rs
Expand Up @@ -434,7 +434,8 @@ fn build_sprite_pipeline<B: Backend>(
write: !transparent,
}),
)
.build(factory, None).map_err(|_| pso::CreationError::Other);
.build(factory, None)
.map_err(|_| pso::CreationError::Other);

unsafe {
factory.destroy_shader_module(shader_vertex);
Expand Down
9 changes: 6 additions & 3 deletions amethyst_rendy/src/pass/skybox.rs
Expand Up @@ -97,10 +97,12 @@ impl<B: Backend> RenderGroupDesc<B, World> for DrawSkyboxDesc {
profile_scope!("build");

let env = FlatEnvironmentSub::new(factory).map_err(|_| pso::CreationError::Other)?;
let colors = DynamicUniform::new(factory, pso::ShaderStageFlags::FRAGMENT).map_err(|_| pso::CreationError::Other)?;
let colors = DynamicUniform::new(factory, pso::ShaderStageFlags::FRAGMENT)
.map_err(|_| pso::CreationError::Other)?;
let mesh = Shape::Sphere(16, 16)
.generate::<Vec<PosTex>>(None)
.build(queue, factory).map_err(|_| pso::CreationError::Other)?;
.build(queue, factory)
.map_err(|_| pso::CreationError::Other)?;

let (pipeline, pipeline_layout) = build_skybox_pipeline(
factory,
Expand Down Expand Up @@ -225,7 +227,8 @@ fn build_skybox_pipeline<B: Backend>(
blend: None,
}]),
)
.build(factory, None).map_err(|_| pso::CreationError::Other);
.build(factory, None)
.map_err(|_| pso::CreationError::Other);

unsafe {
factory.destroy_shader_module(shader_vertex);
Expand Down
23 changes: 11 additions & 12 deletions amethyst_rendy/src/plugins.rs
Expand Up @@ -22,14 +22,12 @@ mod window {
bundle::{ImageOptions, OutputColor},
Format, Kind,
};
use amethyst_config::{Config, ConfigError};
use amethyst_core::{
ecs::{ReadExpect, SystemData},
SystemBundle,
};
use amethyst_window::{DisplayConfig, ScreenDimensions, Window, WindowBundle, EventLoop};
use amethyst_window::{ScreenDimensions, Window, WindowBundle};
use rendy::hal::command::{ClearColor, ClearDepthStencil, ClearValue};
use std::path::Path;

/// A [RenderPlugin] for opening a window and displaying a render target to it.
///
Expand All @@ -43,8 +41,11 @@ mod window {
}

impl RenderToWindow {
/// Creates new RenderToWindow plugin
pub fn new() -> Self {
Self { ..Default::default() }
Self {
..Default::default()
}
}

/// Select render target which will be presented to window.
Expand All @@ -60,7 +61,7 @@ mod window {
}
}

impl< B: Backend> RenderPlugin<B> for RenderToWindow {
impl<B: Backend> RenderPlugin<B> for RenderToWindow {
fn on_build<'a, 'b>(
&mut self,
world: &mut World,
Expand Down Expand Up @@ -89,7 +90,7 @@ mod window {
world: &World,
) -> Result<(), Error> {
self.dirty = false;

let window = <ReadExpect<'_, Window>>::fetch(world);
let surface = factory.create_surface(&*window)?;
let dimensions = self.dimensions.as_ref().unwrap();
Expand All @@ -101,9 +102,9 @@ mod window {
format: Format::D32Sfloat,
clear: Some(ClearValue {
depth_stencil: ClearDepthStencil {
depth: 1.0,
stencil: 0
}
depth: 1.0,
stencil: 0,
},
}),
};

Expand All @@ -113,9 +114,7 @@ mod window {
crate::bundle::TargetPlanOutputs {
colors: vec![OutputColor::Surface(
surface,
self.clear.map(|c|ClearValue {
color: c
}),
self.clear.map(|c| ClearValue { color: c }),
)],
depth: Some(depth_options),
},
Expand Down

0 comments on commit bf2058f

Please sign in to comment.