aboutsummaryrefslogtreecommitdiff
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
parent00f7d8dd3dc47ed3cfa951325e809a92c37341b7 (diff)
downloadmusw-826fce49c5319d0965c603dc950623cc07996376.tar.gz
musw-826fce49c5319d0965c603dc950623cc07996376.tar.bz2
musw-826fce49c5319d0965c603dc950623cc07996376.zip
only send/recv the fired bullets on simstate packets.
-rw-r--r--musw.c20
-rw-r--r--muswd.c15
-rw-r--r--pack.c14
-rw-r--r--todo1
4 files changed, 42 insertions, 8 deletions
diff --git a/musw.c b/musw.c
index 75dea1a..8d428c0 100644
--- a/musw.c
+++ b/musw.c
@@ -327,6 +327,7 @@ void
threadnetppu(void *)
{
int i, j;
+ int nfired[2], bi;
uchar *bufp;
Frame *frame, *newf;
@@ -384,11 +385,20 @@ threadnetppu(void *)
&universe->ships[1].p, &universe->ships[1].θ,
&universe->star.p);
- /* TODO: only recv the fired ones */
- for(i = 0; i < nelem(universe->ships); i++)
- for(j = 0; j < nelem(universe->ships[i].rounds); j++)
- bufp += unpack(bufp, frame->len - (bufp-frame->data), "Pd",
- &universe->ships[i].rounds[j].p, &universe->ships[i].rounds[j].θ);
+ bufp += unpack(bufp, frame->len - (bufp-frame->data), "bb", &nfired[0], &nfired[1]);
+
+ if(debug)
+ fprint(2, "nfired0 %d nfired1 %d\n", nfired[0], nfired[1]);
+
+ for(i = 0; i < nelem(universe->ships); i++)
+ for(j = 0; j < nfired[i]; j++){
+ bufp += unpack(bufp, frame->len - (bufp-frame->data), "b",
+ &bi);
+ if(debug)
+ fprint(2, "bi %d\n", bi);
+ bufp += unpack(bufp, frame->len - (bufp-frame->data), "Pd",
+ &universe->ships[i].rounds[bi].p, &universe->ships[i].rounds[bi].θ);
+ }
break;
case NSnudge:
newf = newframe(nil, NCnudge, frame->seq+1, frame->seq, 0, nil);
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);
diff --git a/pack.c b/pack.c
index f1a9a0a..ae58df6 100644
--- a/pack.c
+++ b/pack.c
@@ -45,6 +45,14 @@ vpack(uchar *p, int n, char *fmt, va_list a)
switch(*fmt++){
case '\0':
return p - p0;
+ case 'b':
+ k = va_arg(a, ulong);
+
+ if(p+1 > e)
+ goto err;
+
+ *p++ = k;
+ break;
case 'd':
d.x = va_arg(a, double);
@@ -119,6 +127,12 @@ vunpack(uchar *p, int n, char *fmt, va_list a)
switch(*fmt++){
case '\0':
return p - p0;
+ case 'b':
+ if(p+1 > e)
+ goto err;
+
+ *va_arg(a, ulong*) = *p++;
+ break;
case 'd':
if(p+8 > e)
goto err;
diff --git a/todo b/todo
index e7722ba..a9c0ca7 100644
--- a/todo
+++ b/todo
@@ -13,6 +13,7 @@
[✓] waiting for a player
[✓] main game
[ ] reduce the amount of data sent on every NSsimstate packet
+ [✓] only send the fired bullets
[?] the client must try to connect continously
> there's an error in the udp stack that doesn't allow the client to receive packets if run before the server is up.
[ ] more realistic DEC Type 30 CRT emulation