• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Xevion / Pac-Man / 16885120893

11 Aug 2025 03:49PM UTC coverage: 49.087% (-3.7%) from 52.782%
16885120893

push

github

Xevion
refactor: platform trait, platform-specific code handling into platform module

0 of 103 new or added lines in 5 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

645 of 1314 relevant lines covered (49.09%)

364.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/platform/emscripten.rs
1
//! Emscripten platform implementation.
2

3
use std::borrow::Cow;
4
use std::time::Duration;
5

6
use crate::asset::{Asset, AssetError};
7
use crate::platform::{Platform, PlatformError};
8

9
/// Emscripten platform implementation.
10
pub struct EmscriptenPlatform;
11

12
impl Platform for EmscriptenPlatform {
NEW
13
    fn sleep(&self, duration: Duration) {
×
NEW
14
        unsafe {
×
NEW
15
            emscripten_sleep(duration.as_millis() as u32);
×
NEW
16
        }
×
NEW
17
    }
×
18

NEW
19
    fn get_time(&self) -> f64 {
×
NEW
20
        unsafe { emscripten_get_now() }
×
NEW
21
    }
×
22

NEW
23
    fn init_console(&self) -> Result<(), PlatformError> {
×
NEW
24
        Ok(()) // No-op for Emscripten
×
NEW
25
    }
×
26

NEW
27
    fn get_canvas_size(&self) -> Option<(u32, u32)> {
×
NEW
28
        Some(unsafe { get_canvas_size() })
×
NEW
29
    }
×
30

NEW
31
    fn get_asset_bytes(&self, asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
×
32
        use sdl2::rwops::RWops;
33
        use std::io::Read;
34

NEW
35
        let path = format!("assets/game/{}", asset.path());
×
NEW
36
        let mut rwops = RWops::from_file(&path, "rb").map_err(|_| AssetError::NotFound(asset.path().to_string()))?;
×
37

NEW
38
        let len = rwops.len().ok_or_else(|| AssetError::NotFound(asset.path().to_string()))?;
×
39

NEW
40
        let mut buf = vec![0u8; len];
×
NEW
41
        rwops
×
NEW
42
            .read_exact(&mut buf)
×
NEW
43
            .map_err(|e| AssetError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
×
44

NEW
45
        Ok(Cow::Owned(buf))
×
NEW
46
    }
×
47
}
48

49
// Emscripten FFI functions
50
extern "C" {
51
    fn emscripten_get_now() -> f64;
52
    fn emscripten_sleep(ms: u32);
53
    fn emscripten_get_element_css_size(target: *const u8, width: *mut f64, height: *mut f64) -> i32;
54
}
55

NEW
56
unsafe fn get_canvas_size() -> (u32, u32) {
×
NEW
57
    let mut width = 0.0;
×
NEW
58
    let mut height = 0.0;
×
NEW
59
    emscripten_get_element_css_size("canvas\0".as_ptr(), &mut width, &mut height);
×
NEW
60
    (width as u32, height as u32)
×
NEW
61
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc