Skip to main content

gizmo_engine/
plugins.rs

1use crate::app::{App, Plugin};
2use gizmo_physics_rigid::world::PhysicsWorld;
3
4use crate::math::Vec3;
5
6/// Gizmo Engine Fizik Eklentisi (Plugin).
7/// Eklendiğinde fizik dünyasını (PhysicsWorld) başlatır.
8#[non_exhaustive]
9pub struct PhysicsPlugin {
10    pub gravity: Vec3,
11}
12
13impl Default for PhysicsPlugin {
14    fn default() -> Self {
15        Self {
16            gravity: Vec3::new(0.0, -9.81, 0.0),
17        }
18    }
19}
20
21impl PhysicsPlugin {
22    /// Varsayılan yerçekimi ile yeni bir PhysicsPlugin oluşturur.
23    pub fn new() -> Self {
24        Self::default()
25    }
26
27    /// Yerçekimi vektörünü ayarlar (zincirlenebilir).
28    pub fn with_gravity(mut self, gravity: Vec3) -> Self {
29        self.gravity = gravity;
30        self
31    }
32}
33
34impl<State: 'static> Plugin<State> for PhysicsPlugin {
35    fn build(&self, app: &mut App<State>) {
36        tracing::info!(
37            "[Plugin] PhysicsPlugin yükleniyor (Yerçekimi: {:?})...",
38            self.gravity
39        );
40        app.world
41            .insert_resource(PhysicsWorld::new().with_gravity(self.gravity));
42        // Run the physics step automatically at the app's fixed timestep (the
43        // `PhysicsTime` accumulator loop that also drives `TransformPlugin`), so
44        // callers don't hand-call `cpu_physics_step_system` every frame. Labelled
45        // so transform systems can order themselves after it if both are added.
46        app.schedule.add_di_system(
47            gizmo_core::system::SystemConfig::new(Box::new(
48                crate::systems::physics::PhysicsStepSystem,
49            ))
50            .label("physics_step"),
51        );
52    }
53}
54
55/// Transform (hiyerarşi ve senkronizasyon) sistemlerini başlatan eklenti.
56pub struct TransformPlugin;
57
58impl<State: 'static> Plugin<State> for TransformPlugin {
59    fn build(&self, app: &mut App<State>) {
60        // PostUpdate (veya Update sonu) gibi bir faz eklenebilir, şimdilik direkt ekleniyor.
61        app.schedule.add_di_system(
62            gizmo_core::system::SystemConfig::new(Box::new(
63                crate::systems::transform::TransformSyncSystem,
64            ))
65            .label("transform_sync"),
66        );
67        app.schedule.add_di_system(
68            gizmo_core::system::SystemConfig::new(Box::new(
69                crate::systems::transform::TransformPropagateSystem,
70            ))
71            .label("transform_propagate")
72            .after("transform_sync"),
73        );
74    }
75}