1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::common::{BodyInfo, Interaction};
use crate::constants::VARIABLE_PARAMETER_RECORD_LENGTH;
use crate::common::model::{EntityId, Location, Orientation, PduBody, VariableParameter, VectorF32};
use crate::common::entity_state::model::{EntityAppearance};
use crate::entity_state_update::builder::EntityStateUpdateBuilder;
use crate::enumerations::PduType;

const BASE_ENTITY_STATE_UPDATE_BODY_LENGTH : u16 = 60;

/// 5.3.5 Entity State Update PDU
///
/// 7.2.5 Entity State Update PDU
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EntityStateUpdate {
    pub entity_id : EntityId,
    pub entity_linear_velocity : VectorF32,
    pub entity_location : Location,
    pub entity_orientation : Orientation,
    pub entity_appearance: EntityAppearance,
    pub variable_parameters: Vec<VariableParameter>,
}

impl EntityStateUpdate {
    pub fn builder() -> EntityStateUpdateBuilder {
        EntityStateUpdateBuilder::new()
    }

    pub fn into_builder(self) -> EntityStateUpdateBuilder {
        EntityStateUpdateBuilder::new_from_body(self)
    }

    pub fn into_pdu_body(self) -> PduBody {
        PduBody::EntityStateUpdate(self)
    }
}

impl BodyInfo for EntityStateUpdate {
    fn body_length(&self) -> u16 {
        BASE_ENTITY_STATE_UPDATE_BODY_LENGTH + (VARIABLE_PARAMETER_RECORD_LENGTH * (self.variable_parameters.len() as u16))
    }

    fn body_type(&self) -> PduType {
        PduType::EntityStateUpdate
    }
}

impl Interaction for EntityStateUpdate {
    fn originator(&self) -> Option<&EntityId> {
        Some(&self.entity_id)
    }

    fn receiver(&self) -> Option<&EntityId> {
        None
    }
}