+#[cfg(target_os = "emscripten")]
+pub fn set_main_loop_callback<F>(callback: F)
+where
+ F: FnMut() -> support::Action,
+{
+ MAIN_LOOP_CALLBACK.with(|log| {
+ *log.borrow_mut() = &callback as *const _ as *mut c_void;
+ });
+
+ unsafe {
+ emscripten_set_main_loop(wrapper::<F>, 0, 1);
+ }
+
+ unsafe extern "C" fn wrapper<F>()
+ where
+ F: FnMut() -> support::Action,
+ {
+ MAIN_LOOP_CALLBACK.with(|z| {
+ let closure = *z.borrow_mut() as *mut F;
+ (*closure)();
+ });
+ }
+}
+
+#[cfg(not(target_os = "emscripten"))]
+pub fn set_main_loop_callback<F>(callback: F)
+where
+ F: FnMut() -> support::Action,
+{
+ support::start_loop(callback);
+}
+
+//extern crate gleam;
+
+/*
+extern "C" {
+ fn emscripten_GetProcAddress(
+ name: *const ::std::os::raw::c_char,
+ ) -> *const ::std::os::raw::c_void;
+}
+*/
+
+fn main() {
+ /*
+ let gl = gleam::gl::GlesFns::load_with(|addr| {
+ let addr = std::ffi::CString::new(addr).unwrap();
+ emscripten_GetProcAddress(addr.into_raw() as *const _) as *const _
+ });
+ gl.glGetInternalformativ(0, 0, 0, 0, 0);
+ */
+
+ let mut soundplayer = sound::start();
+
+ let event_loop = glutin::event_loop::EventLoop::new();
+ //let fullscreen = Some(glutin::window::Fullscreen::Borderless(event_loop.primary_monitor()));
+ let window = glutin::window::WindowBuilder::new()
+ //.with_dimensions(1280, 720)
+ //.with_fullscreen(fullscreen);
+ ;
+ //.with_title("MandelWow");
+ let context = glutin::ContextBuilder::new()
+ //.with_gl_profile(glutin::GlProfile::Core)
+ //.with_gl(glutin::GlRequest::Specific(glutin::Api::WebGl, (2, 0)))
+ .with_gl(glutin::GlRequest::Specific(
+ glutin::Api::OpenGlEs,
+ (3, 0),
+ ))
+ //.with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (4, 0)))
+ //.with_depth_buffer(24)
+ .with_vsync(true);
+
+ let display = glium::Display::new(window, context, &event_loop).unwrap();
+ gl_info(&display);
+ let mut world = World::new(&display);
+
+ let mut timer = Timer::new();
+ let mut camera = support::camera::CameraState::new();
+ let _fullscreen = true;
+
+ event_loop.run(move |event, _, control_flow| {
+ let t = timer.t;
+ let new_hit = sound::hit_event(&mut soundplayer);
+ if new_hit > world.last_hit {
+ world.hit_time = t;
+ }
+ world.last_hit = new_hit;
+
+ camera.update();
+
+ *control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::from_nanos(16666667));
+ match event {
+ Event::NewEvents(cause) => {
+ match cause {
+ event::StartCause::ResumeTimeReached { .. } | event::StartCause::Init => {
+ world.draw_frame(&display, &camera, t);
+ },
+ _ => {}
+ }
+ } _ => (),
+ }
+ if let Event::WindowEvent { event, .. } = event {
+ camera.process_input(&event);
+ match event {
+ WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
+ WindowEvent::KeyboardInput { input, .. } => {
+ if input.state == event::ElementState::Pressed {
+ if let Some(key) = input.virtual_keycode {
+ match key {
+ VirtualKeyCode::Escape | VirtualKeyCode::Q => {
+ *control_flow = ControlFlow::Exit;
+ }
+ _ => (),
+ }
+ }
+ }
+ }
+ /*
+ KeyboardInput { input: glutin::KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::Escape), .. } } |
+ KeyboardInput { input: glutin::KeyboardInput { state: Pressed, virtual_keycode: Some(VirtualKeyCode::Q), .. } } => {
+ *control_flow = ControlFlow::Exit;