From 9595969f2e916e800ec029623305920e11ef182b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 2 Aug 2017 00:55:52 -0400 Subject: Split tile access and modify --- server.c | 16 ++++++++++++++-- torus.h | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server.c b/server.c index 97d4230..fc3b3d0 100755 --- a/server.c +++ b/server.c @@ -56,11 +56,23 @@ static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) { memset(tile->colors, COLOR_WHITE, CELLS_SIZE); tile->create = time(NULL); } + return tile; +} + +static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) { + struct Tile *tile = tileGet(tileX, tileY); tile->access = time(NULL); tile->accessCount++; return tile; } +static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) { + struct Tile *tile = tileGet(tileX, tileY); + tile->modify = time(NULL); + tile->modifyCount++; + return tile; +} + static struct Client { int fd; @@ -102,7 +114,7 @@ static bool clientSend(const struct Client *client, const struct ServerMessage * if (len < 0) return false; if (msg->type == SERVER_TILE) { - struct Tile *tile = tileGet(client->tileX, client->tileY); + struct Tile *tile = tileAccess(client->tileX, client->tileY); len = send(client->fd, tile, sizeof(*tile), 0); if (len < 0) return false; } @@ -227,7 +239,7 @@ static bool clientMove(struct Client *client, int8_t dx, int8_t dy) { } static bool clientPut(const struct Client *client, uint8_t color, char cell) { - struct Tile *tile = tileGet(client->tileX, client->tileY); + struct Tile *tile = tileModify(client->tileX, client->tileY); tile->colors[client->cellY][client->cellX] = color; tile->cells[client->cellY][client->cellX] = cell; diff --git a/torus.h b/torus.h index 9158ef7..6b28f8c 100644 --- a/torus.h +++ b/torus.h @@ -27,10 +27,12 @@ enum { struct Tile { time_t create; - time_t access; + time_t modify; char cells[CELL_ROWS][CELL_COLS] ALIGNED(16); uint8_t colors[CELL_ROWS][CELL_COLS] ALIGNED(16); + uint32_t modifyCount; uint32_t accessCount; + time_t access; } ALIGNED(4096); static_assert(sizeof(struct Tile) == 4096, "struct Tile is page-sized"); static_assert(offsetof(struct Tile, cells) == 16, "stable cells offset"); -- cgit 1.4.1 g-agent.conf (unfollow)
Commit message (Expand)Author
2019-06-28Set HISTSIZE in catshJune McEnroe
2019-06-28Unset iflag when exiting catshJune McEnroe
2019-06-24Consolidate catsh history documentationJune McEnroe
2019-06-19Set LESS=FRXJune McEnroe
2019-06-16Alias date=ddateJune McEnroe
2019-06-15Set sensitivity by slot in TF2June McEnroe
2019-06-15Add AcceptanceJune McEnroe
2019-06-07Add variables to bitJune McEnroe
2019-06-05Add A Closed and Common OrbitJune McEnroe
2019-06-02Add RebornJune McEnroe
2019-05-30Add bit to bin.7June McEnroe
2019-05-30Simplify and build bitJune McEnroe
2019-05-29Add xx -p optionJune McEnroe
2019-05-27Add FrontierJune McEnroe
2019-05-27Break nicks with ZWNJJune McEnroe
2019-05-26Add DawnJune McEnroe
2019-05-20Declare vasprintf(3) for GNUJune McEnroe
2019-05-20Fix comparison warning in ttpreJune McEnroe
2019-05-20Add AuthorityJune McEnroe
2019-05-19Specify precedence of unary versions of operatorsJune McEnroe
2019-05-18Add compound assignment operators to orderJune McEnroe
2019-05-15Support simple assignment in orderJune McEnroe
2019-05-15Implement sizeof in orderJune McEnroe
2019-05-15Add orderJune McEnroe
2019-05-12Add T suffix in bitJune McEnroe
2019-05-10Highlight yacc and lex files as CJune McEnroe
2019-05-10Use val instead of suboptargJune McEnroe
2019-05-09Add Parable of the SowerJune McEnroe
2019-05-07Add bit without buildJune McEnroe
2019-05-04Fix MANDIR typoJune McEnroe
2019-05-04Move relay to binJune McEnroe