Parcourir la source

Restore old data format

backport
Causal Agent il y a 7 mois
Parent
révision
4a270f301b
Signé par: Curtis McEnroe <june@causal.agency> ID de la clé GPG: CEA2F97ADCFCD77C
5 fichiers modifiés avec 44 ajouts et 25 suppressions
  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 Voir le fichier

@@ -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();
}


+ 5
- 2
merge.c Voir le fichier

@@ -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);

+ 6
- 5
meta.c Voir le fichier

@@ -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
);
}
}

+ 7
- 7
server.c Voir le fichier

@@ -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) {

+ 25
- 10
torus.h Voir le fichier

@@ -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 {

Chargement…
Annuler
Enregistrer