stevenarella/std_or_web/src/lib.rs

55 lines
1.6 KiB
Rust
Raw Normal View History

use cfg_if::cfg_if;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
// TODO: a real filesystem like https://emscripten.org/docs/api_reference/Filesystem-API.html
pub mod fs {
use std::convert::AsRef;
use std::io::Result;
use std::path::Path;
use std::io::{Read, Write};
pub struct File { }
impl File {
pub fn create<P: AsRef<Path>>(path: P) -> Result<File> {
println!("File create {}", path.as_ref().to_str().unwrap());
Ok(File{})
}
pub fn open<P: AsRef<Path>>(path: P) -> Result<File> {
println!("File open {}", path.as_ref().to_str().unwrap());
Ok(File{})
}
}
impl Read for File {
fn read(&mut self, _buf: &mut [u8]) -> Result<usize> {
println!("File read");
Ok(0)
}
}
impl Read for &File {
fn read(&mut self, _buf: &mut [u8]) -> Result<usize> {
println!("&File read");
Ok(0)
}
}
impl Write for File {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
println!("File write {:?}", buf);
Ok(buf.len())
}
fn flush(&mut self) -> Result<()> {
Ok(())
}
}
}
} else {
pub use std::fs;
}
}