aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-13 18:36:24 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-13 18:36:24 -0400
commit9f8c9bd56c99273b5e59992fd6620b3aabfd3655 (patch)
tree6a8f7d1c1ef6ad5e901605528a7c5a268f812df2
parent0a86f0f0b7e74c2c9a09d7cef4c722e4024fcc6d (diff)
downloadexuberant-hacks-9f8c9bd56c99273b5e59992fd6620b3aabfd3655.tar.gz
exuberant-hacks-9f8c9bd56c99273b5e59992fd6620b3aabfd3655.zip
refactor exuberantbovines into src/bin
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml5
-rwxr-xr-xoriginal/model_c2rs.py2
-rw-r--r--src/bin/cow_model/cow_face.rs (renamed from src/cow_face.rs)2
-rw-r--r--src/bin/cow_model/cow_hide.rs (renamed from src/cow_hide.rs)2
-rw-r--r--src/bin/cow_model/cow_hoofs.rs (renamed from src/cow_hoofs.rs)2
-rw-r--r--src/bin/cow_model/cow_horns.rs (renamed from src/cow_horns.rs)2
-rw-r--r--src/bin/cow_model/cow_tail.rs (renamed from src/cow_tail.rs)2
-rw-r--r--src/bin/cow_model/cow_udder.rs (renamed from src/cow_udder.rs)2
-rw-r--r--src/bin/cow_model/cow_vertex.rs (renamed from src/cow_vertex.rs)0
-rw-r--r--src/bin/cow_model/mod.rs15
-rw-r--r--src/bin/exuberantbovines.rs (renamed from src/main.rs)85
-rw-r--r--src/lib.rs67
13 files changed, 105 insertions, 83 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 10b995f..31505f1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,5 +1,5 @@
[root]
-name = "exuberant-bovines"
+name = "exuberantbovines"
version = "0.1.0"
dependencies = [
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 603f4c5..19775a6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "exuberant-bovines"
+name = "exuberantbovines"
version = "0.1.0"
authors = ["bnewbold <bnewbold@robocracy.org>"]
@@ -12,6 +12,3 @@ glium = "0.*"
image = "0.*"
getopts = "^0.2"
-[[bin]]
-name = "exuberantbovines"
-path = "src/main.rs"
diff --git a/original/model_c2rs.py b/original/model_c2rs.py
index 9d6c63b..832fac5 100755
--- a/original/model_c2rs.py
+++ b/original/model_c2rs.py
@@ -33,7 +33,7 @@ def main():
// This file auto-generated from %s.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const %s_VERTICES: [Vertex; %d] = [
""" % (fname, fname.upper(), len(vertices)))
diff --git a/src/cow_face.rs b/src/bin/cow_model/cow_face.rs
index 58fcf57..529d555 100644
--- a/src/cow_face.rs
+++ b/src/bin/cow_model/cow_face.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_face.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_FACE_VERTICES: [Vertex; 335] = [
Vertex { position: (4.897808, 1.946794, -0.628057),
diff --git a/src/cow_hide.rs b/src/bin/cow_model/cow_hide.rs
index 8e426af..6972b62 100644
--- a/src/cow_hide.rs
+++ b/src/bin/cow_model/cow_hide.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_hide.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_HIDE_VERTICES: [Vertex; 13049] = [
Vertex { position: (2.229345, -0.992723, -0.862826),
diff --git a/src/cow_hoofs.rs b/src/bin/cow_model/cow_hoofs.rs
index 454e2c9..5d3fb25 100644
--- a/src/cow_hoofs.rs
+++ b/src/bin/cow_model/cow_hoofs.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_hoofs.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_HOOFS_VERTICES: [Vertex; 1031] = [
Vertex { position: (1.970051, -3.141862, -1.065178),
diff --git a/src/cow_horns.rs b/src/bin/cow_model/cow_horns.rs
index 72b9b8d..86f1954 100644
--- a/src/cow_horns.rs
+++ b/src/bin/cow_model/cow_horns.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_horns.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_HORNS_VERTICES: [Vertex; 1019] = [
Vertex { position: (4.22473, 2.624525, -0.491916),
diff --git a/src/cow_tail.rs b/src/bin/cow_model/cow_tail.rs
index 4dba8f4..93148ca 100644
--- a/src/cow_tail.rs
+++ b/src/bin/cow_model/cow_tail.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_tail.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_TAIL_VERTICES: [Vertex; 458] = [
Vertex { position: (-3.67645, -0.551317, 0.077574),
diff --git a/src/cow_udder.rs b/src/bin/cow_model/cow_udder.rs
index 2ed7cdd..1d48444 100644
--- a/src/cow_udder.rs
+++ b/src/bin/cow_model/cow_udder.rs
@@ -2,7 +2,7 @@
// This file auto-generated from cow_udder.c using model_c2rs.py
// Don't edit by hand!
-use cow_vertex::Vertex;
+use super::cow_vertex::Vertex;
pub const COW_UDDER_VERTICES: [Vertex; 1514] = [
Vertex { position: (-2.033406, -0.91003, -0.96422),
diff --git a/src/cow_vertex.rs b/src/bin/cow_model/cow_vertex.rs
index c099052..c099052 100644
--- a/src/cow_vertex.rs
+++ b/src/bin/cow_model/cow_vertex.rs
diff --git a/src/bin/cow_model/mod.rs b/src/bin/cow_model/mod.rs
new file mode 100644
index 0000000..c0fdb01
--- /dev/null
+++ b/src/bin/cow_model/mod.rs
@@ -0,0 +1,15 @@
+
+mod cow_vertex;
+mod cow_face;
+mod cow_hide;
+mod cow_hoofs;
+mod cow_horns;
+mod cow_tail;
+mod cow_udder;
+
+pub use self::cow_face::COW_FACE_VERTICES;
+pub use self::cow_hide::COW_HIDE_VERTICES;
+pub use self::cow_hoofs::COW_HOOFS_VERTICES;
+pub use self::cow_horns::COW_HORNS_VERTICES;
+pub use self::cow_tail::COW_TAIL_VERTICES;
+pub use self::cow_udder::COW_UDDER_VERTICES;
diff --git a/src/main.rs b/src/bin/exuberantbovines.rs
index af0a37f..1fdf7a0 100644
--- a/src/main.rs
+++ b/src/bin/exuberantbovines.rs
@@ -1,25 +1,16 @@
+extern crate exuberantbovines;
+extern crate getopts;
+
#[macro_use]
extern crate glium;
-extern crate image;
-extern crate getopts;
-
-use std::env;
-use std::u64;
-use std::process::exit;
+use exuberantbovines::{generic_main, util};
use getopts::Options;
use glium::glutin::os::unix::WindowBuilderExt;
-
-mod util;
-mod cow_vertex;
-mod cow_face;
-mod cow_hide;
-mod cow_hoofs;
-mod cow_horns;
-mod cow_tail;
-mod cow_udder;
+mod cow_model;
+
fn run(window_id: Option<u64>) {
use glium::{DisplayBuild, Surface};
@@ -40,17 +31,17 @@ fn run(window_id: Option<u64>) {
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
let face_vertices = glium::VertexBuffer::new(
- &display, &cow_face::COW_FACE_VERTICES).unwrap();
+ &display, &cow_model::COW_FACE_VERTICES).unwrap();
let hide_vertices = glium::VertexBuffer::new(
- &display, &cow_hide::COW_HIDE_VERTICES).unwrap();
+ &display, &cow_model::COW_HIDE_VERTICES).unwrap();
let hoofs_vertices = glium::VertexBuffer::new(
- &display, &cow_hoofs::COW_HOOFS_VERTICES).unwrap();
+ &display, &cow_model::COW_HOOFS_VERTICES).unwrap();
let horns_vertices = glium::VertexBuffer::new(
- &display, &cow_horns::COW_HORNS_VERTICES).unwrap();
+ &display, &cow_model::COW_HORNS_VERTICES).unwrap();
let tail_vertices = glium::VertexBuffer::new(
- &display, &cow_tail::COW_TAIL_VERTICES).unwrap();
+ &display, &cow_model::COW_TAIL_VERTICES).unwrap();
let udder_vertices = glium::VertexBuffer::new(
- &display, &cow_udder::COW_UDDER_VERTICES).unwrap();
+ &display, &cow_model::COW_UDDER_VERTICES).unwrap();
let vertex_shader_src = r#"
#version 140
@@ -186,63 +177,15 @@ fn run(window_id: Option<u64>) {
}
-fn print_usage(program: &str, opts: Options) {
- let brief = format!("Usage: {} [options]", program);
- print!("{}", opts.usage(&brief));
-}
-
fn main() {
- let args: Vec<String> = env::args().collect();
- let program = args[0].clone();
-
- // Turn, eg, "-root" into "--root"
- let args = util::convert_xscreensaver_args(args);
let mut opts = Options::new();
-
- // Common Args (all screensavers)
- opts.optflag("h", "help", "print this help menu");
- opts.optflag("", "window", "run in a window (IGNORED)");
- opts.optflag("", "root", "run in root window (IGNORED)");
- opts.optflag("", "fps", "show frames per second (IGNORED)");
- opts.optopt("", "window-id", "X window id number", "NUM");
-
- // Bovine-specific args
opts.optflag("", "wire", "wireframe mode (IGNORED)");
opts.optopt("c", "count", "how many cows? (1 to 9) (IGNORED)", "NUM");
opts.optopt("", "delay", "inter-frame delay (0 to 100000) (IGNORED)", "NUM");
opts.optopt("s", "speed", "how fast? ratio, with 1.0 as normal (IGNORED)", "NUM");
- let matches = match opts.parse(&args[1..]) {
- Ok(m) => { m }
- Err(f) => {
- print_usage(&program, opts);
- println!("");
- println!("{}", f.to_string());
- exit(-1);
- }
- };
-
- if matches.opt_present("help") {
- print_usage(&program, opts);
- exit(0);
- }
-
- // if no "--window-id", try environment variable (arg has priority though)
- let window_id_string: Option<String> =
- matches.opt_str("window-id")
- .or(env::var("XSCREENSAVER_WINDOW").ok());
-
- let window_id = window_id_string.map(|id| match util::dechex2u64(&id) {
- Ok(y) => y,
- Err(e) => {
- println!("Couldn't parse numerical argument: {}", e);
- exit(-1); },
- });
-
- if window_id.is_some() {
- println!("Drawing on existing X window: 0x{:07X}", window_id.unwrap());
- }
+ let (_, window_id) = generic_main(opts);
+ run(window_id)
- run(window_id);
}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..c0f537d
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,67 @@
+
+#[macro_use]
+extern crate glium;
+
+extern crate image;
+extern crate getopts;
+
+use std::env;
+use std::u64;
+use std::process::exit;
+use getopts::{Options, Matches};
+use glium::glutin::os::unix::WindowBuilderExt;
+
+pub mod util;
+
+fn print_usage(program: &str, opts: Options) {
+ let brief = format!("Usage: {} [options]", program);
+ print!("{}", opts.usage(&brief));
+}
+
+pub fn generic_main(mut opts: Options) -> (Matches, Option<u64>) {
+ let args: Vec<String> = env::args().collect();
+ let program = args[0].clone();
+
+ // Turn, eg, "-root" into "--root"
+ let args = util::convert_xscreensaver_args(args);
+
+ // Common Args (all screensavers)
+ opts.optflag("h", "help", "print this help menu");
+ opts.optflag("", "window", "run in a window (IGNORED)");
+ opts.optflag("", "root", "run in root window (IGNORED)");
+ opts.optflag("", "fps", "show frames per second (IGNORED)");
+ opts.optopt("", "window-id", "X window id number", "NUM");
+
+ let matches = match opts.parse(&args[1..]) {
+ Ok(m) => { m }
+ Err(f) => {
+ print_usage(&program, opts);
+ println!("");
+ println!("{}", f.to_string());
+ exit(-1);
+ }
+ };
+
+ if matches.opt_present("help") {
+ print_usage(&program, opts);
+ exit(0);
+ }
+
+ // if no "--window-id", try environment variable (arg has priority though)
+ let window_id_string: Option<String> =
+ matches.opt_str("window-id")
+ .or(env::var("XSCREENSAVER_WINDOW").ok());
+
+ let window_id = window_id_string.map(|id| match util::dechex2u64(&id) {
+ Ok(y) => y,
+ Err(e) => {
+ println!("Couldn't parse numerical argument: {}", e);
+ exit(-1); },
+ });
+
+ if window_id.is_some() {
+ println!("Drawing on existing X window: 0x{:07X}", window_id.unwrap());
+ }
+
+ (matches, window_id)
+}