/* Hurry Curry! - a game about cooking Copyright (C) 2025 Hurry Curry! Contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License only. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #![feature(exit_status_error)] pub mod record; pub mod render; pub mod replay; use crate::{record::record, render::render, replay::replay}; use clap::Parser; use hurrycurry_protocol::PacketC; use log::{info, warn, LevelFilter}; use serde::{Deserialize, Serialize}; use std::{ path::PathBuf, time::{Duration, SystemTime}, }; use tokio::{net::TcpListener, time::sleep}; #[derive(Parser)] enum Args { /// Connects as a spectator and saves the protocol packets for replay Record { /// Dont stop after the first game but restart instead #[arg(short, long)] r#loop: bool, url: String, output: PathBuf, }, /// Starts a local server that replays previously recorded sessions Replay { input: PathBuf }, /// Runs a replay server and the client in movie mode to record that replay Render { /// Replay file path input: PathBuf, /// Output video file path passed to godot (must end in either .avi for MJPEG or .png for PNG sequence) output: PathBuf, #[arg(short = 'r', long, default_value = "30")] framerate: usize, /// Render without display server; Requires wlheadless-run and mutter #[arg(short = 'H', long)] headless: bool, #[arg(long, default_value = "wayland")] video_driver: String, #[arg(long, default_value = "vulkan")] rendering_driver: String, #[arg(long, default_value = "mutter")] headless_compositor: String, }, } #[derive(Serialize, Deserialize)] struct Event { ts: f64, packet: PacketC, } #[tokio::main] async fn main() -> anyhow::Result<()> { env_logger::builder() .filter_level(LevelFilter::Info) .parse_env("LOG") .init(); rustls::crypto::ring::default_provider() .install_default() .unwrap(); let args = Args::parse(); match args { Args::Record { url, output, r#loop, } => loop { let out = if r#loop { output.join(format!( "replay-{}", SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() .as_secs() )) } else { output.clone() }; if let Err(e) = record(&out, &url).await { warn!("recording failed: {e}"); sleep(Duration::from_secs(1)).await; } if r#loop { info!("restarting..."); } else { break; } }, Args::Replay { input } => { let ws_listener = TcpListener::bind("127.0.0.1:27032").await?; info!("listening for websockets on {}", ws_listener.local_addr()?); loop { replay(&ws_listener, &input).await?; } } Args::Render { input, output, framerate, headless, rendering_driver, headless_compositor, video_driver, } => { render( &input, &output, framerate, headless, &rendering_driver, &video_driver, &headless_compositor, ) .await?; } } Ok(()) }