Skip to content

Commit e3eebbb

Browse files
committed
ppu: make Object not Copy.
Usually we want to take references to Object. Having it copied by default was actually the cause of a now-fixed bug.
1 parent 1001414 commit e3eebbb

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

glvs-core/src/ppu.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod video;
55

66
extern crate alloc;
77
use alloc::boxed::Box;
8+
use core::array;
89
use core::ops::{Index, IndexMut};
910

1011
use arbitrary_int::{u3, u5};
@@ -77,7 +78,7 @@ pub enum RegisterKind {
7778
Data,
7879
}
7980

80-
#[derive(Debug, Default, Clone, Copy)]
81+
#[derive(Debug, Default, Clone)]
8182
pub struct Object {
8283
x: u8,
8384
y: u8,
@@ -125,8 +126,8 @@ impl Ppu {
125126
}
126127
},
127128
palettes: [0; 32],
128-
oam: [Object::default(); 64],
129-
line_oam: [Object::default(); 8],
129+
oam: array::from_fn(|_| Object::default()),
130+
line_oam: array::from_fn(|_| Object::default()),
130131
regs: Registers::default(),
131132
data_buffer: 0,
132133
second_write: false,
@@ -169,15 +170,15 @@ impl Ppu {
169170
self.sprite_shifter_1.fill(0);
170171

171172
self.zero_hit_possible = false;
172-
for (i, obj) in self.oam.into_iter().enumerate() {
173+
for (i, obj) in self.oam.iter().enumerate() {
173174
let diff = self.scanline as i16 - i16::from(obj.y);
174175
if (0..if self.regs.ctrl.large_sprite() { 16 } else { 8 }).contains(&diff)
175176
&& self.sprite_count < 8
176177
{
177178
if i == 0 {
178179
self.zero_hit_possible = true;
179180
}
180-
self.line_oam[usize::from(self.sprite_count)] = obj;
181+
self.line_oam[usize::from(self.sprite_count)] = obj.clone();
181182
self.sprite_count += 1;
182183
}
183184
}

0 commit comments

Comments
 (0)