mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
intentional use of terrain targeting and select_pos as passed to the event handler. select_pos is None when not needed.
This commit is contained in:
parent
42d5836cfa
commit
b4d12b7995
@ -412,8 +412,14 @@ impl PlayState for SessionState {
|
|||||||
&& client.is_wielding() == Some(true);
|
&& client.is_wielding() == Some(true);
|
||||||
|
|
||||||
// Check to see whether we're aiming at anything
|
// Check to see whether we're aiming at anything
|
||||||
let (build_target, collect_target, entity_target, mine_target, shortest_dist) =
|
let (
|
||||||
targets_under_cursor(&client, cam_pos, cam_dir, can_build, is_mining);
|
build_target,
|
||||||
|
collect_target,
|
||||||
|
entity_target,
|
||||||
|
mine_target,
|
||||||
|
terrain_target,
|
||||||
|
shortest_dist,
|
||||||
|
) = targets_under_cursor(&client, cam_pos, cam_dir, can_build, is_mining);
|
||||||
|
|
||||||
self.interactable = select_interactable(
|
self.interactable = select_interactable(
|
||||||
&client,
|
&client,
|
||||||
@ -442,10 +448,11 @@ impl PlayState for SessionState {
|
|||||||
} else {
|
} else {
|
||||||
self.scene.set_select_pos(None);
|
self.scene.set_select_pos(None);
|
||||||
}
|
}
|
||||||
|
// filled block in line of sight
|
||||||
|
let default_select_pos = terrain_target.map(|tt| tt.position);
|
||||||
|
|
||||||
// Throw out distance info, it will be useful in the future
|
// Throw out distance info, it will be useful in the future
|
||||||
self.target_entity = entity_target.map(|t| t.kind.0);
|
self.target_entity = entity_target.map(|t| t.kind.0);
|
||||||
let default_select_pos = entity_target.map(|et| et.position);
|
|
||||||
|
|
||||||
// Handle window events.
|
// Handle window events.
|
||||||
for event in events {
|
for event in events {
|
||||||
@ -476,16 +483,10 @@ impl PlayState for SessionState {
|
|||||||
}) {
|
}) {
|
||||||
client.remove_block(build_target.position_int());
|
client.remove_block(build_target.position_int());
|
||||||
} else {
|
} else {
|
||||||
let mut select_pos = default_select_pos;
|
|
||||||
if let Some(mine_target) = mine_target.filter(|mt| {
|
|
||||||
is_mining && is_nearest_target(shortest_dist, *mt)
|
|
||||||
}) {
|
|
||||||
select_pos = Some(mine_target.position);
|
|
||||||
}
|
|
||||||
client.handle_input(
|
client.handle_input(
|
||||||
InputKind::Primary,
|
InputKind::Primary,
|
||||||
state,
|
state,
|
||||||
select_pos,
|
default_select_pos,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -504,7 +505,7 @@ impl PlayState for SessionState {
|
|||||||
client.handle_input(
|
client.handle_input(
|
||||||
InputKind::Secondary,
|
InputKind::Secondary,
|
||||||
state,
|
state,
|
||||||
default_select_pos,
|
None,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -513,7 +514,7 @@ impl PlayState for SessionState {
|
|||||||
self.client.borrow_mut().handle_input(
|
self.client.borrow_mut().handle_input(
|
||||||
InputKind::Block,
|
InputKind::Block,
|
||||||
state,
|
state,
|
||||||
default_select_pos,
|
None,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -536,7 +537,7 @@ impl PlayState for SessionState {
|
|||||||
client.handle_input(
|
client.handle_input(
|
||||||
InputKind::Roll,
|
InputKind::Roll,
|
||||||
state,
|
state,
|
||||||
default_select_pos,
|
None,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -551,7 +552,7 @@ impl PlayState for SessionState {
|
|||||||
self.client.borrow_mut().handle_input(
|
self.client.borrow_mut().handle_input(
|
||||||
InputKind::Jump,
|
InputKind::Jump,
|
||||||
state,
|
state,
|
||||||
default_select_pos,
|
None,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -626,7 +627,7 @@ impl PlayState for SessionState {
|
|||||||
self.client.borrow_mut().handle_input(
|
self.client.borrow_mut().handle_input(
|
||||||
InputKind::Fly,
|
InputKind::Fly,
|
||||||
self.key_state.fly,
|
self.key_state.fly,
|
||||||
default_select_pos,
|
None,
|
||||||
self.target_entity,
|
self.target_entity,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -31,6 +31,10 @@ pub struct Entity(pub specs::Entity);
|
|||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Mine;
|
pub struct Mine;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
// line of sight (if not bocked by entity). Not build/mine mode dependent.
|
||||||
|
pub struct Terrain;
|
||||||
|
|
||||||
impl<T> Target<T> {
|
impl<T> Target<T> {
|
||||||
pub fn position_int(self) -> Vec3<i32> { self.position.map(|p| p.floor() as i32) }
|
pub fn position_int(self) -> Vec3<i32> { self.position.map(|p| p.floor() as i32) }
|
||||||
}
|
}
|
||||||
@ -48,6 +52,7 @@ pub(super) fn targets_under_cursor(
|
|||||||
Option<Target<Collectable>>,
|
Option<Target<Collectable>>,
|
||||||
Option<Target<Entity>>,
|
Option<Target<Entity>>,
|
||||||
Option<Target<Mine>>,
|
Option<Target<Mine>>,
|
||||||
|
Option<Target<Terrain>>,
|
||||||
f32,
|
f32,
|
||||||
) {
|
) {
|
||||||
span!(_guard, "targets_under_cursor");
|
span!(_guard, "targets_under_cursor");
|
||||||
@ -193,12 +198,23 @@ pub(super) fn targets_under_cursor(
|
|||||||
} else { None }
|
} else { None }
|
||||||
});
|
});
|
||||||
|
|
||||||
let build_target = if can_build {
|
let solid_ray_dist = solid_cam_ray.map(|r| r.0);
|
||||||
|
let terrain_target = if let (None, Some(distance)) = (entity_target, solid_ray_dist) {
|
||||||
|
solid_pos.map(|position| Target {
|
||||||
|
kind: Terrain,
|
||||||
|
distance,
|
||||||
|
position,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let build_target = if let (true, Some(distance)) = (can_build, solid_ray_dist) {
|
||||||
place_block_pos
|
place_block_pos
|
||||||
.zip(solid_pos.zip(solid_cam_ray))
|
.zip(solid_pos)
|
||||||
.map(|(place_pos, (position, ray))| Target {
|
.map(|(place_pos, position)| Target {
|
||||||
kind: Build(place_pos),
|
kind: Build(place_pos),
|
||||||
distance: ray.0,
|
distance,
|
||||||
position,
|
position,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -226,6 +242,7 @@ pub(super) fn targets_under_cursor(
|
|||||||
collect_target,
|
collect_target,
|
||||||
entity_target,
|
entity_target,
|
||||||
mine_target,
|
mine_target,
|
||||||
|
terrain_target,
|
||||||
shortest_cam_dist,
|
shortest_cam_dist,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user