mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 10:44:07 +02:00
clippy fixes
This commit is contained in:
parent
efb0a0f7f2
commit
5e1ae07d36
5 changed files with 83 additions and 164 deletions
|
|
@ -6,12 +6,12 @@ const MAP_BYTES: &[u8] = include_bytes!("../koth_bagel_rc2a.bsp");
|
|||
|
||||
fn from_bytes(c: &mut Criterion) {
|
||||
c.bench_function("parse bsp", |b| {
|
||||
b.iter(|| Bsp::read(black_box(&MAP_BYTES)).unwrap())
|
||||
b.iter(|| Bsp::read(black_box(MAP_BYTES)).unwrap())
|
||||
});
|
||||
}
|
||||
|
||||
fn leaf_at(c: &mut Criterion) {
|
||||
let bsp = Bsp::read(&MAP_BYTES).unwrap();
|
||||
let bsp = Bsp::read(MAP_BYTES).unwrap();
|
||||
|
||||
c.bench_function("get leaf at position", |b| {
|
||||
b.iter(|| {
|
||||
|
|
|
|||
97
flake.lock
generated
97
flake.lock
generated
|
|
@ -1,22 +1,59 @@
|
|||
{
|
||||
"nodes": {
|
||||
"naersk": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1733688869,
|
||||
"narHash": "sha256-KrhxxFj1CjESDrL5+u/zsVH0K+Ik9tvoac/oFPoxSB8=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "604637106e420ad99907cae401e13ab6b452e7d9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flakelight": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1736429655,
|
||||
"narHash": "sha256-BwMekRuVlSB9C0QgwKMICiJ5EVbLGjfe4qyueyNQyGI=",
|
||||
"lastModified": 1739191238,
|
||||
"narHash": "sha256-DRuhQDWscKWXAZcatFDLQ0+pMKmGZ9lEZdxygq8rVSU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "0621e47bd95542b8e1ce2ee2d65d6a1f887a13ce",
|
||||
"repo": "flakelight",
|
||||
"rev": "5656e7f5fda93676642d199fd9eb47b970d6139e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"repo": "flakelight",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"mill-scale": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flakelight": [
|
||||
"flakelight"
|
||||
],
|
||||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735052218,
|
||||
"narHash": "sha256-I30wh6G8fSUO4EseexxiDXcxyUhXR6C8BvEeKn6xyfE=",
|
||||
"owner": "icewind1991",
|
||||
"repo": "mill-scale",
|
||||
"rev": "7e45bb598ff63a8416ee3c26743b20644563bd93",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "icewind1991",
|
||||
"repo": "mill-scale",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
|
|
@ -37,24 +74,25 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay",
|
||||
"utils": "utils"
|
||||
"flakelight": "flakelight",
|
||||
"mill-scale": "mill-scale",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"mill-scale",
|
||||
"flakelight",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1739500069,
|
||||
"narHash": "sha256-eCxWMqMsP2KQkleWWhs9KzFvxgd9v0F0iq7Piw6XDAs=",
|
||||
"lastModified": 1733884434,
|
||||
"narHash": "sha256-8GXR9kC07dyOIshAyfZhG11xfvBRSZzYghnZ2weOKJU=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "cd3e0a87bf9edadb0f311ba1eb677bbae7a08b81",
|
||||
"rev": "d0483df44ddf0fd1985f564abccbe568e020ddf2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -62,39 +100,6 @@
|
|||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
|
|||
108
flake.nix
108
flake.nix
|
|
@ -1,100 +1,16 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-24.11";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
naersk.url = "github:nix-community/naersk";
|
||||
naersk.inputs.nixpkgs.follows = "nixpkgs";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||
flakelight = {
|
||||
url = "github:nix-community/flakelight";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
mill-scale = {
|
||||
url = "github:icewind1991/mill-scale";
|
||||
inputs.flakelight.follows = "flakelight";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
naersk,
|
||||
rust-overlay,
|
||||
}:
|
||||
utils.lib.eachDefaultSystem (system: let
|
||||
overlays = [(import rust-overlay)];
|
||||
pkgs = (import nixpkgs) {
|
||||
inherit system overlays;
|
||||
};
|
||||
inherit (pkgs) lib callPackage rust-bin mkShell;
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
|
||||
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
|
||||
inherit (builtins) fromTOML readFile;
|
||||
toolchain = rust-bin.stable.latest.default;
|
||||
msrvToolchain = rust-bin.stable."${msrv}".default;
|
||||
|
||||
naersk' = callPackage naersk {
|
||||
rustc = toolchain;
|
||||
cargo = toolchain;
|
||||
};
|
||||
msrvNaersk = callPackage naersk {
|
||||
rustc = msrvToolchain;
|
||||
cargo = msrvToolchain;
|
||||
};
|
||||
|
||||
src = sourceByRegex ./. ["Cargo.*" "(src|derive|benches|tests|examples|koth_bagel.*)(/.*)?"];
|
||||
nearskOpt = {
|
||||
pname = "vbsp";
|
||||
root = src;
|
||||
};
|
||||
in rec {
|
||||
packages = {
|
||||
check = naersk'.buildPackage (nearskOpt
|
||||
// {
|
||||
mode = "check";
|
||||
});
|
||||
clippy = naersk'.buildPackage (nearskOpt
|
||||
// {
|
||||
mode = "clippy";
|
||||
});
|
||||
test = naersk'.buildPackage (nearskOpt
|
||||
// {
|
||||
release = false;
|
||||
mode = "test";
|
||||
});
|
||||
msrv = msrvNaersk.buildPackage (nearskOpt
|
||||
// {
|
||||
mode = "check";
|
||||
});
|
||||
};
|
||||
|
||||
devShells = let
|
||||
tools = with pkgs; [
|
||||
bacon
|
||||
cargo-edit
|
||||
cargo-outdated
|
||||
cargo-audit
|
||||
cargo-msrv
|
||||
cargo-semver-checks
|
||||
(writeShellApplication {
|
||||
name = "cargo-fuzz";
|
||||
runtimeInputs = [cargo-fuzz toolchain];
|
||||
text = ''
|
||||
# shellcheck disable=SC2068
|
||||
RUSTC_BOOTSTRAP=1 cargo-fuzz $@
|
||||
'';
|
||||
})
|
||||
(writeShellApplication {
|
||||
name = "cargo-expand";
|
||||
runtimeInputs = [cargo-expand toolchain];
|
||||
text = ''
|
||||
# shellcheck disable=SC2068
|
||||
RUSTC_BOOTSTRAP=1 cargo-expand $@
|
||||
'';
|
||||
})
|
||||
];
|
||||
in {
|
||||
default = mkShell {
|
||||
nativeBuildInputs = [toolchain] ++ tools;
|
||||
};
|
||||
msrv = mkShell {
|
||||
nativeBuildInputs = [msrvToolchain] ++ tools;
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
outputs = { mill-scale, ... }: mill-scale ./. {
|
||||
extraPaths = [./fuzz ./examples ./benches ./koth_bagel_rc2a.bsp];
|
||||
};
|
||||
}
|
||||
|
|
@ -6,8 +6,6 @@ use crate::data::*;
|
|||
use crate::Bsp;
|
||||
use ahash::RandomState;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::hash::BuildHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// A handle represents a data structure in the bsp file and the bsp file containing it.
|
||||
|
|
@ -163,11 +161,11 @@ impl<'a> Handle<'a, TextureData> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get a color that is unique but determistic for this texture
|
||||
/// Get a color that is unique but deterministic for this texture
|
||||
pub fn debug_color(&self) -> [u8; 3] {
|
||||
let mut name_hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher();
|
||||
self.name().hash(&mut name_hasher);
|
||||
let name_hash = name_hasher.finish().to_be_bytes();
|
||||
let name_hash = RandomState::with_seeds(0, 0, 0, 0)
|
||||
.hash_one(self.name())
|
||||
.to_le_bytes();
|
||||
[name_hash[0], name_hash[1], name_hash[2]]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
src/lib.rs
28
src/lib.rs
|
|
@ -547,20 +547,6 @@ impl Bsp {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Bsp;
|
||||
|
||||
#[test]
|
||||
fn tf2_file() {
|
||||
use std::fs::read;
|
||||
|
||||
let data = read("koth_bagel_rc2a.bsp").unwrap();
|
||||
|
||||
Bsp::read(&data).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// LZMA decompression with the header used by source
|
||||
fn lzma_decompress_with_header(data: &[u8], expected_length: usize) -> Result<Vec<u8>, BspError> {
|
||||
// extra 8 byte because game lumps need some padding for reasons
|
||||
|
|
@ -597,3 +583,17 @@ fn lzma_decompress_with_header(data: &[u8], expected_length: usize) -> Result<Ve
|
|||
}
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Bsp;
|
||||
|
||||
#[test]
|
||||
fn tf2_file() {
|
||||
use std::fs::read;
|
||||
|
||||
let data = read("koth_bagel_rc2a.bsp").unwrap();
|
||||
|
||||
Bsp::read(&data).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue