aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-06-05 21:21:56 +0000
committerrodri <rgl@antares-labs.eu>2023-06-05 21:21:56 +0000
commit650a361f5a04e4fc39ade90459d280d227875cb1 (patch)
tree2d97defc243ce642522acd6a2f388574e1d66e24
parent9c20abc1ab976cab00040a32299896dc8ea71e6c (diff)
downloadmusw-650a361f5a04e4fc39ade90459d280d227875cb1.tar.gz
musw-650a361f5a04e4fc39ade90459d280d227875cb1.tar.bz2
musw-650a361f5a04e4fc39ade90459d280d227875cb1.zip
use a queue for player input to dampen race conditions between the netcode and the sims.
-rw-r--r--dat.h1
-rw-r--r--muswd.c6
-rw-r--r--pack.c1
-rw-r--r--party.c1
-rw-r--r--physics.c1
-rw-r--r--player.c3
-rw-r--r--universe.c1
7 files changed, 13 insertions, 1 deletions
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<<Kquit) != 0){
np = p->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 <ip.h>
#include <mp.h>
#include <libsec.h>
+#include <thread.h>
#include <draw.h>
#include <geometry.h>
#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 <ip.h>
#include <mp.h>
#include <libsec.h>
+#include <thread.h>
#include <draw.h>
#include <geometry.h>
#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 <ip.h>
#include <mp.h>
#include <libsec.h>
+#include <thread.h>
#include <draw.h>
#include <geometry.h>
#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 <ip.h>
#include <mp.h>
#include <libsec.h>
+#include <thread.h>
#include <draw.h>
#include <geometry.h>
#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 <ip.h>
#include <mp.h>
#include <libsec.h>
+#include <thread.h>
#include <draw.h>
#include <geometry.h>
#include "dat.h"