Skip to content

Commit

Permalink
Merge pull request #50 from shawnscode/dev
Browse files Browse the repository at this point in the history
Cleans deprecated codes and adds explict 'scope lifetime for `SystemDispatcher`.
  • Loading branch information
shawnscode authored Apr 3, 2018
2 parents dcd0d83 + 90a038d commit 2c95585
Show file tree
Hide file tree
Showing 38 changed files with 1,125 additions and 905 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ The format is based on [Keep a Changelog][kc], and this project adheres to

## [Unreleased]

This version introduces a lots of break changes and significant performance improvement by integrating with [rayon](https://github.com/rayon-rs/rayon). And the error handle mechanism has been refined with [failure](https://github.com/rust-lang-nursery/failure).
## [0.4.0] - 2018-04-03

* This version introduces a lots of break changes and significant performance improvement by integrating with [rayon](https://github.com/rayon-rs/rayon).

* The error handle mechanism has been refined with [failure](https://github.com/rust-lang-nursery/failure).

## [0.3.0] - 2018-02-28

Expand Down Expand Up @@ -64,4 +68,5 @@ This version introduces a lots of break changes and significant performance impr
[0.2.0]: https://github.com/shawnscode/crayon/compare/v0.1.0...v0.2.0
[0.2.1]: https://github.com/shawnscode/crayon/compare/v0.1.0...v0.2.1
[0.3.0]: https://github.com/shawnscode/crayon/compare/v0.2.1...v0.3.0
[Unreleased]: https://github.com/shawnscode/crayon/compare/v0.3.0...HEAD
[0.4.0]: https://github.com/shawnscode/crayon/compare/v0.3.0...v0.4.0
[Unreleased]: https://github.com/shawnscode/crayon/compare/v0.4.0...HEAD
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ codecov = { repository = "shawnscode/crayon", branch = "master", service = "gith
members = [ "crayon-examples", "modules/imgui", "modules/3d" ]

[dependencies]
libc = "0.2.36"
gl = "0.9.0"
glutin = "0.12.0"
cgmath = "0.16.0"
gl = "0.10.0"
glutin = "0.13.1"
cgmath = "0.16.1"
failure = "0.1.1"
rayon = "1.0.1"
zip = "0.3.0"
zip = "0.3.1"

[dev-dependencies]
rand = "0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion crayon-examples/src/imgui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Window {
let canvas = Canvas::new(ctx).unwrap();

let mut setup = SurfaceSetup::default();
setup.set_clear(Color::white(), None, None);
setup.set_clear(math::Color::white(), None, None);
setup.set_sequence(true);
let surface = ctx.shared::<GraphicsSystem>().create_surface(setup)?;

Expand Down
2 changes: 1 addition & 1 deletion crayon-examples/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Window {
let canvas = Canvas::new(ctx).unwrap();

let mut setup = SurfaceSetup::default();
setup.set_clear(Color::white(), None, None);
setup.set_clear(math::Color::white(), None, None);
setup.set_sequence(true);
let surface = ctx.shared::<GraphicsSystem>().create_surface(setup)?;

Expand Down
31 changes: 19 additions & 12 deletions crayon-examples/src/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Window {
let video = ctx.shared::<GraphicsSystem>().clone();

// Create scene.
let mut scene = Scene::new(ctx)?;
let mut scene = Scene::new(ctx, SceneSetup::default())?;

let camera = {
let camera = scene.create();
Expand Down Expand Up @@ -71,11 +71,16 @@ impl Window {
}

fn create_lits(scene: &mut Scene, video: &GraphicsSystemShared) -> Result<[Entity; 4]> {
let shader = factory::pipeline::color(scene)?;
let shader = factory::pipeline::color(&mut scene.resources)?;
let mesh = factory::mesh::cube(video)?;

let mut lits = [Entity::nil(); 4];
let colors = [Color::red(), Color::blue(), Color::green(), Color::cyan()];
let colors = [
math::Color::red(),
math::Color::blue(),
math::Color::green(),
math::Color::cyan(),
];
let positions = [
[1.0, 0.5, 0.0],
[-1.0, 0.5, 0.0],
Expand Down Expand Up @@ -104,10 +109,11 @@ impl Window {
ent.set_position(positions[i]);
}

let color: [f32; 4] = colors[i].into();
let mat = scene.create_material(MaterialSetup::new(shader))?;
let color: [f32; 4] = colors[i].rgba();
let mat = scene.resources.create_material(MaterialSetup::new(shader))?;

{
let mut m = scene.material_mut(mat).unwrap();
let mut m = scene.resources.material_mut(mat).unwrap();
m.bind("u_Color", color)?;
}

Expand Down Expand Up @@ -136,24 +142,24 @@ impl Window {
scene: &mut Scene,
video: &GraphicsSystemShared,
) -> Result<(Entity, MaterialHandle)> {
let shader = factory::pipeline::phong(scene)?;
let shader = factory::pipeline::phong(&mut scene.resources)?;

let mut setup = MeshSetup::default();
setup.location = Location::shared("/std/cornell_box.obj");
let mesh = video.create_mesh_from_file::<OBJParser>(setup)?;

let mat_wall = scene.create_material(MaterialSetup::new(shader))?;
let mat_wall = scene.resources.create_material(MaterialSetup::new(shader))?;
{
let m = scene.material_mut(mat_wall).unwrap();
let m = scene.resources.material_mut(mat_wall).unwrap();
m.bind("u_Ambient", [1.0, 1.0, 1.0])?;
m.bind("u_Diffuse", [1.0, 1.0, 1.0])?;
m.bind("u_Specular", [0.0, 0.0, 0.0])?;
m.bind("u_Shininess", 0.0)?;
}

let mat_block = scene.create_material(MaterialSetup::new(shader))?;
let mat_block = scene.resources.create_material(MaterialSetup::new(shader))?;
{
let m = scene.material_mut(mat_block).unwrap();
let m = scene.resources.material_mut(mat_block).unwrap();
m.bind("u_Ambient", [1.0, 1.0, 1.0])?;
m.bind("u_Diffuse", [1.0, 1.0, 1.0])?;
m.bind("u_Specular", [1.0, 1.0, 1.0])?;
Expand Down Expand Up @@ -238,7 +244,7 @@ impl Application for Window {
}

{
let m = self.scene.material_mut(self.material).unwrap();
let m = self.scene.resources.material_mut(self.material).unwrap();
m.bind("u_Ambient", *ambient)?;
m.bind("u_Diffuse", *diffuse)?;
m.bind("u_Specular", *specular)?;
Expand All @@ -251,6 +257,7 @@ impl Application for Window {
} else {
self.scene.draw_shadow(None)?;
}

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crayon-examples/src/render_target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Window {
let mut setup = SurfaceSetup::default();
setup.set_attachments(&[rendered_texture], None)?;
setup.set_order(0);
setup.set_clear(Color::gray(), None, None);
setup.set_clear(math::Color::gray(), None, None);
let surface = video.create_surface(setup)?;

// Create shader state.
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Application for Window {

fn on_update(&mut self, _: &Context) -> Result<()> {
{
let mut dc = DrawCall::new(self.pass.shader, self.pass.mesh);
let dc = DrawCall::new(self.pass.shader, self.pass.mesh);
let cmd = dc.build_from(0, 3)?;
self.video.submit(self.pass.surface, 0u64, cmd)?;
}
Expand Down
26 changes: 13 additions & 13 deletions modules/3d/src/assets/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod pipeline {
use crayon::resource::prelude::*;
use self::UniformVariableType as UVT;

use scene::Scene;
use resources::Resources;
use assets::pipeline::{PipelineHandle, PipelineSetup};
use errors::*;

Expand All @@ -12,9 +12,9 @@ pub mod pipeline {
pub const UNDEFINED: &str = "__Core/Scene/Shader/UNDEFINED";
pub const COLOR: &str = "__Core/Scene/Shader/COLOR";

pub fn pbr(scene: &mut Scene) -> Result<PipelineHandle> {
pub fn pbr(resources: &mut Resources) -> Result<PipelineHandle> {
let location = Location::shared(PBR);
if let Some(pipeline) = scene.lookup_pipeline(location) {
if let Some(pipeline) = resources.lookup_pipeline(location) {
return Ok(pipeline);
}

Expand Down Expand Up @@ -44,12 +44,12 @@ pub mod pipeline {
setup.params.uniforms = uniforms;

let pipeline_setup = PipelineSetup::new(setup);
scene.create_pipeline(pipeline_setup)
resources.create_pipeline(pipeline_setup)
}

pub fn phong(scene: &mut Scene) -> Result<PipelineHandle> {
pub fn phong(resources: &mut Resources) -> Result<PipelineHandle> {
let location = Location::shared(PHONG);
if let Some(pipeline) = scene.lookup_pipeline(location) {
if let Some(pipeline) = resources.lookup_pipeline(location) {
return Ok(pipeline);
}

Expand Down Expand Up @@ -100,12 +100,12 @@ pub mod pipeline {
setup.params.uniforms = uniforms;

let pipeline_setup = PipelineSetup::new(setup);
scene.create_pipeline(pipeline_setup)
resources.create_pipeline(pipeline_setup)
}

pub fn color(scene: &mut Scene) -> Result<PipelineHandle> {
pub fn color(resources: &mut Resources) -> Result<PipelineHandle> {
let location = Location::shared(COLOR);
if let Some(pipeline) = scene.lookup_pipeline(location) {
if let Some(pipeline) = resources.lookup_pipeline(location) {
return Ok(pipeline);
}

Expand Down Expand Up @@ -133,12 +133,12 @@ pub mod pipeline {
setup.params.uniforms = uniforms;

let pipeline_setup = PipelineSetup::new(setup);
scene.create_pipeline(pipeline_setup)
resources.create_pipeline(pipeline_setup)
}

pub fn undefined(scene: &mut Scene) -> Result<PipelineHandle> {
pub fn undefined(resources: &mut Resources) -> Result<PipelineHandle> {
let location = Location::shared(UNDEFINED);
if let Some(pipeline) = scene.lookup_pipeline(location) {
if let Some(pipeline) = resources.lookup_pipeline(location) {
return Ok(pipeline);
}

Expand All @@ -165,7 +165,7 @@ pub mod pipeline {
setup.params.uniforms = uniforms;

let pipeline_setup = PipelineSetup::new(setup);
scene.create_pipeline(pipeline_setup)
resources.create_pipeline(pipeline_setup)
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/3d/src/components/light.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crayon::math;
use crayon::ecs::prelude::*;
use crayon::utils::Color;

#[derive(Debug, Clone, Copy)]
pub struct Light {
Expand All @@ -8,7 +8,7 @@ pub struct Light {
/// Is this light casting shadow.
pub shadow_caster: bool,
/// Color of the light.
pub color: Color,
pub color: math::Color<f32>,
/// Brightness of the light source, in lumens.
pub intensity: f32,
/// Light source
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Default for Light {
Light {
enable: true,
shadow_caster: false,
color: Color::white(),
color: math::Color::white(),
intensity: 1.0,
source: LitSource::Dir,
}
Expand Down
Loading

0 comments on commit 2c95585

Please sign in to comment.