extern crate glium;
extern crate glutin;
-#[cfg(feature = "rust-rocket")]
-extern crate rust_rocket;
-
use cgmath::{Euler, Matrix4, Rad, SquareMatrix, Vector3, Vector4, Zero};
use cgmath::conv::array4x4;
use glium::{DisplayBuild, Surface};
fn main() {
let mut soundplayer = sound::start();
- let mut rocket = rust_rocket::Rocket::new().unwrap();
- rocket.get_track_mut("test");
- rocket.get_track_mut("test2");
- rocket.get_track_mut("a:test2");
- let mut current_row = 0;
-
let display = glutin::WindowBuilder::new()
.with_dimensions(1280, 720)
.with_gl_profile(glutin::GlProfile::Core)
}
}
- if let Some(event) = rocket.poll_events() {
- match event {
- rust_rocket::Event::SetRow(row) => {
- println!("SetRow (row: {:?})", row);
- current_row = row;
- }
- rust_rocket::Event::Pause(_) => {
- let track1 = rocket.get_track("test").unwrap();
- println!("Pause (value: {:?}) (row: {:?})", track1.get_value(current_row as f32), current_row);
- }
- _ => (),
- }
- println!("{:?}", event);
- }
-
timer.update();
support::Action::Continue
use std::time::{Duration, Instant};
+#[cfg(feature = "editor")]
+use rust_rocket;
+
+#[cfg(feature = "editor")]
+type Rocket = rust_rocket::Rocket;
+
+#[cfg(not(feature = "editor"))]
+type Rocket = ();
+
+const BPS: f32 = 10.0;
+
#[derive(Debug)]
pub struct Timer {
pub t: f32,
accum_idle_time: Duration,
pub pause: bool,
+
+ pub rocket: Option<Rocket>,
}
impl Timer {
accum_draw_time: Duration::default(),
accum_idle_time: Duration::default(),
pause: false,
+ rocket: Timer::init_rocket(),
}
}
pub fn update(&mut self) {
let now = Instant::now();
+ self.poll_rocket();
if !self.pause {
// Increment time
self.t += 0.01;
let avg_idle_time = millis(self.accum_idle_time / frames_done);
println!("fps={:.1} draw={:.1}ms idle={:.1}ms", fps, avg_draw_time, avg_idle_time);
}
+
+ #[cfg(not(feature = "editor"))]
+ fn init_rocket() -> Option<Rocket> { None }
+
+ #[cfg(not(feature = "editor"))]
+ fn poll_rocket(&mut self) {}
+
+ #[cfg(feature = "editor")]
+ fn init_rocket() -> Option<Rocket> {
+ Rocket::new().ok()
+ }
+
+ #[cfg(feature = "editor")]
+ fn poll_rocket(&mut self) {
+ match self.rocket {
+ Some(ref mut rocket) => {
+ let current_row = (self.t * BPS) as u32;
+ if let Some(event) = rocket.poll_events() {
+ match event {
+ rust_rocket::Event::SetRow(row) => {
+ println!("SetRow (row: {:?})", row);
+ self.t = row as f32 / BPS;
+ }
+ rust_rocket::Event::Pause(_) => {
+ let track1 = rocket.get_track_mut("test");
+ println!("Pause (value: {:?}) (row: {:?})", track1.get_value(current_row as f32), current_row);
+ }
+ _ => (),
+ }
+ println!("{:?}", event);
+ }
+ }
+ None => ()
+ }
+ }
}