Skip to content

Commit

Permalink
Added names to a bunch of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyTornetta committed Oct 26, 2023
1 parent a740e08 commit 4ac139c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 61 deletions.
1 change: 1 addition & 0 deletions cosmos_client/assets/lang/blocks/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ cosmos:molten_stone=Molten Stone
cosmos:cheese=Cheese (Lava)
cosmos:ice=Ice
cosmos:water=Water
cosmos:build_block=Build Block
2 changes: 2 additions & 0 deletions cosmos_client/src/netty/gameplay/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub(crate) fn client_sync_players(
BloomSettings { ..Default::default() },
CameraHelper::default(),
Skybox(Handle::default()),
Name::new("Main Camera"),
MainCamera,
// No double UI rendering
UiCameraConfig { show_ui: false },
Expand All @@ -358,6 +359,7 @@ pub(crate) fn client_sync_players(

commands.spawn((
PlayerWorld { player: client_entity },
Name::new("Player World"),
loc,
PhysicsWorld {
world_id: DEFAULT_WORLD_ID,
Expand Down
110 changes: 66 additions & 44 deletions cosmos_client/src/structure/ship/build_mode.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Handles the build mode logic on the client-side
use bevy::{
pbr::{NotShadowCaster, NotShadowReceiver},
prelude::{
in_state, shape, App, AssetServer, Assets, BuildChildren, Changed, Color, Commands, Component, DespawnRecursiveExt, Entity,
EventReader, IntoSystemConfigs, MaterialMeshBundle, Mesh, Parent, Query, Res, ResMut, Transform, Update, Vec3, With, Without,
EventReader, IntoSystemConfigs, MaterialMeshBundle, Mesh, Name, Parent, Query, Res, ResMut, Transform, Update, Vec3, With, Without,
},
time::Time,
};
Expand All @@ -14,7 +15,10 @@ use cosmos_core::{
structure::{
chunk::CHUNK_DIMENSIONSF,
coordinates::BlockCoordinate,
ship::build_mode::{BuildAxis, BuildMode, ExitBuildModeEvent},
ship::{
build_mode::{BuildAxis, BuildMode, ExitBuildModeEvent},
core::DieWithStructure,
},
Structure,
},
};
Expand Down Expand Up @@ -233,20 +237,26 @@ fn change_visuals(
commands.entity(structure_entity).with_children(|ecmds| {
visuals.0 = Some(
ecmds
.spawn(MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(0.001, size as f32, size as f32).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32,
vertical: size as u32,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(1.0, 0.0, 0.0).into(),
}),
transform: Transform::from_xyz(coords.x, 0.5, 0.5),
..Default::default()
})
.spawn((
DieWithStructure,
NotShadowCaster,
NotShadowReceiver,
Name::new("X Axis - build mode"),
MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(0.001, size as f32, size as f32).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32,
vertical: size as u32,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(1.0, 0.0, 0.0).into(),
}),
transform: Transform::from_xyz(coords.x, 0.5, 0.5),
..Default::default()
},
))
.id(),
);
});
Expand All @@ -258,20 +268,26 @@ fn change_visuals(
commands.entity(structure_entity).with_children(|ecmds| {
visuals.1 = Some(
ecmds
.spawn(MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(size as f32, 0.001, size as f32).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32,
vertical: size as u32,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(0.0, 1.0, 0.0).into(),
}),
transform: Transform::from_xyz(0.5, coords.y, 0.5),
..Default::default()
})
.spawn((
DieWithStructure,
NotShadowCaster,
NotShadowReceiver,
Name::new("Y Axis - build mode"),
MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(size as f32, 0.001, size as f32).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32,
vertical: size as u32,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(0.0, 1.0, 0.0).into(),
}),
transform: Transform::from_xyz(0.5, coords.y, 0.5),
..Default::default()
},
))
.id(),
);
});
Expand All @@ -283,20 +299,26 @@ fn change_visuals(
commands.entity(structure_entity).with_children(|ecmds| {
visuals.2 = Some(
ecmds
.spawn(MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(size as f32, size as f32, 0.001).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32 / 4,
vertical: size as u32 / 4,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(0.0, 0.0, 1.0).into(),
}),
transform: Transform::from_xyz(0.5, 0.5, coords.z),
..Default::default()
})
.spawn((
DieWithStructure,
NotShadowCaster,
NotShadowReceiver,
Name::new("Z Axis - build mode"),
MaterialMeshBundle {
mesh: meshes.add(shape::Box::new(size as f32, size as f32, 0.001).into()),
material: materials.add(UnlitRepeatedMaterial {
repeats: Repeats {
horizontal: size as u32 / 4,
vertical: size as u32 / 4,
..Default::default()
},
texture: texture_handle.clone(),
color: Color::rgb(0.0, 0.0, 1.0).into(),
}),
transform: Transform::from_xyz(0.5, 0.5, coords.z),
..Default::default()
},
))
.id(),
);
});
Expand Down
29 changes: 16 additions & 13 deletions cosmos_client/src/universe/star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::f32::consts::PI;
use bevy::{
pbr::NotShadowCaster,
prelude::{
shape, Added, App, Assets, Commands, DirectionalLight, DirectionalLightBundle, Entity, EulerRot, Mesh, OnEnter, PbrBundle, Quat,
Query, ResMut, StandardMaterial, Transform, Update, Vec3, With, Without,
shape, Added, App, Assets, Commands, DirectionalLight, DirectionalLightBundle, Entity, EulerRot, Mesh, Name, OnEnter, PbrBundle,
Quat, Query, ResMut, StandardMaterial, Transform, Update, Vec3, With, Without,
},
};
use cosmos_core::{physics::location::SECTOR_DIMENSIONS, universe::star::Star};
Expand Down Expand Up @@ -62,19 +62,22 @@ fn create_added_star(

/// There is only ever one light source for stars, it is just moved around as needed
fn create_star_light_source(mut commands: Commands) {
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 30000.0,
shadows_enabled: true,
..Default::default()
},
transform: Transform {
translation: Vec3::ZERO,
rotation: Quat::from_euler(EulerRot::XYZ, -PI / 4.0, 0.1, 0.1),
commands.spawn((
Name::new("Star Light Emitter"),
DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 30000.0,
shadows_enabled: true,
..Default::default()
},
transform: Transform {
translation: Vec3::ZERO,
rotation: Quat::from_euler(EulerRot::XYZ, -PI / 4.0, 0.1, 0.1),
..Default::default()
},
..Default::default()
},
..Default::default()
});
));
}

pub(super) fn register(app: &mut App) {
Expand Down
3 changes: 2 additions & 1 deletion cosmos_core/src/structure/asteroid/asteroid_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Used to build an asteroid
use bevy::ecs::system::EntityCommands;
use bevy::{ecs::system::EntityCommands, prelude::Name};
use bevy_rapier3d::prelude::{RigidBody, Velocity};

use crate::{
Expand Down Expand Up @@ -36,6 +36,7 @@ impl<T: TStructureBuilder> TAsteroidBuilder for AsteroidBuilder<T> {

entity.insert((
Asteroid,
Name::new("Asteroid"),
RigidBody::Fixed,
LoadingDistance::new(ASTEROID_LOAD_RADIUS, ASTEROID_UNLOAD_RADIUS),
));
Expand Down
8 changes: 7 additions & 1 deletion cosmos_core/src/structure/ship/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ fn monitor_block_events(mut commands: Commands, blocks: Res<Registry<Block>>, mu
}
}

#[derive(Component)]
/// Marks a child of a structure as needing to be despawned when the structure itself is despawned.
///
/// If something does not have this component and its parent ship is despawned, it will have its parent removed instead of being despawned.
pub struct DieWithStructure;

/// Makes sure that when the ship is despawned, only that ship is despawned and not
/// any of the things docked to it (like the player walking on it)
fn save_the_kids(
query: Query<&Children, (With<NeedsDespawned>, With<Ship>)>,
is_this_structure: Query<(), Or<(With<ChunkEntity>, With<StructureSystem>)>>,
is_this_structure: Query<(), Or<(With<ChunkEntity>, With<StructureSystem>, With<DieWithStructure>)>>,
mut commands: Commands,
) {
for children in query.iter() {
Expand Down
14 changes: 12 additions & 2 deletions cosmos_server/src/physics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ pub fn assign_player_world(
let world_id = rapier_context.add_world(RapierWorld::default());

let world_entity = commands
.spawn((PlayerWorld { player: player_entity }, *location, PhysicsWorld { world_id }))
.spawn((
Name::new("Player World"),
PlayerWorld { player: player_entity },
*location,
PhysicsWorld { world_id },
))
.id();

commands
Expand Down Expand Up @@ -108,7 +113,12 @@ fn move_players_between_worlds(
let world_id = rapier_context.add_world(RapierWorld::default());

let world_entity = commands
.spawn((PlayerWorld { player: entity }, *location, PhysicsWorld { world_id }))
.spawn((
Name::new("Player World"),
PlayerWorld { player: entity },
*location,
PhysicsWorld { world_id },
))
.id();

let (mut world_within, mut body_world) = world_within_query.get_mut(entity).unwrap();
Expand Down

0 comments on commit 4ac139c

Please sign in to comment.