Resolve stutter upon switching to dice customise screen (#442)

1. Dealloc now uses the normal dealloc procedure.
    * Better because normalisation is quick, O(1).
    * More normalisation means inserting into the list is faster.
2. Run sfx frame during the generation of upgrades (which can take an
unbounded amount of time).

* Both of these are required to remove the stuttering.
* It sounds really weird now that it works right :/

- [ ] Changelog updated / no changelog update needed
This commit is contained in:
Corwin 2023-06-05 21:01:12 +01:00 committed by GitHub
commit 28e3a7faf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 9 deletions

View file

@ -85,12 +85,6 @@ impl BlockAllocator {
self.with_inner(|inner| inner.dealloc(ptr, layout));
}
pub unsafe fn dealloc_no_normalise(&self, ptr: *mut u8, layout: Layout) {
self.with_inner(|inner| {
inner.dealloc_no_normalise(ptr, layout);
});
}
pub unsafe fn grow(
&self,
ptr: *mut u8,

View file

@ -342,7 +342,7 @@ impl VRamManager {
let tile_reference = Self::reference_from_index(tile_index);
unsafe {
TILE_ALLOCATOR.dealloc_no_normalise(
TILE_ALLOCATOR.dealloc(
tile_reference.0.cast().as_ptr(),
layout_of(tile_index.format()),
);

View file

@ -175,7 +175,7 @@ pub(crate) fn customise_screen(
agb.sfx.frame();
let mut upgrades = crate::level_generation::generate_upgrades(level);
let mut upgrades = crate::level_generation::generate_upgrades(level, &mut || agb.sfx.frame());
let mut _upgrade_objects = create_upgrade_objects(&agb.obj, &upgrades);
let mut input = agb::input::ButtonController::new();

View file

@ -92,7 +92,7 @@ fn generate_cooldown(current_level: u32) -> u32 {
rng::gen().rem_euclid((5 * 60 - current_level as i32 * 10).max(1)) as u32 + 2 * 60
}
pub fn generate_upgrades(level: u32) -> Vec<Face> {
pub fn generate_upgrades(level: u32, call: &mut dyn FnMut()) -> Vec<Face> {
let mut upgrade_values = HashMap::new();
upgrade_values.insert(Face::Shoot, 5);
@ -128,6 +128,8 @@ pub fn generate_upgrades(level: u32) -> Vec<Face> {
let mut attempts = 0;
while upgrades.len() != 3 {
call();
attempts += 1;
let next = potential_upgrades[rng::gen() as usize % potential_upgrades.len()];
let number_of_malfunctions = upgrades
@ -144,6 +146,7 @@ pub fn generate_upgrades(level: u32) -> Vec<Face> {
}
if attempts > 100 {
attempts = 0;
upgrades.clear();
}
}