improve the migration

This commit is contained in:
Corwin 2023-04-05 18:35:45 +01:00
parent 78eebdd270
commit c84e81299b
No known key found for this signature in database
14 changed files with 172 additions and 179 deletions

View file

@ -4,7 +4,7 @@
use agb::{
display::tiled::{TileFormat, TileSet, TileSetting, TiledMap},
display::{
object::{OamManager, Object, Size, Sprite},
object::{OamManaged, Object, Size, Sprite},
palette16::Palette16,
tiled::RegularBackgroundSize,
HEIGHT, WIDTH,
@ -76,9 +76,9 @@ fn main(mut gba: agb::Gba) -> ! {
let object = gba.display.object.get_managed();
let sprite = object.get_vram_sprite(&CHICKEN_SPRITES[0]);
let sprite = object.get_sprite(&CHICKEN_SPRITES[0]);
let mut chicken = Character {
object: object.add_object(sprite),
object: object.object(sprite),
position: Vector2D {
x: (6 * 8) << 8,
y: ((7 * 8) - 4) << 8,
@ -145,7 +145,7 @@ fn main(mut gba: agb::Gba) -> ! {
fn update_chicken_object(
chicken: &'_ mut Character<'_>,
gfx: &OamManager,
gfx: &OamManaged,
state: State,
frame_count: u32,
) {
@ -158,19 +158,19 @@ fn update_chicken_object(
State::Ground => {
if chicken.velocity.x.abs() > 1 << 4 {
chicken.object.set_sprite(
gfx.get_vram_sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 1, 3, 10)]),
gfx.get_sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 1, 3, 10)]),
);
} else {
chicken
.object
.set_sprite(gfx.get_vram_sprite(&CHICKEN_SPRITES[0]));
.set_sprite(gfx.get_sprite(&CHICKEN_SPRITES[0]));
}
}
State::Upwards => {}
State::Flapping => {
chicken.object.set_sprite(
gfx.get_vram_sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 4, 5, 5)]),
);
chicken
.object
.set_sprite(gfx.get_sprite(&CHICKEN_SPRITES[frame_ranger(frame_count, 4, 5, 5)]));
}
}

View file

