diff options
author | rodri <rgl@antares-labs.eu> | 2023-05-28 19:32:09 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-05-28 19:32:09 +0000 |
commit | 0625897dd0194986b02988eb5a9c2969e24adf0c (patch) | |
tree | cb957e1f9bd7cf6177dd4296d6aedbece6924a1a | |
parent | 29c02c33749f9ca21ffa1c22cc2cc37f58584467 (diff) | |
download | musw-0625897dd0194986b02988eb5a9c2969e24adf0c.tar.gz musw-0625897dd0194986b02988eb5a9c2969e24adf0c.tar.bz2 musw-0625897dd0194986b02988eb5a9c2969e24adf0c.zip |
cleaned up the client game loop.
-rw-r--r-- | musw.c | 90 | ||||
-rw-r--r-- | todo | 2 |
2 files changed, 50 insertions, 42 deletions
@@ -645,11 +645,11 @@ resize(void) State *intro_δ(State *s, void *arg) { - double ∆t; static ulong elapsed; + uvlong ∆t; - ∆t = *(double*)arg; - elapsed += ∆t/1e6; + ∆t = *(uvlong*)arg; + elapsed += ∆t; if(elapsed > 5000) return &gamestates[GSConnecting]; return s; @@ -695,6 +695,49 @@ soundproc(void *) } void +threadshow(void *) +{ + uvlong then, now, frametime, lastpktsent; + Vfx *vfx; + Ioproc *io; + + then = nanosec(); + lastpktsent = 0; + io = ioproc(); + for(;;){ + now = nanosec(); + frametime = (now - then)/1000000ULL; + then = now; + + switch(gamestate-gamestates){ + case GSPlaying: + universe->star.spr->step(universe->star.spr, frametime); + for(vfx = vfxqueue.next; vfx != &vfxqueue; vfx = vfx->next) + vfx->step(vfx, frametime); + /* fallthrough */ + default: + if(netconn.state == NCSConnecting) + lastpktsent += frametime; + + if(netconn.state == NCSDisconnected || + (netconn.state == NCSConnecting && lastpktsent >= 1000)){ + initconn(); + lastpktsent = 0; + } + break; + case GSIntro: + intro->step(intro, frametime); + break; + } + gamestate = gamestate->δ(gamestate, &frametime); + + redraw(); + + iosleep(io, HZ2MS(30)); + } +} + +void usage(void) { fprint(2, "usage: %s [-dg] server\n", argv0); @@ -704,14 +747,10 @@ usage(void) void threadmain(int argc, char *argv[]) { - uvlong then, now, lastpktsent; - double frametime; char *server; int fd; - Vfx *vfx; cm_Source *bgsound; Mousectl *mc; - Ioproc *io; GEOMfmtinstall(); fmtinstall('I', eipfmt); @@ -793,39 +832,6 @@ threadmain(int argc, char *argv[]) threadcreate(threadnetppu, nil, mainstacksize); threadcreate(threadnetsend, &fd, mainstacksize); threadcreate(threadresize, mc, mainstacksize); - - then = nanosec(); - lastpktsent = 0; - io = ioproc(); - for(;;){ - now = nanosec(); - frametime = now - then; - then = now; - - switch(gamestate-gamestates){ - case GSPlaying: - universe->star.spr->step(universe->star.spr, frametime/1e6); - for(vfx = vfxqueue.next; vfx != &vfxqueue; vfx = vfx->next) - vfx->step(vfx, frametime/1e6); - /* fallthrough */ - default: - if(netconn.state == NCSConnecting) - lastpktsent += frametime/1e6; - - if(netconn.state == NCSDisconnected || - (netconn.state == NCSConnecting && lastpktsent >= 1000)){ - initconn(); - lastpktsent = 0; - } - break; - case GSIntro: - intro->step(intro, frametime/1e6); - break; - } - gamestate = gamestate->δ(gamestate, &frametime); - - redraw(); - - iosleep(io, HZ2MS(30)); - } + threadcreate(threadshow, nil, mainstacksize); + yield(); } @@ -1,4 +1,6 @@ [ ] collision detection + [ ] load the models on the server + [ ] the server sends the ship models to the clients [✓] toroidal warping [✓] respect bullets's ttl [✓] communicate this event to the clients (δ: fired 1 → 0) |