mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-18 00:12:38 -06:00
Compare commits
3 Commits
4cc5816d1f
...
v0.60.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
028ee28840 | ||
|
|
a489bff0d1 | ||
|
|
0907b5ebe7 |
@@ -13,6 +13,7 @@ keywords = ["game", "pacman", "arcade", "sdl2"]
|
|||||||
categories = ["games", "emulators"]
|
categories = ["games", "emulators"]
|
||||||
publish = false
|
publish = false
|
||||||
exclude = ["/assets/unpacked/**", "/assets/site/**", "/bacon.toml", "/Justfile"]
|
exclude = ["/assets/unpacked/**", "/assets/site/**", "/bacon.toml", "/Justfile"]
|
||||||
|
default-run = "pacman"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
4
Justfile
4
Justfile
@@ -38,3 +38,7 @@ coverage:
|
|||||||
samply:
|
samply:
|
||||||
cargo build --profile profile
|
cargo build --profile profile
|
||||||
samply record ./target/profile/pacman{{ binary_extension }}
|
samply record ./target/profile/pacman{{ binary_extension }}
|
||||||
|
|
||||||
|
# Build the project for Emscripten
|
||||||
|
web:
|
||||||
|
bun run web.build.ts
|
||||||
|
|||||||
91
src/bin/timing_demo.rs
Normal file
91
src/bin/timing_demo.rs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
use circular_buffer::CircularBuffer;
|
||||||
|
use pacman::constants::CANVAS_SIZE;
|
||||||
|
use sdl2::event::Event;
|
||||||
|
use sdl2::keyboard::Keycode;
|
||||||
|
use sdl2::pixels::Color;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
fn main() -> Result<(), String> {
|
||||||
|
let sdl_context = sdl2::init()?;
|
||||||
|
let video_subsystem = sdl_context.video()?;
|
||||||
|
|
||||||
|
let window = video_subsystem
|
||||||
|
.window("SDL2 Timing Demo", CANVAS_SIZE.x, CANVAS_SIZE.y)
|
||||||
|
.opengl()
|
||||||
|
.position_centered()
|
||||||
|
.build()
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let mut canvas = window.into_canvas().accelerated().build().map_err(|e| e.to_string())?;
|
||||||
|
canvas
|
||||||
|
.set_logical_size(CANVAS_SIZE.x, CANVAS_SIZE.y)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let mut event_pump = sdl_context.event_pump()?;
|
||||||
|
|
||||||
|
// Store frame timings in milliseconds
|
||||||
|
let mut frame_timings = CircularBuffer::<20_000, f64>::new();
|
||||||
|
let mut last_report_time = Instant::now();
|
||||||
|
let report_interval = Duration::from_millis(500);
|
||||||
|
|
||||||
|
'running: loop {
|
||||||
|
let frame_start_time = Instant::now();
|
||||||
|
|
||||||
|
for event in event_pump.poll_iter() {
|
||||||
|
match event {
|
||||||
|
Event::Quit { .. }
|
||||||
|
| Event::KeyDown {
|
||||||
|
keycode: Some(Keycode::Escape),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
break 'running;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the screen
|
||||||
|
canvas.set_draw_color(Color::RGB(0, 0, 0));
|
||||||
|
canvas.clear();
|
||||||
|
canvas.present();
|
||||||
|
|
||||||
|
// Record timing
|
||||||
|
let frame_duration = frame_start_time.elapsed();
|
||||||
|
frame_timings.push_back(frame_duration.as_secs_f64());
|
||||||
|
|
||||||
|
// Report stats every `report_interval`
|
||||||
|
let elapsed = last_report_time.elapsed();
|
||||||
|
if elapsed >= report_interval {
|
||||||
|
if !frame_timings.is_empty() {
|
||||||
|
let count = frame_timings.len() as f64;
|
||||||
|
let sum: f64 = frame_timings.iter().sum();
|
||||||
|
let mean = sum / count;
|
||||||
|
|
||||||
|
let variance = frame_timings
|
||||||
|
.iter()
|
||||||
|
.map(|value| {
|
||||||
|
let diff = mean - value;
|
||||||
|
diff * diff
|
||||||
|
})
|
||||||
|
.sum::<f64>()
|
||||||
|
/ count;
|
||||||
|
let std_dev = variance.sqrt();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Rendered {count} frames at {fps:.1} fps (last {elapsed:.2?}): mean={mean:.3?}, std_dev={std_dev:.3?}",
|
||||||
|
count = frame_timings.len(),
|
||||||
|
fps = count / elapsed.as_secs_f64(),
|
||||||
|
elapsed = elapsed,
|
||||||
|
mean = Duration::from_secs_f64(mean),
|
||||||
|
std_dev = Duration::from_secs_f64(std_dev),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset for next interval
|
||||||
|
frame_timings.clear();
|
||||||
|
last_report_time = Instant::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Desktop platform implementation.
|
//! Desktop platform implementation.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Duration;
|
||||||
|
|
||||||
use rand::rngs::ThreadRng;
|
use rand::rngs::ThreadRng;
|
||||||
|
|
||||||
@@ -17,10 +17,6 @@ pub fn sleep(duration: Duration, focused: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_time() -> f64 {
|
|
||||||
Instant::now().elapsed().as_secs_f64()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_console() -> Result<(), PlatformError> {
|
pub fn init_console() -> Result<(), PlatformError> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
@@ -53,10 +49,6 @@ pub fn requires_console() -> bool {
|
|||||||
cfg!(windows)
|
cfg!(windows)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_canvas_size() -> Option<(u32, u32)> {
|
|
||||||
None // Desktop doesn't need this
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
|
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
|
||||||
match asset {
|
match asset {
|
||||||
Asset::Wav1 => Ok(Cow::Borrowed(include_bytes!("../../assets/game/sound/waka/1.ogg"))),
|
Asset::Wav1 => Ok(Cow::Borrowed(include_bytes!("../../assets/game/sound/waka/1.ogg"))),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::error::{AssetError, PlatformError};
|
|||||||
use rand::{rngs::SmallRng, SeedableRng};
|
use rand::{rngs::SmallRng, SeedableRng};
|
||||||
|
|
||||||
// Emscripten FFI functions
|
// Emscripten FFI functions
|
||||||
|
#[allow(dead_code)]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn emscripten_get_now() -> f64;
|
fn emscripten_get_now() -> f64;
|
||||||
fn emscripten_sleep(ms: u32);
|
fn emscripten_sleep(ms: u32);
|
||||||
@@ -20,10 +21,6 @@ pub fn sleep(duration: Duration, _focused: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_time() -> f64 {
|
|
||||||
unsafe { emscripten_get_now() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_console() -> Result<(), PlatformError> {
|
pub fn init_console() -> Result<(), PlatformError> {
|
||||||
Ok(()) // No-op for Emscripten
|
Ok(()) // No-op for Emscripten
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,8 +225,6 @@ pub fn render_system(
|
|||||||
})
|
})
|
||||||
.err()
|
.err()
|
||||||
.map(|e| errors.write(TextureError::RenderFailed(e.to_string()).into()));
|
.map(|e| errors.write(TextureError::RenderFailed(e.to_string()).into()));
|
||||||
|
|
||||||
canvas.copy(&backbuffer.0, None, None).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn present_system(
|
pub fn present_system(
|
||||||
|
|||||||
Reference in New Issue
Block a user