summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c18
-rw-r--r--merge.c4
-rw-r--r--meta.c10
-rw-r--r--server.c22
-rw-r--r--torus.h28
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 {