diff --git a/Cargo.lock b/Cargo.lock index e7db65e..824e64e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1373,7 +1373,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1383,7 +1383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1395,6 +1395,12 @@ dependencies = [ "getrandom 0.2.16", ] +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" + [[package]] name = "redox_syscall" version = "0.5.13" @@ -1417,7 +1423,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "spki", "subtle", @@ -1548,7 +1554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -2071,6 +2077,20 @@ dependencies = [ "syn", ] +[[package]] +name = "varo" +version = "0.1.0" +dependencies = [ + "blake3", + "digest", + "rand_core 0.9.3", + "serde", + "serde_json", + "tempfile", + "vanth", + "vanth_derive", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 6606edd..1219416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ edition = "2024" clap = { version = "4.5.42", features = ["derive"] } bevy_app = "0.16.1" bevy_ecs = "0.16.1" -bitcode = "0.6.6" +bincode = "2.0.1" serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" digest = "0.10.7" @@ -21,3 +21,4 @@ proc-macro2 = "1.0" sqlx = "0.8.6" rusqlite = { version = "0.32.1", features = ["bundled"] } tempfile = "3.12.0" +rand_core = "0.9.3" diff --git a/crates/vanth/src/lib.rs b/crates/vanth/src/lib.rs index 8796aa6..120c1ec 100644 --- a/crates/vanth/src/lib.rs +++ b/crates/vanth/src/lib.rs @@ -180,3 +180,8 @@ impl Plugin for VanthPlugin { // fn run_reference_tasks(tasks: Query<(&ReferenceGetTask<>)>) { // } + +/// A world which Vanth entities live in. Lifetimes `'v` of [`Vanth<'v>`] types are tied to the lifetime of the `Root`. +pub struct Root { + +} diff --git a/crates/vanth/tests/integration/main.rs b/crates/vanth/tests/integration/main.rs index 3c9841a..3044c26 100644 --- a/crates/vanth/tests/integration/main.rs +++ b/crates/vanth/tests/integration/main.rs @@ -4,3 +4,4 @@ use vanth::{Component, Node, Reference}; mod derive; mod fs; mod store; +mod reference; diff --git a/crates/vanth/tests/integration/reference.rs b/crates/vanth/tests/integration/reference.rs new file mode 100644 index 0000000..a926e3b --- /dev/null +++ b/crates/vanth/tests/integration/reference.rs @@ -0,0 +1,20 @@ +use bevy_ecs::{component::Component, entity::Entity, event::{Event, EventWriter}, system::Query}; + +#[derive(Event)] +struct LevelUpEvent { + inner: T, +} + +#[derive(Component)] +struct FooTask { + field: i32, +} + +fn player_level_up( + mut ev_levelup: EventWriter>, + query: Query<(Entity, &FooTask)>, +) { + for (entity, xp) in query.iter() { + ev_levelup.write(LevelUpEvent:: { inner: 5 }); + } +} diff --git a/crates/varo/Cargo.toml b/crates/varo/Cargo.toml new file mode 100644 index 0000000..4436fc2 --- /dev/null +++ b/crates/varo/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "varo" +version.workspace = true +edition.workspace = true + +[lib] +path = "src/lib.rs" + +[dependencies] +digest.workspace = true +serde.workspace = true +serde_json.workspace = true +blake3.workspace = true +vanth = { path = "../vanth" } +vanth_derive = { path = "../vanth_derive" } +rand_core.workspace = true + +[dev-dependencies] +tempfile = { workspace = true } diff --git a/crates/varo/src/lib.rs b/crates/varo/src/lib.rs new file mode 100644 index 0000000..409af7c --- /dev/null +++ b/crates/varo/src/lib.rs @@ -0,0 +1,49 @@ +use rand_core::SeedableRng; +use serde::{Deserialize, Serialize}; +use vanth_derive::Vanth; + +#[derive(Clone, Debug, Deserialize, Serialize, Vanth)] +pub struct Rng { + // TODO: RNG +} + +impl Rng { + // TODO +} + +pub trait Varo { + /// Produce a random + fn next(digest: &mut Rng) -> Self; +} + +#[derive(Clone, Debug, Deserialize, Serialize, Vanth)] +pub struct Distribution { + /// 0th element is the mean, 1st is the variance etc. + pub moments: Vec, +} + +impl Distribution { + pub fn sample(digest: &mut Rng) -> f32 { + todo!() + } +} + +#[derive(Clone, Debug, Deserialize, Serialize, Vanth)] +pub struct Score { + value: f32, +} + +#[derive(Clone, Debug, Deserialize, Serialize, Vanth)] +pub struct OptimizationResult { + /// List of pairs of evaluation score and Rng used to generate the value. + values: Vec<(Rng, f32)> +} + +pub fn optimize(evaluator: impl Fn(T) -> Score, rng: &mut Rng, rounds: u32) -> OptimizationResult { + // TODO: + // `for i in 0..rounds`: create a clone of `rng` and feed it `i`. + // Call T::next() and pass it to the evaluator. + // Return a sorted list, highest scores first. + + todo!() +}