From 85ae39946323bee87595842deaf296b2ff457549 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Jan 2019 11:01:49 -0500 Subject: Restore old data format --- server.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'server.c') 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) { -- cgit 1.4.1 From 8f5c1ba04aeef135228c6b5658c571811de9ce8d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Jan 2019 11:09:42 -0500 Subject: Fix map generation for old metadata discrepancies --- server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server.c') diff --git a/server.c b/server.c index 1547519..37f57ca 100644 --- a/server.c +++ b/server.c @@ -312,7 +312,7 @@ static bool clientMap(const struct Client *client) { uint32_t tileX = ((mapX + x) % TileCols + TileCols) % TileCols; struct Meta meta = tileMeta(&tiles[tileY * TileRows + tileX]); - if (meta.createTime) { + if (meta.createTime > 1) { if (meta.createTime < map.min.createTime) { map.min.createTime = meta.createTime; } -- cgit 1.4.1 From a2b5beb434b38aa8d0856166950053f8cf456f42 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Jan 2019 13:22:21 -0500 Subject: Add teleportation "Spawns" in the old code. --- client.c | 7 +++++++ server.c | 13 +++++++++++++ torus.h | 13 +++++++++++++ 3 files changed, 33 insertions(+) (limited to 'server.c') diff --git a/client.c b/client.c index 9aa052a..867b4de 100644 --- a/client.c +++ b/client.c @@ -271,6 +271,11 @@ static void clientMap(void) { clientMessage(msg); } +static void clientTele(uint8_t port) { + struct ClientMessage msg = { .type = ClientTele, .port = port }; + clientMessage(msg); +} + static struct { enum { ModeNormal, @@ -402,6 +407,8 @@ static void inputNormal(bool keyCode, wchar_t ch) { break; case Esc: modeNormal(); input.shift = 0; break; case 'q': endwin(); exit(EX_OK); + break; case 'Q': clientTele(input.color % ARRAY_LEN(Ports)); + break; case '\\': input.delta = (input.delta == 1 ? 4 : 1); break; case 'h': clientMove(-input.delta, 0); diff --git a/server.c b/server.c index 37f57ca..bd4e980 100644 --- a/server.c +++ b/server.c @@ -359,6 +359,16 @@ static bool clientMap(const struct Client *client) { return true; } +static bool clientTele(struct Client *client, uint8_t port) { + if (port >= ARRAY_LEN(Ports)) return false; + struct Client old = *client; + client->tileX = Ports[port].tileX; + client->tileY = Ports[port].tileY; + client->cellX = CellInitX; + client->cellY = CellInitY; + return clientUpdate(client, &old); +} + int main(int argc, char *argv[]) { int error; @@ -477,6 +487,9 @@ int main(int argc, char *argv[]) { break; case ClientMap: { success = clientMap(client); } + break; case ClientTele: { + success = clientTele(client, msg.port); + } } if (!success) clientRemove(client); } diff --git a/torus.h b/torus.h index 7da2915..b9d842f 100644 --- a/torus.h +++ b/torus.h @@ -104,6 +104,17 @@ static const size_t TilesSize = sizeof(struct Tile[TileRows][TileCols]); static const uint32_t TileInitX = 0; static const uint32_t TileInitY = 0; +static const struct { + uint32_t tileX; + uint32_t tileY; +} Ports[] = { + { TileInitX, TileInitY }, + { TileCols * 3 / 4, TileRows * 3 / 4 }, // NW + { TileCols * 1 / 4, TileRows * 3 / 4 }, // NE + { TileCols * 1 / 4, TileRows * 1 / 4 }, // SE + { TileCols * 3 / 4, TileRows * 1 / 4 }, // SW +}; + enum { MapRows = 11, MapCols = 11, @@ -152,6 +163,7 @@ struct ClientMessage { ClientFlip, ClientPut, ClientMap, + ClientTele, } type; union { struct { @@ -162,5 +174,6 @@ struct ClientMessage { uint8_t color; uint8_t cell; } put; + uint8_t port; }; }; -- cgit 1.4.1