Release 0.1.5: Update dependencies and reworked argument parsing
This commit is contained in:
parent
be66e2cad3
commit
9c6c423e16
7 changed files with 150 additions and 71 deletions
82
Cargo.lock
generated
82
Cargo.lock
generated
|
@ -4,15 +4,16 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ELApse"
|
name = "ELApse"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"image",
|
"image",
|
||||||
"piston",
|
"piston",
|
||||||
"piston2d-graphics",
|
"piston2d-graphics 0.45.0",
|
||||||
"piston_window",
|
"piston_window",
|
||||||
"rand",
|
"rand",
|
||||||
"unreal_asset",
|
"unreal_asset",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -623,6 +624,15 @@ version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "funty"
|
name = "funty"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
@ -809,6 +819,16 @@ version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-bidi",
|
||||||
|
"unicode-normalization",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "image"
|
name = "image"
|
||||||
version = "0.25.2"
|
version = "0.25.2"
|
||||||
|
@ -1413,7 +1433,7 @@ dependencies = [
|
||||||
"gfx",
|
"gfx",
|
||||||
"piston-gfx_texture",
|
"piston-gfx_texture",
|
||||||
"piston-shaders_graphics2d",
|
"piston-shaders_graphics2d",
|
||||||
"piston2d-graphics",
|
"piston2d-graphics 0.44.0",
|
||||||
"shader_version",
|
"shader_version",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1432,6 +1452,19 @@ dependencies = [
|
||||||
"vecmath",
|
"vecmath",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston2d-graphics"
|
||||||
|
version = "0.45.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "efa81d40c7b656d270fdbfeef8c531cc04493a001937f5a7d0c5cdb3db2b1469"
|
||||||
|
dependencies = [
|
||||||
|
"interpolation",
|
||||||
|
"piston-texture",
|
||||||
|
"piston-viewport",
|
||||||
|
"read_color",
|
||||||
|
"vecmath",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "piston_window"
|
name = "piston_window"
|
||||||
version = "0.132.0"
|
version = "0.132.0"
|
||||||
|
@ -1443,7 +1476,7 @@ dependencies = [
|
||||||
"piston",
|
"piston",
|
||||||
"piston-texture",
|
"piston-texture",
|
||||||
"piston2d-gfx_graphics",
|
"piston2d-gfx_graphics",
|
||||||
"piston2d-graphics",
|
"piston2d-graphics 0.44.0",
|
||||||
"pistoncore-glutin_window",
|
"pistoncore-glutin_window",
|
||||||
"shader_version",
|
"shader_version",
|
||||||
]
|
]
|
||||||
|
@ -2036,6 +2069,21 @@ dependencies = [
|
||||||
"strict-num",
|
"strict-num",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.8.19"
|
version = "0.8.19"
|
||||||
|
@ -2093,12 +2141,27 @@ version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a"
|
checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-bidi"
|
||||||
|
version = "0.3.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-normalization"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unreal_asset"
|
name = "unreal_asset"
|
||||||
version = "0.1.16"
|
version = "0.1.16"
|
||||||
|
@ -2146,6 +2209,17 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "url"
|
||||||
|
version = "2.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"idna",
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ELApse"
|
name = "ELApse"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/BlackDragon-B/ELApse"
|
repository = "https://github.com/BlackDragon-B/ELApse"
|
||||||
authors = ["BlackDragon-B <kyan@blackdrgn.nl>"]
|
authors = ["BlackDragon-B <kyan@blackdrgn.nl>"]
|
||||||
|
@ -11,10 +11,11 @@ readme = "README.md"
|
||||||
clap = { version = "4.5.17", features = ["derive"] }
|
clap = { version = "4.5.17", features = ["derive"] }
|
||||||
image = "0.25.2"
|
image = "0.25.2"
|
||||||
piston = "1.0.0"
|
piston = "1.0.0"
|
||||||
piston2d-graphics = "0.44.0"
|
piston2d-graphics = "0.45.0"
|
||||||
piston_window = "0.132.0"
|
piston_window = "0.132.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
unreal_asset = "0.1.16"
|
unreal_asset = "0.1.16"
|
||||||
|
url = "2.5.2"
|
||||||
|
|
||||||
# The profile that 'cargo dist' will build with
|
# The profile that 'cargo dist' will build with
|
||||||
[profile.dist]
|
[profile.dist]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{ffi::OsStr, fs::{self, read, File}, os::raw, path::Path};
|
use std::{ffi::OsStr, fs::{self, File}, path::Path};
|
||||||
use image::{ImageFormat, ImageReader};
|
use image::ImageFormat;
|
||||||
use unreal_asset::{asset::AssetTrait, cast, engine_version::EngineVersion, exports::{self, normal_export::NormalExport, Export, ExportBaseTrait}, properties::{array_property::ArrayProperty, color_property::ColorProperty, struct_property::StructProperty, Property}, types::{fname::FNameContainer, PackageIndex}, Asset};
|
use unreal_asset::{cast, engine_version::EngineVersion, exports::Export, properties::Property, Asset};
|
||||||
|
|
||||||
fn rawrgb(path: &str) -> Result<Vec<u8>, String> {
|
fn rawrgb(path: &str) -> Result<Vec<u8>, String> {
|
||||||
match fs::read(path) {
|
match fs::read(path) {
|
||||||
|
|
12
src/input.rs
12
src/input.rs
|
@ -30,9 +30,9 @@ pub fn stdin(tx: Sender<Vec<[f32; 4]>>) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>) {
|
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>,bindaddr: String) {
|
||||||
thread::spawn( move || {
|
thread::spawn( move || {
|
||||||
let socket = UdpSocket::bind("127.0.0.1:21324").unwrap();
|
let socket = UdpSocket::bind(bindaddr).unwrap();
|
||||||
let mut buf = [0; 1500];
|
let mut buf = [0; 1500];
|
||||||
loop {
|
loop {
|
||||||
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
|
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
|
||||||
|
@ -45,6 +45,7 @@ pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>) {
|
||||||
pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
|
pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
|
||||||
thread::spawn( move || {
|
thread::spawn( move || {
|
||||||
let Ok(rawbytes) = fileparser::parse(&path) else {
|
let Ok(rawbytes) = fileparser::parse(&path) else {
|
||||||
|
println!("File not found");
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
};
|
};
|
||||||
for frame in rawbytes.chunks(720) {
|
for frame in rawbytes.chunks(720) {
|
||||||
|
@ -58,10 +59,3 @@ pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone, Debug)]
|
|
||||||
pub enum Input {
|
|
||||||
stdin,
|
|
||||||
realtimeudp,
|
|
||||||
file,
|
|
||||||
}
|
|
||||||
|
|
88
src/main.rs
88
src/main.rs
|
@ -6,60 +6,64 @@ mod utils;
|
||||||
mod fileparser;
|
mod fileparser;
|
||||||
|
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
use clap::{command, error::{self, ContextKind, ContextValue, ErrorKind}, Parser};
|
use clap::Parser;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Input driver to use
|
/// Input to use
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
input: input::Input,
|
input: String,
|
||||||
|
|
||||||
/// File input for the file driver
|
/// Output to use
|
||||||
#[arg(required(false), short, long, requires = "input")]
|
|
||||||
file: Option<String>,
|
|
||||||
|
|
||||||
/// Output driver to use
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
output: output::Output,
|
output: String,
|
||||||
|
|
||||||
/// Destination IP for the realtimeudp driver
|
|
||||||
#[arg(required(false), short, long, requires = "output")]
|
|
||||||
destip: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
// let mut arg = clap::command!()
|
|
||||||
// .arg(clap::arg!(-o --output <file> "The output file to write to. Use - for stdout."))
|
|
||||||
// .arg_required_else_help(true);
|
|
||||||
let (tx, rx): (Sender<Vec<[f32; 4]>>, Receiver<Vec<[f32; 4]>>) = mpsc::channel();
|
let (tx, rx): (Sender<Vec<[f32; 4]>>, Receiver<Vec<[f32; 4]>>) = mpsc::channel();
|
||||||
// if x {
|
match args.input.as_str() {
|
||||||
// input::stdin(tx);
|
"-" | "stdin" => input::stdin(tx),
|
||||||
// } else {
|
_ => {
|
||||||
// input::realtimeudp(tx)
|
match Url::parse(&args.input) {
|
||||||
// }
|
Ok(o) => {
|
||||||
match args.input {
|
match o.scheme() {
|
||||||
input::Input::stdin => input::stdin(tx),
|
"udp" => {
|
||||||
input::Input::realtimeudp => input::realtimeudp(tx),
|
input::realtimeudp(tx, utils::get_host(o));
|
||||||
input::Input::file => {
|
},
|
||||||
if args.file.is_some() {
|
"file" => input::file(tx, o.path().to_owned()),
|
||||||
input::file(tx, args.file.unwrap());
|
_ => {
|
||||||
} else {
|
println!("Unrecognized uri scheme");
|
||||||
utils::err_missing_args(vec!["--file".to_owned()])
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
input::file(tx, args.input);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// input::file(tx);
|
match args.output.as_str() {
|
||||||
// output::piston(rx) 21324
|
"piston" => output::piston(rx),
|
||||||
match args.output {
|
_ => {
|
||||||
output::Output::piston => output::piston(rx),
|
match Url::parse(&args.output) {
|
||||||
output::Output::realtimeudp => {
|
Ok(o) => {
|
||||||
if args.destip.is_some() {
|
match o.scheme() {
|
||||||
output::realtimeudp(rx, args.destip.unwrap())
|
"udp" => output::realtimeudp(rx,utils::get_host(o)),
|
||||||
} else {
|
_ => {
|
||||||
utils::err_missing_args(vec!["--destip".to_owned()])
|
println!("Unrecognized uri scheme");
|
||||||
}
|
std::process::exit(1);
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
println!("Output out of scope");
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
extern crate piston_window;
|
|
||||||
|
|
||||||
use graphics;
|
|
||||||
use piston_window::*;
|
use piston_window::*;
|
||||||
use graphics::math::Scalar;
|
use piston_window::graphics::math::Scalar;
|
||||||
use std::{net::{SocketAddr, UdpSocket}, sync::mpsc::Receiver, time::Duration};
|
use std::{net::UdpSocket, sync::mpsc::Receiver, time::Duration};
|
||||||
|
|
||||||
use crate::utils::{compare, offset};
|
use crate::utils::{compare, offset};
|
||||||
|
|
||||||
|
|
22
src/utils.rs
22
src/utils.rs
|
@ -1,5 +1,3 @@
|
||||||
use clap::error::{ContextKind, ContextValue, ErrorKind};
|
|
||||||
|
|
||||||
pub fn compare(a: f64, b: f64) -> f64 {
|
pub fn compare(a: f64, b: f64) -> f64 {
|
||||||
if a > b {
|
if a > b {
|
||||||
b
|
b
|
||||||
|
@ -20,9 +18,19 @@ pub fn scaleu8tof32(old_value: u8) -> f32 { // Convert a u8 between 0 and 255 to
|
||||||
(((old_value as f32 - 0.0) * (0.0 - 1.0)) / (0.0 - 255.0)) + 0.0
|
(((old_value as f32 - 0.0) * (0.0 - 1.0)) / (0.0 - 255.0)) + 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn err_missing_args(args: Vec<String>) {
|
pub fn get_host(url: url::Url) -> String {
|
||||||
let mut err = clap::Error::new(ErrorKind::MissingRequiredArgument);
|
match url.host_str() {
|
||||||
err.insert(ContextKind::InvalidArg, ContextValue::Strings(args));
|
Some(addr) => {
|
||||||
let _ = err.print();
|
let port = match url.port() {
|
||||||
std::process::exit(1);
|
Some(port) => port,
|
||||||
|
None => 21324,
|
||||||
|
};
|
||||||
|
return format!("{}:{}",addr,port);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
println!("Invalid host");
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue