varius fixes

This commit is contained in:
Isse 2023-04-18 13:55:29 +02:00
parent b3a70627e5
commit 134d0f0c04
15 changed files with 112 additions and 77 deletions

View File

@ -737,9 +737,11 @@ impl ServerChatCommand {
"Send messages to everyone on the server",
None,
),
ServerChatCommand::MakeVolume => {
cmd(vec![Integer("size", 15, Optional)], "Create a volume (experimental)", Some(Admin))
},
ServerChatCommand::MakeVolume => cmd(
vec![Integer("size", 15, Optional)],
"Create a volume (experimental)",
Some(Admin),
),
ServerChatCommand::Location => {
cmd(vec![Any("name", Required)], "Teleport to a location", None)
},

View File

@ -243,7 +243,10 @@ pub mod figuredata {
AssetExt::load("common.manifests.ship_manifest")?;
let mut colliders = HashMap::new();
for (_, spec) in (manifest.read().0).0.iter() {
for (index, bone) in [&spec.bone0, &spec.bone1, &spec.bone2, &spec.bone3].iter().enumerate() {
for (index, bone) in [&spec.bone0, &spec.bone1, &spec.bone2, &spec.bone3]
.iter()
.enumerate()
{
// TODO: Currently both client and server load models and manifests from
// "common.voxel.". In order to support CSG procedural airships, we probably
// need to load them in the server and sync them as an ECS resource.

View File

@ -1,7 +1,7 @@
// The limit on distance between the entity and a collectible (squared)
pub const MAX_PICKUP_RANGE: f32 = 5.0;
pub const MAX_MOUNT_RANGE: f32 = 5.0;
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 1.5;
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0;
pub const MAX_TRADE_RANGE: f32 = 20.0;
pub const GRAVITY: f32 = 25.0;

View File

@ -436,7 +436,8 @@ impl Block {
}
pub fn is_controller(&self) -> bool {
self.get_sprite().map_or(false, |sprite| sprite.is_controller())
self.get_sprite()
.map_or(false, |sprite| sprite.is_controller())
}
#[inline]

View File

@ -506,13 +506,14 @@ impl SpriteKind {
pub fn is_mountable(&self) -> bool { self.mount_offset().is_some() }
#[inline]
pub fn is_controller(&self) -> bool {
matches!(self, SpriteKind::Helm)
}
pub fn is_controller(&self) -> bool { matches!(self, SpriteKind::Helm) }
#[inline]
pub fn is_door(&self) -> bool {
matches!(self, SpriteKind::Door | SpriteKind::DoorWide | SpriteKind::DoorDark)
matches!(
self,
SpriteKind::Door | SpriteKind::DoorWide | SpriteKind::DoorDark
)
}
/// Which tool (if any) is needed to collect this sprite?

View File

@ -156,9 +156,7 @@ impl FindDist<Cylinder> for Vec3<f32> {
}
#[inline]
fn min_distance(self, other: Cylinder) -> f32 {
other.min_distance(self)
}
fn min_distance(self, other: Cylinder) -> f32 { other.min_distance(self) }
}
#[cfg(test)]

View File

@ -1699,8 +1699,8 @@ fn handle_make_volume(
let pos = position(server, target, "target")?;
let ship = comp::ship::Body::Volume;
let sz = parse_cmd_args!(args, u32).unwrap_or(15);
if sz < 1 || sz > 127 {
return Err(format!("Size has to be between 1 and 127."));
if !(1..=127).contains(&sz) {
return Err("Size has to be between 1 and 127.".to_string());
};
let sz = Vec3::broadcast(sz);
let collider = {
@ -1715,9 +1715,12 @@ fn handle_make_volume(
};
server
.state
.create_ship(comp::Pos(pos.0 + Vec3::unit_z() * (50.0 + sz.z as f32 / 2.0)), comp::Ori::default(), ship, move |_| {
collider
})
.create_ship(
comp::Pos(pos.0 + Vec3::unit_z() * (50.0 + sz.z as f32 / 2.0)),
comp::Ori::default(),
ship,
move |_| collider,
)
.build();
server.notify_client(

View File

@ -151,9 +151,9 @@ pub fn handle_mount_volume(server: &mut Server, rider: EcsEntity, volume_pos: Vo
&state.ecs().read_storage(),
);
if let Some((transform, block)) = block_transform
if let Some((mat, block)) = block_transform
&& let Some(mount_offset) = block.mount_offset() {
let mount_pos = (Mat4::from(transform) * mount_offset.0.with_w(1.0)).xyz();
let mount_pos = (mat * mount_offset.0.with_w(1.0)).xyz();
let within_range = {
let positions = state.ecs().read_storage::<Pos>();
positions.get(rider).map_or(false, |pos| pos.0.distance_squared(mount_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE)

View File

@ -13,6 +13,7 @@ use common::{
InventoryUpdate,
},
consts::MAX_PICKUP_RANGE,
mounting::VolumePos,
recipe::{
self, default_component_recipe_book, default_recipe_book, default_repair_recipe_book,
},
@ -21,7 +22,7 @@ use common::{
trade::Trades,
uid::Uid,
util::find_dist::{self, FindDist},
vol::ReadVol, mounting::VolumePos,
vol::ReadVol,
};
use common_net::sync::WorldSyncExt;
use common_state::State;
@ -750,7 +751,14 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
.filter(|pos| {
let entity_cylinder = get_cylinder(state, entity);
let in_range = within_pickup_range(entity_cylinder, || {
pos.get_block_and_transform(&state.terrain(), &state.ecs().read_resource(), &state.read_storage(), &state.read_storage(), &state.read_storage()).map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5)))
pos.get_block_and_transform(
&state.terrain(),
&state.ecs().read_resource(),
&state.read_storage(),
&state.read_storage(),
&state.read_storage(),
)
.map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5)))
});
if !in_range {
debug!(
@ -762,7 +770,13 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
}
in_range
})
.and_then(|pos| pos.get_block(&state.terrain(), &state.ecs().read_resource(), &state.read_storage()))
.and_then(|pos| {
pos.get_block(
&state.terrain(),
&state.ecs().read_resource(),
&state.read_storage(),
)
})
.and_then(|block| block.get_sprite())
};

View File

@ -2040,7 +2040,7 @@ impl Hud {
}
// Render overtime for an interactable block
if let Some(Interactable::Block(block, pos, interaction)) = interactable
if let Some(Interactable::Block(block, pos, interaction)) = interactable
&& let Some((mat, _)) = pos.get_block_and_transform(&ecs.read_resource(), &ecs.read_resource(), &ecs.read_storage(), &ecs.read_storage(), &ecs.read_storage()) {
let overitem_id = overitem_walker.next(
&mut self.ids.overitems,

View File

@ -38,9 +38,10 @@ use common::{
comp::{
inventory::slot::EquipSlot,
item::{tool::AbilityContext, Hands, ItemKind, ToolKind},
ship::{self, figuredata::VOXEL_COLLIDER_MANIFEST}, Body, CharacterActivity, CharacterState, Collider, Controller, Health, Inventory,
Item, ItemKey, Last, LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos,
Scale, SkillSet, Stance, Vel,
ship::{self, figuredata::VOXEL_COLLIDER_MANIFEST},
Body, CharacterActivity, CharacterState, Collider, Controller, Health, Inventory, Item,
ItemKey, Last, LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale,
SkillSet, Stance, Vel,
},
link::Is,
mounting::{Rider, VolumeRider},
@ -6104,7 +6105,7 @@ impl FigureMgr {
pos.0.into(),
ori.into_vec4().into(),
vk,
Arc::clone(&vol),
Arc::clone(vol),
tick,
&slow_jobs,
terrain,
@ -6346,23 +6347,25 @@ impl FigureMgr {
if let Some((data, sprite_instances)) =
self.get_sprite_instances(entity, body, collider)
{
let dist = collider.and_then(|collider| {
let vol = collider.get_vol(&voxel_colliders_manifest)?;
let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::translation_3d(vol.translation);
let dist = collider
.and_then(|collider| {
let vol = collider.get_vol(&voxel_colliders_manifest)?;
let p = mat.inverted().mul_point(cam_pos);
let aabb = Aabb {
min: Vec3::zero(),
max: vol.volume().sz.as_(),
};
Some(if aabb.contains_point(p) {
0.0
} else {
aabb.distance_to_point(p)
let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::translation_3d(vol.translation);
let p = mat.inverted().mul_point(cam_pos);
let aabb = Aabb {
min: Vec3::zero(),
max: vol.volume().sz.as_(),
};
Some(if aabb.contains_point(p) {
0.0
} else {
aabb.distance_to_point(p)
})
})
}).unwrap_or_else(|| pos.0.distance(cam_pos));
.unwrap_or_else(|| pos.0.distance(cam_pos));
if dist < sprite_render_distance {
let lod_level = if dist < sprite_high_detail_distance {

View File

@ -3,7 +3,10 @@ use super::{
load::{BodySpec, ShipBoneMeshes},
EcsEntity,
};
use common::{assets, comp::ship::{figuredata::VoxelCollider, AIRSHIP_SCALE}};
use common::{
assets,
comp::ship::figuredata::VoxelCollider,
};
use std::{convert::TryFrom, sync::Arc};
#[derive(Copy, Clone, PartialEq, Eq, Hash)]

View File

@ -690,8 +690,7 @@ impl Scene {
.filter(|(pos, _, light_anim, h)| {
light_anim.col != Rgb::zero()
&& light_anim.strength > 0.0
&& pos.0.distance_squared(viewpoint_pos)
< max_light_dist
&& pos.0.distance_squared(viewpoint_pos) < max_light_dist
&& h.map_or(true, |h| !h.is_dead)
})
.map(|(pos, interpolated, light_anim, _)| {
@ -714,33 +713,42 @@ impl Scene {
&scene_data.state.read_storage::<comp::Ori>(),
&scene_data.state.read_storage::<comp::Body>(),
&scene_data.state.read_storage::<comp::Collider>(),
).join().filter_map(|(entity, pos, ori, body, collider)| {
let vol = collider.get_vol(&voxel_colliders_manifest)?;
)
.join()
.filter_map(|(entity, pos, ori, body, collider)| {
let vol = collider.get_vol(&voxel_colliders_manifest)?;
let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::translation_3d(vol.translation);
let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::translation_3d(vol.translation);
let p = mat.inverted().mul_point(viewpoint_pos);
let aabb = Aabb {
min: Vec3::zero(),
max: vol.volume().sz.as_(),
};
if aabb.contains_point(p) || aabb.distance_to_point(p) < max_light_dist {
figure_mgr
.get_blocks_of_interest(entity, body, Some(collider))
.map(move |(blocks_of_interest, _)| {
blocks_of_interest.lights.iter().map(
move |(block_offset, level)| {
let wpos = mat.mul_point(block_offset.as_() + 0.5);
(wpos, level)
},
).filter(move |(wpos, _)| wpos.distance_squared(viewpoint_pos) < max_light_dist)
.map(|(wpos, level)| Light::new(wpos, Rgb::white(), *level as f32 / 7.0))
})
} else {
None
}
}).flatten()
let p = mat.inverted().mul_point(viewpoint_pos);
let aabb = Aabb {
min: Vec3::zero(),
max: vol.volume().sz.as_(),
};
if aabb.contains_point(p) || aabb.distance_to_point(p) < max_light_dist {
figure_mgr
.get_blocks_of_interest(entity, body, Some(collider))
.map(move |(blocks_of_interest, _)| {
blocks_of_interest
.lights
.iter()
.map(move |(block_offset, level)| {
let wpos = mat.mul_point(block_offset.as_() + 0.5);
(wpos, level)
})
.filter(move |(wpos, _)| {
wpos.distance_squared(viewpoint_pos) < max_light_dist
})
.map(|(wpos, level)| {
Light::new(wpos, Rgb::white(), *level as f32 / 7.0)
})
})
} else {
None
}
})
.flatten(),
);
lights.sort_by_key(|light| light.get_pos().distance_squared(viewpoint_pos) as i32);
lights.truncate(MAX_LIGHT_COUNT);

View File

@ -312,8 +312,9 @@ pub(super) fn select_interactable(
.chain(volumes)
.filter(|(wpos, volume_pos, interaction)| {
match interaction {
Interaction::Mount => !is_volume_rider.contains(player_entity) && wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE &&
is_volume_rider.join().find(|is_volume_rider| is_volume_rider.pos == *volume_pos).is_none(),
Interaction::Mount => !is_volume_rider.contains(player_entity)
&& wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE
&& !is_volume_rider.join().any(|is_volume_rider| is_volume_rider.pos == *volume_pos),
_ => true,
}
})
@ -333,7 +334,7 @@ pub(super) fn select_interactable(
&ecs.read_resource::<UidAllocator>(),
&ecs.read_storage(),
block_pos,
interaction.clone(),
*interaction,
)
})
.or_else(|| closest_interactable_entity.map(|(e, _)| Interactable::Entity(e)))

View File

@ -951,9 +951,7 @@ impl PlayState for SessionState {
BlockInteraction::Craft(tab) => {
self.hud.show.open_crafting_tab(
*tab,
block
.get_sprite()
.map(|s| (*pos, s)),
block.get_sprite().map(|s| (*pos, s)),
)
},
BlockInteraction::Mount => {