gizmo/lib.rs
1//! # Gizmo Engine
2//!
3//! `gizmo-engine` is the all-in-one facade crate of the Gizmo game engine. It
4//! re-exports the individual subsystem crates (core ECS, math, app loop,
5//! physics, renderer, windowing, audio, scene, editor, UI, animation and AI)
6//! and adds an ergonomic, Bevy-like convenience layer on top: [`Color`],
7//! ready-made [`bundles`], a [`spawner`] API and prefabricated scene helpers.
8//!
9//! Note that the published *package* is named `gizmo-engine`, while the *library*
10//! (and thus the crate path used in `use` statements and examples) is simply
11//! `gizmo`. That is declared by `[lib] name = "gizmo"` in the manifest, so
12//! `cargo add gizmo-engine` followed by `use gizmo::prelude::*;` works with no
13//! rename in your own `Cargo.toml`:
14//!
15//! ```
16//! use gizmo::prelude::*;
17//!
18//! // The path in every example on this page is the real one.
19//! let mut world = World::new();
20//! let e = world.spawn();
21//! world.add_component(e, Transform::new(Vec3::new(0.0, 1.0, 0.0)));
22//! assert_eq!(
23//! world.query::<&Transform>().unwrap().get(e.id()).unwrap().position.y,
24//! 1.0
25//! );
26//! ```
27//!
28//! ## Feature flags
29//!
30//! Subsystems are gated behind Cargo features so you only compile what you need:
31//!
32//! - `window` — windowing via `winit`.
33//! - `render` — the `wgpu`-based renderer (implies `window`).
34//! - `audio` — audio playback.
35//! - `physics`, `physics-dynamics`, `physics-soft` — physics subsystems.
36//! - `scene` — scene (de)serialization.
37//! - `editor` — the `egui`-based in-engine editor (implies `render`).
38//! - `ui` — the UI subsystem.
39//! - `animation` — skeletal/property animation.
40//! - `scripting` — scripting support.
41//! - `network` — networking / P2P deterministic rollback via `gizmo-net`.
42//! - `headless` — run the app loop without a window (e.g. for servers/tests).
43//!
44//! The `default` feature enables a full desktop game setup (`window`, `render`,
45//! `audio`, `physics`, `scene`, `editor`, `ui`, `animation`, `network`).
46//!
47//! ## Re-exported third-party crates
48//!
49//! For convenience the facade re-exports the external crates that appear in its
50//! public API so downstream users do not have to add them separately:
51//! [`wgpu`] and [`bytemuck`] (with `render`), [`egui`] (with `editor`) and
52//! [`winit`] (with `window`).
53
54// Feature gating rule for the facade's own modules:
55//
56// These used to be unconditional `pub mod`s whose bodies referenced the *optional*
57// `gizmo-renderer` / `gizmo-physics-*` dependencies unconditionally, so `gizmo-engine`
58// only ever compiled with `render` AND `physics` on — including under its own advertised
59// `headless` feature. Gate at the narrowest level that still compiles: a whole module
60// where every item needs the dependency, individual items where the split is inside.
61//
62// `Transform` lives in `gizmo-physics-core`, so anything touching transforms needs the
63// `physics` feature — that is why several purely-logical modules are gated on it.
64
65/// GPU asset loading — requires a renderer.
66#[cfg(feature = "render")]
67pub mod asset_server;
68/// Ready-made component bundles. Light/camera/mesh bundles need `render`; the rigid-body
69/// bundle needs `physics` (see the per-item gates inside).
70#[cfg(any(feature = "render", feature = "physics"))]
71pub mod bundles;
72pub mod color;
73pub mod plugins;
74pub mod prelude;
75/// Entity spawning helpers built on the renderer's mesh/material pipeline. They also spawn
76/// rigid bodies, hence the `physics` half of the gate.
77#[cfg(all(feature = "render", feature = "physics"))]
78pub mod spawner;
79pub mod systems;
80#[cfg(test)]
81mod test_gpu;
82
83// === Motor Alt Sistemleri ===
84pub use gizmo_ai as ai;
85#[cfg(feature = "analysis")]
86pub use gizmo_analysis as analysis;
87pub use gizmo_app as app;
88pub use gizmo_core as core;
89pub use gizmo_math as math;
90/// Re-exports of the split physics crates under one `gizmo::physics` path.
91#[cfg(feature = "physics")]
92pub mod physics;
93#[cfg(feature = "render")]
94pub use gizmo_renderer as renderer;
95
96#[cfg(feature = "window")]
97pub use gizmo_window as window;
98
99// Sık kullanılan matematik tiplerini lib.rs'ten doğrudan aç:
100pub use math::{Mat4, Quat, Vec2, Vec3, Vec4};
101
102#[cfg(all(feature = "window", feature = "render", feature = "physics"))]
103pub mod simple;
104#[cfg(all(feature = "window", feature = "render", feature = "physics"))]
105pub use simple::*;
106
107// === Opsiyonel Modüller ===
108#[cfg(feature = "audio")]
109pub use gizmo_audio as audio;
110
111#[cfg(feature = "editor")]
112pub use gizmo_editor as editor;
113
114#[cfg(feature = "scripting")]
115pub use gizmo_scripting as scripting;
116
117#[cfg(feature = "scene")]
118pub use gizmo_scene as scene;
119// `pub use gizmo_scene::ron;` used to sit here. It went away with `gizmo-scene`'s own
120// re-export (2026-08-09): the RON parser is an implementation detail of the scene file
121// format, not API. What it was there for — turning a hand-written RON level string into a
122// scene — is `scene::SceneData::from_ron_str` / `to_ron_string` now. This facade is Stage B
123// and could have kept leaking the parser (docs/ENGINE.md §4), but only by taking a direct
124// dependency on it and pinning that pin in lock-step with `gizmo-scene`'s, where a drift
125// between the two would hand callers a parser type the `From` impls in `gizmo-scene` do not
126// accept.
127
128/// A [`scene::registry::SceneRegistry`] holding every component the enabled feature set
129/// can round-trip — not just the physics ones.
130///
131/// `gizmo-scene` deliberately depends on neither the renderer nor the scripting layer, so
132/// that scene save/load works in a GPU-free headless build. The cost is that
133/// [`scene::registry::default_scene_registry`] can only register what physics owns:
134/// transforms, bodies, colliders and the fighter components. Everything a scene visibly
135/// consists of — lights, cameras, audio emitters — lived outside its reach, so saving a
136/// scene from the editor and loading it back returned the physics and dropped the rest,
137/// silently.
138///
139/// This is the facade's job, because the facade is the layer that can see all of them. Use
140/// it wherever you would otherwise call `default_scene_registry`.
141///
142/// To round-trip your *own* components, register them on the result — anything that is
143/// `Component + Serialize + DeserializeOwned` qualifies:
144///
145/// ```no_run
146/// # use gizmo::scene::scene::SceneData;
147/// # #[derive(Clone, serde::Serialize, serde::Deserialize)]
148/// # struct Health(f32);
149/// # gizmo::core::impl_component!(Health);
150/// let mut registry = gizmo::full_scene_registry();
151/// registry
152/// .register_serializable::<Health>("Health")
153/// .expect("name must not collide with a built-in");
154/// // `registry` now round-trips Health alongside everything the engine registers.
155/// ```
156#[cfg(feature = "scene")]
157pub fn full_scene_registry() -> scene::registry::SceneRegistry {
158 app::scene_registry::full_scene_registry()
159}
160
161#[cfg(feature = "ui")]
162pub use gizmo_ui as ui;
163
164#[cfg(feature = "animation")]
165pub use gizmo_animation as animation;
166
167#[cfg(feature = "network")]
168pub use gizmo_net as net;
169
170// === 3. Parti Re-Export (Kullanıcının ayrıca eklemesine gerek kalmasın) ===
171pub use gizmo_core::gizmo_log;
172
173/// 1.0 contract: the external graphics/window types below (`wgpu`, `bytemuck`,
174/// `egui`, `winit`) are deliberately part of the public API. Their versions
175/// depend on the semver of the relevant renderer/window crate; a major version
176/// bump in these external crates counts as breaking for the facade too.
177#[cfg(feature = "render")]
178pub use bytemuck;
179
180/// 1.0 contract: this external graphics type is deliberately part of the public
181/// API; its version depends on the semver of the relevant UI crate. It is enabled
182/// with the `egui` feature (overlay UI / editor).
183#[cfg(feature = "egui")]
184pub use egui;
185
186/// 1.0 contract: this external graphics type is deliberately part of the public
187/// API; its version depends on the semver of the renderer crate.
188#[cfg(feature = "render")]
189pub use wgpu;
190
191/// 1.0 contract: this external window type is deliberately part of the public
192/// API; its version depends on the semver of the window crate.
193#[cfg(feature = "window")]
194pub use winit;