Skip to content

Commit

Permalink
extract out push_write_event_id
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdotink committed Dec 18, 2023
1 parent 881e8d5 commit 22492a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion zap/src/output/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ impl<'a> ClientOutput<'a> {
}
}

fn push_write_event_id(&mut self, id: usize) {
self.push_line(&format!("local pos = alloc({})", self.file.event_id_ty().size()));
self.push_line(&format!(
"buffer.write{}(outgoing_buff, pos, {id})",
self.file.event_id_ty()
));
}

fn push_return_fire(&mut self, ev: &EvDecl, id: usize) {
let ty = &ev.data;

Expand All @@ -254,7 +262,8 @@ impl<'a> ClientOutput<'a> {
self.push_line("load_empty()");
}

self.push_line(&format!("buffer.write{}(outgoing_buff, {id})", self.file.event_id_ty()));
self.push_write_event_id(id);

self.push_stmts(&gen_ser(ty, value.into(), self.file.write_checks));

if ev.evty == EvType::Unreliable {
Expand Down
20 changes: 16 additions & 4 deletions zap/src/output/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ impl<'a> ServerOutput<'a> {
}
}

fn push_write_event_id(&mut self, id: usize) {
self.push_line(&format!("local pos = alloc({})", self.file.event_id_ty().size()));
self.push_line(&format!(
"buffer.write{}(outgoing_buff, pos, {id})",
self.file.event_id_ty()
));
}

fn push_return_fire(&mut self, ev: &EvDecl, id: usize) {
let ty = &ev.data;

Expand All @@ -259,12 +267,13 @@ impl<'a> ServerOutput<'a> {
self.push(")\n");
self.indent();

self.push_write_event_id(id);

match ev.evty {
EvType::Reliable => self.push_line(&format!("load(player_map[{player}])")),
EvType::Unreliable => self.push_line("load_empty()"),
}

self.push_line(&format!("buffer.write{}(outgoing_buff, {id})", self.file.event_id_ty()));
self.push_stmts(&gen_ser(ty, value.into(), self.file.write_checks));

match ev.evty {
Expand Down Expand Up @@ -294,7 +303,8 @@ impl<'a> ServerOutput<'a> {

self.push_line("load_empty()");

self.push_line(&format!("buffer.write{}(outgoing_buff, {id})", self.file.event_id_ty()));
self.push_write_event_id(id);

self.push_stmts(&gen_ser(ty, value.into(), self.file.write_checks));

match ev.evty {
Expand Down Expand Up @@ -336,7 +346,8 @@ impl<'a> ServerOutput<'a> {

self.push_line("load_empty()");

self.push_line(&format!("buffer.write{}(outgoing_buff, {id})", self.file.event_id_ty()));
self.push_write_event_id(id);

self.push_stmts(&gen_ser(ty, value.into(), self.file.write_checks));

match ev.evty {
Expand Down Expand Up @@ -390,7 +401,8 @@ impl<'a> ServerOutput<'a> {

self.push_line("load_empty()");

self.push_line(&format!("buffer.write{}(outgoing_buff, {id})", self.file.event_id_ty()));
self.push_write_event_id(id);

self.push_stmts(&gen_ser(ty, value.into(), self.file.write_checks));

match ev.evty {
Expand Down

0 comments on commit 22492a4

Please sign in to comment.