diff options
author | June McEnroe <june@causal.agency> | 2019-01-04 11:01:49 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-01-04 11:01:49 -0500 |
commit | 85ae39946323bee87595842deaf296b2ff457549 (patch) | |
tree | bffeb1ba6c27382bc4a20034b984cdea15d06399 | |
parent | Call cap_enter in client and server (diff) | |
download | torus-85ae39946323bee87595842deaf296b2ff457549.tar.gz torus-85ae39946323bee87595842deaf296b2ff457549.zip |
Restore old data format
-rw-r--r-- | client.c | 2 | ||||
-rw-r--r-- | merge.c | 7 | ||||
-rw-r--r-- | meta.c | 11 | ||||
-rw-r--r-- | server.c | 14 | ||||
-rw-r--r-- | torus.h | 35 |
5 files changed, 44 insertions, 25 deletions
diff --git a/client.c b/client.c index 904ded7..6dabd38 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 ce5dbef..66a7a5e 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 ff80bd1..6e76647 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 a662efd..1547519 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 41c662b..7da2915 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 { |