Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.6 Upgrade #7

Merged
merged 9 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/

# AWS User-specific
.idea/**/aws.xml
Expand Down Expand Up @@ -40,9 +41,9 @@
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
.idea/*.iml
# .idea/modules
# *.iml
*.iml
# *.ipr

# CMake
Expand Down Expand Up @@ -223,4 +224,4 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains,clion
# End of https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains,clion
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

112 changes: 0 additions & 112 deletions .idea/bevy_proto.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_proto"
version = "0.2.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to bump the minor version with this change at least.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I'll definitely bump the major version haha, just prefer to do that last in case other PRs or changes need to be merged before bumping. Just keeps everything on the same page 🙂

edition = "2018"
edition = "2021"
authors = ["Gino Valente <gino.valente.code@gmail.com>"]
description = "Create config files for entities in Bevy"
repository = "https://github.com/MrGVSV/bevy_proto"
Expand All @@ -12,7 +12,9 @@ exclude = ["assets/**/*", ".github/**/*"]

[dependencies]
bevy_proto_derive = { version = "0.1.0", path = "bevy_proto_derive" }
bevy = "0.5"
# bevy = "0.6"
# bevy = { version = "0.6", default-features = false, path = "../bevy" }
MrGVSV marked this conversation as resolved.
Show resolved Hide resolved
bevy = { version = "0.6", path = "../bevy" }
MrGVSV marked this conversation as resolved.
Show resolved Hide resolved
serde = "1.0.130"
typetag = "0.1"
serde_yaml = "0.8"
Expand Down Expand Up @@ -41,4 +43,4 @@ path = "examples/templates.rs"

[[example]]
name = "bench"
path = "examples/bench.rs"
path = "examples/bench.rs"
chrisburnor marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion bevy_proto_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_proto_derive"
version = "0.1.0"
edition = "2018"
edition = "2021"
authors = ["Gino Valente <gino.valente.code@gmail.com>"]
description = "Derive macro for use with bevy_proto"
repository = "https://github.com/MrGVSV/bevy_proto"
Expand Down
6 changes: 3 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_proto::{ProtoCommands, ProtoComponent, ProtoData, ProtoPlugin};

/// This is the component we will use with our prototype
/// It must derive both Serialize and Deserialize from serde in order to compile
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Component)]
struct Person {
pub name: String,
}
Expand Down Expand Up @@ -44,7 +44,7 @@ impl ProtoComponent for Person {
///
/// Here, we call the attribute with the "Copy" argument as this struct can
/// readily derive Copy and should be marginally faster than Clone
#[derive(Serialize, Deserialize, ProtoComponent)]
#[derive(Serialize, Deserialize, ProtoComponent, Component)]
struct Ordered {
#[proto_comp(Copy)]
pub order: i32,
Expand Down Expand Up @@ -81,7 +81,7 @@ fn introduce(query: Query<(&Person, &Ordered), Added<Person>>) {
}

fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// This plugin should come AFTER any others that it might rely on
// In this case, we need access to what's added by [`DefaultPlugins`]
Expand Down
23 changes: 8 additions & 15 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ fn spawn_sprites_proto(

fn spawn_sprites_programmatic(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>,
) {
println!("Spawning Programmatically:");
let mut total: u128 = 0;
let mut before = Instant::now();
let texture: Handle<Texture> = asset_server.load("textures/sprite.png");
let mat = materials.add(texture.into());

for _ in 0..BATCH_COUNT {
for _ in 0..BATCH_SIZE {
commands.spawn_bundle(SpriteBundle {
material: mat.clone(),
texture: asset_server.load("textures/sprite.png"),
..Default::default()
});
}
Expand All @@ -72,7 +69,7 @@ fn main() {
"Entity Count: {} | Batch Size: {}",
ENTITY_COUNT, BATCH_SIZE
);
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ProtoPlugin::default())
.add_startup_system(spawn_sprites_proto.system().label("prototype"))
Expand All @@ -83,7 +80,7 @@ fn main() {
/// The code below is covered in the `bundles` example. It's an implementation
/// detail we don't need to focus on for this particular example

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Component)]
struct SpriteBundleDef {
pub texture_path: HandlePath,
}
Expand All @@ -92,13 +89,13 @@ struct SpriteBundleDef {
impl ProtoComponent for SpriteBundleDef {
fn insert_self(&self, commands: &mut ProtoCommands, _asset_server: &Res<AssetServer>) {
// === Get Prepared Assets === //
let material: Handle<ColorMaterial> = commands
let texture: Handle<Image> = commands
.get_handle(self, &self.texture_path)
.expect("Expected ColorMaterial handle to have been created");
.expect("Expected Image handle to have been created");

// === Generate Bundle === //
let my_bundle = SpriteBundle {
material,
texture,
..Default::default()
};

Expand All @@ -109,13 +106,9 @@ impl ProtoComponent for SpriteBundleDef {
fn prepare(&self, world: &mut World, prototype: &Box<dyn Prototypical>, data: &mut ProtoData) {
// === Load Handles === //
let asset_server = world.get_resource::<AssetServer>().unwrap();
let texture: Handle<Texture> = asset_server.load(self.texture_path.as_str());

// === Transform Handles === //
let mut mat_res = world.get_resource_mut::<Assets<ColorMaterial>>().unwrap();
let mat = mat_res.add(texture.into());
let texture: Handle<Image> = asset_server.load(self.texture_path.as_str());

// === Save Handles === //
data.insert_handle(prototype, self, &self.texture_path, mat);
data.insert_handle(prototype, self, &self.texture_path, texture);
}
}
Loading