dis_rs/common/entity_state_update/
model.rs1use crate::common::entity_state::model::EntityAppearance;
2use crate::common::model::{
3 EntityId, Location, Orientation, PduBody, VariableParameter, VectorF32,
4};
5use crate::common::{BodyInfo, Interaction};
6use crate::constants::VARIABLE_PARAMETER_RECORD_LENGTH;
7use crate::entity_state_update::builder::EntityStateUpdateBuilder;
8use crate::enumerations::PduType;
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11
12const BASE_ENTITY_STATE_UPDATE_BODY_LENGTH: u16 = 60;
13
14#[derive(Clone, Debug, Default, PartialEq)]
18#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19pub struct EntityStateUpdate {
20 pub entity_id: EntityId,
21 pub entity_linear_velocity: VectorF32,
22 pub entity_location: Location,
23 pub entity_orientation: Orientation,
24 pub entity_appearance: EntityAppearance,
25 pub variable_parameters: Vec<VariableParameter>,
26}
27
28impl EntityStateUpdate {
29 #[must_use]
30 pub fn builder() -> EntityStateUpdateBuilder {
31 EntityStateUpdateBuilder::new()
32 }
33
34 #[must_use]
35 pub fn into_builder(self) -> EntityStateUpdateBuilder {
36 EntityStateUpdateBuilder::new_from_body(self)
37 }
38
39 #[must_use]
40 pub fn into_pdu_body(self) -> PduBody {
41 PduBody::EntityStateUpdate(self)
42 }
43}
44
45impl BodyInfo for EntityStateUpdate {
46 fn body_length(&self) -> u16 {
47 BASE_ENTITY_STATE_UPDATE_BODY_LENGTH
48 + (VARIABLE_PARAMETER_RECORD_LENGTH * (self.variable_parameters.len() as u16))
49 }
50
51 fn body_type(&self) -> PduType {
52 PduType::EntityStateUpdate
53 }
54}
55
56impl Interaction for EntityStateUpdate {
57 fn originator(&self) -> Option<&EntityId> {
58 Some(&self.entity_id)
59 }
60
61 fn receiver(&self) -> Option<&EntityId> {
62 None
63 }
64}