X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=support%2Fmod.rs;h=add172f33632c53ebec10cc9947c561fb34fe67a;hb=a8aebfadf8f18928b3f8ced81a7f0d4a4421466d;hp=8996e55de71827c6e2f93b8a2153c42ba7832d34;hpb=b1f47d18bd76c1d1475f992f021e714289f4b79a;p=mandelwow.git diff --git a/support/mod.rs b/support/mod.rs index 8996e55..add172f 100644 --- a/support/mod.rs +++ b/support/mod.rs @@ -1,10 +1,5 @@ #![allow(dead_code)] -extern crate genmesh; -extern crate obj; - -use std::thread; -use std::time::{Duration, Instant}; use glium::{self, Display}; use glium::vertex::VertexBufferAny; @@ -17,69 +12,10 @@ pub enum Action { } pub fn start_loop(mut callback: F) where F: FnMut() -> Action { - let mut accumulator = Duration::new(0, 0); - let mut previous_clock = Instant::now(); - loop { match callback() { Action::Stop => break, Action::Continue => () }; - - let now = Instant::now(); - accumulator += now - previous_clock; - previous_clock = now; - - let fixed_time_stamp = Duration::new(0, 16666667); - while accumulator >= fixed_time_stamp { - accumulator -= fixed_time_stamp; - - // if you have a game, update the state here - } - - thread::sleep(fixed_time_stamp - accumulator); - } -} - -/// Returns a vertex buffer that should be rendered as `TrianglesList`. -pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny { - #[derive(Copy, Clone)] - struct Vertex { - position: [f32; 3], - normal: [f32; 3], - texture: [f32; 2], } - - implement_vertex!(Vertex, position, normal, texture); - - let mut data = ::std::io::BufReader::new(data); - let data = obj::Obj::load(&mut data); - - let mut vertex_data = Vec::new(); - - for object in data.object_iter() { - for shape in object.group_iter().flat_map(|g| g.indices().iter()) { - match shape { - &genmesh::Polygon::PolyTri(genmesh::Triangle { x: v1, y: v2, z: v3 }) => { - for v in [v1, v2, v3].iter() { - let position = data.position()[v.0]; - let texture = v.1.map(|index| data.texture()[index]); - let normal = v.2.map(|index| data.normal()[index]); - - let texture = texture.unwrap_or([0.0, 0.0]); - let normal = normal.unwrap_or([0.0, 0.0, 0.0]); - - vertex_data.push(Vertex { - position: position, - normal: normal, - texture: texture, - }) - } - }, - _ => unimplemented!() - } - } - } - - glium::vertex::VertexBuffer::new(display, &vertex_data).unwrap().into_vertex_buffer_any() }