Update to 0.12 (#6)

0.12 was just released, so template can be updated. No need for render graph anymore, just uses render plugins, and ran cargo update to get rendy minor version
master
Aaron Housh 5 years ago committed by Hilmar Wiegand
parent d1906a5072
commit fb9be8a263

1573
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -5,7 +5,7 @@ authors = ["Hilmar Wiegand <me@hwgnd.de>"]
edition = "2018"
[dependencies]
amethyst = "0.11.0"
amethyst = "0.12.0"
log = { version = "0.4.6", features = ["serde"] }
[features]

@ -1,16 +1,14 @@
use amethyst::{
assets::Processor,
core::transform::TransformBundle,
prelude::*,
renderer::{
sprite_visibility::SpriteVisibilitySortingSystem, types::DefaultBackend, RenderingSystem,
SpriteSheet,
plugins::{RenderFlat2D, RenderToWindow},
types::DefaultBackend,
RenderingBundle,
},
utils::application_root_dir,
window::WindowBundle,
};
mod render;
mod state;
fn main() -> amethyst::Result<()> {
@ -21,23 +19,16 @@ fn main() -> amethyst::Result<()> {
let resources = app_root.join("resources");
let display_config = resources.join("display_config.ron");
let render_graph = render::RenderGraph::default();
let render_system = RenderingSystem::<DefaultBackend, _>::new(render_graph);
let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config))?
.with_bundle(TransformBundle::new())?
.with(
SpriteVisibilitySortingSystem::new(),
"sprite_visibility_system",
&["transform_system"],
)
.with(
Processor::<SpriteSheet>::new(),
"sprite_sheet_processor",
&[],
)
.with_thread_local(render_system);
.with_bundle(
RenderingBundle::<DefaultBackend>::new()
.with_plugin(
RenderToWindow::from_config_path(display_config)
.with_clear([0.34, 0.36, 0.52, 1.0]),
)
.with_plugin(RenderFlat2D::default()),
)?;
let mut game = Application::new(resources, state::MyState, game_data)?;
game.run();

@ -1,103 +0,0 @@
use amethyst::{
ecs::prelude::{ReadExpect, Resources, SystemData},
renderer::{
pass::{DrawFlat2DDesc, DrawFlat2DTransparentDesc},
rendy::{
factory::Factory,
graph::{
render::{RenderGroupDesc, SubpassBuilder},
GraphBuilder,
},
hal::format::Format,
},
types::DefaultBackend,
GraphCreator, Kind,
},
window::{ScreenDimensions, Window},
};
// Window background color
static CLEAR_COLOR: [f32; 4] = [0.34, 0.36, 0.52, 1.0];
#[derive(Default)]
pub struct RenderGraph {
dimensions: Option<ScreenDimensions>,
dirty: bool,
}
impl GraphCreator<DefaultBackend> for RenderGraph {
fn rebuild(&mut self, res: &Resources) -> bool {
use std::ops::Deref;
// Only rebuild when dimensions have changed
let new_dimensions = res.try_fetch::<ScreenDimensions>();
let new_dimensions = new_dimensions.as_ref().map(|d| d.deref());
if self.dimensions.as_ref() != new_dimensions {
self.dirty = true;
self.dimensions = new_dimensions.map(|d| d.clone());
return false;
}
self.dirty
}
fn builder(
&mut self,
factory: &mut Factory<DefaultBackend>,
res: &Resources,
) -> GraphBuilder<DefaultBackend, Resources> {
use amethyst::renderer::rendy::{
graph::present::PresentNode,
hal::command::{ClearDepthStencil, ClearValue},
};
// Since we're freshly building the graph, it will never
// be dirty after this function is called.
self.dirty = false;
let window = <ReadExpect<'_, Window>>::fetch(res);
let surface = factory.create_surface(&window);
let surface_format = factory.get_surface_format(&surface);
let dimensions = self.dimensions.as_ref().unwrap();
let window_kind = Kind::D2(dimensions.width() as u32, dimensions.height() as u32, 1, 1);
let clear_color = ClearValue::Color(CLEAR_COLOR.into());
let clear_depth = ClearValue::DepthStencil(ClearDepthStencil(1.0, 0));
// Build the RenderGraph
let mut builder = GraphBuilder::new();
let color = builder.create_image(window_kind, 1, surface_format, Some(clear_color));
let depth = builder.create_image(window_kind, 1, Format::D32Sfloat, Some(clear_depth));
// Add additional draw groups here for things like UI
let opaque = builder.add_node(
SubpassBuilder::new()
// Draw sprites with flat subpass
.with_group(DrawFlat2DDesc::new().builder())
.with_color(color)
.with_depth_stencil(depth)
.into_pass(),
);
let transparent = builder.add_node(
SubpassBuilder::new()
// Draw sprites with transparency
.with_group(DrawFlat2DTransparentDesc::new().builder())
.with_color(color)
.with_depth_stencil(depth)
.into_pass(),
);
// Render the result to the surface
let _present = builder.add_node(
PresentNode::builder(factory, surface, color)
.with_dependency(opaque)
.with_dependency(transparent),
);
builder
}
}
Loading…
Cancel
Save