From 29b38a1f453cc71e892a1a85970a2b414778c5c9 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Sat, 16 Nov 2024 20:58:31 -0800 Subject: [PATCH] desktop: Add `record::Script`. This is a storage format for character movement record/replay. There is no way to actually use it yet (hence `allow(dead_code)`); the code to do that is not ready. --- Cargo.lock | 3 + all-is-cubes-desktop/Cargo.toml | 3 + all-is-cubes-desktop/src/record.rs | 2 + all-is-cubes-desktop/src/record/script.rs | 268 ++++++++++++++++++++++ all-is-cubes/src/character.rs | 2 +- all-is-cubes/src/physics/body.rs | 3 +- 6 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 all-is-cubes-desktop/src/record/script.rs diff --git a/Cargo.lock b/Cargo.lock index a90228357..e036409d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,6 +152,7 @@ dependencies = [ "cfg-if", "clap", "directories-next", + "euclid", "futures-core", "gilrs", "gltf", @@ -161,6 +162,7 @@ dependencies = [ "kira", "log", "png", + "pretty_assertions", "rand", "ratatui", "re_sdk", @@ -2015,6 +2017,7 @@ dependencies = [ "arbitrary", "mint", "num-traits", + "serde", ] [[package]] diff --git a/all-is-cubes-desktop/Cargo.toml b/all-is-cubes-desktop/Cargo.toml index 70fc970b6..dd0501b48 100644 --- a/all-is-cubes-desktop/Cargo.toml +++ b/all-is-cubes-desktop/Cargo.toml @@ -43,6 +43,7 @@ record = [ "dep:all-is-cubes-mesh", # used in glTF recording "all-is-cubes-port/export", "all-is-cubes-port/all-formats", + "euclid/serde", # TODO: stop depending on euclid’s serde impls for record::Script ] # Importing non-native data formats. import = ["all-is-cubes-port/import", "all-is-cubes-port/all-formats"] @@ -75,6 +76,7 @@ anyhow = { workspace = true } cfg-if = { workspace = true } clap = { workspace = true } directories-next = "2.0.0" +euclid = { workspace = true, optional = true } futures-core = { workspace = true } gilrs = { workspace = true } hashbrown = { workspace = true } @@ -104,6 +106,7 @@ yield-progress = { workspace = true, features = ["log_hiccups"] } [dev-dependencies] gltf = "1.4.0" # for round-trip test; must match version of gltf-json +pretty_assertions = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["macros"] } trycmd = { workspace = true } diff --git a/all-is-cubes-desktop/src/record.rs b/all-is-cubes-desktop/src/record.rs index fa7bc3f55..8e6aef6d0 100644 --- a/all-is-cubes-desktop/src/record.rs +++ b/all-is-cubes-desktop/src/record.rs @@ -20,6 +20,8 @@ mod options; pub use options::*; mod rmain; pub(crate) use rmain::{configure_session_for_recording, configure_universe_for_recording}; +mod script; +pub use script::Script; mod write_gltf; mod write_png; diff --git a/all-is-cubes-desktop/src/record/script.rs b/all-is-cubes-desktop/src/record/script.rs new file mode 100644 index 000000000..44d07bbd5 --- /dev/null +++ b/all-is-cubes-desktop/src/record/script.rs @@ -0,0 +1,268 @@ +#![allow(dead_code, reason = "TODO: Implement `Script` recording and playback")] + +use std::fs; +use std::io; +use std::ops; +use std::path::PathBuf; +use std::sync::Arc; +use std::time::Duration; + +use anyhow::Context as _; + +use all_is_cubes::character::{self, Character}; +use all_is_cubes::euclid::{num::One, num::Zero as _, Point3D, Vector3D}; +use all_is_cubes::listen; +use all_is_cubes::math::{Cube, NotNan}; +use all_is_cubes::physics::BodyTransaction; +use all_is_cubes::transaction::Merge as _; +use all_is_cubes::{behavior, universe}; +use all_is_cubes_render::{camera::StandardCameras, Flaws}; + +// ------------------------------------------------------------------------------------------------- + +/// Definition of an animation to make a [`Character`] follow a predefined path. +#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)] +pub struct Script { + // TODO: stop depending on euclid’s serde formats + position: Data, Cube>>, + look_direction: Data, Cube>>, +} + +/// Behavior attached to a [`Character`] which executes a [`Script`]. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Performance { + script: Arc