From dfe58d1f0859e19e311458d28bcf227981f95d70 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 30 Oct 2008 15:44:54 +0000 Subject: [PATCH] network time cleanups git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3336 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 2 +- source/src/clients2c.cpp | 9 ++++++--- source/src/main.cpp | 4 ++-- source/src/physics.cpp | 4 ++-- source/src/protos.h | 1 + 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 178574d6..03d34e17 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -424,7 +424,7 @@ void gets2c() // get updates from the server case ENET_EVENT_TYPE_RECEIVE: if(discmillis) conoutf("attempting to disconnect..."); - else localservertoclient(event.channelID, event.packet->data, (int)event.packet->dataLength); + else servertoclient(event.channelID, event.packet->data, (int)event.packet->dataLength); enet_packet_destroy(event.packet); break; diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index f90efd79..3113534d 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -862,15 +862,18 @@ void receivefile(uchar *data, int len) } } -void localservertoclient(int chan, uchar *buf, int len) // processes any updates from the server +void servertoclient(int chan, uchar *buf, int len) // processes any updates from the server { ucharbuf p(buf, len); - lastmillis -= curtime; // make sure local packets get processed with the same time as network packets switch(chan) { case 0: parsepositions(p); break; case 1: parsemessages(-1, NULL, p); break; case 2: receivefile(p.buf, p.maxlen); break; } - lastmillis += curtime; // restore time +} + +void localservertoclient(int chan, uchar *buf, int len) // processes any updates from the server +{ + servertoclient(chan, buf, len); } diff --git a/source/src/main.cpp b/source/src/main.cpp index 5db87ec3..8f664527 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -688,11 +688,11 @@ int main(int argc, char **argv) checkinput(); - if(lastmillis) updateworld(curtime, lastmillis); - lastmillis += curtime; totalmillis = millis; + if(lastmillis) updateworld(curtime, lastmillis); + serverslice(0); fps = (1000.0f/elapsed+fps*10)/11; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 64d8a551..666e31bf 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -614,7 +614,7 @@ int physsteps = 0, physframetime = PHYSFRAMETIME, lastphysframe = 0; void physicsframe() // optimally schedule physics frames inside the graphics frames { - int diff = lastmillis + curtime - lastphysframe; + int diff = lastmillis - lastphysframe; if(diff <= 0) physsteps = 0; else { @@ -632,7 +632,7 @@ void interppos(physent *pl) pl->o = pl->newpos; pl->o.z += pl->eyeheight; - int diff = lastphysframe - (lastmillis + curtime); + int diff = lastphysframe - lastmillis; if(diff <= 0 || !physinterp) return; vec deltapos(pl->deltapos); diff --git a/source/src/protos.h b/source/src/protos.h index 7bf19446..60e594d8 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -623,6 +623,7 @@ extern int stringsort(const char **a, const char **b); // server extern int modeacronyms; +extern void servertoclient(int chan, uchar *buf, int len); extern void localservertoclient(int chan, uchar *buf, int len); extern const char *modestr(int n, bool acronyms = false); extern const char *voteerrorstr(int n);