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 entity;
71pub mod entity_builder;
72pub mod game;
73pub mod game_config;
74#[cfg(feature = "native")]
75pub mod input;
76#[cfg(feature = "native")]
77pub mod rendering;
78#[cfg(feature = "native")]
79pub mod rendering_3d;
80#[cfg(feature = "native")]
81pub mod texture;
82#[cfg(feature = "native")]
83pub mod window;
84
85// Re-export commonly used types for convenience
86pub use crate::core::error::{GoudError, GoudResult};
87pub use crate::core::math::{Color, Rect, Vec2, Vec3, Vec4};
88pub use crate::ecs::{Component, Entity, EntityAllocator, SparseSet, World};
89
90// Re-export SDK types from sub-modules so public API paths are preserved
91pub use entity_builder::EntityBuilder;
92pub use game::GoudGame;
93pub use game_config::{GameConfig, GameContext};
94
95// Re-export components module contents at sdk level for convenience
96// Note: We explicitly re-export to avoid shadowing issues
97pub use components::{
98 // Propagation
99 propagate_transforms,
100 propagate_transforms_2d,
101 // Audio
102 AttenuationModel,
103 AudioChannel,
104 AudioSource,
105 // Hierarchy
106 Children,
107 // Physics
108 Collider,
109 ColliderShape,
110 // Transforms
111 GlobalTransform,
112 GlobalTransform2D,
113 Mat3x3,
114 Name,
115 Parent,
116 RigidBody,
117 RigidBodyType,
118 // Rendering
119 Sprite,
120 Transform,
121 Transform2D,
122};
123
124// =============================================================================
125// Prelude - Convenient imports
126// =============================================================================
127
128/// Prelude module for convenient imports.
129///
130/// ```rust
131/// use goud_engine::sdk::prelude::*;
132/// ```
133pub mod prelude {
134 // Math types
135 pub use crate::core::math::{Color, Rect, Vec2, Vec3, Vec4};
136
137 // ECS core
138 pub use crate::ecs::{Component, Entity, World};
139
140 // SDK types
141 pub use super::{EntityBuilder, GameConfig, GameContext, GoudError, GoudGame, GoudResult};
142
143 // Components - explicitly list to avoid shadowing
144 pub use super::components::{
145 // Propagation
146 propagate_transforms,
147 propagate_transforms_2d,
148 // Audio
149 AttenuationModel,
150 AudioChannel,
151 AudioSource,
152 // Hierarchy
153 Children,
154 // Physics
155 Collider,
156 ColliderShape,
157 // Transforms
158 GlobalTransform,
159 GlobalTransform2D,
160 Mat3x3,
161 Name,
162 Parent,
163 RigidBody,
164 RigidBodyType,
165 // Rendering
166 Sprite,
167 Transform,
168 Transform2D,
169 };
170}