aboutsummaryrefslogtreecommitdiff
path: root/musw.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-03-04 23:32:47 +0000
committerrodri <rgl@antares-labs.eu>2023-03-04 23:32:47 +0000
commit941d146cea7d0c2ce872e599622a5c9e01d37fe2 (patch)
tree0fe67a2d7f4f906b1e33acee2b1d70d2e03e1fa5 /musw.c
parent9712ec712cc6a57d416ef2b1e86d15ef161016df (diff)
downloadmusw-941d146cea7d0c2ce872e599622a5c9e01d37fe2.tar.gz
musw-941d146cea7d0c2ce872e599622a5c9e01d37fe2.tar.bz2
musw-941d146cea7d0c2ce872e599622a5c9e01d37fe2.zip
implemented client reconnection loop.
currently not working. there seems to be a problem with 9front's udp stack. needs investigation.
Diffstat (limited to 'musw.c')
-rw-r--r--musw.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/musw.c b/musw.c
index 32bf155..ea3803a 100644
--- a/musw.c
+++ b/musw.c
@@ -12,13 +12,6 @@
#include "dat.h"
#include "fns.h"
-typedef struct Keymap Keymap;
-struct Keymap
-{
- Rune key;
- KeyOp op;
-};
-
Keymap kmap[] = {
{.key = Kup, .op = K↑},
{.key = Kleft, .op = K↺},
@@ -38,6 +31,7 @@ Universe *universe;
VModel *needlemdl, *wedgemdl;
Image *screenb;
Image *skymap;
+Scene *curscene;
Channel *ingress;
Channel *egress;
NetConn netconn;
@@ -311,7 +305,7 @@ threadnetrecv(void *arg)
if(debug){
rport = frame->udp.rport[0]<<8 | frame->udp.rport[1];
lport = frame->udp.lport[0]<<8 | frame->udp.lport[1];
- fprint(2, "%I!%ud → %I!%ud | rcvd %Φ\n",
+ fprint(2, "%I!%ud ← %I!%ud | rcvd %Φ\n",
frame->udp.laddr, lport, frame->udp.raddr, rport, frame);
}
}
@@ -557,7 +551,7 @@ usage(void)
void
threadmain(int argc, char *argv[])
{
- uvlong then, now;
+ uvlong then, now, lastpktsent;
double frametime;
char *server;
int fd;
@@ -625,19 +619,26 @@ threadmain(int argc, char *argv[])
threadcreate(threadresize, mc, mainstacksize);
then = nanosec();
+ lastpktsent = 0;
io = ioproc();
for(;;){
now = nanosec();
frametime = now - then;
then = now;
+ if(netconn.state != NCSConnected)
+ lastpktsent += frametime/1e6;
+
+ if(netconn.state == NCSDisconnected ||
+ (netconn.state == NCSConnecting && lastpktsent >= 1000)){
+ initconn();
+ lastpktsent = 0;
+ }
+
universe->star.spr->step(universe->star.spr, frametime/1e6);
redraw();
- if(netconn.state == NCSDisconnected)
- initconn();
-
iosleep(io, HZ2MS(30));
}
}