Skip to content

Commit

Permalink
Rename dynamic-api Feature to dynamic_api
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Nov 5, 2020
1 parent 9111e06 commit 40a70b4
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ png = ["bevy_render/png"]
hdr = ["bevy_render/hdr"]

# Enable the dynamic systems and components API ( useful for developing scripting solutions )
dynamic-api = ["bevy_ecs/dynamic-api", "bevy_scene/dynamic-api"]
dynamic_api = ["bevy_ecs/dynamic_api", "bevy_scene/dynamic_api"]

# Audio format support (MP3 is enabled by default)
mp3 = ["bevy_audio/mp3"]
Expand Down Expand Up @@ -224,12 +224,12 @@ path = "examples/ecs/hierarchy.rs"
[[example]]
name = "dynamic_systems"
path = "examples/ecs/dynamic_systems.rs"
required-features = ["dynamic-api"]
required-features = ["dynamic_api"]

[[example]]
name = "dynamic_components"
path = "examples/ecs/dynamic_components.rs"
required-features = ["dynamic-api"]
required-features = ["dynamic_api"]

[[example]]
name = "breakout"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["game-engines", "data-structures"]

[features]
profiler = []
dynamic-api = ["bevy_hecs/dynamic-api"]
dynamic_api = ["bevy_hecs/dynamic_api"]

