From 9bd49e16c9f41b12887a314c6c0317b0c8e8f852 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 21 Aug 2018 14:00:15 -0400 Subject: Shrink the torus and rearrange struct Tile --- client.c | 18 +++++++++--------- merge.c | 4 ++-- meta.c | 10 +++++----- server.c | 22 +++++++--------------- torus.h | 28 ++++++++++++---------------- 5 files changed, 35 insertions(+), 47 deletions(-) diff --git a/client.c b/client.c index 6fb2483..37cc7ce 100644 --- a/client.c +++ b/client.c @@ -346,23 +346,23 @@ static void serverMap(void) { time_t timeMin = timeNow; for (int y = 0; y < MAP_ROWS; ++y) { for (int x = 0; x < MAP_COLS; ++x) { - struct MapTile tile = map.tiles[y][x]; - if (countMax < tile.modifyCount) countMax = tile.modifyCount; - if (tile.modifyTime && timeMin > tile.modifyTime) { - timeMin = tile.modifyTime; + struct Meta meta = map.meta[y][x]; + if (countMax < meta.modifyCount) countMax = meta.modifyCount; + if (meta.modifyTime && timeMin > meta.modifyTime) { + timeMin = meta.modifyTime; } } } for (int y = 0; y < MAP_ROWS; ++y) { for (int x = 0; x < MAP_COLS; ++x) { - struct MapTile tile = map.tiles[y][x]; + struct Meta meta = map.meta[y][x]; - double count = (tile.modifyCount && countMax > 1) - ? log(tile.modifyCount) / log(countMax) + double count = (meta.modifyCount && countMax > 1) + ? log(meta.modifyCount) / log(countMax) : 0.0; - double time = (tile.modifyTime && timeNow - timeMin) - ? (double)(tile.modifyTime - timeMin) / (double)(timeNow - timeMin) + double time = (meta.modifyTime && timeNow - timeMin) + ? (double)(meta.modifyTime - timeMin) / (double)(timeNow - timeMin) : 0.0; count *= ARRAY_LEN(MAP_CELLS) - 2; time *= ARRAY_LEN(MAP_COLORS) - 1; diff --git a/merge.c b/merge.c index 276d071..ea1326e 100644 --- a/merge.c +++ b/merge.c @@ -93,11 +93,11 @@ int main(int argc, char *argv[]) { if (!countA && !countB) break; if (!countA || !countB) errx(EX_DATAERR, "different size inputs"); - const struct Tile *tileC = (tileA.accessTime > tileB.accessTime) + const struct Tile *tileC = (tileA.meta.accessTime > tileB.meta.accessTime) ? &tileA : &tileB; - if (tileA.modifyTime != tileB.modifyTime) { + if (tileA.meta.modifyTime != tileB.meta.modifyTime) { drawTile(0, &tileA); drawTile(CELL_ROWS + 1, &tileB); move(CELL_ROWS * 2 + 2, 0); diff --git a/meta.c b/meta.c index 14a0930..ed55a8d 100644 --- a/meta.c +++ b/meta.c @@ -32,11 +32,11 @@ int main() { "%d,%d,%jd,%u,%jd,%u,%jd\n", i % TILE_COLS, i / TILE_COLS, - tile.createTime, - tile.modifyCount, - tile.modifyTime, - tile.accessCount, - tile.accessTime + tile.meta.createTime, + tile.meta.modifyCount, + tile.meta.modifyTime, + tile.meta.accessCount, + tile.meta.accessTime ); } } diff --git a/server.c b/server.c index 5b502ef..e565816 100644 --- a/server.c +++ b/server.c @@ -58,25 +58,25 @@ static void tilesMap(void) { static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) { struct Tile *tile = &tiles[tileY * TILE_ROWS + tileX]; - if (!tile->createTime) { + if (!tile->meta.createTime) { memset(tile->cells, ' ', CELLS_SIZE); memset(tile->colors, COLOR_WHITE, CELLS_SIZE); - tile->createTime = time(NULL); + tile->meta.createTime = time(NULL); } return tile; } static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) { struct Tile *tile = tileGet(tileX, tileY); - tile->accessTime = time(NULL); - tile->accessCount++; + tile->meta.accessTime = time(NULL); + tile->meta.accessCount++; return tile; } static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) { struct Tile *tile = tileGet(tileX, tileY); - tile->modifyTime = time(NULL); - tile->modifyCount++; + tile->meta.modifyTime = time(NULL); + tile->meta.modifyCount++; return tile; } @@ -282,15 +282,7 @@ static bool clientMap(const struct Client *client) { for (int32_t x = 0; x < MAP_COLS; ++x) { uint32_t tileY = ((mapY + y) % TILE_ROWS + TILE_ROWS) % TILE_ROWS; uint32_t tileX = ((mapX + x) % TILE_COLS + TILE_COLS) % TILE_COLS; - - const struct Tile *tile = &tiles[tileY * TILE_ROWS + tileX]; - map.tiles[y][x] = (struct MapTile) { - .createTime = tile->createTime, - .modifyTime = tile->modifyTime, - .accessTime = tile->accessTime, - .modifyCount = tile->modifyCount, - .accessCount = tile->accessCount, - }; + map.meta[y][x] = tiles[tileY * TILE_ROWS + tileX].meta; } } diff --git a/torus.h b/torus.h index 26204f3..9c047b9 100644 --- a/torus.h +++ b/torus.h @@ -48,7 +48,7 @@ enum { }; enum { - CELL_ROWS = 25, + CELL_ROWS = 24, CELL_COLS = 80, }; static const size_t CELLS_SIZE = sizeof(char[CELL_ROWS][CELL_COLS]); @@ -56,22 +56,24 @@ static const size_t CELLS_SIZE = sizeof(char[CELL_ROWS][CELL_COLS]); static const uint8_t CELL_INIT_X = CELL_COLS / 2; static const uint8_t CELL_INIT_Y = CELL_ROWS / 2; -struct ALIGNED(4096) Tile { +struct Meta { time_t createTime; time_t modifyTime; - char ALIGNED(16) cells[CELL_ROWS][CELL_COLS]; - uint8_t ALIGNED(16) colors[CELL_ROWS][CELL_COLS]; + time_t accessTime; uint32_t modifyCount; uint32_t accessCount; - time_t accessTime; +}; + +struct ALIGNED(4096) Tile { + char cells[CELL_ROWS][CELL_COLS]; + uint8_t colors[CELL_ROWS][CELL_COLS]; + struct Meta meta; }; static_assert(4096 == sizeof(struct Tile), "struct Tile is page-sized"); -static_assert(16 == offsetof(struct Tile, cells), "stable cells offset"); -static_assert(2016 == offsetof(struct Tile, colors), "stable colors offset"); enum { - TILE_ROWS = 512, - TILE_COLS = 512, + TILE_ROWS = 64, + TILE_COLS = 64, }; static const size_t TILES_SIZE = sizeof(struct Tile[TILE_ROWS][TILE_COLS]); @@ -84,13 +86,7 @@ enum { }; struct Map { - struct MapTile { - time_t createTime; - time_t modifyTime; - time_t accessTime; - uint32_t modifyCount; - uint32_t accessCount; - } tiles[MAP_ROWS][MAP_COLS]; + struct Meta meta[MAP_ROWS][MAP_COLS]; }; struct ServerMessage { -- cgit 1.4.1 ber messageJune McEnroe 2019-11-01Add Hobo Johnson and The Lovemakers Tiny DeskJune McEnroe 2019-10-30Use braces in causal.agency MakefileJune McEnroe 2019-10-30Add scheme "screenshot" to causal.agencyJune McEnroe 2019-10-30Add pounce to causal.agencyJune McEnroe 2019-10-28Mark ' for \aJune McEnroe 2019-10-23Add The Book of the Unnamed MidwifeJune McEnroe 2019-10-22Add ConcreteJune McEnroe Fun. 2019-10-14Set the write variable for nvim man modeJune McEnroe Embarrassing... 2019-10-13Add All Systems RedJune McEnroe 2019-10-10Add The Book of PhoenixJune McEnroe 2019-10-03Add two Kim Petras songsJune McEnroe 2019-10-02Update neovim 0.4.2June McEnroe Finally a release with my man mode fix... Meanwhile neovim itself has probably gotten worse. 2019-10-02Claim to be curl(1) in titleJune McEnroe IMDB serves a page to our dumb User-Agent whose <title> is past the 8K boundary but serves something normal to curl(1). 2019-10-02Add The Red Threads of FortuneJune McEnroe 2019-09-28Add The Black Tides of HeavenJune McEnroe 2019-09-27Fail on HTTP failure status in titleJune McEnroe 2019-09-23Add Trail of LightningJune McEnroe 2019-09-22Revert "Enable cookies in title"June McEnroe This reverts commit 3231fe21d3b389448c9a5ca7b4c91fdd25c9e677. 2019-09-20Enable cookies in titleJune McEnroe Perhaps this will make it less suspicious to Google. Who knows. 2019-09-16Use sensitivity aliases in TF2June McEnroe 2019-09-16Add The Just CityJune McEnroe 2019-09-12Only GET the final redirect locationJune McEnroe 2019-09-12Consume entire bodyJune McEnroe Aborting the request and leaving data around may be causing intermittent errors. Just discard the rest of the data. 2019-09-10Add title -v flagJune McEnroe 2019-09-10Use curl error bufferJune McEnroe 2019-09-10Set Accept-Encoding in titleJune McEnroe Because apparently it's fine for servers to respond with Content-Encoding you didn't ask for, and curl won't decode it if you didn't ask for it. 2019-09-08Set title User-AgentJune McEnroe Some things don't like you if you don't send one. 2019-09-07Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe Allows restarting consumers safely. 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe Oops, didn't see this. 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe