Skip to content

Commit

Permalink
Remove derivative dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Jan 19, 2020
1 parent 15b1022 commit 516c9ab
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -23,7 +23,6 @@ travis-ci = { repository = "slide-rs/specs" }

[dependencies]
crossbeam-queue = "0.2"
derivative = "1"
hashbrown = "0.6.0"
hibitset = { version = "0.6.1", default-features = false }
log = "0.4"
Expand Down
13 changes: 9 additions & 4 deletions src/changeset.rs
Expand Up @@ -2,8 +2,6 @@

use std::{iter::FromIterator, ops::AddAssign};

use derivative::Derivative;

use crate::{prelude::*, storage::UnprotectedStorage, world::Index};

/// Change set that can be collected from an iterator, and joined on for easy
Expand Down Expand Up @@ -37,13 +35,20 @@ use crate::{prelude::*, storage::UnprotectedStorage, world::Index};
/// }
/// # }
/// ```
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct ChangeSet<T> {
mask: BitSet,
inner: DenseVecStorage<T>,
}

impl<T> Default for ChangeSet<T> {
fn default() -> Self {
Self {
mask: Default::default(),
inner: Default::default(),
}
}
}

impl<T> ChangeSet<T> {
/// Create a new change set
pub fn new() -> Self {
Expand Down
7 changes: 2 additions & 5 deletions src/saveload/marker.rs
Expand Up @@ -2,7 +2,6 @@

use std::{collections::HashMap, fmt::Debug, hash::Hash, marker::PhantomData};

use derivative::Derivative;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -362,8 +361,7 @@ pub trait MarkerAllocator<M: Marker>: Resource {

/// Basic marker implementation usable for saving and loading, uses `u64` as
/// identifier
#[derive(Derivative, Serialize, Deserialize)]
#[derivative(Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[derive(Derivative, Serialize, Deserialize, Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[repr(transparent)]
pub struct SimpleMarker<T: ?Sized>(u64, #[serde(skip)] PhantomData<T>);

Expand All @@ -387,8 +385,7 @@ where
}

/// Basic marker allocator, uses `u64` as identifier
#[derive(Derivative)]
#[derivative(Clone, Debug)]
#[derive(Clone, Debug)]
pub struct SimpleMarkerAllocator<T: ?Sized> {
index: u64,
mapping: HashMap<u64, Entity>,
Expand Down
15 changes: 12 additions & 3 deletions src/storage/mod.rs
Expand Up @@ -21,7 +21,6 @@ use std::{
ops::{Deref, DerefMut, Not},
};

use derivative::Derivative;
use hibitset::{BitSet, BitSetLike, BitSetNot};
use shred::{CastFrom, Fetch};

Expand Down Expand Up @@ -130,13 +129,23 @@ pub type InsertResult<T> = Result<Option<T>, Error>;

/// The `UnprotectedStorage` together with the `BitSet` that knows
/// about which elements are stored, and which are not.
#[derive(Derivative)]
#[derivative(Default(bound = "T::Storage: Default"))]
pub struct MaskedStorage<T: Component> {
mask: BitSet,
inner: T::Storage,
}

impl<T: Component> Default for MaskedStorage<T>
where
T::Storage: Default,
{
fn default() -> Self {
Self {
mask: Default::default(),
inner: Default::default(),
}
}
}

impl<T: Component> MaskedStorage<T> {
/// Creates a new `MaskedStorage`. This is called when you register
/// a new component type within the world.
Expand Down
40 changes: 29 additions & 11 deletions src/storage/storages.rs
Expand Up @@ -3,7 +3,6 @@
use std::collections::BTreeMap;
use std::mem::MaybeUninit;

use derivative::Derivative;
use hashbrown::HashMap;
use hibitset::BitSetLike;

Expand All @@ -25,10 +24,14 @@ pub trait SliceAccess<T> {
}

/// BTreeMap-based storage.
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct BTreeStorage<T>(BTreeMap<Index, T>);

impl<T> Default for BTreeStorage<T> {
fn default() -> Self {
Self(Default::default())
}
}

impl<T> UnprotectedStorage<T> for BTreeStorage<T> {
unsafe fn clean<B>(&mut self, _has: B)
where
Expand Down Expand Up @@ -59,10 +62,14 @@ unsafe impl<T> DistinctStorage for BTreeStorage<T> {}
/// `HashMap`-based storage. Best suited for rare components.
///
/// This uses the [hashbrown::HashMap] internally.
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct HashMapStorage<T>(HashMap<Index, T>);

impl<T> Default for HashMapStorage<T> {
fn default() -> Self {
Self(Default::default())
}
}

impl<T> UnprotectedStorage<T> for HashMapStorage<T> {
unsafe fn clean<B>(&mut self, _has: B)
where
Expand Down Expand Up @@ -102,14 +109,22 @@ unsafe impl<T> DistinctStorage for HashMapStorage<T> {}
/// cannot be compared with indices from any other storage, and
/// a particular entity's position within this slice may change
/// over time.
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct DenseVecStorage<T> {
data: Vec<T>,
entity_id: Vec<Index>,
data_id: Vec<MaybeUninit<Index>>,
}

impl<T> Default for DenseVecStorage<T> {
fn default() -> Self {
Self {
data: Default::default(),
entity_id: Default::default(),
data_id: Default::default(),
}
}
}

impl<T> SliceAccess<T> for DenseVecStorage<T> {
type Element = T;

Expand Down Expand Up @@ -225,10 +240,14 @@ unsafe impl<T> DistinctStorage for NullStorage<T> {}
/// entity IDs. These can be compared to other `VecStorage`s, to
/// other `DefaultVecStorage`s, and to `Entity::id()`s for live
/// entities.
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct VecStorage<T>(Vec<MaybeUninit<T>>);

impl<T> Default for VecStorage<T> {
fn default() -> Self {
Self(Default::default())
}
}

impl<T> SliceAccess<T> for VecStorage<T> {
type Element = MaybeUninit<T>;

Expand Down Expand Up @@ -294,8 +313,7 @@ unsafe impl<T> DistinctStorage for VecStorage<T> {}
/// `as_slice()` and `as_mut_slice()` indices correspond to entity IDs.
/// These can be compared to other `DefaultVecStorage`s, to other
/// `VecStorage`s, and to `Entity::id()`s for live entities.
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
#[derive(Default)]
pub struct DefaultVecStorage<T>(Vec<T>);

impl<T> UnprotectedStorage<T> for DefaultVecStorage<T> where T: Default {
Expand Down
12 changes: 8 additions & 4 deletions src/world/lazy.rs
@@ -1,5 +1,4 @@
use crossbeam_queue::SegQueue;
use derivative::Derivative;

use crate::{prelude::*, world::EntitiesRes};

Expand Down Expand Up @@ -80,13 +79,18 @@ where
/// Please note that the provided methods take `&self`
/// so there's no need to get `LazyUpdate` mutably.
/// This resource is added to the world by default.
#[derive(Derivative)]
#[derivative(Default)]
pub struct LazyUpdate {
#[derivative(Default(value = "Some(Default::default())"))]
queue: Option<Queue<Box<dyn LazyUpdateInternal>>>,
}

impl Default for LazyUpdate {
fn default() -> Self {
Self {
queue: Some(Default::default())
}
}
}

impl LazyUpdate {
/// Creates a new `LazyBuilder` which inserts components
/// using `LazyUpdate`. This means that the components won't
Expand Down

0 comments on commit 516c9ab

Please sign in to comment.