mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Use 32-bit numbers more for more performance (and start tracking that)
This commit is contained in:
parent
b8adf08382
commit
6f8633861d
|
@ -10,8 +10,8 @@ pub struct Track<'a> {
|
|||
pub patterns_to_play: &'a [usize],
|
||||
|
||||
pub num_channels: usize,
|
||||
pub frames_per_tick: Num<u16, 8>,
|
||||
pub ticks_per_step: u16,
|
||||
pub frames_per_tick: Num<u32, 8>,
|
||||
pub ticks_per_step: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -11,14 +11,35 @@ const DB_TOFFE: Track = import_xm!("examples/db_toffe.xm");
|
|||
fn main(mut gba: Gba) -> ! {
|
||||
let vblank_provider = agb::interrupt::VBlank::get();
|
||||
|
||||
let timer_controller = gba.timers.timers();
|
||||
let mut timer = timer_controller.timer2;
|
||||
let mut timer2 = timer_controller.timer3;
|
||||
timer.set_enabled(true);
|
||||
timer2.set_cascade(true).set_enabled(true);
|
||||
|
||||
let mut mixer = gba.mixer.mixer(Frequency::Hz18157);
|
||||
mixer.enable();
|
||||
|
||||
let mut tracker = Tracker::new(&DB_TOFFE);
|
||||
|
||||
loop {
|
||||
let before_mixing_cycles_high = timer2.value();
|
||||
let before_mixing_cycles_low = timer.value();
|
||||
|
||||
tracker.step(&mut mixer);
|
||||
|
||||
mixer.frame();
|
||||
let after_mixing_cycles_low = timer.value();
|
||||
let after_mixing_cycles_high = timer2.value();
|
||||
|
||||
vblank_provider.wait_for_vblank();
|
||||
|
||||
let before_mixing_cycles =
|
||||
((before_mixing_cycles_high as u32) << 16) + before_mixing_cycles_low as u32;
|
||||
let after_mixing_cycles =
|
||||
((after_mixing_cycles_high as u32) << 16) + after_mixing_cycles_low as u32;
|
||||
let total_cycles = after_mixing_cycles.wrapping_sub(before_mixing_cycles);
|
||||
|
||||
agb::println!("{total_cycles} cycles");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ pub struct Tracker {
|
|||
track: &'static Track<'static>,
|
||||
channels: Vec<TrackerChannel>,
|
||||
|
||||
frame: Num<u16, 8>,
|
||||
tick: u16,
|
||||
frame: Num<u32, 8>,
|
||||
tick: u32,
|
||||
first: bool,
|
||||
|
||||
current_row: usize,
|
||||
|
@ -164,7 +164,7 @@ impl TrackerChannel {
|
|||
&mut self,
|
||||
mixer: &mut Mixer<'_>,
|
||||
effect: &PatternEffect,
|
||||
tick: u16,
|
||||
tick: u32,
|
||||
speed: Num<u32, 8>,
|
||||
) {
|
||||
if let Some(channel) = self
|
||||
|
|
|
@ -272,7 +272,7 @@ pub fn parse_module(module: &Module) -> TokenStream {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
// Number 150 here deduced experimentally
|
||||
let frames_per_tick = Num::<u16, 8>::new(150) / module.default_bpm;
|
||||
let frames_per_tick = Num::<u32, 8>::new(150) / module.default_bpm as u32;
|
||||
let ticks_per_step = module.default_tempo;
|
||||
|
||||
let interop = agb_tracker_interop::Track {
|
||||
|
@ -283,7 +283,7 @@ pub fn parse_module(module: &Module) -> TokenStream {
|
|||
patterns_to_play: &patterns_to_play,
|
||||
|
||||
frames_per_tick,
|
||||
ticks_per_step,
|
||||
ticks_per_step: ticks_per_step.into(),
|
||||
};
|
||||
|
||||
quote!(#interop)
|
||||
|
|
Loading…
Reference in a new issue