From 9454e41c53bb72548ca3b375a7fb05bb24173aea Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Sun, 16 Jun 2024 22:36:02 +0530 Subject: [PATCH] feat: Removed useless deps --- Cargo.lock | 31 ++++++-------------------- Cargo.toml | 4 +--- flake.nix | 63 ++++++++++++++++++++++++++++++++++++++++++++--------- src/main.rs | 23 +++++++++++-------- 4 files changed, 75 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92a6419..642082c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,21 +20,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "audio" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2d8fdbcbaf6b6967eefcbf476d7ded6d3bd29ddfa5b141e39e25d3cd531a14f" -dependencies = [ - "audio-core", -] - -[[package]] -name = "audio-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db446410e749ce0157f460ef73d97f002251808aa6b6ca69f476578f36e958e0" - [[package]] name = "autocfg" version = "1.3.0" @@ -143,15 +128,6 @@ dependencies = [ "png", ] -[[package]] -name = "lib" -version = "0.1.0" -dependencies = [ - "audio", - "macroquad", - "once_cell", -] - [[package]] name = "libc" version = "0.2.155" @@ -304,6 +280,13 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tadventure" +version = "0.1.0" +dependencies = [ + "macroquad", +] + [[package]] name = "ttf-parser" version = "0.15.2" diff --git a/Cargo.toml b/Cargo.toml index 9b76845..a456968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,9 @@ [package] -name = "lib" +name = "tadventure" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -audio = "0.2.0" macroquad = "0.4.8" -once_cell = "1.19.0" diff --git a/flake.nix b/flake.nix index 0057def..c7ac513 100644 --- a/flake.nix +++ b/flake.nix @@ -34,19 +34,26 @@ stableToolchainWithRustAnalyzer = pkgs.rust-bin.stable.latest.default.override { extensions = ["rust-src" "rust-analyzer"]; # Extra targets if required - # targets = [ - # "x86_64-unknown-linux-gnu" - # "x86_64-unknown-linux-musl" - # "x86_64-apple-darwin" - # "aarch64-apple-darwin" - # ]; + targets = [ + "wasm32-unknown-unknown" + # "x86_64-unknown-linux-gnu" + # "x86_64-unknown-linux-musl" + # "x86_64-apple-darwin" + # "aarch64-apple-darwin" + ]; }; craneLib = (crane.mkLib pkgs).overrideToolchain stableToolchain; src = craneLib.cleanCargoSource (craneLib.path ./.); commonArgs = { inherit src; buildInputs = with pkgs; - [] + [ + alsa-lib + # wayland + # xorg.libX11 + # xorg.libXi + # libGL + ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ libiconv # pkgs.darwin.apple_sdk.frameworks.CoreServices @@ -63,25 +70,60 @@ # LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; # For using pkg-config that many libraries require # PKG_CONFIG_PATH = lib.makeSearchPath "lib/pkgconfig" (with pkgs;[ openssl.dev zlib.dev ]); + LD_LIBRARY_PATH = builtins.concatStringsSep ":" [ + "${pkgs.xorg.libX11}/lib" + "${pkgs.xorg.libXi}/lib" + "${pkgs.libGL}/lib" + "${pkgs.wayland}/lib" + ]; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; in { checks = { - hello-clippy = craneLib.cargoClippy (commonArgs + tadventure-clippy = craneLib.cargoClippy (commonArgs // { inherit cargoArtifacts; cargoClippyExtraArgs = "--all-targets -- --deny warnings"; }); - hello-fmt = craneLib.cargoFmt { + tadventure-fmt = craneLib.cargoFmt { inherit src; }; - hello-nextest = craneLib.cargoNextest (commonArgs + tadventure-nextest = craneLib.cargoNextest (commonArgs // { inherit cargoArtifacts; partitions = 1; partitionType = "count"; }); }; + packages = rec { + tadventure-unwrapped = pkgs.rustPlatform.buildRustPackage { + pname = "tadventure"; + version = "0.1.0"; + cargoLock = { + lockFile = "${src}/Cargo.lock"; + }; + inherit src; + }; + tadventure = pkgs.buildFHSEnv { + name = "tadventure"; + targetPkgs = pkgs: + with pkgs; [ + tadventure-unwrapped + xorg.libX11 + xorg.libXi + libGL + egl-wayland + ]; + multiPkgs = pkgs: + with pkgs; [ + alsa-lib + ]; + runScript = '' + ${tadventure-unwrapped}/bin/tadventure + ''; + }; + default = tadventure; + }; devShells.default = (craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell (commonArgs // { @@ -90,6 +132,7 @@ packages = with pkgs; [ cargo-nextest cargo-criterion + trunk ]; }); } diff --git a/src/main.rs b/src/main.rs index 146237e..c728eef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ use macroquad::prelude::*; -use once_cell::sync::Lazy; pub struct Character { pos: Vec2, @@ -9,15 +8,26 @@ pub struct Character { // static BACKGROUND_TEXTURE: Lazy = // Lazy::new(|| Texture2D::from_file_with_format(include_bytes!("../assets/grass.png"), None)); +fn window_conf() -> Conf { + Conf { + window_title: "Window Conf".to_owned(), + fullscreen: true, + platform: miniquad::conf::Platform { + linux_backend: miniquad::conf::LinuxBackend::WaylandWithX11Fallback, + ..Default::default() + }, + ..Default::default() + } +} -#[macroquad::main("Tadventure")] +#[macroquad::main(window_conf)] async fn main() { let mut character = Character::new( Vec2::new(100.0, 100.0), Vec2::new(0.0, 0.0), vec2(0f32, 0f32), ); - let mut cursor = Cursor::new(); + let mut cursor = Cursor::default(); loop { clear_background(GREEN); @@ -64,17 +74,12 @@ impl Character { } } +#[derive(Default)] pub struct Cursor { pos: Vec2, } impl Cursor { - pub fn new() -> Self { - Self { - pos: vec2(0.0, 0.0), - } - } - pub fn handle_mouse(&mut self) { let mouse_pos = mouse_position(); self.pos = vec2(mouse_pos.0, mouse_pos.1);