From 984fd4a002cd31854730b24ba70c447b165f4d15 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 10 Mar 2007 18:26:59 +0100 Subject: [PATCH] code cosmetics (mostly var/function renaming) --- board.c | 153 +++++++++++++++++++++++------------------------ board.h | 40 +++++-------- client.c | 140 +++++++++++++++++++++---------------------- client.h | 4 +- curses.c | 176 ++++++++++++++++++++++++++++--------------------------- curses.h | 24 ++++---- inet.c | 4 +- netris.h | 10 ++-- server.c | 30 +++++----- 9 files changed, 288 insertions(+), 293 deletions(-) diff --git a/board.c b/board.c index 22b200c..a452f6d 100644 --- a/board.c +++ b/board.c @@ -156,7 +156,7 @@ static const char shapes[7][4][4][4] = { {0000, 0000, 0000, 0000} } } }; -int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func) +int shape_iterate(char s, int scr, int y, int x, ShapeDrawFunc func) { //Draw a certain shape using int i, j, result; char type, rotation; @@ -192,7 +192,7 @@ static unsigned char oldBoard[MAX_SCREENS][MAX_BOARD_HEIGHT][MAX_BOARD_WIDTH]; static unsigned int changed[MAX_SCREENS][MAX_BOARD_HEIGHT]; static int shadowy; -void ClearField(int scr) +void player_empty(int scr) { //Empty the whole field (all blocks BT_none) int y, x; @@ -202,7 +202,7 @@ void ClearField(int scr) } } -unsigned char GetBlock(int scr, int y, int x) +unsigned char block_get(int scr, int y, int x) { //Returns the block on field at position (x,y) if (y < 0 || x < 0 || x >= Players[scr].boardWidth) return BT_wall; @@ -212,7 +212,7 @@ unsigned char GetBlock(int scr, int y, int x) return board[scr][y][x]; } -static void SetBlock(int scr, int y, int x, unsigned char type) +static void block_set(int scr, int y, int x, unsigned char type) { if (y >= 0 && y < Players[scr].boardHeight && x >= 0 && x < Players[scr].boardWidth) { @@ -221,7 +221,7 @@ static void SetBlock(int scr, int y, int x, unsigned char type) } } -int RefreshBoard(int scr) +int player_draw(int scr) { //draw changes to screen int y, x, any = 0; unsigned int c; @@ -230,7 +230,7 @@ int RefreshBoard(int scr) if ((c = changed[scr][y])) { // line changed for (x = 0; c; (c >>= 1), x++) if (c & 1 && board[scr][y][x] != oldBoard[scr][y][x]) { - PlotBlock(scr, y, x, board[scr][y][x]); + block_draw_window(scr, y, x, board[scr][y][x]); oldBoard[scr][y][x] = board[scr][y][x]; } changed[scr][y] = 0; // reset @@ -239,151 +239,154 @@ int RefreshBoard(int scr) return any; } -int GlanceFunc(int scr, int y, int x, unsigned char type) +int block_iter_set_status(int scr, int y, int x, unsigned char type) { - PlotBlockXY(y, x, type); + block_draw_status(y, x, type); return 0; } -int ShadowFunc(int scr, int y, int x, unsigned char type) +static int block_iter_shadow(int scr, int y, int x, unsigned char type) { //draw shadow - SetBlock(scr, y, x, BT_shadow); + block_set(scr, y, x, BT_shadow); return 0; } -int PlotFunc(int scr, int y, int x, unsigned char type) +static int block_iter_set(int scr, int y, int x, unsigned char type) { - SetBlock(scr, y, x, type); + block_set(scr, y, x, type); return 0; } -void PlotShape(char shape, int scr, int y, int x, int shadow) + +void shape_draw(char shape, int scr, int y, int x, int shadow) { //put shape on field if (shadow) { for (shadowy = y - 1; shadowy >= 0; shadowy--) - if (!ShapeFits(shape, scr, shadowy, x)) + if (!shape_get(shape, scr, shadowy, x)) break; - ShapeIterate(shape, scr, shadowy + 1, x, ShadowFunc); + shape_iterate(shape, scr, shadowy + 1, x, block_iter_shadow); } //draw shadow - ShapeIterate(shape, scr, y, x, PlotFunc); + shape_iterate(shape, scr, y, x, block_iter_set); } -int EraseFunc(int scr, int y, int x, unsigned char type) +static int block_iter_erase(int scr, int y, int x, unsigned char type) { - SetBlock(scr, y, x, BT_none); + block_set(scr, y, x, BT_none); return 0; } -void EraseShape(char shape, int scr, int y, int x, int shadow) + +void shape_erase(char shape, int scr, int y, int x, int shadow) { //remove block from field - ShapeIterate(shape, scr, y, x, EraseFunc); + shape_iterate(shape, scr, y, x, block_iter_erase); if (shadow && scr == me) // draw shadow - ShapeIterate(shape, scr, shadowy + 1, x, EraseFunc); + shape_iterate(shape, scr, shadowy + 1, x, block_iter_erase); } -int CollisionFunc(int scr, int y, int x, unsigned char type) +static int block_iter_get(int scr, int y, int x, unsigned char type) { - return GetBlock(scr, y, x) > BT_none; + return block_get(scr, y, x) > BT_none; } -int ShapeFits(char shape, int scr, int y, int x) + +int shape_get(char shape, int scr, int y, int x) { //check if there's nothing in the way - return !ShapeIterate(shape, scr, y, x, CollisionFunc); + return !shape_iterate(shape, scr, y, x, block_iter_get); } -int VisibleFunc(int scr, int y, int x, unsigned char type) +static int block_iter_visible(int scr, int y, int x, unsigned char type) { return (y >= 0 && y < Players[scr].boardVisible && x >= 0 && x < Players[scr].boardWidth); } -int ShapeVisible(char shape, int scr, int y, int x) +int shape_visible(char shape, int scr, int y, int x) { - return ShapeIterate(shape, scr, y, x, VisibleFunc); + return shape_iterate(shape, scr, y, x, block_iter_visible); } -int MovePiece(int scr, int deltaY, int deltaX) +int player_move(int scr, int deltaY, int deltaX) { int result; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); - result = ShapeFits(Players[scr].curShape, scr, Players[scr].curY + deltaY, + result = shape_get(Players[scr].curShape, scr, Players[scr].curY + deltaY, Players[scr].curX + deltaX); if (result) { Players[scr].curY += deltaY; Players[scr].curX += deltaX; } - PlotShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); return result; } -int RotatePiece(int scr, int dir) +int player_rotate(int scr, int dir) { char newshape; int result; - EraseShape(Players[scr].curShape, scr, Players[scr].curY, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); /* (inc|dec)rement only 3 least significant bits which indicate rotation */ newshape = (Players[scr].curShape & 252) + (((Players[scr].curShape & 3) + dir) & 3); - result = ShapeFits(newshape, scr, Players[scr].curY, Players[scr].curX); + result = shape_get(newshape, scr, Players[scr].curY, Players[scr].curX); if (!result) { // move if it doesn't fit anymore short int slideX; for (slideX = 0; slideX < 2; slideX = -slideX) { // slide left and right if (slideX >= 0) slideX++; // slide more - if (result = ShapeFits(newshape, scr, Players[scr].curY, + if (result = shape_get(newshape, scr, Players[scr].curY, Players[scr].curX+slideX)) break; } if (result) Players[scr].curX += slideX; } if (result) Players[scr].curShape = newshape; - PlotShape(Players[scr].curShape, scr, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); return result; } -int DropPiece(int scr) +int player_drop(int scr) { int count = 0; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); - while (ShapeFits(Players[scr].curShape, scr, + while (shape_get(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) { Players[scr].curY--; count++; } - PlotShape(Players[scr].curShape, scr, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 0); return count; } -int BlockFree(int scr, int x, int y, unsigned char z) +static int block_free(int scr, int x, int y, unsigned char z) { //Check if blocks are empty below block (x,y) and sticking to (x,y) mask unsigned char curblock; if (y == 0) return 0; // at bottom - curblock = GetBlock(scr, y, x) & z; - if (curblock & 0x10 && !BlockFree(scr, x, y-1, z & 0xD0)) return 0; - if (curblock & 0x20 && !BlockFree(scr, x, y+1, z & 0xE0)) return 0; - if (curblock & 0x40 && !BlockFree(scr, x+1, y, z & 0x70)) return 0; - if (curblock & 0x80 && !BlockFree(scr, x-1, y, z & 0xB0)) return 0; - if ((z = GetBlock(scr, y-1, x)) & 0x20) return 1; // stuck to block below + curblock = block_get(scr, y, x) & z; + if (curblock & 0x10 && !block_free(scr, x, y-1, z & 0xD0)) return 0; + if (curblock & 0x20 && !block_free(scr, x, y+1, z & 0xE0)) return 0; + if (curblock & 0x40 && !block_free(scr, x+1, y, z & 0x70)) return 0; + if (curblock & 0x80 && !block_free(scr, x-1, y, z & 0xB0)) return 0; + if ((z = block_get(scr, y-1, x)) & 0x20) return 1; // stuck to block below if (z > BT_none) return 0; // some other piece below return 1; // nothing below } -int BlockFall(int scr, int x, int y, unsigned char z) +static int block_down(int scr, int x, int y, unsigned char z) { //Drop down block (x,y) and those sticking to it mask - if (GetBlock(scr, y, x) & z & 0x10) BlockFall(scr, x, y-1, z & 0xD0); - if (GetBlock(scr, y, x) & z & 0x20) BlockFall(scr, x, y+1, z & 0xE0); - if (GetBlock(scr, y, x) & z & 0x40) BlockFall(scr, x+1, y, z & 0x70); - if (GetBlock(scr, y, x) & z & 0x80) BlockFall(scr, x-1, y, z & 0xB0); - SetBlock(scr, y-1, x, GetBlock(scr, y, x)); - SetBlock(scr, y, x, BT_none); + if (block_get(scr, y, x) & z & 0x10) block_down(scr, x, y-1, z & 0xD0); + if (block_get(scr, y, x) & z & 0x20) block_down(scr, x, y+1, z & 0xE0); + if (block_get(scr, y, x) & z & 0x40) block_down(scr, x+1, y, z & 0x70); + if (block_get(scr, y, x) & z & 0x80) block_down(scr, x-1, y, z & 0xB0); + block_set(scr, y-1, x, block_get(scr, y, x)); + block_set(scr, y, x, BT_none); } -int CheckFall(int scr) +int player_down(int scr) { //Drop any free blocks on field int xloop, x, x2, y, fallen = 0; unsigned char z; @@ -391,10 +394,10 @@ int CheckFall(int scr) if (!Game.gravity) return 0; for (y = Players[scr].boardHeight - 1; y > 0; y--) for (x = 0; x < Players[scr].boardWidth; x++) { - if ((z = GetBlock(scr, y, x)) > BT_none && (z & 0xA0) == 0) { + if ((z = block_get(scr, y, x)) > BT_none && (z & 0xA0) == 0) { // block present which doesn't stick left/up => topleft block - if (BlockFree(scr, x, y, 0xF0)) { - BlockFall(scr, x, y, 0xF0); // move blocks down + if (block_free(scr, x, y, 0xF0)) { + block_down(scr, x, y, 0xF0); // move blocks down fallen++; } } //block present @@ -402,67 +405,67 @@ int CheckFall(int scr) return fallen; } -int LineIsFull(int scr, int y) +static int player_linecheck(int scr, int y) { //return 0 if any blocks present on line int x; for (x = 0; x < Players[scr].boardWidth; x++) - if (GetBlock(scr, y, x) <= BT_none) + if (block_get(scr, y, x) <= BT_none) return 0; return 1; } -void CopyLine(int scr, int from, int to) +static void player_linecopy(int scr, int from, int to) { //move blocks on line to line int x; if (from != to) for (x = 0; x < Players[scr].boardWidth; ++x) - SetBlock(scr, to, x, GetBlock(scr, from, x)); + block_set(scr, to, x, block_get(scr, from, x)); } -int ClearFullLines(int scr) +int player_lineclear(int scr) { //remove full lines, return lines cleared int from, to, x, linescleared = 0; do { from = to = 0; while (to < Players[scr].boardHeight) { - while (LineIsFull(scr, from)) { + while (player_linecheck(scr, from)) { from++; // skip for (x = 0; x 1) - SetBlock(scr, from-2, x, GetBlock(scr, from-2, x) & 0xDF); + block_set(scr, from-2, x, block_get(scr, from-2, x) & 0xDF); } } - CopyLine(scr, from++, to++); + player_linecopy(scr, from++, to++); } linescleared += from - to; - } while (CheckFall(scr)); + } while (player_down(scr)); return linescleared; } -void InsertJunk(int scr, int color, int count, int column) +void player_lineadd(int scr, int color, int count, int column) { //add junklines with hole at to by team int y, x; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); for (y = Players[scr].boardHeight - count - 1; y >= 0; --y) - CopyLine(scr, y, y + count); + player_linecopy(scr, y, y + count); for (y = 0; y < count; ++y) for (x = 0; x < Players[scr].boardWidth; ++x) - SetBlock(scr, y, x, x == column ? BT_none : color + 1 + block_set(scr, y, x, x == column ? BT_none : color + 1 + 0x40 * (x != column-1 && x < Players[scr].boardWidth-1) + 0x80 * (x != column+1 && x > 0)); Players[scr].curY += count; // move piece up.. for (y = 0; y < count; ++y) - if (ShapeFits(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) + if (shape_get(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) Players[scr].curY--; // ...and down again as far as possible else break; - PlotShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); } diff --git a/board.h b/board.h index 09212ff..5bd6a5d 100644 --- a/board.h +++ b/board.h @@ -4,32 +4,22 @@ extern float stdOptions[7]; typedef int (*ShapeDrawFunc)(int scr, int y, int x, unsigned char type); -extern int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func); +extern int shape_iterate(char s, int scr, int y, int x, ShapeDrawFunc func); extern char ChooseOption(float options[7]); -extern void ClearField(int scr); -extern unsigned char GetBlock(int scr, int y, int x); -extern int RefreshBoard(int scr); -extern int GlanceFunc(int scr, int y, int x, unsigned char type); -extern int ShadowFunc(int scr, int y, int x, unsigned char type); -extern int PlotFunc(int scr, int y, int x, unsigned char type); -extern void PlotShape(char shape, int scr, int y, int x, int shadow); -extern int EraseFunc(int scr, int y, int x, unsigned char type); -extern void EraseShape(char shape, int scr, int y, int x, int shadow); -extern int CollisionFunc(int scr, int y, int x, unsigned char type); -extern int ShapeFits(char shape, int scr, int y, int x); -extern int VisibleFunc(int scr, int y, int x, unsigned char type); -extern int ShapeVisible(char shape, int scr, int y, int x); -extern int MovePiece(int scr, int deltaY, int deltaX); -extern int RotatePiece(int scr, int dir); -extern int DropPiece(int scr); -extern int BlockFree(int scr, int x, int y, unsigned char z); -extern int BlockFall(int scr, int x, int y, unsigned char z); -extern int CheckFall(int scr); -extern int LineIsFull(int scr, int y); -extern void CopyLine(int scr, int from, int to); -extern int ClearFullLines(int scr); -extern void FreezePiece(int scr); -extern void InsertJunk(int scr, int color, int count, int column); +extern void player_empty(int scr); +extern unsigned char block_get(int scr, int y, int x); +extern int player_draw(int scr); +extern int block_iter_set_status(int scr, int y, int x, unsigned char type); +extern void shape_draw(char shape, int scr, int y, int x, int shadow); +extern void shape_erase(char shape, int scr, int y, int x, int shadow); +extern int shape_get(char shape, int scr, int y, int x); +extern int shape_visible(char shape, int scr, int y, int x); +extern int player_move(int scr, int deltaY, int deltaX); +extern int player_rotate(int scr, int dir); +extern int player_drop(int scr); +extern int player_down(int scr); +extern int player_lineclear(int scr); +extern void player_lineadd(int scr, int color, int count, int column); #endif //__BOARD_H diff --git a/client.c b/client.c index 8f2b00b..648db94 100644 --- a/client.c +++ b/client.c @@ -59,7 +59,7 @@ static char *keyNames[KT_numKeys+1] = { "Faster", "Pause", "Redraw", "Say", "Quit", NULL }; -_Sets Sets = {7, 0, 1, 1, 1}; +sets_t Sets = {7, 0, 1, 1, 1}; static char keyTable[KT_numKeys+1]; @@ -217,7 +217,7 @@ static void handle_conffile(char *filename) } //defaults } -static int game_piece(int scr, char shape) +static int player_piece(int scr, char shape) { Players[scr].score.pieces++; { @@ -226,13 +226,13 @@ static int game_piece(int scr, char shape) } Players[scr].curY = Players[scr].boardVisible + 4; Players[scr].curX = Players[scr].boardWidth / 2 - 2; - while (!ShapeVisible(Players[scr].curShape, scr, + while (!shape_visible(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX)) Players[scr].curY--; - if (!ShapeFits(Players[scr].curShape, scr, + if (!shape_get(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX)) return 0; - PlotShape(Players[scr].curShape, scr, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); return 1; } @@ -264,9 +264,9 @@ static void game_reset(void) Players[i].score.score = Players[i].score.lines = Players[i].score.adds = 0; Players[i].score.pieces = -1; - ClearField(i); + player_empty(i); } //reset all players - InitFields(); + screen_setup(); } static void game_clear(int scr) @@ -278,7 +278,7 @@ static void game_clear(int scr) int linevaluesq[] = { 20, 50, 100, 200, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 6000, 7500 }; - if ((linesCleared = ClearFullLines(scr)) > 0) { + if ((linesCleared = player_lineclear(scr)) > 0) { if (Game.type == GT_onePlayer) if ((Players[scr].score.lines / 10) < ((Players[scr].score.lines+linesCleared)/10)) { @@ -301,12 +301,12 @@ static void game_clear(int scr) junkLines = linesCleared - (Game.gravity ? 1 : linesCleared < 4); data[0] = junkLines; SendPacket(me, NP_giveJunk, sizeof(data), data); - Message("\\%dYou send %d lines", + msg_add("\\%dYou send %d lines", Players[me].team > 7 ? 7 : Players[me].team, junkLines); } //send junk to others } //multiplayer else { - Message("\\%dYou cleared %d lines", + msg_add("\\%dYou cleared %d lines", Players[me].team > 7 ? 7 : Players[me].team, linesCleared); } //singleplayer } //IT'S YOU @@ -324,7 +324,7 @@ static void game_loop(void) { switch (cmd) { case CT_quit: - ShowPause(me); + window_msg_status(me); refresh(); gameStatus = 0; return; @@ -332,15 +332,15 @@ static void game_loop(void) if (Players[me].alive <= 0) return; Players[me].flags ^= SCF_paused; if (Game.started > 1) - Message(Players[me].flags & SCF_paused + msg_add(Players[me].flags & SCF_paused ? "You paused the game" : "You unpaused the game"); else - Message(Players[me].flags & SCF_paused + msg_add(Players[me].flags & SCF_paused ? "You are not ready" : "You are ready"); game_setpaused(); if (Game.type == GT_classicTwo) SendPacket(me, NP_pause, 0, NULL); - ShowPause(me); + window_msg_status(me); changed = 1; return; } @@ -362,7 +362,7 @@ static void game_loop(void) return handle_cmd(i, cmdend + 1); } } - Message("Unknown command /%s", cmd); + msg_add("Unknown command /%s", cmd); } void handle_str(char *str) @@ -375,7 +375,7 @@ static void game_loop(void) memmove(chatText, chatText + 1, strlen(chatText)); } - Message("<\\%d%s\\7> %s", + msg_add("<\\%d%s\\7> %s", Players[me].team > 7 ? 7 : Players[me].team, Players[me].name, chatText); if (Game.type == GT_classicTwo) @@ -394,7 +394,7 @@ static void game_loop(void) handle_str(chatText); memset(chatText, 0, sizeof(chatText)); } //say it - else Messagetype(27, -1, NULL); //escape + else msg_add_char(27, -1, NULL); //escape return; } else if (key == 27) //escape @@ -403,7 +403,7 @@ static void game_loop(void) chatText[strlen(chatText) - 1] = 0; else if (strlen(chatText) < MSG_WIDTH-1) //text chatText[strlen(chatText)] = key; - Messagetype(key, strlen(chatText) - 1, chatText); + msg_add_char(key, strlen(chatText) - 1, chatText); return; } //key in chat mode @@ -415,13 +415,13 @@ static void game_loop(void) switch (key) { case KT_redraw: clear(); - InitFields(); + screen_setup(); // ScheduleFullRedraw(); refresh(); return; case KT_say: chatMode = 1; - Messagetype(key, strlen(chatText) - 1, chatText); + msg_add_char(key, strlen(chatText) - 1, chatText); return; case KT_quit: handle_cmd(CT_quit, NULL); @@ -435,20 +435,20 @@ static void game_loop(void) // actions only available while actually playing switch (key) { case KT_left: - if (MovePiece(me, 0, -1) && spied) SendPacket(me, NP_left, 0, NULL); + if (player_move(me, 0, -1) && spied) SendPacket(me, NP_left, 0, NULL); break; case KT_right: - if (MovePiece(me, 0, 1) && spied) SendPacket(me, NP_right, 0, NULL); + if (player_move(me, 0, 1) && spied) SendPacket(me, NP_right, 0, NULL); break; case KT_rotleft: - if (RotatePiece(me, -1) && spied) SendPacket(me, NP_rotleft, 0, NULL); + if (player_rotate(me, -1) && spied) SendPacket(me, NP_rotleft, 0, NULL); break; case KT_rotright: - if (RotatePiece(me, 1) && spied) SendPacket(me, NP_rotright, 0, NULL); + if (player_rotate(me, 1) && spied) SendPacket(me, NP_rotright, 0, NULL); break; case KT_down: SetITimer(Game.speed, Game.speed); - if (MovePiece(me, -1, 0)) { + if (player_move(me, -1, 0)) { if (spied) SendPacket(me, NP_down, 0, NULL); } //move one down else @@ -456,14 +456,14 @@ static void game_loop(void) break; case KT_dropsoft: SetITimer(Game.speed, Game.speed); - if (DropPiece(me)) { + if (player_drop(me)) { if (spied) SendPacket(me, NP_drop, 0, NULL); } else gameStatus = 1; //dropped break; case KT_drop: SetITimer(Game.speed, Game.speed); - if (DropPiece(me)) { + if (player_drop(me)) { if (spied) SendPacket(me, NP_drop, 0, NULL); } gameStatus = 1; // drop @@ -474,7 +474,7 @@ static void game_loop(void) Game.speed = SPEEDMINIMUM; SetITimer(Game.speed, SetITimer(0, 0)); Players[me].score.level++; - ShowScore(me, Players[me].score); + status_draw(me, Players[me].score); changed = 1; break; } @@ -491,26 +491,26 @@ static void game_loop(void) { memcpy(&Players[net.uid].nextShape, net.data, sizeof(Players[0].nextShape)); - game_piece(net.uid, Players[net.uid].curShape); + player_piece(net.uid, Players[net.uid].curShape); break; } case NP_down: - MovePiece(net.uid, -1, 0); + player_move(net.uid, -1, 0); break; case NP_left: - MovePiece(net.uid, 0, -1); + player_move(net.uid, 0, -1); break; case NP_right: - MovePiece(net.uid, 0, 1); + player_move(net.uid, 0, 1); break; case NP_rotleft: - RotatePiece(net.uid, -1); + player_rotate(net.uid, -1); break; case NP_rotright: - RotatePiece(net.uid, 1); + player_rotate(net.uid, 1); break; case NP_drop: - DropPiece(net.uid); + player_drop(net.uid); break; case NP_clear: game_clear(net.uid); @@ -520,7 +520,7 @@ static void game_loop(void) netint4 data[3]; memcpy(data, net.data, sizeof(data)); - InsertJunk(net.uid, Players[data[2]].team, data[0], data[1]); + player_lineadd(net.uid, Players[data[2]].team, data[0], data[1]); break; } //player added junklines case NP_giveJunk: @@ -531,11 +531,11 @@ static void game_loop(void) if (Players[me].alive <= 0) break; memcpy(data, net.data, sizeof(data[0])); column = Random(0, Players[me].boardWidth); - Message("\\%d%s sends %d lines", + msg_add("\\%d%s sends %d lines", Players[net.uid].team > 7 ? 7 : Players[net.uid].team, Players[net.uid].name, data[0]); lastadd = net.uid; - InsertJunk(me, Players[net.uid].team, data[0], column); + player_lineadd(me, Players[net.uid].team, data[0], column); if (spied) { data[1] = column; data[2] = net.uid; @@ -545,7 +545,7 @@ static void game_loop(void) } //receive junklines case NP_msg: { - Message("<\\%d%s\\7> %s", + msg_add("<\\%d%s\\7> %s", Players[net.uid].team > 7 ? 7 : Players[net.uid].team, Players[net.uid].name, net.data, net.type); break; @@ -556,9 +556,9 @@ static void game_loop(void) Game.started = 2; paused = 0; - Message("The game has started"); + msg_add("The game has started"); for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive > 0) - ShowPause(i); + window_msg_status(i); break; } //start game case NP_stop: @@ -568,21 +568,21 @@ static void game_loop(void) float timer; int i; - Message("The game has ended"); + msg_add("The game has ended"); timer = CurTimeval() / 1e6; if (timer > 5) { for (i = MAX_SCREENS-1; i > 0; i--) if (Players[i].alive >= 0) { - Message("\\%d%10s%6.1fp%5.1fa", + msg_add("\\%d%10s%6.1fp%5.1fa", Players[i].team > 7 ? 7 : Players[i].team, Players[i].name, Players[i].score.pieces / timer * 60, Players[i].score.adds / timer * 60); if (Players[i].alive > 0) winner = i; } //show player stats if (winner) - Message("%s won after %0.0f'%02d\"", + msg_add("%s won after %0.0f'%02d\"", Players[winner].name, timer / 60, (int)timer % 60); } //show game stats - Message(NULL); + msg_add(NULL); } //game was playing Game.started = 0; memcpy(&Game.seed, net.data, net.size); @@ -595,7 +595,7 @@ static void game_loop(void) } //reset players } game_reset(); //reset everything - ShowTime(); //redraw timer while unpaused + status_tick(); //redraw timer while unpaused game_setpaused(); //pause oldPaused = 0; //reset pause changed = 1; @@ -606,18 +606,18 @@ static void game_loop(void) { if (net.uid>maxPlayer) maxPlayer = net.uid; memcpy(&Players[net.uid], net.data, net.size); - ClearField(net.uid); - InitFields(); + player_empty(net.uid); + screen_setup(); if (Players[net.uid].team > 7) - Message("%s joined the game", Players[net.uid].name); + msg_add("%s joined the game", Players[net.uid].name); else - Message("%s joined %s team", Players[net.uid].name, + msg_add("%s joined %s team", Players[net.uid].name, teamname[Players[net.uid].team]); if (Players[net.uid].flags & SCF_paused) { game_setpaused(); } //player has paused -// DrawField(net.uid); -// ShowPause(net.uid); +// window_draw(net.uid); +// window_msg_status(net.uid); changed = 1; break; } //player joined @@ -632,9 +632,9 @@ static void game_loop(void) else strcpy(s, Players[net.uid].flags&SCF_paused ? "is not ready" : "is ready"); - Message("%s %s", Players[net.uid].name, s); + msg_add("%s %s", Players[net.uid].name, s); game_setpaused(); - ShowPause(net.uid); + window_msg_status(net.uid); changed = 1; break; } //(un)pause @@ -643,9 +643,9 @@ static void game_loop(void) game_setpaused(); oldPaused = 0; Players[net.uid].alive = -1; - Message("%s left", Players[net.uid].name); + msg_add("%s left", Players[net.uid].name); game_setpaused(); - ShowPause(net.uid); + window_msg_status(net.uid); changed = 1; break; case NP_argghhh: @@ -654,17 +654,17 @@ static void game_loop(void) memcpy(&i, net.data, sizeof(i)); Players[net.uid].alive = 0; if (i == me) - Message("\\%dYou fragged %s", + msg_add("\\%dYou fragged %s", Players[me].team > 7 ? 7 : Players[me].team, Players[net.uid].name); else if (i == net.uid) - Message("\\%d%s died", + msg_add("\\%d%s died", Players[i].team > 7 ? 7 : Players[i].team, Players[i].name); else - Message("\\%d%s fragged %s", + msg_add("\\%d%s fragged %s", Players[i].team > 7 ? 7 : Players[i].team, Players[i].name, Players[net.uid].name); game_setpaused(); - ShowPause(net.uid); + window_msg_status(net.uid); changed = 1; break; } //G/O @@ -681,22 +681,22 @@ static void game_loop(void) while (gameStatus) { gameStatus = 2; if (Players[me].alive > 0) { - if (!game_piece(me, ChooseOption(stdOptions))) { + if (!player_piece(me, ChooseOption(stdOptions))) { netint4 data[4]; Players[me].alive = 0; - if (lastadd == me) Message("\\%dYou died", + if (lastadd == me) msg_add("\\%dYou died", Players[me].team > 7 ? 7 : Players[me].team); - else Message("\\%d%s fragged you", + else msg_add("\\%d%s fragged you", Players[lastadd].team > 7 ? 7 : Players[lastadd].team, Players[lastadd].name); if (Game.type == GT_classicTwo) SendPacket(me, NP_argghhh, sizeof(lastadd), &lastadd); - ShowPause(me); + window_msg_status(me); changed = 1; } //die else { - ShowScore(me, Players[me].score); + status_draw(me, Players[me].score); if (spied) { SendPacket(me, NP_newPiece, sizeof(Players[me].curShape), &Players[me].curShape); } //send new piece @@ -705,9 +705,9 @@ static void game_loop(void) while (gameStatus == 2) { for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive > 0 && window[i].shown) - changed |= RefreshBoard(i); + changed |= player_draw(i); if (changed) { - if (!paused) ShowTime(); + if (!paused) status_tick(); refresh(); changed = 0; } //screen update @@ -720,7 +720,7 @@ static void game_loop(void) switch (WaitMyEvent(&event, EM_any)) { case E_alarm: if (!paused && Players[me].alive > 0) - if (!MovePiece(me, -1, 0)) //move down + if (!player_move(me, -1, 0)) //move down gameStatus = 1; //new piece else if (spied) SendPacket(me, NP_down, 0, NULL); @@ -774,7 +774,7 @@ int main(int argc, char **argv) Players[i].boardHeight = MAX_BOARD_HEIGHT; Players[i].boardVisible = 20; strcpy(Players[i].name, "???"); - ClearField(i); + player_empty(i); } if (!(userName = getenv("LOGNAME")) || !userName[0]) if (!(userName = getenv("USER")) || !userName[0]) @@ -812,7 +812,7 @@ int main(int argc, char **argv) Game.seed = time(0); Game.started = 2; me = 1; - memcpy(&Players[me], &Players[0], sizeof(_Player)); + memcpy(&Players[me], &Players[0], sizeof(player_t)); Players[me].team = 7; game_loop(); } //singleplay diff --git a/client.h b/client.h index 2da42ed..32cdb05 100644 --- a/client.h +++ b/client.h @@ -7,8 +7,8 @@ typedef struct { short standout; short color; short ascii; -} _Sets; -extern _Sets Sets; +} sets_t; +extern sets_t Sets; #endif //__CLIENT_H diff --git a/curses.c b/curses.c index 98465b6..0e841ef 100644 --- a/curses.c +++ b/curses.c @@ -220,7 +220,7 @@ static void DrawTitle(void) standend(); //normal text } -void DrawBox(int x1, int y1, int x2, int y2) +static void window_border(int x1, int y1, int x2, int y2) { //draw grid int y, x; @@ -240,38 +240,38 @@ void DrawBox(int x1, int y1, int x2, int y2) addch(Sets.ascii ? '+' : ACS_LRCORNER); } -void DrawField(int scr) -{ //draw field for player scr - if (!window[scr].shown) return; - DrawBox(window[scr].posx - 1, window[scr].posy - Players[scr].boardVisible, - window[scr].posx + window[scr].size * Players[scr].boardWidth, window[scr].posy + 1); +void window_draw(int player) +{ //draw field for player + if (!window[player].shown) return; + window_border(window[player].posx - 1, window[player].posy - Players[player].boardVisible, + window[player].posx + window[player].size * Players[player].boardWidth, window[player].posy + 1); { - char s[window[scr].size * Players[scr].boardWidth + 1]; + char s[window[player].size * Players[player].boardWidth + 1]; - if (Players[scr].host && Players[scr].host[0]) + if (Players[player].host && Players[player].host[0]) snprintf(s, sizeof(s), " %s <%s> ", - Players[scr].name, Players[scr].host); - else snprintf(s, sizeof(s), " %s ", Players[scr].name); + Players[player].name, Players[player].host); + else snprintf(s, sizeof(s), " %s ", Players[player].name); s[sizeof(s)] = 0; - if (haveColor && Players[scr].team > 0 && Players[scr].team <= 7) - attrset(A_REVERSE | COLOR_PAIR(Players[scr].team + 1)); - mvaddstr(1, window[scr].posx, s); + if (haveColor && Players[player].team > 0 && Players[player].team <= 7) + attrset(A_REVERSE | COLOR_PAIR(Players[player].team + 1)); + mvaddstr(1, window[player].posx, s); if (haveColor) standend(); } //display playername/host { int x, y; - for (y = 0; y <= Players[scr].boardVisible; y++) - for (x = 0; x <= Players[scr].boardWidth; x++) - PlotBlock(scr, y, x, GetBlock(scr, y, x)); + for (y = 0; y <= Players[player].boardVisible; y++) + for (x = 0; x <= Players[player].boardWidth; x++) + block_draw_window(player, y, x, block_get(player, y, x)); } //draw field - ShowPause(scr); + window_msg_status(player); } -void InitFields(void) +void screen_setup(void) { //calculate positions of all fields - int scr, prevscr; + int i, prev; int y, x; int spaceavail; @@ -284,7 +284,7 @@ void InitFields(void) window[me].shown = 1; statusXPos = window[me].size * Players[me].boardWidth + 3; statusYPos = 21; - ShowScore(me, Players[me].score); + status_draw(me, Players[me].score); messageXPos = 2; messageYPos = 24; @@ -296,46 +296,46 @@ void InitFields(void) messageXPos = statusXPos + 16; messageYPos = 2; } //messagebox doesn't fit below - DrawBox(messageXPos - 2, messageYPos - 1, + window_border(messageXPos - 2, messageYPos - 1, messageXPos + messageWidth + 1, messageYPos+messageHeight); if (msgwin = subwin(stdscr, messageHeight, messageWidth, messageYPos, messageXPos)) scrollok(msgwin, 1); //allow scrolling wmove(msgwin, messageHeight - 2, 0); - for (scr = messageHeight - 2; scr >= 0; scr--) //display message history - DisplayMessage(message[scr]); + for (i = messageHeight - 2; i >= 0; i--) //display message history + msg_draw(message[i]); spaceavail = x; - for (scr = 1; scr <= maxPlayer; scr++) - spaceavail -= Players[scr].boardWidth+2; - prevscr = me; - for (scr = 1; scr < MAX_SCREENS; scr++) if (scr != me) { - window[scr].posy = 21; - window[scr].posx = - window[prevscr].posx + 2 + window[prevscr].size * Players[prevscr].boardWidth; - if (prevscr == me) { - window[scr].posx += 15; //scorebar + for (i = 1; i <= maxPlayer; i++) + spaceavail -= Players[i].boardWidth+2; + prev = me; + for (i = 1; i < MAX_SCREENS; i++) if (i != me) { + window[i].posy = 21; + window[i].posx = + window[prev].posx + 2 + window[prev].size * Players[prev].boardWidth; + if (prev == me) { + window[i].posx += 15; //scorebar if (messageYPos < 24) - window[scr].posx += messageWidth + 4; //messagebox - spaceavail -= window[scr].posx - 3; + window[i].posx += messageWidth + 4; //messagebox + spaceavail -= window[i].posx - 3; } //stuff before second player if (spaceavail >= 0) { - window[scr].size = 2; - spaceavail -= Players[scr].boardWidth; + window[i].size = 2; + spaceavail -= Players[i].boardWidth; } //not enough space, half width else - window[scr].size = 1; - if (x < window[scr].posx + 1 + window[scr].size * Players[scr].boardWidth) - window[scr].shown = 0; //field doesn't fit on screen + window[i].size = 1; + if (x < window[i].posx + 1 + window[i].size * Players[i].boardWidth) + window[i].shown = 0; //field doesn't fit on screen else - window[scr].shown = 1; - prevscr = scr; + window[i].shown = 1; + prev = i; } - for (scr = 1; scr <= maxPlayer; scr++) - DrawField(scr); + for (i = 1; i <= maxPlayer; i++) + window_draw(i); } -static void DisplayMessage(char *p) +static void msg_draw(char *p) { char s[MSG_WIDTH]; char *psearch; @@ -356,7 +356,7 @@ static void DisplayMessage(char *p) waddch(msgwin, '\n'); } -void Message(char *fmt, ...) +void msg_add(char *fmt, ...) { //print game/bot message va_list args; char s[MSG_WIDTH]; @@ -374,12 +374,12 @@ void Message(char *fmt, ...) strcpy(p, s); wmove(msgwin, messageHeight - 1, 0); - DisplayMessage(s); + msg_draw(s); wclrtoeol(msgwin); wrefresh(msgwin); } -void Messagetype(char c, int x, char *s) +void msg_add_char(char c, int x, char *s) { //show single typed character if (c == 27) { mvwaddch(msgwin, messageHeight-1, (x+1) % (messageWidth-1), ' '); @@ -395,7 +395,7 @@ void Messagetype(char c, int x, char *s) wrefresh(msgwin); } -static void PlotBlock1(int y, int x, unsigned char type) +static void block_draw_2(int y, int x, unsigned char type) { //display block on screen move(y, x); if (type == BT_none) addstr(" "); @@ -464,7 +464,8 @@ static void PlotBlock1(int y, int x, unsigned char type) #endif } //display one brick } -static void PlotBlock1S(int y, int x, unsigned char type) + +static void block_draw_1(int y, int x, unsigned char type) { //display block small move(y, x); if (type == BT_none) addch(' '); @@ -488,30 +489,31 @@ static void PlotBlock1S(int y, int x, unsigned char type) #endif } //display one brick } -void PlotBlock(int scr, int y, int x, unsigned char type) + +void block_draw_window(int player, int y, int x, unsigned char type) { - if (y >= 0 && y < Players[scr].boardVisible - && x >= 0 && x < Players[scr].boardWidth) { - if (window[scr].size > 1) - PlotBlock1(window[scr].posy - y, window[scr].posx + 2*x, type); + if (y >= 0 && y < Players[player].boardVisible + && x >= 0 && x < Players[player].boardWidth) { + if (window[player].size > 1) + block_draw_2(window[player].posy - y, window[player].posx + 2*x, type); else - PlotBlock1S(window[scr].posy - y, window[scr].posx + x, type); + block_draw_1(window[player].posy - y, window[player].posx + x, type); } //on screen } -void PlotBlockXY(int y, int x, unsigned char type) -{ //Draw block at specified position on screen (not on field) - PlotBlock1(20 - y, 2 * x, type); +void block_draw_status(int y, int x, unsigned char type) +{ //Draw block at specified position next to field + block_draw_2(20 - y, 2 * x, type); } -void ShowScore(int scr, struct _Score score) +void status_draw(int player, struct score_t score) { //show score stuff float timer; mvaddstr(13, statusXPos, MSG_NEXT " "); mvaddstr(14, statusXPos + 5, " "); - ShapeIterate(Players[scr].nextShape, scr, 8, - statusXPos/2 + (Players[scr].nextShape/4 == 5 ? 3 : 4), - GlanceFunc); //draw; stick one more to the left + shape_iterate(Players[player].nextShape, player, 8, + statusXPos/2 + (Players[player].nextShape/4 == 5 ? 3 : 4), + block_iter_set_status); //draw; BT_I one more to the left mvprintw(3, statusXPos, MSG_LEVEL, score.level); mvprintw(5, statusXPos, MSG_SCORE, score.score); mvprintw(6, statusXPos, MSG_LINES, score.lines); @@ -530,55 +532,55 @@ void ShowScore(int scr, struct _Score score) } //too early to display stats, remove old.. } -void FieldMessage(int playa, char *message) -{ //put a message over playa's field - if (!window[playa].shown) return; +void window_msg(int player, char *message) +{ //put a message over player's field + if (!window[player].shown) return; if (message) { char s[MAX_BOARD_WIDTH+1]; memset(s, ' ', MAX_BOARD_WIDTH); - memcpy(&s[(window[playa].size * Players[playa].boardWidth / 2) - (strlen(message) / 2)], + memcpy(&s[(window[player].size * Players[player].boardWidth / 2) - (strlen(message) / 2)], message, strlen(message)); - s[window[playa].size * Players[playa].boardWidth] = 0; + s[window[player].size * Players[player].boardWidth] = 0; #ifdef HAVE_NCURSES attrset(A_REVERSE); #else standout(); #endif - mvprintw(window[playa].posy - Players[playa].boardVisible / 2, - window[playa].posx, "%s", s); + mvprintw(window[player].posy - Players[player].boardVisible / 2, + window[player].posx, "%s", s); standend(); } //display else { int x, y; - y = Players[playa].boardVisible / 2; - for (x = 0; x <= Players[playa].boardWidth; x++) - PlotBlock(playa, y, x, GetBlock(playa, y, x)); + y = Players[player].boardVisible / 2; + for (x = 0; x <= Players[player].boardWidth; x++) + block_draw_window(player, y, x, block_get(player, y, x)); } //restore field } -void ShowPause(int playa) -{ //put paused over player's field - if (Players[playa].alive > 0) - if (Players[playa].flags & SCF_paused) +void window_msg_status(int player) +{ //put status (pause, readiness, game over) over player's field + if (Players[player].alive > 0) + if (Players[player].flags & SCF_paused) if (Game.started > 1) - FieldMessage(playa, window[playa].size > 1 ? "P A U S E D" : "PAUSED"); + window_msg(player, window[player].size > 1 ? "P A U S E D" : "PAUSED"); else - FieldMessage(playa, - window[playa].size > 1 ? "N O T R E A D Y" : "NOT READY"); + window_msg(player, + window[player].size > 1 ? "N O T R E A D Y" : "NOT READY"); else if (Game.started > 1) - FieldMessage(playa, NULL); + window_msg(player, NULL); else - FieldMessage(playa, window[playa].size > 1 ? "R E A D Y" : "READY"); - else if (!Players[playa].alive) - FieldMessage(playa, - window[playa].size > 1 ? "G A M E O V E R" : "GAME OVER"); + window_msg(player, window[player].size > 1 ? "R E A D Y" : "READY"); + else if (!Players[player].alive) + window_msg(player, + window[player].size > 1 ? "G A M E O V E R" : "GAME OVER"); else - FieldMessage(playa, window[playa].size > 1 ? "E M P T Y" : "EMPTY"); + window_msg(player, window[player].size > 1 ? "E M P T Y" : "EMPTY"); } -void ShowTime(void) +void status_tick(void) { //display timer mvprintw(statusYPos, statusXPos, "timer %7.0f ", CurTimeval() / 1e6); } @@ -592,7 +594,7 @@ static void CatchWinCh(int sig) { //handle window resize endwin(); //exit curses refresh(); //and reinit display (with different sizes) - InitFields(); //manually redraw everything + screen_setup();//manually redraw everything refresh(); //refresh } diff --git a/curses.h b/curses.h index 13abc67..7228ec1 100644 --- a/curses.h +++ b/curses.h @@ -14,18 +14,18 @@ extern void InitScreens(void); extern void CleanupScreens(void); static void GetTermcapInfo(void); static void OutputTermStr(char *str, int flush); -extern void DrawBox(int x1, int y1, int x2, int y2); -extern void DrawField(int scr); -extern void InitFields(void); -static void DisplayMessage(char *p); -extern void Messagef(char *fmt, ...); -extern void Messagetype(char c, int x, char *s); -extern void PlotBlock(int scr, int y, int x, unsigned char type); -extern void PlotBlockXY(int y, int x, unsigned char type); -extern void ShowScore(int scr, struct _Score score); -extern void FieldMessage(int playa, char *message); -extern void ShowPause(int playa); -extern void ShowTime(void); +static void window_border(int x1, int y1, int x2, int y2); +extern void window_draw(int player); +extern void screen_setup(void); +static void msg_draw(char *p); +extern void msg_add(char *fmt, ...); +extern void msg_add_char(char c, int x, char *s); +extern void block_draw_window(int player, int y, int x, unsigned char type); +extern void block_draw_status(int y, int x, unsigned char type); +extern void status_draw(int player, struct score_t score); +extern void window_msg(int player, char *message); +extern void window_msg_status(int player); +extern void status_tick(void); extern void ScheduleFullRedraw(void); static void CatchWinCh(int sig); diff --git a/inet.c b/inet.c index 6ab0e66..e674044 100644 --- a/inet.c +++ b/inet.c @@ -95,11 +95,11 @@ void HandShake(void) case NP_hello: { me = event.u.net.uid; - memcpy(&Players[me], &Players[0], sizeof(_Player)); + memcpy(&Players[me], &Players[0], sizeof(player_t)); fprintf(stderr, "Accepted (%s) as #%d (%s)\n", event.u.net.data, me, Players[me].name); SendPacket(0, NP_newPlayer, - sizeof(_Player) - sizeof(Players[me].host), + sizeof(player_t) - sizeof(Players[me].host), &Players[me]); break; } diff --git a/netris.h b/netris.h index 28a4132..99c8dcb 100644 --- a/netris.h +++ b/netris.h @@ -157,14 +157,14 @@ typedef struct { int boardHeight, boardWidth, boardVisible; int curX, curY; char curShape, nextShape; - struct _Score { + struct score_t { short level; long score; int pieces, lines, adds; } score; char host[256]; //last -} _Player; -EXT _Player Players[MAX_SCREENS]; +} player_t; +EXT player_t Players[MAX_SCREENS]; EXT short me; EXT short maxPlayer; EXT int spied; //in player.flags @@ -182,8 +182,8 @@ typedef struct { long seed; //4 int initspeed; //5 int speed; -} _Game; -EXT _Game Game; +} game_t; +EXT game_t Game; #define MSG_WIDTH 128 diff --git a/server.c b/server.c index d33cf24..ff09dc4 100644 --- a/server.c +++ b/server.c @@ -79,19 +79,19 @@ static EventGenRec *nextGen = &alarmGen; static sigjmp_buf close_env; -static void SendPacketTo(short playa, short uid, NetPacketType type, int size, void *data) +static void SendPacketTo(short player, short uid, NetPacketType type, int size, void *data) { //send to someone netint4 header[3]; - if (netGen[playa].fd >= 0) { + if (netGen[player].fd >= 0) { if (verbose) - fprintf(stderr, MSG_SERVER_DBG_SEND "\n", type, uid, playa); + fprintf(stderr, MSG_SERVER_DBG_SEND "\n", type, uid, player); header[0] = hton4(uid); header[1] = hton4(type); header[2] = hton4(size + HEADER_SIZE); - if (MyWrite(netGen[playa].fd, header, HEADER_SIZE) != HEADER_SIZE) + if (MyWrite(netGen[player].fd, header, HEADER_SIZE) != HEADER_SIZE) die("write (header)"); - if (size > 0 && data && MyWrite(netGen[playa].fd, data, size) != size) + if (size > 0 && data && MyWrite(netGen[player].fd, data, size) != size) die("write"); } } @@ -101,20 +101,20 @@ static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event) return E_alarm; } -static void SCloseNet(short playa) +static void SCloseNet(short player) { //kick some connection's ass! MyEvent event; - if (netGen[playa].fd >= 0) { - if (Players[playa].alive >= 0) { - SendPacketTo(playa, 0, NP_endConn, 0, NULL); + if (netGen[player].fd >= 0) { + if (Players[player].alive >= 0) { + SendPacketTo(player, 0, NP_endConn, 0, NULL); do {} while (WaitMyEvent(&event, EM_net) != E_lostConn); } //say bye to player - close(netGen[playa].fd); - netGen[playa].fd = -1; + close(netGen[player].fd); + netGen[player].fd = -1; } - if (netGen[playa].next) - RemoveEventGen(&netGen[playa]); + if (netGen[player].next) + RemoveEventGen(&netGen[player]); } static void CloseNets(void) @@ -319,11 +319,11 @@ static int StartServer(void) for (i = 1; i < MAX_SCREENS; i++) if (netGen[i].fd >= 0 && i != event.u.net.sender) { SendPacketTo(event.u.net.sender, i, NP_newPlayer, - sizeof(_Player), &Players[i]); + sizeof(player_t), &Players[i]); SendPacketTo(event.u.net.sender, i, NP_newPiece, sizeof(Players[i].curShape), &Players[i].curShape); SendPacketTo(i, event.u.net.sender, NP_newPlayer, - sizeof(_Player), &Players[event.u.net.sender]); + sizeof(player_t), &Players[event.u.net.sender]); } //send (to) players fprintf(stderr, MSG_SERVER_PLAYER_JOIN "\n", event.u.net.sender, -- 2.30.0