From d0d33de51e6b3336ac3333252985d5fcdb875ca6 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 30 Jun 2020 12:48:47 +0200 Subject: [PATCH] Store time as u32 --- src/converter/ddr2osu.rs | 4 ++-- src/ddr/ssq.rs | 14 +++++++------- src/osu/beatmap.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/converter/ddr2osu.rs b/src/converter/ddr2osu.rs index 88d07a7..a84e80d 100644 --- a/src/converter/ddr2osu.rs +++ b/src/converter/ddr2osu.rs @@ -144,7 +144,7 @@ impl ShockStepGenerator { } } -fn get_time_from_beats(beats: f32, tempo_changes: &[ssq::TempoChange]) -> Option { +fn get_time_from_beats(beats: f32, tempo_changes: &[ssq::TempoChange]) -> Option { for tempo_change in tempo_changes { // For TempoChanges that are infinitely short but exactly cover that beat, use the start // time of that TempoChange @@ -157,7 +157,7 @@ fn get_time_from_beats(beats: f32, tempo_changes: &[ssq::TempoChange]) -> Option if beats < tempo_change.end_beats { return Some( tempo_change.start_ms - + ((beats - tempo_change.start_beats) * tempo_change.beat_length) as i32, + + ((beats - tempo_change.start_beats) * tempo_change.beat_length) as u32, ); } } diff --git a/src/ddr/ssq.rs b/src/ddr/ssq.rs index 4535fc5..646ff3c 100644 --- a/src/ddr/ssq.rs +++ b/src/ddr/ssq.rs @@ -29,8 +29,8 @@ pub enum Error { /// Convert time offset to beats /// time offset is the measure times MEASURE_LENGTH -fn measure_to_beats(metric: i32) -> f32 { - 4.0 * metric as f32 / MEASURE_LENGTH +fn measure_to_beats(measure: u32) -> f32 { + 4.0 * measure as f32 / MEASURE_LENGTH } #[derive(Debug, Clone, PartialEq, Default)] @@ -153,7 +153,7 @@ impl Row { #[derive(Clone, Debug, PartialEq)] pub struct TempoChange { - pub start_ms: i32, + pub start_ms: u32, pub start_beats: f32, pub end_beats: f32, pub beat_length: f32, @@ -163,7 +163,7 @@ pub struct TempoChange { pub struct TempoChanges(pub Vec); impl TempoChanges { - fn parse(ticks_per_second: i32, data: &[u8]) -> Result { + fn parse(ticks_per_second: u32, data: &[u8]) -> Result { let mut cursor = Cursor::new(data); let count = cursor.read_u32::()?.try_into()?; @@ -175,8 +175,8 @@ impl TempoChanges { let mut elapsed_ms = 0; let mut elapsed_beats = 0.0; for i in 1..count { - let delta_measure = measure[i] - measure[i - 1]; - let delta_ticks = tempo_data[i] - tempo_data[i - 1]; + let delta_measure: u32 = (measure[i] - measure[i - 1]).abs().try_into()?; + let delta_ticks: u32 = (tempo_data[i] - tempo_data[i - 1]).abs().try_into()?; let length_ms = 1000 * delta_ticks / ticks_per_second; let length_beats = measure_to_beats(delta_measure); @@ -236,7 +236,7 @@ impl Chart { let mut freeze_steps = Vec::new(); for step in 0..count { - let beats = measure_to_beats(measures[step]); + let beats = measure_to_beats(measures[step].try_into()?); // check if either all eight bits are set (shock for double) or the first four (shock for // single) diff --git a/src/osu/beatmap.rs b/src/osu/beatmap.rs index 4beda74..85168e3 100644 --- a/src/osu/beatmap.rs +++ b/src/osu/beatmap.rs @@ -10,7 +10,7 @@ pub type DecimalOsuPixel = f32; pub type SampleIndex = u16; -pub type Time = i32; +pub type Time = u32; // Helper functions fn bitflags(flags: [bool; 8]) -> u8 {