aboutsummaryrefslogtreecommitdiff
path: root/muswd.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-04-23 14:33:14 +0000
committerrodri <rgl@antares-labs.eu>2023-04-23 14:33:14 +0000
commit826fce49c5319d0965c603dc950623cc07996376 (patch)
treeb32f1a46ce48c8d6007586bb263be0d75d6052eb /muswd.c
parent00f7d8dd3dc47ed3cfa951325e809a92c37341b7 (diff)
downloadmusw-826fce49c5319d0965c603dc950623cc07996376.tar.gz
musw-826fce49c5319d0965c603dc950623cc07996376.tar.bz2
musw-826fce49c5319d0965c603dc950623cc07996376.zip
only send/recv the fired bullets on simstate packets.
Diffstat (limited to 'muswd.c')
-rw-r--r--muswd.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/muswd.c b/muswd.c
index 27a9e00..3502637 100644
--- a/muswd.c
+++ b/muswd.c
@@ -279,6 +279,7 @@ void
broadcaststate(void)
{
int i, j, k;
+ int nfired[2];
uchar *bufp;
Frame *frame;
NetConn *pnc;
@@ -296,11 +297,19 @@ broadcaststate(void)
p->u->ships[1].p, p->u->ships[1].θ,
p->u->star.p);
- /* TODO: only send the fired ones */
+ nfired[0] = nfired[1] = 0;
for(j = 0; j < nelem(p->u->ships); j++)
for(k = 0; k < nelem(p->u->ships[j].rounds); k++)
- bufp += pack(bufp, frame->len - (bufp-frame->data), "Pd",
- p->u->ships[j].rounds[k].p, p->u->ships[j].rounds[k].θ);
+ if(p->u->ships[j].rounds[k].fired)
+ nfired[j]++;
+
+ bufp += pack(bufp, frame->len - (bufp-frame->data), "bb", nfired[0], nfired[1]);
+
+ for(j = 0; j < nelem(p->u->ships); j++)
+ for(k = 0; k < nelem(p->u->ships[j].rounds); k++)
+ if(p->u->ships[j].rounds[k].fired)
+ bufp += pack(bufp, frame->len - (bufp-frame->data), "bPd",
+ k, p->u->ships[j].rounds[k].p, p->u->ships[j].rounds[k].θ);
signframe(frame, pnc->dh.priv);