about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--client.c9
-rw-r--r--server.c11
-rw-r--r--torus.h17
3 files changed, 27 insertions, 10 deletions
diff --git a/client.c b/client.c
index f477602..5a41dbc 100644
--- a/client.c
+++ b/client.c
@@ -65,8 +65,11 @@ static void clientPut(uint8_t color, char cell) {
     clientMessage(&msg);
 }
 
-static void clientSpawn(void) {
-    struct ClientMessage msg = { .type = CLIENT_SPAWN };
+static void clientSpawn(uint8_t spawn) {
+    struct ClientMessage msg = {
+        .type = CLIENT_SPAWN,
+        .data.s.spawn = spawn,
+    };
     clientMessage(&msg);
 }
 
@@ -185,7 +188,7 @@ static void readInput(void) {
         case ESC: mode = MODE_NORMAL; break;
 
         case 'q': endwin(); exit(EX_OK);
-        case 'Q': clientSpawn(); break;
+        case 'Q': clientSpawn(inputColor < SPAWN_COUNT ? inputColor : 0); break;
 
         case 'a': clientMove(1, 0); // fallthrough
         case 'i': insertMode(1, 0); break;
diff --git a/server.c b/server.c
index a22046f..3836f5d 100644
--- a/server.c
+++ b/server.c
@@ -224,10 +224,11 @@ static bool clientUpdate(struct Client *client, struct Client *old) {
     return true;
 }
 
-static bool clientSpawn(struct Client *client) {
+static bool clientSpawn(struct Client *client, uint8_t spawn) {
+    if (spawn >= SPAWN_COUNT) return false;
     struct Client old = *client;
-    client->tileX = TILE_INIT_X;
-    client->tileY = TILE_INIT_Y;
+    client->tileX = SPAWN[spawn].tileX;
+    client->tileY = SPAWN[spawn].tileY;
     client->cellX = CELL_INIT_X;
     client->cellY = CELL_INIT_Y;
     return clientUpdate(client, &old);
@@ -333,7 +334,7 @@ int main() {
             } else if (msg.type == CLIENT_PUT) {
                 success = clientPut(client, msg.data.p.color, msg.data.p.cell);
             } else if (msg.type == CLIENT_SPAWN) {
-                success = clientSpawn(client);
+                success = clientSpawn(client, msg.data.s.spawn);
             }
             if (!success) clientRemove(client);
 
@@ -359,6 +360,6 @@ int main() {
         nevents = kevent(kq, &event, 1, NULL, 0, NULL);
         if (nevents < 0) err(EX_OSERR, "kevent");
 
-        if (!clientSpawn(client)) clientRemove(client);
+        if (!clientSpawn(client, 0)) clientRemove(client);
     }
 }
diff --git a/torus.h b/torus.h
index 85ae3d5..fe5e6b1 100644
--- a/torus.h
+++ b/torus.h
@@ -58,8 +58,18 @@ static_assert(offsetof(struct Tile, colors) == 2016, "stable colors offset");
 #define TILE_COLS (512)
 #define TILES_SIZE (sizeof(struct Tile[TILE_ROWS][TILE_COLS]))
 
-#define TILE_INIT_X (0)
-#define TILE_INIT_Y (0)
+static const struct {
+    uint32_t tileX;
+    uint32_t tileY;
+} SPAWN[] = {
+    { 0, 0 },
+    { TILE_COLS * 3 / 4, TILE_ROWS * 3 / 4 }, // NW
+    { TILE_COLS * 1 / 4, TILE_ROWS * 3 / 4 }, // NE
+    { TILE_COLS * 1 / 4, TILE_ROWS * 1 / 4 }, // SE
+    { TILE_COLS * 3 / 4, TILE_ROWS * 1 / 4 }, // SW
+};
+
+#define SPAWN_COUNT (sizeof(SPAWN) / sizeof(SPAWN[0]))
 
 enum ServerMessageType {
     SERVER_TILE,
@@ -109,5 +119,8 @@ struct ClientMessage {
             uint8_t color;
             char cell;
         } p;
+        struct {
+            uint8_t spawn;
+        } s;
     } data;
 };
2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe