use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MaxHealthEvent {
pub time: u64,
pub agent: AgentId,
pub max_health: u64,
}
impl Extract for MaxHealthEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
max_health: event.dst_agent,
}
}
}
impl TryExtract for MaxHealthEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::MaxHealthUpdate
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct HealthUpdateEvent {
pub time: u64,
pub agent: AgentId,
pub health: f32,
}
impl HealthUpdateEvent {
pub const CONVERT: f32 = 10_000.0;
}
impl Extract for HealthUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
health: event.dst_agent as f32 / Self::CONVERT,
}
}
}
impl TryExtract for HealthUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::HealthUpdate
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BarrierUpdateEvent {
pub time: u64,
pub agent: AgentId,
pub barrier: f32,
}
impl BarrierUpdateEvent {
pub const CONVERT: f32 = 10_000.0;
}
impl Extract for BarrierUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
barrier: event.dst_agent as f32 / Self::CONVERT,
}
}
}
impl TryExtract for BarrierUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::BarrierUpdate
}
}