Skip to main content

GoudGame

Struct GoudGame 

Source
pub struct GoudGame { /* private fields */ }
Expand description

The main game instance managing the ECS world and game loop.

§Example

use goud_engine::sdk::{GoudGame, GameConfig};
use goud_engine::sdk::components::Transform2D;
use goud_engine::core::math::Vec2;

let mut game = GoudGame::new(GameConfig::default()).unwrap();
let player = game.spawn()
    .with(Transform2D::from_position(Vec2::new(400.0, 300.0)))
    .build();

Implementations§

Source§

impl GoudGame

Source

pub fn ffi_entity_spawn_empty(&mut self) -> u64

Spawns a new empty entity with no components.

Returns the entity as a u64 bit representation for FFI compatibility.

Source

pub unsafe fn ffi_entity_spawn_batch( &mut self, count: u32, out_entities: *mut u64, ) -> u32

Spawns multiple empty entities in a batch and writes their IDs to the provided output buffer.

Returns the number of entities spawned.

§Safety

out_entities must point to valid memory with capacity for at least count u64 values.

Source

pub fn ffi_entity_despawn(&mut self, entity_id: u64) -> bool

Despawns an entity and all its components from the world.

Returns true if the entity was despawned, false otherwise.

Source

pub unsafe fn ffi_entity_despawn_batch( &mut self, entity_ids: *const u64, count: u32, ) -> u32

Despawns multiple entities in a batch.

Returns the number of entities successfully despawned.

§Safety

entity_ids must point to valid memory with at least count u64 values.

Source

pub fn ffi_entity_is_alive(&self, entity_id: u64) -> bool

Checks if an entity is currently alive in the world.

Source

pub fn ffi_entity_count(&self) -> u32

Returns the total number of alive entities in the world.

Source

pub unsafe fn ffi_entity_is_alive_batch( &self, entity_ids: *const u64, count: u32, out_results: *mut u8, ) -> u32

Checks if multiple entities are alive in the world.

Results are written to out_results where 1 = alive, 0 = dead. Returns the number of results written.

§Safety
  • entity_ids must point to valid memory with at least count u64 values.
  • out_results must point to valid memory with at least count u8 values.
Source§

impl GoudGame

Source

pub fn new(config: GameConfig) -> Result<GoudGame, GoudError>

Creates a new game instance with the given configuration.

This creates a headless game instance suitable for testing and non-graphical use. For a windowed game with rendering, use with_platform instead.

Source

pub fn default_game() -> Result<GoudGame, GoudError>

Creates a game with default configuration.

Source

pub fn with_platform(config: GameConfig) -> Result<GoudGame, GoudError>

Creates a windowed game instance with a GLFW platform backend.

This initializes a GLFW window with an OpenGL 3.3 Core context, sets up the sprite batch renderer, and prepares the asset server.

§Errors

Returns an error if GLFW initialization or window creation fails.

Source

pub fn world(&self) -> &World

Returns a reference to the default scene’s ECS world.

Source

pub fn world_mut(&mut self) -> &mut World

Returns a mutable reference to the default scene’s ECS world.

Source

pub fn spawn(&mut self) -> EntityBuilder<'_>

Creates an entity builder for fluent entity creation (default scene).

Source

pub fn spawn_empty(&mut self) -> Entity

Spawns an empty entity with no components (default scene).

Source

pub fn spawn_batch(&mut self, count: usize) -> Vec<Entity>

Spawns multiple empty entities at once (default scene).

Source

pub fn despawn(&mut self, entity: Entity) -> bool

Despawns an entity and removes all its components (default scene).

Source

pub fn get<T>(&self, entity: Entity) -> Option<&T>
where T: Component,

Gets a reference to a component on an entity (default scene).

Source

pub fn get_mut<T>(&mut self, entity: Entity) -> Option<&mut T>
where T: Component,

Gets a mutable reference to a component on an entity (default scene).

Source

pub fn insert<T>(&mut self, entity: Entity, component: T)
where T: Component,

Adds or replaces a component on an entity (default scene).

Source

pub fn remove<T>(&mut self, entity: Entity) -> Option<T>
where T: Component,

Removes a component from an entity (default scene).

Source

pub fn has<T>(&self, entity: Entity) -> bool
where T: Component,

Checks if an entity has a specific component (default scene).

Source

pub fn entity_count(&self) -> usize

Returns the number of entities in the default scene.

Source

pub fn is_alive(&self, entity: Entity) -> bool

Checks if an entity is alive (default scene).

Source

pub fn create_scene(&mut self, name: &str) -> Result<u32, GoudError>

