Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize event ids by splitting them up by server/client and reliable/unreliable #143

Open
wants to merge 3 commits into
base: 0.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions zap/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,55 @@ pub struct Config<'src> {
pub disable_fire_all: bool,
}

impl<'src> Config<'src> {
pub fn event_id_ty(&self) -> NumTy {
NumTy::from_f64(1.0, (self.evdecls.len() + self.fndecls.len()) as f64)
impl Config<'_> {
pub fn server_reliable_count(&self) -> usize {
let reliable_count = self
.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Client && evdecl.evty == EvType::Reliable)
.count();

reliable_count + self.fndecls.len()
}

pub fn server_unreliable_count(&self) -> usize {
self.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Client && evdecl.evty == EvType::Unreliable)
.count()
}

pub fn client_reliable_count(&self) -> usize {
let reliable_count = self
.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Server && evdecl.evty == EvType::Reliable)
.count();

reliable_count + self.fndecls.len()
}

pub fn client_unreliable_count(&self) -> usize {
self.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Server && evdecl.evty == EvType::Unreliable)
.count()
}
jackdotink marked this conversation as resolved.
Show resolved Hide resolved

pub fn server_reliable_ty(&self) -> NumTy {
NumTy::from_f64(0.0, self.server_reliable_count() as f64 - 1.0)
}

pub fn server_unreliable_ty(&self) -> NumTy {
NumTy::from_f64(0.0, self.server_unreliable_count() as f64 - 1.0)
}

pub fn client_reliable_ty(&self) -> NumTy {
NumTy::from_f64(0.0, self.client_reliable_count() as f64 - 1.0)
}

pub fn client_unreliable_ty(&self) -> NumTy {
NumTy::from_f64(0.0, self.client_unreliable_count() as f64 - 1.0)
}
}

Expand Down Expand Up @@ -78,7 +124,8 @@ pub struct FnDecl<'src> {
pub call: FnCall,
pub args: Vec<Parameter<'src>>,
pub rets: Option<Vec<Ty<'src>>>,
pub id: usize,
pub client_id: usize,
pub server_id: usize,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
Loading
Loading