From 36a55544f958ecd35906663d0e54835a47d79947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Mon, 10 Aug 2009 21:14:18 +0200 Subject: [PATCH] Remove usage of some temporary vars --- game.c | 3 ++- network.c | 56 ++++++++++++++++--------------------------------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/game.c b/game.c index e331c4c..22702a2 100644 --- a/game.c +++ b/game.c @@ -109,7 +109,8 @@ static void firstzero(void) { gountil=mycount=mydatacount=0; memset(latestactions,0,sizeof(latestactions)); memset(latestcounts,0,sizeof(latestcounts)); - actionput=actioncount=0; + memset(actionblock,0,sizeof(actionblock)); + actioncount = 0; } static void initgame() { diff --git a/network.c b/network.c index c458599..88196a2 100644 --- a/network.c +++ b/network.c @@ -27,8 +27,7 @@ int mydatacount; int myslot; network_type network = NETWORK_NONE; -static unsigned char hist[ACTIONHIST][MAXNETNODES]; -int actionput,actioncount; +int actioncount; unsigned char actionblock[ACTIONHIST*MAXNETNODES]; int myaction; @@ -53,7 +52,7 @@ enum network_packet_types { /* slave -> master packets */ PKT_MYDATA, /* 4 bytes unique #,4 bytes frame #, 1 byte data */ /* master -> slave packets */ - PKT_STEP, /* 4 bytes unique #, 4 bytes frame #, 8 bytes ACT_* */ + PKT_STEP, /* 4 bytes unique #, 4 bytes frame #, history x MAXNETNODES bytes ACT_* */ PKT_INVALID = 0xff }; @@ -254,56 +253,35 @@ static int isvalidmsg_from_master() { /* Handling game actions */ static void addactions(void) { - memmove(hist[actionput],actions,MAXNETNODES); - ++actionput; - if(actionput==ACTIONHIST) - actionput=0; + memmove(actionblock+MAXNETNODES, actionblock, (ACTIONHIST-1)*MAXNETNODES); + memcpy(actionblock, actions, MAXNETNODES); ++actioncount; } -static void buildactions(void) { - unsigned char *p; - int i,j; - p=actionblock; - i=0; - while(i<20) { - if(actioncount-i>0) { - j=actionput-i-1; - if(j<0) j+=ACTIONHIST; - memmove(p,hist[j],MAXNETNODES); - } else { - memset(p,0,MAXNETNODES); - } - p+=MAXNETNODES; - ++i; - } -} - static void sendactions(int which) { unsigned char msg[512]; msg[0] = PKT_STEP; - write_unique(msg+1); - writeuint32(msg+5, actioncount); - memcpy(msg+9,actionblock,MAXNETNODES*ACTIONHIST); - putmsg(&netnodes[which].netname,msg,MAXNETNODES*ACTIONHIST+9); + write_unique(msg + 1); + writeuint32(msg + 5, actioncount); + memcpy(msg + 9, actionblock, MAXNETNODES*ACTIONHIST); + putmsg(&netnodes[which].netname, msg, MAXNETNODES*ACTIONHIST + 9); } static void sendmine(int frame) { unsigned char msg[64]; msg[0] = PKT_MYDATA; - write_unique(msg+1); - writeuint32(msg+5, frame); - msg[9]=myaction; - putmsg(&mastername,msg,10); + write_unique(msg + 1); + writeuint32(msg + 5, frame); + msg[9] = myaction; + putmsg(&mastername, msg, 10); } int networktraffic(void) { int i; int length; int whosent; - unsigned char newactions[MAXNETNODES]; long now; long count; @@ -311,8 +289,8 @@ int networktraffic(void) { case NETWORK_NONE: return -1; case NETWORK_MASTER: - memcpy(newactions,latestactions,MAXNETNODES); - newactions[0]=myaction; + memcpy(actions,latestactions,MAXNETNODES); + actions[0]=myaction; now=gtime(); for(;;) { if(gtime()-now>15) break; @@ -327,18 +305,16 @@ int networktraffic(void) { count=readuint32(mesg+5); if(count>latestcounts[whosent]) { latestcounts[whosent]=count; - newactions[whosent]=mesg[9]; + actions[whosent]=mesg[9]; } } if(myaction==ACT_QUIT) { for(i=1;i