From 4a270f301bbf2cf07c340e895cb79c226b9fb7fb Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 4 Jan 2019 11:01:49 -0500 Subject: Restore old data format --- client.c | 2 +- merge.c | 7 +++++-- meta.c | 11 ++++++----- server.c | 14 +++++++------- torus.h | 35 +++++++++++++++++++++++++---------- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/client.c b/client.c index 6edcd6e..7f4c158 100644 --- a/client.c +++ b/client.c @@ -490,7 +490,7 @@ static void inputNormal(bool keyCode, wchar_t ch) { static void inputHelp(bool keyCode, wchar_t ch) { (void)keyCode; (void)ch; - if (tile.meta.createTime) drawTile(&tile); + if (tileMeta(&tile).createTime) drawTile(&tile); modeNormal(); } diff --git a/merge.c b/merge.c index 997f97f..0e45c84 100644 --- a/merge.c +++ b/merge.c @@ -105,11 +105,14 @@ int main(int argc, char *argv[]) { if (!countA && !countB) break; if (!countA || !countB) errx(EX_DATAERR, "different size inputs"); - const struct Tile *tileC = (tileA.meta.accessTime > tileB.meta.accessTime) + struct Meta metaA = tileMeta(&tileA); + struct Meta metaB = tileMeta(&tileB); + + const struct Tile *tileC = (metaA.accessTime > metaB.accessTime) ? &tileA : &tileB; - if (tileA.meta.modifyTime != tileB.meta.modifyTime) { + if (metaA.modifyTime != metaB.modifyTime) { drawTile(0, &tileA); drawTile(CellRows + 1, &tileB); move(CellRows * 2 + 2, 0); diff --git a/meta.c b/meta.c index 90577d1..5e1736e 100644 --- a/meta.c +++ b/meta.c @@ -28,15 +28,16 @@ int main() { if (ferror(stdin)) err(EX_IOERR, "(stdin)"); if (!count) return EX_OK; + struct Meta meta = tileMeta(&tile); printf( "%d,%d,%jd,%u,%jd,%u,%jd\n", i % TileCols, i / TileCols, - tile.meta.createTime, - tile.meta.modifyCount, - tile.meta.modifyTime, - tile.meta.accessCount, - tile.meta.accessTime + meta.createTime, + meta.modifyCount, + meta.modifyTime, + meta.accessCount, + meta.accessTime ); } } diff --git a/server.c b/server.c index 47441cc..f90f369 100644 --- a/server.c +++ b/server.c @@ -64,25 +64,25 @@ static void tilesMap(const char *path) { static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) { struct Tile *tile = &tiles[tileY * TileRows + tileX]; - if (!tile->meta.createTime) { + if (!tile->createTime) { memset(tile->cells, ' ', CellsSize); memset(tile->colors, ColorWhite, CellsSize); - tile->meta.createTime = time(NULL); + tile->createTime = time(NULL); } return tile; } static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) { struct Tile *tile = tileGet(tileX, tileY); - tile->meta.accessTime = time(NULL); - tile->meta.accessCount++; + tile->accessTime = time(NULL); + tile->accessCount++; return tile; } static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) { struct Tile *tile = tileGet(tileX, tileY); - tile->meta.modifyTime = time(NULL); - tile->meta.modifyCount++; + tile->modifyTime = time(NULL); + tile->modifyCount++; return tile; } @@ -310,7 +310,7 @@ static bool clientMap(const struct Client *client) { for (int32_t x = 0; x < MapCols; ++x) { uint32_t tileY = ((mapY + y) % TileRows + TileRows) % TileRows; uint32_t tileX = ((mapX + x) % TileCols + TileCols) % TileCols; - struct Meta meta = tiles[tileY * TileRows + tileX].meta; + struct Meta meta = tileMeta(&tiles[tileY * TileRows + tileX]); if (meta.createTime) { if (meta.createTime < map.min.createTime) { diff --git a/torus.h b/torus.h index d469014..a18f515 100644 --- a/torus.h +++ b/torus.h @@ -57,7 +57,7 @@ static const wchar_t CP437[256] = ( ); enum { - CellRows = 24, + CellRows = 25, CellCols = 80, }; static const size_t CellsSize = sizeof(uint8_t[CellRows][CellCols]); @@ -74,24 +74,39 @@ struct Meta { }; struct Tile { - alignas(4096) uint8_t cells[CellRows][CellCols]; - uint8_t colors[CellRows][CellCols]; - struct Meta meta; + alignas(4096) + time_t createTime; + time_t modifyTime; + alignas(16) uint8_t cells[CellRows][CellCols]; + alignas(16) uint8_t colors[CellRows][CellCols]; + uint32_t modifyCount; + uint32_t accessCount; + time_t accessTime; }; static_assert(4096 == sizeof(struct Tile), "struct Tile is page-sized"); +static inline struct Meta tileMeta(const struct Tile *tile) { + return (struct Meta) { + .createTime = tile->createTime, + .modifyTime = tile->modifyTime, + .accessTime = tile->accessTime, + .modifyCount = tile->modifyCount, + .accessCount = tile->accessCount, + }; +} + enum { - TileRows = 64, - TileCols = 64, + TileRows = 512, + TileCols = 512, }; static const size_t TilesSize = sizeof(struct Tile[TileRows][TileCols]); -static const uint32_t TileInitX = TileCols / 2; -static const uint32_t TileInitY = TileRows / 2; +static const uint32_t TileInitX = 0; +static const uint32_t TileInitY = 0; enum { - MapRows = 7, - MapCols = 7, + MapRows = 11, + MapCols = 11, }; struct Map { -- cgit 1.4.1