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 |
--- a/src/chess/rules.c Wed Apr 16 20:32:25 2014 +0200 +++ b/src/chess/rules.c Wed Apr 16 21:16:05 2014 +0200 @@ -48,17 +48,20 @@ elem->next = NULL; elem->move = *move; - gettimeofday(&(elem->move.timestamp), NULL); + struct timeval curtimestamp; + gettimeofday(&curtimestamp, NULL); + elem->move.timestamp.tv_sec = curtimestamp.tv_sec; + elem->move.timestamp.tv_usec = curtimestamp.tv_usec; if (gamestate->lastmove) { - struct timeval *lasttstamp = &(gamestate->lastmove->move.timestamp); - time_t sec = elem->move.timestamp.tv_sec - lasttstamp->tv_sec; + struct movetimeval *lasttstamp = &(gamestate->lastmove->move.timestamp); + uint64_t sec = curtimestamp.tv_sec - lasttstamp->tv_sec; suseconds_t micros; - if (elem->move.timestamp.tv_usec < lasttstamp->tv_usec) { - micros = 1e6L-(lasttstamp->tv_usec - elem->move.timestamp.tv_usec); + if (curtimestamp.tv_usec < lasttstamp->tv_usec) { + micros = 1e6L-(lasttstamp->tv_usec - curtimestamp.tv_usec); sec--; } else { - micros = elem->move.timestamp.tv_usec - lasttstamp->tv_usec; + micros = curtimestamp.tv_usec - lasttstamp->tv_usec; } elem->move.movetime.tv_sec = sec; @@ -559,7 +562,7 @@ while (movelist) { time += gameinfo->addtime; - struct timeval *movetime = &(movelist->move.movetime); + struct movetimeval *movetime = &(movelist->move.movetime); if (movetime->tv_sec >= time) { return 0; } @@ -573,7 +576,7 @@ time_t sec; movelist = gamestate->lastmove; if ((movelist->move.piece & COLOR_MASK) != color) { - struct timeval *lastmovetstamp = &(movelist->move.timestamp); + struct movetimeval *lastmovetstamp = &(movelist->move.timestamp); struct timeval currenttstamp; gettimeofday(¤ttstamp, NULL); micros += currenttstamp.tv_usec - lastmovetstamp->tv_usec;
--- a/src/chess/rules.h Wed Apr 16 20:32:25 2014 +0200 +++ b/src/chess/rules.h Wed Apr 16 21:16:05 2014 +0200 @@ -69,6 +69,11 @@ typedef uint8_t Board[8][8]; +struct movetimeval { + uint64_t tv_sec; + int32_t tv_usec; +}; + typedef struct { uint8_t piece; uint8_t fromfile; @@ -76,10 +81,10 @@ uint8_t tofile; uint8_t torow; uint8_t promotion; - struct timeval timestamp; - struct timeval movetime; - _Bool check; - _Bool capture; + struct movetimeval timestamp; + struct movetimeval movetime; + uint8_t check; + uint8_t capture; } Move; typedef struct MoveList MoveList; @@ -92,7 +97,7 @@ typedef struct { uint8_t servercolor; - _Bool timecontrol; + uint8_t timecontrol; uint16_t time; uint16_t addtime; } GameInfo;