mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Fix-and-test-2023-01-06 (#365)
Fix warnings and add test to benchmark the allocator - [x] Changelog updated / no changelog update needed
This commit is contained in:
commit
fd66ca8afe
|
@ -79,7 +79,7 @@ pub fn include_gfx(input: TokenStream) -> TokenStream {
|
||||||
let mut palette256 = Palette256::new();
|
let mut palette256 = Palette256::new();
|
||||||
|
|
||||||
for (name, settings) in images.iter() {
|
for (name, settings) in images.iter() {
|
||||||
let image_filename = &parent.join(&settings.filename());
|
let image_filename = &parent.join(settings.filename());
|
||||||
let image = Image::load_from_file(image_filename);
|
let image = Image::load_from_file(image_filename);
|
||||||
|
|
||||||
match settings.colours() {
|
match settings.colours() {
|
||||||
|
@ -282,7 +282,7 @@ fn convert_image(
|
||||||
optimisation_results: &Palette16OptimisationResults,
|
optimisation_results: &Palette16OptimisationResults,
|
||||||
assignment_offset: Option<usize>,
|
assignment_offset: Option<usize>,
|
||||||
) -> proc_macro2::TokenStream {
|
) -> proc_macro2::TokenStream {
|
||||||
let image_filename = &parent.join(&settings.filename());
|
let image_filename = &parent.join(settings.filename());
|
||||||
let image = Image::load_from_file(image_filename);
|
let image = Image::load_from_file(image_filename);
|
||||||
|
|
||||||
rust_generator::generate_code(
|
rust_generator::generate_code(
|
||||||
|
@ -339,7 +339,6 @@ fn palette_tile_data(
|
||||||
.map(|colour| colour.to_rgb15())
|
.map(|colour| colour.to_rgb15())
|
||||||
.chain(iter::repeat(0))
|
.chain(iter::repeat(0))
|
||||||
.take(16)
|
.take(16)
|
||||||
.map(|colour| colour as u16)
|
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -19,8 +19,7 @@ pub(crate) fn generate_palette_code(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|colour| colour.to_rgb15())
|
.map(|colour| colour.to_rgb15())
|
||||||
.chain(iter::repeat(0))
|
.chain(iter::repeat(0))
|
||||||
.take(16)
|
.take(16);
|
||||||
.map(|colour| colour as u16);
|
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#crate_prefix::display::palette16::Palette16::new([
|
#crate_prefix::display::palette16::Palette16::new([
|
||||||
|
|
|
@ -251,4 +251,45 @@ mod test {
|
||||||
"address of allocation should be within iwram, instead at {p:?}"
|
"address of allocation should be within iwram, instead at {p:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn benchmark_allocation(_gba: &mut crate::Gba) {
|
||||||
|
let mut stored: Vec<Vec<u8>> = Vec::new();
|
||||||
|
|
||||||
|
let mut rng = crate::rng::RandomNumberGenerator::new();
|
||||||
|
|
||||||
|
const MAX_VEC_LENGTH: usize = 100;
|
||||||
|
|
||||||
|
enum Action {
|
||||||
|
Add { size: usize },
|
||||||
|
Remove { index: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
let next_action = |rng: &mut crate::rng::RandomNumberGenerator, stored: &[Vec<u8>]| {
|
||||||
|
if stored.len() >= MAX_VEC_LENGTH {
|
||||||
|
Action::Remove {
|
||||||
|
index: (rng.gen() as usize) % stored.len(),
|
||||||
|
}
|
||||||
|
} else if stored.is_empty() || rng.gen() as usize % 4 != 0 {
|
||||||
|
Action::Add {
|
||||||
|
size: rng.gen() as usize % 32,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Action::Remove {
|
||||||
|
index: (rng.gen() as usize) % stored.len(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for _ in 0..10000 {
|
||||||
|
match next_action(&mut rng, &stored) {
|
||||||
|
Action::Add { size } => {
|
||||||
|
stored.push(Vec::with_capacity(size));
|
||||||
|
}
|
||||||
|
Action::Remove { index } => {
|
||||||
|
stored.swap_remove(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ fn update_changelog(root_directory: &Path, new_version: &Version) -> Result<Stri
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
|
||||||
std::fs::write(&changelog_file, &changelog_content)
|
std::fs::write(&changelog_file, changelog_content)
|
||||||
.map_err(|_| Error::FailedToWriteChangelog)?;
|
.map_err(|_| Error::FailedToWriteChangelog)?;
|
||||||
|
|
||||||
Ok(change_content)
|
Ok(change_content)
|
||||||
|
|
Loading…
Reference in a new issue