use std::sync::Arc;
use henad_core::view::StatEntry;
use crate::gpu::view::agents::GpuAgents;
use crate::gpu::view::display::GpuDisplay;
#[derive(Debug)]
pub struct Snapshot {
pub tick: u64,
pub serial: u64,
pub population: u64,
pub heap_bytes: usize,
pub actual_tps: f64,
pub engine_ms: f64,
pub view_ms: f64,
pub view: SnapshotView,
pub stats: Vec<StatEntry>,
}
#[derive(Debug)]
pub enum SnapshotView {
Cpu(CpuLayers),
Gpu(GpuSnapshot),
}
#[derive(Debug, Default)]
pub struct CpuLayers {
pub grid: Option<GridSnapshot>,
pub points: Option<PointSnapshot>,
pub edges: Option<Box<EdgeSnapshot>>,
}
impl CpuLayers {
pub fn is_empty(&self) -> bool {
self.grid.is_none() && self.points.is_none()
}
}
#[derive(Debug, Default)]
pub struct GpuSnapshot {
pub display: Option<Arc<GpuDisplay>>,
pub agents: Option<Arc<GpuAgents>>,
}
impl GpuSnapshot {
pub fn is_empty(&self) -> bool {
self.display.is_none() && self.agents.is_none()
}
}
pub struct GridSnapshot {
pub width: u32,
pub height: u32,
pub cells: Vec<u8>,
pub palette: &'static [[u8; 4]],
}
impl std::fmt::Debug for GridSnapshot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GridSnapshot")
.field("width", &self.width)
.field("height", &self.height)
.field("palette_len", &self.palette.len())
.finish_non_exhaustive()
}
}
#[derive(Default)]
pub struct EdgeSnapshot {
pub version: u64,
pub src: Vec<u32>,
pub dst: Vec<u32>,
pub color: Vec<u8>,
pub palette: &'static [[u8; 4]],
pub directed: bool,
}
impl std::fmt::Debug for EdgeSnapshot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EdgeSnapshot")
.field("version", &self.version)
.field("len", &self.src.len())
.field("colored", &!self.color.is_empty())
.field("palette_len", &self.palette.len())
.field("directed", &self.directed)
.finish_non_exhaustive()
}
}
pub struct PointSnapshot {
pub pos_x: Vec<f32>,
pub pos_y: Vec<f32>,
pub world_w: f32,
pub world_h: f32,
pub color: Vec<u8>,
pub palette: &'static [[u8; 4]],
}
impl std::fmt::Debug for PointSnapshot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PointSnapshot")
.field("len", &self.pos_x.len())
.field("world_w", &self.world_w)
.field("world_h", &self.world_h)
.field("colored", &!self.color.is_empty())
.field("palette_len", &self.palette.len())
.finish_non_exhaustive()
}
}