Skip to main content

goud_engine/sdk/
mod.rs

1//! # Rust Native SDK for GoudEngine
2//!
3//! This module provides a high-level, ergonomic Rust API for game development.
4//! Unlike the FFI layer which is designed for cross-language bindings, this SDK
5//! is pure Rust with zero FFI overhead - ideal for Rust-native game development.
6//!
7//! ## Architecture Philosophy
8//!
9//! The SDK follows a "Rust-first" design principle:
10//!
11//! - **All game logic lives in Rust**: Components, systems, and game behavior
12//!   are implemented in Rust and exposed through this SDK
13//! - **Zero-overhead abstractions**: No FFI marshalling, no runtime type checks
14//! - **Type-safe**: Full Rust type safety with compile-time guarantees
15//! - **Ergonomic**: Builder patterns, fluent APIs, and sensible defaults
16//!
17//! ## Quick Start
18//!
19//! ```rust,ignore
20//! use goud_engine::sdk::{GoudGame, GameConfig};
21//! use goud_engine::sdk::components::{Transform2D, Sprite};
22//! use goud_engine::core::math::Vec2;
23//!
24//! fn main() {
25//!     // Create game instance
26//!     let mut game = GoudGame::new(GameConfig {
27//!         title: "My Game".to_string(),
28//!         width: 800,
29//!         height: 600,
30//!         ..Default::default()
31//!     }).expect("Failed to create game");
32//!
33//!     // Spawn entities with fluent builder API
34//!     let player = game.spawn()
35//!         .with(Transform2D::from_position(Vec2::new(100.0, 100.0)))
36//!         .with(Sprite::default())
37//!         .build();
38//!
39//!     // Run game loop
40//!     game.run(|ctx| {
41//!         // Update logic here
42//!         ctx.delta_time(); // Get frame delta
43//!         ctx.input();      // Access input state
44//!     });
45//! }
46//! ```
47//!
48//! ## Module Organization
49//!
50//! - [`components`]: Re-exports of all ECS components (Transform2D, Sprite, etc.)
51//! - [`GoudGame`]: High-level game abstraction managing world, window, and loop
52//! - [`EntityBuilder`]: Fluent builder for spawning entities with components
53//! - [`GameContext`]: Runtime context passed to update callbacks
54//!
55//! ## Comparison with FFI Layer
56//!
57//! | Feature | SDK (this module) | FFI Layer |
58//! |---------|-------------------|-----------|
59//! | Target | Rust games | C#/Python/etc |
60//! | Overhead | Zero | Marshalling cost |
61//! | Type Safety | Compile-time | Runtime checks |
62//! | API Style | Idiomatic Rust | C-compatible |
63
64pub mod collision;
65pub mod color;
66pub mod component_ops;
67pub mod components;
68pub mod components_sprite;
69pub mod components_transform2d;
70pub mod debug_overlay;
71pub mod engine_config;
72pub mod entity;
73pub mod entity_builder;
74pub mod game;
75pub mod game_config;
76#[cfg(feature = "native")]
77pub mod input;
78#[cfg(feature = "native")]
79pub mod rendering;
80#[cfg(feature = "native")]
81pub mod rendering_3d;
82pub mod scene;
83#[cfg(feature = "native")]
84pub mod texture;
85#[cfg(feature = "native")]
86pub mod window;
87
88// Re-export commonly used types for convenience
89pub use crate::core::error::{GoudError, GoudResult};
90pub use crate::core::math::{Color, Rect, Vec2, Vec3, Vec4};
91pub use crate::ecs::{Component, Entity, EntityAllocator, SparseSet, World};
92
93// Re-export SDK types from sub-modules so public API paths are preserved
94pub use engine_config::EngineConfig;
95pub use entity_builder::EntityBuilder;
96pub use game::GoudGame;
97pub use game_config::{GameConfig, GameContext};
98pub use scene::{SceneId, SceneManager};
99
100// Re-export components module contents at sdk level for convenience
101// Note: We explicitly re-export to avoid shadowing issues
102pub use components::{
103    // Propagation
104    propagate_transforms,
105    propagate_transforms_2d,
106    // Audio
107    AttenuationModel,
108    AudioChannel,
109    AudioSource,
110    // Hierarchy
111    Children,
112    // Physics
113    Collider,
114    ColliderShape,
115    // Transforms
116    GlobalTransform,
117    GlobalTransform2D,
118    Mat3x3,
119    Name,
120    Parent,
121    RigidBody,
122    RigidBodyType,
123    // Rendering
124    Sprite,
125    Transform,
126    Transform2D,
127};
128
129// =============================================================================
130// Prelude - Convenient imports
131// =============================================================================
132
133/// Prelude module for convenient imports.
134///
135/// ```rust
136/// use goud_engine::sdk::prelude::*;
137/// ```
138pub mod prelude {
139    // Math types
140    pub use crate::core::math::{Color, Rect, Vec2, Vec3, Vec4};
141
142    // ECS core
143    pub use crate::ecs::{Component, Entity, World};
144
145    // SDK types
146    pub use super::{
147        EngineConfig, EntityBuilder, GameConfig, GameContext, GoudError, GoudGame, GoudResult,
148        SceneId, SceneManager,
149    };
150
151    // Components - explicitly list to avoid shadowing
152    pub use super::components::{
153        // Propagation
154        propagate_transforms,
155        propagate_transforms_2d,
156        // Audio
157        AttenuationModel,
158        AudioChannel,
159        AudioSource,
160        // Hierarchy
161        Children,
162        // Physics
163        Collider,
164        ColliderShape,
165        // Transforms
166        GlobalTransform,
167        GlobalTransform2D,
168        Mat3x3,
169        Name,
170        Parent,
171        RigidBody,
172        RigidBodyType,
173        // Rendering
174        Sprite,
175        Transform,
176        Transform2D,
177    };
178}