about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c24
-rw-r--r--help.c4
-rw-r--r--server.c24
-rw-r--r--torus.h18
4 files changed, 34 insertions, 36 deletions
diff --git a/client.c b/client.c
index bddf20f..f30bbcc 100644
--- a/client.c
+++ b/client.c
@@ -46,7 +46,7 @@ static void clientMessage(struct ClientMessage msg) {
 static void clientMove(int8_t dx, int8_t dy) {
     struct ClientMessage msg = {
         .type = CLIENT_MOVE,
-        .data.m = { .dx = dx, .dy = dy },
+        .move = { .dx = dx, .dy = dy },
     };
     clientMessage(msg);
 }
@@ -54,7 +54,7 @@ static void clientMove(int8_t dx, int8_t dy) {
 static void clientPut(uint8_t color, char cell) {
     struct ClientMessage msg = {
         .type = CLIENT_PUT,
-        .data.p = { .color = color, .cell = cell },
+        .put = { .color = color, .cell = cell },
     };
     clientMessage(msg);
 }
@@ -62,7 +62,7 @@ static void clientPut(uint8_t color, char cell) {
 static void clientSpawn(uint8_t spawn) {
     struct ClientMessage msg = {
         .type = CLIENT_SPAWN,
-        .data.s.spawn = spawn,
+        .spawn = spawn,
     };
     clientMessage(msg);
 }
@@ -308,25 +308,25 @@ static void readMessage(void) {
         } break;
 
         case SERVER_MOVE: {
-            move(msg.data.m.cellY, msg.data.m.cellX);
+            move(msg.move.cellY, msg.move.cellX);
             refresh();
         } return;
 
         case SERVER_PUT: {
             serverPut(
-                msg.data.p.cellX,
-                msg.data.p.cellY,
-                msg.data.p.color,
-                msg.data.p.cell
+                msg.put.cellX,
+                msg.put.cellY,
+                msg.put.color,
+                msg.put.cell
             );
         } break;
 
         case SERVER_CURSOR: {
             serverCursor(
-                msg.data.c.oldCellX,
-                msg.data.c.oldCellY,
-                msg.data.c.newCellX,
-                msg.data.c.newCellY
+                msg.cursor.oldCellX,
+                msg.cursor.oldCellY,
+                msg.cursor.newCellX,
+                msg.cursor.newCellY
             );
         } break;
 
diff --git a/help.c b/help.c
index f82cd5d..da73527 100644
--- a/help.c
+++ b/help.c
@@ -33,7 +33,7 @@ static void clientMessage(struct ClientMessage msg) {
 static void clientMove(int8_t dx, int8_t dy) {
     struct ClientMessage msg = {
         .type = CLIENT_MOVE,
-        .data.m = { .dx = dx, .dy = dy },
+        .move = { .dx = dx, .dy = dy },
     };
     clientMessage(msg);
 }
@@ -41,7 +41,7 @@ static void clientMove(int8_t dx, int8_t dy) {
 static void clientPut(uint8_t color, char cell) {
     struct ClientMessage msg = {
         .type = CLIENT_PUT,
-        .data.p = { .color = color, .cell = cell },
+        .put = { .color = color, .cell = cell },
     };
     clientMessage(msg);
 }
diff --git a/server.c b/server.c
index 5eca81e..67aa76c 100644
--- a/server.c
+++ b/server.c
@@ -143,7 +143,7 @@ static void clientRemove(struct Client *client) {
 
     struct ServerMessage msg = {
         .type = SERVER_CURSOR,
-        .data.c = {
+        .cursor = {
             .oldCellX = client->cellX, .oldCellY = client->cellY,
             .newCellX = CURSOR_NONE,   .newCellY = CURSOR_NONE,
         },
@@ -157,7 +157,7 @@ static void clientRemove(struct Client *client) {
 static bool clientCursors(const struct Client *client) {
     struct ServerMessage msg = {
         .type = SERVER_CURSOR,
-        .data.c = { .oldCellX = CURSOR_NONE, .oldCellY = CURSOR_NONE },
+        .cursor = { .oldCellX = CURSOR_NONE, .oldCellY = CURSOR_NONE },
     };
 
     for (struct Client *friend = clientHead; friend; friend = friend->next) {
@@ -165,8 +165,8 @@ static bool clientCursors(const struct Client *client) {
         if (friend->tileX != client->tileX) continue;
         if (friend->tileY != client->tileY) continue;
 
-        msg.data.c.newCellX = friend->cellX;
-        msg.data.c.newCellY = friend->cellY;
+        msg.cursor.newCellX = friend->cellX;
+        msg.cursor.newCellY = friend->cellY;
         if (!clientSend(client, msg)) return false;
     }
     return true;
@@ -175,7 +175,7 @@ static bool clientCursors(const struct Client *client) {
 static bool clientUpdate(const struct Client *client, const struct Client *old) {
     struct ServerMessage msg = {
         .type = SERVER_MOVE,
-        .data.m = { .cellX = client->cellX, .cellY = client->cellY },
+        .move = { .cellX = client->cellX, .cellY = client->cellY },
     };
     if (!clientSend(client, msg)) return false;
 
@@ -187,7 +187,7 @@ static bool clientUpdate(const struct Client *client, const struct Client *old)
 
         msg = (struct ServerMessage) {
             .type = SERVER_CURSOR,
-            .data.c = {
+            .cursor = {
                 .oldCellX = old->cellX,  .oldCellY = old->cellY,
                 .newCellX = CURSOR_NONE, .newCellY = CURSOR_NONE,
             },
@@ -196,7 +196,7 @@ static bool clientUpdate(const struct Client *client, const struct Client *old)
 
         msg = (struct ServerMessage) {
             .type = SERVER_CURSOR,
-            .data.c = {
+            .cursor = {
                 .oldCellX = CURSOR_NONE,   .oldCellY = CURSOR_NONE,
                 .newCellX = client->cellX, .newCellY = client->cellY,
             },
@@ -206,7 +206,7 @@ static bool clientUpdate(const struct Client *client, const struct Client *old)
     } else {
         msg = (struct ServerMessage) {
             .type = SERVER_CURSOR,
-            .data.c = {
+            .cursor = {
                 .oldCellX = old->cellX,    .oldCellY = old->cellY,
                 .newCellX = client->cellX, .newCellY = client->cellY,
             },
@@ -275,7 +275,7 @@ static bool clientPut(const struct Client *client, uint8_t color, char cell) {
 
     struct ServerMessage msg = {
         .type = SERVER_PUT,
-        .data.p = {
+        .put = {
             .cellX = client->cellX,
             .cellY = client->cellY,
             .color = color,
@@ -363,11 +363,11 @@ int main() {
 
         bool success = false;
         if (msg.type == CLIENT_MOVE) {
-            success = clientMove(client, msg.data.m.dx, msg.data.m.dy);
+            success = clientMove(client, msg.move.dx, msg.move.dy);
         } else if (msg.type == CLIENT_PUT) {
-            success = clientPut(client, msg.data.p.color, msg.data.p.cell);
+            success = clientPut(client, msg.put.color, msg.put.cell);
         } else if (msg.type == CLIENT_SPAWN) {
-            success = clientSpawn(client, msg.data.s.spawn);
+            success = clientSpawn(client, msg.spawn);
         }
         if (!success) clientRemove(client);
     }
diff --git a/torus.h b/torus.h
index 7597878..92cf934 100644
--- a/torus.h
+++ b/torus.h
@@ -99,20 +99,20 @@ struct ServerMessage {
         struct {
             uint8_t cellX;
             uint8_t cellY;
-        } m;
+        } move;
         struct {
             uint8_t cellX;
             uint8_t cellY;
             uint8_t color;
             char cell;
-        } p;
+        } put;
         struct {
             uint8_t oldCellX;
             uint8_t oldCellY;
             uint8_t newCellX;
             uint8_t newCellY;
-        } c;
-    } data;
+        } cursor;
+    };
 };
 
 static const uint8_t CURSOR_NONE = UINT8_MAX;
@@ -127,13 +127,11 @@ struct ClientMessage {
         struct {
             int8_t dx;
             int8_t dy;
-        } m;
+        } move;
         struct {
             uint8_t color;
             char cell;
-        } p;
-        struct {
-            uint8_t spawn;
-        } s;
-    } data;
+        } put;
+        uint8_t spawn;
+    };
 };