Merge pull request #885 from zuiyu1998/remove_lazy_static

Remove lazy static
This commit is contained in:
zuiyu
2026-01-29 19:43:06 +03:00
committed by GitHub
parent 2ec015aea9
commit c600a95c28
24 changed files with 400 additions and 292 deletions
-1
View File
@@ -15,7 +15,6 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md", "/resources/**/
[dependencies]
fyrox = { version = "1.0.0-rc.1", path = "../fyrox", default-features = false }
fyrox-build-tools = { version = "1.0.0-rc.1", path = "../fyrox-build-tools" }
lazy_static = "1.4.0"
ron = "0.11"
serde = { version = "1", features = ["derive"] }
toml = { version = "0.9", default-features = false, features = ["parse"] }
+10 -16
View File
@@ -29,9 +29,6 @@
#![allow(clippy::mutable_key_type)]
#![allow(mismatched_lifetime_syntaxes)]
#[macro_use]
extern crate lazy_static;
pub mod asset;
pub mod audio;
pub mod camera;
@@ -227,9 +224,8 @@ static EDITOR_VERSION: LazyLock<String> = LazyLock::new(|| {
"<unknown>".to_string()
});
lazy_static! {
static ref EDITOR_TEXTURE_CACHE: Mutex<FxHashMap<usize, TextureResource>> = Default::default();
}
static EDITOR_TEXTURE_CACHE: LazyLock<Mutex<FxHashMap<usize, TextureResource>>> =
LazyLock::new(Mutex::default);
pub fn load_texture_internal(data: &[u8]) -> Option<TextureResource> {
let mut cache = EDITOR_TEXTURE_CACHE.safe_lock();
@@ -277,16 +273,14 @@ macro_rules! load_image {
};
}
lazy_static! {
static ref GIZMO_SHADER: ShaderResource = {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../resources/shaders/gizmo.shader"),
Default::default(),
)
.unwrap()
};
}
static GIZMO_SHADER: LazyLock<ShaderResource> = LazyLock::new(|| {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../resources/shaders/gizmo.shader"),
Default::default(),
)
.unwrap()
});
pub fn make_color_material(color: Color) -> MaterialResource {
let mut material = Material::from_shader(GIZMO_SHADER.clone());
+10 -10
View File
@@ -35,6 +35,8 @@ mod segment2d;
mod triangle;
mod triangle2d;
use std::sync::LazyLock;
use super::inspector::InspectorPlugin;
use crate::{
camera::PickingOptions,
@@ -270,16 +272,14 @@ fn make_shape_gizmo(
}
}
lazy_static! {
static ref GIZMO_SHADER: ShaderResource = {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../../../resources/shaders/sprite_gizmo.shader"),
Default::default(),
)
.unwrap()
};
}
static GIZMO_SHADER: LazyLock<ShaderResource> = LazyLock::new(|| {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../../../resources/shaders/sprite_gizmo.shader"),
Default::default(),
)
.unwrap()
});
fn make_handle(scene: &mut Scene, root: Handle<Pivot>, visible: bool) -> Handle<Sprite> {
let mut material = Material::from_shader(GIZMO_SHADER.clone());
+42 -22
View File
@@ -126,34 +126,54 @@ use fyrox::asset::manager::ResourceManager;
use fyrox::engine::ApplicationLoopController;
use fyrox::gui::button::Button;
use fyrox::gui::message::MessageData;
use std::sync::LazyLock;
use std::{
fmt::Debug,
ops::{Deref, DerefMut},
sync::Arc,
};
lazy_static! {
static ref VISIBLE_IMAGE: Option<TextureResource> =
load_image!("../../../resources/visible.png");
static ref BRUSH_IMAGE: Option<TextureResource> = load_image!("../../../resources/brush.png");
static ref ERASER_IMAGE: Option<TextureResource> = load_image!("../../../resources/eraser.png");
static ref FILL_IMAGE: Option<TextureResource> = load_image!("../../../resources/fill.png");
static ref PICK_IMAGE: Option<TextureResource> = load_image!("../../../resources/pipette.png");
static ref RECT_FILL_IMAGE: Option<TextureResource> =
load_image!("../../../resources/rect_fill.png");
static ref NINE_SLICE_IMAGE: Option<TextureResource> =
load_image!("../../../resources/nine_slice.png");
static ref LINE_IMAGE: Option<TextureResource> = load_image!("../../../resources/line.png");
static ref TURN_LEFT_IMAGE: Option<TextureResource> =
load_image!("../../../resources/turn_left.png");
static ref TURN_RIGHT_IMAGE: Option<TextureResource> =
load_image!("../../../resources/turn_right.png");
static ref FLIP_X_IMAGE: Option<TextureResource> = load_image!("../../../resources/flip_x.png");
static ref FLIP_Y_IMAGE: Option<TextureResource> = load_image!("../../../resources/flip_y.png");
static ref RANDOM_IMAGE: Option<TextureResource> = load_image!("../../../resources/die.png");
static ref PALETTE_IMAGE: Option<TextureResource> =
load_image!("../../../resources/palette.png");
}
static VISIBLE_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/visible.png"));
static BRUSH_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/brush.png"));
static ERASER_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/eraser.png"));
static FILL_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/fill.png"));
static PICK_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/pipette.png"));
static RECT_FILL_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/rect_fill.png"));
static NINE_SLICE_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/nine_slice.png"));
static LINE_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/line.png"));
static TURN_LEFT_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/turn_left.png"));
static TURN_RIGHT_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/turn_right.png"));
static FLIP_X_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/flip_x.png"));
static FLIP_Y_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/flip_y.png"));
static RANDOM_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/die.png"));
static PALETTE_IMAGE: LazyLock<Option<TextureResource>> =
LazyLock::new(|| load_image!("../../../resources/palette.png"));
/// A structure to keep track of which cells of a tile map brush are involved in macros.
/// Each macro is expected to keep track of which cells it is using, but this information
+9 -11
View File
@@ -109,7 +109,7 @@ use std::{
rc::Rc,
sync::{
mpsc::{self, Receiver},
Arc,
Arc, LazyLock,
},
};
@@ -151,16 +151,14 @@ pub struct GameScene {
pub settings_receiver: Receiver<SettingsMessage>,
}
lazy_static! {
static ref GRID_SHADER: ShaderResource = {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../../resources/shaders/grid.shader"),
Default::default(),
)
.unwrap()
};
}
static GRID_SHADER: LazyLock<ShaderResource> = LazyLock::new(|| {
ShaderResource::from_str(
Uuid::new_v4(),
include_str!("../../resources/shaders/grid.shader"),
Default::default(),
)
.unwrap()
});
fn make_grid_material() -> MaterialResource {
let material = Material::from_shader(GRID_SHADER.clone());
-1
View File
@@ -21,7 +21,6 @@ base64 = "0.22.1"
byteorder = "1.4.3"
rand = "0.8"
memoffset = "0.9.0"
lazy_static = "1.4.0"
nalgebra = { version = "0.34", features = ["bytemuck"] }
arrayvec = "0.7.2"
futures = { version = "0.3.17", features = ["thread-pool"] }
-2
View File
@@ -29,8 +29,6 @@
#[macro_use]
extern crate memoffset;
#[macro_use]
extern crate lazy_static;
pub use arrayvec;
pub use byteorder;
+3 -5
View File
@@ -36,7 +36,7 @@ use std::{
fmt::{Debug, Display, Formatter},
hash::{Hash, Hasher},
ops::Deref,
sync::Arc,
sync::{Arc, LazyLock},
};
#[derive(Clone, Debug)]
@@ -274,10 +274,8 @@ impl ImmutableStringStorage {
}
}
lazy_static! {
static ref SSTORAGE: Arc<Mutex<ImmutableStringStorage>> =
Arc::new(Mutex::new(ImmutableStringStorage::default()));
}
static SSTORAGE: LazyLock<Arc<Mutex<ImmutableStringStorage>>> =
LazyLock::new(|| Arc::new(Mutex::new(ImmutableStringStorage::default())));
#[cfg(test)]
mod test {
-1
View File
@@ -32,7 +32,6 @@ rapier3d = { version = "0.30", features = ["debug-render"] }
image = { version = "0.25.1", default-features = false, features = ["gif", "jpeg", "png", "tga", "tiff", "bmp"] }
inflate = "0.4.5"
serde = { version = "1", features = ["derive"] }
lazy_static = "1.4.0"
rayon = "1.5.1"
bitflags = "2.9.1"
walkdir = "2.3.2"
-1
View File
@@ -45,7 +45,6 @@ pub mod utils;
pub use crate::core::rand;
pub use fxhash;
pub use lazy_static;
pub use walkdir;
pub use winit::*;
+12 -8
View File
@@ -98,11 +98,11 @@ use crate::{
use cache::DynamicSurfaceCache;
use fxhash::FxHashMap;
use fyrox_graph::SceneGraph;
use lazy_static::lazy_static;
use observer::{Observer, ObserversCollection};
use resources::RendererResources;
pub use settings::*;
pub use stats::*;
use std::sync::LazyLock;
use std::{
any::{Any, TypeId},
cell::RefCell,
@@ -112,13 +112,17 @@ use std::{
};
use winit::window::Window;
lazy_static! {
static ref GBUFFER_PASS_NAME: ImmutableString = ImmutableString::new("GBuffer");
static ref DIRECTIONAL_SHADOW_PASS_NAME: ImmutableString =
ImmutableString::new("DirectionalShadow");
static ref SPOT_SHADOW_PASS_NAME: ImmutableString = ImmutableString::new("SpotShadow");
static ref POINT_SHADOW_PASS_NAME: ImmutableString = ImmutableString::new("PointShadow");
}
static GBUFFER_PASS_NAME: LazyLock<ImmutableString> =
LazyLock::new(|| ImmutableString::new("GBuffer"));
static DIRECTIONAL_SHADOW_PASS_NAME: LazyLock<ImmutableString> =
LazyLock::new(|| ImmutableString::new("DirectionalShadow"));
static SPOT_SHADOW_PASS_NAME: LazyLock<ImmutableString> =
LazyLock::new(|| ImmutableString::new("SpotShadow"));
static POINT_SHADOW_PASS_NAME: LazyLock<ImmutableString> =
LazyLock::new(|| ImmutableString::new("PointShadow"));
/// Checks whether the provided render pass name is one of the names of built-in shadow render passes.
pub fn is_shadow_pass(render_pass_name: &str) -> bool {
+6 -6
View File
@@ -23,6 +23,7 @@
use std::{
fmt::Display,
path::{Path, PathBuf},
sync::LazyLock,
};
use crate::{
@@ -38,7 +39,6 @@ use crate::{
},
};
use gltf::{buffer::View, image, Document};
use lazy_static::lazy_static;
use super::uri;
@@ -49,8 +49,8 @@ use crate::resource::texture::TextureMinificationFilter as FyroxMinFilter;
use gltf::texture::MagFilter as GltfMagFilter;
use gltf::texture::MinFilter as GltfMinFilter;
lazy_static! {
pub static ref GLTF_SHADER: BuiltInResource<Shader> = BuiltInResource::new(
pub static GLTF_SHADER: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
"__GLTF_StandardShader",
embedded_data_source!("gltf_standard.shader"),
|data| {
@@ -59,9 +59,9 @@ lazy_static! {
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
}
);
}
},
)
});
fn convert_mini(filter: GltfMinFilter) -> FyroxMinFilter {
match filter {
+38 -29
View File
@@ -61,12 +61,11 @@ use bytemuck::{Pod, Zeroable};
use fxhash::{FxHashMap, FxHasher};
use fyrox_resource::manager::BuiltInResource;
use half::f16;
use lazy_static::lazy_static;
use std::{
error::Error,
hash::Hasher,
path::{Path, PathBuf},
sync::Arc,
sync::{Arc, LazyLock},
};
/// A target shape for blending.
@@ -1468,64 +1467,74 @@ impl ResourceLoader for SurfaceDataLoader {
}
}
lazy_static! {
/// Cube surface resource.
pub static ref CUBE: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Cube surface resource.
pub static CUBE: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__CubeSurface",
SurfaceResource::new_ok(
uuid!("d3a4604a-e1c6-430b-b524-8d3213723952"),
ResourceKind::Embedded,
SurfaceData::make_cube(Matrix4::identity()),
)
);
),
)
});
/// Quad surface resource.
pub static ref QUAD: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Quad surface resource.
pub static QUAD: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__QuadSurface",
SurfaceResource::new_ok(
uuid!("a124317f-640b-4c1b-9fdc-af62f745eeba"),
ResourceKind::Embedded,
SurfaceData::make_quad(&Matrix4::identity()),
)
);
),
)
});
/// Cylinder surface resource.
pub static ref CYLINDER: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Cylinder surface resource.
pub static CYLINDER: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__CylinderSurface",
SurfaceResource::new_ok(
uuid!("16300ec8-4446-41a7-8ad6-9b45428d0b1b"),
ResourceKind::Embedded,
SurfaceData::make_cylinder(32, 1.0, 1.0, true, &Matrix4::identity()),
)
);
),
)
});
/// Sphere surface resource.
pub static ref SPHERE: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Sphere surface resource.
pub static SPHERE: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__SphereSurface",
SurfaceResource::new_ok(
uuid!("ff1811ba-b9ad-4c37-89b8-503f79aaa4bd"),
ResourceKind::Embedded,
SurfaceData::make_sphere(32, 32, 1.0, &Matrix4::identity()),
)
);
),
)
});
/// Cone surface resource.
pub static ref CONE: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Cone surface resource.
pub static CONE: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__ConeSurface",
SurfaceResource::new_ok(
uuid!("e4e79405-39c5-4fe4-ba3e-c961f3d7379e"),
ResourceKind::Embedded,
SurfaceData::make_cone(32, 1.0, 1.0, &Matrix4::identity()),
)
);
),
)
});
/// Torus surface resource.
pub static ref TORUS: BuiltInResource<SurfaceData> = BuiltInResource::new_no_source(
/// Torus surface resource.
pub static TORUS: LazyLock<BuiltInResource<SurfaceData>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__TorusSurface",
SurfaceResource::new_ok(
uuid!("d2bb5455-c72e-475d-90da-e3a7bd5b7d07"),
ResourceKind::Embedded,
SurfaceData::make_torus(1.0, 0.25,32, 32, &Matrix4::identity()),
)
);
}
SurfaceData::make_torus(1.0, 0.25, 32, 32, &Matrix4::identity()),
),
)
});
+38 -23
View File
@@ -20,7 +20,7 @@
//! Skybox is a huge box around a camera. See [`SkyBox`] docs for more info.
use std::fmt::Display;
use std::{fmt::Display, sync::LazyLock};
use crate::{
asset::{builtin::BuiltInResource, embedded_data_source, untyped::ResourceKind},
@@ -31,7 +31,6 @@ use fyrox_texture::{
CompressionOptions, Texture, TextureImportOptions, TextureKind, TextureMinificationFilter,
TexturePixelKind, TextureResource, TextureResourceExtension, TextureWrapMode,
};
use lazy_static::lazy_static;
use uuid::{uuid, Uuid};
/// Skybox is a huge box around a camera. Each face has its own texture, when textures are
@@ -508,39 +507,55 @@ fn load_texture(id: Uuid, data: &[u8]) -> TextureResource {
.unwrap()
}
lazy_static! {
static ref BUILT_IN_SKYBOX_FRONT: BuiltInResource<Texture> = BuiltInResource::new(
static BUILT_IN_SKYBOX_FRONT: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_FRONT",
embedded_data_source!("skybox/front.png"),
|data| { load_texture(uuid!("f8d4519b-2947-4c83-9aa5-800a70ae918e"), data) }
);
static ref BUILT_IN_SKYBOX_BACK: BuiltInResource<Texture> = BuiltInResource::new(
|data| load_texture(uuid!("f8d4519b-2947-4c83-9aa5-800a70ae918e"), data),
)
});
static BUILT_IN_SKYBOX_BACK: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_BACK",
embedded_data_source!("skybox/back.png"),
|data| { load_texture(uuid!("28676705-58bd-440f-b0aa-ce42cf95be79"), data) }
);
static ref BUILT_IN_SKYBOX_TOP: BuiltInResource<Texture> = BuiltInResource::new(
|data| load_texture(uuid!("28676705-58bd-440f-b0aa-ce42cf95be79"), data),
)
});
static BUILT_IN_SKYBOX_TOP: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_TOP",
embedded_data_source!("skybox/top.png"),
|data| { load_texture(uuid!("03e38da7-53d1-48c0-87f8-2baf9869d61d"), data) }
);
static ref BUILT_IN_SKYBOX_BOTTOM: BuiltInResource<Texture> = BuiltInResource::new(
|data| load_texture(uuid!("03e38da7-53d1-48c0-87f8-2baf9869d61d"), data),
)
});
static BUILT_IN_SKYBOX_BOTTOM: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_BOTTOM",
embedded_data_source!("skybox/bottom.png"),
|data| { load_texture(uuid!("01684dc1-34b2-48b3-b8c2-30a7718cb9e7"), data) }
);
static ref BUILT_IN_SKYBOX_LEFT: BuiltInResource<Texture> = BuiltInResource::new(
|data| load_texture(uuid!("01684dc1-34b2-48b3-b8c2-30a7718cb9e7"), data),
)
});
static BUILT_IN_SKYBOX_LEFT: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_LEFT",
embedded_data_source!("skybox/left.png"),
|data| { load_texture(uuid!("1725b779-7633-477a-a7b0-995c079c3202"), data) }
);
static ref BUILT_IN_SKYBOX_RIGHT: BuiltInResource<Texture> = BuiltInResource::new(
|data| load_texture(uuid!("1725b779-7633-477a-a7b0-995c079c3202"), data),
)
});
static BUILT_IN_SKYBOX_RIGHT: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_SKYBOX_RIGHT",
embedded_data_source!("skybox/right.png"),
|data| { load_texture(uuid!("5f74865a-3eae-4bff-8743-b9d1f7bb3c59"), data) }
);
static ref BUILT_IN_SKYBOX: SkyBox = SkyBoxKind::make_built_in_skybox();
}
|data| load_texture(uuid!("5f74865a-3eae-4bff-8743-b9d1f7bb3c59"), data),
)
});
static BUILT_IN_SKYBOX: LazyLock<SkyBox> = LazyLock::new(SkyBoxKind::make_built_in_skybox);
impl SkyBoxKind {
fn make_built_in_skybox() -> SkyBox {
+10 -7
View File
@@ -65,12 +65,12 @@ use fyrox_graph::SceneGraph;
use fyrox_resource::untyped::ResourceKind;
use half::f16;
use image::{imageops::FilterType, ImageBuffer, Luma};
use lazy_static::lazy_static;
use std::{
cell::Cell,
cmp::Ordering,
collections::HashMap,
ops::{Deref, DerefMut, Range},
sync::LazyLock,
};
pub mod brushstroke;
@@ -86,17 +86,20 @@ use super::collider::BitMask;
/// Current implementation version marker.
pub const VERSION: u8 = 0;
lazy_static! {
/// Solid white texture
pub static ref WHITE_1X1: TextureResource = TextureResource::from_bytes(
/// WHITE_1X1 TextureResource.
pub static WHITE_1X1: LazyLock<TextureResource> = LazyLock::new(|| {
TextureResource::from_bytes(
uuid!("09a71013-ccb2-4a41-a48a-ab6c80f14f0e"),
TextureKind::Rectangle { width: 1, height: 1 },
TextureKind::Rectangle {
width: 1,
height: 1,
},
TexturePixelKind::R8,
vec![255],
ResourceKind::External,
)
.unwrap();
}
.unwrap()
});
/// Position of a single cell within terrain data.
#[derive(Debug, Clone)]
+7 -7
View File
@@ -51,7 +51,6 @@ pub use transform::*;
pub use update::*;
use super::{dim2::rectangle::RectangleVertex, node::constructor::NodeConstructor};
use crate::lazy_static::*;
use crate::{
asset::{untyped::ResourceKind, ResourceDataRef},
core::{
@@ -89,19 +88,20 @@ use std::{
fmt::Display,
ops::{Deref, DerefMut},
path::PathBuf,
sync::LazyLock,
};
/// Current implementation version marker.
pub const VERSION: u8 = 0;
lazy_static! {
/// The default material for tiles that have no material set.
pub static ref DEFAULT_TILE_MATERIAL: MaterialResource = MaterialResource::new_ok(
/// The default material for tiles that have no material set.
pub static DEFAULT_TILE_MATERIAL: LazyLock<MaterialResource> = LazyLock::new(|| {
MaterialResource::new_ok(
uuid!("36bf5b66-b4fa-4bca-80eb-33a271d8f825"),
ResourceKind::External,
Material::standard_tile()
);
}
Material::standard_tile(),
)
});
/// Context for rendering tiles in a tile map. It is especially used by
/// [`TileMapEffect`] objects.
-1
View File
@@ -21,7 +21,6 @@ fyrox-graphics = { version = "1.0.0-rc.1", path = "../fyrox-graphics" }
strum = "0.27"
strum_macros = "0.27"
fxhash = "0.2.1"
lazy_static = "1.4.0"
uuid = "1"
serde = { version = "1", features = ["derive"] }
ron = "0.11.0"
+55 -42
View File
@@ -24,13 +24,12 @@ use fyrox_resource::{
Resource, ResourceData,
};
use fyrox_texture::TextureResource;
use lazy_static::lazy_static;
use std::{
any::Any,
error::Error,
fmt::{Display, Formatter},
path::Path,
sync::Arc,
sync::{Arc, LazyLock},
};
use strum_macros::{AsRefStr, EnumString, VariantNames};
@@ -1084,79 +1083,93 @@ impl MaterialResourceExtension for MaterialResource {
}
}
lazy_static! {
/// Standard PBR material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD: BuiltInResource<Material> = BuiltInResource::new_no_source("__StandardMaterial",
/// Standard PBR material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardMaterial",
MaterialResource::new_ok(
uuid!("fac37721-d1b8-422e-ae0c-83196ecd0a26"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard()),
)
);
),
)
});
/// Standard 2D material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_2D: BuiltInResource<Material> = BuiltInResource::new_no_source("__Standard2DMaterial",
/// Standard 2D material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_2D: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__Standard2DMaterial",
MaterialResource::new_ok(
uuid!("fe78a0d0-d059-4156-bc63-c3d2e36ad4b6"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_2d()),
)
);
),
)
});
/// Standard particle system material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_PARTICLE_SYSTEM: BuiltInResource<Material> = BuiltInResource::new_no_source(
/// Standard particle system material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_PARTICLE_SYSTEM: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardParticleSystemMaterial",
MaterialResource::new_ok(
uuid!("5bebe6e5-4aeb-496f-88f6-abe2b1ac798b"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_particle_system(),),
)
);
Material::from_shader(ShaderResource::standard_particle_system()),
),
)
});
/// Standard sprite material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_SPRITE: BuiltInResource<Material> = BuiltInResource::new_no_source(
/// Standard sprite material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_SPRITE: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardSpriteMaterial",
MaterialResource::new_ok(
uuid!("3e331786-baae-412b-9d99-7370174bca43"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_sprite()),
)
);
),
)
});
/// Standard terrain material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_TERRAIN: BuiltInResource<Material> = BuiltInResource::new_no_source(
/// Standard terrain material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_TERRAIN: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardTerrainMaterial",
MaterialResource::new_ok(
uuid!("0e407e22-41ad-4763-9adb-9d2e86351ece"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_terrain()),
)
);
),
)
});
/// Standard two-sided material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_TWOSIDES: BuiltInResource<Material> = BuiltInResource::new_no_source(
/// Standard two-sided material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_TWOSIDES: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardTwoSidesMaterial",
MaterialResource::new_ok(
uuid!("24115321-7766-495c-bc3a-75db2f73d26d"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_twosides()),
)
);
Material::from_shader(ShaderResource::standard_twosides()),
),
)
});
/// Standard widget material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static ref STANDARD_WIDGET: BuiltInResource<Material> = BuiltInResource::new_no_source(
/// Standard widget material. Keep in mind that this material is global, any modification
/// of it will reflect on every other usage of it.
pub static STANDARD_WIDGET: LazyLock<BuiltInResource<Material>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__StandardWidgetMaterial",
MaterialResource::new_ok(
uuid!("e5d61a6f-5c94-4137-b303-1ae29cfff6e7"),
ResourceKind::External,
Material::from_shader(ShaderResource::standard_widget()),
)
);
}
Material::from_shader(ShaderResource::standard_widget()),
),
)
});
+86 -55
View File
@@ -469,10 +469,10 @@ use fyrox_resource::{
embedded_data_source, io::ResourceIo, manager::BuiltInResource, untyped::ResourceKind,
Resource, ResourceData,
};
use lazy_static::lazy_static;
use ron::ser::PrettyConfig;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::ops::{Deref, DerefMut};
use std::sync::LazyLock;
use std::{
error::Error,
fmt::{Display, Formatter},
@@ -951,9 +951,9 @@ impl ShaderResourceExtension for ShaderResource {
}
}
lazy_static! {
/// Standard shader.
pub static ref STANDARD: BuiltInResource<Shader> = BuiltInResource::new(
/// Standard shader.
pub static STANDARD: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_SHADER_NAME,
embedded_data_source!("standard/standard.shader"),
|data| {
@@ -962,40 +962,58 @@ lazy_static! {
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
}
);
/// Standard 2D shader.
pub static ref STANDARD_2D: BuiltInResource<Shader> = BuiltInResource::new(
},
)
});
/// Standard 2D shader.
pub static STANDARD_2D: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_2D_SHADER_NAME,
embedded_data_source!("standard/standard2d.shader"),
|data| ShaderResource::new_ok(
uuid!("55fa05b0-3c25-4e46-bae7-65f093185b75"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
);
/// Standard particle system shader.
pub static ref STANDARD_PARTICLE_SYSTEM: BuiltInResource<Shader> = BuiltInResource::new(
|data| {
ShaderResource::new_ok(
uuid!("55fa05b0-3c25-4e46-bae7-65f093185b75"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
},
)
});
/// Standard particle system shader.
pub static STANDARD_PARTICLE_SYSTEM: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_PARTICLE_SYSTEM_SHADER_NAME,
embedded_data_source!("standard/standard_particle_system.shader"),
|data| ShaderResource::new_ok(
uuid!("eb474445-6a25-4481-bca9-f919699c300f"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
);
/// Standard sprite shader.
pub static ref STANDARD_SPRITE: BuiltInResource<Shader> = BuiltInResource::new(
|data| {
ShaderResource::new_ok(
uuid!("eb474445-6a25-4481-bca9-f919699c300f"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
},
)
});
/// Standard sprite shader.
pub static STANDARD_SPRITE: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_SPRITE_SHADER_NAME,
embedded_data_source!("standard/standard_sprite.shader"),
|data| ShaderResource::new_ok(
uuid!("a135826a-4c1b-46d5-ba1f-0c9a226aa52c"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
);
/// Standard terrain shader.
pub static ref STANDARD_TERRAIN: BuiltInResource<Shader> = BuiltInResource::new(
|data| {
ShaderResource::new_ok(
uuid!("a135826a-4c1b-46d5-ba1f-0c9a226aa52c"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
},
)
});
/// Standard terrain shader.
pub static STANDARD_TERRAIN: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_TERRAIN_SHADER_NAME,
embedded_data_source!("standard/terrain.shader"),
|data| {
@@ -1004,10 +1022,13 @@ lazy_static! {
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
}
);
/// Standard tile shader.
pub static ref STANDARD_TILE: BuiltInResource<Shader> = BuiltInResource::new(
},
)
});
/// Standard tile shader.
pub static STANDARD_TILE: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_TILE_SHADER_NAME,
embedded_data_source!("standard/tile.shader"),
|data| {
@@ -1016,29 +1037,39 @@ lazy_static! {
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
}
);
/// Standard two-sides shader.
pub static ref STANDARD_TWOSIDES: BuiltInResource<Shader> = BuiltInResource::new(
},
)
});
/// Standard two-sides shader.
pub static STANDARD_TWOSIDES: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_TWOSIDES_SHADER_NAME,
embedded_data_source!("standard/standard-two-sides.shader"),
|data| ShaderResource::new_ok(
uuid!("f7979409-5185-4e1c-a644-d53cea64af8f"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
);
/// Standard widget shader.
pub static ref STANDARD_WIDGET: BuiltInResource<Shader> = BuiltInResource::new(
|data| {
ShaderResource::new_ok(
uuid!("f7979409-5185-4e1c-a644-d53cea64af8f"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
},
)
});
/// Standard widget shader.
pub static STANDARD_WIDGET: LazyLock<BuiltInResource<Shader>> = LazyLock::new(|| {
BuiltInResource::new(
STANDARD_WIDGET_SHADER_NAME,
embedded_data_source!("standard/widget.shader"),
|data| ShaderResource::new_ok(
uuid!("f5908aa4-e187-42a8-95d2-dc6577f6def4"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
);
}
|data| {
ShaderResource::new_ok(
uuid!("f5908aa4-e187-42a8-95d2-dc6577f6def4"),
ResourceKind::External,
Shader::from_string_bytes(data).unwrap(),
)
},
)
});
#[cfg(test)]
mod test {
-1
View File
@@ -18,7 +18,6 @@ fyrox-resource = { path = "../fyrox-resource", version = "1.0.0-rc.1" }
ddsfile = "0.5.0"
fast_image_resize = "5.0.0"
serde = { version = "1", features = ["derive"] }
lazy_static = "1.4.0"
fxhash = "0.2.1"
strum = "0.27"
strum_macros = "0.27"
+20 -11
View File
@@ -64,8 +64,8 @@ use fyrox_resource::{
untyped::ResourceKind, Resource, ResourceData,
};
use image::{ColorType, DynamicImage, ImageError, ImageFormat, Pixel};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
use std::{
fmt::{Debug, Display, Formatter},
hash::{Hash, Hasher},
@@ -670,30 +670,39 @@ impl TextureImportOptions {
}
}
lazy_static! {
/// Placeholder texture.
pub static ref PLACEHOLDER: BuiltInResource<Texture> = BuiltInResource::new("__PlaceholderTexture", embedded_data_source!("default.png"),
/// Placeholder texture.
pub static PLACEHOLDER: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__PlaceholderTexture",
embedded_data_source!("default.png"),
|data| {
TextureResource::load_from_memory(
uuid!("58b0e112-a21a-481f-b305-a2dc5a8bea1f"),
ResourceKind::External,
data,
Default::default()
Default::default(),
)
.unwrap()
});
/// Pure color texture.
pub static ref PURE_COLOR: BuiltInResource<Texture> = BuiltInResource::new("__PureColorTexture", embedded_data_source!("pure_color.png"),
},
)
});
/// Pure color texture.
pub static PURE_COLOR: LazyLock<BuiltInResource<Texture>> = LazyLock::new(|| {
BuiltInResource::new(
"__PureColorTexture",
embedded_data_source!("pure_color.png"),
|data| {
TextureResource::load_from_memory(
uuid!("9709eef2-305c-44da-91e5-6f293d74408a"),
ResourceKind::External,
data,
Default::default()
Default::default(),
)
.unwrap()
});
}
},
)
});
/// Type alias for texture resources.
pub type TextureResource = Resource<Texture>;
-1
View File
@@ -21,7 +21,6 @@ fyrox-texture = { path = "../fyrox-texture", version = "1.0.0-rc.1" }
fyrox-graph = { path = "../fyrox-graph", version = "1.0.0-rc.1" }
fyrox-animation = { path = "../fyrox-animation", version = "1.0.0-rc.1" }
fyrox-material = { path = "../fyrox-material", version = "1.0.0-rc.2" }
lazy_static = "1.4.0"
copypasta = "0.10.1"
fontdue = "0.9.2"
notify = "8"
+39 -23
View File
@@ -39,7 +39,7 @@ use fyrox_resource::{
embedded_data_source, io::ResourceIo, manager::BuiltInResource, untyped::UntypedResource,
Resource, ResourceData,
};
use lazy_static::lazy_static;
use std::sync::LazyLock;
use std::{
error::Error,
fmt::{Debug, Formatter},
@@ -412,53 +412,69 @@ impl Hash for FontHeight {
/// A resource that allows a font to be loaded.
pub type FontResource = Resource<Font>;
lazy_static! {
/// Fyrox's default build-in font for rendering bold italic text when no other font is specified.
pub static ref BOLD_ITALIC: BuiltInResource<Font> = BuiltInResource::new(
/// Fyrox's default build-in font for rendering bold italic text when no other font is specified.
pub static BOLD_ITALIC: LazyLock<BuiltInResource<Font>> = LazyLock::new(|| {
BuiltInResource::new(
"__BOLD_ITALIC__",
embedded_data_source!("./bold_italic.ttf"),
|data| {
FontResource::new_ok(
uuid!("f5b02124-9601-452a-9368-3fa2a9703ecd"),
ResourceKind::External,
Font::from_memory(data.to_vec(), 1024, FontStyles::default(), Vec::default()).unwrap(),
Font::from_memory(data.to_vec(), 1024, FontStyles::default(), Vec::default())
.unwrap(),
)
}
);
/// Fyrox's default build-in font for rendering italic text when no other font is specified.
pub static ref BUILT_IN_ITALIC: BuiltInResource<Font> = BuiltInResource::new(
},
)
});
/// Fyrox's default build-in font for rendering italic text when no other font is specified.
pub static BUILT_IN_ITALIC: LazyLock<BuiltInResource<Font>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_ITALIC__",
embedded_data_source!("./built_in_italic.ttf"),
|data| {
let bold = Some(BOLD_ITALIC.resource());
let styles = FontStyles{bold, ..FontStyles::default()};
let styles = FontStyles {
bold,
..FontStyles::default()
};
FontResource::new_ok(
uuid!("1cd79487-6c76-4370-91c2-e6e1e728950a"),
ResourceKind::External,
Font::from_memory(data.to_vec(), 1024, styles, Vec::default()).unwrap(),
)
}
);
/// Fyrox's default build-in font for rendering bold text when no other font is specified.
pub static ref BUILT_IN_BOLD: BuiltInResource<Font> = BuiltInResource::new(
},
)
});
/// Fyrox's default build-in font for rendering bold text when no other font is specified.
pub static BUILT_IN_BOLD: LazyLock<BuiltInResource<Font>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_BOLD__",
embedded_data_source!("./built_in_bold.ttf"),
|data| {
let italic = Some(BOLD_ITALIC.resource());
let styles = FontStyles{italic, ..FontStyles::default()};
let styles = FontStyles {
italic,
..FontStyles::default()
};
FontResource::new_ok(
uuid!("8a471243-2466-4241-a4cb-c341ce8e844a"),
ResourceKind::External,
Font::from_memory(data.to_vec(), 1024, styles, Vec::default()).unwrap(),
)
}
);
/// Fyrox's default build-in font for rendering text when no other font is specified.
pub static ref BUILT_IN_FONT: BuiltInResource<Font> = BuiltInResource::new(
},
)
});
/// Fyrox's default build-in font for rendering text when no other font is specified.
pub static BUILT_IN_FONT: LazyLock<BuiltInResource<Font>> = LazyLock::new(|| {
BuiltInResource::new(
"__BUILT_IN_FONT__",
embedded_data_source!("./built_in_font.ttf"),
|data| {
let styles = FontStyles{
let styles = FontStyles {
bold: Some(BUILT_IN_BOLD.resource()),
italic: Some(BUILT_IN_ITALIC.resource()),
bold_italic: Some(BOLD_ITALIC.resource()),
@@ -468,9 +484,9 @@ lazy_static! {
ResourceKind::External,
Font::from_memory(data.to_vec(), 1024, styles, Vec::default()).unwrap(),
)
}
);
}
},
)
});
/// Wait for all subfonts of this font to be completely loaded, including recursively searching
/// through the fallback fonts, and the fallbacks of the fallbacks, to ensure that this font is
+15 -8
View File
@@ -45,8 +45,10 @@ use fyrox_resource::{
manager::{BuiltInResource, ResourceManager},
};
use fyrox_texture::TextureResource;
use lazy_static::lazy_static;
use std::any::{Any, TypeId};
use std::{
any::{Any, TypeId},
sync::LazyLock,
};
use std::{
ops::{Deref, DerefMut},
path::Path,
@@ -123,12 +125,17 @@ impl_casts!(Color => Color);
impl_casts!(Brush => Brush);
impl_casts!(TextureResource => Texture);
lazy_static! {
/// Default style of the library.
pub static ref DEFAULT_STYLE: BuiltInResource<Style> = BuiltInResource::new_no_source("__DEFAULT_STYLE__",
StyleResource::new_ok(uuid!("1e0716e8-e728-491c-a65b-ca11b15048be"), ResourceKind::External, Style::dark_style())
);
}
/// Default style of the library.
pub static DEFAULT_STYLE: LazyLock<BuiltInResource<Style>> = LazyLock::new(|| {
BuiltInResource::new_no_source(
"__DEFAULT_STYLE__",
StyleResource::new_ok(
uuid!("1e0716e8-e728-491c-a65b-ca11b15048be"),
ResourceKind::External,
Style::dark_style(),
),
)
});
/// A property, that can bind its value to a style. Why can't we just fetch the actual value from
/// the style and why do we need to store the value as well? The answer is flexibility. In this