Merge pull request #200 from gwilymk/small-fixes-to-match-rust-api-guidelines

Small fixes to match rust api guidelines
This commit is contained in:
Gwilym Kuiper 2022-03-23 21:44:01 +00:00 committed by GitHub
commit 1982df727c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 194 additions and 344 deletions

View file

@ -72,9 +72,9 @@ fn main(mut gba: agb::Gba) -> ! {
let object = gba.display.object.get(); let object = gba.display.object.get();
let sprite = object.get_sprite(&ChickenSprites[0]); let sprite = object.sprite(&CHICKEN_SPRITES[0]);
let mut chicken = Character { let mut chicken = Character {
object: object.get_object(sprite), object: object.object(sprite),
position: Vector2D { position: Vector2D {
x: (6 * 8) << 8, x: (6 * 8) << 8,
y: ((7 * 8) - 4) << 8, y: ((7 * 8) - 4) << 8,
@ -154,19 +154,19 @@ fn update_chicken_object<'a>(
State::Ground => { State::Ground => {
if chicken.velocity.x.abs() > 1 << 4 { if chicken.velocity.x.abs() > 1 << 4 {
chicken.object.set_sprite( chicken.object.set_sprite(
object.get_sprite(&ChickenSprites[frame_ranger(frame_count, 1, 3, 10)]), object.sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 1, 3, 10)]),
); );
} else { } else {
chicken chicken
.object .object
.set_sprite(object.get_sprite(&ChickenSprites[0])); .set_sprite(object.sprite(&CHICKEN_SPRITES[0]));
} }
} }
State::Upwards => {} State::Upwards => {}
State::Flapping => { State::Flapping => {
chicken chicken
.object .object
.set_sprite(object.get_sprite(&ChickenSprites[frame_ranger(frame_count, 4, 5, 5)])); .set_sprite(object.sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 4, 5, 5)]));
} }
} }
@ -251,12 +251,12 @@ fn handle_collision(
// Below is the data for the sprites // Below is the data for the sprites
static ChickenPalette: Palette16 = static CHICKEN_PALETTE: Palette16 =
Palette16::new([0x7C1E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); Palette16::new([0x7C1E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
static ChickenSprites: &[Sprite] = &[ static CHICKEN_SPRITES: &[Sprite] = &[
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
@ -265,7 +265,7 @@ static ChickenSprites: &[Sprite] = &[
Size::S8x8, Size::S8x8,
), ),
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x10, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x10, 0x00,
@ -274,7 +274,7 @@ static ChickenSprites: &[Sprite] = &[
Size::S8x8, Size::S8x8,
), ),
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x10, 0x01, 0x10, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x10, 0x01, 0x10, 0x00,
@ -283,7 +283,7 @@ static ChickenSprites: &[Sprite] = &[
Size::S8x8, Size::S8x8,
), ),
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x00, 0x10, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x11, 0x01, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x11, 0x01, 0x00,
@ -292,7 +292,7 @@ static ChickenSprites: &[Sprite] = &[
Size::S8x8, Size::S8x8,
), ),
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x11, 0x11, 0x11, 0x10, 0x10, 0x11, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x11, 0x11, 0x11, 0x10, 0x10, 0x11, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
@ -301,7 +301,7 @@ static ChickenSprites: &[Sprite] = &[
Size::S8x8, Size::S8x8,
), ),
Sprite::new( Sprite::new(
&ChickenPalette, &CHICKEN_PALETTE,
&[ &[
0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x11, 0x11, 0x01, 0x10, 0x11, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x10, 0x11, 0x10, 0x11, 0x11, 0x01, 0x10, 0x11,
0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x11, 0x01, 0x10, 0x11, 0x11, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,

View file

@ -25,7 +25,7 @@ fn main(mut gba: Gba) -> ! {
input.update(); input.update();
{ {
if let Some(channel) = mixer.get_channel(&channel_id) { if let Some(channel) = mixer.channel(&channel_id) {
let half: Num<i16, 4> = Num::new(1) / 2; let half: Num<i16, 4> = Num::new(1) / 2;
let half_usize: Num<usize, 8> = Num::new(1) / 2; let half_usize: Num<usize, 8> = Num::new(1) / 2;
match input.x_tri() { match input.x_tri() {

View file

@ -5,7 +5,7 @@ extern crate alloc;
use agb::display::object::{Graphics, ObjectController, Sprite, TagMap}; use agb::display::object::{Graphics, ObjectController, Sprite, TagMap};
use alloc::vec::Vec; use alloc::vec::Vec;
use bare_metal::CriticalSection;
const GRAPHICS: &Graphics = agb::include_aseprite!( const GRAPHICS: &Graphics = agb::include_aseprite!(
"../examples/the-purple-night/gfx/objects.aseprite", "../examples/the-purple-night/gfx/objects.aseprite",
@ -20,7 +20,7 @@ fn all_sprites(gfx: &ObjectController) {
for y in 0..9 { for y in 0..9 {
for x in 0..14 { for x in 0..14 {
let mut obj = gfx.get_object(gfx.get_sprite(&SPRITES[0])); let mut obj = gfx.object(gfx.sprite(&SPRITES[0]));
obj.show(); obj.show();
obj.set_position((x * 16 + 8, y * 16 + 8).into()); obj.set_position((x * 16 + 8, y * 16 + 8).into());
objs.push(obj); objs.push(obj);
@ -48,7 +48,7 @@ fn all_sprites(gfx: &ObjectController) {
let objs_len = objs.len(); let objs_len = objs.len();
for (i, obj) in objs.iter_mut().enumerate() { for (i, obj) in objs.iter_mut().enumerate() {
let this_image = (image + i * SPRITES.len() / objs_len) % SPRITES.len(); let this_image = (image + i * SPRITES.len() / objs_len) % SPRITES.len();
obj.set_sprite(gfx.get_sprite(&SPRITES[this_image])); obj.set_sprite(gfx.sprite(&SPRITES[this_image]));
obj.commit(); obj.commit();
} }
} }
@ -62,10 +62,10 @@ fn all_tags(gfx: &ObjectController) {
for (i, v) in TAG_MAP.values().enumerate() { for (i, v) in TAG_MAP.values().enumerate() {
let x = (i % 7) as i32; let x = (i % 7) as i32;
let y = (i / 7) as i32; let y = (i / 7) as i32;
let sprite = v.get_sprite(0); let sprite = v.sprite(0);
let (size_x, size_y) = sprite.size().to_width_height(); let (size_x, size_y) = sprite.size().to_width_height();
let (size_x, size_y) = (size_x as i32, size_y as i32); let (size_x, size_y) = (size_x as i32, size_y as i32);
let mut obj = gfx.get_object(gfx.get_sprite(sprite)); let mut obj = gfx.object(gfx.sprite(sprite));
obj.show(); obj.show();
obj.set_position((x * 32 + 16 - size_x / 2, y * 32 + 16 - size_y / 2).into()); obj.set_position((x * 32 + 16 - size_x / 2, y * 32 + 16 - size_y / 2).into());
objs.push((obj, v)); objs.push((obj, v));
@ -90,7 +90,7 @@ fn all_tags(gfx: &ObjectController) {
if count % 5 == 0 { if count % 5 == 0 {
image += 1; image += 1;
for (obj, tag) in objs.iter_mut() { for (obj, tag) in objs.iter_mut() {
obj.set_sprite(gfx.get_sprite(tag.get_animation_sprite(image))); obj.set_sprite(gfx.sprite(tag.animation_sprite(image)));
obj.commit(); obj.commit();
} }
} }

View file

@ -25,10 +25,10 @@ fn main(mut gba: Gba) -> ! {
let mut frame_counter = 0i32; let mut frame_counter = 0i32;
loop { loop {
vblank_provider.wait_for_vblank(); vblank_provider.wait_for_vblank();
let before_mixing_cycles = timer.get_value(); let before_mixing_cycles = timer.value();
mixer.after_vblank(); mixer.after_vblank();
mixer.frame(); mixer.frame();
let after_mixing_cycles = timer.get_value(); let after_mixing_cycles = timer.value();
frame_counter = frame_counter.wrapping_add(1); frame_counter = frame_counter.wrapping_add(1);

View file

@ -37,7 +37,7 @@ const EWRAM_END: usize = 0x0204_0000;
#[global_allocator] #[global_allocator]
static GLOBAL_ALLOC: BlockAllocator = unsafe { static GLOBAL_ALLOC: BlockAllocator = unsafe {
BlockAllocator::new(StartEnd { BlockAllocator::new(StartEnd {
start: get_data_end, start: data_end,
end: || EWRAM_END, end: || EWRAM_END,
}) })
}; };
@ -56,7 +56,7 @@ fn alloc_error(layout: Layout) -> ! {
); );
} }
fn get_data_end() -> usize { fn data_end() -> usize {
extern "C" { extern "C" {
static __ewram_data_end: usize; static __ewram_data_end: usize;
} }
@ -138,7 +138,7 @@ mod test {
#[test_case] #[test_case]
fn should_return_data_end_somewhere_in_ewram(_gba: &mut crate::Gba) { fn should_return_data_end_somewhere_in_ewram(_gba: &mut crate::Gba) {
let data_end = get_data_end(); let data_end = data_end();
assert!( assert!(
0x0200_0000 <= data_end, 0x0200_0000 <= data_end,

View file

@ -1,117 +0,0 @@
use core::cell::RefCell;
type Index = u8;
pub struct Loan<'a, const S: usize> {
pub my_index: Index,
arena: &'a RefCell<ArenaInner<S>>,
}
#[derive(Debug)]
struct ArenaInner<const S: usize> {
arena: [Index; S],
first: Index,
}
pub struct Arena<const S: usize> {
arena_inner: RefCell<ArenaInner<S>>,
}
impl<const S: usize> Arena<S> {
pub fn new() -> Arena<S> {
// we use the special value u8::MAX as a None
assert!(S < u8::MAX as usize - 1);
let mut arena: [u8; S] = [u8::MAX; S];
arena
.iter_mut()
.enumerate()
.for_each(|(idx, a)| *a = idx as Index + 1);
if let Some(a) = arena.last_mut() {
*a = u8::MAX;
}
Arena {
arena_inner: RefCell::new(ArenaInner { arena, first: 0 }),
}
}
pub fn get_next_free(&self) -> Option<Loan<S>> {
let mut arena = self.arena_inner.borrow_mut();
let i = arena.first;
if i == u8::MAX {
return None;
}
arena.first = arena.arena[i as usize];
arena.arena[i as usize] = 1;
Some(Loan {
my_index: i,
arena: &self.arena_inner,
})
}
}
impl<const S: usize> Drop for Loan<'_, S> {
fn drop(&mut self) {
let mut arena = self.arena.borrow_mut();
let mut me = arena.arena[self.my_index as usize];
me -= 1;
if me == 0 {
arena.arena[self.my_index as usize] = arena.first;
arena.first = self.my_index;
} else {
arena.arena[self.my_index as usize] = me;
}
}
}
impl<const S: usize> Clone for Loan<'_, S> {
fn clone(&self) -> Self {
self.arena.borrow_mut().arena[self.my_index as usize] += 1;
Loan {
my_index: self.my_index,
arena: self.arena,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test_case]
fn get_everything(_gba: &mut crate::Gba) {
let s: Arena<4> = Arena::new();
{
let c = alloc::vec![s.get_next_free(), s.get_next_free()];
c.iter()
.enumerate()
.for_each(|(i, a)| assert!(a.is_some(), "expected index {} is some", i));
}
{
let c = alloc::vec![
s.get_next_free(),
s.get_next_free(),
s.get_next_free(),
s.get_next_free()
];
c.iter().for_each(|a| assert!(a.is_some()));
assert!(s.get_next_free().is_none());
}
{
let c = alloc::vec![
s.get_next_free(),
s.get_next_free(),
s.get_next_free(),
s.get_next_free()
];
c.iter().for_each(|a| assert!(a.is_some()));
assert!(s.get_next_free().is_none());
}
}
}

View file

@ -1,7 +1,7 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use core::alloc::Layout; use core::alloc::Layout;
use core::cell::RefCell; use core::cell::RefCell;
use core::hash::BuildHasherDefault;
use core::ptr::NonNull; use core::ptr::NonNull;
use core::slice; use core::slice;
use modular_bitfield::prelude::{B10, B2, B3, B4, B5, B8, B9}; use modular_bitfield::prelude::{B10, B2, B3, B4, B5, B8, B9};
@ -164,21 +164,21 @@ pub struct Tag {
} }
impl Tag { impl Tag {
pub fn get_sprites(&self) -> &'static [Sprite] { pub fn sprites(&self) -> &'static [Sprite] {
unsafe { slice::from_raw_parts(self.sprites, self.len) } unsafe { slice::from_raw_parts(self.sprites, self.len) }
} }
pub fn get_sprite(&self, idx: usize) -> &'static Sprite { pub fn sprite(&self, idx: usize) -> &'static Sprite {
&self.get_sprites()[idx] &self.sprites()[idx]
} }
#[inline] #[inline]
pub fn get_animation_sprite(&self, idx: usize) -> &'static Sprite { pub fn animation_sprite(&self, idx: usize) -> &'static Sprite {
let len_sub_1 = self.len - 1; let len_sub_1 = self.len - 1;
match self.direction { match self.direction {
Direction::Forward => self.get_sprite(idx % self.len), Direction::Forward => self.sprite(idx % self.len),
Direction::Backward => self.get_sprite(len_sub_1 - (idx % self.len)), Direction::Backward => self.sprite(len_sub_1 - (idx % self.len)),
Direction::Pingpong => self.get_sprite( Direction::Pingpong => self.sprite(
(((idx + len_sub_1) % (len_sub_1 * 2)) as isize - len_sub_1 as isize).abs() (((idx + len_sub_1) % (len_sub_1 * 2)) as isize - len_sub_1 as isize).abs()
as usize, as usize,
), ),
@ -335,7 +335,6 @@ impl Drop for Loan<'_> {
} }
pub struct ObjectController { pub struct ObjectController {
free_affine_matricies: RefCell<Vec<u8>>,
free_objects: RefCell<Vec<u8>>, free_objects: RefCell<Vec<u8>>,
sprite_controller: SpriteController, sprite_controller: SpriteController,
} }
@ -356,12 +355,11 @@ impl ObjectController {
Self { Self {
free_objects: RefCell::new((0..128).collect()), free_objects: RefCell::new((0..128).collect()),
free_affine_matricies: RefCell::new((0..32).collect()),
sprite_controller: SpriteController::new(), sprite_controller: SpriteController::new(),
} }
} }
pub fn get_object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Object<'b, 'a> { pub fn object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Object<'b, 'a> {
self.try_get_object(sprite).expect("No object available") self.try_get_object(sprite).expect("No object available")
} }
@ -375,7 +373,7 @@ impl ObjectController {
let mut attrs = Attributes::new(); let mut attrs = Attributes::new();
attrs.a2.set_tile_index(sprite.sprite_location); attrs.a2.set_tile_index(sprite.sprite_location);
let shape_size = sprite.id.get_sprite().size.shape_size(); let shape_size = sprite.id.sprite().size.shape_size();
attrs.a2.set_palete_bank(sprite.palette_location as u8); attrs.a2.set_palete_bank(sprite.palette_location as u8);
attrs.a0.set_shape(shape_size.0); attrs.a0.set_shape(shape_size.0);
attrs.a1a.set_size(shape_size.1); attrs.a1a.set_size(shape_size.1);
@ -389,7 +387,7 @@ impl ObjectController {
}) })
} }
pub fn get_sprite(&self, sprite: &'static Sprite) -> SpriteBorrow { pub fn sprite(&self, sprite: &'static Sprite) -> SpriteBorrow {
self.sprite_controller self.sprite_controller
.try_get_sprite(sprite) .try_get_sprite(sprite)
.expect("No slot for sprite available") .expect("No slot for sprite available")
@ -410,7 +408,7 @@ impl Drop for Object<'_, '_> {
impl<'a, 'b> Object<'a, 'b> { impl<'a, 'b> Object<'a, 'b> {
pub fn set_sprite(&'_ mut self, sprite: SpriteBorrow<'a>) { pub fn set_sprite(&'_ mut self, sprite: SpriteBorrow<'a>) {
self.attrs.a2.set_tile_index(sprite.sprite_location); self.attrs.a2.set_tile_index(sprite.sprite_location);
let shape_size = sprite.id.get_sprite().size.shape_size(); let shape_size = sprite.id.sprite().size.shape_size();
self.attrs.a2.set_palete_bank(sprite.palette_location as u8); self.attrs.a2.set_palete_bank(sprite.palette_location as u8);
self.attrs.a0.set_shape(shape_size.0); self.attrs.a0.set_shape(shape_size.0);
self.attrs.a1a.set_size(shape_size.1); self.attrs.a1a.set_size(shape_size.1);
@ -496,9 +494,9 @@ impl<'a, 'b> Object<'a, 'b> {
struct SpriteId(usize); struct SpriteId(usize);
impl SpriteId { impl SpriteId {
fn get_sprite(self) -> &'static Sprite { fn sprite(self) -> &'static Sprite {
// # Safety // # Safety
// This must be constructed using the get_id of a sprite, so // This must be constructed using the id() of a sprite, so
// they are always valid and always static // they are always valid and always static
unsafe { (self.0 as *const Sprite).as_ref().unwrap_unchecked() } unsafe { (self.0 as *const Sprite).as_ref().unwrap_unchecked() }
} }
@ -509,14 +507,8 @@ impl SpriteId {
#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]
struct PaletteId(usize); struct PaletteId(usize);
impl PaletteId {
fn get_palette(self) -> &'static Palette16 {
unsafe { (self.0 as *const Palette16).as_ref().unwrap_unchecked() }
}
}
impl Palette16 { impl Palette16 {
fn get_id(&'static self) -> PaletteId { fn id(&'static self) -> PaletteId {
PaletteId(self as *const _ as usize) PaletteId(self as *const _ as usize)
} }
const fn layout() -> Layout { const fn layout() -> Layout {
@ -525,7 +517,7 @@ impl Palette16 {
} }
impl Sprite { impl Sprite {
fn get_id(&'static self) -> SpriteId { fn id(&'static self) -> SpriteId {
SpriteId(self as *const _ as usize) SpriteId(self as *const _ as usize)
} }
fn layout(&self) -> Layout { fn layout(&self) -> Layout {
@ -551,11 +543,11 @@ impl SpriteController {
} }
fn try_get_sprite(&self, sprite: &'static Sprite) -> Option<SpriteBorrow> { fn try_get_sprite(&self, sprite: &'static Sprite) -> Option<SpriteBorrow> {
let mut inner = self.inner.borrow_mut(); let mut inner = self.inner.borrow_mut();
let id = sprite.get_id(); let id = sprite.id();
if let Some(storage) = inner.sprite.get_mut(&id) { if let Some(storage) = inner.sprite.get_mut(&id) {
storage.count += 1; storage.count += 1;
let location = storage.location; let location = storage.location;
let palette_location = inner.get_palette(sprite.palette).unwrap(); let palette_location = inner.palette(sprite.palette).unwrap();
Some(SpriteBorrow { Some(SpriteBorrow {
id, id,
palette_location, palette_location,
@ -566,7 +558,7 @@ impl SpriteController {
// layout is non zero sized, so this is safe to call // layout is non zero sized, so this is safe to call
let dest = unsafe { SPRITE_ALLOCATOR.alloc(sprite.layout())? }; let dest = unsafe { SPRITE_ALLOCATOR.alloc(sprite.layout())? };
let palette_location = inner.get_palette(sprite.palette); let palette_location = inner.palette(sprite.palette);
let palette_location = match palette_location { let palette_location = match palette_location {
Some(a) => a, Some(a) => a,
None => { None => {
@ -603,8 +595,8 @@ impl SpriteControllerInner {
sprite: HashMap::default(), sprite: HashMap::default(),
} }
} }
fn get_palette(&mut self, palette: &'static Palette16) -> Option<u16> { fn palette(&mut self, palette: &'static Palette16) -> Option<u16> {
let id = palette.get_id(); let id = palette.id();
if let Some(storage) = self.palette.get_mut(&id) { if let Some(storage) = self.palette.get_mut(&id) {
storage.count += 1; storage.count += 1;
Some(storage.location) Some(storage.location)
@ -627,14 +619,14 @@ impl SpriteControllerInner {
} }
fn return_sprite(&mut self, sprite: &'static Sprite) { fn return_sprite(&mut self, sprite: &'static Sprite) {
let storage = self.sprite.get_mut(&sprite.get_id()); let storage = self.sprite.get_mut(&sprite.id());
if let Some(storage) = storage { if let Some(storage) = storage {
storage.count -= 1; storage.count -= 1;
if storage.count == 0 { if storage.count == 0 {
unsafe { SPRITE_ALLOCATOR.dealloc(storage.as_sprite_ptr(), sprite.layout()) }; unsafe { SPRITE_ALLOCATOR.dealloc(storage.as_sprite_ptr(), sprite.layout()) };
self.sprite.remove(&sprite.get_id()); self.sprite.remove(&sprite.id());
} }
} }
@ -642,7 +634,7 @@ impl SpriteControllerInner {
} }
fn return_palette(&mut self, palette: &'static Palette16) { fn return_palette(&mut self, palette: &'static Palette16) {
let id = palette.get_id(); let id = palette.id();
if let Some(storage) = self.palette.get_mut(&id) { if let Some(storage) = self.palette.get_mut(&id) {
storage.count -= 1; storage.count -= 1;
@ -658,7 +650,7 @@ impl SpriteControllerInner {
impl<'a> Drop for SpriteBorrow<'a> { impl<'a> Drop for SpriteBorrow<'a> {
fn drop(&mut self) { fn drop(&mut self) {
let mut inner = self.controller.borrow_mut(); let mut inner = self.controller.borrow_mut();
inner.return_sprite(self.id.get_sprite()) inner.return_sprite(self.id.sprite())
} }
} }
@ -666,7 +658,7 @@ impl<'a> Clone for SpriteBorrow<'a> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
let mut inner = self.controller.borrow_mut(); let mut inner = self.controller.borrow_mut();
inner.sprite.entry(self.id).and_modify(|a| a.count += 1); inner.sprite.entry(self.id).and_modify(|a| a.count += 1);
let _ = inner.get_palette(self.id.get_sprite().palette).unwrap(); let _ = inner.palette(self.id.sprite().palette).unwrap();
Self { Self {
id: self.id, id: self.id,
sprite_location: self.sprite_location, sprite_location: self.sprite_location,

View file

@ -16,7 +16,7 @@ impl Palette16 {
self.colours[index] = colour; self.colours[index] = colour;
} }
pub fn get_colour(&self, index: usize) -> u16 { pub fn colour(&self, index: usize) -> u16 {
self.colours[index] self.colours[index]
} }
} }

View file

@ -9,7 +9,7 @@ use crate::{
pub struct InfiniteScrolledMap<'a> { pub struct InfiniteScrolledMap<'a> {
map: MapLoan<'a, RegularMap>, map: MapLoan<'a, RegularMap>,
get_tile: Box<dyn Fn(Vector2D<i32>) -> (TileSetReference, TileSetting)>, tile: Box<dyn Fn(Vector2D<i32>) -> (TileSetReference, TileSetting)>,
current_pos: Vector2D<i32>, current_pos: Vector2D<i32>,
offset: Vector2D<i32>, offset: Vector2D<i32>,
@ -26,11 +26,11 @@ pub enum PartialUpdateStatus {
impl<'a> InfiniteScrolledMap<'a> { impl<'a> InfiniteScrolledMap<'a> {
pub fn new( pub fn new(
map: MapLoan<'a, RegularMap>, map: MapLoan<'a, RegularMap>,
get_tile: Box<dyn Fn(Vector2D<i32>) -> (TileSetReference, TileSetting)>, tile: Box<dyn Fn(Vector2D<i32>) -> (TileSetReference, TileSetting)>,
) -> Self { ) -> Self {
Self { Self {
map, map,
get_tile, tile,
current_pos: (0, 0).into(), current_pos: (0, 0).into(),
offset: (0, 0).into(), offset: (0, 0).into(),
copied_up_to: 0, copied_up_to: 0,
@ -79,7 +79,7 @@ impl<'a> InfiniteScrolledMap<'a> {
{ {
for (x_idx, x) in (x_start..x_end).enumerate() { for (x_idx, x) in (x_start..x_end).enumerate() {
let pos = (x, y).into(); let pos = (x, y).into();
let (tile_set_ref, tile_setting) = (self.get_tile)(pos); let (tile_set_ref, tile_setting) = (self.tile)(pos);
self.map.set_tile( self.map.set_tile(
vram, vram,
@ -172,7 +172,7 @@ impl<'a> InfiniteScrolledMap<'a> {
.iter() .iter()
.chain(horizontal_rect_to_update.iter()) .chain(horizontal_rect_to_update.iter())
{ {
let (tile_set_ref, tile_setting) = (self.get_tile)((tile_x, tile_y).into()); let (tile_set_ref, tile_setting) = (self.tile)((tile_x, tile_y).into());
self.map.set_tile( self.map.set_tile(
vram, vram,
@ -186,7 +186,7 @@ impl<'a> InfiniteScrolledMap<'a> {
); );
} }
let current_scroll = self.map.get_scroll_pos(); let current_scroll = self.map.scroll_pos();
let new_scroll = ( let new_scroll = (
(current_scroll.x as i32 + difference.x).rem_euclid(32 * 8) as u16, (current_scroll.x as i32 + difference.x).rem_euclid(32 * 8) as u16,
(current_scroll.y as i32 + difference.y).rem_euclid(32 * 8) as u16, (current_scroll.y as i32 + difference.y).rem_euclid(32 * 8) as u16,

View file

@ -121,7 +121,7 @@ impl RegularMap {
self.y_scroll = pos.y; self.y_scroll = pos.y;
} }
pub fn get_scroll_pos(&self) -> Vector2D<u16> { pub fn scroll_pos(&self) -> Vector2D<u16> {
(self.x_scroll, self.y_scroll).into() (self.x_scroll, self.y_scroll).into()
} }

View file

@ -59,10 +59,6 @@ impl<'a> TileSet<'a> {
pub fn new(tiles: &'a [u8], format: TileFormat) -> Self { pub fn new(tiles: &'a [u8], format: TileFormat) -> Self {
Self { tiles, format } Self { tiles, format }
} }
fn num_tiles(&self) -> usize {
self.tiles.len() / self.format.tile_size() * 4
}
} }
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]

View file

@ -206,7 +206,7 @@ where
pub fn insert(&mut self, key: K, value: V) -> Option<V> { pub fn insert(&mut self, key: K, value: V) -> Option<V> {
let hash = self.hash(&key); let hash = self.hash(&key);
if let Some(location) = self.nodes.get_location(&key, hash) { if let Some(location) = self.nodes.location(&key, hash) {
Some(self.nodes.replace_at_location(location, key, value)) Some(self.nodes.replace_at_location(location, key, value))
} else { } else {
if self.nodes.capacity() * 85 / 100 <= self.len() { if self.nodes.capacity() * 85 / 100 <= self.len() {
@ -222,7 +222,7 @@ where
fn insert_and_get(&mut self, key: K, value: V) -> &'_ mut V { fn insert_and_get(&mut self, key: K, value: V) -> &'_ mut V {
let hash = self.hash(&key); let hash = self.hash(&key);
let location = if let Some(location) = self.nodes.get_location(&key, hash) { let location = if let Some(location) = self.nodes.location(&key, hash) {
self.nodes.replace_at_location(location, key, value); self.nodes.replace_at_location(location, key, value);
location location
} else { } else {
@ -239,7 +239,7 @@ where
/// Returns `true` if the map contains a value for the specified key. /// Returns `true` if the map contains a value for the specified key.
pub fn contains_key(&self, k: &K) -> bool { pub fn contains_key(&self, k: &K) -> bool {
let hash = self.hash(k); let hash = self.hash(k);
self.nodes.get_location(k, hash).is_some() self.nodes.location(k, hash).is_some()
} }
/// Returns the key-value pair corresponding to the supplied key /// Returns the key-value pair corresponding to the supplied key
@ -247,7 +247,7 @@ where
let hash = self.hash(key); let hash = self.hash(key);
self.nodes self.nodes
.get_location(key, hash) .location(key, hash)
.and_then(|location| self.nodes.nodes[location].key_value_ref()) .and_then(|location| self.nodes.nodes[location].key_value_ref())
} }
@ -262,7 +262,7 @@ where
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> { pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
let hash = self.hash(key); let hash = self.hash(key);
if let Some(location) = self.nodes.get_location(key, hash) { if let Some(location) = self.nodes.location(key, hash) {
self.nodes.nodes[location].value_mut() self.nodes.nodes[location].value_mut()
} else { } else {
None None
@ -275,7 +275,7 @@ where
let hash = self.hash(key); let hash = self.hash(key);
self.nodes self.nodes
.get_location(key, hash) .location(key, hash)
.map(|location| self.nodes.remove_from_location(location)) .map(|location| self.nodes.remove_from_location(location))
} }
} }
@ -504,7 +504,7 @@ where
/// Gets the given key's corresponding entry in the map for in-place manipulation. /// Gets the given key's corresponding entry in the map for in-place manipulation.
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> { pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
let hash = self.hash(&key); let hash = self.hash(&key);
let location = self.nodes.get_location(&key, hash); let location = self.nodes.location(&key, hash);
if let Some(location) = location { if let Some(location) = location {
Entry::Occupied(OccupiedEntry { Entry::Occupied(OccupiedEntry {
@ -602,12 +602,12 @@ impl<K, V> NodeStorage<K, V> {
loop { loop {
let location = fast_mod( let location = fast_mod(
self.capacity(), self.capacity(),
new_node.hash + new_node.get_distance() as HashType, new_node.hash + new_node.distance() as HashType,
); );
let current_node = &mut self.nodes[location]; let current_node = &mut self.nodes[location];
if current_node.has_value() { if current_node.has_value() {
if current_node.get_distance() <= new_node.get_distance() { if current_node.distance() <= new_node.distance() {
mem::swap(&mut new_node, current_node); mem::swap(&mut new_node, current_node);
if inserted_location == usize::MAX { if inserted_location == usize::MAX {
@ -623,9 +623,8 @@ impl<K, V> NodeStorage<K, V> {
} }
new_node.increment_distance(); new_node.increment_distance();
self.max_distance_to_initial_bucket = new_node self.max_distance_to_initial_bucket =
.get_distance() new_node.distance().max(self.max_distance_to_initial_bucket);
.max(self.max_distance_to_initial_bucket);
} }
self.number_of_items += 1; self.number_of_items += 1;
@ -641,9 +640,7 @@ impl<K, V> NodeStorage<K, V> {
// if the next node is empty, or the next location has 0 distance to initial bucket then // if the next node is empty, or the next location has 0 distance to initial bucket then
// we can clear the current node // we can clear the current node
if !self.nodes[next_location].has_value() if !self.nodes[next_location].has_value() || self.nodes[next_location].distance() == 0 {
|| self.nodes[next_location].get_distance() == 0
{
return self.nodes[current_location].take_key_value().unwrap().1; return self.nodes[current_location].take_key_value().unwrap().1;
} }
@ -653,7 +650,7 @@ impl<K, V> NodeStorage<K, V> {
} }
} }
fn get_location(&self, key: &K, hash: HashType) -> Option<usize> fn location(&self, key: &K, hash: HashType) -> Option<usize>
where where
K: Eq, K: Eq,
{ {
@ -809,7 +806,7 @@ impl<K, V> Node<K, V> {
} }
} }
fn get_distance(&self) -> i32 { fn distance(&self) -> i32 {
self.distance_to_initial_bucket self.distance_to_initial_bucket
} }
} }

View file

@ -375,7 +375,7 @@ pub fn profiler(timer: &mut crate::timer::Timer, period: u16) -> InterruptHandle
timer.set_overflow_amount(period); timer.set_overflow_amount(period);
timer.set_enabled(true); timer.set_enabled(true);
add_interrupt_handler(timer.get_interrupt(), |_key: &CriticalSection| { add_interrupt_handler(timer.interrupt(), |_key: &CriticalSection| {
crate::println!("{:#010x}", crate::get_program_counter_before_interrupt()); crate::println!("{:#010x}", crate::program_counter_before_interrupt());
}) })
} }

View file

@ -138,7 +138,6 @@ pub use agb_sound_converter::include_wav;
extern crate alloc; extern crate alloc;
mod agb_alloc; mod agb_alloc;
mod arena;
mod bitarray; mod bitarray;
/// Implements everything relating to things that are displayed on screen. /// Implements everything relating to things that are displayed on screen.
pub mod display; pub mod display;
@ -409,7 +408,7 @@ mod test {
} }
#[inline(never)] #[inline(never)]
pub fn get_program_counter_before_interrupt() -> u32 { pub(crate) fn program_counter_before_interrupt() -> u32 {
extern "C" { extern "C" {
static mut agb_rs__program_counter: u32; static mut agb_rs__program_counter: u32;
} }

View file

@ -85,7 +85,7 @@ impl<'a> Mixer<'a> {
panic!("Cannot play more than 8 sounds at once"); panic!("Cannot play more than 8 sounds at once");
} }
pub fn get_channel(&mut self, id: &ChannelId) -> Option<&'_ mut SoundChannel> { pub fn channel(&mut self, id: &ChannelId) -> Option<&'_ mut SoundChannel> {
if let Some(channel) = &mut self.channels[id.0] { if let Some(channel) = &mut self.channels[id.0] {
if self.indices[id.0] == id.1 && !channel.is_done { if self.indices[id.0] == id.1 && !channel.is_done {
return Some(channel); return Some(channel);
@ -141,7 +141,7 @@ impl MixerBuffer {
} }
fn swap(&mut self) { fn swap(&mut self) {
let (left_buffer, right_buffer) = self.get_write_buffer().split_at(SOUND_BUFFER_SIZE); let (left_buffer, right_buffer) = self.write_buffer().split_at(SOUND_BUFFER_SIZE);
hw::enable_dma_for_sound(left_buffer, LeftOrRight::Left); hw::enable_dma_for_sound(left_buffer, LeftOrRight::Left);
hw::enable_dma_for_sound(right_buffer, LeftOrRight::Right); hw::enable_dma_for_sound(right_buffer, LeftOrRight::Right);
@ -150,7 +150,7 @@ impl MixerBuffer {
} }
fn clear(&mut self) { fn clear(&mut self) {
self.get_write_buffer().fill(0); self.write_buffer().fill(0);
} }
fn write_channels<'a>(&mut self, channels: impl Iterator<Item = &'a mut SoundChannel>) { fn write_channels<'a>(&mut self, channels: impl Iterator<Item = &'a mut SoundChannel>) {
@ -202,13 +202,13 @@ impl MixerBuffer {
channel.pos += playback_speed * SOUND_BUFFER_SIZE; channel.pos += playback_speed * SOUND_BUFFER_SIZE;
} }
let write_buffer = self.get_write_buffer(); let write_buffer = self.write_buffer();
unsafe { unsafe {
agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr()); agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr());
} }
} }
fn get_write_buffer(&mut self) -> &mut [i8; SOUND_BUFFER_SIZE * 2] { fn write_buffer(&mut self) -> &mut [i8; SOUND_BUFFER_SIZE * 2] {
if self.buffer_1_active { if self.buffer_1_active {
&mut self.buffer2.0 &mut self.buffer2.0
} else { } else {

View file

@ -21,7 +21,7 @@ pub enum Divider {
} }
impl Divider { impl Divider {
fn get_as_bits(&self) -> u16 { fn as_bits(&self) -> u16 {
use Divider::*; use Divider::*;
match self { match self {
@ -71,13 +71,12 @@ impl Timer {
self.data_register().set(count_up_value); self.data_register().set(count_up_value);
} }
pub fn get_value(&self) -> u16 { pub fn value(&self) -> u16 {
self.data_register().get() self.data_register().get()
} }
pub fn set_divider(&mut self, divider: Divider) { pub fn set_divider(&mut self, divider: Divider) {
self.control_register() self.control_register().set_bits(divider.as_bits(), 2, 0);
.set_bits(divider.get_as_bits(), 2, 0);
} }
pub fn set_enabled(&mut self, enabled: bool) { pub fn set_enabled(&mut self, enabled: bool) {
@ -96,18 +95,18 @@ impl Timer {
} }
fn data_register(&self) -> MemoryMapped<u16> { fn data_register(&self) -> MemoryMapped<u16> {
timer_data(self.get_timer_number()) timer_data(self.timer_number())
} }
fn control_register(&self) -> MemoryMapped<u16> { fn control_register(&self) -> MemoryMapped<u16> {
timer_control(self.get_timer_number()) timer_control(self.timer_number())
} }
fn get_timer_number(&self) -> usize { fn timer_number(&self) -> usize {
self.timer_number as usize self.timer_number as usize
} }
pub fn get_interrupt(&self) -> crate::interrupt::Interrupt { pub fn interrupt(&self) -> crate::interrupt::Interrupt {
use crate::interrupt::Interrupt; use crate::interrupt::Interrupt;
match self.timer_number { match self.timer_number {
0 => Interrupt::Timer0, 0 => Interrupt::Timer0,

View file

@ -23,12 +23,8 @@ fn main(mut gba: Gba) -> ! {
let object = gba.display.object.get(); let object = gba.display.object.get();
const BALL: &Tag = GRAPHICS.tags().get("Ball"); const BALL: &Tag = GRAPHICS.tags().get("Ball");
let ball_sprite = object let ball_sprite = object.sprite(BALL.sprite(0));
.try_get_sprite(BALL.get_sprite(0)) let mut ball = object.object(ball_sprite);
.expect("We should be able to load a sprite");
let mut ball = object
.try_get_object(ball_sprite)
.expect("We should have enoguh space to store an object");
ball.set_x(50).set_y(50).show(); ball.set_x(50).set_y(50).show();

View file

@ -2,7 +2,7 @@ use crate::TAG_MAP;
use super::{sfx::SfxPlayer, Entity, FixedNumberType, HatState, Level}; use super::{sfx::SfxPlayer, Entity, FixedNumberType, HatState, Level};
use agb::{ use agb::{
display::object::{ObjectController, Size, Tag}, display::object::{ObjectController, Tag},
fixnum::Vector2D, fixnum::Vector2D,
}; };
@ -140,7 +140,7 @@ pub struct Slime<'a> {
impl<'a> Slime<'a> { impl<'a> Slime<'a> {
fn new(object: &'a ObjectController, start_pos: Vector2D<FixedNumberType>) -> Self { fn new(object: &'a ObjectController, start_pos: Vector2D<FixedNumberType>) -> Self {
let mut slime = Slime { let slime = Slime {
enemy_info: EnemyInfo::new(object, start_pos, (14u16, 14u16).into()), enemy_info: EnemyInfo::new(object, start_pos, (14u16, 14u16).into()),
state: SlimeState::Idle, state: SlimeState::Idle,
}; };
@ -164,8 +164,8 @@ impl<'a> Slime<'a> {
SlimeState::Idle => { SlimeState::Idle => {
let offset = (timer / 16) as usize; let offset = (timer / 16) as usize;
let frame = SLIME_IDLE.get_animation_sprite(offset); let frame = SLIME_IDLE.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
@ -204,8 +204,8 @@ impl<'a> Slime<'a> {
self.enemy_info.entity.velocity = (0, 0).into(); self.enemy_info.entity.velocity = (0, 0).into();
self.state = SlimeState::Idle; self.state = SlimeState::Idle;
} else { } else {
let frame = SLIME_JUMP.get_animation_sprite(offset); let frame = SLIME_JUMP.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
} }
@ -230,8 +230,8 @@ impl<'a> Slime<'a> {
return UpdateState::Remove; return UpdateState::Remove;
} }
let frame = SLIME_SPLAT.get_animation_sprite(offset); let frame = SLIME_SPLAT.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
} }
@ -262,7 +262,7 @@ pub struct Snail<'a> {
impl<'a> Snail<'a> { impl<'a> Snail<'a> {
fn new(object: &'a ObjectController, start_pos: Vector2D<FixedNumberType>) -> Self { fn new(object: &'a ObjectController, start_pos: Vector2D<FixedNumberType>) -> Self {
let mut snail = Snail { let snail = Snail {
enemy_info: EnemyInfo::new(object, start_pos, (16u16, 16u16).into()), enemy_info: EnemyInfo::new(object, start_pos, (16u16, 16u16).into()),
state: SnailState::Idle(0), state: SnailState::Idle(0),
}; };
@ -301,8 +301,8 @@ impl<'a> Snail<'a> {
} }
} }
let frame = SNAIL_IDLE.get_animation_sprite(0); let frame = SNAIL_IDLE.animation_sprite(0);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
if player_has_collided { if player_has_collided {
@ -321,8 +321,8 @@ impl<'a> Snail<'a> {
} }
self.enemy_info.entity.velocity = (0, 0).into(); self.enemy_info.entity.velocity = (0, 0).into();
let frame = SNAIL_EMERGE.get_animation_sprite(offset); let frame = SNAIL_EMERGE.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
@ -343,8 +343,8 @@ impl<'a> Snail<'a> {
let offset = (timer - time) as usize / 8; let offset = (timer - time) as usize / 8;
let frame = SNAIL_MOVE.get_animation_sprite(offset); let frame = SNAIL_MOVE.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
@ -377,8 +377,8 @@ impl<'a> Snail<'a> {
self.state = SnailState::Idle(timer); self.state = SnailState::Idle(timer);
} }
let frame = SNAIL_EMERGE.get_animation_sprite(offset); let frame = SNAIL_EMERGE.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
self.enemy_info.entity.velocity = (0, 0).into(); self.enemy_info.entity.velocity = (0, 0).into();
@ -398,16 +398,16 @@ impl<'a> Snail<'a> {
let offset = (timer - time) as usize / 4; let offset = (timer - time) as usize / 4;
let frame = if offset < 5 { let frame = if offset < 5 {
SNAIL_EMERGE.get_animation_sprite(5 - offset) SNAIL_EMERGE.animation_sprite(5 - offset)
} else if offset == 5 { } else if offset == 5 {
SNAIL_IDLE.get_animation_sprite(0) SNAIL_IDLE.animation_sprite(0)
} else if offset < 5 + 7 { } else if offset < 5 + 7 {
SNAIL_DEATH.get_animation_sprite(offset - 5) SNAIL_DEATH.animation_sprite(offset - 5)
} else { } else {
return UpdateState::Remove; return UpdateState::Remove;
}; };
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite); self.enemy_info.entity.sprite.set_sprite(sprite);
self.enemy_info.entity.velocity = (0, 0).into(); self.enemy_info.entity.velocity = (0, 0).into();

View file

@ -5,7 +5,7 @@ extern crate alloc;
use agb::{ use agb::{
display::{ display::{
object::{Graphics, Object, ObjectController, Sprite, Tag, TagMap}, object::{Graphics, Object, ObjectController, Tag, TagMap},
tiled::{ tiled::{
InfiniteScrolledMap, PartialUpdateStatus, TileFormat, TileSet, TileSetting, VRamManager, InfiniteScrolledMap, PartialUpdateStatus, TileFormat, TileSet, TileSetting, VRamManager,
}, },
@ -119,8 +119,8 @@ pub struct Entity<'a> {
impl<'a> Entity<'a> { impl<'a> Entity<'a> {
pub fn new(object: &'a ObjectController, collision_mask: Vector2D<u16>) -> Self { pub fn new(object: &'a ObjectController, collision_mask: Vector2D<u16>) -> Self {
let dummy_sprite = object.get_sprite(WALKING.get_sprite(0)); let dummy_sprite = object.sprite(WALKING.sprite(0));
let mut sprite = object.get_object(dummy_sprite); let mut sprite = object.object(dummy_sprite);
sprite.set_priority(Priority::P1); sprite.set_priority(Priority::P1);
Entity { Entity {
sprite, sprite,
@ -349,9 +349,9 @@ impl<'a> Player<'a> {
wizard wizard
.sprite .sprite
.set_sprite(controller.get_sprite(HAT_SPIN_1.get_sprite(0))); .set_sprite(controller.sprite(HAT_SPIN_1.sprite(0)));
hat.sprite hat.sprite
.set_sprite(controller.get_sprite(HAT_SPIN_1.get_sprite(0))); .set_sprite(controller.sprite(HAT_SPIN_1.sprite(0)));
wizard.sprite.show(); wizard.sprite.show();
hat.sprite.show(); hat.sprite.show();
@ -456,8 +456,8 @@ impl<'a> Player<'a> {
let offset = (ping_pong(timer / 16, 4)) as usize; let offset = (ping_pong(timer / 16, 4)) as usize;
self.wizard_frame = offset as u8; self.wizard_frame = offset as u8;
let frame = WALKING.get_animation_sprite(offset); let frame = WALKING.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.wizard.sprite.set_sprite(sprite); self.wizard.sprite.set_sprite(sprite);
} }
@ -466,8 +466,8 @@ impl<'a> Player<'a> {
// going up // going up
self.wizard_frame = 5; self.wizard_frame = 5;
let frame = JUMPING.get_animation_sprite(0); let frame = JUMPING.animation_sprite(0);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.wizard.sprite.set_sprite(sprite); self.wizard.sprite.set_sprite(sprite);
} else if self.wizard.velocity.y > FixedNumberType::new(1) / 16 { } else if self.wizard.velocity.y > FixedNumberType::new(1) / 16 {
@ -481,8 +481,8 @@ impl<'a> Player<'a> {
self.wizard_frame = 0; self.wizard_frame = 0;
let frame = FALLING.get_animation_sprite(offset); let frame = FALLING.animation_sprite(offset);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.wizard.sprite.set_sprite(sprite); self.wizard.sprite.set_sprite(sprite);
} }
@ -503,13 +503,13 @@ impl<'a> Player<'a> {
self.wizard.sprite.set_hflip(true); self.wizard.sprite.set_hflip(true);
self.hat self.hat
.sprite .sprite
.set_sprite(controller.get_sprite(hat_base_tile.get_sprite(5))); .set_sprite(controller.sprite(hat_base_tile.sprite(5)));
} }
agb::input::Tri::Positive => { agb::input::Tri::Positive => {
self.wizard.sprite.set_hflip(false); self.wizard.sprite.set_hflip(false);
self.hat self.hat
.sprite .sprite
.set_sprite(controller.get_sprite(hat_base_tile.get_sprite(0))); .set_sprite(controller.sprite(hat_base_tile.sprite(0)));
} }
_ => {} _ => {}
} }
@ -541,7 +541,7 @@ impl<'a> Player<'a> {
let hat_sprite_offset = (timer / hat_sprite_divider) as usize; let hat_sprite_offset = (timer / hat_sprite_divider) as usize;
self.hat.sprite.set_sprite( self.hat.sprite.set_sprite(
controller.get_sprite(hat_base_tile.get_animation_sprite(hat_sprite_offset)), controller.sprite(hat_base_tile.animation_sprite(hat_sprite_offset)),
); );
if self.hat_slow_counter < 30 && self.hat.velocity.magnitude() < 2.into() { if self.hat_slow_counter < 30 && self.hat.velocity.magnitude() < 2.into() {
@ -574,7 +574,7 @@ impl<'a> Player<'a> {
} }
HatState::WizardTowards => { HatState::WizardTowards => {
self.hat.sprite.set_sprite( self.hat.sprite.set_sprite(
controller.get_sprite(hat_base_tile.get_animation_sprite(timer as usize / 2)), controller.sprite(hat_base_tile.animation_sprite(timer as usize / 2)),
); );
let distance_vector = let distance_vector =
self.hat.position - self.wizard.position + hat_resting_position; self.hat.position - self.wizard.position + hat_resting_position;
@ -676,8 +676,8 @@ impl<'a, 'b, 'c> PlayingLevel<'a, 'b> {
fn dead_update(&mut self, controller: &'a ObjectController) -> bool { fn dead_update(&mut self, controller: &'a ObjectController) -> bool {
self.timer += 1; self.timer += 1;
let frame = PLAYER_DEATH.get_animation_sprite(self.timer as usize / 8); let frame = PLAYER_DEATH.animation_sprite(self.timer as usize / 8);
let sprite = controller.get_sprite(frame); let sprite = controller.sprite(frame);
self.player.wizard.velocity += (0.into(), FixedNumberType::new(1) / 32).into(); self.player.wizard.velocity += (0.into(), FixedNumberType::new(1) / 32).into();
self.player.wizard.position += self.player.wizard.velocity; self.player.wizard.position += self.player.wizard.velocity;
@ -813,7 +813,7 @@ fn main(mut agb: agb::Gba) -> ! {
loop { loop {
vram.set_background_palettes(tile_sheet::background.palettes); vram.set_background_palettes(tile_sheet::background.palettes);
let mut object = agb.display.object.get(); let object = agb.display.object.get();
let mut timer_controller = agb.timers.timers(); let mut timer_controller = agb.timers.timers();
let mut mixer = agb.mixer.mixer(&mut timer_controller.timer0); let mut mixer = agb.mixer.mixer(&mut timer_controller.timer0);

View file

@ -161,8 +161,8 @@ struct Entity<'a> {
impl<'a> Entity<'a> { impl<'a> Entity<'a> {
fn new(object_controller: &'a ObjectController, collision_mask: Rect<u16>) -> Self { fn new(object_controller: &'a ObjectController, collision_mask: Rect<u16>) -> Self {
let s = object_controller.get_sprite(LONGSWORD_IDLE.get_sprite(0)); let s = object_controller.sprite(LONGSWORD_IDLE.sprite(0));
let mut sprite = object_controller.get_object(s); let mut sprite = object_controller.object(s);
sprite.set_priority(Priority::P1); sprite.set_priority(Priority::P1);
Entity { Entity {
sprite, sprite,
@ -350,10 +350,10 @@ impl SwordState {
fn idle_animation(self, counter: u16) -> &'static Sprite { fn idle_animation(self, counter: u16) -> &'static Sprite {
let counter = counter as usize; let counter = counter as usize;
match self { match self {
SwordState::LongSword => LONGSWORD_IDLE.get_animation_sprite(counter / 8), SwordState::LongSword => LONGSWORD_IDLE.animation_sprite(counter / 8),
SwordState::ShortSword => SHORTSWORD_IDLE.get_animation_sprite(counter / 8), SwordState::ShortSword => SHORTSWORD_IDLE.animation_sprite(counter / 8),
SwordState::Dagger => KNIFE_IDLE.get_animation_sprite(counter / 8), SwordState::Dagger => KNIFE_IDLE.animation_sprite(counter / 8),
SwordState::Swordless => SWORDLESS_IDLE.get_animation_sprite(counter / 8), SwordState::Swordless => SWORDLESS_IDLE.animation_sprite(counter / 8),
} }
} }
fn jump_tag(self) -> &'static Tag { fn jump_tag(self) -> &'static Tag {
@ -367,10 +367,10 @@ impl SwordState {
fn walk_animation(self, counter: u16) -> &'static Sprite { fn walk_animation(self, counter: u16) -> &'static Sprite {
let counter = counter as usize; let counter = counter as usize;
match self { match self {
SwordState::LongSword => LONGSWORD_WALK.get_animation_sprite(counter / 4), SwordState::LongSword => LONGSWORD_WALK.animation_sprite(counter / 4),
SwordState::ShortSword => SHORTSWORD_WALK.get_animation_sprite(counter / 4), SwordState::ShortSword => SHORTSWORD_WALK.animation_sprite(counter / 4),
SwordState::Dagger => KNIFE_WALK.get_animation_sprite(counter / 4), SwordState::Dagger => KNIFE_WALK.animation_sprite(counter / 4),
SwordState::Swordless => SWORDLESS_WALK.get_animation_sprite(counter / 4), SwordState::Swordless => SWORDLESS_WALK.animation_sprite(counter / 4),
} }
} }
fn attack_duration(self) -> u16 { fn attack_duration(self) -> u16 {
@ -536,7 +536,7 @@ impl<'a> Player<'a> {
object_controller, object_controller,
Rect::new((0_u16, 0_u16).into(), (4_u16, 12_u16).into()), Rect::new((0_u16, 0_u16).into(), (4_u16, 12_u16).into()),
); );
let s = object_controller.get_sprite(LONGSWORD_IDLE.get_sprite(0)); let s = object_controller.sprite(LONGSWORD_IDLE.sprite(0));
entity.sprite.set_sprite(s); entity.sprite.set_sprite(s);
entity.sprite.show(); entity.sprite.show();
entity.position = (144, 0).into(); entity.position = (144, 0).into();
@ -590,12 +590,12 @@ impl<'a> Player<'a> {
self.entity.sprite.set_hflip(self.facing == Tri::Negative); self.entity.sprite.set_hflip(self.facing == Tri::Negative);
self.entity.velocity.x += self.sword.ground_walk_force() * x as i32; self.entity.velocity.x += self.sword.ground_walk_force() * x as i32;
if self.entity.velocity.x.abs() > Number::new(1) / 10 { if self.entity.velocity.x.abs() > Number::new(1) / 10 {
let sprite = controller let sprite =
.get_sprite(self.sword.walk_animation(self.sprite_offset)); controller.sprite(self.sword.walk_animation(self.sprite_offset));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
} else { } else {
let sprite = controller let sprite =
.get_sprite(self.sword.idle_animation(self.sprite_offset)); controller.sprite(self.sword.idle_animation(self.sprite_offset));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
} }
@ -615,8 +615,7 @@ impl<'a> Player<'a> {
let frame = self.sword.attack_frame(*a); let frame = self.sword.attack_frame(*a);
self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32; self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32;
let tag = self.sword.attack_tag(); let tag = self.sword.attack_tag();
let sprite = let sprite = controller.sprite(tag.animation_sprite(frame as usize));
controller.get_sprite(tag.get_animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
hurtbox = self.sword.ground_attack_hurtbox(frame); hurtbox = self.sword.ground_attack_hurtbox(frame);
@ -630,8 +629,7 @@ impl<'a> Player<'a> {
let frame = self.sword.hold_frame(); let frame = self.sword.hold_frame();
self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32; self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32;
let tag = self.sword.attack_tag(); let tag = self.sword.attack_tag();
let sprite = let sprite = controller.sprite(tag.animation_sprite(frame as usize));
controller.get_sprite(tag.get_animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
if *a == 0 { if *a == 0 {
self.attack_timer = AttackTimer::Idle; self.attack_timer = AttackTimer::Idle;
@ -656,8 +654,7 @@ impl<'a> Player<'a> {
2 2
}; };
let tag = self.sword.jump_tag(); let tag = self.sword.jump_tag();
let sprite = let sprite = controller.sprite(tag.animation_sprite(frame as usize));
controller.get_sprite(tag.get_animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
if x != Tri::Zero { if x != Tri::Zero {
@ -679,8 +676,7 @@ impl<'a> Player<'a> {
*a -= 1; *a -= 1;
let frame = self.sword.jump_attack_frame(*a); let frame = self.sword.jump_attack_frame(*a);
let tag = self.sword.jump_attack_tag(); let tag = self.sword.jump_attack_tag();
let sprite = let sprite = controller.sprite(tag.animation_sprite(frame as usize));
controller.get_sprite(tag.get_animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
hurtbox = self.sword.air_attack_hurtbox(frame); hurtbox = self.sword.air_attack_hurtbox(frame);
@ -842,8 +838,8 @@ impl BatData {
sfx.bat_flap(); sfx.bat_flap();
} }
let sprite = BAT_IDLE.get_sprite(self.sprite_offset as usize / 8); let sprite = BAT_IDLE.sprite(self.sprite_offset as usize / 8);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -877,8 +873,8 @@ impl BatData {
self.sprite_offset = 0; self.sprite_offset = 0;
} }
let sprite = BAT_IDLE.get_sprite(self.sprite_offset as usize / 2); let sprite = BAT_IDLE.sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -904,8 +900,8 @@ impl BatData {
} }
BatState::Dead => { BatState::Dead => {
const BAT_DEAD: &Tag = TAG_MAP.get("bat dead"); const BAT_DEAD: &Tag = TAG_MAP.get("bat dead");
let sprite = BAT_DEAD.get_sprite(0); let sprite = BAT_DEAD.sprite(0);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -972,8 +968,8 @@ impl SlimeData {
const IDLE: &Tag = TAG_MAP.get("slime idle"); const IDLE: &Tag = TAG_MAP.get("slime idle");
let sprite = IDLE.get_sprite(self.sprite_offset as usize / 16); let sprite = IDLE.sprite(self.sprite_offset as usize / 16);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -1012,8 +1008,8 @@ impl SlimeData {
const CHASE: &Tag = TAG_MAP.get("Slime jump"); const CHASE: &Tag = TAG_MAP.get("Slime jump");
let sprite = CHASE.get_sprite(frame as usize); let sprite = CHASE.sprite(frame as usize);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -1042,8 +1038,8 @@ impl SlimeData {
SlimeState::Dead(count) => { SlimeState::Dead(count) => {
if *count < 5 * 4 { if *count < 5 * 4 {
const DEATH: &Tag = TAG_MAP.get("Slime death"); const DEATH: &Tag = TAG_MAP.get("Slime death");
let sprite = DEATH.get_sprite(*count as usize / 4); let sprite = DEATH.sprite(*count as usize / 4);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
*count += 1; *count += 1;
@ -1110,8 +1106,8 @@ impl MiniFlameData {
entity.velocity = resulting_direction.normalise() * Number::new(2); entity.velocity = resulting_direction.normalise() * Number::new(2);
} }
} else { } else {
let sprite = ANGRY.get_animation_sprite(self.sprite_offset as usize / 8); let sprite = ANGRY.animation_sprite(self.sprite_offset as usize / 8);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
entity.velocity = (0.into(), Number::new(-1) / Number::new(4)).into(); entity.velocity = (0.into(), Number::new(-1) / Number::new(4)).into();
@ -1158,8 +1154,8 @@ impl MiniFlameData {
self.state = MiniFlameState::Idle(90); self.state = MiniFlameState::Idle(90);
} }
let sprite = ANGRY.get_animation_sprite(self.sprite_offset as usize / 2); let sprite = ANGRY.animation_sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
} }
MiniFlameState::Dead => { MiniFlameState::Dead => {
@ -1170,8 +1166,8 @@ impl MiniFlameData {
const DEATH: &Tag = TAG_MAP.get("angry boss dead"); const DEATH: &Tag = TAG_MAP.get("angry boss dead");
let sprite = DEATH.get_animation_sprite(self.sprite_offset as usize / 12); let sprite = DEATH.animation_sprite(self.sprite_offset as usize / 12);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
self.sprite_offset += 1; self.sprite_offset += 1;
@ -1231,8 +1227,8 @@ impl EmuData {
const IDLE: &Tag = TAG_MAP.get("emu - idle"); const IDLE: &Tag = TAG_MAP.get("emu - idle");
let sprite = IDLE.get_sprite(self.sprite_offset as usize / 16); let sprite = IDLE.sprite(self.sprite_offset as usize / 16);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
if (entity.position.y - player.entity.position.y).abs() < 10.into() { if (entity.position.y - player.entity.position.y).abs() < 10.into() {
@ -1278,8 +1274,8 @@ impl EmuData {
const WALK: &Tag = TAG_MAP.get("emu-walk"); const WALK: &Tag = TAG_MAP.get("emu-walk");
let sprite = WALK.get_sprite(self.sprite_offset as usize / 2); let sprite = WALK.sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
let gravity: Number = 1.into(); let gravity: Number = 1.into();
@ -1333,8 +1329,8 @@ impl EmuData {
const DEATH: &Tag = TAG_MAP.get("emu - die"); const DEATH: &Tag = TAG_MAP.get("emu - die");
let sprite = DEATH.get_animation_sprite(self.sprite_offset as usize / 4); let sprite = DEATH.animation_sprite(self.sprite_offset as usize / 4);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
self.sprite_offset += 1; self.sprite_offset += 1;
@ -1370,10 +1366,10 @@ impl EnemyData {
const MINI_FLAME: &Tag = TAG_MAP.get("angry boss"); const MINI_FLAME: &Tag = TAG_MAP.get("angry boss");
const EMU: &Tag = TAG_MAP.get("emu - idle"); const EMU: &Tag = TAG_MAP.get("emu - idle");
match self { match self {
EnemyData::Slime(_) => SLIME.get_sprite(0), EnemyData::Slime(_) => SLIME.sprite(0),
EnemyData::Bat(_) => BAT.get_sprite(0), EnemyData::Bat(_) => BAT.sprite(0),
EnemyData::MiniFlame(_) => MINI_FLAME.get_sprite(0), EnemyData::MiniFlame(_) => MINI_FLAME.sprite(0),
EnemyData::Emu(_) => EMU.get_sprite(0), EnemyData::Emu(_) => EMU.sprite(0),
} }
} }
@ -1404,7 +1400,7 @@ impl<'a> Enemy<'a> {
let mut entity = Entity::new(object_controller, enemy_data.collision_mask()); let mut entity = Entity::new(object_controller, enemy_data.collision_mask());
let sprite = enemy_data.sprite(); let sprite = enemy_data.sprite();
let sprite = object_controller.get_sprite(sprite); let sprite = object_controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
entity.sprite.show(); entity.sprite.show();
@ -1445,14 +1441,6 @@ impl ParticleData {
Self::BossHealer(0, target) Self::BossHealer(0, target)
} }
fn tile_id(&self) -> u16 {
match self {
ParticleData::Dust(_) => 70,
ParticleData::Health(_) => 88,
ParticleData::BossHealer(_, _) => 88,
}
}
fn update<'a>( fn update<'a>(
&mut self, &mut self,
controller: &'a ObjectController, controller: &'a ObjectController,
@ -1467,8 +1455,8 @@ impl ParticleData {
} }
const DUST: &Tag = TAG_MAP.get("dust"); const DUST: &Tag = TAG_MAP.get("dust");
let sprite = DUST.get_sprite(*frame as usize / 3); let sprite = DUST.sprite(*frame as usize / 3);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -1481,8 +1469,8 @@ impl ParticleData {
} }
const HEALTH: &Tag = TAG_MAP.get("Heath"); const HEALTH: &Tag = TAG_MAP.get("Heath");
let sprite = HEALTH.get_animation_sprite(*frame as usize / 3); let sprite = HEALTH.animation_sprite(*frame as usize / 3);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -1507,8 +1495,8 @@ impl ParticleData {
} }
ParticleData::BossHealer(frame, target) => { ParticleData::BossHealer(frame, target) => {
const HEALTH: &Tag = TAG_MAP.get("Heath"); const HEALTH: &Tag = TAG_MAP.get("Heath");
let sprite = HEALTH.get_animation_sprite(*frame as usize / 3); let sprite = HEALTH.animation_sprite(*frame as usize / 3);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
@ -1671,8 +1659,8 @@ impl<'a> FollowingBoss<'a> {
const BOSS: &Tag = TAG_MAP.get("happy boss"); const BOSS: &Tag = TAG_MAP.get("happy boss");
let sprite = BOSS.get_animation_sprite(frame as usize); let sprite = BOSS.animation_sprite(frame as usize);
let sprite = controller.get_sprite(sprite); let sprite = controller.sprite(sprite);
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
@ -1807,8 +1795,8 @@ impl<'a> Boss<'a> {
const BOSS: &Tag = TAG_MAP.get("Boss"); const BOSS: &Tag = TAG_MAP.get("Boss");
let sprite = BOSS.get_animation_sprite(frame as usize); let sprite = BOSS.animation_sprite(frame as usize);
let sprite = object_controller.get_sprite(sprite); let sprite = object_controller.sprite(sprite);
self.entity.sprite.set_sprite(sprite); self.entity.sprite.set_sprite(sprite);
@ -2164,8 +2152,8 @@ impl<'a> Game<'a> {
fn update_sunrise(vram: &mut VRamManager, time: u16) { fn update_sunrise(vram: &mut VRamManager, time: u16) {
let mut modified_palette = background::background.palettes[0].clone(); let mut modified_palette = background::background.palettes[0].clone();
let a = modified_palette.get_colour(0); let a = modified_palette.colour(0);
let b = modified_palette.get_colour(1); let b = modified_palette.colour(1);
modified_palette.update_colour(0, interpolate_colour(a, 17982, time, 120)); modified_palette.update_colour(0, interpolate_colour(a, 17982, time, 120));
modified_palette.update_colour(1, interpolate_colour(b, 22427, time, 120)); modified_palette.update_colour(1, interpolate_colour(b, 22427, time, 120));
@ -2178,7 +2166,7 @@ impl<'a> Game<'a> {
fn update_fade_out(vram: &mut VRamManager, time: u16) { fn update_fade_out(vram: &mut VRamManager, time: u16) {
let mut modified_palette = background::background.palettes[0].clone(); let mut modified_palette = background::background.palettes[0].clone();
let c = modified_palette.get_colour(2); let c = modified_palette.colour(2);
modified_palette.update_colour(0, interpolate_colour(17982, 0x7FFF, time, 600)); modified_palette.update_colour(0, interpolate_colour(17982, 0x7FFF, time, 600));
modified_palette.update_colour(1, interpolate_colour(22427, 0x7FFF, time, 600)); modified_palette.update_colour(1, interpolate_colour(22427, 0x7FFF, time, 600));

View file

@ -45,7 +45,7 @@ impl<'a> Sfx<'a> {
pub fn stop_music(&mut self) { pub fn stop_music(&mut self) {
if let Some(bgm) = &self.bgm { if let Some(bgm) = &self.bgm {
let channel = self.mixer.get_channel(bgm).unwrap(); let channel = self.mixer.channel(bgm).unwrap();
channel.stop(); channel.stop();
} }
self.bgm = None; self.bgm = None;
@ -53,7 +53,7 @@ impl<'a> Sfx<'a> {
pub fn purple_night(&mut self) { pub fn purple_night(&mut self) {
if let Some(bgm) = &self.bgm { if let Some(bgm) = &self.bgm {
let channel = self.mixer.get_channel(bgm).unwrap(); let channel = self.mixer.channel(bgm).unwrap();
channel.stop(); channel.stop();
} }
@ -64,7 +64,7 @@ impl<'a> Sfx<'a> {
pub fn sunrise(&mut self) { pub fn sunrise(&mut self) {
if let Some(bgm) = &self.bgm { if let Some(bgm) = &self.bgm {
let channel = self.mixer.get_channel(bgm).unwrap(); let channel = self.mixer.channel(bgm).unwrap();
channel.stop(); channel.stop();
} }
@ -75,7 +75,7 @@ impl<'a> Sfx<'a> {
pub fn boss(&mut self) { pub fn boss(&mut self) {
if let Some(bgm) = &self.bgm { if let Some(bgm) = &self.bgm {
let channel = self.mixer.get_channel(bgm).unwrap(); let channel = self.mixer.channel(bgm).unwrap();
channel.stop(); channel.stop();
} }