From 9ef34035db7d7c66a1345815777511cb6e0a9c17 Mon Sep 17 00:00:00 2001 From: james7132 Date: Tue, 13 Dec 2022 05:40:35 -0800 Subject: [PATCH 1/2] Shrink DrawFunctionId --- crates/bevy_render/src/lib.rs | 3 +++ crates/bevy_render/src/render_phase/draw.rs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index f595023588e76..8720d443fc214 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -1,3 +1,6 @@ +#[cfg(target_pointer_width = "16")] +compile_error!("bevy_render cannot safely compile for a 16-bit platform."); + extern crate core; pub mod camera; diff --git a/crates/bevy_render/src/render_phase/draw.rs b/crates/bevy_render/src/render_phase/draw.rs index 67ff987b7972d..14930b1931ffa 100644 --- a/crates/bevy_render/src/render_phase/draw.rs +++ b/crates/bevy_render/src/render_phase/draw.rs @@ -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`]. @@ -82,15 +82,15 @@ impl DrawFunctionsInternal

{ /// Adds the [`Draw`] function and associates it to the type `T` pub fn add_with>(&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); self.indices.insert(TypeId::of::(), id); id } /// Retrieves the [`Draw`] function corresponding to the `id` mutably. pub fn get_mut(&mut self, id: DrawFunctionId) -> Option<&mut dyn Draw

> { - 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`. From 01fc417af77a2bbcc217a875151eea99b045c2fe Mon Sep 17 00:00:00 2001 From: James Liu Date: Tue, 13 Dec 2022 13:20:43 -0800 Subject: [PATCH 2/2] Remove error about safely compiling. --- crates/bevy_render/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 8720d443fc214..5f3e414068758 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -1,5 +1,5 @@ #[cfg(target_pointer_width = "16")] -compile_error!("bevy_render cannot safely compile for a 16-bit platform."); +compile_error!("bevy_render cannot compile for a 16-bit platform."); extern crate core;