aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mkfile1
-rw-r--r--musw.c6
-rw-r--r--muswd.c10
-rw-r--r--party.c86
-rw-r--r--player.c91
5 files changed, 102 insertions, 92 deletions
diff --git a/mkfile b/mkfile
index 6973c0e..eb3c9a0 100644
--- a/mkfile
+++ b/mkfile
@@ -12,6 +12,7 @@ OFILES=\
nanosec.$O\
pack.$O\
party.$O\
+ player.$O\
universe.$O\
sprite.$O\
vfx.$O\
diff --git a/musw.c b/musw.c
index fd04db3..fd8c8ac 100644
--- a/musw.c
+++ b/musw.c
@@ -657,14 +657,16 @@ State *intro_δ(State *s, void *arg)
State *connecting_δ(State *s, void*)
{
- if(netconn.state != NCSConnecting)
+ if(netconn.state == NCSConnected)
return &gamestates[GSMatching];
return s;
}
State *matching_δ(State *s, void*)
{
- if(netconn.state == NCSConnected && weplaying)
+ if(netconn.state != NCSConnected)
+ return &gamestates[GSConnecting];
+ if(weplaying)
return &gamestates[GSPlaying];
return s;
}
diff --git a/muswd.c b/muswd.c
index 4f871d8..1882e59 100644
--- a/muswd.c
+++ b/muswd.c
@@ -336,7 +336,7 @@ threadsim(void *)
uvlong then, now;
double frametime, Δt;
Ioproc *io;
- Party *p;
+ Party *p, *np;
Player *player;
Ship *ship;
@@ -352,8 +352,7 @@ threadsim(void *)
if(players.len >= 2)
newparty(&theparty, players.get(&players), players.get(&players));
-partywalk:
- for(p = theparty.next; p != &theparty; p = p->next){
+ for(p = theparty.next; p != &theparty; p = np){
p->u->timeacc += frametime/1e9;
for(i = 0; i < nelem(p->players); i++){
@@ -361,8 +360,9 @@ partywalk:
ship = &p->u->ships[i];
if((player->kdown & 1<<Kquit) != 0){
+ np = p->next;
popconn(player->conn);
- goto partywalk;
+ goto partydone;
}
if((player->kdown & 1<<K↑) != 0)
ship->forward(ship, Δt);
@@ -384,6 +384,8 @@ partywalk:
p->u->step(p->u, Δt);
p->u->collide(p->u);
}
+ np = p->next;
+partydone:;
}
broadcaststate();
diff --git a/party.c b/party.c
index be0f4ed..031a4fa 100644
--- a/party.c
+++ b/party.c
@@ -8,8 +8,6 @@
#include "dat.h"
#include "fns.h"
-/* Party */
-
Party *
newparty(Party *p, Player *player0, Player *player1)
{
@@ -50,87 +48,3 @@ initparty(Party *p)
{
p->next = p->prev = p;
}
-
-/* Player */
-
-Player *
-newplayer(char *name, NetConn *nc)
-{
- Player *p;
-
- p = emalloc(sizeof(Player));
- p->name = name? strdup(name): nil;
- p->conn = nc;
- p->oldkdown = p->kdown = 0;
- p->next = nil;
-
- return p;
-}
-
-void
-delplayer(Player *p)
-{
- free(p->name);
- free(p);
-}
-
-/* Player queue */
-
-static void
-playerq_put(Playerq *pq, Player *p)
-{
- if(pq->tail == nil)
- pq->head = pq->tail = p;
- else{
- pq->tail->next = p;
- pq->tail = p;
- }
- pq->len++;
-}
-
-static Player *
-playerq_get(Playerq *pq)
-{
- Player *p;
-
- if(pq->head == nil)
- return nil;
-
- p = pq->head;
- if(pq->head == pq->tail)
- pq->head = pq->tail = nil;
- else{
- pq->head = p->next;
- p->next = nil;
- }
- pq->len--;
- return p;
-}
-
-static void
-playerq_del(Playerq *pq, Player *p)
-{
- Player *np;
-
- if(pq->head == p){
- pq->get(pq);
- return;
- }
-
- for(np = pq->head; np != nil && np->next != nil; np = np->next)
- if(np->next == p){
- np->next = np->next->next;
- p->next = nil;
- pq->len--;
- }
-}
-
-void
-initplayerq(Playerq *pq)
-{
- pq->head = pq->tail = nil;
- pq->len = 0;
- pq->put = playerq_put;
- pq->get = playerq_get;
- pq->del = playerq_del;
-}
diff --git a/player.c b/player.c
new file mode 100644
index 0000000..fc573b7
--- /dev/null
+++ b/player.c
@@ -0,0 +1,91 @@
+#include <u.h>
+#include <libc.h>
+#include <ip.h>
+#include <mp.h>
+#include <libsec.h>
+#include <draw.h>
+#include <geometry.h>
+#include "dat.h"
+#include "fns.h"
+
+Player *
+newplayer(char *name, NetConn *nc)
+{
+ Player *p;
+
+ p = emalloc(sizeof(Player));
+ p->name = name? strdup(name): nil;
+ p->conn = nc;
+ p->oldkdown = p->kdown = 0;
+ p->next = nil;
+
+ return p;
+}
+
+void
+delplayer(Player *p)
+{
+ free(p->name);
+ free(p);
+}
+
+/* Player queue */
+
+static void
+playerq_put(Playerq *pq, Player *p)
+{
+ if(pq->tail == nil)
+ pq->head = pq->tail = p;
+ else{
+ pq->tail->next = p;
+ pq->tail = p;
+ }
+ pq->len++;
+}
+
+static Player *
+playerq_get(Playerq *pq)
+{
+ Player *p;
+
+ if(pq->head == nil)
+ return nil;
+
+ p = pq->head;
+ if(pq->head == pq->tail)
+ pq->head = pq->tail = nil;
+ else{
+ pq->head = p->next;
+ p->next = nil;
+ }
+ pq->len--;
+ return p;
+}
+
+static void
+playerq_del(Playerq *pq, Player *p)
+{
+ Player *np;
+
+ if(pq->head == p){
+ pq->get(pq);
+ return;
+ }
+
+ for(np = pq->head; np != nil && np->next != nil; np = np->next)
+ if(np->next == p){
+ np->next = np->next->next;
+ p->next = nil;
+ pq->len--;
+ }
+}
+
+void
+initplayerq(Playerq *pq)
+{
+ pq->head = pq->tail = nil;
+ pq->len = 0;
+ pq->put = playerq_put;
+ pq->get = playerq_get;
+ pq->del = playerq_del;
+} \ No newline at end of file