Creates a new scene with the given name.

Source

pub fn destroy_scene(&mut self, id: u32) -> Result<(), GoudError>

Destroys a scene. Cannot destroy the default scene.

Source

pub fn scene(&self, id: u32) -> Option<&World>

Returns a reference to a scene’s world.

Source

pub fn scene_mut(&mut self, id: u32) -> Option<&mut World>

Returns a mutable reference to a scene’s world.

Source

pub fn scene_by_name(&self, name: &str) -> Option<u32>

Looks up a scene by name.

Source

pub fn set_scene_active( &mut self, id: u32, active: bool, ) -> Result<(), GoudError>

Sets whether a scene is active.

Source

pub fn scene_manager(&self) -> &SceneManager

Returns a reference to the scene manager.

Source

pub fn scene_manager_mut(&mut self) -> &mut SceneManager

Returns a mutable reference to the scene manager.

Source

pub fn config(&self) -> &GameConfig

Returns the game configuration.

Source

pub fn title(&self) -> &str

Returns the window title.

Source

pub fn window_size(&self) -> (u32, u32)

Returns the window dimensions.

Source

pub fn run<F>(&mut self, update: F)
where F: FnMut(&mut GameContext, &mut World),

Runs the game loop with the given update callback.

The callback receives the default scene’s world for backward compatibility. Use scene_manager_mut inside the callback for multi-scene access.

Source

pub fn update_frame<F>(&mut self, delta_time: f32, update: F)
where F: FnMut(&mut GameContext, &mut World),

Runs a single frame update for all active scenes.

Source

pub fn fps_stats(&self) -> FpsStats

Returns the current FPS statistics from the debug overlay.

Source

pub fn set_fps_overlay_enabled(&mut self, enabled: bool)

Enables or disables the FPS stats overlay.

Source

pub fn frame_count(&self) -> u64

Returns the current frame count.

Source

pub fn total_time(&self) -> f32

Returns the total time elapsed since game start.

Source

pub fn fps(&self) -> f32

Returns the current FPS.

Source

pub fn is_initialized(&self) -> bool

Returns true if the game has been initialized.

Source

pub fn from_engine_config(config: EngineConfig) -> Result<GoudGame, GoudError>

Creates a headless game from an EngineConfig builder.

Source

pub fn from_engine_config_with_platform( config: EngineConfig, ) -> Result<GoudGame, GoudError>

Creates a windowed game from an EngineConfig builder.

Source

pub fn providers(&self) -> &ProviderRegistry

Returns a reference to the provider registry.

Source§

impl GoudGame

Source

pub fn is_key_pressed(&self, key: Key) -> bool

Returns true if the given key is currently held down.

§Example
if game.is_key_pressed(Key::W) {
    // Move forward continuously while held
}
Source

pub fn is_key_just_pressed(&self, key: Key) -> bool

Returns true if the given key was pressed this frame (not held from previous frame).

Use this for one-shot actions like jumping or menu selection.

Source

pub fn is_key_just_released(&self, key: Key) -> bool

Returns true if the given key was released this frame.

Source

pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool

Returns true if the given mouse button is currently held down.

Source

pub fn is_mouse_button_just_pressed(&self, button: MouseButton) -> bool

Returns true if the given mouse button was pressed this frame.

Source

pub fn is_mouse_button_just_released(&self, button: MouseButton) -> bool

Returns true if the given mouse button was released this frame.

Source

pub fn mouse_position(&self) -> (f32, f32)

Returns the current mouse position in window coordinates.

Returns (x, y) where (0, 0) is the top-left corner.

Source

pub fn mouse_delta(&self) -> (f32, f32)

Returns the mouse movement delta since the last frame.

Returns (dx, dy) where positive X is right and positive Y is down.

Source

pub fn scroll_delta(&self) -> (f32, f32)

Returns the scroll wheel delta since the last frame.

Returns (horizontal, vertical) scroll amounts.

Source

pub fn map_action_key(&mut self, action: &str, key: Key)

Maps a key to a named action.

An action can have multiple key bindings. When any bound key is pressed, the action is considered active.

§Example
game.map_action_key("Jump", Key::Space);
game.map_action_key("Jump", Key::W);

if game.is_action_pressed("Jump") {
    // Triggered by Space OR W
}
Source

pub fn map_action_mouse_button(&mut self, action: &str, button: MouseButton)

Maps a mouse button to a named action.

Source

pub fn is_action_pressed(&self, action: &str) -> bool

Returns true if any binding for the named action is currently held.

Source

pub fn is_action_just_pressed(&self, action: &str) -> bool

