Skip to content

Commit

Permalink
chore: Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbiros committed Oct 22, 2024
1 parent 31dbdd3 commit 6196aa3
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
7 changes: 4 additions & 3 deletions benches/add_components_profiling.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! For profiling.

use core::hint::black_box;

use evenio::prelude::*;

fn main() {
Expand All @@ -25,7 +26,7 @@ fn main() {

let mut world = World::new();

for _ in 0..1<<24 {
for _ in 0..1 << 24 {
spawn_with_components!(
world,
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9,
Expand All @@ -35,5 +36,5 @@ fn main() {
);

black_box(&mut world);
};
}
}
}
6 changes: 1 addition & 5 deletions src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ impl Archetypes {
}
}

pub(crate) fn plan_remove(
&mut self,
entity_id: EntityId,
component_idx: ComponentIdx,
) {
pub(crate) fn plan_remove(&mut self, entity_id: EntityId, component_idx: ComponentIdx) {
match self.planned_moves.entry(entity_id) {
Entry::Occupied(mut entry) => {
let planned_move = entry.get_mut();
Expand Down
10 changes: 6 additions & 4 deletions src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::iter::FusedIterator;
use core::marker::PhantomData;
use core::ops::{BitOr, BitOrAssign, BitXor, BitXorAssign};
use core::{any, fmt};
use core::hash::{Hash, Hasher};

use crate::sparse::SparseIndex;

/// A set data structure backed by a vector of bits.
Expand Down Expand Up @@ -148,7 +149,8 @@ impl<T: SparseIndex> BitSet<T> {

let (block_index, bit_index) = div_rem(idx, BITS);

let before_block = self.blocks
let before_block = self
.blocks
.iter()
.copied()
.take(block_index)
Expand All @@ -162,14 +164,14 @@ impl<T: SparseIndex> BitSet<T> {
let in_block = (block & mask).count_ones();
(before_block + in_block) as usize
}

/// Removes all elements of `other` from `self`.
pub(crate) fn remove_all(&mut self, other: &Self) {
for (a, b) in self.blocks.iter_mut().zip(other.blocks.iter()) {
*a &= !*b;
}
}

/// Returns an iterator over the element in the set in ascending order.
pub(crate) fn iter(&self) -> Iter<T> {
Iter {
Expand Down
5 changes: 3 additions & 2 deletions src/data_store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::alloc::{alloc, realloc, dealloc, handle_alloc_error};
use alloc::alloc::{alloc, dealloc, handle_alloc_error, realloc};
use core::alloc::Layout;
use core::ptr::{copy_nonoverlapping, NonNull};

use crate::data_type::DataType;
#[derive(Debug)]
pub(crate) struct DataStore {
Expand Down Expand Up @@ -248,7 +249,7 @@ impl DataStore {
from.element_type,
to.element_type,
));

copy_nonoverlapping(
from.get_unchecked(from_index),
to.get_unchecked_mut(to_index),
Expand Down
5 changes: 3 additions & 2 deletions src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use core::alloc::Layout;
use core::any::{type_name, TypeId};
use core::ptr::NonNull;

use crate::drop::{drop_fn_of, DropFn};

/// A type whose properties are stored and processed dynamically at runtime.
Expand Down Expand Up @@ -42,8 +43,8 @@ impl DataType {
// cannot be null.
unsafe { NonNull::new_unchecked(self.layout.align() as *mut u8) }
}

pub(crate) fn layout_and_drop_fn_equal(a: DataType, b: DataType) -> bool {
a.layout == b.layout && a.drop_fn == b.drop_fn
}
}
}
5 changes: 4 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,10 @@ fn initialize_component_set<C: ComponentSet>(

// Apply the permutation, sorting the indices.
let component_indices = permutation.apply_collect(unsorted_component_indices);
debug_assert!(component_indices.windows(2).all(|w| w[0] <= w[1]), "Components should be ordered");
debug_assert!(
component_indices.windows(2).all(|w| w[0] <= w[1]),
"Components should be ordered"
);

// Check if there are any duplicates.
if sorted_slice_contains_duplicates(&component_indices) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use rayon;
/// use evenio::prelude::*;
/// ```
pub mod prelude {
pub use crate::component::{Component, ComponentSet, ComponentId};
pub use crate::component::{Component, ComponentId, ComponentSet};
pub use crate::entity::EntityId;
pub use crate::event::{
Despawn, EventMut, GlobalEvent, GlobalEventId, Insert, Receiver, ReceiverMut, Remove,
Expand Down
3 changes: 2 additions & 1 deletion src/permutation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! [`Permutation`] struct for storing reorderings.

use core::mem::MaybeUninit;

use crate::boxed_slice;

/// A permutation used for reordering the elements of a slice.
Expand Down Expand Up @@ -74,4 +75,4 @@ impl Permutation {
// length) exactly once, all elements in `result` are initialized now.
unsafe { boxed_slice::assume_init(result) }
}
}
}
14 changes: 10 additions & 4 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ use crate::world::World;
///
/// # Safety
///
/// Implementors must ensure that [`Query::get_access`] correctly registers the data
/// accessed in [`Query::get`].
/// Implementors must ensure that [`Query::get_access`] correctly registers the
/// data accessed in [`Query::get`].
pub unsafe trait Query {
/// The item returned by this query. This must be the same type as `Self`,
/// but with a modified lifetime.
Expand Down Expand Up @@ -134,7 +134,10 @@ unsafe impl<C: Component> Query for &'_ C {
}

fn get_new_state(world: &World) -> Option<Self::State> {
world.components().get_by_type_id(TypeId::of::<C>()).map(|info| info.id().index())
world
.components()
.get_by_type_id(TypeId::of::<C>())
.map(|info| info.id().index())
}

fn new_arch_state(arch: &Archetype, state: &Self::State) -> Option<Self::ArchState> {
Expand Down Expand Up @@ -169,7 +172,10 @@ unsafe impl<C: Component<Mutability = Mutable>> Query for &'_ mut C {
}

fn get_new_state(world: &World) -> Option<Self::State> {
world.components().get_by_type_id(TypeId::of::<C>()).map(|info| info.id().index())
world
.components()
.get_by_type_id(TypeId::of::<C>())
.map(|info| info.id().index())
}

fn new_arch_state(arch: &Archetype, state: &Self::State) -> Option<Self::ArchState> {
Expand Down
2 changes: 1 addition & 1 deletion src/sparse_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<K: SparseIndex, V> SparseMap<K, V> {
pub(crate) fn values(&self) -> &[V] {
&self.dense
}

pub(crate) fn into_keys_values(self) -> (Vec<K>, Vec<V>) {
(self.indices, self.dense)
}
Expand Down

0 comments on commit 6196aa3

Please sign in to comment.