use ints instead of bytes for uuids

This commit is contained in:
Carter Anderson 2020-05-04 11:20:12 -07:00
parent ba795fdfb5
commit af2a111801
5 changed files with 44 additions and 28 deletions

View File

@ -8,9 +8,7 @@ use uuid::Uuid;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct HandleId(pub Uuid);
pub const DEFAULT_HANDLE_ID: HandleId = HandleId(Uuid::from_bytes([
238, 232, 56, 216, 245, 246, 77, 29, 165, 188, 211, 202, 249, 248, 15, 4,
]));
pub const DEFAULT_HANDLE_ID: HandleId = HandleId(Uuid::from_u128(240940089166493627844978703213080810552));
impl HandleId {
pub fn new() -> HandleId {
@ -31,6 +29,13 @@ impl<T> Handle<T> {
}
}
pub const fn from_u128(value: u128) -> Self {
Handle {
id: HandleId(Uuid::from_u128(value)),
marker: PhantomData,
}
}
pub const fn from_bytes(bytes: [u8; 16]) -> Self {
Handle {
id: HandleId(Uuid::from_bytes(bytes)),

View File

@ -7,6 +7,12 @@ use uuid::Uuid;
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct DiagnosticId(pub Uuid);
impl DiagnosticId {
pub const fn from_u128(value: u128) -> Self {
DiagnosticId(Uuid::from_u128(value))
}
}
#[derive(Debug)]
pub struct DiagnosticMeasurement {
pub time: SystemTime,

View File

@ -2,15 +2,10 @@ use super::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_core::time::Time;
use legion::prelude::*;
use std::time::Duration;
use uuid::Uuid;
pub const FPS: DiagnosticId = DiagnosticId(Uuid::from_bytes([
157, 191, 0, 72, 223, 223, 70, 128, 137, 117, 54, 177, 132, 13, 170, 124,
]));
pub const FRAME_TIME: DiagnosticId = DiagnosticId(Uuid::from_bytes([
216, 184, 55, 12, 28, 116, 69, 201, 187, 137, 176, 77, 83, 89, 251, 241,
]));
pub const FPS: DiagnosticId = DiagnosticId::from_u128(288146834822086093791974408528866909483);
pub const FRAME_TIME: DiagnosticId =
DiagnosticId::from_u128(54021991829115352065418785002088010276);
pub fn setup_frame_time_diagnostic_system(mut diagnostics: ResourceMut<Diagnostics>) {
diagnostics.add(Diagnostic::new(FRAME_TIME, "frame_time", 10));

View File

@ -4,8 +4,8 @@ pub mod entity;
mod margins;
mod node;
mod rect;
mod sprite;
mod render;
mod sprite;
mod ui_update_system;
pub use anchors::*;
@ -14,8 +14,8 @@ pub use margins::*;
pub use node::*;
pub use rect::*;
pub use render::*;
pub use ui_update_system::*;
pub use sprite::*;
pub use ui_update_system::*;
use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_asset::{AssetStorage, Handle};
@ -31,9 +31,7 @@ use sprite::sprite_system;
#[derive(Default)]
pub struct UiPlugin;
pub const QUAD_HANDLE: Handle<Mesh> = Handle::from_bytes([
179, 41, 129, 128, 95, 217, 79, 194, 167, 95, 107, 115, 97, 151, 20, 62,
]);
pub const QUAD_HANDLE: Handle<Mesh> = Handle::from_u128(142404619811301375266013514540294236421);
impl AppPlugin for UiPlugin {
fn build(&self, app: &mut AppBuilder) {

View File

@ -1,18 +1,20 @@
use crate::{ColorMaterial, Rect};
use bevy_asset::{AssetStorage, Handle};
use bevy_render::{
base_render_graph,
draw_target::AssignedMeshesDrawTarget,
pipeline::{state_descriptors::*, PipelineDescriptor},
render_graph::{nodes::{UniformNode, PassNode, AssetUniformNode}, RenderGraph},
render_graph::{
nodes::{AssetUniformNode, PassNode, UniformNode},
RenderGraph,
},
shader::{Shader, ShaderStage, ShaderStages},
texture::TextureFormat, base_render_graph,
texture::TextureFormat,
};
use legion::prelude::Resources;
use crate::{ColorMaterial, Rect};
pub const UI_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
Handle::from_bytes([
163, 238, 40, 24, 156, 49, 73, 203, 156, 189, 249, 55, 133, 242, 116, 51,
]);
Handle::from_u128(323432002226399387835192542539754486265);
pub fn build_ui_pipeline(shaders: &mut AssetStorage<Shader>) -> PipelineDescriptor {
PipelineDescriptor {
@ -65,15 +67,25 @@ pub trait UiRenderGraphBuilder {
impl UiRenderGraphBuilder for RenderGraph {
fn add_ui_graph(&mut self, resources: &Resources) -> &mut Self {
self.add_system_node_named("color_material", AssetUniformNode::<ColorMaterial>::new(false), resources);
self.add_node_edge("color_material", base_render_graph::node::MAIN_PASS).unwrap();
self.add_system_node_named(
"color_material",
AssetUniformNode::<ColorMaterial>::new(false),
resources,
);
self.add_node_edge("color_material", base_render_graph::node::MAIN_PASS)
.unwrap();
self.add_system_node_named("rect", UniformNode::<Rect>::new(false), resources);
self.add_node_edge("rect", base_render_graph::node::MAIN_PASS).unwrap();
let mut pipelines = resources.get_mut::<AssetStorage<PipelineDescriptor>>().unwrap();
self.add_node_edge("rect", base_render_graph::node::MAIN_PASS)
.unwrap();
let mut pipelines = resources
.get_mut::<AssetStorage<PipelineDescriptor>>()
.unwrap();
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
pipelines.add_with_handle(UI_PIPELINE_HANDLE, build_ui_pipeline(&mut shaders));
let main_pass: &mut PassNode = self.get_node_mut(base_render_graph::node::MAIN_PASS).unwrap();
let main_pass: &mut PassNode = self
.get_node_mut(base_render_graph::node::MAIN_PASS)
.unwrap();
main_pass.add_pipeline(UI_PIPELINE_HANDLE, vec![Box::new(AssignedMeshesDrawTarget)]);
self
}
}
}