mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-26 00:56:38 +11:00
keep track of which objects have been assigned
This commit is contained in:
parent
9fad597844
commit
a7cb7ea7b4
1 changed files with 28 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
||||||
use super::DISPLAY_CONTROL;
|
use super::DISPLAY_CONTROL;
|
||||||
|
use crate::bitarray::Bitarray;
|
||||||
use crate::memory_mapped::MemoryMapped1DArray;
|
use crate::memory_mapped::MemoryMapped1DArray;
|
||||||
|
|
||||||
const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray<u16, 512> =
|
const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray<u16, 512> =
|
||||||
|
@ -6,8 +7,8 @@ const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray<u16, 512> =
|
||||||
|
|
||||||
/// Handles distributing objects and matricies along with operations that effect all objects.
|
/// Handles distributing objects and matricies along with operations that effect all objects.
|
||||||
pub struct ObjectControl {
|
pub struct ObjectControl {
|
||||||
object_count: u8,
|
objects: Bitarray<4>,
|
||||||
affine_count: u8,
|
affines: Bitarray<1>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The standard object, without rotation.
|
/// The standard object, without rotation.
|
||||||
|
@ -227,8 +228,8 @@ impl ObjectControl {
|
||||||
unsafe { o.commit(index) };
|
unsafe { o.commit(index) };
|
||||||
}
|
}
|
||||||
ObjectControl {
|
ObjectControl {
|
||||||
object_count: 0,
|
objects: Bitarray::new(),
|
||||||
affine_count: 0,
|
affines: Bitarray::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,14 +247,32 @@ impl ObjectControl {
|
||||||
DISPLAY_CONTROL.set(disp);
|
DISPLAY_CONTROL.set(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_unused_object_index(&mut self) -> u8 {
|
||||||
|
for index in 0..128 {
|
||||||
|
if self.objects.get(index).unwrap() == false {
|
||||||
|
self.objects.set(index, true);
|
||||||
|
return index as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("object id must be less than 128");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_unused_affine_index(&mut self) -> u8 {
|
||||||
|
for index in 0..32 {
|
||||||
|
if self.affines.get(index).unwrap() == false {
|
||||||
|
self.affines.set(index, true);
|
||||||
|
return index as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("affine id must be less than 32");
|
||||||
|
}
|
||||||
|
|
||||||
/// Get an unused standard object. Currently dropping an unused object will
|
/// Get an unused standard object. Currently dropping an unused object will
|
||||||
/// not free this. You should either keep around all objects you need
|
/// not free this. You should either keep around all objects you need
|
||||||
/// forever or drop and reobtain ObjectControl. Panics if more than 128
|
/// forever or drop and reobtain ObjectControl. Panics if more than 128
|
||||||
/// objects are obtained.
|
/// objects are obtained.
|
||||||
pub fn get_object_standard(&mut self) -> ObjectStandard {
|
pub fn get_object_standard(&mut self) -> ObjectStandard {
|
||||||
let id = self.object_count;
|
let id = self.get_unused_object_index();
|
||||||
self.object_count += 1;
|
|
||||||
assert!(id < 128, "object id must be less than 128");
|
|
||||||
ObjectStandard {
|
ObjectStandard {
|
||||||
attributes: ObjectAttribute::new(),
|
attributes: ObjectAttribute::new(),
|
||||||
id,
|
id,
|
||||||
|
@ -265,9 +284,7 @@ impl ObjectControl {
|
||||||
/// forever or drop and reobtain ObjectControl. Panics if more than 128
|
/// forever or drop and reobtain ObjectControl. Panics if more than 128
|
||||||
/// objects are obtained.
|
/// objects are obtained.
|
||||||
pub fn get_object_affine(&mut self) -> ObjectAffine {
|
pub fn get_object_affine(&mut self) -> ObjectAffine {
|
||||||
let id = self.object_count;
|
let id = self.get_unused_object_index();
|
||||||
self.object_count += 1;
|
|
||||||
assert!(id < 128, "object id must be less than 128");
|
|
||||||
ObjectAffine {
|
ObjectAffine {
|
||||||
attributes: ObjectAttribute::new(),
|
attributes: ObjectAttribute::new(),
|
||||||
id,
|
id,
|
||||||
|
@ -280,9 +297,7 @@ impl ObjectControl {
|
||||||
/// need forever or drop and reobtain ObjectControl. Panics if more than 32
|
/// need forever or drop and reobtain ObjectControl. Panics if more than 32
|
||||||
/// affine matricies are obtained.
|
/// affine matricies are obtained.
|
||||||
pub fn get_affine(&mut self) -> AffineMatrix {
|
pub fn get_affine(&mut self) -> AffineMatrix {
|
||||||
let id = self.affine_count;
|
let id = self.get_unused_affine_index();
|
||||||
self.affine_count += 1;
|
|
||||||
assert!(id < 32, "affine id must be less than 32");
|
|
||||||
AffineMatrix {
|
AffineMatrix {
|
||||||
attributes: AffineMatrixAttributes {
|
attributes: AffineMatrixAttributes {
|
||||||
p_a: 0,
|
p_a: 0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue