Skip to content

Commit

Permalink
Merge pull request #3 from bevyengine/master
Browse files Browse the repository at this point in the history
Merge latest changes
  • Loading branch information
ashneverdawn authored Aug 30, 2020
2 parents 1051135 + 8106f77 commit 0e8b836
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 17 deletions.
22 changes: 13 additions & 9 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
sync::Arc,
thread,
};

use thiserror::Error;

/// The type used for asset versioning
Expand Down Expand Up @@ -184,21 +185,24 @@ impl AssetServer {

#[cfg(feature = "filesystem_watcher")]
pub fn filesystem_watcher_system(asset_server: Res<AssetServer>) {
use notify::event::{Event, EventKind, ModifyKind};
let mut changed = HashSet::default();

while let Some(filesystem_watcher) = asset_server.filesystem_watcher.read().as_ref() {
let result = match filesystem_watcher.receiver.try_recv() {
Ok(result) => result,
Err(TryRecvError::Empty) => {
loop {
let result = {
let rwlock_guard = asset_server.filesystem_watcher.read();
if let Some(filesystem_watcher) = rwlock_guard.as_ref() {
filesystem_watcher.receiver.try_recv()
} else {
break;
}
};
let event = match result {
Ok(result) => result.unwrap(),
Err(TryRecvError::Empty) => break,
Err(TryRecvError::Disconnected) => panic!("FilesystemWatcher disconnected"),
};

let event = result.unwrap();
if let Event {
kind: EventKind::Modify(ModifyKind::Data(_)),
if let notify::event::Event {
kind: notify::event::EventKind::Modify(_),
paths,
..
} = event
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_ecs/src/schedule/parallel_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl ExecutorStage {
systems: &[Arc<Mutex<Box<dyn System>>>],
schedule_changed: bool,
) {
let start_archetypes_generation = world.archetypes_generation();
let compute_pool = resources
.get_cloned::<bevy_tasks::ComputeTaskPool>()
.unwrap();
Expand Down Expand Up @@ -388,7 +389,11 @@ impl ExecutorStage {
}
}

self.last_archetypes_generation = world.archetypes_generation();
// If world's archetypes_generation is the same as it was before running any systems then
// we can assume that all systems have correct archetype accesses.
if start_archetypes_generation == world.archetypes_generation() {
self.last_archetypes_generation = world.archetypes_generation();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ once_cell = "1.4.0"
downcast-rs = "1.1.1"
thiserror = "1.0"
anyhow = "1.0"
hex = "0.4.2"
hexasphere = "1.0.0"
parking_lot = "0.10"

Expand Down
96 changes: 96 additions & 0 deletions crates/bevy_render/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ impl Color {
Color { r, g, b, a }
}

pub fn hex<T: AsRef<str>>(hex: T) -> Result<Color, HexColorError> {
let hex = hex.as_ref();

// RGB
if hex.len() == 3 {
let mut data = [0; 6];
for (i, ch) in hex.chars().enumerate() {
data[i * 2] = ch as u8;
data[i * 2 + 1] = ch as u8;
}
return decode_rgb(&data);
}

// RGBA
if hex.len() == 4 {
let mut data = [0; 8];
for (i, ch) in hex.chars().enumerate() {
data[i * 2] = ch as u8;
data[i * 2 + 1] = ch as u8;
}
return decode_rgba(&data);
}

// RRGGBB
if hex.len() == 6 {
return decode_rgb(hex.as_bytes());
}

// RRGGBBAA
if hex.len() == 8 {
return decode_rgba(hex.as_bytes());
}

Err(HexColorError::Length)
}

pub fn rgb_u8(r: u8, g: u8, b: u8) -> Color {
Color::rgba_u8(r, g, b, u8::MAX)
}
Expand Down Expand Up @@ -219,3 +255,63 @@ impl From<Handle<Texture>> for ColorSource {
}

impl_render_resource_bytes!(Color);

#[derive(Debug)]
pub enum HexColorError {
Length,
Hex(hex::FromHexError),
}

fn decode_rgb(data: &[u8]) -> Result<Color, HexColorError> {
let mut buf = [0; 3];
match hex::decode_to_slice(data, &mut buf) {
Ok(_) => {
let r = buf[0] as f32 / 255.0;
let g = buf[1] as f32 / 255.0;
let b = buf[2] as f32 / 255.0;
Ok(Color::rgb(r, g, b))
}
Err(err) => Err(HexColorError::Hex(err)),
}
}

fn decode_rgba(data: &[u8]) -> Result<Color, HexColorError> {
let mut buf = [0; 4];
match hex::decode_to_slice(data, &mut buf) {
Ok(_) => {
let r = buf[0] as f32 / 255.0;
let g = buf[1] as f32 / 255.0;
let b = buf[2] as f32 / 255.0;
let a = buf[3] as f32 / 255.0;
Ok(Color::rgba(r, g, b, a))
}
Err(err) => Err(HexColorError::Hex(err)),
}
}

#[test]
fn test_hex_color() {
assert_eq!(Color::hex("FFF").unwrap(), Color::rgb(1.0, 1.0, 1.0));
assert_eq!(Color::hex("000").unwrap(), Color::rgb(0.0, 0.0, 0.0));
assert!(Color::hex("---").is_err());

assert_eq!(Color::hex("FFFF").unwrap(), Color::rgba(1.0, 1.0, 1.0, 1.0));
assert_eq!(Color::hex("0000").unwrap(), Color::rgba(0.0, 0.0, 0.0, 0.0));
assert!(Color::hex("----").is_err());

assert_eq!(Color::hex("FFFFFF").unwrap(), Color::rgb(1.0, 1.0, 1.0));
assert_eq!(Color::hex("000000").unwrap(), Color::rgb(0.0, 0.0, 0.0));
assert!(Color::hex("------").is_err());

assert_eq!(
Color::hex("FFFFFFFF").unwrap(),
Color::rgba(1.0, 1.0, 1.0, 1.0)
);
assert_eq!(
Color::hex("00000000").unwrap(),
Color::rgba(0.0, 0.0, 0.0, 0.0)
);
assert!(Color::hex("--------").is_err());

assert!(Color::hex("1234567890").is_err());
}
2 changes: 1 addition & 1 deletion crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum RenderCommand {
}

/// A component that indicates how to draw an entity.
#[derive(Properties)]
#[derive(Properties, Clone)]
pub struct Draw {
pub is_visible: bool,
pub is_transparent: bool,
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod prelude {
draw::Draw,
entity::*,
mesh::{shape, Mesh},
pass::ClearColor,
pipeline::RenderPipelines,
shader::Shader,
texture::Texture,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/render_pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RenderPipeline {
}
}

#[derive(Properties)]
#[derive(Properties, Clone)]
pub struct RenderPipelines {
pub pipelines: Vec<RenderPipeline>,
#[property(ignore)]
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_text/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use bevy_render::{
};
use bevy_sprite::{TextureAtlas, TextureAtlasSprite};

#[derive(Clone)]
pub struct TextStyle {
pub font_size: f32,
pub color: Color,
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bevy_transform::{
prelude::{Rotation, Scale, Transform, Translation},
};

#[derive(Bundle)]
#[derive(Bundle, Clone)]
pub struct NodeComponents {
pub node: Node,
pub style: Style,
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Default for NodeComponents {
}
}

#[derive(Bundle)]
#[derive(Bundle, Clone)]
pub struct ImageComponents {
pub node: Node,
pub style: Style,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Default for ImageComponents {
}
}

#[derive(Bundle)]
#[derive(Bundle, Clone)]
pub struct TextComponents {
pub node: Node,
pub style: Style,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Default for TextComponents {
}
}

#[derive(Bundle)]
#[derive(Bundle, Clone)]
pub struct ButtonComponents {
pub node: Node,
pub button: Button,
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ui/src/widget/button.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#[derive(Clone)]
pub struct Button;
1 change: 1 addition & 0 deletions crates/bevy_ui/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bevy_math::Size;
use bevy_render::texture::Texture;
use bevy_sprite::ColorMaterial;

#[derive(Clone)]
pub enum Image {
KeepAspect,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bevy_sprite::TextureAtlas;
use bevy_text::{DrawableText, Font, FontAtlasSet, TextStyle};
use bevy_transform::prelude::Transform;

#[derive(Default)]
#[derive(Default, Clone)]
pub struct Text {
pub value: String,
pub font: Handle<Font>,
Expand Down

0 comments on commit 0e8b836

Please sign in to comment.