Browse Source

Add some documentation to client.c

Samuel Čavoj 2 years ago
parent
commit
a859b4d3cf
1 changed files with 28 additions and 0 deletions
  1. 28 0
      client.c

+ 28 - 0
client.c

@@ -96,6 +96,13 @@ void send_hello() {
 
 char FIELD[(WIDTH+1)*HEIGHT];
 
+
+/**
+ * Put a character in the local buffer and put it on screen, if it is currently
+ * not toosmall. The cursor position is clobbered.
+ *
+ * x and y are in screen coordinates
+ */
 void put_char_raw(int y, int x, char ch) {
     clamp_yx(y, x);
     if (!toosmall)
@@ -105,19 +112,40 @@ void put_char_raw(int y, int x, char ch) {
     FIELD[y*(WIDTH+1)+x] = ch;
 }
 
+/**
+ * Calls put_char_raw with translated coordinates and prevents the cursor
+ * from moving.
+ * Called on received network events.
+ *
+ * x and y are in buffer coordinates
+ */
 void put_char_net(int y, int x, char ch) {
+    // Translate to screen coordinates
     y = y + ORIGIN_Y + 1;
     x = x + ORIGIN_X + 1;
     int oldy, oldx;
+    // Position of the cursor is stored, as put_char_raw moves it.
     getyx(stdscr, oldy, oldx);
     put_char_raw(y, x, ch);
     move(oldy, oldx);
 }
 
+/**
+ * Calls put_char_raw and sends event over network. Prevents cursor from moving.
+ * Called on locally generated events (user interactions).
+ * Does nothing if toosmall is set, in order to prevent user from doing
+ * what they can't see.
+ *
+ * x and y are in screen coordinates.
+ */
 void put_char_usr(int y, int x, char ch) {
     if (toosmall)
         return;
     put_char_raw(y, x, ch);
+    // Prevent cursor from moving. While this is contraproductive in some cases,
+    // for example drawing vertical lines becomes slightly easier.
+    // A better solution would be to enable to user to select one of several
+    // movement modes.
     move(y, x);
 
     struct packet_update_t packet = {