Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phira/locales/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ item-bgm = BGM Volume
item-cali = Adjust Offset

item-show-acc = Real-Time Accuracy
item-show-avg-fps = Show AVG FPS
item-dc-pause = Double-Tap to Pause
item-dhint = Simultaneous Hint
item-dhint-sub = Highlight notes that are meant to be hit at the same time.
Expand Down
1 change: 1 addition & 0 deletions phira/locales/zh-CN/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ item-bgm = BGM 音量
item-cali = 调整延迟

item-show-acc = 显示实时准度
item-show-avg-fps = 显示平均帧率
item-dc-pause = 双击暂停
item-dhint = 双押提示
item-dhint-sub = 同时触线的音符将会被高亮
Expand Down
10 changes: 10 additions & 0 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ impl AudioList {

struct ChartList {
show_acc_btn: DRectButton,
show_avg_fps_btn: DRectButton,
dc_pause_btn: DRectButton,
dhint_btn: DRectButton,
opt_btn: DRectButton,
Expand All @@ -648,6 +649,7 @@ impl ChartList {
pub fn new() -> Self {
Self {
show_acc_btn: DRectButton::new(),
show_avg_fps_btn: DRectButton::new(),
dc_pause_btn: DRectButton::new(),
dhint_btn: DRectButton::new(),
opt_btn: DRectButton::new(),
Expand All @@ -667,6 +669,10 @@ impl ChartList {
config.show_acc ^= true;
return Ok(Some(true));
}
if self.show_avg_fps_btn.touch(touch, t) {
config.show_avg_fps ^= true;
return Ok(Some(true));
}
if self.dc_pause_btn.touch(touch, t) {
config.double_click_to_pause ^= true;
return Ok(Some(true));
Expand Down Expand Up @@ -710,6 +716,10 @@ impl ChartList {
render_title(ui, tl!("item-show-acc"), None);
render_switch(ui, rr, t, &mut self.show_acc_btn, config.show_acc);
}
item! {
render_title(ui, tl!("item-show-avg-fps"), None);
render_switch(ui, rr, t, &mut self.show_avg_fps_btn, config.show_avg_fps);
}
item! {
render_title(ui, tl!("item-dc-pause"), None);
render_switch(ui, rr, t, &mut self.dc_pause_btn, config.double_click_to_pause);
Expand Down
2 changes: 2 additions & 0 deletions prpr/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Config {
pub res_pack_path: Option<String>,
pub sample_count: u32,
pub show_acc: bool,
pub show_avg_fps: bool,
pub speed: f32,
pub touch_debug: bool,
pub volume_music: f32,
Expand Down Expand Up @@ -83,6 +84,7 @@ impl Default for Config {
res_pack_path: None,
sample_count: 1,
show_acc: false,
show_avg_fps: false,
speed: 1.,
touch_debug: false,
volume_music: 1.,
Expand Down
17 changes: 16 additions & 1 deletion prpr/src/scene/ending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct EndingScene {
btn_proceed: DRectButton,

tr_start: f32,

avg_fps: Option<f32>,
}

impl EndingScene {
Expand All @@ -75,6 +77,7 @@ impl EndingScene {
historic_best: u32,
record_data: Option<Vec<u8>>,
record: Option<SimpleRecord>,
avg_fps: Option<f32>,
) -> Result<Self> {
let mut audio = create_audio_manger(config)?;
let bgm = audio.create_music(
Expand Down Expand Up @@ -132,6 +135,8 @@ impl EndingScene {
btn_proceed: DRectButton::new(),

tr_start: f32::NAN,

avg_fps,
})
}
}
Expand Down Expand Up @@ -349,12 +354,22 @@ impl Scene for EndingScene {
let r = ui.text("|").pos(r.right() + 0.03, r.y).color(cs).size(s).draw();

let r = ui.text(tl!("error")).pos(r.right() + 0.03, r.y).color(cl).size(s).draw_using(&BOLD_FONT);
ui.text(format!("±{}ms", (res.std * 1000.).round() as i32))
let r = ui.text(format!("±{}ms", (res.std * 1000.).round() as i32))
.pos(r.right() + 0.02, r.y)
.size(s)
.color(ct)
.draw_using(&BOLD_FONT);

if let Some(avg_fps) = self.avg_fps {
let r = ui.text("|").pos(r.right() + 0.03, r.y).color(cs).size(s).draw();
let r = ui.text("AVG FPS").pos(r.right() + 0.03, r.y).color(cl).size(s).draw_using(&BOLD_FONT);
ui.text(format!("{:.1}", avg_fps))
.pos(r.right() + 0.02, r.y)
.size(s)
.color(ct)
.draw_using(&BOLD_FONT);
}

let mut y = -top + 0.4 + ui.top * 0.3;
let tp = y;
let mut x = -0.26 + (1.2 - y) / 1.9 * 0.4;
Expand Down
25 changes: 25 additions & 0 deletions prpr/src/scene/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub struct GameScene {
update_fn: Option<UpdateFn>,

pub touch_points: Vec<(f32, f32)>,
fps_frame_count: u32,
fps_total_time: f64,
fps_last_frame_time: f64,
}

macro_rules! reset {
Expand All @@ -159,6 +162,9 @@ macro_rules! reset {
$tm.reset();
$self.last_update_time = $tm.now();
$self.state = State::Starting;
$self.fps_frame_count = 0;
$self.fps_total_time = 0.0;
$self.fps_last_frame_time = $tm.real_time();
}};
}

Expand Down Expand Up @@ -303,6 +309,10 @@ impl GameScene {
update_fn,

touch_points: Vec::new(),

fps_frame_count: 0,
fps_total_time: 0.0,
fps_last_frame_time: 0.0,
})
}

Expand Down Expand Up @@ -783,6 +793,13 @@ impl GameScene {
}
});
}
pub fn get_avg_fps(&self) -> Option<f32> {
if self.fps_frame_count > 0 && self.fps_total_time > 0.0 {
Some(self.fps_frame_count as f32 / self.fps_total_time as f32)
} else {
None
}
}
}

impl Scene for GameScene {
Expand Down Expand Up @@ -926,6 +943,7 @@ impl Scene for GameScene {
self.player.as_ref().map_or(0, |it| it.historic_best),
record_data,
record,
if self.res.config.show_avg_fps { self.get_avg_fps() } else { None },
)?))),
GameMode::TweakOffset => Some(NextScene::PopWithResult(Box::new(None::<f32>))),
GameMode::Exercise => None,
Expand Down Expand Up @@ -1043,6 +1061,13 @@ impl Scene for GameScene {
}

fn render(&mut self, tm: &mut TimeManager, ui: &mut Ui) -> Result<()> {
if matches!(self.state, State::Playing) && !tm.paused() {
let current_time = tm.real_time();
let frame_delta = current_time - self.fps_last_frame_time;
self.fps_last_frame_time = current_time;
self.fps_total_time += frame_delta;
self.fps_frame_count += 1;
}
let res = &mut self.res;
let asp = ui.viewport.2 as f32 / ui.viewport.3 as f32;
if res.update_size(ui.viewport) || self.mode == GameMode::View {
Expand Down