diff options
-rw-r--r-- | musw.c | 20 | ||||
-rw-r--r-- | muswd.c | 15 | ||||
-rw-r--r-- | pack.c | 14 | ||||
-rw-r--r-- | todo | 1 |
4 files changed, 42 insertions, 8 deletions
@@ -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); @@ -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); @@ -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; @@ -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 |