🧪💩 workspace, vanth, varo: Add varo crate and Root struct, update dependencies

- Replaced `bitcode` crate with `bincode` in workspace dependencies.
- Added new crate `varo` for random optimization with `Varo` trait, `Distribution`, and `optimize` function.
- Defined `Root` world struct placeholder in `vanth` crate.
- Created `reference.rs` test module in `vanth` with custom components and events.
- Added TODOs in `varo` for RNG implementation and `optimize` function.
This commit is contained in:
Markus Scully 2025-08-06 16:20:05 +03:00
parent a1cc9b6e04
commit 5614cfe95f
Signed by: mascully
GPG key ID: 93CA5814B698101C
7 changed files with 120 additions and 5 deletions

View file

@ -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 {
}

View file

@ -4,3 +4,4 @@ use vanth::{Component, Node, Reference};
mod derive;
mod fs;
mod store;
mod reference;

View file

@ -0,0 +1,20 @@
use bevy_ecs::{component::Component, entity::Entity, event::{Event, EventWriter}, system::Query};
#[derive(Event)]
struct LevelUpEvent<T> {
inner: T,
}
#[derive(Component)]
struct FooTask {
field: i32,
}
fn player_level_up(
mut ev_levelup: EventWriter<LevelUpEvent<i32>>,
query: Query<(Entity, &FooTask)>,
) {
for (entity, xp) in query.iter() {
ev_levelup.write(LevelUpEvent::<i32> { inner: 5 });
}
}

19
crates/varo/Cargo.toml Normal file
View file

@ -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 }

49
crates/varo/src/lib.rs Normal file
View file

@ -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<f32>,
}
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<T: Varo>(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!()
}