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
|
if last_character_states
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.map(|&l| {
|
.map(|&l| !client_character_state.is_same_state(&l.0))
|
||||||
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)
|
|
||||||
})
|
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
{
|
{
|
||||||
let _ = last_character_states
|
let _ = last_character_states
|
||||||
|
@ -63,6 +63,20 @@ pub struct CharacterState {
|
|||||||
pub action: ActionState,
|
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 {
|
impl Default for CharacterState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -1161,13 +1161,7 @@ impl Server {
|
|||||||
{
|
{
|
||||||
if last_character_state
|
if last_character_state
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.map(|&l| {
|
.map(|&l| !client_character_state.is_same_state(&l.0))
|
||||||
// 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)
|
|
||||||
})
|
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
{
|
{
|
||||||
let _ =
|
let _ =
|
||||||
|
@ -691,15 +691,10 @@ impl FigureMgr {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
if std::mem::discriminant(&last_character.0.movement)
|
if !character.is_same_movement(&last_character.0) {
|
||||||
!= std::mem::discriminant(&character.movement)
|
|
||||||
{
|
|
||||||
state.last_movement_change = Instant::now();
|
state.last_movement_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
if !character.is_same_action(&last_character.0) {
|
||||||
if std::mem::discriminant(&last_character.0.action)
|
|
||||||
!= std::mem::discriminant(&character.action)
|
|
||||||
{
|
|
||||||
state.last_action_change = Instant::now();
|
state.last_action_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,9 +785,7 @@ impl FigureMgr {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
if std::mem::discriminant(&last_character.0.movement)
|
if !character.is_same_movement(&last_character.0) {
|
||||||
!= std::mem::discriminant(&character.movement)
|
|
||||||
{
|
|
||||||
state.last_movement_change = Instant::now();
|
state.last_movement_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,9 +832,7 @@ impl FigureMgr {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
if std::mem::discriminant(&last_character.0.movement)
|
if !character.is_same_movement(&last_character.0) {
|
||||||
!= std::mem::discriminant(&character.movement)
|
|
||||||
{
|
|
||||||
state.last_movement_change = Instant::now();
|
state.last_movement_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user