Remove usage of some temporary vars
This commit is contained in:
parent
9aee736978
commit
36a55544f9
3
game.c
3
game.c
@ -109,7 +109,8 @@ static void firstzero(void) {
|
|||||||
gountil=mycount=mydatacount=0;
|
gountil=mycount=mydatacount=0;
|
||||||
memset(latestactions,0,sizeof(latestactions));
|
memset(latestactions,0,sizeof(latestactions));
|
||||||
memset(latestcounts,0,sizeof(latestcounts));
|
memset(latestcounts,0,sizeof(latestcounts));
|
||||||
actionput=actioncount=0;
|
memset(actionblock,0,sizeof(actionblock));
|
||||||
|
actioncount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initgame() {
|
static void initgame() {
|
||||||
|
40
network.c
40
network.c
@ -27,8 +27,7 @@ int mydatacount;
|
|||||||
int myslot;
|
int myslot;
|
||||||
network_type network = NETWORK_NONE;
|
network_type network = NETWORK_NONE;
|
||||||
|
|
||||||
static unsigned char hist[ACTIONHIST][MAXNETNODES];
|
int actioncount;
|
||||||
int actionput,actioncount;
|
|
||||||
unsigned char actionblock[ACTIONHIST*MAXNETNODES];
|
unsigned char actionblock[ACTIONHIST*MAXNETNODES];
|
||||||
|
|
||||||
int myaction;
|
int myaction;
|
||||||
@ -53,7 +52,7 @@ enum network_packet_types {
|
|||||||
/* slave -> master packets */
|
/* slave -> master packets */
|
||||||
PKT_MYDATA, /* 4 bytes unique #,4 bytes frame #, 1 byte data */
|
PKT_MYDATA, /* 4 bytes unique #,4 bytes frame #, 1 byte data */
|
||||||
/* master -> slave packets */
|
/* 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
|
PKT_INVALID = 0xff
|
||||||
};
|
};
|
||||||
@ -254,31 +253,11 @@ static int isvalidmsg_from_master() {
|
|||||||
/* Handling game actions */
|
/* Handling game actions */
|
||||||
|
|
||||||
static void addactions(void) {
|
static void addactions(void) {
|
||||||
memmove(hist[actionput],actions,MAXNETNODES);
|
memmove(actionblock+MAXNETNODES, actionblock, (ACTIONHIST-1)*MAXNETNODES);
|
||||||
++actionput;
|
memcpy(actionblock, actions, MAXNETNODES);
|
||||||
if(actionput==ACTIONHIST)
|
|
||||||
actionput=0;
|
|
||||||
++actioncount;
|
++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) {
|
static void sendactions(int which) {
|
||||||
unsigned char msg[512];
|
unsigned char msg[512];
|
||||||
|
|
||||||
@ -303,7 +282,6 @@ int networktraffic(void) {
|
|||||||
int i;
|
int i;
|
||||||
int length;
|
int length;
|
||||||
int whosent;
|
int whosent;
|
||||||
unsigned char newactions[MAXNETNODES];
|
|
||||||
long now;
|
long now;
|
||||||
long count;
|
long count;
|
||||||
|
|
||||||
@ -311,8 +289,8 @@ int networktraffic(void) {
|
|||||||
case NETWORK_NONE:
|
case NETWORK_NONE:
|
||||||
return -1;
|
return -1;
|
||||||
case NETWORK_MASTER:
|
case NETWORK_MASTER:
|
||||||
memcpy(newactions,latestactions,MAXNETNODES);
|
memcpy(actions,latestactions,MAXNETNODES);
|
||||||
newactions[0]=myaction;
|
actions[0]=myaction;
|
||||||
now=gtime();
|
now=gtime();
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(gtime()-now>15) break;
|
if(gtime()-now>15) break;
|
||||||
@ -327,18 +305,16 @@ int networktraffic(void) {
|
|||||||
count=readuint32(mesg+5);
|
count=readuint32(mesg+5);
|
||||||
if(count>latestcounts[whosent]) {
|
if(count>latestcounts[whosent]) {
|
||||||
latestcounts[whosent]=count;
|
latestcounts[whosent]=count;
|
||||||
newactions[whosent]=mesg[9];
|
actions[whosent]=mesg[9];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(myaction==ACT_QUIT) {
|
if(myaction==ACT_QUIT) {
|
||||||
for(i=1;i<MAXNETNODES;++i)
|
for(i=1;i<MAXNETNODES;++i)
|
||||||
if(netnodes[i].used)
|
if(netnodes[i].used)
|
||||||
newactions[i]=ACT_QUIT;
|
actions[i]=ACT_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(actions,newactions,sizeof(actions));
|
|
||||||
addactions();
|
addactions();
|
||||||
buildactions();
|
|
||||||
for(i=1;i<MAXNETNODES;++i)
|
for(i=1;i<MAXNETNODES;++i)
|
||||||
if(netnodes[i].used)
|
if(netnodes[i].used)
|
||||||
sendactions(i);
|
sendactions(i);
|
||||||
|
Loading…
Reference in New Issue
Block a user