diff options
author | June McEnroe <june@causal.agency> | 2018-08-21 14:00:15 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-08-21 14:00:59 -0400 |
commit | d8c973966760095026218ab09be8d30eb9983e3b (patch) | |
tree | 9dff0fa40a56907d3740a4c2147d24174efeb40a | |
parent | Remove spawns (diff) | |
download | torus-d8c973966760095026218ab09be8d30eb9983e3b.tar.gz torus-d8c973966760095026218ab09be8d30eb9983e3b.zip |
Shrink the torus and rearrange struct Tile
Diffstat (limited to '')
-rw-r--r-- | client.c | 18 | ||||
-rw-r--r-- | merge.c | 4 | ||||
-rw-r--r-- | meta.c | 10 | ||||
-rw-r--r-- | server.c | 22 | ||||
-rw-r--r-- | torus.h | 28 |
5 files changed, 35 insertions, 47 deletions
diff --git a/client.c b/client.c index 1e3421b..cb0107e 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 70c5d4e..e6d2fde 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 c913cf7..990928a 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 f59e9c4..ff13af3 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 93622ad..4109b89 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 { |