mirror of
https://codeberg.org/icewind/vbspview.git
synced 2026-06-03 18:24:09 +02:00
tick ui
This commit is contained in:
parent
cb395c87a4
commit
f3dc4d0f7a
3 changed files with 48 additions and 7 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use crate::DemoInfo;
|
||||
use std::ops::RangeInclusive;
|
||||
use three_d::egui::{Slider, Ui};
|
||||
use three_d::*;
|
||||
use tracing::{debug, info};
|
||||
|
||||
|
|
@ -10,6 +12,10 @@ pub trait Control {
|
|||
elapsed_time: f64,
|
||||
accumulated_time: f64,
|
||||
) -> ThreeDResult<bool>;
|
||||
|
||||
fn ui(&mut self, _ui: &mut Ui) {}
|
||||
|
||||
fn post_ui(&mut self, _time: f64) {}
|
||||
}
|
||||
|
||||
pub struct FirstPerson {
|
||||
|
|
@ -133,6 +139,9 @@ pub struct DemoCamera {
|
|||
playing: bool,
|
||||
start_tick: f64,
|
||||
playback_start_time: f64,
|
||||
ui_tick: u32,
|
||||
last_ui_tick: u32,
|
||||
force_update: bool,
|
||||
}
|
||||
|
||||
impl Control for DemoCamera {
|
||||
|
|
@ -153,7 +162,7 @@ impl Control for DemoCamera {
|
|||
if self.playing {
|
||||
self.playback_start_time = accumulated_time;
|
||||
} else {
|
||||
self.start_tick = self.tick(accumulated_time);
|
||||
self.start_tick = self.demo_tick(accumulated_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,11 +170,12 @@ impl Control for DemoCamera {
|
|||
};
|
||||
}
|
||||
|
||||
if self.playing {
|
||||
let tick = self.tick(accumulated_time);
|
||||
if self.playing | self.force_update {
|
||||
let tick = self.demo_tick(accumulated_time);
|
||||
self.ui_tick = tick as u32 + self.demo.start_tick;
|
||||
if self.demo.positions.len() as f64 <= tick {
|
||||
self.playing = false;
|
||||
self.start_tick = self.tick(accumulated_time);
|
||||
self.start_tick = self.demo_tick(accumulated_time);
|
||||
change = true;
|
||||
info!(
|
||||
tick = tick,
|
||||
|
|
@ -183,10 +193,27 @@ impl Control for DemoCamera {
|
|||
let (position, [pitch, yaw]) = self.demo.positions[tick as usize];
|
||||
self.apply_view(_camera, position, yaw, pitch);
|
||||
}
|
||||
self.force_update = false;
|
||||
}
|
||||
|
||||
Ok(self.playing | change)
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut Ui) {
|
||||
ui.label("Playback");
|
||||
self.last_ui_tick = self.ui_tick;
|
||||
let range = self.tick_range();
|
||||
ui.add(Slider::new(&mut self.ui_tick, range).text("tick"));
|
||||
}
|
||||
|
||||
fn post_ui(&mut self, time: f64) {
|
||||
if self.ui_tick != self.last_ui_tick {
|
||||
let tick = self.ui_tick.saturating_sub(self.demo.start_tick);
|
||||
self.start_tick = tick as f64;
|
||||
self.playback_start_time = time;
|
||||
self.force_update = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DemoCamera {
|
||||
|
|
@ -196,10 +223,13 @@ impl DemoCamera {
|
|||
playing: false,
|
||||
start_tick: 0.0,
|
||||
playback_start_time: 0.0,
|
||||
ui_tick: 0,
|
||||
last_ui_tick: 0,
|
||||
force_update: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn tick(&self, time: f64) -> f64 {
|
||||
fn demo_tick(&self, time: f64) -> f64 {
|
||||
let playback_time = (time - self.playback_start_time) / 1000.0;
|
||||
self.start_tick + playback_time / self.demo.time_per_tick
|
||||
}
|
||||
|
|
@ -212,6 +242,10 @@ impl DemoCamera {
|
|||
.set_view(position, target, vec3(0.0, 1.0, 0.0))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn tick_range(&self) -> RangeInclusive<u32> {
|
||||
self.demo.start_tick..=self.demo.positions.len() as u32 + self.demo.start_tick
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_camera_action(
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ impl<C: Control> Renderer<C> {
|
|||
}
|
||||
|
||||
pub fn render(&mut self, mut frame_input: FrameInput) -> ThreeDResult<FrameOutput> {
|
||||
let (ui_change, _panel_width) = self.gui.update(&mut frame_input, &self.camera)?;
|
||||
let (ui_change, _panel_width) =
|
||||
self.gui
|
||||
.update(&mut frame_input, &self.camera, &mut self.control)?;
|
||||
let change = frame_input.first_frame || ui_change;
|
||||
if change {
|
||||
if self.gui.shadows_enabled {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::Control;
|
||||
use three_d::egui::*;
|
||||
use three_d::{Camera, Context, DebugType, FrameInput, ThreeDResult, GUI};
|
||||
|
||||
|
|
@ -24,10 +25,11 @@ impl DebugUI {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn update(
|
||||
pub fn update<C: Control>(
|
||||
&mut self,
|
||||
frame_input: &mut FrameInput,
|
||||
camera: &Camera,
|
||||
control: &mut C,
|
||||
) -> ThreeDResult<(bool, u32)> {
|
||||
let mut panel_width = 0;
|
||||
let change = self.ui.update(frame_input, |gui_context| {
|
||||
|
|
@ -60,9 +62,12 @@ impl DebugUI {
|
|||
ui.add(Label::new(format!("\tx: {}", camera.position().x)));
|
||||
ui.add(Label::new(format!("\ty: {}", camera.position().y)));
|
||||
ui.add(Label::new(format!("\tz: {}", camera.position().z)));
|
||||
|
||||
control.ui(ui);
|
||||
});
|
||||
panel_width = gui_context.used_size().x as u32;
|
||||
})?;
|
||||
control.post_ui(frame_input.accumulated_time);
|
||||
Ok((change, panel_width))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue