diff options
| author | alf9310 <alf9310@rit.edu> | 2025-10-17 14:34:19 -0400 |
|---|---|---|
| committer | alf9310 <alf9310@rit.edu> | 2025-10-17 14:34:19 -0400 |
| commit | a4538b90420f159b4449c80739fb208ec1c01d70 (patch) | |
| tree | 65275ee11f2cf109c73647dd8e57c8d15a4b9e1c /graphics | |
| parent | Game name (diff) | |
| download | DungeonCrawl-a4538b90420f159b4449c80739fb208ec1c01d70.tar.gz DungeonCrawl-a4538b90420f159b4449c80739fb208ec1c01d70.tar.bz2 DungeonCrawl-a4538b90420f159b4449c80739fb208ec1c01d70.zip | |
Added render documentation
Diffstat (limited to 'graphics')
| -rw-r--r-- | graphics/src/lib.rs | 20 | ||||
| -rw-r--r-- | graphics/src/render.rs | 19 |
2 files changed, 38 insertions, 1 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 5f44e41..4f55388 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -1,9 +1,14 @@ +//! The `graphics` crate contains the core functionality for +//! rendering using the `raylib` library. + use raylib::prelude::*; use crate::render::{FrameInfo, Renderer}; pub mod render; +/// The `Window` type represents the game window +#[derive(Debug)] pub struct Window { handle: RaylibHandle, thread: RaylibThread, @@ -12,6 +17,13 @@ pub struct Window { impl Window { /// Instantiates a new window provided with the default /// window `width`, `height`, and `title`. + /// + /// # Examples + /// ```no_run + /// use graphics::Window; + /// + /// let window = Window::new(800, 600, "Dungeon Crawl"); + /// ``` pub fn new(width: i32, height: i32, title: &str) -> Self { let (handle, thread) = raylib::init() .size(width, height) @@ -30,6 +42,14 @@ impl Window { } /// Returns the renderer for the game + /// + /// # Examples + /// ```no_run + /// use graphics::Window; + /// + /// let mut window = Window::new(800, 600, "Dungeon Crawl"); + /// let mut renderer = window.renderer(); + /// ``` pub fn renderer(&mut self) -> Renderer<'_> { let info = FrameInfo::new(&self.handle); let handle = self.handle.begin_drawing(&self.thread); diff --git a/graphics/src/render.rs b/graphics/src/render.rs index add19ab..68a7b68 100644 --- a/graphics/src/render.rs +++ b/graphics/src/render.rs @@ -1,10 +1,15 @@ +//! The `render` module contains the structures for displaying +//! the game, with each frame represented by a `Renderer` and +//! frame specific information in `FrameInfo`. + use dungeon::{Dungeon, Entity}; use raylib::{ color::Color, prelude::{RaylibDraw, RaylibDrawHandle, RaylibHandle}, }; -/// Information used each frame +/// The `FrameInfo` struct contains information about +/// the current frame being rendered. pub struct FrameInfo { /// Time in seconds since last frame drawn pub delta: f32, @@ -12,6 +17,8 @@ pub struct FrameInfo { pub fps: u32, } impl FrameInfo { + /// Creates a new `FrameInfo` from the provided + /// `RaylibHandle`. pub fn new(handle: &RaylibHandle) -> Self { Self { delta: handle.get_frame_time(), @@ -58,6 +65,16 @@ impl<'a> Renderer<'a> { } /// Draws an entire frame + /// + /// # Examples + /// ```no_run + /// use dungeon::Dungeon; + /// use graphics::Window; + /// let mut window = Window::new(800, 600, "Dungeon Crawl"); + /// let mut renderer = window.renderer(); + /// let dungeon = Dungeon::new(); + /// renderer.draw_frame(&dungeon); + /// ``` pub fn draw_frame(&mut self, dungeon: &Dungeon) { // Clear the background to black self.clear(); |