summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-07-21 14:32:26 +0200
committerHampusM <hampus@hampusmat.com>2026-07-21 14:32:26 +0200
commit63675d4168224b66d28c9d64a8e121ef397d4edd (patch)
tree2c2c13535b971dd95a354099347cd6a530e16796
parent67bb995ffdd201997758701eeda35b4373b51104 (diff)
refactor(engine): use pair macro in phase entity declarations
-rw-r--r--engine/src/asset.rs16
-rw-r--r--engine/src/input.rs17
-rw-r--r--engine/src/rendering.rs35
-rw-r--r--engine/src/rendering/shader.rs16
-rw-r--r--engine/src/windowing.rs14
5 files changed, 27 insertions, 71 deletions
diff --git a/engine/src/asset.rs b/engine/src/asset.rs
index ebcf5c7..b72fc74 100644
--- a/engine/src/asset.rs
+++ b/engine/src/asset.rs
@@ -18,22 +18,16 @@ use std::sync::Arc;
use ecs::actions::Actions;
-use crate::ecs::pair::{ChildOf, Pair};
+use crate::ecs::pair;
+use crate::ecs::pair::ChildOf;
use crate::ecs::phase::{Phase, PRE_UPDATE as PRE_UPDATE_PHASE};
use crate::ecs::sole::Single;
use crate::ecs::{declare_entity, Sole};
use crate::work_queue::{Work, WorkQueue};
-declare_entity!(
- pub HANDLE_ASSETS_PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*PRE_UPDATE_PHASE)
- .build()
- )
-);
+declare_entity! {
+pub HANDLE_ASSETS_PHASE: (Phase, pair!(ChildOf, { *PRE_UPDATE_PHASE }));
+}
/// Asset label.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
diff --git a/engine/src/input.rs b/engine/src/input.rs
index 0234b4b..a86cb1a 100644
--- a/engine/src/input.rs
+++ b/engine/src/input.rs
@@ -1,22 +1,15 @@
-use crate::ecs::declare_entity;
+use crate::ecs::{declare_entity, pair};
use crate::ecs::extension::Collector as ExtensionCollector;
-use crate::ecs::pair::{ChildOf, Pair};
+use crate::ecs::pair::ChildOf;
use crate::ecs::phase::Phase;
use crate::windowing::PHASE as WINDOWING_PHASE;
pub mod keyboard;
pub mod mouse;
-declare_entity!(
- pub PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*WINDOWING_PHASE)
- .build()
- )
-);
+declare_entity! {
+pub PHASE: (Phase, pair!(ChildOf, { *WINDOWING_PHASE }));
+}
/// Input extension.
#[derive(Debug, Default)]
diff --git a/engine/src/rendering.rs b/engine/src/rendering.rs
index 4871f08..e67a457 100644
--- a/engine/src/rendering.rs
+++ b/engine/src/rendering.rs
@@ -18,7 +18,7 @@ use crate::ecs::sole::Single;
use crate::ecs::system::initializable::Initializable;
use crate::ecs::system::observer::Observe;
use crate::ecs::system::Into;
-use crate::ecs::{declare_entity, Component, Query, Sole};
+use crate::ecs::{declare_entity, pair, Component, Query, Sole};
use crate::image::Image;
use crate::mesh::Mesh;
use crate::rendering::blending::Config as BlendingConfig;
@@ -42,32 +42,13 @@ pub mod shader;
static NEXT_SURFACE_ID: AtomicU64 = AtomicU64::new(0);
-declare_entity!(
- pub PRE_RENDER_PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*POST_UPDATE_PHASE)
- .build()
- )
-);
-
-declare_entity!(
- pub RENDER_PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*PRE_RENDER_PHASE)
- .build()
- )
-);
-
-declare_entity!(
- pub POST_RENDER_PHASE,
- (Phase, Pair::builder().relation::<ChildOf>().target_id(*RENDER_PHASE).build())
-);
+declare_entity! {
+pub PRE_RENDER_PHASE: (Phase, pair!(ChildOf, { *POST_UPDATE_PHASE }));
+
+pub RENDER_PHASE: (Phase, pair!(ChildOf, { *PRE_RENDER_PHASE }));
+
+pub POST_RENDER_PHASE: (Phase, pair!(ChildOf, { *RENDER_PHASE }));
+}
builder! {
#[builder(name=ExtensionBuilder, derives=(Debug, Clone, Default))]
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs
index 74109a7..7d5bd51 100644
--- a/engine/src/rendering/shader.rs
+++ b/engine/src/rendering/shader.rs
@@ -28,8 +28,9 @@ use crate::asset::{
Submitter as AssetSubmitter,
HANDLE_ASSETS_PHASE,
};
+use crate::ecs::pair;
use crate::builder;
-use crate::ecs::pair::{ChildOf, Pair};
+use crate::ecs::pair::ChildOf;
use crate::ecs::phase::{Phase, POST_UPDATE as POST_UPDATE_PHASE};
use crate::ecs::sole::Single;
use crate::ecs::{declare_entity, Component, Sole};
@@ -1004,16 +1005,9 @@ enum ImportError
CanonicalizePathFailed(#[source] std::io::Error),
}
-declare_entity!(
- IMPORT_SHADERS_PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*HANDLE_ASSETS_PHASE)
- .build()
- )
-);
+declare_entity! {
+pub IMPORT_SHADERS_PHASE: (Phase, pair!(ChildOf, { *HANDLE_ASSETS_PHASE }));
+}
pub(super) fn prepare(collector: &mut crate::ecs::extension::Collector<'_>)
{
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs
index 6997f73..b59075e 100644
--- a/engine/src/windowing.rs
+++ b/engine/src/windowing.rs
@@ -20,6 +20,7 @@ use winit::keyboard::PhysicalKey;
use winit::monitor::MonitorHandle as WinitMonitorHandle;
use winit::window::{Window as WinitWindow, WindowId as WinitWindowId};
+use crate::ecs::pair;
use crate::ecs::actions::Actions;
use crate::ecs::component::Component;
use crate::ecs::entity::obtainer::Obtainer as EntityObtainer;
@@ -66,16 +67,9 @@ const TEXT_KEY_QUEUE_SIZE: usize = 255;
static CONTEXT_CREATED: AtomicBool = AtomicBool::new(false);
-declare_entity!(
- pub PHASE,
- (
- Phase,
- Pair::builder()
- .relation::<ChildOf>()
- .target_id(*UPDATE_PHASE)
- .build()
- )
-);
+declare_entity! {
+pub PHASE: (Phase, pair!(ChildOf, { *UPDATE_PHASE }));
+}
#[derive(Debug, Default)]
#[non_exhaustive]