summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-10 13:31:04 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-10 13:31:04 -0500
commitb50a79e6f9cd09973a406e5ccc50510aee3423f2 (patch)
tree67d7dd951cc5680f6e2526f48bef7b1bde5db1c3
parentupdate raylib to 5.6-dev (diff)
downloadDungeonCrawl-b50a79e6f9cd09973a406e5ccc50510aee3423f2.tar.gz
DungeonCrawl-b50a79e6f9cd09973a406e5ccc50510aee3423f2.tar.bz2
DungeonCrawl-b50a79e6f9cd09973a406e5ccc50510aee3423f2.zip
graphics: have some window arguments passed in through cmd args, fix camera pos
-rw-r--r--Cargo.lock195
-rw-r--r--Cargo.toml2
-rw-r--r--game/Cargo.toml1
-rw-r--r--game/src/main.rs18
-rw-r--r--graphics/src/lib.rs139
-rw-r--r--graphics/src/render.rs4
6 files changed, 307 insertions, 52 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c1395d5..df90b5b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12,6 +12,56 @@ dependencies = [
]
[[package]]
+name = "anstream"
+version = "0.6.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
+
+[[package]]
+name = "anstyle-parse"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
+dependencies = [
+ "anstyle",
+ "once_cell_polyfill",
+ "windows-sys",
+]
+
+[[package]]
name = "bindgen"
version = "0.71.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -76,6 +126,46 @@ dependencies = [
]
[[package]]
+name = "clap"
+version = "4.5.51"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.5.51"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.5.49"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
+
+[[package]]
name = "cmake"
version = "0.1.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -85,6 +175,12 @@ dependencies = [
]
[[package]]
+name = "colorchoice"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
+
+[[package]]
name = "dungeon"
version = "0.1.0"
dependencies = [
@@ -109,6 +205,7 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
name = "game"
version = "0.1.0"
dependencies = [
+ "clap",
"dungeon",
"graphics",
]
@@ -155,6 +252,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+
+[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -224,6 +327,12 @@ dependencies = [
]
[[package]]
+name = "once_cell_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+
+[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -372,6 +481,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
+name = "strsim"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
+[[package]]
name = "strum"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -427,6 +542,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
+name = "utf8parse"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+
+[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -442,6 +563,80 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
+name = "windows-sys"
+version = "0.60.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.53.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
+dependencies = [
+ "windows-link",
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+
+[[package]]
name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index af86efa..d554afc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,6 +16,7 @@ publish = false
rust-version = "1.87"
[workspace.dependencies]
+clap = { version = "4", features = ["derive"] }
dungeon = { path = "dungeon" }
game = { path = "game" }
graphics = { path = "graphics" }
@@ -37,6 +38,7 @@ features = [
"SUPPORT_CAMERA_SYSTEM",
"SUPPORT_FILEFORMAT_BMP",
"SUPPORT_STANDARD_FILEIO",
+ "SUPPORT_TRACELOG",
]
[workspace.lints.clippy]
diff --git a/game/Cargo.toml b/game/Cargo.toml
index 2792e83..b42d1c1 100644
--- a/game/Cargo.toml
+++ b/game/Cargo.toml
@@ -8,6 +8,7 @@ publish.workspace = true
rust-version.workspace = true
[dependencies]
+clap.workspace = true
dungeon.workspace = true
graphics.workspace = true
diff --git a/game/src/main.rs b/game/src/main.rs
index 5c9e8c7..d96273e 100644
--- a/game/src/main.rs
+++ b/game/src/main.rs
@@ -1,9 +1,25 @@
+use clap::Parser;
use dungeon::*;
use graphics::*;
+#[derive(Parser)]
+struct Args {
+ /// Enable vsync
+ #[arg(long)]
+ vsync: bool,
+ // Enable verbose logging
+ #[arg(short, long)]
+ verbose: bool,
+}
+
fn main() -> Result<()> {
+ // Parse arguments
+ let args = Args::parse();
// Load the window
- let mut window = Window::new_default()?;
+ let mut window = WindowBuilder::new()
+ .vsync(args.vsync)
+ .verbose(args.verbose)
+ .build()?;
// Initial game state
let mut dungeon = Dungeon::new();
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 27e49d3..811494c 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -1,6 +1,7 @@
//! The `graphics` crate contains the core functionality for
//! rendering using the `raylib` library.
+use std::borrow::Cow;
use std::cell::RefCell;
use dungeon::Dungeon;
@@ -21,37 +22,75 @@ pub type Error = Box<dyn std::error::Error>;
/// The `Result` type used witin this crate
pub type Result<T> = std::result::Result<T, crate::Error>;
-/// The `Window` type represents the game window
+/// The `WindowBuilder` type allows setting partial options for the window
#[derive(Debug)]
-pub struct Window {
- // persistant renderer
- renderer: Renderer,
- // core raylib handles
- handle: RefCell<RaylibHandle>,
- thread: RaylibThread,
- // audio data/subsystem
- audio: Audio,
+pub struct WindowBuilder<'a> {
+ title: Cow<'a, str>,
+ width: u16,
+ height: u16,
+ vsync: bool,
+ verbose: bool,
}
-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").unwrap();
- /// ```
- pub fn new(width: u16, height: u16, title: &str) -> crate::Result<Self> {
- let (mut handle, thread) = raylib::init()
- .size(width.into(), height.into())
- .title(title)
- .resizable()
- .log_level(TraceLogLevel::LOG_WARNING)
- .build();
+impl<'a> WindowBuilder<'a> {
+ /// Default window builder
+ pub fn new() -> Self {
+ Self::default()
+ }
+
+ /// Set the window title
+ pub fn title(&mut self, title: impl Into<Cow<'a, str>>) -> &mut Self {
+ self.title = title.into();
+ self
+ }
+
+ /// Set the default window width
+ pub fn width(&mut self, width: u16) -> &mut Self {
+ self.width = width;
+ self
+ }
+
+ /// Set the default window height
+ pub fn height(&mut self, height: u16) -> &mut Self {
+ self.height = height;
+ self
+ }
+
+ /// Toggle vsync support
+ pub fn vsync(&mut self, vsync: bool) -> &mut Self {
+ self.vsync = vsync;
+ self
+ }
+
+ /// Toggle verbose logging
+ pub fn verbose(&mut self, verbose: bool) -> &mut Self {
+ self.verbose = verbose;
+ self
+ }
+
+ /// Build the window
+ pub fn build(&self) -> crate::Result<Window> {
+ let mut builder = raylib::init();
+
+ // Set raylib args from builder
+ builder.size(self.width.into(), self.height.into());
+ builder.title(&self.title);
+ builder.resizable();
+ if self.vsync {
+ builder.vsync();
+ }
+ if self.verbose {
+ builder.log_level(TraceLogLevel::LOG_INFO);
+ } else {
+ builder.log_level(TraceLogLevel::LOG_WARNING);
+ }
+
+ let (mut handle, thread) = builder.build();
+ if !handle.is_window_ready() {
+ return Err("Raylib window not ready!".into());
+ }
// update window min size
- handle.set_window_min_size(width.into(), height.into());
+ handle.set_window_min_size(self.width.into(), self.height.into());
// load audio
let audio = Audio::load()?;
@@ -59,26 +98,38 @@ impl Window {
// load renderer
let renderer = Renderer::new(&mut handle, &thread)?;
- Ok(Self {
+ Ok(Window {
handle: RefCell::new(handle),
thread,
renderer,
audio,
})
}
-
- /// Instantiates a new window with a default tile and size
- ///
- /// # Examples
- /// ```no_run
- /// use graphics::Window;
- ///
- /// let window = Window::new_default().unwrap();
- /// ```
- pub fn new_default() -> crate::Result<Self> {
- Self::new(render::RENDER_WIDTH, render::RENDER_HEIGHT, "Dungeon Crawl")
+}
+impl Default for WindowBuilder<'_> {
+ fn default() -> Self {
+ Self {
+ title: Cow::Borrowed("Dungeon Crawl"),
+ width: render::RENDER_WIDTH,
+ height: render::RENDER_HEIGHT,
+ vsync: false,
+ verbose: false,
+ }
}
+}
+/// The `Window` type represents the game window
+#[derive(Debug)]
+pub struct Window {
+ // persistant renderer
+ renderer: Renderer,
+ // core raylib handles
+ handle: RefCell<RaylibHandle>,
+ thread: RaylibThread,
+ // audio data/subsystem
+ audio: Audio,
+}
+impl Window {
/// Returns if the window should be closed.
/// This usually means the 'x' button has been pressed.
pub fn is_open(&self) -> bool {
@@ -86,16 +137,6 @@ impl Window {
}
/// Draws the next ingame frame
- ///
- /// # Examples
- /// ```no_run
- /// use graphics::Window;
- /// use dungeon::Dungeon;
- ///
- /// let dungeon = Dungeon::new();
- /// let mut window = Window::new(800, 600, "Dungeon Crawl").unwrap();
- /// window.draw_frame(&dungeon);
- /// ```
pub fn draw_frame(&mut self, dungeon: &Dungeon) {
self.renderer
.draw_frame(self.handle.get_mut(), &self.thread, dungeon);
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 1061af3..945528b 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -736,8 +736,8 @@ impl DungeonExt for Dungeon {
};
/// The maximum position the camera is allowed to go
const CAMERA_MAX: Vector2 = vec2! {
- MAP_SIZE * TILE_SIZE - RENDER_WIDTH/2,
- MAP_SIZE * TILE_SIZE - RENDER_HEIGHT/2 - UI_HEIGHT/2,
+ MAP_SIZE * TILE_SIZE - RENDER_WIDTH/2 - TILE_SIZE/2,
+ MAP_SIZE * TILE_SIZE - RENDER_HEIGHT/2 - TILE_SIZE/2,
};
let pos = self.camera();