From 650a361f5a04e4fc39ade90459d280d227875cb1 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 5 Jun 2023 21:21:56 +0000 Subject: use a queue for player input to dampen race conditions between the netcode and the sims. --- dat.h | 1 + muswd.c | 6 +++++- pack.c | 1 + party.c | 1 + physics.c | 1 + player.c | 3 +++ universe.c | 1 + 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dat.h b/dat.h index 024c1c9..0615d6a 100644 --- a/dat.h +++ b/dat.h @@ -213,6 +213,7 @@ struct Player { char *name; NetConn *conn; + Channel *inputq; ulong oldkdown, kdown; Player *next; }; diff --git a/muswd.c b/muswd.c index 1882e59..a61595c 100644 --- a/muswd.c +++ b/muswd.c @@ -233,7 +233,7 @@ threadnetppu(void *) if(debug) fprint(2, "\t%.*lub\n", sizeof(kdown)*8, kdown); - nc->player->kdown = kdown; + nbsendul(nc->player->inputq, kdown); break; case NCbuhbye: @@ -333,6 +333,7 @@ void threadsim(void *) { int i; + ulong kdown; uvlong then, now; double frametime, Δt; Ioproc *io; @@ -359,6 +360,9 @@ threadsim(void *) player = p->players[i]; ship = &p->u->ships[i]; + if(nbrecv(player->inputq, &kdown) != 0) + player->kdown = kdown; + if((player->kdown & 1<next; popconn(player->conn); diff --git a/pack.c b/pack.c index ae58df6..2befb20 100644 --- a/pack.c +++ b/pack.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" diff --git a/party.c b/party.c index 031a4fa..6eeaab4 100644 --- a/party.c +++ b/party.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" diff --git a/physics.c b/physics.c index 1eb528a..78fd494 100644 --- a/physics.c +++ b/physics.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" diff --git a/player.c b/player.c index fc573b7..b7e9a3e 100644 --- a/player.c +++ b/player.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" @@ -16,6 +17,7 @@ newplayer(char *name, NetConn *nc) p = emalloc(sizeof(Player)); p->name = name? strdup(name): nil; p->conn = nc; + p->inputq = chancreate(sizeof(ulong), 20); p->oldkdown = p->kdown = 0; p->next = nil; @@ -26,6 +28,7 @@ void delplayer(Player *p) { free(p->name); + chanclose(p->inputq); free(p); } diff --git a/universe.c b/universe.c index c146a73..4fd75fd 100644 --- a/universe.c +++ b/universe.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" -- cgit v1.2.3