mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
rename parts of objects
This commit is contained in:
parent
d183b8373d
commit
d6006c7808
|
@ -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,
|
||||
) {
|
||||
|
|
|
@ -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<i32, 16>) {
|
||||
fn all_sprites(gfx: &OamManager, rotation_speed: Num<i32, 16>) {
|
||||
let mut input = agb::input::ButtonController::new();
|
||||
let mut objs = Vec::new();
|
||||
|
||||
let mut rotation: Num<i32, 16> = 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<i32, 16>) {
|
|||
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<i32, 16>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn all_tags(gfx: &OAMManager) {
|
||||
fn all_tags(gfx: &OamManager) {
|
||||
let mut input = agb::input::ButtonController::new();
|
||||
let mut objs = Vec::new();
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -15,14 +15,14 @@ struct AffineMatrixData {
|
|||
pub(crate) struct AffineMatrixVram(Rc<AffineMatrixData>);
|
||||
|
||||
#[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::<AffineMatrix>(),
|
||||
core::mem::size_of::<Option<AffineMatrix>>()
|
||||
core::mem::size_of::<AffineMatrixInstance>(),
|
||||
core::mem::size_of::<Option<AffineMatrixInstance>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<UnmanagedObject>,
|
||||
object: UnsafeCell<ObjectUnmanaged>,
|
||||
z_order: Cell<Ordering>,
|
||||
z_index: Cell<i32>,
|
||||
}
|
||||
|
@ -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<StaticSpriteLoader>,
|
||||
unmanaged: UnsafeCell<UnmanagedOAM<'gba>>,
|
||||
sprite_loader: UnsafeCell<SpriteLoader>,
|
||||
unmanaged: UnsafeCell<OamUnmanaged<'gba>>,
|
||||
}
|
||||
|
||||
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<C, T>(&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) };
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -53,7 +53,7 @@ impl PaletteId {
|
|||
}
|
||||
|
||||
/// This holds loading of static sprites and palettes.
|
||||
pub struct StaticSpriteLoader {
|
||||
pub struct SpriteLoader {
|
||||
static_palette_map: HashMap<PaletteId, Weak<PaletteVramData>>,
|
||||
static_sprite_map: HashMap<SpriteId, Weak<SpriteVramData>>,
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ impl SpriteVram {
|
|||
}
|
||||
}
|
||||
|
||||
impl StaticSpriteLoader {
|
||||
impl SpriteLoader {
|
||||
fn create_sprite_no_insert(
|
||||
palette_map: &mut HashMap<PaletteId, Weak<PaletteVramData>>,
|
||||
sprite: &'static Sprite,
|
||||
|
@ -245,7 +245,7 @@ impl StaticSpriteLoader {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for StaticSpriteLoader {
|
||||
impl Default for SpriteLoader {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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<OamFrameModifyables>,
|
||||
previous_frame_sprites: Vec<SpriteVram>,
|
||||
}
|
||||
|
||||
pub struct OAMIterator<'oam> {
|
||||
pub struct OamIterator<'oam> {
|
||||
index: usize,
|
||||
frame_data: &'oam UnsafeCell<OamFrameModifyables>,
|
||||
}
|
||||
|
||||
pub struct OAMSlot<'oam> {
|
||||
pub struct OamSlot<'oam> {
|
||||
slot: usize,
|
||||
frame_data: &'oam UnsafeCell<OamFrameModifyables>,
|
||||
}
|
||||
|
||||
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<Self::Item> {
|
||||
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<AffineMatrixVram>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue