Wed, 16 Apr 2014 21:16:05 +0200
fixed Move struct size inconsistancy across plattforms
src/chess/rules.c | file | annotate | diff | comparison | revisions | |
src/chess/rules.h | file | annotate | diff | comparison | revisions |
1.1 --- a/src/chess/rules.c Wed Apr 16 20:32:25 2014 +0200 1.2 +++ b/src/chess/rules.c Wed Apr 16 21:16:05 2014 +0200 1.3 @@ -48,17 +48,20 @@ 1.4 elem->next = NULL; 1.5 elem->move = *move; 1.6 1.7 - gettimeofday(&(elem->move.timestamp), NULL); 1.8 + struct timeval curtimestamp; 1.9 + gettimeofday(&curtimestamp, NULL); 1.10 + elem->move.timestamp.tv_sec = curtimestamp.tv_sec; 1.11 + elem->move.timestamp.tv_usec = curtimestamp.tv_usec; 1.12 1.13 if (gamestate->lastmove) { 1.14 - struct timeval *lasttstamp = &(gamestate->lastmove->move.timestamp); 1.15 - time_t sec = elem->move.timestamp.tv_sec - lasttstamp->tv_sec; 1.16 + struct movetimeval *lasttstamp = &(gamestate->lastmove->move.timestamp); 1.17 + uint64_t sec = curtimestamp.tv_sec - lasttstamp->tv_sec; 1.18 suseconds_t micros; 1.19 - if (elem->move.timestamp.tv_usec < lasttstamp->tv_usec) { 1.20 - micros = 1e6L-(lasttstamp->tv_usec - elem->move.timestamp.tv_usec); 1.21 + if (curtimestamp.tv_usec < lasttstamp->tv_usec) { 1.22 + micros = 1e6L-(lasttstamp->tv_usec - curtimestamp.tv_usec); 1.23 sec--; 1.24 } else { 1.25 - micros = elem->move.timestamp.tv_usec - lasttstamp->tv_usec; 1.26 + micros = curtimestamp.tv_usec - lasttstamp->tv_usec; 1.27 } 1.28 1.29 elem->move.movetime.tv_sec = sec; 1.30 @@ -559,7 +562,7 @@ 1.31 while (movelist) { 1.32 time += gameinfo->addtime; 1.33 1.34 - struct timeval *movetime = &(movelist->move.movetime); 1.35 + struct movetimeval *movetime = &(movelist->move.movetime); 1.36 if (movetime->tv_sec >= time) { 1.37 return 0; 1.38 } 1.39 @@ -573,7 +576,7 @@ 1.40 time_t sec; 1.41 movelist = gamestate->lastmove; 1.42 if ((movelist->move.piece & COLOR_MASK) != color) { 1.43 - struct timeval *lastmovetstamp = &(movelist->move.timestamp); 1.44 + struct movetimeval *lastmovetstamp = &(movelist->move.timestamp); 1.45 struct timeval currenttstamp; 1.46 gettimeofday(¤ttstamp, NULL); 1.47 micros += currenttstamp.tv_usec - lastmovetstamp->tv_usec;
2.1 --- a/src/chess/rules.h Wed Apr 16 20:32:25 2014 +0200 2.2 +++ b/src/chess/rules.h Wed Apr 16 21:16:05 2014 +0200 2.3 @@ -69,6 +69,11 @@ 2.4 2.5 typedef uint8_t Board[8][8]; 2.6 2.7 +struct movetimeval { 2.8 + uint64_t tv_sec; 2.9 + int32_t tv_usec; 2.10 +}; 2.11 + 2.12 typedef struct { 2.13 uint8_t piece; 2.14 uint8_t fromfile; 2.15 @@ -76,10 +81,10 @@ 2.16 uint8_t tofile; 2.17 uint8_t torow; 2.18 uint8_t promotion; 2.19 - struct timeval timestamp; 2.20 - struct timeval movetime; 2.21 - _Bool check; 2.22 - _Bool capture; 2.23 + struct movetimeval timestamp; 2.24 + struct movetimeval movetime; 2.25 + uint8_t check; 2.26 + uint8_t capture; 2.27 } Move; 2.28 2.29 typedef struct MoveList MoveList; 2.30 @@ -92,7 +97,7 @@ 2.31 2.32 typedef struct { 2.33 uint8_t servercolor; 2.34 - _Bool timecontrol; 2.35 + uint8_t timecontrol; 2.36 uint16_t time; 2.37 uint16_t addtime; 2.38 } GameInfo;