Skip to content

Commit

Permalink
replace instant with web-time, vide rust-windowing/winit#2836
Browse files Browse the repository at this point in the history
  • Loading branch information
pillowtrucker committed Dec 21, 2023
1 parent 53586ba commit db92dae
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rend3-routine = { version = "^0.3.0",path = "rend3/rend3-routine" }
webbrowser = "0.8.2"

bytemuck = { version = "1.14.0", features = ["derive"] }
instant = "0.1.12"
web-time = "0.2.3"
nanorand = { version = "0.7", default-features = false, features = ["wyrand"] }
pico-args = "0.5"
wgpu-profiler = "0.15.0"
Expand Down
4 changes: 2 additions & 2 deletions assets/LinacLab.blend
Git LFS file not shown
2 changes: 1 addition & 1 deletion assets/LinacLab.blend1
Git LFS file not shown
2 changes: 1 addition & 1 deletion rend3
28 changes: 15 additions & 13 deletions src/brainworms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use backstage::pyrotechnics::kinetic_narrative::{Gay, KineticEffect, KineticLabe
use egui::{Color32, TextStyle, Visuals};
use frame_rate::FrameRate;
use glam::{DVec2, Mat3A, Mat4, Vec3, Vec3A};
use instant::{Duration, Instant};
use log::info;
use nanorand::{RandomGen, Rng};
use pico_args::Arguments;
Expand Down Expand Up @@ -36,20 +35,23 @@ use winit::{event::WindowEvent, event_loop::EventLoopWindowTarget};

use crate::backstage::plumbing::platform_scancodes::Scancodes;
use crate::play::stage3d::{button_pressed, load_gltf, load_skybox, spawn};
#[cfg(not(wasm_platform))]
use std::time;
#[cfg(wasm_platform)]
use web_time as time;
#[cfg(target_arch = "wasm32")]
use winit::keyboard::PhysicalKey::Code;
#[cfg(not(target_arch = "wasm32"))]
use winit::platform::scancode::PhysicalKeyExtScancode;

struct GameProgrammeData {
egui_routine: rend3_egui::EguiRenderRoutine,
egui_ctx: egui::Context,
platform: egui_winit::State,
_test_text: String,
test_lines: String,
random_line_effects: Vec<KineticEffect>,
_start_time: instant::Instant,
last_update: instant::Instant,
_start_time: time::Instant,
last_update: time::Instant,
frame_rate: FrameRate,
elapsed: f32,
}
Expand Down Expand Up @@ -113,8 +115,8 @@ struct GameProgrammeSettings {
camera_yaw: f32,
camera_location: Vec3A,
previous_profiling_stats: Option<Vec<GpuTimerScopeResult>>,
timestamp_last_second: Instant,
timestamp_last_frame: Instant,
timestamp_last_second: time::Instant,
timestamp_last_frame: time::Instant,
frame_times: histogram::Histogram,
last_mouse_delta: Option<DVec2>,

Expand Down Expand Up @@ -238,8 +240,8 @@ impl GameProgrammeSettings {
camera_yaw: camera_info[4],
camera_location: Vec3A::new(camera_info[0], camera_info[1], camera_info[2]),
previous_profiling_stats: None,
timestamp_last_second: Instant::now(),
timestamp_last_frame: Instant::now(),
timestamp_last_second: time::Instant::now(),
timestamp_last_frame: time::Instant::now(),
frame_times: histogram::Histogram::new(),
last_mouse_delta: None,

Expand Down Expand Up @@ -404,8 +406,8 @@ impl rend3_framework::App for GameProgramme {
//Images

self.data = Some(GameProgrammeData {
_start_time: instant::Instant::now(),
last_update: instant::Instant::now(),
_start_time: time::Instant::now(),
last_update: time::Instant::now(),
frame_rate: FrameRate::new(100),
elapsed: 0.0,
egui_routine,
Expand Down Expand Up @@ -465,7 +467,7 @@ impl rend3_framework::App for GameProgramme {
let last_frame_duration = data.last_update.elapsed().as_secs_f32();
data.elapsed += last_frame_duration;
data.frame_rate.update(last_frame_duration);
data.last_update = instant::Instant::now();
data.last_update = time::Instant::now();
let view = Mat4::from_euler(
glam::EulerRot::XYZ,
-self.settings.camera_pitch,
Expand Down Expand Up @@ -581,7 +583,7 @@ impl rend3_framework::App for GameProgramme {
}
rend3_framework::Event::AboutToWait => {
profiling::scope!("MainEventsCleared");
let now = Instant::now();
let now = time::Instant::now();

let delta_time = now - self.settings.timestamp_last_frame;
self.settings
Expand All @@ -590,7 +592,7 @@ impl rend3_framework::App for GameProgramme {
.unwrap();

let elapsed_since_second = now - self.settings.timestamp_last_second;
if elapsed_since_second > Duration::from_secs(1) {
if elapsed_since_second > time::Duration::from_secs(1) {
let count = self.settings.frame_times.entries();
println!(
"{:0>5} frames over {:0>5.2}s. \
Expand Down
19 changes: 11 additions & 8 deletions src/play/stage3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use glam::{DVec2, Mat3A, Mat4, UVec2, Vec3, Vec3A};
use instant::Instant;
use pico_args::Arguments;
use rend3::{
types::{
Expand All @@ -18,6 +17,10 @@ use rend3::{
use rend3_framework::{lock, AssetPath, Mutex, UserResizeEvent};
use rend3_gltf::GltfSceneInstance;
use rend3_routine::{base::BaseRenderGraph, pbr::NormalTextureYDirection, skybox::SkyboxRoutine};
#[cfg(not(wasm_platform))]
use std::time;
#[cfg(wasm_platform)]
use web_time as time;
use wgpu_profiler::GpuTimerScopeResult;
#[cfg(target_arch = "wasm32")]
use winit::keyboard::PhysicalKey::Code;
Expand Down Expand Up @@ -79,7 +82,7 @@ pub(crate) async fn load_gltf(
location: AssetPath<'_>,
) -> Option<(rend3_gltf::LoadedGltfScene, GltfSceneInstance)> {
// profiling::scope!("loading gltf");
let gltf_start = Instant::now();
let gltf_start = time::Instant::now();
let is_default_scene = matches!(location, AssetPath::Internal(_));
let path = loader.get_asset_path(location);
let path = Path::new(&*path);
Expand Down Expand Up @@ -120,7 +123,7 @@ pub(crate) async fn load_gltf(
};

let gltf_elapsed = gltf_start.elapsed();
let resources_start = Instant::now();
let resources_start = time::Instant::now();
let (scene, instance) = rend3_gltf::load_gltf(renderer, &gltf_data, settings, |uri| async {
if let Some(base64) = rend3_gltf::try_load_base64(&uri) {
Ok(base64)
Expand Down Expand Up @@ -315,8 +318,8 @@ struct SceneViewer {
camera_yaw: f32,
camera_location: Vec3A,
previous_profiling_stats: Option<Vec<GpuTimerScopeResult>>,
timestamp_last_second: Instant,
timestamp_last_frame: Instant,
timestamp_last_second: time::Instant,
timestamp_last_frame: time::Instant,
frame_times: histogram::Histogram,
last_mouse_delta: Option<DVec2>,

Expand Down Expand Up @@ -441,8 +444,8 @@ impl SceneViewer {
camera_yaw: camera_info[4],
camera_location: Vec3A::new(camera_info[0], camera_info[1], camera_info[2]),
previous_profiling_stats: None,
timestamp_last_second: Instant::now(),
timestamp_last_frame: Instant::now(),
timestamp_last_second: time::Instant::now(),
timestamp_last_frame: time::Instant::now(),
frame_times: histogram::Histogram::new(),
last_mouse_delta: None,

Expand Down Expand Up @@ -552,7 +555,7 @@ impl rend3_framework::App for SceneViewer {
match event {
Event::AboutToWait => {
profiling::scope!("MainEventsCleared");
let now = Instant::now();
let now = time::Instant::now();

let delta_time = now - self.timestamp_last_frame;
self.frame_times
Expand Down

0 comments on commit db92dae

Please sign in to comment.