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

[Merged by Bors] - Shrink DrawFunctionId #6944

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(target_pointer_width = "16")]
compile_error!("bevy_render cannot safely compile for a 16-bit platform.");
james7132 marked this conversation as resolved.
Show resolved Hide resolved

extern crate core;

pub mod camera;
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/render_phase/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub trait PhaseItem: Sized + Send + Sync + 'static {
// TODO: make this generic?
/// An identifier for a [`Draw`] function stored in [`DrawFunctions`].
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct DrawFunctionId(usize);
pub struct DrawFunctionId(u32);

/// Stores all draw functions for the [`PhaseItem`] type.
/// For retrieval they are associated with their [`TypeId`].
Expand All @@ -82,15 +82,15 @@ impl<P: PhaseItem> DrawFunctionsInternal<P> {

/// Adds the [`Draw`] function and associates it to the type `T`
pub fn add_with<T: 'static, D: Draw<P>>(&mut self, draw_function: D) -> DrawFunctionId {
let id = DrawFunctionId(self.draw_functions.len().try_into().unwrap());
self.draw_functions.push(Box::new(draw_function));
let id = DrawFunctionId(self.draw_functions.len() - 1);
james7132 marked this conversation as resolved.
Show resolved Hide resolved
self.indices.insert(TypeId::of::<T>(), id);
id
}

/// Retrieves the [`Draw`] function corresponding to the `id` mutably.
pub fn get_mut(&mut self, id: DrawFunctionId) -> Option<&mut dyn Draw<P>> {
self.draw_functions.get_mut(id.0).map(|f| &mut **f)
self.draw_functions.get_mut(id.0 as usize).map(|f| &mut **f)
}

/// Retrieves the id of the [`Draw`] function corresponding to their associated type `T`.
Expand Down