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 all 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: 4 additions & 4 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"
edition = "2018"
version = "0.2.2"
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,7 @@ exclude = ["assets/**/*", ".github/**/*"]

[dependencies]
bevy_proto_derive = { version = "0.1.0", path = "bevy_proto_derive" }
bevy = "0.5"
bevy = "0.6"
serde = "1.0.130"
typetag = "0.1"
serde_yaml = "0.8"
Expand Down Expand Up @@ -41,4 +41,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
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Then add it to your app like so:
use bevy_proto::ProtoPlugin;

fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// add dependent plugins, resources, etc. here
// ...
Expand Down Expand Up @@ -295,7 +295,7 @@ struct Renderable {
impl ProtoComponent for Creature {
// Required
fn insert_self(&self, commands: &mut ProtoCommands, asset_server: &Res<AssetServer>) {
let handle: Handle<Texture> = asset_server.load(self.texture_path.as_str());
let handle: Handle<Image> = asset_server.load(self.texture_path.as_str());

entity.insert(SomeTexture {
texture_handle: handle
Expand Down Expand Up @@ -340,14 +340,10 @@ impl ProtoComponent for Creature {
) {
// === 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);
}
}
```
Expand Down
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