@ -5,7 +5,7 @@ extern crate alloc;
use agb::display::{
affine::AffineMatrix,
object::{self, Graphics, OamManager, Sprite, TagMap},
object::{self, Graphics, OamManaged, Sprite, TagMap},
};
use agb::fixnum::num;
use agb_fixnum::Num;
@ -20,7 +20,7 @@ const GRAPHICS: &Graphics = agb::include_aseprite!(
const SPRITES: &[Sprite] = GRAPHICS.sprites();
const TAG_MAP: &TagMap = GRAPHICS.tags();
fn all_sprites(gfx: &OamManager, rotation_speed: Num<i32, 16>) {
fn all_sprites(gfx: &OamManaged, rotation_speed: Num<i32, 16>) {
let mut input = agb::input::ButtonController::new();
let mut objs = Vec::new();
@ -31,7 +31,7 @@ fn all_sprites(gfx: &OamManager, rotation_speed: Num<i32, 16>) {
for y in 0..9 {
for x in 0..14 {
let mut obj = gfx.add_object_static_sprite(&SPRITES[0]);
let mut obj = gfx.object_sprite(&SPRITES[0]);
obj.set_affine_matrix(matrix.clone());
obj.show_affine(object::AffineMode::Affine);
obj.set_position((x * 16 + 8, y * 16 + 8).into());
@ -68,14 +68,14 @@ fn all_sprites(gfx: &OamManager, rotation_speed: Num<i32, 16>) {
image %= SPRITES.len();
for (i, obj) in objs.iter_mut().enumerate() {
let this_image = (image + i) % SPRITES.len();
obj.set_sprite(gfx.get_vram_sprite(&SPRITES[this_image]));
obj.set_sprite(gfx.get_sprite(&SPRITES[this_image]));
}
}
gfx.commit();
}
}
fn all_tags(gfx: &OamManager) {
fn all_tags(gfx: &OamManaged) {
let mut input = agb::input::ButtonController::new();
let mut objs = Vec::new();
@ -85,7 +85,7 @@ fn all_tags(gfx: &OamManager) {
let sprite = v.sprite(0);
let (size_x, size_y) = sprite.size().to_width_height();
let (size_x, size_y) = (size_x as i32, size_y as i32);
let mut obj = gfx.add_object_static_sprite(sprite);
let mut obj = gfx.object_sprite(sprite);
obj.show();
obj.set_position((x * 32 + 16 - size_x / 2, y * 32 + 16 - size_y / 2).into());
objs.push((obj, v));
@ -110,7 +110,7 @@ fn all_tags(gfx: &OamManager) {
if count % 5 == 0 {
image += 1;
for (obj, tag) in objs.iter_mut() {
obj.set_sprite(gfx.get_vram_sprite(tag.animation_sprite(image)));
obj.set_sprite(gfx.get_sprite(tag.animation_sprite(image)));
}
gfx.commit();
}

View file

@ -6,7 +6,7 @@ use video::Video;
use self::{
blend::Blend,
object::{initilise_oam, OamManager, OamUnmanaged, SpriteLoader},
object::{initilise_oam, OamManaged, OamUnmanaged, SpriteLoader},
window::Windows,
};
@ -89,9 +89,9 @@ impl ObjectDistribution {
(OamUnmanaged::new(), SpriteLoader::new())
}
pub fn get_managed(&mut self) -> OamManager<'_> {
pub fn get_managed(&mut self) -> OamManaged<'_> {
unsafe { initilise_oam() };
OamManager::new()
OamManaged::new()
}
}

View file

@ -8,7 +8,7 @@ pub use sprites::{
};
pub use affine::AffineMatrixInstance;
pub use managed::{OamManager, Object};
pub use managed::{OamManaged, Object};
pub use unmanaged::{AffineMode, OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged};
use super::DISPLAY_CONTROL;

View file

@ -125,13 +125,13 @@ impl Store {
}
}
pub struct OamManager<'gba> {
pub struct OamManaged<'gba> {
object_store: Store,
sprite_loader: UnsafeCell<SpriteLoader>,
unmanaged: UnsafeCell<OamUnmanaged<'gba>>,
}
impl OamManager<'_> {
impl OamManaged<'_> {
pub(crate) fn new() -> Self {
Self {
object_store: Store {
@ -172,20 +172,20 @@ impl OamManager<'_> {
}
}
pub fn add_object(&self, sprite: SpriteVram) -> Object<'_> {
pub fn object(&self, sprite: SpriteVram) -> Object<'_> {
self.object_store
.insert_object(ObjectUnmanaged::new(sprite))
}
pub fn get_vram_sprite(&self, sprite: &'static Sprite) -> SpriteVram {
pub fn get_sprite(&self, sprite: &'static Sprite) -> SpriteVram {
// safety: not reentrant
unsafe {
self.do_work_with_sprite_loader(|sprite_loader| sprite_loader.get_vram_sprite(sprite))
}
}
pub fn add_object_static_sprite(&self, sprite: &'static Sprite) -> Object<'_> {
self.add_object(self.get_vram_sprite(sprite))
pub fn object_sprite(&self, sprite: &'static Sprite) -> Object<'_> {
self.object(self.get_sprite(sprite))
}
}
@ -449,11 +449,11 @@ mod tests {
fn test_always_ordered(gba: &mut crate::Gba) {
let managed = gba.display.object.get_managed();
let sprite = managed.get_vram_sprite(TEST_SPRITE);
let sprite = managed.get_sprite(TEST_SPRITE);
let mut objects = Vec::new();
for _ in 0..200 {
let obj = managed.add_object(sprite.clone());
let obj = managed.object(sprite.clone());
objects.push(obj);
}

View file

@ -32,7 +32,7 @@ const BALL: &Tag = GRAPHICS.tags().get("Ball");
#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
// Get the OAM manager
let object = gba.display.object.get();
let object = gba.display.object.get_managed();
// Create an object with the ball sprite
let mut ball = object.object_sprite(BALL.sprite(0));

View file

@ -494,7 +494,7 @@ pub(crate) fn battle_screen(
let obj = &agb.obj;
let mut select_box_obj = agb.obj.add_object_static_sprite(SELECT_BOX.sprite(0));
let mut select_box_obj = agb.obj.object_sprite(SELECT_BOX.sprite(0));
select_box_obj.show();
let num_dice = player_dice.dice.len();
@ -587,7 +587,7 @@ pub(crate) fn battle_screen(
.set_x(selected_die as u16 * 40 + 28 - 4)
.set_sprite(
agb.obj
.get_vram_sprite(SELECT_BOX.animation_sprite(counter / 10)),
.get_sprite(SELECT_BOX.animation_sprite(counter / 10)),
);
agb.star_background.update();

View file

@ -1,4 +1,4 @@
use agb::display::object::{OamManager, Object};
use agb::display::object::{OamManaged, Object};
use agb::rng;
use alloc::vec;
use alloc::vec::Vec;
@ -39,7 +39,7 @@ pub struct BattleScreenDisplay<'a> {
const HEALTH_BAR_WIDTH: usize = 48;
impl<'a> BattleScreenDisplay<'a> {
pub fn new(obj: &'a OamManager, current_battle_state: &CurrentBattleState) -> Self {
pub fn new(obj: &'a OamManaged, current_battle_state: &CurrentBattleState) -> Self {
let mut misc_sprites = vec![];
let player_x = 12;
let player_y = 8;
@ -52,8 +52,8 @@ impl<'a> BattleScreenDisplay<'a> {
Ship::PilotedShip
});
let mut player_obj = obj.add_object_static_sprite(player_sprite);
let mut enemy_obj = obj.add_object_static_sprite(enemy_sprite);
let mut player_obj = obj.object_sprite(player_sprite);
let mut enemy_obj = obj.object_sprite(enemy_sprite);
player_obj.set_x(player_x).set_y(player_y).set_z(1).show();
enemy_obj.set_x(enemy_x).set_y(player_y).set_z(1).show();
@ -66,7 +66,7 @@ impl<'a> BattleScreenDisplay<'a> {
.faces_to_render()
.enumerate()
.map(|(i, (face, _))| {
let mut die_obj = obj.add_object_static_sprite(FACE_SPRITES.sprite_for_face(face));
let mut die_obj = obj.object_sprite(FACE_SPRITES.sprite_for_face(face));
die_obj.set_y(120).set_x(i as u16 * 40 + 28).show();
@ -89,7 +89,7 @@ impl<'a> BattleScreenDisplay<'a> {
let player_shield: Vec<_> = (0..5)
.map(|i| {
let mut shield_obj = obj.add_object_static_sprite(shield_sprite);
let mut shield_obj = obj.object_sprite(shield_sprite);
shield_obj
.set_x(player_x + 18 + 11 * i)
.set_y(player_y)
@ -101,7 +101,7 @@ impl<'a> BattleScreenDisplay<'a> {
let enemy_shield: Vec<_> = (0..5)
.map(|i| {
let mut shield_obj = obj.add_object_static_sprite(shield_sprite);
let mut shield_obj = obj.object_sprite(shield_sprite);
shield_obj
.set_x(enemy_x - 16 - 11 * i)
.set_y(player_y)
@ -146,9 +146,8 @@ impl<'a> BattleScreenDisplay<'a> {
let enemy_attack_display = (0..2)
.map(|i| {
let mut attack_obj = obj.add_object_static_sprite(
ENEMY_ATTACK_SPRITES.sprite_for_attack(EnemyAttackType::Attack),
);
let mut attack_obj = obj
.object_sprite(ENEMY_ATTACK_SPRITES.sprite_for_attack(EnemyAttackType::Attack));
let attack_obj_position = (120, 56 + 32 * i).into();
attack_obj.set_position(attack_obj_position).hide();
@ -189,14 +188,14 @@ impl<'a> BattleScreenDisplay<'a> {
pub fn update(
&mut self,
obj: &'a OamManager,
obj: &'a OamManaged,
current_battle_state: &CurrentBattleState,
) -> Vec<Action> {
for (i, player_shield) in self.objs.player_shield.iter_mut().enumerate() {
if i < current_battle_state.player.shield_count as usize {
player_shield
.show()
.set_sprite(obj.get_vram_sprite(SHIELD.sprite(0)));
.set_sprite(obj.get_sprite(SHIELD.sprite(0)));
} else {
player_shield.hide();
}
@ -206,7 +205,7 @@ impl<'a> BattleScreenDisplay<'a> {
if i < current_battle_state.enemy.shield_count as usize {
player_shield
.show()
.set_sprite(obj.get_vram_sprite(SHIELD.sprite(0)));
.set_sprite(obj.get_sprite(SHIELD.sprite(0)));
} else {
player_shield.hide();
}
@ -250,7 +249,7 @@ impl<'a> BattleScreenDisplay<'a> {
.zip(current_battle_state.rolled_dice.faces_to_render())
.zip(self.objs.dice_cooldowns.iter_mut())
{
die_obj.set_sprite(obj.get_vram_sprite(FACE_SPRITES.sprite_for_face(current_face)));
die_obj.set_sprite(obj.get_sprite(FACE_SPRITES.sprite_for_face(current_face)));
if let Some(cooldown) = cooldown {
cooldown_healthbar
@ -279,7 +278,7 @@ impl<'a> BattleScreenDisplay<'a> {
actions_to_apply
}
pub fn add_action(&mut self, action: Action, obj: &'a OamManager, sfx: &mut Sfx) {
pub fn add_action(&mut self, action: Action, obj: &'a OamManaged, sfx: &mut Sfx) {
play_sound_for_action_start(&action, sfx);
self.animations
@ -309,10 +308,10 @@ impl<'a> EnemyAttackDisplay<'a> {
}
}
pub fn update(&mut self, attack: &Option<EnemyAttackState>, obj: &'a OamManager) {
pub fn update(&mut self, attack: &Option<EnemyAttackState>, obj: &'a OamManaged) {
if let Some(attack) = attack {
self.face.show().set_sprite(
obj.get_vram_sprite(ENEMY_ATTACK_SPRITES.sprite_for_attack(attack.attack_type())),
obj.get_sprite(ENEMY_ATTACK_SPRITES.sprite_for_attack(attack.attack_type())),
);
self.cooldown
.set_value((attack.cooldown * 48 / attack.max_cooldown) as usize, obj);
@ -350,27 +349,27 @@ enum AnimationUpdateState {
}
impl<'a> AnimationStateHolder<'a> {
fn for_action(a: Action, obj: &'a OamManager) -> Self {
fn for_action(a: Action, obj: &'a OamManaged) -> Self {
let state = match a {
Action::PlayerActivateShield { amount, .. } => {
AnimationState::PlayerActivateShield { amount, frame: 0 }
}
Action::PlayerShoot { .. } => AnimationState::PlayerShoot {
bullet: obj.add_object_static_sprite(BULLET_SPRITE),
bullet: obj.object_sprite(BULLET_SPRITE),
x: 64,
},
Action::PlayerDisrupt { .. } => AnimationState::PlayerDisrupt {
bullet: obj.add_object_static_sprite(DISRUPT_BULLET),
bullet: obj.object_sprite(DISRUPT_BULLET),
x: 64,
},
Action::PlayerHeal { .. } => AnimationState::PlayerHeal {},
Action::PlayerBurstShield { .. } => AnimationState::PlayerBurstShield { frame: 0 },
Action::PlayerSendBurstShield { .. } => AnimationState::PlayerSendBurstShield {
bullet: obj.add_object_static_sprite(BURST_BULLET),
bullet: obj.object_sprite(BURST_BULLET),
x: 64,
},
Action::EnemyShoot { .. } => AnimationState::EnemyShoot {
bullet: obj.add_object_static_sprite(BULLET_SPRITE),
bullet: obj.object_sprite(BULLET_SPRITE),
x: 175,
},
Action::EnemyShield { amount, .. } => AnimationState::EnemyShield { amount, frame: 0 },
@ -383,7 +382,7 @@ impl<'a> AnimationStateHolder<'a> {
fn update(
&mut self,
objs: &mut BattleScreenDisplayObjects<'a>,
obj: &'a OamManager,
obj: &'a OamManaged,
current_battle_state: &CurrentBattleState,
) -> AnimationUpdateState {
match &mut self.state {
@ -414,7 +413,7 @@ impl<'a> AnimationStateHolder<'a> {
for i in current_player_shields..*amount {
objs.player_shield[i as usize]
.show()
.set_sprite(obj.get_vram_sprite(SHIELD.sprite(3 - *frame / 2)));
.set_sprite(obj.get_sprite(SHIELD.sprite(3 - *frame / 2)));
}
} else {
return AnimationUpdateState::RemoveWithAction(self.action.clone());
@ -445,7 +444,7 @@ impl<'a> AnimationStateHolder<'a> {
for i in current_enemy_shields..*amount {
objs.enemy_shield[i as usize]
.show()
.set_sprite(obj.get_vram_sprite(SHIELD.sprite(3 - *frame / 2)));
.set_sprite(obj.get_sprite(SHIELD.sprite(3 - *frame / 2)));
}
} else {
return AnimationUpdateState::RemoveWithAction(self.action.clone());
@ -468,7 +467,7 @@ impl<'a> AnimationStateHolder<'a> {
AnimationState::PlayerBurstShield { frame } => {
if *frame < 10 {
for shield in objs.player_shield.iter_mut() {
shield.set_sprite(obj.get_vram_sprite(SHIELD.sprite(*frame / 2)));
shield.set_sprite(obj.get_sprite(SHIELD.sprite(*frame / 2)));
}
*frame += 1;
@ -476,7 +475,7 @@ impl<'a> AnimationStateHolder<'a> {
AnimationUpdateState::Continue
} else {
for shield in objs.player_shield.iter_mut() {
shield.set_sprite(obj.get_vram_sprite(SHIELD.sprite(0)));
shield.set_sprite(obj.get_sprite(SHIELD.sprite(0)));
}
AnimationUpdateState::RemoveWithAction(self.action.clone())

View file

@ -1,6 +1,6 @@
use agb::{
display::{
object::{OamManager, Object},
object::{OamManaged, Object},
tiled::{RegularMap, TiledMap},
HEIGHT, WIDTH,
},
@ -91,10 +91,10 @@ fn move_net_position_ud(idx: usize, direction: Tri) -> usize {
}
}
fn create_dice_display<'a>(gfx: &'a OamManager, dice: &'_ PlayerDice) -> Vec<Object<'a>> {
fn create_dice_display<'a>(gfx: &'a OamManaged, dice: &'_ PlayerDice) -> Vec<Object<'a>> {
let mut objects = Vec::new();
for (idx, dice) in dice.dice.iter().enumerate() {
let mut obj = gfx.add_object_static_sprite(FACE_SPRITES.sprite_for_face(dice.faces[1]));
let mut obj = gfx.object_sprite(FACE_SPRITES.sprite_for_face(dice.faces[1]));
obj.set_x((idx as i32 * 32 - 24 / 2 + 20) as u16);
obj.set_y(16 - 24 / 2);
@ -105,10 +105,10 @@ fn create_dice_display<'a>(gfx: &'a OamManager, dice: &'_ PlayerDice) -> Vec<Obj
objects
}
fn create_net<'a>(gfx: &'a OamManager, die: &'_ Die, modified: &[usize]) -> Vec<Object<'a>> {
fn create_net<'a>(gfx: &'a OamManaged, die: &'_ Die, modified: &[usize]) -> Vec<Object<'a>> {
let mut objects = Vec::new();
for (idx, &face) in die.faces.iter().enumerate() {
let mut obj = gfx.add_object_static_sprite(FACE_SPRITES.sprite_for_face(face));
let mut obj = gfx.object_sprite(FACE_SPRITES.sprite_for_face(face));
let (x, y) = screen_position_for_index(idx);
obj.set_x((x - 24 / 2) as u16);
obj.set_y((y - 24 / 2) as u16);
@ -119,7 +119,7 @@ fn create_net<'a>(gfx: &'a OamManager, die: &'_ Die, modified: &[usize]) -> Vec<
}
for &m in modified.iter().chain(core::iter::once(&3)) {
let mut obj = gfx.add_object_static_sprite(MODIFIED_BOX);
let mut obj = gfx.object_sprite(MODIFIED_BOX);
let (x, y) = screen_position_for_index(m);
obj.set_x((x - 32 / 2) as u16);
obj.set_y((y - 32 / 2) as u16);
@ -139,10 +139,10 @@ fn upgrade_position(idx: usize) -> (u32, u32) {
)
}
fn create_upgrade_objects<'a>(gfx: &'a OamManager, upgrades: &[Face]) -> Vec<Object<'a>> {
fn create_upgrade_objects<'a>(gfx: &'a OamManaged, upgrades: &[Face]) -> Vec<Object<'a>> {
let mut objects = Vec::new();
for (idx, &upgrade) in upgrades.iter().enumerate() {
let mut obj = gfx.add_object_static_sprite(FACE_SPRITES.sprite_for_face(upgrade));
let mut obj = gfx.object_sprite(FACE_SPRITES.sprite_for_face(upgrade));
let (x, y) = upgrade_position(idx);
obj.set_x((x - 24 / 2) as u16);
obj.set_y((y - 24 / 2) as u16);
@ -180,13 +180,13 @@ pub(crate) fn customise_screen(
let mut input = agb::input::ButtonController::new();
let mut select_box = agb.obj.add_object_static_sprite(SELECT_BOX.sprite(0));
let mut select_box = agb.obj.object_sprite(SELECT_BOX.sprite(0));
select_box.show();
let mut selected_dice = agb.obj.add_object_static_sprite(SELECTED_BOX);
let mut selected_dice = agb.obj.object_sprite(SELECTED_BOX);
selected_dice.hide();
let mut selected_face = agb.obj.add_object_static_sprite(SELECTED_BOX);
let mut selected_face = agb.obj.object_sprite(SELECTED_BOX);
selected_face.hide();
agb.sfx.frame();
@ -340,7 +340,7 @@ pub(crate) fn customise_screen(
select_box.set_sprite(
agb.obj
.get_vram_sprite(SELECT_BOX.animation_sprite(counter / 10)),
.get_sprite(SELECT_BOX.animation_sprite(counter / 10)),
);
agb.star_background.update();

View file

@ -1,5 +1,5 @@
use agb::{
display::object::{OamManager, Object, Sprite, Tag},
display::object::{OamManaged, Object, Sprite, Tag},
fixnum::Vector2D,
};
use alloc::vec::Vec;
@ -141,12 +141,12 @@ pub struct HealthBar<'a> {
}
impl<'a> HealthBar<'a> {
pub fn new(pos: Vector2D<i32>, max: usize, obj: &'a OamManager) -> Self {
pub fn new(pos: Vector2D<i32>, max: usize, obj: &'a OamManaged) -> Self {
assert_eq!(max % 8, 0);
let sprites = (0..(max / 8))
.map(|i| {
let mut health_object = obj.add_object_static_sprite(SMALL_SPRITES.red_bar(0));
let mut health_object = obj.object_sprite(SMALL_SPRITES.red_bar(0));
health_object
.set_position(pos + (i as i32 * 8, 0).into())
.show();
@ -157,18 +157,16 @@ impl<'a> HealthBar<'a> {
Self { max, sprites }
}
pub fn set_value(&mut self, new_value: usize, obj: &'a OamManager) {
pub fn set_value(&mut self, new_value: usize, obj: &'a OamManaged) {
assert!(new_value <= self.max);
for (i, sprite) in self.sprites.iter_mut().enumerate() {
if (i + 1) * 8 < new_value {
sprite.set_sprite(obj.get_vram_sprite(SMALL_SPRITES.red_bar(0)));
sprite.set_sprite(obj.get_sprite(SMALL_SPRITES.red_bar(0)));
} else if i * 8 < new_value {
sprite.set_sprite(
obj.get_vram_sprite(SMALL_SPRITES.red_bar(8 - (new_value - i * 8))),
);
sprite.set_sprite(obj.get_sprite(SMALL_SPRITES.red_bar(8 - (new_value - i * 8))));
} else {
sprite.set_sprite(obj.get_vram_sprite(SMALL_SPRITES.red_bar(8)));
sprite.set_sprite(obj.get_sprite(SMALL_SPRITES.red_bar(8)));
}
}
}
@ -195,22 +193,22 @@ pub struct FractionDisplay<'a> {
}
impl<'a> FractionDisplay<'a> {
pub fn new(pos: Vector2D<i32>, digits: usize, obj: &'a OamManager) -> Self {
pub fn new(pos: Vector2D<i32>, digits: usize, obj: &'a OamManaged) -> Self {
let mut sprites = Vec::with_capacity(digits * 2 + 1);
for i in 0..digits {
let mut left_digit = obj.add_object_static_sprite(SMALL_SPRITES.number(0));
let mut left_digit = obj.object_sprite(SMALL_SPRITES.number(0));
left_digit.set_position(pos + (i as i32 * 4, 0).into());
sprites.push(left_digit);
let mut right_digit = obj.add_object_static_sprite(SMALL_SPRITES.number(0));
let mut right_digit = obj.object_sprite(SMALL_SPRITES.number(0));
right_digit.set_position(pos + (i as i32 * 4 + digits as i32 * 4 + 7, 0).into());
sprites.push(right_digit);
}
let mut slash = obj.add_object_static_sprite(SMALL_SPRITES.slash());
let mut slash = obj.object_sprite(SMALL_SPRITES.slash());
slash.set_position(pos + (digits as i32 * 4 + 1, 0).into());
sprites.push(slash);
@ -222,7 +220,7 @@ impl<'a> FractionDisplay<'a> {
}
}
pub fn set_value(&mut self, current: usize, max: usize, obj: &'a OamManager) {
pub fn set_value(&mut self, current: usize, max: usize, obj: &'a OamManaged) {
if self.current_current == current && self.current_max == max {
return;
}
@ -235,13 +233,13 @@ impl<'a> FractionDisplay<'a> {
current /= 10;
let current_value_sprite = &mut self.sprites[(self.digits - i) * 2 - 2];
current_value_sprite
.set_sprite(obj.get_vram_sprite(SMALL_SPRITES.number(current_value_digit as u32)));
.set_sprite(obj.get_sprite(SMALL_SPRITES.number(current_value_digit as u32)));
let max_value_digit = max % 10;
max /= 10;
let max_value_sprite = &mut self.sprites[(self.digits - i) * 2 - 1];
max_value_sprite
.set_sprite(obj.get_vram_sprite(SMALL_SPRITES.number(max_value_digit as u32)));
.set_sprite(obj.get_sprite(SMALL_SPRITES.number(max_value_digit as u32)));
}
}
}
@ -261,7 +259,7 @@ impl<'a> NumberDisplay<'a> {
}
}
pub fn set_value(&mut self, new_value: Option<u32>, obj: &'a OamManager) {
pub fn set_value(&mut self, new_value: Option<u32>, obj: &'a OamManaged) {
if self.value == new_value {
return;
}
@ -272,7 +270,7 @@ impl<'a> NumberDisplay<'a> {
if let Some(mut new_value) = new_value {
if new_value == 0 {
let mut zero_object = obj.add_object_static_sprite(SMALL_SPRITES.number(0));
let mut zero_object = obj.object_sprite(SMALL_SPRITES.number(0));
zero_object.show().set_position(self.position);
self.objects.push(zero_object);
@ -285,7 +283,7 @@ impl<'a> NumberDisplay<'a> {
new_value /= 10;
let mut current_value_obj =
obj.add_object_static_sprite(SMALL_SPRITES.number(current_value_digit));
obj.object_sprite(SMALL_SPRITES.number(current_value_digit));
current_value_obj
.show()

View file

@ -12,7 +12,7 @@
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
#![cfg_attr(test, test_runner(agb::test_runner::test_runner))]
use agb::display::object::OamManager;
use agb::display::object::OamManaged;
use agb::display::tiled::{TileFormat, TiledMap, VRamManager};
use agb::display::Priority;
use agb::interrupt::VBlank;
@ -90,7 +90,7 @@ pub struct PlayerDice {
}
struct Agb<'a> {
obj: OamManager<'a>,
obj: OamManaged<'a>,
vblank: VBlank,
star_background: StarBackground<'a>,
vram: VRamManager,

View file

@ -2,7 +2,7 @@ use crate::TAG_MAP;
use super::{sfx::SfxPlayer, Entity, FixedNumberType, HatState, Level};
use agb::{
display::object::{OamManager, Tag},
display::object::{OamManaged, Tag},
fixnum::Vector2D,
};
@ -35,11 +35,11 @@ pub enum EnemyUpdateState {
}
impl<'a> Enemy<'a> {
pub fn new_slime(object: &'a OamManager, start_pos: Vector2D<FixedNumberType>) -> Self {
pub fn new_slime(object: &'a OamManaged, start_pos: Vector2D<FixedNumberType>) -> Self {
Enemy::Slime(Slime::new(object, start_pos + (0, 1).into()))
}
pub fn new_snail(object: &'a OamManager, start_pos: Vector2D<FixedNumberType>) -> Self {
pub fn new_snail(object: &'a OamManaged, start_pos: Vector2D<FixedNumberType>) -> Self {
Enemy::Snail(Snail::new(object, start_pos))
}
@ -52,7 +52,7 @@ impl<'a> Enemy<'a> {
pub fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
level: &Level,
player_pos: Vector2D<FixedNumberType>,
hat_state: HatState,
@ -94,7 +94,7 @@ struct EnemyInfo<'a> {
impl<'a> EnemyInfo<'a> {
fn new(
object: &'a OamManager,
object: &'a OamManaged,
start_pos: Vector2D<FixedNumberType>,
collision: Vector2D<u16>,
) -> Self {
@ -135,7 +135,7 @@ pub struct Slime<'a> {
}
impl<'a> Slime<'a> {
fn new(object: &'a OamManager, start_pos: Vector2D<FixedNumberType>) -> Self {
fn new(object: &'a OamManaged, start_pos: Vector2D<FixedNumberType>) -> Self {
let slime = Slime {
enemy_info: EnemyInfo::new(object, start_pos, (14u16, 14u16).into()),
state: SlimeState::Idle,
@ -146,7 +146,7 @@ impl<'a> Slime<'a> {
fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
level: &Level,
player_pos: Vector2D<FixedNumberType>,
hat_state: HatState,
@ -161,7 +161,7 @@ impl<'a> Slime<'a> {
let offset = (timer / 16) as usize;
let frame = SLIME_IDLE.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
@ -201,7 +201,7 @@ impl<'a> Slime<'a> {
self.state = SlimeState::Idle;
} else {
let frame = SLIME_JUMP.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
}
@ -227,7 +227,7 @@ impl<'a> Slime<'a> {
}
let frame = SLIME_SPLAT.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
}
@ -257,7 +257,7 @@ pub struct Snail<'a> {
}
impl<'a> Snail<'a> {
fn new(object: &'a OamManager, start_pos: Vector2D<FixedNumberType>) -> Self {
fn new(object: &'a OamManaged, start_pos: Vector2D<FixedNumberType>) -> Self {
let snail = Snail {
enemy_info: EnemyInfo::new(object, start_pos, (16u16, 16u16).into()),
state: SnailState::Idle(0),
@ -272,7 +272,7 @@ impl<'a> Snail<'a> {
fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
level: &Level,
player_pos: Vector2D<FixedNumberType>,
hat_state: HatState,
@ -298,7 +298,7 @@ impl<'a> Snail<'a> {
}
let frame = SNAIL_IDLE.animation_sprite(0);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
if player_has_collided {
@ -318,7 +318,7 @@ impl<'a> Snail<'a> {
self.enemy_info.entity.velocity = (0, 0).into();
let frame = SNAIL_EMERGE.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
@ -340,7 +340,7 @@ impl<'a> Snail<'a> {
let offset = (timer - time) as usize / 8;
let frame = SNAIL_MOVE.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
@ -374,7 +374,7 @@ impl<'a> Snail<'a> {
}
let frame = SNAIL_EMERGE.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
self.enemy_info.entity.velocity = (0, 0).into();
@ -403,7 +403,7 @@ impl<'a> Snail<'a> {
return UpdateState::Remove;
};
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.enemy_info.entity.sprite.set_sprite(sprite);
self.enemy_info.entity.velocity = (0, 0).into();

View file

@ -8,7 +8,7 @@ extern crate alloc;
use agb::{
display::{
object::{Graphics, OamManager, Object, Tag, TagMap},
object::{Graphics, OamManaged, Object, Tag, TagMap},
tiled::{
InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet,
TileSetting, TiledMap, VRamManager,
@ -124,8 +124,8 @@ pub struct Entity<'a> {
}
impl<'a> Entity<'a> {
pub fn new(object: &'a OamManager, collision_mask: Vector2D<u16>) -> Self {
let mut dummy_object = object.add_object_static_sprite(WALKING.sprite(0));
pub fn new(object: &'a OamManaged, collision_mask: Vector2D<u16>) -> Self {
let mut dummy_object = object.object_sprite(WALKING.sprite(0));
dummy_object.set_priority(Priority::P1);
Entity {
sprite: dummy_object,
@ -347,15 +347,15 @@ fn ping_pong(i: i32, n: i32) -> i32 {
}
impl<'a> Player<'a> {
fn new(controller: &'a OamManager, start_position: Vector2D<FixedNumberType>) -> Self {
fn new(controller: &'a OamManaged, start_position: Vector2D<FixedNumberType>) -> Self {
let mut wizard = Entity::new(controller, (6_u16, 14_u16).into());
let mut hat = Entity::new(controller, (6_u16, 6_u16).into());
wizard
.sprite
.set_sprite(controller.get_vram_sprite(HAT_SPIN_1.sprite(0)));
.set_sprite(controller.get_sprite(HAT_SPIN_1.sprite(0)));
hat.sprite
.set_sprite(controller.get_vram_sprite(HAT_SPIN_1.sprite(0)));
.set_sprite(controller.get_sprite(HAT_SPIN_1.sprite(0)));
wizard.sprite.show();
hat.sprite.show();
@ -381,7 +381,7 @@ impl<'a> Player<'a> {
fn update_frame(
&mut self,
input: &ButtonController,
controller: &'a OamManager,
controller: &'a OamManaged,
timer: i32,
level: &Level,
enemies: &[enemies::Enemy],
@ -460,7 +460,7 @@ impl<'a> Player<'a> {
self.wizard_frame = offset as u8;
let frame = WALKING.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.wizard.sprite.set_sprite(sprite);
}
@ -470,7 +470,7 @@ impl<'a> Player<'a> {
self.wizard_frame = 5;
let frame = JUMPING.animation_sprite(0);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.wizard.sprite.set_sprite(sprite);
} else if self.wizard.velocity.y > FixedNumberType::new(1) / 16 {
@ -485,7 +485,7 @@ impl<'a> Player<'a> {
self.wizard_frame = 0;
let frame = FALLING.animation_sprite(offset);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.wizard.sprite.set_sprite(sprite);
}
@ -512,13 +512,13 @@ impl<'a> Player<'a> {
self.wizard.sprite.set_hflip(true);
self.hat
.sprite
.set_sprite(controller.get_vram_sprite(hat_base_tile.sprite(5)));
.set_sprite(controller.get_sprite(hat_base_tile.sprite(5)));
}
agb::input::Tri::Positive => {
self.wizard.sprite.set_hflip(false);
self.hat
.sprite
.set_sprite(controller.get_vram_sprite(hat_base_tile.sprite(0)));
.set_sprite(controller.get_sprite(hat_base_tile.sprite(0)));
}
_ => {}
}
@ -544,7 +544,7 @@ impl<'a> Player<'a> {
let hat_sprite_offset = (timer / hat_sprite_divider) as usize;
self.hat.sprite.set_sprite(
controller.get_vram_sprite(hat_base_tile.animation_sprite(hat_sprite_offset)),
controller.get_sprite(hat_base_tile.animation_sprite(hat_sprite_offset)),
);
if self.hat_slow_counter < 30 && self.hat.velocity.magnitude() < 2.into() {
@ -577,7 +577,7 @@ impl<'a> Player<'a> {
}
HatState::WizardTowards => {
self.hat.sprite.set_sprite(
controller.get_vram_sprite(hat_base_tile.animation_sprite(timer as usize / 2)),
controller.get_sprite(hat_base_tile.animation_sprite(timer as usize / 2)),
);
let distance_vector =
self.hat.position - self.wizard.position + hat_resting_position;
@ -615,7 +615,7 @@ enum UpdateState {
impl<'a, 'b> PlayingLevel<'a, 'b> {
fn open_level(
level: &'a Level,
object_control: &'a OamManager,
object_control: &'a OamManaged,
background: &'a mut InfiniteScrolledMap<'b>,
foreground: &'a mut InfiniteScrolledMap<'b>,
input: ButtonController,
@ -676,11 +676,11 @@ impl<'a, 'b> PlayingLevel<'a, 'b> {
self.player.wizard.sprite.set_priority(Priority::P0);
}
fn dead_update(&mut self, controller: &'a OamManager) -> bool {
fn dead_update(&mut self, controller: &'a OamManaged) -> bool {
self.timer += 1;
let frame = PLAYER_DEATH.animation_sprite(self.timer as usize / 8);
let sprite = controller.get_vram_sprite(frame);
let sprite = controller.get_sprite(frame);
self.player.wizard.velocity += (0.into(), FixedNumberType::new(1) / 32).into();
self.player.wizard.position += self.player.wizard.velocity;
@ -695,7 +695,7 @@ impl<'a, 'b> PlayingLevel<'a, 'b> {
&mut self,
sfx_player: &mut SfxPlayer,
vram: &mut VRamManager,
controller: &'a OamManager,
controller: &'a OamManaged,
) -> UpdateState {
self.timer += 1;
self.input.update();

View file

@ -14,7 +14,7 @@ use alloc::{boxed::Box, vec::Vec};
use agb::{
display::{
object::{Graphics, OamManager, Object, Sprite, Tag, TagMap},
object::{Graphics, OamManaged, Object, Sprite, Tag, TagMap},
tiled::{
InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet, TileSetting,
VRamManager,
@ -164,8 +164,8 @@ struct Entity<'a> {
}
impl<'a> Entity<'a> {
fn new(object_controller: &'a OamManager, collision_mask: Rect<u16>) -> Self {
let mut sprite = object_controller.add_object_static_sprite(LONG_SWORD_IDLE.sprite(0));
fn new(object_controller: &'a OamManaged, collision_mask: Rect<u16>) -> Self {
let mut sprite = object_controller.object_sprite(LONG_SWORD_IDLE.sprite(0));
sprite.set_priority(Priority::P1);
Entity {
sprite,
@ -532,12 +532,12 @@ struct Player<'a> {
}
impl<'a> Player<'a> {
fn new(object_controller: &'a OamManager<'a>) -> Player {
fn new(object_controller: &'a OamManaged<'_>) -> Player<'a> {
let mut entity = Entity::new(
object_controller,
Rect::new((0_u16, 0_u16).into(), (4_u16, 12_u16).into()),
);
let s = object_controller.get_vram_sprite(LONG_SWORD_IDLE.sprite(0));
let s = object_controller.get_sprite(LONG_SWORD_IDLE.sprite(0));
entity.sprite.set_sprite(s);
entity.sprite.show();
entity.position = (144, 0).into();
@ -558,7 +558,7 @@ impl<'a> Player<'a> {
fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
buttons: &ButtonController,
level: &Level,
sfx: &mut sfx::Sfx,
@ -590,11 +590,11 @@ impl<'a> Player<'a> {
self.entity.velocity.x += self.sword.ground_walk_force() * x as i32;
if self.entity.velocity.x.abs() > Number::new(1) / 10 {
let sprite = controller
.get_vram_sprite(self.sword.walk_animation(self.sprite_offset));
.get_sprite(self.sword.walk_animation(self.sprite_offset));
self.entity.sprite.set_sprite(sprite);
} else {
let sprite = controller
.get_vram_sprite(self.sword.idle_animation(self.sprite_offset));
.get_sprite(self.sword.idle_animation(self.sprite_offset));
self.entity.sprite.set_sprite(sprite);
}
@ -614,8 +614,7 @@ impl<'a> Player<'a> {
let frame = self.sword.attack_frame(*a);
self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32;
let tag = self.sword.attack_tag();
let sprite =
controller.get_vram_sprite(tag.animation_sprite(frame as usize));
let sprite = controller.get_sprite(tag.animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite);
hurtbox = self.sword.ground_attack_hurtbox(frame);
@ -629,8 +628,7 @@ impl<'a> Player<'a> {
let frame = self.sword.hold_frame();
self.fudge_factor.x = self.sword.fudge(frame) * self.facing as i32;
let tag = self.sword.attack_tag();
let sprite =
controller.get_vram_sprite(tag.animation_sprite(frame as usize));
let sprite = controller.get_sprite(tag.animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite);
if *a == 0 {
self.attack_timer = AttackTimer::Idle;
@ -655,8 +653,7 @@ impl<'a> Player<'a> {
2
};
let tag = self.sword.jump_tag();
let sprite =
controller.get_vram_sprite(tag.animation_sprite(frame as usize));
let sprite = controller.get_sprite(tag.animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite);
if x != Tri::Zero {
@ -678,8 +675,7 @@ impl<'a> Player<'a> {
*a -= 1;
let frame = self.sword.jump_attack_frame(*a);
let tag = self.sword.jump_attack_tag();
let sprite =
controller.get_vram_sprite(tag.animation_sprite(frame as usize));
let sprite = controller.get_sprite(tag.animation_sprite(frame as usize));
self.entity.sprite.set_sprite(sprite);
hurtbox = self.sword.air_attack_hurtbox(frame);
@ -814,7 +810,7 @@ impl BatData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
level: &Level,
@ -842,7 +838,7 @@ impl BatData {
}
let sprite = BAT_IDLE.sprite(self.sprite_offset as usize / 8);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -877,7 +873,7 @@ impl BatData {
}
let sprite = BAT_IDLE.sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -904,7 +900,7 @@ impl BatData {
BatState::Dead => {
const BAT_DEAD: &Tag = TAG_MAP.get("bat dead");
let sprite = BAT_DEAD.sprite(0);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -947,7 +943,7 @@ impl SlimeData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
level: &Level,
@ -972,7 +968,7 @@ impl SlimeData {
const IDLE: &Tag = TAG_MAP.get("slime idle");
let sprite = IDLE.sprite(self.sprite_offset as usize / 16);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -1012,7 +1008,7 @@ impl SlimeData {
const CHASE: &Tag = TAG_MAP.get("Slime jump");
let sprite = CHASE.sprite(frame as usize);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -1042,7 +1038,7 @@ impl SlimeData {
if *count < 5 * 4 {
const DEATH: &Tag = TAG_MAP.get("Slime death");
let sprite = DEATH.sprite(*count as usize / 4);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
*count += 1;
@ -1076,7 +1072,7 @@ impl MiniFlameData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
_level: &Level,
@ -1110,7 +1106,7 @@ impl MiniFlameData {
}
} else {
let sprite = ANGRY.animation_sprite(self.sprite_offset as usize / 8);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
entity.velocity = (0.into(), Number::new(-1) / Number::new(4)).into();
@ -1158,7 +1154,7 @@ impl MiniFlameData {
}
let sprite = ANGRY.animation_sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
}
MiniFlameState::Dead => {
@ -1170,7 +1166,7 @@ impl MiniFlameData {
const DEATH: &Tag = TAG_MAP.get("angry boss dead");
let sprite = DEATH.animation_sprite(self.sprite_offset as usize / 12);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
self.sprite_offset += 1;
@ -1205,7 +1201,7 @@ impl EmuData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
level: &Level,
@ -1231,7 +1227,7 @@ impl EmuData {
const IDLE: &Tag = TAG_MAP.get("emu - idle");
let sprite = IDLE.sprite(self.sprite_offset as usize / 16);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
if (entity.position.y - player.entity.position.y).abs() < 10.into() {
@ -1278,7 +1274,7 @@ impl EmuData {
const WALK: &Tag = TAG_MAP.get("emu-walk");
let sprite = WALK.sprite(self.sprite_offset as usize / 2);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
let gravity: Number = 1.into();
@ -1333,7 +1329,7 @@ impl EmuData {
const DEATH: &Tag = TAG_MAP.get("emu - die");
let sprite = DEATH.animation_sprite(self.sprite_offset as usize / 4);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
self.sprite_offset += 1;
@ -1378,7 +1374,7 @@ impl EnemyData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
level: &Level,
@ -1399,11 +1395,11 @@ struct Enemy<'a> {
}
impl<'a> Enemy<'a> {
fn new(object_controller: &'a OamManager, enemy_data: EnemyData) -> Self {
fn new(object_controller: &'a OamManaged, enemy_data: EnemyData) -> Self {
let mut entity = Entity::new(object_controller, enemy_data.collision_mask());
let sprite = enemy_data.sprite();
let sprite = object_controller.get_vram_sprite(sprite);
let sprite = object_controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
entity.sprite.show();
@ -1413,7 +1409,7 @@ impl<'a> Enemy<'a> {
fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
player: &Player,
level: &Level,
sfx: &mut sfx::Sfx,
@ -1444,7 +1440,7 @@ impl ParticleData {
fn update<'a>(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
entity: &mut Entity<'a>,
player: &Player,
_level: &Level,
@ -1457,7 +1453,7 @@ impl ParticleData {
const DUST: &Tag = TAG_MAP.get("dust");
let sprite = DUST.sprite(*frame as usize / 3);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -1471,7 +1467,7 @@ impl ParticleData {
const HEALTH: &Tag = TAG_MAP.get("Heath");
let sprite = HEALTH.animation_sprite(*frame as usize / 3);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -1497,7 +1493,7 @@ impl ParticleData {
ParticleData::BossHealer(frame, target) => {
const HEALTH: &Tag = TAG_MAP.get("Heath");
let sprite = HEALTH.animation_sprite(*frame as usize / 3);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
entity.sprite.set_sprite(sprite);
@ -1532,7 +1528,7 @@ struct Particle<'a> {
impl<'a> Particle<'a> {
fn new(
object_controller: &'a OamManager,
object_controller: &'a OamManaged,
particle_data: ParticleData,
position: Vector2D<Number>,
) -> Self {
@ -1551,7 +1547,7 @@ impl<'a> Particle<'a> {
fn update(
&mut self,
controller: &'a OamManager,
controller: &'a OamManaged,
player: &Player,
level: &Level,
) -> UpdateInstruction {
@ -1578,7 +1574,7 @@ impl<'a> BossState<'a> {
fn update(
&mut self,
enemies: &mut Arena<Enemy<'a>>,
object_controller: &'a OamManager,
object_controller: &'a OamManaged,
player: &Player,
sfx: &mut sfx::Sfx,
) -> BossInstruction {
@ -1613,7 +1609,7 @@ struct FollowingBoss<'a> {
}
impl<'a> FollowingBoss<'a> {
fn new(object_controller: &'a OamManager, position: Vector2D<Number>) -> Self {
fn new(object_controller: &'a OamManaged, position: Vector2D<Number>) -> Self {
let mut entity = Entity::new(
object_controller,
Rect::new((0_u16, 0_u16).into(), (0_u16, 0_u16).into()),
@ -1628,7 +1624,7 @@ impl<'a> FollowingBoss<'a> {
gone: false,
}
}
fn update(&mut self, controller: &'a OamManager, player: &Player) {
fn update(&mut self, controller: &'a OamManaged, player: &Player) {
let difference = player.entity.position - self.entity.position;
self.timer += 1;
@ -1661,7 +1657,7 @@ impl<'a> FollowingBoss<'a> {
const BOSS: &Tag = TAG_MAP.get("happy boss");
let sprite = BOSS.animation_sprite(frame as usize);
let sprite = controller.get_vram_sprite(sprite);
let sprite = controller.get_sprite(sprite);
self.entity.sprite.set_sprite(sprite);
@ -1697,7 +1693,7 @@ enum BossInstruction {
}
impl<'a> Boss<'a> {
fn new(object_controller: &'a OamManager, screen_coords: Vector2D<Number>) -> Self {
fn new(object_controller: &'a OamManaged, screen_coords: Vector2D<Number>) -> Self {
let mut entity = Entity::new(
object_controller,
Rect::new((0_u16, 0_u16).into(), (28_u16, 28_u16).into()),
@ -1716,7 +1712,7 @@ impl<'a> Boss<'a> {
fn update(
&mut self,
enemies: &mut Arena<Enemy<'a>>,
object_controller: &'a OamManager,
object_controller: &'a OamManaged,
player: &Player,
sfx: &mut sfx::Sfx,
) -> BossInstruction {
@ -1797,7 +1793,7 @@ impl<'a> Boss<'a> {
const BOSS: &Tag = TAG_MAP.get("Boss");
let sprite = BOSS.animation_sprite(frame as usize);
let sprite = object_controller.get_vram_sprite(sprite);
let sprite = object_controller.get_sprite(sprite);
self.entity.sprite.set_sprite(sprite);
@ -1820,7 +1816,7 @@ impl<'a> Boss<'a> {
self.entity
.commit_with_size(offset + shake, (32, 32).into());
}
fn explode(&self, enemies: &mut Arena<Enemy<'a>>, object_controller: &'a OamManager) {
fn explode(&self, enemies: &mut Arena<Enemy<'a>>, object_controller: &'a OamManaged) {
for _ in 0..(6 - self.health) {
let x_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1;
let y_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1;
@ -1894,7 +1890,7 @@ impl<'a> Game<'a> {
fn advance_frame(
&mut self,
object_controller: &'a OamManager,
object_controller: &'a OamManaged,
vram: &mut VRamManager,
sfx: &mut sfx::Sfx,
) -> GameStatus {
@ -2108,7 +2104,7 @@ impl<'a> Game<'a> {
}
}
fn load_enemies(&mut self, object_controller: &'a OamManager) {
fn load_enemies(&mut self, object_controller: &'a OamManaged) {
if self.slime_load < self.level.slime_spawns.len() {
for (idx, slime_spawn) in self
.level
@ -2178,7 +2174,7 @@ impl<'a> Game<'a> {
vram.set_background_palettes(&modified_palettes);
}
fn new(object: &'a OamManager<'a>, level: Level<'a>, start_at_boss: bool) -> Self {
fn new(object: &'a OamManaged<'a>, level: Level<'a>, start_at_boss: bool) -> Self {
let mut player = Player::new(object);
let mut offset = (8, 8).into();
if start_at_boss {