use crate::common::entity_state::model::EntityAppearance;
use crate::common::model::{
EntityId, Location, Orientation, PduBody, VariableParameter, VectorF32,
};
use crate::common::{BodyInfo, Interaction};
use crate::constants::VARIABLE_PARAMETER_RECORD_LENGTH;
use crate::entity_state_update::builder::EntityStateUpdateBuilder;
use crate::enumerations::PduType;
use crate::BodyRaw;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
const BASE_ENTITY_STATE_UPDATE_BODY_LENGTH: u16 = 60;
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
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 BodyRaw for EntityStateUpdate {
type Builder = EntityStateUpdateBuilder;
fn builder() -> Self::Builder {
Self::Builder::new()
}
fn into_builder(self) -> Self::Builder {
Self::Builder::new_from_body(self)
}
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
}
}