From 4a270f301bbf2cf07c340e895cb79c226b9fb7fb Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 4 Jan 2019 11:01:49 -0500 Subject: Restore old data format --- torus.h | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'torus.h') diff --git a/torus.h b/torus.h index d469014..a18f515 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 { -- cgit 1.4.1 From 7f49436baea5d29586c7ac10c4586ef59d788e5d Mon Sep 17 00:00:00 2001 From: Curtis 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 'torus.h') diff --git a/client.c b/client.c index d48ba17..c9800cf 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 ad9815b..356387f 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 a18f515..ba552eb 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 mp;id=7769a4f6e94452719e09b8f0c3a1ecca09b55355&follow=1'>Log a message when stopping a service waiting to restart 1.1June McEnroe 2020-11-10Refactor unveil calls so errors can be reported properlyJune McEnroe 2020-10-27Do not increment signalsJune McEnroe 2020-10-23Only look up group if one is namedJune McEnroe 2020-10-23Remove default defines of RUNDIR, ETCDIRJune McEnroe 2020-10-23Set shell scripts executable in buildJune McEnroe 2020-10-20Humanize milliseconds if interval is less than 1sJune McEnroe 2020-10-20Humanize restart intervalJune McEnroe 2020-08-17Document default catsit.conf location on OpenBSD 1.0June McEnroe 2020-08-17Template catsit script with RUNDIRJune McEnroe 2020-08-17Clean up includesJune McEnroe 2020-08-17Log service uptime in statusJune McEnroe