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

Replace FloatOrd with ordered_float crate #6917

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use bevy_render::{
render_resource::CachedRenderPipelineId,
Extract, RenderApp, RenderStage,
};
use bevy_utils::FloatOrd;
use bevy_utils::OrderedFloat;
use std::ops::Range;

use crate::{tonemapping::TonemappingNode, upscaling::UpscalingNode};
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Plugin for Core2dPlugin {
}

pub struct Transparent2d {
pub sort_key: FloatOrd,
pub sort_key: OrderedFloat<f32>,
pub entity: Entity,
pub pipeline: CachedRenderPipelineId,
pub draw_function: DrawFunctionId,
Expand All @@ -113,7 +113,7 @@ pub struct Transparent2d {
}

impl PhaseItem for Transparent2d {
type SortKey = FloatOrd;
type SortKey = OrderedFloat<f32>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use bevy_render::{
view::ViewDepthTexture,
Extract, RenderApp, RenderStage,
};
use bevy_utils::{FloatOrd, HashMap};
use bevy_utils::{HashMap, OrderedFloat};

use crate::{tonemapping::TonemappingNode, upscaling::UpscalingNode};

Expand Down Expand Up @@ -122,11 +122,11 @@ pub struct Opaque3d {

impl PhaseItem for Opaque3d {
// NOTE: Values increase towards the camera. Front-to-back ordering for opaque means we need a descending sort.
type SortKey = Reverse<FloatOrd>;
type SortKey = Reverse<OrderedFloat<f32>>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
Reverse(FloatOrd(self.distance))
Reverse(OrderedFloat(self.distance))
}

#[inline]
Expand Down Expand Up @@ -164,11 +164,11 @@ pub struct AlphaMask3d {

impl PhaseItem for AlphaMask3d {
// NOTE: Values increase towards the camera. Front-to-back ordering for alpha mask means we need a descending sort.
type SortKey = Reverse<FloatOrd>;
type SortKey = Reverse<OrderedFloat<f32>>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
Reverse(FloatOrd(self.distance))
Reverse(OrderedFloat(self.distance))
}

#[inline]
Expand Down Expand Up @@ -206,11 +206,11 @@ pub struct Transparent3d {

impl PhaseItem for Transparent3d {
// NOTE: Values increase towards the camera. Back-to-front ordering for transparent means we need an ascending sort.
type SortKey = FloatOrd;
type SortKey = OrderedFloat<f32>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
FloatOrd(self.distance)
OrderedFloat(self.distance)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use bevy_render::{
Extract,
};
use bevy_transform::{components::GlobalTransform, prelude::Transform};
use bevy_utils::FloatOrd;
use bevy_utils::OrderedFloat;
use bevy_utils::{
tracing::{error, warn},
HashMap,
Expand Down Expand Up @@ -1697,11 +1697,11 @@ pub struct Shadow {
}

impl PhaseItem for Shadow {
type SortKey = FloatOrd;
type SortKey = OrderedFloat<f32>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
FloatOrd(self.distance)
OrderedFloat(self.distance)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/mesh2d/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use bevy_render::{
Extract, RenderApp, RenderStage,
};
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::{FloatOrd, HashMap, HashSet};
use bevy_utils::{HashMap, HashSet, OrderedFloat};
use std::hash::Hash;
use std::marker::PhantomData;

Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn queue_material2d_meshes<M: Material2d>(
// lowest sort key and getting closer should increase. As we have
// -z in front of the camera, the largest distance is -far with values increasing toward the
// camera. As such we can just use mesh_z as the distance
sort_key: FloatOrd(mesh_z),
sort_key: OrderedFloat(mesh_z),
// This material is not batched
batch_range: None,
});
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use bevy_render::{
Extract,
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::FloatOrd;
use bevy_utils::HashMap;
use bevy_utils::OrderedFloat;
use bytemuck::{Pod, Zeroable};
use fixedbitset::FixedBitSet;

Expand Down Expand Up @@ -632,7 +632,7 @@ pub fn queue_sprites(
});

// These items will be sorted by depth with other phase items
let sort_key = FloatOrd(extracted_sprite.transform.translation().z);
let sort_key = OrderedFloat(extracted_sprite.transform.translation().z);

// Store the vertex data and add the item to the render phase
if current_batch.colored {
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_text/src/font_atlas_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use bevy_math::Vec2;
use bevy_reflect::TypeUuid;
use bevy_render::texture::Image;
use bevy_sprite::TextureAtlas;
use bevy_utils::FloatOrd;
use bevy_utils::HashMap;
use bevy_utils::OrderedFloat;

type FontSizeKey = FloatOrd;
type FontSizeKey = OrderedFloat<f32>;

#[derive(TypeUuid)]
#[uuid = "73ba778b-b6b5-4f45-982d-d21b6b86ace2"]
Expand Down Expand Up @@ -41,7 +41,7 @@ impl FontAtlasSet {

pub fn has_glyph(&self, glyph_id: GlyphId, glyph_position: Point, font_size: f32) -> bool {
self.font_atlases
.get(&FloatOrd(font_size))
.get(&OrderedFloat(font_size))
.map_or(false, |font_atlas| {
font_atlas
.iter()
Expand All @@ -61,7 +61,7 @@ impl FontAtlasSet {
let font_size = glyph.scale.y;
let font_atlases = self
.font_atlases
.entry(FloatOrd(font_size))
.entry(OrderedFloat(font_size))
.or_insert_with(|| {
vec![FontAtlas::new(
textures,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl FontAtlasSet {
position: Point,
) -> Option<GlyphAtlasInfo> {
self.font_atlases
.get(&FloatOrd(font_size))
.get(&OrderedFloat(font_size))
.and_then(|font_atlases| {
font_atlases
.iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use bevy_render::{
use bevy_sprite::{SpriteAssetEvents, TextureAtlas};
use bevy_text::{Text, TextLayoutInfo};
use bevy_transform::components::GlobalTransform;
use bevy_utils::FloatOrd;
use bevy_utils::HashMap;
use bevy_utils::OrderedFloat;
use bevy_window::{WindowId, Windows};
use bytemuck::{Pod, Zeroable};
use std::ops::Range;
Expand Down Expand Up @@ -620,7 +620,7 @@ pub fn queue_uinodes(
draw_function: draw_ui_function,
pipeline,
entity,
sort_key: FloatOrd(batch.z),
sort_key: OrderedFloat(batch.z),
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy_render::{
renderer::*,
view::*,
};
use bevy_utils::FloatOrd;
use bevy_utils::OrderedFloat;

pub struct UiPassNode {
ui_view_query: QueryState<
Expand Down Expand Up @@ -102,14 +102,14 @@ impl Node for UiPassNode {
}

pub struct TransparentUi {
pub sort_key: FloatOrd,
pub sort_key: OrderedFloat<f32>,
pub entity: Entity,
pub pipeline: CachedRenderPipelineId,
pub draw_function: DrawFunctionId,
}

impl PhaseItem for TransparentUi {
type SortKey = FloatOrd;
type SortKey = OrderedFloat<f32>;

#[inline]
fn sort_key(&self) -> Self::SortKey {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
instant = { version = "0.1", features = ["wasm-bindgen"] }
uuid = { version = "1.1", features = ["v4", "serde"] }
hashbrown = { version = "0.12", features = ["serde"] }
ordered-float = "3.4.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = {version = "0.2.0", features = ["js"]}
66 changes: 0 additions & 66 deletions crates/bevy_utils/src/float_ord.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ pub use short_names::get_short_name;
pub mod synccell;

mod default;
mod float_ord;

pub use ahash::AHasher;
pub use default::default;
pub use float_ord::*;
pub use hashbrown;
pub use instant::{Duration, Instant};
pub use ordered_float::*;
pub use tracing;
pub use uuid::Uuid;

Expand Down