2022-01-17 06:51:56 +00:00
|
|
|
use crate::sync::{self, NetSync};
|
2022-01-18 05:24:37 +00:00
|
|
|
use common::comp;
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2019-04-29 20:37:19 +00:00
|
|
|
use std::marker::PhantomData;
|
2019-04-10 17:23:27 +00:00
|
|
|
|
2022-01-18 05:24:37 +00:00
|
|
|
macro_rules! comp_packet {
|
|
|
|
($($component_name:ident: $component_type:ident,)*) => {
|
|
|
|
sum_type::sum_type! {
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum EcsCompPacket {
|
|
|
|
$($component_type($component_type),)*
|
|
|
|
Pos(comp::Pos),
|
|
|
|
Vel(comp::Vel),
|
|
|
|
Ori(comp::Ori),
|
|
|
|
}
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2022-01-18 05:24:37 +00:00
|
|
|
sum_type::sum_type! {
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum EcsCompPhantom {
|
|
|
|
$($component_type(PhantomData<$component_type>),)*
|
|
|
|
Pos(PhantomData<comp::Pos>),
|
|
|
|
Vel(PhantomData<comp::Vel>),
|
|
|
|
Ori(PhantomData<comp::Ori>),
|
|
|
|
}
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2022-01-18 05:24:37 +00:00
|
|
|
impl sync::CompPacket for EcsCompPacket {
|
|
|
|
type Phantom = EcsCompPhantom;
|
|
|
|
|
|
|
|
fn apply_insert(self, entity: specs::Entity, world: &specs::World, force_update: bool) {
|
|
|
|
match self {
|
2022-01-17 06:51:56 +00:00
|
|
|
$(Self::$component_type(mut comp) => {
|
|
|
|
comp.pre_insert(world);
|
2022-01-18 05:24:37 +00:00
|
|
|
sync::handle_insert(comp, entity, world);
|
|
|
|
},)*
|
|
|
|
Self::Pos(comp) => {
|
|
|
|
sync::handle_interp_insert(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
Self::Vel(comp) => {
|
|
|
|
sync::handle_interp_insert(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
Self::Ori(comp) => {
|
|
|
|
sync::handle_interp_insert(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn apply_modify(self, entity: specs::Entity, world: &specs::World, force_update: bool) {
|
|
|
|
match self {
|
2022-01-17 06:51:56 +00:00
|
|
|
$(Self::$component_type(mut comp) => {
|
|
|
|
comp.pre_modify(world);
|
2022-01-18 05:24:37 +00:00
|
|
|
sync::handle_modify(comp, entity, world);
|
|
|
|
},)*
|
|
|
|
Self::Pos(comp) => {
|
|
|
|
sync::handle_interp_modify(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
Self::Vel(comp) => {
|
|
|
|
sync::handle_interp_modify(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
Self::Ori(comp) => {
|
|
|
|
sync::handle_interp_modify(comp, entity, world, force_update)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) {
|
|
|
|
match phantom {
|
|
|
|
$(EcsCompPhantom::$component_type(_) => {
|
|
|
|
sync::handle_remove::<$component_type>(entity, world);
|
|
|
|
},)*
|
|
|
|
EcsCompPhantom::Pos(_) => {
|
|
|
|
sync::handle_interp_remove::<comp::Pos>(entity, world)
|
|
|
|
},
|
|
|
|
EcsCompPhantom::Vel(_) => {
|
|
|
|
sync::handle_interp_remove::<comp::Vel>(entity, world)
|
|
|
|
},
|
|
|
|
EcsCompPhantom::Ori(_) => {
|
|
|
|
sync::handle_interp_remove::<comp::Ori>(entity, world)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
2022-01-18 05:24:37 +00:00
|
|
|
|
|
|
|
use crate::synced_components::*;
|
|
|
|
crate::synced_components!(comp_packet);
|