summaryrefslogtreecommitdiff
path: root/graphics/src/render.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-10 23:27:40 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-10 23:27:40 -0500
commit0fb57c082c1362196e2abd09e9c37fdc818edd7c (patch)
tree530c97107f6ae2679833be9ed6a36b2ecf348458 /graphics/src/render.rs
parentuse fmt fns directly when possible (diff)
downloadDungeonCrawl-0fb57c082c1362196e2abd09e9c37fdc818edd7c.tar.gz
DungeonCrawl-0fb57c082c1362196e2abd09e9c37fdc818edd7c.tar.bz2
DungeonCrawl-0fb57c082c1362196e2abd09e9c37fdc818edd7c.zip
graphics: add feature to include assets statically in the binary
Diffstat (limited to '')
-rw-r--r--graphics/src/render.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 945528b..bbfa2b9 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -46,6 +46,27 @@ macro_rules! draw_text {
}};
}
+#[cfg(not(feature = "static"))]
+macro_rules! load_texture {
+ ($handle:expr, $thread:expr, $filepath:expr) => (
+ $handle.load_texture($thread, $filepath)?
+ )
+}
+
+#[cfg(feature = "static")]
+macro_rules! load_texture {
+ ($handle:expr, $thread:expr, $filepath:expr) => (
+ {
+ let bytes = include_bytes!(concat!("../../", $filepath));
+ let len = $filepath.len();
+ let ext = &$filepath[len-4..];
+ let image = ::raylib::texture::Image::load_image_from_mem(ext, bytes)?;
+ $handle.load_texture_from_image($thread, &image)?
+ }
+
+ )
+}
+
/// The baseline size of all ingame sprites and tile textures
const TEXTURE_SIZE: u16 = 16;
@@ -121,10 +142,10 @@ struct Textures {
}
impl Textures {
fn new(handle: &mut RaylibHandle, thread: &RaylibThread) -> crate::Result<Self> {
- let atlas = handle.load_texture(thread, "assets/atlas.bmp")?;
- let player = handle.load_texture(thread, "assets/player.bmp")?;
- let error = handle.load_texture(thread, "assets/error.bmp")?;
- let font = handle.load_texture(thread, "assets/font.bmp")?;
+ let atlas = load_texture!(handle, thread, "assets/atlas.bmp");
+ let player = load_texture!(handle, thread, "assets/player.bmp");
+ let error = load_texture!(handle, thread, "assets/error.bmp");
+ let font = load_texture!(handle, thread, "assets/font.bmp");
Ok(Self {
atlas,