mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move std::mem::discriminant into new method
This commit is contained in:
parent
d822356161
commit
9a832dd56b
@ -290,12 +290,7 @@ impl Client {
|
||||
{
|
||||
if last_character_states
|
||||
.get(entity)
|
||||
.map(|&l| {
|
||||
std::mem::discriminant(&l.0.movement)
|
||||
!= std::mem::discriminant(&client_character_state.movement)
|
||||
|| std::mem::discriminant(&l.0.action)
|
||||
!= std::mem::discriminant(&client_character_state.action)
|
||||
})
|
||||
.map(|&l| !client_character_state.is_same_state(&l.0))
|
||||
.unwrap_or(true)
|
||||
{
|
||||
let _ = last_character_states
|
||||
|
@ -63,6 +63,20 @@ pub struct CharacterState {
|
||||
pub action: ActionState,
|
||||
}
|
||||
|
||||
impl CharacterState {
|
||||
pub fn is_same_movement(&self, other: &Self) -> bool {
|
||||
// Check if enum item is the same without looking at the inner data
|
||||
std::mem::discriminant(&self.movement) == std::mem::discriminant(&other.movement)
|
||||
}
|
||||
pub fn is_same_action(&self, other: &Self) -> bool {
|
||||
// Check if enum item is the same without looking at the inner data
|
||||
std::mem::discriminant(&self.action) == std::mem::discriminant(&other.action)
|
||||
}
|
||||
pub fn is_same_state(&self, other: &Self) -> bool {
|
||||
self.is_same_movement(other) && self.is_same_action(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CharacterState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
@ -1161,13 +1161,7 @@ impl Server {
|
||||
{
|
||||
if last_character_state
|
||||
.get(entity)
|
||||
.map(|&l| {
|
||||
// Check if enum item is the same without looking at the inner data
|
||||
std::mem::discriminant(&l.0.movement)
|
||||
!= std::mem::discriminant(&client_character_state.movement)
|
||||
|| std::mem::discriminant(&l.0.action)
|
||||
!= std::mem::discriminant(&client_character_state.action)
|
||||
})
|
||||
.map(|&l| !client_character_state.is_same_state(&l.0))
|
||||
.unwrap_or(true)
|
||||
{
|
||||
let _ =
|
||||
|
@ -691,15 +691,10 @@ impl FigureMgr {
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
if std::mem::discriminant(&last_character.0.movement)
|
||||
!= std::mem::discriminant(&character.movement)
|
||||
{
|
||||
if !character.is_same_movement(&last_character.0) {
|
||||
state.last_movement_change = Instant::now();
|
||||
}
|
||||
|
||||
if std::mem::discriminant(&last_character.0.action)
|
||||
!= std::mem::discriminant(&character.action)
|
||||
{
|
||||
if !character.is_same_action(&last_character.0) {
|
||||
state.last_action_change = Instant::now();
|
||||
}
|
||||
|
||||
@ -790,9 +785,7 @@ impl FigureMgr {
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
if std::mem::discriminant(&last_character.0.movement)
|
||||
!= std::mem::discriminant(&character.movement)
|
||||
{
|
||||
if !character.is_same_movement(&last_character.0) {
|
||||
state.last_movement_change = Instant::now();
|
||||
}
|
||||
|
||||
@ -839,9 +832,7 @@ impl FigureMgr {
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
if std::mem::discriminant(&last_character.0.movement)
|
||||
!= std::mem::discriminant(&character.movement)
|
||||
{
|
||||
if !character.is_same_movement(&last_character.0) {
|
||||
state.last_movement_change = Instant::now();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user