Skip to content

Commit

Permalink
Bevy 0.14 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF authored Jul 11, 2024
1 parent b734170 commit 09a95bc
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 91 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build
run: cargo build --verbose

build_features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: all features
run: cargo build --verbose --all-features
Expand All @@ -39,7 +39,7 @@ jobs:
build_examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build 2d game of life
run: cargo clippy --all-features --example 2d_game_of_life
Expand All @@ -57,15 +57,15 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: test
run: cargo test --tests --all-features

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: "rustfmt"
Expand All @@ -75,7 +75,7 @@ jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cargo clippy installation
run: rustup component add clippy
Expand All @@ -85,7 +85,7 @@ jobs:
rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: rustdoc
run: cargo rustdoc --all-features -- -D warnings
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

* Bevy 0.14
* (**BREAKING**) `CyclicColorState` now takes a `const N: usize` generic instead
of hard coded `9`
* `2d_cyclic_colors` example is now in grayscale
* Reflection is now optional through `bevy_reflect` feature gate

## 0.9.0

* Added rustfmt config (#19)
Expand Down
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,38 @@ categories = ["game-engines", "game-development"]
resolver = "2"

[features]
default = ["2D"]
default = ["2D", "bevy_reflect"]
2D = []
3D = []
auto-coloring = ["bevy/bevy_sprite"]
auto-coloring = ["bevy/bevy_sprite", "bevy/bevy_color"]
bevy_reflect = ["dep:bevy_reflect"]

[dependencies.bevy]
version = "0.13"
version = "0.14"
default-features = false
features = ["bevy_render"]

[dependencies.bevy_reflect]
version = "0.14"
optional = true

[dev-dependencies]
rand = "0.8"

[dev-dependencies.bevy]
version = "0.13"
version = "0.14"
features = [
"bevy_asset",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_color",
"bevy_render",
"bevy_sprite",
"png",
"x11",
"tonemapping_luts",
"multi-threaded",
"multi_threaded",
# Faster compilation
"dynamic_linking"
]
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ No feature is required for the plugin to work and the main traits `Cell` and
* plugin presets: `GameOfLife3dPlugin`, `ImmigrationGame3dPlugin`,
`RainbowGame3dPlugin`, `WireWorld3dPlugin`, `CyclicAutomaton3dPlugin`
* `auto-coloring` (Example or debug purpose):
* Enables `CellStateMaterials` resource to contain material handles
* The `CellState` type now requires to build a `CellStateMaterials`
* All `CellState` components with materials will be colored according to
their type.
* The `CellState` trait now requires a `color` method
* `bevy_reflect` (enabled by default): Enable support for reflection for
common types

## Disclaimer

Expand Down
9 changes: 5 additions & 4 deletions examples/2d_cyclic_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use bevy::prelude::*;
use bevy_life::{CyclicColorCellState, CyclicColors2dPlugin, MooreCell2d, SimulationBatch};
use rand::Rng;

const N: usize = 9;

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
Expand All @@ -12,7 +14,7 @@ fn main() {
}),
..default()
}))
.add_plugins(CyclicColors2dPlugin::new().with_time_step(0.05))
.add_plugins(CyclicColors2dPlugin::<N>::new().with_time_step(0.05))
.insert_resource(SimulationBatch)
.add_systems(Startup, (setup_camera, setup_map))
.run();
Expand All @@ -32,7 +34,6 @@ fn spawn_map(commands: &mut Commands) {
let (size_x, size_y) = (300, 200);
let sprite_size = 4.;

let max_index = CyclicColorCellState::max_index();
commands
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
-(size_x as f32 * sprite_size) / 2.,
Expand All @@ -42,8 +43,8 @@ fn spawn_map(commands: &mut Commands) {
.with_children(|builder| {
for y in 0..=size_y {
for x in 0..=size_x {
let color_index = rng.gen_range(0..max_index);
let state = CyclicColorCellState(color_index);
let color_index = rng.gen_range(0..N);
let state = CyclicColorCellState::<N>(color_index);
builder.spawn((
SpriteBundle {
sprite: Sprite {
Expand Down
2 changes: 1 addition & 1 deletion examples/2d_game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) {
let mut rng = rand::thread_rng();
let (size_x, size_y) = (600, 400);
let sprite_size = 2.;
let color = Color::rgba(0., 0., 0., 0.);
let color = Color::srgba(0., 0., 0., 0.);

commands
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
Expand Down
2 changes: 1 addition & 1 deletion examples/2d_immigration_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) {
let mut rng = rand::thread_rng();
let (size_x, size_y) = (600, 400);
let sprite_size = 2.;
let color = Color::rgba(0., 0., 0., 0.);
let color = Color::srgba(0., 0., 0., 0.);

commands
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
Expand Down
2 changes: 1 addition & 1 deletion examples/2d_rainbow_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) {
let mut rng = rand::thread_rng();
let (size_x, size_y) = (600, 400);
let sprite_size = 2.;
let color = Color::rgba(1., 0., 0., 1.);
let color = Color::srgba(1., 0., 0., 1.);

commands
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
Expand Down
10 changes: 5 additions & 5 deletions examples/2d_rock_paper_scissor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_life::{CellState, CellularAutomatonPlugin, MooreCell2d, SimulationBatch};
use rand::Rng;

Expand Down Expand Up @@ -61,7 +61,7 @@ fn spawn_map(commands: &mut Commands) {
let mut rng = rand::thread_rng();
let (size_x, size_y) = (300, 200);
let sprite_size = 4.;
let color = Color::rgba(0., 0., 0., 0.);
let color = Color::srgba(0., 0., 0., 0.);

commands
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
Expand Down Expand Up @@ -106,8 +106,8 @@ pub fn color_sprites(
query
.par_iter_mut()
.for_each(|(state, mut sprite)| match state {
RockPaperScissor::Rock => sprite.color = Color::BLUE,
RockPaperScissor::Paper => sprite.color = Color::BEIGE,
RockPaperScissor::Scissor => sprite.color = Color::RED,
RockPaperScissor::Rock => sprite.color = Color::Srgba(BLUE),
RockPaperScissor::Paper => sprite.color = Color::Srgba(BEIGE),
RockPaperScissor::Scissor => sprite.color = Color::Srgba(RED),
});
}
5 changes: 3 additions & 2 deletions src/components/cell/hexagon_2d_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::Cell;
use bevy::prelude::{Component, IVec3, Reflect};
use bevy::prelude::{Component, IVec3};
use std::ops::Deref;

const NEIGHBOR_COORDINATES: [IVec3; 6] = [
Expand Down Expand Up @@ -34,7 +34,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 6] = [
/// \_____/
///
/// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood
#[derive(Debug, Clone, Component, Reflect)]
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct HexagonCell2d {
/// The 2D cell coordinates
pub coords: IVec3,
Expand Down
5 changes: 3 additions & 2 deletions src/components/cell/moore_2d_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::Cell;
use bevy::prelude::{Component, IVec2, Reflect};
use bevy::prelude::{Component, IVec2};
use std::ops::Deref;

const NEIGHBOR_COORDINATES: [IVec2; 8] = [
Expand Down Expand Up @@ -40,7 +40,8 @@ const NEIGHBOR_COORDINATES: [IVec2; 8] = [
/// ```
///
/// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood
#[derive(Debug, Clone, Component, Reflect)]
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct MooreCell2d {
/// The 2D cell coordinates
pub coords: IVec2,
Expand Down
5 changes: 3 additions & 2 deletions src/components/cell/moore_3d_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::Cell;
use bevy::prelude::{Component, IVec3, Reflect};
use bevy::prelude::{Component, IVec3};
use std::ops::Deref;

const NEIGHBOR_COORDINATES: [IVec3; 26] = [
Expand Down Expand Up @@ -66,7 +66,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 26] = [
/// [Moore] 3D cell, it has 26 neighbors and uses `IVec3` coordinates
///
/// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood
#[derive(Debug, Clone, Component, Reflect)]
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct MooreCell3d {
/// The 3D cell coordinates
pub coords: IVec3,
Expand Down
5 changes: 3 additions & 2 deletions src/components/cell/neumann_2d_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::Cell;
use bevy::prelude::{Component, IVec2, Reflect};
use bevy::prelude::{Component, IVec2};
use std::ops::Deref;

const NEIGHBOR_COORDINATES: [IVec2; 4] = [
Expand Down Expand Up @@ -31,7 +31,8 @@ const NEIGHBOR_COORDINATES: [IVec2; 4] = [
/// +-------+
/// ```
/// [Neumann]: https://en.wikipedia.org/wiki/Von_Neumann_neighborhood
#[derive(Debug, Clone, Component, Reflect)]
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct NeumannCell2d {
/// The 2D cell coordinates
pub coords: IVec2,
Expand Down
5 changes: 3 additions & 2 deletions src/components/cell/neumann_3d_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::Cell;
use bevy::prelude::{Component, IVec3, Reflect};
use bevy::prelude::{Component, IVec3};
use std::ops::Deref;

const NEIGHBOR_COORDINATES: [IVec3; 6] = [
Expand Down Expand Up @@ -27,7 +27,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 6] = [
/// coordinates
///
/// [Neumann]: https://en.wikipedia.org/wiki/Von_Neumann_neighborhood
#[derive(Debug, Clone, Component, Reflect)]
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct NeumannCell3d {
/// The 3D cell coordinates
pub coords: IVec3,
Expand Down
7 changes: 4 additions & 3 deletions src/components/cell_state/conway_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::components::CellState;
use bevy::prelude::{Component, Reflect};
#[cfg(feature = "auto-coloring")]
use bevy::render::color::Color;
use bevy::prelude::Color;
use bevy::prelude::Component;
use std::ops::{Deref, DerefMut};

/// Classic cellular automation state and rules following Conway's game of life
Expand All @@ -17,7 +17,8 @@ use std::ops::{Deref, DerefMut};
/// if by reproduction.
///
/// A dead cell is `false`, a live cell is `true`
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component, Reflect)]
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct ConwayCellState(pub bool);

impl CellState for ConwayCellState {
Expand Down
7 changes: 4 additions & 3 deletions src/components/cell_state/conway_state_3d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::components::CellState;
use bevy::prelude::{Component, Reflect};
#[cfg(feature = "auto-coloring")]
use bevy::render::color::Color;
use bevy::prelude::Color;
use bevy::prelude::Component;
use std::ops::{Deref, DerefMut};

/// Classic cellular automation state and rules following Conway's game of life
Expand All @@ -17,7 +17,8 @@ use std::ops::{Deref, DerefMut};
/// by reproduction.
///
/// A dead cell is `false`, a live cell is `true`
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component, Reflect)]
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct ConwayCell4555State(pub bool);

impl CellState for ConwayCell4555State {
Expand Down
Loading

0 comments on commit 09a95bc

Please sign in to comment.