Remove usage of some temporary vars

This commit is contained in:
Stefan Bühler 2009-08-10 21:14:18 +02:00
parent 9aee736978
commit 36a55544f9
2 changed files with 18 additions and 41 deletions

3
game.c
View File

@ -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() {

View File

@ -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,31 +253,11 @@ 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];
@ -303,7 +282,6 @@ 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<MAXNETNODES;++i)
if(netnodes[i].used)
newactions[i]=ACT_QUIT;
actions[i]=ACT_QUIT;
}
memmove(actions,newactions,sizeof(actions));
addactions();
buildactions();
for(i=1;i<MAXNETNODES;++i)
if(netnodes[i].used)
sendactions(i);