fix animations, fix SlotMap dirty widget panic, set gui scale, set dash to 1080p
[skip ci]
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use glam::{Vec2, vec2};
|
||||
use std::sync::Arc;
|
||||
use testbed::{Testbed, testbed_any::TestbedAny};
|
||||
use timestep::Timestep;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::filter::LevelFilter;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
@@ -28,6 +27,7 @@ use winit::{
|
||||
event_loop::ControlFlow,
|
||||
keyboard::{KeyCode, PhysicalKey},
|
||||
};
|
||||
use wlx_common::timestep::Timestep;
|
||||
|
||||
use crate::{
|
||||
rate_limiter::RateLimiter,
|
||||
@@ -40,7 +40,6 @@ mod assets;
|
||||
mod profiler;
|
||||
mod rate_limiter;
|
||||
mod testbed;
|
||||
mod timestep;
|
||||
mod vulkan;
|
||||
|
||||
fn init_logging() {
|
||||
@@ -114,8 +113,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut profiler = profiler::Profiler::new(1000);
|
||||
let mut frame_index: u64 = 0;
|
||||
|
||||
let mut timestep = Timestep::new();
|
||||
timestep.set_tps(60.0);
|
||||
let mut timestep = Timestep::new(60.0);
|
||||
|
||||
let mut limiter = RateLimiter::new();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::timestep::get_micros;
|
||||
use wlx_common::timestep::get_micros;
|
||||
|
||||
pub struct Profiler {
|
||||
interval_us: u64,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::timestep::get_micros;
|
||||
use wlx_common::timestep::get_micros;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RateLimiter {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
use std::{sync::LazyLock, time::Instant};
|
||||
static TIME_START: LazyLock<Instant> = LazyLock::new(Instant::now);
|
||||
|
||||
pub fn get_micros() -> u64 {
|
||||
TIME_START.elapsed().as_micros() as u64
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Timestep {
|
||||
current_time_us: u64,
|
||||
accumulator: f32,
|
||||
time_micros: u64,
|
||||
ticks: u32,
|
||||
speed: f32,
|
||||
pub alpha: f32,
|
||||
delta: f32,
|
||||
loopnum: u8,
|
||||
}
|
||||
|
||||
impl Timestep {
|
||||
pub fn new() -> Timestep {
|
||||
let mut timestep = Timestep {
|
||||
speed: 1.0,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
timestep.reset();
|
||||
timestep
|
||||
}
|
||||
|
||||
fn calculate_alpha(&mut self) {
|
||||
self.alpha = (self.accumulator / self.delta).clamp(0.0, 1.0);
|
||||
}
|
||||
|
||||
pub fn set_tps(&mut self, tps: f32) {
|
||||
self.delta = 1000.0 / tps;
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.current_time_us = get_micros();
|
||||
self.accumulator = 0.0;
|
||||
}
|
||||
|
||||
pub fn on_tick(&mut self) -> bool {
|
||||
let newtime = get_micros();
|
||||
let frametime = newtime - self.current_time_us;
|
||||
self.time_micros += frametime;
|
||||
self.current_time_us = newtime;
|
||||
self.accumulator += frametime as f32 * self.speed / 1000.0;
|
||||
self.calculate_alpha();
|
||||
|
||||
if self.accumulator >= self.delta {
|
||||
self.accumulator -= self.delta;
|
||||
self.loopnum += 1;
|
||||
self.ticks += 1;
|
||||
|
||||
if self.loopnum > 5 {
|
||||
// cannot keep up!
|
||||
self.loopnum = 0;
|
||||
self.accumulator = 0.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
} else {
|
||||
self.loopnum = 0;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user