diff options
| -rw-r--r-- | game/Cargo.toml | 1 | ||||
| -rw-r--r-- | graphics/Cargo.toml | 5 | ||||
| -rw-r--r-- | graphics/src/render.rs | 29 |
3 files changed, 29 insertions, 6 deletions
diff --git a/game/Cargo.toml b/game/Cargo.toml index 7b5668e..009b8b4 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -19,3 +19,4 @@ workspace = true default = [] wayland = ["graphics/wayland"] sdl = ["graphics/sdl"] +static = ["graphics/static"] diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index e898b04..0fe31d0 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -16,8 +16,9 @@ workspace = true [features] default = [] -wayland = ["raylib/GLFW_BUILD_WAYLAND", "raylib/wayland"] -sdl = ["raylib/sdl"] +wayland = ["raylib/wayland", "raylib/GLFW_BUILD_WAYLAND"] +sdl = ["raylib/sdl", "raylib/SUPPORT_MODULE_RTEXT"] +static = [] # Individual features seem to currently be # broken on windows 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, |