Browse Source

Restore old data format

June 2 weeks ago
parent
commit
4a270f301b
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
5 changed files with 44 additions and 25 deletions
  1. 1
    1
      client.c
  2. 5
    2
      merge.c
  3. 6
    5
      meta.c
  4. 7
    7
      server.c
  5. 25
    10
      torus.h

+ 1
- 1
client.c View File

@@ -490,7 +490,7 @@ static void inputNormal(bool keyCode, wchar_t ch) {
490 490
 static void inputHelp(bool keyCode, wchar_t ch) {
491 491
 	(void)keyCode;
492 492
 	(void)ch;
493
-	if (tile.meta.createTime) drawTile(&tile);
493
+	if (tileMeta(&tile).createTime) drawTile(&tile);
494 494
 	modeNormal();
495 495
 }
496 496
 

+ 5
- 2
merge.c View File

@@ -105,11 +105,14 @@ int main(int argc, char *argv[]) {
105 105
 		if (!countA && !countB) break;
106 106
 		if (!countA || !countB) errx(EX_DATAERR, "different size inputs");
107 107
 
108
-		const struct Tile *tileC = (tileA.meta.accessTime > tileB.meta.accessTime)
108
+		struct Meta metaA = tileMeta(&tileA);
109
+		struct Meta metaB = tileMeta(&tileB);
110
+
111
+		const struct Tile *tileC = (metaA.accessTime > metaB.accessTime)
109 112
 			? &tileA
110 113
 			: &tileB;
111 114
 
112
-		if (tileA.meta.modifyTime != tileB.meta.modifyTime) {
115
+		if (metaA.modifyTime != metaB.modifyTime) {
113 116
 			drawTile(0, &tileA);
114 117
 			drawTile(CellRows + 1, &tileB);
115 118
 			move(CellRows * 2 + 2, 0);

+ 6
- 5
meta.c View File

@@ -28,15 +28,16 @@ int main() {
28 28
 		if (ferror(stdin)) err(EX_IOERR, "(stdin)");
29 29
 		if (!count) return EX_OK;
30 30
 
31
+		struct Meta meta = tileMeta(&tile);
31 32
 		printf(
32 33
 			"%d,%d,%jd,%u,%jd,%u,%jd\n",
33 34
 			i % TileCols,
34 35
 			i / TileCols,
35
-			tile.meta.createTime,
36
-			tile.meta.modifyCount,
37
-			tile.meta.modifyTime,
38
-			tile.meta.accessCount,
39
-			tile.meta.accessTime
36
+			meta.createTime,
37
+			meta.modifyCount,
38
+			meta.modifyTime,
39
+			meta.accessCount,
40
+			meta.accessTime
40 41
 		);
41 42
 	}
42 43
 }

+ 7
- 7
server.c View File

@@ -64,25 +64,25 @@ static void tilesMap(const char *path) {
64 64
 
65 65
 static struct Tile *tileGet(uint32_t tileX, uint32_t tileY) {
66 66
 	struct Tile *tile = &tiles[tileY * TileRows + tileX];
67
-	if (!tile->meta.createTime) {
67
+	if (!tile->createTime) {
68 68
 		memset(tile->cells, ' ', CellsSize);
69 69
 		memset(tile->colors, ColorWhite, CellsSize);
70
-		tile->meta.createTime = time(NULL);
70
+		tile->createTime = time(NULL);
71 71
 	}
72 72
 	return tile;
73 73
 }
74 74
 
75 75
 static struct Tile *tileAccess(uint32_t tileX, uint32_t tileY) {
76 76
 	struct Tile *tile = tileGet(tileX, tileY);
77
-	tile->meta.accessTime = time(NULL);
78
-	tile->meta.accessCount++;
77
+	tile->accessTime = time(NULL);
78
+	tile->accessCount++;
79 79
 	return tile;
80 80
 }
81 81
 
82 82
 static struct Tile *tileModify(uint32_t tileX, uint32_t tileY) {
83 83
 	struct Tile *tile = tileGet(tileX, tileY);
84
-	tile->meta.modifyTime = time(NULL);
85
-	tile->meta.modifyCount++;
84
+	tile->modifyTime = time(NULL);
85
+	tile->modifyCount++;
86 86
 	return tile;
87 87
 }
88 88
 
@@ -310,7 +310,7 @@ static bool clientMap(const struct Client *client) {
310 310
 		for (int32_t x = 0; x < MapCols; ++x) {
311 311
 			uint32_t tileY = ((mapY + y) % TileRows + TileRows) % TileRows;
312 312
 			uint32_t tileX = ((mapX + x) % TileCols + TileCols) % TileCols;
313
-			struct Meta meta = tiles[tileY * TileRows + tileX].meta;
313
+			struct Meta meta = tileMeta(&tiles[tileY * TileRows + tileX]);
314 314
 
315 315
 			if (meta.createTime) {
316 316
 				if (meta.createTime < map.min.createTime) {

+ 25
- 10
torus.h View File

@@ -57,7 +57,7 @@ static const wchar_t CP437[256] = (
57 57
 );
58 58
 
59 59
 enum {
60
-	CellRows = 24,
60
+	CellRows = 25,
61 61
 	CellCols = 80,
62 62
 };
63 63
 static const size_t CellsSize = sizeof(uint8_t[CellRows][CellCols]);
@@ -74,24 +74,39 @@ struct Meta {
74 74
 };
75 75
 
76 76
 struct Tile {
77
-	alignas(4096) uint8_t cells[CellRows][CellCols];
78
-	uint8_t colors[CellRows][CellCols];
79
-	struct Meta meta;
77
+	alignas(4096)
78
+	time_t createTime;
79
+	time_t modifyTime;
80
+	alignas(16) uint8_t cells[CellRows][CellCols];
81
+	alignas(16) uint8_t colors[CellRows][CellCols];
82
+	uint32_t modifyCount;
83
+	uint32_t accessCount;
84
+	time_t accessTime;
80 85
 };
81 86
 static_assert(4096 == sizeof(struct Tile), "struct Tile is page-sized");
82 87
 
88
+static inline struct Meta tileMeta(const struct Tile *tile) {
89
+	return (struct Meta) {
90
+		.createTime = tile->createTime,
91
+		.modifyTime = tile->modifyTime,
92
+		.accessTime = tile->accessTime,
93
+		.modifyCount = tile->modifyCount,
94
+		.accessCount = tile->accessCount,
95
+	};
96
+}
97
+
83 98
 enum {
84
-	TileRows = 64,
85
-	TileCols = 64,
99
+	TileRows = 512,
100
+	TileCols = 512,
86 101
 };
87 102
 static const size_t TilesSize = sizeof(struct Tile[TileRows][TileCols]);
88 103
 
89
-static const uint32_t TileInitX = TileCols / 2;
90
-static const uint32_t TileInitY = TileRows / 2;
104
+static const uint32_t TileInitX = 0;
105
+static const uint32_t TileInitY = 0;
91 106
 
92 107
 enum {
93
-	MapRows = 7,
94
-	MapCols = 7,
108
+	MapRows = 11,
109
+	MapCols = 11,
95 110
 };
96 111
 
97 112
 struct Map {

Loading…
Cancel
Save