Skip to content

Commit

Permalink
Split Bevy impls across multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Apr 29, 2023
1 parent 0bafa8b commit 0f04af3
Show file tree
Hide file tree
Showing 16 changed files with 1,581 additions and 1,581 deletions.
1,581 changes: 0 additions & 1,581 deletions bevy_proto_backend/src/impls.rs

This file was deleted.

3 changes: 3 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/animation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use bevy::app::App;

pub(super) fn register(_app: &mut App) {}
79 changes: 79 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use bevy::app::App;
use bevy::asset::{Asset, AssetServer, Handle};
use bevy::ecs::world::EntityMut;

use crate::impls::macros::register_schematic;
use bevy_proto_derive::impl_external_schematic;

use crate::proto::ProtoAsset;
use crate::schematics::FromSchematicInput;
use crate::tree::EntityTree;

#[allow(unused_variables)]
pub(super) fn register(app: &mut App) {
#[cfg(feature = "bevy_animation")]
register_schematic!(app, Handle<bevy::prelude::AnimationClip>);

#[cfg(feature = "bevy_audio")]
register_schematic!(
app,
Handle<bevy::prelude::AudioSink>,
Handle<bevy::prelude::AudioSource>,
Handle<bevy::prelude::SpatialAudioSink>,
);

#[cfg(feature = "bevy_gltf")]
register_schematic!(
app,
Handle<bevy::gltf::Gltf>,
Handle<bevy::gltf::GltfMesh>,
Handle<bevy::gltf::GltfPrimitive>,
Handle<bevy::gltf::GltfNode>,
);

#[cfg(feature = "bevy_pbr")]
register_schematic!(app, Handle<bevy::prelude::StandardMaterial>);

#[cfg(feature = "bevy_render")]
register_schematic!(
app,
Handle<bevy::prelude::Image>,
Handle<bevy::render::mesh::skinning::SkinnedMeshInverseBindposes>,
Handle<bevy::prelude::Mesh>,
Handle<bevy::prelude::Shader>,
);

#[cfg(feature = "bevy_scene")]
register_schematic!(
app,
Handle<bevy::prelude::DynamicScene>,
Handle<bevy::prelude::Scene>,
);

#[cfg(feature = "bevy_sprite")]
register_schematic!(
app,
Handle<bevy::prelude::ColorMaterial>,
Handle<bevy::prelude::TextureAtlas>,
);

#[cfg(feature = "bevy_text")]
register_schematic!(
app,
Handle<bevy::prelude::Font>,
Handle<bevy::text::FontAtlasSet>,
);
}

impl_external_schematic! {
#[schematic(from = ProtoAsset)]
struct Handle<T: Asset> {}
// ---
impl<T: Asset> FromSchematicInput<ProtoAsset> for Handle<T> {
fn from_input(input: ProtoAsset, entity: &mut EntityMut, _: &EntityTree) -> Self {
match input {
ProtoAsset::AssetPath(path) => entity.world().resource::<AssetServer>().get_handle(path)
}
}
}
}
23 changes: 23 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use bevy::app::App;
use bevy::core::Name;
use bevy::reflect::{FromReflect, Reflect};

use crate::impls::macros::register_schematic;
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
register_schematic!(app, Name);
}

impl_external_schematic! {
#[schematic(from = NameInput)]
struct Name {}
// ---
#[derive(Reflect, FromReflect)]
pub struct NameInput(String);
impl From<NameInput> for Name {
fn from(input: NameInput) -> Self {
Name::new(input.0)
}
}
}
191 changes: 191 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
use bevy::app::App;
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings};
use bevy::core_pipeline::clear_color::ClearColorConfig;
use bevy::core_pipeline::core_3d::Camera3dDepthLoadOp;
use bevy::core_pipeline::fxaa::Fxaa;
use bevy::core_pipeline::prepass::{DepthPrepass, NormalPrepass};
use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping};
use bevy::prelude::{Camera2d, Camera3d, Color};
use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect};

use crate::impls::macros::{from_to, from_to_default, register_schematic};
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
register_schematic!(
app,
BloomSettings,
Camera2d,
Camera3d,
DebandDither,
DepthPrepass,
Fxaa,
NormalPrepass,
Tonemapping
);
}

impl_external_schematic! {
#[schematic(from = BloomSettingsInput)]
struct BloomSettings {}
// ---
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct BloomSettingsInput {
pub intensity: f32,
pub low_frequency_boost: f32,
pub low_frequency_boost_curvature: f32,
pub high_pass_frequency: f32,
pub prefilter_settings: BloomPrefilterSettingsInput,
pub composite_mode: BloomCompositeModeInput,
}
from_to_default!(
BloomSettings,
BloomSettingsInput,
|value: Input| Self {
intensity: value.intensity,
low_frequency_boost: value.low_frequency_boost,
low_frequency_boost_curvature: value.low_frequency_boost_curvature,
high_pass_frequency: value.high_pass_frequency,
prefilter_settings: value.prefilter_settings.into(),
composite_mode: value.composite_mode.into(),
}
);

#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct BloomPrefilterSettingsInput {
pub threshold: f32,
pub threshold_softness: f32,
}
from_to_default!(
BloomPrefilterSettings,
BloomPrefilterSettingsInput,
|value: Input| Self {
threshold: value.threshold,
threshold_softness: value.threshold_softness,
}
);