[dependencies]
bevy_hecs = { path = "hecs", features = ["macros", "serialize"], version = "0.3.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/hecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std = []
macros = ["bevy_hecs_macros", "lazy_static"]
serialize = ["serde"]
# Enables the dynamic components and systems APIs
dynamic-api = ["std"]
dynamic_api = ["std"]

[dependencies]
bevy_hecs_macros = { path = "macros", version = "0.3.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/hecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl TypeInfo {
}

/// Get the [`TypeInfo`] for an external type with the given layout and drop function
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
pub fn of_external(external_id: u64, layout: Layout, drop: unsafe fn(*mut u8)) -> Self {
TypeInfo {
id: ComponentId::ExternalId(external_id),
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/hecs/src/entity_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl EntityBuilder {
}

/// Add a dynamic component given the component ID, the layout and the raw data slice
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
pub fn add_dynamic(&mut self, info: TypeInfo, data: &[u8]) -> &mut Self {
self.add_with_typeinfo(info, data, false);
self
Expand Down Expand Up @@ -231,10 +231,10 @@ impl Drop for BuiltEntity<'_> {

#[cfg(test)]
mod test {
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use super::*;

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
#[test]
#[should_panic(expected = "Data length does not match component size")]
fn dynamic_data_invalid_length_panics() {
Expand Down
22 changes: 11 additions & 11 deletions crates/bevy_ecs/hecs/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl World {
let arch = &mut self.archetypes[loc.archetype as usize];
let mut info = arch.types().to_vec();
for ty in components.type_info() {
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
// If this is a dynamic component
if let ComponentId::ExternalId(id) = ty.id() {
// If we've previously registered a component under this ID
Expand Down Expand Up @@ -1038,12 +1038,12 @@ impl From<MissingComponent> for ComponentError {
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use std::{cmp::Ordering, hash::Hasher};

/// Uniquely identifies a type of component. This is conceptually similar to
/// Rust's [`TypeId`], but allows for external type IDs to be defined.
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
pub enum ComponentId {
/// A Rust-native [`TypeId`]
Expand All @@ -1053,7 +1053,7 @@ pub enum ComponentId {
ExternalId(u64),
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
#[allow(clippy::derive_hash_xor_eq)] // Fine because we uphold k1 == k2 ⇒ hash(k1) == hash(k2)
impl Hash for ComponentId {
fn hash<H: Hasher>(&self, state: &mut H) {
Expand All @@ -1068,7 +1068,7 @@ impl Hash for ComponentId {
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl Ord for ComponentId {
fn cmp(&self, other: &Self) -> Ordering {
if self == other {
Expand All @@ -1090,14 +1090,14 @@ impl Ord for ComponentId {
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl PartialOrd for ComponentId {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl From<TypeId> for ComponentId {
fn from(item: TypeId) -> Self {
ComponentId::RustTypeId(item)
Expand All @@ -1106,12 +1106,12 @@ impl From<TypeId> for ComponentId {

/// A component identifier
///
/// Without the `dynamic-api` feature enabled, this is just a newtype around a Rust [`TypeId`].
#[cfg(not(feature = "dynamic-api"))]
/// Without the `dynamic_api` feature enabled, this is just a newtype around a Rust [`TypeId`].
#[cfg(not(feature = "dynamic_api"))]
#[derive(Eq, PartialEq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
pub struct ComponentId(pub TypeId);

#[cfg(not(feature = "dynamic-api"))]
#[cfg(not(feature = "dynamic_api"))]
impl From<TypeId> for ComponentId {
fn from(item: TypeId) -> Self {
ComponentId(item)
Expand Down Expand Up @@ -1264,7 +1264,7 @@ where
mod test {
#[test]
#[should_panic(expected = "Attempted to insert dynamic component with a different layout")]
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
fn inconsistent_dynamic_component_info_panics() {
use super::*;
use crate::EntityBuilder;
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::resource::Resources;
use bevy_hecs::{ArchetypeComponent, ComponentId, TypeAccess, World};
use std::borrow::Cow;

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use crate::StatefulQuery;
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use bevy_hecs::DynamicQuery;

/// Determines the strategy used to run the `run_thread_local` function in a [System]
Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait System: Send + Sync {
fn initialize(&mut self, _world: &mut World, _resources: &mut Resources) {}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
pub struct DynamicSystem<S> {
pub name: String,
pub state: S,
Expand All @@ -48,7 +48,7 @@ pub struct DynamicSystem<S> {
settings: DynamicSystemSettings<S>,
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
pub struct DynamicSystemSettings<S> {
pub workload: fn(&mut S, &Resources, &mut [StatefulQuery<DynamicQuery, DynamicQuery>]),
pub queries: Vec<DynamicQuery>,
Expand All @@ -58,7 +58,7 @@ pub struct DynamicSystemSettings<S> {
pub resource_access: TypeAccess<ComponentId>,
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl<S> Default for DynamicSystemSettings<S> {
fn default() -> Self {
Self {
Expand All @@ -72,7 +72,7 @@ impl<S> Default for DynamicSystemSettings<S> {
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl<S> DynamicSystem<S> {
pub fn new(name: String, state: S) -> Self {
DynamicSystem {
Expand All @@ -92,7 +92,7 @@ impl<S> DynamicSystem<S> {
}
}

#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
impl<S: Send + Sync> System for DynamicSystem<S> {
fn name(&self) -> std::borrow::Cow<'static, str> {
self.name.clone().into()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_scene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT"
keywords = ["bevy"]

[features]
dynamic-api = ["bevy_ecs/dynamic-api"]
dynamic_api = ["bevy_ecs/dynamic_api"]

[dependencies]
# bevy
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_scene/src/dynamic_scene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{serde::SceneSerializer, Scene};
use anyhow::Result;
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use bevy_ecs::ComponentId;
use bevy_ecs::{EntityMap, Resources, World};
use bevy_property::{DynamicProperties, PropertyTypeRegistry};
Expand Down Expand Up @@ -42,14 +42,14 @@ impl DynamicScene {
})
}
for type_info in archetype.types() {
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
let id = match type_info.id() {
ComponentId::RustTypeId(id) => id,
ComponentId::ExternalId(_) => {
todo!("Handle external type ids in Bevy scene")
}
};
#[cfg(not(feature = "dynamic-api"))]
#[cfg(not(feature = "dynamic_api"))]
let id = type_info.id().0;

if let Some(component_registration) = component_registry.get(&id) {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{DynamicScene, Scene};
use bevy_app::prelude::*;
use bevy_asset::{AssetEvent, Assets, Handle};
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
use bevy_ecs::ComponentId;
use bevy_ecs::{EntityMap, Resources, World};
use bevy_type_registry::TypeRegistry;
Expand Down Expand Up @@ -163,14 +163,14 @@ impl SceneSpawner {
.entry(*scene_entity)
.or_insert_with(|| world.reserve_entity());
for type_info in archetype.types() {
#[cfg(feature = "dynamic-api")]
#[cfg(feature = "dynamic_api")]
let id = match type_info.id() {
ComponentId::RustTypeId(id) => id,
ComponentId::ExternalId(_) => {
todo!("Handle external type ids in Bevy scene")
}
};
#[cfg(not(feature = "dynamic-api"))]
#[cfg(not(feature = "dynamic_api"))]
let id = type_info.id().0;

if let Some(component_registration) = component_registry.get(&id) {
Expand Down

0 comments on commit 40a70b4

Please sign in to comment.