summaryrefslogtreecommitdiff
path: root/graphics/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/render.rs')
-rw-r--r--graphics/src/render.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 1164953..40b3e1f 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -1,23 +1,22 @@
use dungeon::{Dungeon, Entity};
use raylib::{
color::Color,
- prelude::{RaylibDraw, RaylibDrawHandle},
+ prelude::{RaylibDraw, RaylibDrawHandle, RaylibHandle},
};
-#[cfg(debug_assertions)]
-use raylib::RaylibHandle;
-
-/// Debug information used each frame
-#[cfg(debug_assertions)]
-pub struct DebugInfo {
+/// Information used each frame
+pub struct FrameInfo {
+ /// Time in seconds since last frame drawn
+ pub delta: f32,
+ /// FPS for last frame drawn
pub fps: u32,
}
-
-#[cfg(debug_assertions)]
-impl DebugInfo {
+impl FrameInfo {
pub fn new(handle: &RaylibHandle) -> Self {
- let fps = handle.get_fps();
- Self { fps }
+ Self {
+ delta: handle.get_frame_time(),
+ fps: handle.get_fps(),
+ }
}
}
@@ -25,20 +24,22 @@ impl DebugInfo {
/// frame of the game. It is created per frame.
pub struct Renderer<'a> {
handle: RaylibDrawHandle<'a>,
- #[cfg(debug_assertions)]
- debug: DebugInfo,
+ info: FrameInfo,
}
impl<'a> Renderer<'a> {
/// Creates the renderer for the current frame
- #[cfg(debug_assertions)]
- pub(crate) fn new(handle: RaylibDrawHandle<'a>, debug: DebugInfo) -> Self {
- Self { handle, debug }
+ pub(crate) fn new(handle: RaylibDrawHandle<'a>, info: FrameInfo) -> Self {
+ Self { handle, info }
}
- /// Creates the renderer for the current frame
- #[cfg(not(debug_assertions))]
- pub(crate) fn new(handle: RaylibDrawHandle<'a>) -> Self {
- Self { handle }
+ /// Returns the info struct for the current frame
+ pub fn info(&self) -> &FrameInfo {
+ &self.info
+ }
+
+ /// Returns the per frame delta time
+ pub fn delta_time(&self) -> f32 {
+ self.info.delta
}
/// Returns the current render width
@@ -65,9 +66,9 @@ impl<'a> Renderer<'a> {
self.draw_tiles(dungeon);
self.draw_player(dungeon);
- // Draw fps (debug mode only)
- #[cfg(debug_assertions)]
- self.draw_fps(self.debug.fps);
+ #[cfg(feature = "debug")]
+ // Draw fps (debug only)
+ self.draw_fps(self.info.fps);
}
/// Draw game over screen