about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-21 23:09:38 -0400
committerJune McEnroe <june@causal.agency>2018-08-21 23:09:38 -0400
commit184e580484e466d2b86815f033fd305f303f0c44 (patch)
tree9fbc960cfbcbda36ccf32bf7aa2b0a9acc54536b
parentReplace client with rudimentary CP437 support (diff)
downloadtorus-184e580484e466d2b86815f033fd305f303f0c44.tar.gz
torus-184e580484e466d2b86815f033fd305f303f0c44.zip
Maintain a tile client-side and support cursors
Diffstat (limited to '')
-rw-r--r--client.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/client.c b/client.c
index 8086d3f..3c34525 100644
--- a/client.c
+++ b/client.c
@@ -98,33 +98,45 @@ static short colorPair(uint8_t color) {
 	return (color & 0x70) >> 1 | (color & 0x07);
 }
 
-static void put(uint8_t cellX, uint8_t cellY, uint8_t color, uint8_t cell) {
+static struct Tile tile;
+
+static void tileDraw(uint8_t cellX, uint8_t cellY, attr_t attr) {
+	uint8_t color = tile.colors[cellY][cellX];
+	uint8_t cell = tile.cells[cellY][cellX];
+
 	cchar_t cch;
 	wchar_t wch[] = { CP437[cell], L'\0' };
-	setcchar(&cch, wch, colorAttr(color), colorPair(color), NULL);
+	setcchar(&cch, wch, attr | colorAttr(color), colorPair(color), NULL);
 	mvadd_wch(cellY, cellX, &cch);
 }
 
 static int client;
 
 static void serverTile(void) {
-	struct Tile tile;
 	ssize_t size = recv(client, &tile, sizeof(tile), 0);
 	if (size < 0) err(EX_IOERR, "recv");
 	if ((size_t)size < sizeof(tile)) errx(EX_PROTOCOL, "truncated tile");
 
 	for (uint8_t cellY = 0; cellY < CELL_ROWS; ++cellY) {
 		for (uint8_t cellX = 0; cellX < CELL_COLS; ++cellX) {
-			put(cellX, cellY, tile.colors[cellY][cellX], tile.cells[cellY][cellX]);
+			tileDraw(cellX, cellY, A_NORMAL);
 		}
 	}
 }
 
 static void serverPut(struct ServerMessage msg) {
-	put(msg.put.cellX, msg.put.cellY, msg.put.color, msg.put.cell);
+	tile.colors[msg.put.cellY][msg.put.cellX] = msg.put.color;
+	tile.cells[msg.put.cellY][msg.put.cellX] = msg.put.cell;
+	tileDraw(msg.put.cellY, msg.put.cellX, A_NORMAL);
 }
 
 static void serverCursor(struct ServerMessage msg) {
+	if (msg.cursor.oldCellX != CURSOR_NONE) {
+		tileDraw(msg.cursor.oldCellX, msg.cursor.oldCellY, A_NORMAL);
+	}
+	if (msg.cursor.newCellX != CURSOR_NONE) {
+		tileDraw(msg.cursor.newCellX, msg.cursor.newCellY, A_REVERSE);
+	}
 }
 
 static void serverMap(void) {