From d6006c78089505049dcfce52e42dd4c9e11462fd Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 4 Apr 2023 17:35:53 +0100 Subject: [PATCH] rename parts of objects --- agb/examples/chicken.rs | 4 +-- agb/examples/sprites.rs | 10 +++--- agb/src/display/mod.rs | 10 +++--- agb/src/display/object.rs | 9 +++-- agb/src/display/object/affine.rs | 12 +++---- agb/src/display/object/managed.rs | 31 ++++++++--------- agb/src/display/object/sprites.rs | 2 +- .../object/sprites/sprite_allocator.rs | 6 ++-- agb/src/display/object/unmanaged.rs | 2 +- agb/src/display/object/unmanaged/object.rs | 33 ++++++++++--------- 10 files changed, 60 insertions(+), 59 deletions(-) diff --git a/agb/examples/chicken.rs b/agb/examples/chicken.rs index 06a3e4e8..e7905802 100644 --- a/agb/examples/chicken.rs +++ b/agb/examples/chicken.rs @@ -4,7 +4,7 @@ use agb::{ display::tiled::{TileFormat, TileSet, TileSetting, TiledMap}, display::{ - object::{OAMManager, Object, Size, Sprite}, + object::{OamManager, Object, Size, Sprite}, palette16::Palette16, tiled::RegularBackgroundSize, HEIGHT, WIDTH, @@ -145,7 +145,7 @@ fn main(mut gba: agb::Gba) -> ! { fn update_chicken_object( chicken: &'_ mut Character<'_>, - gfx: &OAMManager, + gfx: &OamManager, state: State, frame_count: u32, ) { diff --git a/agb/examples/sprites.rs b/agb/examples/sprites.rs index 5fb7aa16..776ecafd 100644 --- a/agb/examples/sprites.rs +++ b/agb/examples/sprites.rs @@ -5,7 +5,7 @@ extern crate alloc; use agb::display::{ affine::AffineMatrix, - object::{self, Graphics, OAMManager, Sprite, TagMap}, + object::{self, Graphics, OamManager, Sprite, TagMap}, }; use agb::fixnum::num; use agb_fixnum::Num; @@ -20,14 +20,14 @@ 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) { +fn all_sprites(gfx: &OamManager, rotation_speed: Num) { let mut input = agb::input::ButtonController::new(); let mut objs = Vec::new(); let mut rotation: Num = num!(0.); let rotation_matrix = AffineMatrix::from_rotation(rotation); - let matrix = object::AffineMatrix::new(rotation_matrix.to_object_wrapping()); + let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping()); for y in 0..9 { for x in 0..14 { @@ -55,7 +55,7 @@ fn all_sprites(gfx: &OAMManager, rotation_speed: Num) { rotation += rotation_speed; let rotation_matrix = AffineMatrix::from_rotation(rotation); - let matrix = object::AffineMatrix::new(rotation_matrix.to_object_wrapping()); + let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping()); for obj in objs.iter_mut() { obj.set_affine_matrix(matrix.clone()); @@ -75,7 +75,7 @@ fn all_sprites(gfx: &OAMManager, rotation_speed: Num) { } } -fn all_tags(gfx: &OAMManager) { +fn all_tags(gfx: &OamManager) { let mut input = agb::input::ButtonController::new(); let mut objs = Vec::new(); diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index cf0923fb..8971814c 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -6,7 +6,7 @@ use video::Video; use self::{ blend::Blend, - object::{initilise_oam, OAMManager, StaticSpriteLoader, UnmanagedOAM}, + object::{initilise_oam, OamManager, OamUnmanaged, SpriteLoader}, window::Windows, }; @@ -84,14 +84,14 @@ pub struct Display { pub struct ObjectDistribution; impl ObjectDistribution { - pub fn get_unmanaged(&mut self) -> (UnmanagedOAM<'_>, StaticSpriteLoader) { + pub fn get_unmanaged(&mut self) -> (OamUnmanaged<'_>, SpriteLoader) { unsafe { initilise_oam() }; - (UnmanagedOAM::new(), StaticSpriteLoader::new()) + (OamUnmanaged::new(), SpriteLoader::new()) } - pub fn get_managed(&mut self) -> OAMManager<'_> { + pub fn get_managed(&mut self) -> OamManager<'_> { unsafe { initilise_oam() }; - OAMManager::new() + OamManager::new() } } diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 97e456dc..5406ecbb 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -4,13 +4,12 @@ mod sprites; mod unmanaged; pub use sprites::{ - include_aseprite, DynamicSprite, Graphics, Size, Sprite, SpriteVram, StaticSpriteLoader, Tag, - TagMap, + include_aseprite, DynamicSprite, Graphics, Size, Sprite, SpriteLoader, SpriteVram, Tag, TagMap, }; -pub use affine::AffineMatrix; -pub use managed::{OAMManager, Object}; -pub use unmanaged::{AffineMode, OAMIterator, OAMSlot, UnmanagedOAM, UnmanagedObject}; +pub use affine::AffineMatrixInstance; +pub use managed::{OamManager, Object}; +pub use unmanaged::{AffineMode, OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged}; use super::DISPLAY_CONTROL; diff --git a/agb/src/display/object/affine.rs b/agb/src/display/object/affine.rs index 50818763..703ab160 100644 --- a/agb/src/display/object/affine.rs +++ b/agb/src/display/object/affine.rs @@ -15,14 +15,14 @@ struct AffineMatrixData { pub(crate) struct AffineMatrixVram(Rc); #[derive(Debug, Clone)] -pub struct AffineMatrix { +pub struct AffineMatrixInstance { location: AffineMatrixVram, } -impl AffineMatrix { +impl AffineMatrixInstance { #[must_use] - pub fn new(affine_matrix: AffineMatrixObject) -> AffineMatrix { - AffineMatrix { + pub fn new(affine_matrix: AffineMatrixObject) -> AffineMatrixInstance { + AffineMatrixInstance { location: AffineMatrixVram(Rc::new(AffineMatrixData { frame_count: Cell::new(u32::MAX), location: Cell::new(u32::MAX), @@ -72,8 +72,8 @@ mod tests { #[test_case] fn niche_optimisation(_gba: &mut crate::Gba) { assert_eq!( - core::mem::size_of::(), - core::mem::size_of::>() + core::mem::size_of::(), + core::mem::size_of::>() ); } } diff --git a/agb/src/display/object/managed.rs b/agb/src/display/object/managed.rs index 1c87c935..2d1b6a45 100644 --- a/agb/src/display/object/managed.rs +++ b/agb/src/display/object/managed.rs @@ -6,7 +6,8 @@ use slotmap::{new_key_type, SlotMap}; use crate::display::Priority; use super::{ - AffineMatrix, AffineMode, Sprite, SpriteVram, StaticSpriteLoader, UnmanagedOAM, UnmanagedObject, + AffineMatrixInstance, AffineMode, OamUnmanaged, ObjectUnmanaged, Sprite, SpriteLoader, + SpriteVram, }; new_key_type! {struct ObjectKey; } @@ -18,7 +19,7 @@ struct Ordering { } struct ObjectItem { - object: UnsafeCell, + object: UnsafeCell, z_order: Cell, z_index: Cell, } @@ -71,7 +72,7 @@ impl Store { true } - fn insert_object(&self, object: UnmanagedObject) -> Object { + fn insert_object(&self, object: ObjectUnmanaged) -> Object { let object_item = ObjectItem { object: UnsafeCell::new(object), z_order: Cell::new(Ordering { @@ -121,21 +122,21 @@ impl Store { } } -pub struct OAMManager<'gba> { +pub struct OamManager<'gba> { object_store: Store, - sprite_loader: UnsafeCell, - unmanaged: UnsafeCell>, + sprite_loader: UnsafeCell, + unmanaged: UnsafeCell>, } -impl OAMManager<'_> { +impl OamManager<'_> { pub(crate) fn new() -> Self { Self { object_store: Store { store: UnsafeCell::new(SlotMap::with_key()), first_z: Cell::new(None), }, - sprite_loader: UnsafeCell::new(StaticSpriteLoader::new()), - unmanaged: UnsafeCell::new(UnmanagedOAM::new()), + sprite_loader: UnsafeCell::new(SpriteLoader::new()), + unmanaged: UnsafeCell::new(OamUnmanaged::new()), } } @@ -143,7 +144,7 @@ impl OAMManager<'_> { /// Do not reenter or recurse or otherwise use sprite loader cell during this. unsafe fn do_work_with_sprite_loader(&self, c: C) -> T where - C: Fn(&mut StaticSpriteLoader) -> T, + C: Fn(&mut SpriteLoader) -> T, { let sprite_loader = unsafe { &mut *self.sprite_loader.get() }; @@ -164,13 +165,13 @@ impl OAMManager<'_> { // safety: not reentrant unsafe { - self.do_work_with_sprite_loader(StaticSpriteLoader::garbage_collect); + self.do_work_with_sprite_loader(SpriteLoader::garbage_collect); } } pub fn add_object(&self, sprite: SpriteVram) -> Object<'_> { self.object_store - .insert_object(UnmanagedObject::new(sprite)) + .insert_object(ObjectUnmanaged::new(sprite)) } pub fn get_vram_sprite(&self, sprite: &'static Sprite) -> SpriteVram { @@ -335,13 +336,13 @@ impl Object<'_> { /// Safety: /// Only have *ONE* of these at a time, do not call any functions that modify the slot map while having this. - unsafe fn object(&mut self) -> &mut UnmanagedObject { + unsafe fn object(&mut self) -> &mut ObjectUnmanaged { unsafe { &mut *self.store.get_object(self.me).object.get() } } /// Safety: /// Don't have a mutable one of these while having one of these, do not call any functions that modify the slot map while having this. - unsafe fn object_shared(&self) -> &UnmanagedObject { + unsafe fn object_shared(&self) -> &ObjectUnmanaged { unsafe { &*self.store.get_object(self.me).object.get() } } @@ -414,7 +415,7 @@ impl Object<'_> { self } - pub fn set_affine_matrix(&mut self, affine_matrix: AffineMatrix) -> &mut Self { + pub fn set_affine_matrix(&mut self, affine_matrix: AffineMatrixInstance) -> &mut Self { // safety: only have one of these, doesn't modify slotmap unsafe { self.object().set_affine_matrix(affine_matrix) }; diff --git a/agb/src/display/object/sprites.rs b/agb/src/display/object/sprites.rs index 1c331e46..c384be6a 100644 --- a/agb/src/display/object/sprites.rs +++ b/agb/src/display/object/sprites.rs @@ -4,4 +4,4 @@ mod sprite_allocator; const BYTES_PER_TILE_4BPP: usize = 32; pub use sprite::{include_aseprite, Graphics, Size, Sprite, Tag, TagMap}; -pub use sprite_allocator::{DynamicSprite, SpriteVram, StaticSpriteLoader}; +pub use sprite_allocator::{DynamicSprite, SpriteLoader, SpriteVram}; diff --git a/agb/src/display/object/sprites/sprite_allocator.rs b/agb/src/display/object/sprites/sprite_allocator.rs index caa5e38b..0c8d02a2 100644 --- a/agb/src/display/object/sprites/sprite_allocator.rs +++ b/agb/src/display/object/sprites/sprite_allocator.rs @@ -53,7 +53,7 @@ impl PaletteId { } /// This holds loading of static sprites and palettes. -pub struct StaticSpriteLoader { +pub struct SpriteLoader { static_palette_map: HashMap>, static_sprite_map: HashMap>, } @@ -159,7 +159,7 @@ impl SpriteVram { } } -impl StaticSpriteLoader { +impl SpriteLoader { fn create_sprite_no_insert( palette_map: &mut HashMap>, sprite: &'static Sprite, @@ -245,7 +245,7 @@ impl StaticSpriteLoader { } } -impl Default for StaticSpriteLoader { +impl Default for SpriteLoader { fn default() -> Self { Self::new() } diff --git a/agb/src/display/object/unmanaged.rs b/agb/src/display/object/unmanaged.rs index 3a9db454..42f609fa 100644 --- a/agb/src/display/object/unmanaged.rs +++ b/agb/src/display/object/unmanaged.rs @@ -2,4 +2,4 @@ mod attributes; mod object; pub use attributes::AffineMode; -pub use object::{OAMIterator, OAMSlot, UnmanagedOAM, UnmanagedObject}; +pub use object::{OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged}; diff --git a/agb/src/display/object/unmanaged/object.rs b/agb/src/display/object/unmanaged/object.rs index 982d4eb3..30387b21 100644 --- a/agb/src/display/object/unmanaged/object.rs +++ b/agb/src/display/object/unmanaged/object.rs @@ -5,7 +5,8 @@ use alloc::vec::Vec; use crate::display::{ object::{ - affine::AffineMatrixVram, sprites::SpriteVram, AffineMatrix, OBJECT_ATTRIBUTE_MEMORY, + affine::AffineMatrixVram, sprites::SpriteVram, AffineMatrixInstance, + OBJECT_ATTRIBUTE_MEMORY, }, Priority, }; @@ -20,24 +21,24 @@ struct OamFrameModifyables { affine_matrix_count: u32, } -pub struct UnmanagedOAM<'gba> { +pub struct OamUnmanaged<'gba> { phantom: PhantomData<&'gba ()>, frame_data: UnsafeCell, previous_frame_sprites: Vec, } -pub struct OAMIterator<'oam> { +pub struct OamIterator<'oam> { index: usize, frame_data: &'oam UnsafeCell, } -pub struct OAMSlot<'oam> { +pub struct OamSlot<'oam> { slot: usize, frame_data: &'oam UnsafeCell, } -impl OAMSlot<'_> { - pub fn set(&mut self, object: &UnmanagedObject) { +impl OamSlot<'_> { + pub fn set(&mut self, object: &ObjectUnmanaged) { let mut attributes = object.attributes; // SAFETY: This function is not reentrant and we currently hold a mutable borrow of the [UnmanagedOAM]. let frame_data = unsafe { &mut *self.frame_data.get() }; @@ -72,8 +73,8 @@ impl OAMSlot<'_> { } } -impl<'oam> Iterator for OAMIterator<'oam> { - type Item = OAMSlot<'oam>; +impl<'oam> Iterator for OamIterator<'oam> { + type Item = OamSlot<'oam>; fn next(&mut self) -> Option { let idx = self.index; @@ -82,7 +83,7 @@ impl<'oam> Iterator for OAMIterator<'oam> { if idx >= 128 { None } else { - Some(OAMSlot { + Some(OamSlot { slot: idx, frame_data: self.frame_data, }) @@ -90,7 +91,7 @@ impl<'oam> Iterator for OAMIterator<'oam> { } } -impl Drop for OAMIterator<'_> { +impl Drop for OamIterator<'_> { fn drop(&mut self) { let last_written = unsafe { &*self.frame_data.get() }.up_to; @@ -105,8 +106,8 @@ impl Drop for OAMIterator<'_> { } } -impl UnmanagedOAM<'_> { - pub fn iter(&mut self) -> OAMIterator<'_> { +impl OamUnmanaged<'_> { + pub fn iter(&mut self) -> OamIterator<'_> { let frame_data = self.frame_data.get_mut(); frame_data.up_to = -1; frame_data.frame = frame_data.frame.wrapping_add(1); @@ -120,7 +121,7 @@ impl UnmanagedOAM<'_> { &mut self.previous_frame_sprites, ); - OAMIterator { + OamIterator { index: 0, frame_data: &self.frame_data, } @@ -136,13 +137,13 @@ impl UnmanagedOAM<'_> { } #[derive(Debug, Clone)] -pub struct UnmanagedObject { +pub struct ObjectUnmanaged { attributes: Attributes, sprite: SpriteVram, affine_matrix: Option, } -impl UnmanagedObject { +impl ObjectUnmanaged { #[must_use] pub fn new(sprite: SpriteVram) -> Self { let sprite_location = sprite.location(); @@ -226,7 +227,7 @@ impl UnmanagedObject { self } - pub fn set_affine_matrix(&mut self, affine_matrix: AffineMatrix) -> &mut Self { + pub fn set_affine_matrix(&mut self, affine_matrix: AffineMatrixInstance) -> &mut Self { let vram = affine_matrix.vram(); self.affine_matrix = Some(vram);