Compare commits

...

3 commits

Author SHA1 Message Date
aa07b193b6
Launch game through VSCodium debugger
All checks were successful
CI / Formatting (push) Successful in 1m5s
2025-05-24 13:23:20 -04:00
b7804bd547
Add CLI for networking 2025-05-24 13:22:47 -04:00
62da4093ea
Make VSCodium Rust experience more robust 2025-05-24 13:22:07 -04:00
6 changed files with 98 additions and 18 deletions

46
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,46 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug game",
"cargo": {
"args": ["build"]
},
"args": ["--seed=gargamel"],
"cwd": "${workspaceFolder}",
"env": {
"CARGO_MANIFEST_DIR": "${workspaceFolder}",
"LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
},
"presentation": {
"hidden": false,
"group": "run",
"order": 1
}
},
{
"type": "lldb",
"request": "launch",
"name": "Debug peer",
"cargo": {
"args": ["build"]
},
"args": ["--port=25566", "--connect=[::1]:25565"],
"cwd": "${workspaceFolder}",
"env": {
"CARGO_MANIFEST_DIR": "${workspaceFolder}",
"LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
},
"presentation": {
"hidden": false,
"group": "run",
"order": 2
}
}
]
}

12
.vscode/settings.json vendored
View file

@ -1,8 +1,19 @@
{ {
"files.readonlyFromPermissions": true,
"files.readonlyInclude": {
"**/.rustup/**": true,
"**/.cargo/registry/**": true,
"**/.cargo/git/**": true,
"**/.local/share/cargo/registry/**": true,
"**/.local/share/cargo/git/**": true
},
"[rust]": { "[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer", "editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true "editor.formatOnSave": true
}, },
"rust-analyzer.cargo.extraEnv": {
"RUSTFLAGS": "-Clinker=clang -Clink-arg=-fuse-ld=lld"
},
"rust-analyzer.check.command": "clippy", // "check", // "rust-analyzer.check.command": "clippy", // "check", //
"rust-analyzer.cargo.targetDir": true, "rust-analyzer.cargo.targetDir": true,
"cSpell.words": [ "cSpell.words": [
@ -13,6 +24,7 @@
"PRNG", "PRNG",
"recip", "recip",
"respawns", "respawns",
"Seedable",
"timestep", "timestep",
"timesteps", "timesteps",
"winit", "winit",

12
.vscode/tasks.json vendored
View file

@ -2,18 +2,12 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "Launch", "label": "Build",
"type": "cargo", "type": "cargo",
"command": "run", "command": "build",
"args": ["--", "--seed", "gargamel"],
"options": {
"env": {
"RUST_BACKTRACE": "full"
}
},
"presentation": { "presentation": {
"echo": true, "echo": true,
"reveal": "always", "reveal": "silent",
"focus": false, "focus": false,
"panel": "dedicated", "panel": "dedicated",
"showReuseMessage": false, "showReuseMessage": false,

View file

@ -1,11 +1,18 @@
use std::hash::{DefaultHasher, Hash, Hasher}; use std::hash::{DefaultHasher, Hash, Hasher};
use bevy::prelude::*; use bevy::prelude::*;
use rand::random;
/// Value with which to initialize the PRNG /// Value with which to initialize the PRNG
#[derive(Clone, Resource)] #[derive(Clone, Resource)]
pub struct Seed(u64); pub struct Seed(u64);
impl Seed {
pub fn random() -> Self {
Self(random())
}
}
impl From<String> for Seed { impl From<String> for Seed {
/// Attempt to parse as an integer, fall back to hashing string /// Attempt to parse as an integer, fall back to hashing string
fn from(value: String) -> Self { fn from(value: String) -> Self {

View file

@ -8,12 +8,13 @@ use bevy::{
}, },
prelude::*, prelude::*,
}; };
use bevy_rand::prelude::{GlobalEntropy, WyRand}; use rand::{Rng as _, SeedableRng};
use rand::Rng as _; use wyrand::WyRand;
use super::{ use super::{
objects::{Ball, Player, Radius, Wall}, objects::{Ball, Player, Radius, Wall},
rng::thread_rng, rng::thread_rng,
seed::Seed,
}; };
const BALL_COUNT: u8 = 32; const BALL_COUNT: u8 = 32;
@ -25,7 +26,8 @@ const DIMENSION_SIZES: Range<f32> = 500.0..2000.0;
pub struct PlayableArea(f32, f32); pub struct PlayableArea(f32, f32);
/// Initialize deterministic values /// Initialize deterministic values
pub fn setup_from_seed(mut commands: Commands, mut rng: GlobalEntropy<WyRand>) { pub fn setup_from_seed(mut commands: Commands, seed: Res<Seed>) {
let mut rng = WyRand::from_seed(seed.clone().into());
commands.insert_resource(PlayableArea( commands.insert_resource(PlayableArea(
rng.random_range(DIMENSION_SIZES), rng.random_range(DIMENSION_SIZES),
rng.random_range(DIMENSION_SIZES), rng.random_range(DIMENSION_SIZES),

View file

@ -1,7 +1,8 @@
use std::net::SocketAddr;
use avian2d::{math::Vector, prelude::*}; use avian2d::{math::Vector, prelude::*};
use bevy::{input::common_conditions::input_pressed, prelude::*}; use bevy::{input::common_conditions::input_pressed, prelude::*};
use bevy_rand::prelude::{EntropyPlugin, WyRand}; use clap::{Args, Parser};
use clap::Parser;
mod game; mod game;
use game::{ use game::{
@ -15,14 +16,25 @@ use game::{
#[derive(Parser)] #[derive(Parser)]
#[command(version, about)] #[command(version, about)]
pub struct AppSettings { pub struct AppSettings {
#[arg(short, long, default_value = ":)")] #[command(flatten)]
pub seed: Seed, source: Source,
#[arg(short, long, default_value = "25565")]
port: u16,
}
#[derive(Args)]
#[group(required = false, multiple = false)]
struct Source {
#[arg(short, long)]
seed: Option<Seed>,
#[arg(short, long)]
connect: Option<SocketAddr>,
} }
impl Plugin for AppSettings { impl Plugin for AppSettings {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(Gravity(Vector::ZERO)) app.insert_resource(Gravity(Vector::ZERO))
.insert_resource(self.seed.clone())
.add_plugins(( .add_plugins((
DefaultPlugins.set(WindowPlugin { DefaultPlugins.set(WindowPlugin {
primary_window: Window { primary_window: Window {
@ -34,7 +46,6 @@ impl Plugin for AppSettings {
..default() ..default()
}), }),
PhysicsPlugins::default().with_length_unit(50.0), PhysicsPlugins::default().with_length_unit(50.0),
EntropyPlugin::<WyRand>::with_seed(self.seed.clone().into()),
)) ))
.add_systems( .add_systems(
Startup, Startup,
@ -53,5 +64,13 @@ impl Plugin for AppSettings {
), ),
) )
.add_systems(PostUpdate, move_camera); .add_systems(PostUpdate, move_camera);
if let Some(ref seed) = self.source.seed {
app.insert_resource(seed.clone());
} else if let Some(ref peer) = self.source.connect {
println!("{peer}");
todo!("Handle connecting to peer and retrieving seed");
} else {
app.insert_resource(Seed::random());
}
} }
} }