#[derive(Reflect, FromReflect)]
pub enum BloomCompositeModeInput {
EnergyConserving,
Additive,
}
from_to!(
BloomCompositeMode,
BloomCompositeModeInput,
|value| match value {
Input::EnergyConserving => Self::EnergyConserving,
Input::Additive => Self::Additive,
}
);
}

impl_external_schematic! {
#[schematic(from = Camera2dInput)]
struct Camera2d {}
// ---
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct Camera2dInput {
pub clear_color: ClearColorConfigInput,
}
from_to_default!(
Camera2d,
Camera2dInput,
|value: Input| Self {
clear_color: value.clear_color.into(),
}
);
}

impl_external_schematic! {
#[schematic(from = Camera3dInput)]
struct Camera3d {}
// ---
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct Camera3dInput {
pub clear_color: ClearColorConfigInput,
pub depth_load_op: Camera3dDepthLoadOpInput,
}
from_to_default!(
Camera3d,
Camera3dInput,
|value: Input| Self {
clear_color: value.clear_color.into(),
depth_load_op: value.depth_load_op.into()
}
);

#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub enum Camera3dDepthLoadOpInput {
Clear(f32),
Load,
}
from_to_default!(
Camera3dDepthLoadOp,
Camera3dDepthLoadOpInput,
|value: Input| match value {
Input::Clear(value) => Self::Clear(value),
Input::Load => Self::Load,
}
);
}

impl_external_schematic! {
enum DebandDither {}
}

impl_external_schematic! {
#[schematic(from = DepthPrepassInput)]
struct DepthPrepass {}
// ---
#[derive(Reflect, FromReflect)]
pub struct DepthPrepassInput;
impl From<DepthPrepassInput> for DepthPrepass {
fn from(_: DepthPrepassInput) -> Self {
Self
}
}
}

impl_external_schematic! {
struct Fxaa {}
}

impl_external_schematic! {
#[schematic(from = NormalPrepassInput)]
struct NormalPrepass {}
// ---
#[derive(Reflect, FromReflect)]
pub struct NormalPrepassInput;
impl From<NormalPrepassInput> for NormalPrepass {
fn from(_: NormalPrepassInput) -> Self {
Self
}
}
}

impl_external_schematic! {
enum Tonemapping {}
}

#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub enum ClearColorConfigInput {
Default,
Custom(Color),
None,
}
from_to_default!(
ClearColorConfig,
ClearColorConfigInput,
|value| match value {
Input::Default => Self::Default,
Input::Custom(color) => Self::Custom(color),
Input::None => Self::None,
}
);
27 changes: 27 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/gltf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use bevy::app::App;
use bevy::gltf::GltfExtras;
use bevy::reflect::{FromReflect, Reflect};

use crate::impls::macros::{from_to_default, register_schematic};
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
register_schematic!(app, GltfExtras);
}

impl_external_schematic! {
#[schematic(from = GltfExtrasInput)]
struct GltfExtras {}
// ---
#[derive(Reflect, FromReflect)]
pub struct GltfExtrasInput{
pub value: String,
}
from_to_default!(
GltfExtras,
GltfExtrasInput,
|value: Input| Self {
value: value.value,
}
);
}
44 changes: 44 additions & 0 deletions bevy_proto_backend/src/impls/bevy_impls/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#[cfg(feature = "bevy_animation")]
mod animation;
mod asset;
mod core;
#[cfg(feature = "bevy_core_pipeline")]
mod core_pipeline;
#[cfg(feature = "bevy_gltf")]
mod gltf;
#[cfg(feature = "bevy_pbr")]
mod pbr;
#[cfg(feature = "bevy_render")]
mod render;
#[cfg(feature = "bevy_sprite")]
mod sprite;
#[cfg(feature = "bevy_text")]
mod text;
mod transform;
#[cfg(feature = "bevy_ui")]
mod ui;
mod window;

pub(super) fn register_impls(app: &mut bevy::app::App) {
asset::register(app);
core::register(app);
transform::register(app);
window::register(app);

#[cfg(feature = "bevy_animation")]
animation::register(app);
#[cfg(feature = "bevy_core_pipeline")]
core_pipeline::register(app);
#[cfg(feature = "bevy_gltf")]
gltf::register(app);
#[cfg(feature = "bevy_pbr")]
pbr::register(app);
#[cfg(feature = "bevy_render")]
render::register(app);
#[cfg(feature = "bevy_sprite")]
sprite::register(app);
#[cfg(feature = "bevy_text")]
text::register(app);
#[cfg(feature = "bevy_ui")]
ui::register(app);
}
Loading

0 comments on commit 0f04af3

Please sign in to comment.