Returns true if any binding for the named action was pressed this frame.

Source

pub fn is_action_just_released(&self, action: &str) -> bool

Returns true if any binding for the named action was released this frame.

Source

pub fn input(&self) -> &InputManager

Returns a reference to the underlying InputManager.

Use this for advanced input queries (gamepad, input buffering, etc.) that are not exposed through convenience methods.

Source

pub fn input_mut(&mut self) -> &mut InputManager

Returns a mutable reference to the underlying InputManager.

Use this for advanced configuration (deadzone, buffer duration, etc.).

Source§

impl GoudGame

Source

pub fn begin_2d_render(&mut self) -> Result<(), GoudError>

Begins a 2D rendering pass.

Call this before drawing sprites. Must be paired with end_2d_render.

Source

pub fn end_2d_render(&mut self) -> Result<(), GoudError>

Ends the 2D rendering pass and submits batched draw calls to the GPU.

Source

pub fn draw_sprites(&mut self) -> Result<(), GoudError>

Draws all entities with Sprite + Transform2D components.

Source

pub fn render_2d_stats(&self) -> (usize, usize, f32)

Returns 2D rendering statistics: (sprite_count, batch_count, batch_ratio).

Source

pub fn has_2d_renderer(&self) -> bool

Returns true if a 2D renderer (SpriteBatch) is initialized.

Source§

impl GoudGame

Source

pub fn begin_render(&mut self) -> bool

Begins a new rendering frame. Call before any drawing operations.

Source

pub fn end_render(&mut self) -> bool

Ends the current rendering frame.

Source

pub fn set_viewport(&mut self, x: i32, y: i32, width: u32, height: u32)

Sets the viewport rectangle for rendering.

Source

pub fn enable_blending(&mut self)

Enables alpha blending for transparent sprites.

Source

pub fn disable_blending(&mut self)

Disables alpha blending.

Source

pub fn enable_depth_test(&mut self)

Enables depth testing.

Source

pub fn disable_depth_test(&mut self)

Disables depth testing.

Source

pub fn clear_depth(&mut self)

Clears the depth buffer.

Source

pub fn draw_sprite( &mut self, texture: u64, x: f32, y: f32, width: f32, height: f32, rotation: f32, r: f32, g: f32, b: f32, a: f32, ) -> bool

Draws a textured sprite at the given position (immediate mode).

Source

pub fn draw_sprite_rect( &mut self, texture: u64, x: f32, y: f32, width: f32, height: f32, rotation: f32, src_x: f32, src_y: f32, src_w: f32, src_h: f32, r: f32, g: f32, b: f32, a: f32, ) -> bool

Draws a textured sprite with a source rectangle for sprite sheet animation.

Source

pub fn draw_quad( &mut self, x: f32, y: f32, width: f32, height: f32, r: f32, g: f32, b: f32, a: f32, ) -> bool

Draws a colored quad (no texture) at the given position.

Source

pub unsafe fn get_render_stats(&self, out_stats: *mut GoudRenderStats) -> bool

Gets rendering statistics for the current frame.

Writes default statistics to the provided out-pointer. Returns true on success, false if the pointer is null.

§Safety

out_stats must be a valid, aligned, writable pointer to a GoudRenderStats value, or null (in which case this returns false).

Source§

impl GoudGame

Source

pub fn create_primitive(&mut self, info: PrimitiveCreateInfo) -> u32

Creates a 3D primitive and returns its object ID.

Source

pub fn create_cube( &mut self, texture_id: u32, width: f32, height: f32, depth: f32, ) -> u32

Creates a 3D cube and returns its object ID.

Source

pub fn create_plane(&mut self, texture_id: u32, width: f32, depth: f32) -> u32

Creates a 3D plane and returns its object ID.

Source

pub fn create_sphere( &mut self, texture_id: u32, diameter: f32, segments: u32, ) -> u32

Creates a 3D sphere and returns its object ID.

Source

pub fn create_cylinder( &mut self, texture_id: u32, radius: f32, height: f32, segments: u32, ) -> u32

Creates a 3D cylinder and returns its object ID.

Source

pub fn set_object_position(&mut self, id: u32, x: f32, y: f32, z: f32) -> bool

Sets the position of a 3D object.

Source

pub fn set_object_rotation(&mut self, id: u32, x: f32, y: f32, z: f32) -> bool

Sets the rotation of a 3D object (Euler angles in degrees).

Source

pub fn set_object_scale(&mut self, id: u32, x: f32, y: f32, z: f32) -> bool

Sets the scale of a 3D object.

Source

