aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--musw.c70
-rw-r--r--muswd.c18
-rw-r--r--universe.c3
3 files changed, 79 insertions, 12 deletions
diff --git a/musw.c b/musw.c
index 25acdb0..8d06539 100644
--- a/musw.c
+++ b/musw.c
@@ -111,6 +111,28 @@ readvmodel(char *file)
}
void
+drawbullets(Ship *ship, Image *dst)
+{
+ int i;
+ Bullet *b;
+ Point2 v;
+
+ for(i = 0; i < nelem(ship->rounds); i++){
+ b = &ship->rounds[i];
+ v = Vec2(-1,0); /* it's pointing backwards to paint the tail */
+ Matrix R = {
+ cos(b->θ), -sin(b->θ), 0,
+ sin(b->θ), cos(b->θ), 0,
+ 0, 0, 1,
+ };
+
+ v = xform(v, R);
+ line(dst, toscreen(b->p), toscreen(addpt2(b->p, mulpt2(v, 10))), 0, 0, 0, display->white, ZP);
+ fillellipse(dst, toscreen(b->p), 1, 1, display->white, ZP);
+ }
+}
+
+void
drawship(Ship *ship, Image *dst)
{
int i;
@@ -144,6 +166,8 @@ drawship(Ship *ship, Image *dst)
p += 3;
break;
}
+
+ drawbullets(ship, dst);
}
void
@@ -254,6 +278,8 @@ threadnetrecv(void *arg)
void
threadnetppu(void *)
{
+ int i, j;
+ uchar *bufp;
Frame *frame, *newf;
threadsetname("threadnetppu");
@@ -302,10 +328,17 @@ threadnetppu(void *)
switch(frame->type){
case NSsimstate:
- unpack(frame->data, frame->len, "PdPdP",
+ bufp = frame->data;
+ bufp += unpack(bufp, frame->len, "PdPdP",
&universe->ships[0].p, &universe->ships[0].θ,
&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].θ);
break;
case NSnudge:
newf = newframe(nil, NCnudge, frame->seq+1, frame->seq, 0, nil);
@@ -398,9 +431,26 @@ darkness:
void
drawconnecting(void)
{
- draw(screen, screen->r, display->black, nil, ZP);
- string(screen, addpt(screen->r.min, Pt(100,300)), display->white, ZP, font, "connecting...");
- flushimage(display, 1);
+ static double t0;
+ static Point p = {100,300};
+ Point np;
+ int i;
+
+ if(t0 == 0)
+ t0 = nanosec();
+
+ if(nanosec()-t0 >= 5e9){ /* every five seconds */
+ p = Pt(ntruerand(SCRW-2*100)+100,ntruerand(SCRH-100)+100);
+ t0 = nanosec();
+ }
+
+ draw(screen, screen->r, skymap, nil, ZP);
+ np = string(screen, addpt(screen->r.min, p), display->white, ZP, font, "connecting");
+
+ for(i = 1; i < 3+1; i++){
+ if(nanosec()-t0 > i*1e9)
+ np = string(screen, np, display->white, ZP, font, ".");
+ }
}
void
@@ -410,9 +460,14 @@ redraw(void)
draw(screen, screen->r, skymap, nil, ZP);
- drawship(&universe->ships[0], screen);
- drawship(&universe->ships[1], screen);
- universe->star.spr->draw(universe->star.spr, screen, subpt(toscreen(universe->star.p), Pt(16,16)));
+ if(netconn.state == NCSConnecting)
+ drawconnecting();
+
+ if(netconn.state == NCSConnected){
+ drawship(&universe->ships[0], screen);
+ drawship(&universe->ships[1], screen);
+ universe->star.spr->draw(universe->star.spr, screen, subpt(toscreen(universe->star.p), Pt(16,16)));
+ }
flushimage(display, 1);
unlockdisplay(display);
@@ -494,6 +549,7 @@ threadmain(int argc, char *argv[])
/* TODO: implement this properly with screens and iodial(2) */
drawconnecting();
+ flushimage(display, 1);
fd = dial(server, nil, nil, nil);
if(fd < 0)
sysfatal("dial: %r");
diff --git a/muswd.c b/muswd.c
index cd268ca..ccaae27 100644
--- a/muswd.c
+++ b/muswd.c
@@ -271,7 +271,8 @@ threadnetsend(void *arg)
void
broadcaststate(void)
{
- int i;
+ int i, j, k;
+ uchar *bufp;
Frame *frame;
NetConn *pnc;
Party *p;
@@ -280,11 +281,20 @@ broadcaststate(void)
for(i = 0; i < nelem(p->players); i++){
pnc = p->players[i]->conn;
- frame = newframe(&pnc->udp, NSsimstate, pnc->lastseq+1, 0, 2*(3*8+8)+3*8, nil);
- pack(frame->data, frame->len, "PdPdP",
+ frame = newframe(&pnc->udp, NSsimstate, pnc->lastseq+1, 0, 2*(3*8+8)+3*8+20*(3*8+8), nil);
+
+ bufp = frame->data;
+ bufp += pack(bufp, frame->len, "PdPdP",
p->u->ships[0].p, p->u->ships[0].θ,
p->u->ships[1].p, p->u->ships[1].θ,
p->u->star.p);
+
+ /* TODO: only send the fired ones */
+ 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].θ);
+
signframe(frame, pnc->dh.priv);
sendp(egress, frame);
@@ -488,5 +498,5 @@ threadmain(int argc, char *argv[])
threadcreate(threadnetppu, nil, mainstacksize);
threadcreate(threadnetsend, &adfd, mainstacksize);
threadcreate(threadsim, nil, mainstacksize);
- threadexits(nil);
+ yield();
}
diff --git a/universe.c b/universe.c
index be481c9..bce345c 100644
--- a/universe.c
+++ b/universe.c
@@ -48,10 +48,11 @@ ship_fire(Ship *s)
0, 0, 1,
};
- bv = mulpt2(xform(Vec2(1,0), R), 10*THRUST);
+ bv = mulpt2(xform(Vec2(1,0), R), THRUST);
for(i = 0; i < nelem(s->rounds); i++)
if(!s->rounds[i].fired){
+ s->rounds[i].p = s->p;
s->rounds[i].v = addpt2(s->v, bv);
s->rounds[i].θ = s->θ;
s->rounds[i].fired++;