From 56611596a79075bf62c8ec3fa4f3607b79bb7045 Mon Sep 17 00:00:00 2001 From: core Date: Sun, 6 Jul 2025 16:33:18 -0400 Subject: [PATCH] feat: mod spawning --- Cargo.lock | 1 + crates/unified/Cargo.toml | 1 + crates/unified/assets/config/world.wc.toml | 2 + crates/unified/src/client/incoming_parts.rs | 4 +- crates/unified/src/client/mod.rs | 2 + crates/unified/src/client/net.rs | 8 ++ .../unified/src/client/planet/indicators.rs | 21 +++-- crates/unified/src/config/world.rs | 2 + crates/unified/src/particle/mod.rs | 12 +-- crates/unified/src/server/earth_parts.rs | 76 +++++++++++++++++++ crates/unified/src/server/mod.rs | 5 +- 11 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 crates/unified/src/server/earth_parts.rs diff --git a/Cargo.lock b/Cargo.lock index a0a3e6b97c94428204d4f7176fc46e56786e8c26..0a44d1deb7f206bed193e5f44be6c35a59d29e61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7647,6 +7647,7 @@ version = "0.1.0" dependencies = [ "aeronet", "aeronet_replicon", + "aeronet_transport", "aeronet_websocket", "bevy 0.16.1", "bevy_common_assets", diff --git a/crates/unified/Cargo.toml b/crates/unified/Cargo.toml index 148970459010c6020538655c9c2d3b78059729fc..1f2130a7224a9c99ba4df64202350346aafc4978 100644 --- a/crates/unified/Cargo.toml +++ b/crates/unified/Cargo.toml @@ -44,6 +44,7 @@ getrandom = { version = "0.3", features = [] } aeronet = "0.14" aeronet_replicon = { version = "0.15", features = ["client"] } aeronet_websocket = { version = "0.14", features = ["client"] } +aeronet_transport = "0.14" bevy_enoki = "0.4" diff --git a/crates/unified/assets/config/world.wc.toml b/crates/unified/assets/config/world.wc.toml index 838ad2ac2287adc69558ceb7e3e880eef56163d8..d661cd1c05df4fcee3e37eba6d0bb2407ee0b37b 100644 --- a/crates/unified/assets/config/world.wc.toml +++ b/crates/unified/assets/config/world.wc.toml @@ -1,5 +1,7 @@ [world] gravity = 2 +spawn_parts_at = "Earth" +spawn_parts_interval_secs = 10 [part] default_height = 50 diff --git a/crates/unified/src/client/incoming_parts.rs b/crates/unified/src/client/incoming_parts.rs index 809dadc91dc065f33af57ab0b64e21c1e04abc30..cf3a4b1c8ed86444315f16022f5fce6a6d8f8ea7 100644 --- a/crates/unified/src/client/incoming_parts.rs +++ b/crates/unified/src/client/incoming_parts.rs @@ -26,7 +26,7 @@ fn handle_incoming_parts( })) .insert(ReadMassProperties::default()) .insert(RigidBody::Dynamic); - info!(?new_part, "prepared new part"); + info!(?new_part, ?new_entity, "prepared new part"); } } fn handle_updated_parts( @@ -48,6 +48,6 @@ fn handle_updated_parts( mass: updated_part.mass, principal_inertia: 7.5, })); - info!(?updated_part, "updated part"); + info!(?updated_part, ?updated_entity, "updated part"); } } diff --git a/crates/unified/src/client/mod.rs b/crates/unified/src/client/mod.rs index 1cadf0a625818772558d301b76d69555d17a8be3..08664ab3dcf32ae5bb4a56a0dd0da31532a635ac 100644 --- a/crates/unified/src/client/mod.rs +++ b/crates/unified/src/client/mod.rs @@ -23,6 +23,7 @@ use bevy::core_pipeline::tonemapping::DebandDither; use bevy::prelude::*; use bevy::window::PrimaryWindow; use bevy_replicon::shared::server_entity_map::ServerEntityMap; +use crate::client::net::set_config; use crate::client::planet::indicators::indicators_plugin; pub struct ClientPlugin { @@ -46,6 +47,7 @@ impl Plugin for ClientPlugin { .add_systems(Update, update_cursor_position) .add_systems(Update, follow_camera) .add_systems(Update, find_me) + .add_systems(Update, set_config) .add_plugins((incoming_planets_plugin, indicators_plugin)) .add_plugins(incoming_parts_plugin) .add_plugins(key_input_plugin) diff --git a/crates/unified/src/client/net.rs b/crates/unified/src/client/net.rs index b696caf1cc010183836bcf6855cf0a5646a3c605..a016f09a996a2efef3910ca04dba26992f48866b 100644 --- a/crates/unified/src/client/net.rs +++ b/crates/unified/src/client/net.rs @@ -1,8 +1,16 @@ use aeronet::io::connection::Disconnected; use aeronet::io::{Session, SessionEndpoint}; use aeronet_replicon::client::AeronetRepliconClient; +use aeronet_transport::TransportConfig; use bevy::prelude::*; +pub fn set_config(mut q: Query<&mut TransportConfig, Added>) { + for mut q in q.iter_mut() { + q.max_memory_usage = 8388608; // 8 MiB + } +} + + pub fn on_connecting( trigger: Trigger, names: Query<&Name>, diff --git a/crates/unified/src/client/planet/indicators.rs b/crates/unified/src/client/planet/indicators.rs index 01139c7d0963d5cdbae926344ffa6bb9d3987a5d..5342781a710208b91fc84ad491532893df29e04e 100644 --- a/crates/unified/src/client/planet/indicators.rs +++ b/crates/unified/src/client/planet/indicators.rs @@ -2,10 +2,11 @@ use bevy::prelude::*; use bevy::window::PrimaryWindow; use crate::client::Me; use crate::config::planet::Planet; +use crate::ecs::{MainCamera, StarfieldBack, StarfieldFront, StarfieldMid}; pub fn indicators_plugin(app: &mut App) { app.add_systems(PreUpdate, (add_indicators, update_indicators)) - .add_systems(Update, update_indicators_position); + .add_systems(PostUpdate, update_indicators_position); } #[derive(Component)] @@ -18,7 +19,7 @@ fn add_indicators(planets_wo_indicators: Query<(Entity, &Planet), Without>, player: Query<&Transform, (With, Without)>, - mut indicators: Query<(&mut Transform), (With, Without, Without)>, + mut indicators: Query<(&mut Transform, &mut Sprite), (With, Without, Without, Without)>, window: Query<&Window, With>, + camera: Single<&Transform, (With, Without)>, ) { let Ok(player_position) = player.single() else { return; }; - let window = window.single().unwrap(); + let Ok(window) = window.single() else { return }; for (planet_position, indicator_id) in &planets_w_indicator { let mut offset = planet_position.translation - player_position.translation; - let half_window_height = window.height() / 2.0 - 25.0; - let half_window_width = window.width() / 2.0 - 25.0; + + let sprite_size = 25.0 * camera.scale.z; + + let half_window_height = window.height() * camera.scale.z / 2.0 - (sprite_size / 2.0); + let half_window_width = window.width() * camera.scale.z / 2.0 - (sprite_size / 2.0); offset.x = offset.x.clamp(-half_window_width, half_window_width); offset.y = offset.y.clamp(-half_window_height, half_window_height); - let Ok(mut this_indicator) = indicators.get_mut(indicator_id.0) else { continue; }; + let Ok((mut this_indicator, mut this_sprite)) = indicators.get_mut(indicator_id.0) else { continue; }; + + this_sprite.custom_size = Some(Vec2::splat(sprite_size)); let inv_rot = player_position.rotation.inverse(); this_indicator.translation = inv_rot.mul_vec3(Vec3::new(offset.x, offset.y, 0.0)); diff --git a/crates/unified/src/config/world.rs b/crates/unified/src/config/world.rs index dc1393964c25d2ae81e2aced29fd3e18a9ee88ae..fa9a7034077f90eb30ceccf490f1478c1655d223 100644 --- a/crates/unified/src/config/world.rs +++ b/crates/unified/src/config/world.rs @@ -12,6 +12,8 @@ pub struct GlobalWorldConfig { #[derive(Deserialize, Asset, TypePath, Clone)] pub struct WorldConfig { pub gravity: f32, + pub spawn_parts_at: String, + pub spawn_parts_interval_secs: f32 } #[derive(Deserialize, Asset, TypePath, Clone)] diff --git a/crates/unified/src/particle/mod.rs b/crates/unified/src/particle/mod.rs index cbf29b13411c1bdd2061de981af5ace6ff288bee..7937d0c7f0de1d4c01b5650add56b29ea925e413 100644 --- a/crates/unified/src/particle/mod.rs +++ b/crates/unified/src/particle/mod.rs @@ -1,4 +1,4 @@ -use bevy::color::{Color, ColorCurve}; +use bevy::color::{Color, ColorCurve, LinearRgba}; use bevy::math::cubic_splines::LinearSpline; use bevy::math::Vec2; use rand::Rng; @@ -24,15 +24,16 @@ pub struct ParticleEffect { // -- scale -- // - /// Scale curve over the lifetime of the particle - pub scale: LinearSpline, + // Scale curve over the lifetime of the particle + //pub scale: LinearSpline, // -- color -- // - /// Color curve over the lifetime of the particle - pub color: LinearSpline, + // Color curve over the lifetime of the particle + //pub color: LinearSpline, } +#[derive(Deserialize, Serialize)] pub struct RandF32 { pub value: f32, pub randomness: f32 @@ -43,6 +44,7 @@ impl RandF32 { } } +#[derive(Deserialize, Serialize)] pub struct RandVec2 { pub x: RandF32, pub y: RandF32, diff --git a/crates/unified/src/server/earth_parts.rs b/crates/unified/src/server/earth_parts.rs new file mode 100644 index 0000000000000000000000000000000000000000..d738ebe8f89adae59e6a3d1a80924beb2a469565 --- /dev/null +++ b/crates/unified/src/server/earth_parts.rs @@ -0,0 +1,76 @@ +use std::time::Duration; +use bevy::app::App; +use bevy::math::Vec2; +use bevy::prelude::{Commands, Query, Res, Transform}; +use bevy::time::{Real, Time}; +use bevy_rapier2d::dynamics::{AdditionalMassProperties, ExternalForce, MassProperties}; +use bevy_rapier2d::geometry::Collider; +use bevy_replicon::prelude::Replicated; +use crate::config::planet::Planet; +use crate::ecs::{Part, PartBundle, Player, PlayerThrust}; +use crate::server::world_config::WorldConfigResource; +use bevy::prelude::*; + +#[derive(Resource, Default)] +struct PartTimerRes { + timer: Timer +} + + +pub fn spawn_parts_plugin(app: &mut App) { + app.init_resource::() + .add_systems(Update, spawn_parts_on_earth); +} + + +pub fn spawn_parts_on_earth( + mut commands: Commands, + world_config: Res, + planets: Query<(&Transform, &Planet)>, + mut timer: ResMut, + time: Res