Skip to content

Commit efd3d46

Browse files
committed
feat: use f64 for most value types
1 parent c8b59c1 commit efd3d46

26 files changed

Lines changed: 288 additions & 273 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ phira-mp-common = { git = "https://github.com/TeamFlos/phira-mp", rev = "6967475
6565
prpr = { path = "prpr", default-features = false }
6666
prpr-avc = { path = "prpr-avc" }
6767
prpr-l10n = { path = "prpr-l10n" }
68-
sasa = { git = "https://github.com/Mivik/sasa", rev = "4470cd7", default-features = false }
68+
sasa = { git = "https://github.com/Mivik/sasa", rev = "e76229b", default-features = false }
6969

7070
[profile.release]
7171
opt-level = 2

phira-monitor/src/scene.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct PlayerView {
6161
judges: VecDeque<JudgeEvent>,
6262

6363
current_touches: HashMap<i8, Vec2>,
64-
current_time: f32,
64+
current_time: f64,
6565

6666
latest_time: Option<f32>,
6767
}
@@ -115,7 +115,7 @@ impl PlayerView {
115115
let t = res.time;
116116

117117
let mut updated = false;
118-
while self.touches.front().is_some_and(|it| it.time < t) {
118+
while self.touches.front().is_some_and(|it| t > it.time as f64) {
119119
let Some(frame) = self.touches.pop_front() else { unreachable!() };
120120
for (id, pos) in frame.points {
121121
if id >= 0 {
@@ -124,7 +124,7 @@ impl PlayerView {
124124
self.current_touches.remove(&!id);
125125
}
126126
}
127-
self.current_time = frame.time;
127+
self.current_time = frame.time as f64;
128128
updated = true;
129129
}
130130
if updated {
@@ -135,7 +135,7 @@ impl PlayerView {
135135
let pos = vec2(pos.x(), pos.y());
136136
let id = if *id >= 0 { *id } else { !*id };
137137
let pos = if let Some(old) = current.remove(&id) {
138-
Vec2::tween(&old, &pos, (t - self.current_time) / (frame.time - self.current_time))
138+
Vec2::tween(&old, &pos, ((t - self.current_time) / (frame.time as f64 - self.current_time)) as f32)
139139
} else {
140140
return None;
141141
};
@@ -149,7 +149,7 @@ impl PlayerView {
149149
self.chart.update(res);
150150

151151
while let Some(event) = self.judges.front() {
152-
if event.time > t {
152+
if event.time as f64 > t {
153153
break;
154154
}
155155
let Some(event) = self.judges.pop_front() else { unreachable!() };
@@ -195,7 +195,7 @@ impl PlayerView {
195195
mat *= note.now_transform(
196196
res,
197197
&line.ctrl_obj.borrow_mut(),
198-
(note.height - line.height.now()) / res.aspect_ratio * note.speed,
198+
((note.height - line.height.now() as f64) / res.aspect_ratio as f64 * note.speed) as f32,
199199
incline_sin,
200200
);
201201
mat
@@ -206,7 +206,7 @@ impl PlayerView {
206206
}
207207
}
208208
Err(perfect) => {
209-
note.judge = JudgeStatus::Hold(perfect, t, 0., false, f32::INFINITY);
209+
note.judge = JudgeStatus::Hold(perfect, t, 0., false, f64::INFINITY);
210210
}
211211
}
212212
}

phira/src/page/offset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Page for OffsetPage {
126126

127127
fn update(&mut self, _s: &mut SharedState) -> Result<()> {
128128
if !self.cali.paused() {
129-
let pos = self.cali.position() as f64;
129+
let pos = self.cali.position();
130130
let now = self.tm.now();
131131
if now > 2. {
132132
self.tm.seek_to(now - 2.);
@@ -170,7 +170,7 @@ impl Page for OffsetPage {
170170
self.touched = false;
171171
}
172172
if t <= 1. {
173-
let w = NOTE_WIDTH_RATIO_BASE * config.note_scale * 2.;
173+
let w = NOTE_WIDTH_RATIO_BASE as f32 * config.note_scale * 2.;
174174
let h = w * self.click.height() / self.click.width();
175175
let r = Rect::new(ct.0 - w / 2., ny, w, h);
176176
ui.fill_rect(r, (*self.click, r, ScaleType::Fit));

phira/src/scene/song.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,10 @@ impl SongScene {
917917
hash_map::Entry::Occupied(val) => *val.get(),
918918
hash_map::Entry::Vacant(place) => *place.insert(len.try_into().ok()?),
919919
};
920-
if matches!(it.phase, TouchPhase::Moved) && touch_last_update.get(&id).is_some_and(|it| *it + 1. / 20. >= t) {
920+
if matches!(it.phase, TouchPhase::Moved) && touch_last_update.get(&id).is_some_and(|it| *it as f64 + 1. / 20. >= t) {
921921
return None;
922922
}
923-
touch_last_update.insert(id, t);
923+
touch_last_update.insert(id, t as f32);
924924
if matches!(it.phase, TouchPhase::Ended | TouchPhase::Cancelled) {
925925
touch_ids.remove(&it.id);
926926
id = !id;
@@ -929,18 +929,18 @@ impl SongScene {
929929
})
930930
.collect();
931931
if !points.is_empty() {
932-
touches.push_back(TouchFrame { time: t, points });
932+
touches.push_back(TouchFrame { time: t as f32, points });
933933
}
934-
if last_send_touch_time + 1. < t || touches.len() > 20 {
934+
if last_send_touch_time as f64 + 1. < t || touches.len() > 20 {
935935
if touches.is_empty() {
936-
touches.push_back(TouchFrame { time: t, points: Vec::new() });
936+
touches.push_back(TouchFrame { time: t as f32, points: Vec::new() });
937937
}
938938
let frames = Arc::new(touches.drain(..).collect());
939939
client.blocking_send(ClientCommand::Touches { frames }).unwrap();
940-
last_send_touch_time = t;
940+
last_send_touch_time = t as f32;
941941
}
942942
judges.extend(judge.judgements.borrow_mut().drain(..).map(|it| JudgeEvent {
943-
time: it.0,
943+
time: it.0 as f32,
944944
line_id: it.1,
945945
note_id: it.2,
946946
judgement: {
@@ -956,7 +956,7 @@ impl SongScene {
956956
}
957957
},
958958
}));
959-
if judges.len() > 10 || judges.front().is_some_and(|it| it.time + 0.6 < t) {
959+
if judges.len() > 10 || judges.front().is_some_and(|it| it.time + 0.6 < t as f32) {
960960
let judges = Arc::new(judges.drain(..).collect());
961961
client.blocking_send(ClientCommand::Judges { judges }).unwrap();
962962
}

phira/src/scene/unlock.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct UnlockScene {
3333
render_target: Option<RenderTarget>,
3434
video: Video,
3535
bgm: Option<Bgm>,
36-
music_length: f32,
36+
music_length: f64,
3737

3838
background: SafeTexture,
3939

@@ -133,7 +133,7 @@ impl Scene for UnlockScene {
133133
}
134134
}
135135

136-
let t = tm.now() as f32;
136+
let t = tm.now();
137137
match self.state {
138138
State::Before => {
139139
if t > 0.5 {
@@ -185,7 +185,7 @@ impl Scene for UnlockScene {
185185
fn render(&mut self, tm: &mut TimeManager, ui: &mut prpr::ui::Ui) -> Result<()> {
186186
let mut cam = ui.camera();
187187
let asp = -cam.zoom.y;
188-
let t = tm.now() as f32;
188+
let t = tm.now();
189189
cam.render_target = self.render_target;
190190
set_camera(&cam);
191191
clear_background(BLACK);
@@ -202,7 +202,7 @@ impl Scene for UnlockScene {
202202
ui.loading(
203203
1. - pad,
204204
top - pad,
205-
t,
205+
t as f32,
206206
WHITE,
207207
LoadingParams {
208208
width: 0.01,
@@ -215,11 +215,11 @@ impl Scene for UnlockScene {
215215
let top = 1. / asp;
216216
if t < 0.5 {
217217
let pad = 0.07;
218-
let alpha = if t < 0.5 { 1. - t / 0.5 } else { 0. }; // TODO: more smoothly
218+
let alpha = if t < 0.5 { 1. - t as f32 / 0.5 } else { 0. }; // TODO: more smoothly
219219
ui.loading(
220220
1. - pad,
221221
top - pad,
222-
t,
222+
t as f32,
223223
semi_white(alpha),
224224
LoadingParams {
225225
width: 0.01,
@@ -228,7 +228,7 @@ impl Scene for UnlockScene {
228228
},
229229
);
230230
} else {
231-
let alpha = if t < 0.5 { t / 0.5 * 0.3 } else { 0.3 };
231+
let alpha = if t < 0.5 { t as f32 / 0.5 * 0.3 } else { 0.3 };
232232
let r = ui.screen_rect();
233233
ui.fill_rect(r, (*self.background, r));
234234
ui.fill_rect(r, semi_black(alpha));

prpr-avc/src/video.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ impl Video {
153153
self.video_stream.duration() as f64 * self.time_base().to_f64()
154154
}
155155

156-
pub fn elapsed_to_timestamp(&self, elapsed: f32) -> i64 {
156+
pub fn elapsed_to_timestamp(&self, elapsed: f64) -> i64 {
157157
let time_base = self.time_base();
158-
(elapsed as f64 * time_base.den as f64 / time_base.num as f64).round() as i64
158+
(elapsed * time_base.den as f64 / time_base.num as f64).round() as i64
159159
}
160160

161161
pub fn seek(&self, timestamp: i64) {

prpr/src/bin.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl BinaryData for Color {
196196
impl<T: BinaryData> BinaryData for Keyframe<T> {
197197
fn read_binary<R: Read>(r: &mut BinaryReader<R>) -> Result<Self> {
198198
Ok(Self {
199-
time: r.time()?,
199+
time: r.time()? as f64,
200200
value: r.read()?,
201201
tween: {
202202
let b = r.read::<u8>()?;
@@ -211,7 +211,7 @@ impl<T: BinaryData> BinaryData for Keyframe<T> {
211211
}
212212

213213
fn write_binary<W: Write>(&self, w: &mut BinaryWriter<W>) -> Result<()> {
214-
w.time(self.time)?;
214+
w.time(self.time as f32)?;
215215
w.write(&self.value)?;
216216
let tween = self.tween.as_any();
217217
if let Some(t) = tween.downcast_ref::<StaticTween>() {
@@ -323,8 +323,8 @@ impl BinaryData for Note {
323323
let kind = match r.read::<u8>()? {
324324
0 => NoteKind::Click,
325325
1 => NoteKind::Hold {
326-
end_time: r.read()?,
327-
end_height: r.read()?,
326+
end_time: r.read::<f32>()? as f64,
327+
end_height: r.read::<f32>()? as f64,
328328
},
329329
2 => NoteKind::Flick,
330330
3 => NoteKind::Drag,
@@ -335,9 +335,9 @@ impl BinaryData for Note {
335335
object,
336336
kind,
337337
hitsound,
338-
time: r.time()?,
339-
height: r.read()?,
340-
speed: if r.read()? { r.read::<f32>()? } else { 1. },
338+
time: r.time()? as f64,
339+
height: r.read::<f32>()? as f64,
340+
speed: if r.read()? { r.read::<f32>()? as f64 } else { 1. },
341341
above: r.read()?,
342342
multiple_hint: false,
343343
fake: r.read()?,
@@ -356,19 +356,19 @@ impl BinaryData for Note {
356356
}
357357
NoteKind::Hold { end_time, end_height } => {
358358
w.write_val(1_u8)?;
359-
w.write_val(end_time)?;
360-
w.write_val(end_height)?;
359+
w.write_val(end_time as f32)?;
360+
w.write_val(end_height as f32)?;
361361
}
362362
NoteKind::Flick => w.write_val(2_u8)?,
363363
NoteKind::Drag => w.write_val(3_u8)?,
364364
}
365-
w.time(self.time)?;
366-
w.write_val(self.height)?;
365+
w.time(self.time as f32)?;
366+
w.write_val(self.height as f32)?;
367367
if self.speed == 1.0 {
368368
w.write_val(false)?;
369369
} else {
370370
w.write_val(true)?;
371-
w.write_val(self.speed)?;
371+
w.write_val(self.speed as f32)?;
372372
}
373373
w.write_val(self.above)?;
374374
w.write_val(self.fake)?;

prpr/src/core.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
1313
pub use macroquad::color::Color;
1414

15-
pub const NOTE_WIDTH_RATIO_BASE: f32 = 0.13175016;
16-
pub const HEIGHT_RATIO: f32 = 0.83175;
15+
pub const NOTE_WIDTH_RATIO_BASE: f64 = 0.13175016;
16+
pub const HEIGHT_RATIO: f64 = 0.83175;
1717

18-
pub const EPS: f32 = 1e-5;
18+
pub const EPS: f64 = 1e-5;
1919

2020
pub type Point = nalgebra::Point2<f32>;
2121
pub type Vector = nalgebra::Vector2<f32>;
@@ -95,16 +95,16 @@ impl Default for Triple {
9595
}
9696

9797
impl Triple {
98-
pub fn beats(&self) -> f32 {
99-
self.0 as f32 + self.1 as f32 / self.2 as f32
98+
pub fn beats(&self) -> f64 {
99+
self.0 as f64 + self.1 as f64 / self.2 as f64
100100
}
101101
}
102102

103103
#[derive(Default)] // the default is a dummy
104104
pub struct BpmList {
105105
/// (beats, time, bpm)
106106
/// time in seconds
107-
elements: Vec<(f32, f32, f32)>,
107+
elements: Vec<(f64, f64, f64)>,
108108
/// cursor for searching, value is the index of `elements`
109109
cursor: usize,
110110
}
@@ -113,11 +113,11 @@ impl BpmList {
113113
/// Create a new BpmList from a list of (beats, bpm) pairs
114114
///
115115
/// Basically just calculate the time for each pair(key frame)
116-
pub fn new(ranges: Vec<(f32, f32)>) -> Self {
116+
pub fn new(ranges: Vec<(f64, f64)>) -> Self {
117117
let mut elements = Vec::new();
118118
let mut time = 0.0;
119119
let mut last_beats = 0.0;
120-
let mut last_bpm: Option<f32> = None;
120+
let mut last_bpm: Option<f64> = None;
121121
for (now_beats, bpm) in ranges {
122122
if let Some(bpm) = last_bpm {
123123
time += (now_beats - last_beats) * (60. / bpm);
@@ -130,7 +130,7 @@ impl BpmList {
130130
}
131131

132132
/// Get the time in seconds for a given beats
133-
pub fn time_beats(&mut self, beats: f32) -> f32 {
133+
pub fn time_beats(&mut self, beats: f64) -> f64 {
134134
while let Some(kf) = self.elements.get(self.cursor + 1) {
135135
if kf.0 > beats {
136136
break;
@@ -145,12 +145,12 @@ impl BpmList {
145145
}
146146

147147
/// Get the time in seconds for a given `i + n / d`
148-
pub fn time(&mut self, triple: &Triple) -> f32 {
148+
pub fn time(&mut self, triple: &Triple) -> f64 {
149149
self.time_beats(triple.beats())
150150
}
151151

152152
/// Get the beat coordinate for a given time in seconds
153-
pub fn beat(&mut self, time: f32) -> f32 {
153+
pub fn beat(&mut self, time: f64) -> f64 {
154154
while let Some(kf) = self.elements.get(self.cursor + 1) {
155155
if kf.1 > time {
156156
break;

0 commit comments

Comments
 (0)