pub fn destroy_object(&mut self, object_id: u32) -> bool

Removes a 3D object from the scene.

Source

pub fn add_light( &mut self, light_type: i32, pos_x: f32, pos_y: f32, pos_z: f32, dir_x: f32, dir_y: f32, dir_z: f32, r: f32, g: f32, b: f32, intensity: f32, range: f32, spot_angle: f32, ) -> u32

Adds a light to the 3D scene with flattened parameters.

Source

pub fn update_light( &mut self, light_id: u32, light_type: i32, pos_x: f32, pos_y: f32, pos_z: f32, dir_x: f32, dir_y: f32, dir_z: f32, r: f32, g: f32, b: f32, intensity: f32, range: f32, spot_angle: f32, ) -> bool

Updates a light’s properties.

Source

pub fn remove_light(&mut self, light_id: u32) -> bool

Removes a light from the 3D scene.

Source

pub fn set_camera_position(&mut self, x: f32, y: f32, z: f32) -> bool

Sets the 3D camera position.

Source

pub fn set_camera_rotation(&mut self, pitch: f32, yaw: f32, roll: f32) -> bool

Sets the 3D camera rotation (pitch, yaw, roll in degrees).

Source

pub fn configure_grid( &mut self, enabled: bool, size: f32, divisions: u32, ) -> bool

Configures the ground grid.

Source

pub fn set_grid_enabled(&mut self, enabled: bool) -> bool

Sets grid enabled state.

Source

pub fn configure_skybox( &mut self, enabled: bool, r: f32, g: f32, b: f32, a: f32, ) -> bool

Configures the skybox/background color.

Source

pub fn configure_fog( &mut self, enabled: bool, r: f32, g: f32, b: f32, density: f32, ) -> bool

Configures fog settings.

Source

pub fn set_fog_enabled(&mut self, enabled: bool) -> bool

Sets fog enabled state.

Source

pub fn render(&mut self) -> bool

Renders all 3D objects in the scene.

Source

pub fn render_all(&mut self) -> bool

Renders all 3D objects (alias for render).

Source

pub fn has_3d_renderer(&self) -> bool

Returns true if a 3D renderer is initialized.

Source§

impl GoudGame

Source

pub fn load(&mut self, path: &str) -> u64

Loads a texture from an image file and returns a packed u64 handle.

Returns u64::MAX on error.

Source

pub fn destroy(&mut self, texture: u64) -> bool

Destroys a texture and releases its GPU resources.

Source§

impl GoudGame

Source

pub fn should_close(&self) -> bool

Returns true if the window has been requested to close.

This checks whether the user clicked the close button, pressed Alt+F4, or called set_should_close.

Returns false if no platform backend is initialized (headless mode).

Source

pub fn set_should_close(&mut self, should_close: bool) -> Result<(), GoudError>

Signals the window to close (or not) after the current frame.

§Errors

Returns an error if no platform backend is initialized.

Source

pub fn poll_events(&mut self) -> Result<f32, GoudError>

Polls platform events and advances input state for the new frame.

This processes all pending window/input events, syncs the OpenGL viewport on window resize, and returns the delta time (seconds since last call). Must be called once per frame before querying input.

§Errors

Returns an error if no platform backend is initialized.

Source

pub fn swap_buffers(&mut self) -> Result<(), GoudError>

Presents the rendered frame by swapping front and back buffers.

Call this at the end of each frame after all rendering is complete.

§Errors

Returns an error if no platform backend is initialized.

Source

pub fn clear(&mut self, r: f32, g: f32, b: f32, a: f32)

Clears the window with the specified color.

Sets the clear color and clears the color buffer using the render backend.

Source

pub fn get_window_size(&self) -> (u32, u32)

Returns the physical window size (width, height) in pixels.

If no platform backend is initialized, returns the configured size from GameConfig.

Source

pub fn has_platform(&self) -> bool

Returns true if a platform backend is initialized.

When false, window/rendering methods will return errors or fall back to headless behavior.

Source

pub fn get_delta_time(&self) -> f32

Returns the delta time (seconds since last poll_events call).

This reads from the internal GameContext which is updated by poll_events. Returns 0.0 before the first poll.

Source

pub fn get_framebuffer_size(&self) -> (u32, u32)

Returns the physical framebuffer size (width, height) in pixels.

On HiDPI/Retina displays, this may differ from the logical window size returned by get_window_size. Renderers should use this for gl::Viewport.

If no platform backend is initialized, returns the configured size.

Trait Implementations§

Source§

impl Debug for GoudGame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for GoudGame

Source§

fn default() -> GoudGame

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,