mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 01:21:34 +11:00
const fnify
This commit is contained in:
parent
8a6f341421
commit
c55ff3f714
|
@ -151,9 +151,7 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
});
|
||||
|
||||
let tags = tags
|
||||
.iter()
|
||||
.map(|(tag, num_images)| {
|
||||
let tags = tags.iter().flat_map(|(tag, num_images)| {
|
||||
tag.iter().map(move |tag| {
|
||||
let start = tag.from_frame() as usize + num_images;
|
||||
let end = tag.to_frame() as usize + num_images;
|
||||
|
@ -163,11 +161,10 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream {
|
|||
assert!(start <= end, "Tag {} has start > end", name);
|
||||
|
||||
quote! {
|
||||
#name => Tag::new(SPRITES, #start, #end, #direction)
|
||||
(#name, Tag::new(SPRITES, #start, #end, #direction))
|
||||
}
|
||||
})
|
||||
})
|
||||
.flatten();
|
||||
});
|
||||
|
||||
let include_paths = filenames.iter().map(|s| {
|
||||
let s = s.as_os_str().to_string_lossy();
|
||||
|
@ -189,9 +186,9 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream {
|
|||
];
|
||||
|
||||
const TAGS: &TagMap = &TagMap::new(
|
||||
phf::phf_map! {
|
||||
&[
|
||||
#(#tags),*
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
};
|
||||
|
|
57
agb/Cargo.lock
generated
57
agb/Cargo.lock
generated
|
@ -26,7 +26,6 @@ dependencies = [
|
|||
"bitflags",
|
||||
"hashbrown",
|
||||
"modular-bitfield",
|
||||
"phf",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
|
@ -315,50 +314,6 @@ version = "1.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
|
||||
dependencies = [
|
||||
"phf_macros",
|
||||
"phf_shared",
|
||||
"proc-macro-hack",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_macros"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.5"
|
||||
|
@ -377,12 +332,6 @@ version = "0.2.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
|
@ -467,12 +416,6 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
|
|
|
@ -28,7 +28,6 @@ bare-metal = "1.0"
|
|||
hashbrown = "0.12.0"
|
||||
modular-bitfield = "0.11.2"
|
||||
rustc-hash = { version = "1.0", default-features = false }
|
||||
phf = { version = "0.10", default-features = false, features = ["macros"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
default-target = "thumbv6m-none-eabi"
|
||||
|
|
|
@ -69,7 +69,6 @@ macro_rules! include_aseprite {
|
|||
($($aseprite_path: expr),*) => {{
|
||||
use $crate::display::object::{Size, Sprite, Tag, TagMap};
|
||||
use $crate::display::palette16::Palette16;
|
||||
use $crate::phf;
|
||||
|
||||
$crate::include_aseprite_inner!($($aseprite_path),*);
|
||||
|
||||
|
@ -77,18 +76,44 @@ macro_rules! include_aseprite {
|
|||
}};
|
||||
}
|
||||
|
||||
pub struct TagMap(phf::Map<&'static str, Tag>);
|
||||
pub struct TagMap {
|
||||
tags: &'static [(&'static str, Tag)],
|
||||
}
|
||||
|
||||
const fn const_byte_compare(a: &[u8], b: &[u8]) -> bool {
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut i = 0;
|
||||
while i < a.len() {
|
||||
if a[i] != b[i] {
|
||||
return false;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
impl TagMap {
|
||||
pub const fn new(map: phf::Map<&'static str, Tag>) -> Self {
|
||||
Self(map)
|
||||
pub const fn new(tags: &'static [(&'static str, Tag)]) -> TagMap {
|
||||
Self { tags }
|
||||
}
|
||||
pub const fn get(&'static self, tag: &str) -> Option<&'static Tag> {
|
||||
let mut i = 0;
|
||||
while i < self.tags.len() {
|
||||
let s = self.tags[i].0;
|
||||
if const_byte_compare(s.as_bytes(), tag.as_bytes()) {
|
||||
return Some(&self.tags[i].1);
|
||||
}
|
||||
|
||||
impl Deref for TagMap {
|
||||
type Target = phf::Map<&'static str, Tag>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
i += 1;
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
pub fn values(&self) -> impl Iterator<Item = &'static Tag> {
|
||||
self.tags.iter().map(|x| &x.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,10 +342,9 @@ impl ObjectController {
|
|||
index: inner.pop()?,
|
||||
free_list: &self.free_objects,
|
||||
};
|
||||
let p_sprite = sprite.clone();
|
||||
Some(Object {
|
||||
previous_sprite: sprite.clone(),
|
||||
sprite,
|
||||
previous_sprite: p_sprite,
|
||||
loan,
|
||||
attrs: Attributes::new(),
|
||||
})
|
||||
|
|
|
@ -113,7 +113,6 @@
|
|||
pub use agb_image_converter::include_gfx;
|
||||
|
||||
pub use agb_image_converter::include_aseprite_inner;
|
||||
pub use phf;
|
||||
|
||||
/// This macro declares the entry point to your game written using `agb`.
|
||||
///
|
||||
|
|
93
examples/the-hat-chooses-the-wizard/Cargo.lock
generated
93
examples/the-hat-chooses-the-wizard/Cargo.lock
generated
|
@ -26,7 +26,6 @@ dependencies = [
|
|||
"bitflags",
|
||||
"hashbrown",
|
||||
"modular-bitfield",
|
||||
"phf",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
|
@ -322,50 +321,6 @@ version = "1.10.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
|
||||
dependencies = [
|
||||
"phf_macros",
|
||||
"phf_shared",
|
||||
"proc-macro-hack",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_macros"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.16.8"
|
||||
|
@ -378,18 +333,6 @@ dependencies = [
|
|||
"miniz_oxide 0.3.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
|
@ -408,36 +351,6 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
|
@ -481,12 +394,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
|
|
Loading…
Reference in a new issue