From e2cb2bfce3e4838b777310a03ad814b2aed68250 Mon Sep 17 00:00:00 2001 From: xHire Date: Sat, 4 Oct 2008 13:49:27 +0200 Subject: Development version was renamed form 'tuxanci-svn' to 'tuxanci-dev' Compilation warnings were cleaned up --- src/client/chat.c | 98 ++++++++++++++++++--------------------- src/client/keyboardBuffer.c | 105 ++++++++++++++++++++++++------------------ src/screen/screen_downArena.c | 92 ++++++++++++++---------------------- 3 files changed, 139 insertions(+), 156 deletions(-) (limited to 'src') diff --git a/src/client/chat.c b/src/client/chat.c index 2b2805c..eeca8d8 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -1,5 +1,6 @@ #include +#include #include #include @@ -64,8 +65,7 @@ void drawChat() char str[STR_SIZE]; int i; - if( chat_active == FALSE ) - { + if (chat_active == FALSE) { return; } @@ -73,32 +73,29 @@ void drawChat() CHAT_LOCATION_X, CHAT_LOCATION_Y, 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y); - for( i = 0 ; i < listText->count ; i++ ) - { + for (i = 0; i < listText->count; i++) { char *s; s = (char *)listText->list[i]; drawFontMaxSize(s, - CHAT_LOCATION_X+5, CHAT_LOCATION_Y+5 + i*20, - CHAT_SIZE_X-10, 20, COLOR_WHITE); + CHAT_LOCATION_X + 5, CHAT_LOCATION_Y + 5 + i * 20, + CHAT_SIZE_X - 10, 20, COLOR_WHITE); } strcpy(str, line); - if( timeBlick > CHAT_TIME_BLICK_CURSOR/2 ) - { + if (timeBlick > CHAT_TIME_BLICK_CURSOR / 2) { strcat(str, "\f"); } timeBlick++; - if( timeBlick == CHAT_TIME_BLICK_CURSOR ) - { + if (timeBlick == CHAT_TIME_BLICK_CURSOR) { timeBlick = 0; } - drawFont(str, CHAT_LOCATION_X+5, CHAT_LOCATION_Y+5 + CHAT_MAX_LINES*20, COLOR_WHITE); + drawFont(str, CHAT_LOCATION_X + 5, (CHAT_LOCATION_Y + 5) + (CHAT_MAX_LINES * 20), COLOR_WHITE); } static void processMessageKey(SDL_keysym keysym) @@ -113,31 +110,35 @@ static void processMessageKey(SDL_keysym keysym) len = strlen(line); getTextSize(line, &w, &h); - if( w > CHAT_SIZE_X-40 ) - { + if (w > CHAT_SIZE_X - 40) { return; } - /* zpracovani backspace */ - if (keysym.sym == SDLK_BACKSPACE && len > 0){ - line[len-1]='\0'; + /* processing of backspace */ + if (keysym.sym == SDLK_BACKSPACE && len > 0) { + line[len - 1] = '\0'; return; } - /* zpracovani tisknutelnych paznaku */ - if ( (keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT) - || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE) ){ - line[len] = keysym.sym; /* tady by bylo daleko lepsi dat strcat, - predpoklada se, ze line je vyplnen 0 az dokonce */ + /* processing of printable chars but not letters */ + if ((keysym.sym >= SDLK_SPACE && keysym.sym <= SDLK_AT) + || (keysym.sym >= SDLK_LEFTBRACKET && keysym.sym <= SDLK_BACKQUOTE)) { + /* here would be much better to put 'strcat' as 'line' is expected + * to be full of '0' up to its end + */ + line[len] = keysym.sym; } - /* zpracovani pismenek */ - if ( keysym.sym >= SDLK_a && keysym.sym <= SDLK_z){ + /* processing of letters */ + if (keysym.sym >= SDLK_a && keysym.sym <= SDLK_z) { char c = keysym.sym; - if (keysym.mod == KMOD_SHIFT) + if (keysym.mod == KMOD_SHIFT) { c = toupper(c); - line[len] = c; /* tady by bylo daleko lepsi dat strcat, - predpoklada se, ze line je vyplnen 0 az dokonce */ + } + /* here would be much better to put 'strcat' as 'line' is expected + * to be full of '0' up to its end + */ + line[len] = c; } return; @@ -145,13 +146,11 @@ static void processMessageKey(SDL_keysym keysym) static void sendNewMessage() { - if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) { proto_send_chat_client(line); } - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { char out[STR_PROTO_SIZE]; snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", @@ -175,28 +174,25 @@ static void eventChatDisable() static void eventChatEnable() { - /* Mame zobrazene okno chatu. Je potreba zpracovat vsechny klavesy v bufferu - * s tim, ze pri klavese RETURN provedeme odeslani radku chatu - * na server + /* The chat window is displayed. It is needed to process all keys in the buffer + * but when ENTER is pressed the chat row is sent to the server */ - while( isAnyKeyInKeyboardBuffer() == TRUE ) - { + while (isAnyKeyInKeyboardBuffer() == TRUE) { SDL_keysym key; key = popKeyFromKeyboardBuffer(); - if ( key.sym == SDLK_RETURN ) - { - if ( strcmp(line, "") != 0 ) - { /* mame napsany radek: je potreba jej odeslat */ + if (key.sym == SDLK_RETURN) { + if (strcmp(line, "") != 0) { + /* the chat row is already written - it is needed to send it */ sendNewMessage(); memset(line, '\0', STR_SIZE); - continue; /* pokracovat s dalsimi klavesami */ + continue; /* continue with other keys */ } - else - { /* radek je prazdny, je potreba vypnout okno chatu */ + else { + /* the chat row is empty - it is needed to turn off the chat window */ eventChatDisable(); - /* vypneme zachytavani klaves do bufferu a vycistime buffer */ + /* turn off key catching into the buffer and clear the buffer */ //disableKeyboardBuffer(); //clearKeyboardBuffer(); } @@ -207,12 +203,11 @@ static void eventChatEnable() } /** - * Zpracovani "udalosti" chatu? + * Processing of chat 'events' */ void eventChat() { - if( isChatActive() ) - { + if (isChatActive()) { eventChatEnable(); } } @@ -229,23 +224,22 @@ bool_t isRecivedNewMsg() void addToChat(char *s) { - addList(listText, strdup(s) ); + addList(listText, strdup(s)); - if( listText->count > CHAT_MAX_LINES ) - { + if (listText->count > CHAT_MAX_LINES) { delListItem(listText, 0, free); } - if( chat_active == FALSE ) - { + if (chat_active == FALSE) { receivedNewMsg = TRUE; } } void quitChat() { - assert( listText != NULL ); + assert(listText != NULL); unregisterHotKey(SDLK_RETURN); destroyListItem(listText, free); } + diff --git a/src/client/keyboardBuffer.c b/src/client/keyboardBuffer.c index 7dee362..246d262 100644 --- a/src/client/keyboardBuffer.c +++ b/src/client/keyboardBuffer.c @@ -1,64 +1,69 @@ /* * keyboardBuffer.c * - * Created on: 1.8.2008 + * Created on: 1. 8. 2008 * Author: Karel Podvolecky * - * Jednoducha fronta stisknutych klaves. + * Simple front of pressed keys. * */ #include +#include +#include #include #include #include "keyboardBuffer.h" -static keyboardBuffer_t *keyboardBuffer=NULL; +static keyboardBuffer_t *keyboardBuffer = NULL; static SDL_keysym emptyKey; /* - * Inicializuje klavesovy buffer. Parametr udava pocet klaves. + * Key buffer initializes. The parameter sets the number of keys. */ -void initKeyboardBuffer(int size){ - assert(size>0); - assert(keyboardBuffer==NULL); +void initKeyboardBuffer(int size) +{ + assert(size > 0); + assert(keyboardBuffer == NULL); keyboardBuffer = malloc(sizeof(keyboardBuffer_t)); - assert(keyboardBuffer!=NULL); + assert(keyboardBuffer != NULL); memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t)); keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym)); - assert(keyboardBuffer->buff!=NULL); + assert(keyboardBuffer->buff != NULL); memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym)); - keyboardBuffer->begin=0; - keyboardBuffer->end=0; - keyboardBuffer->count=0; - keyboardBuffer->size=size; + keyboardBuffer->begin = 0; + keyboardBuffer->end = 0; + keyboardBuffer->count = 0; + keyboardBuffer->size = size; emptyKey.sym = SDLK_UNKNOWN; } /* - * Vyprazdni buffer. + * Empty the buffer */ -void clearKeyboardBuffer(){ - assert(keyboardBuffer!=NULL); +void clearKeyboardBuffer() +{ + assert(keyboardBuffer != NULL); - keyboardBuffer->begin=0; - keyboardBuffer->end=0; - keyboardBuffer->count=0; + keyboardBuffer->begin = 0; + keyboardBuffer->end = 0; + keyboardBuffer->count = 0; memset(keyboardBuffer->buff, 0, keyboardBuffer->size * sizeof(SDL_keysym)); } /* - * Prida klavesu na konec bufferu. Pokud je buffer preplnen, - * vypise chybu na chybovy vystup a klavesu zahodi. + * Adds key to the end of the buffer. If the buffer is overrun, + * an error is printed to stderr and the key is dropped. */ -bool_t pushKeyToKeyboardBuffer(SDL_keysym key){ - assert(keyboardBuffer!=NULL); +bool_t pushKeyToKeyboardBuffer(SDL_keysym key) +{ + assert(keyboardBuffer != NULL); if (keyboardBuffer->count >= keyboardBuffer->size){ fprintf(stderr, _("Keyboard Buffer overrun! Dropping key: %02x\n"), key.sym); @@ -68,8 +73,9 @@ bool_t pushKeyToKeyboardBuffer(SDL_keysym key){ keyboardBuffer->buff[keyboardBuffer->end] = key; keyboardBuffer->end++; - if (keyboardBuffer->end>=keyboardBuffer->size) - keyboardBuffer->end=0; + if (keyboardBuffer->end >= keyboardBuffer->size) { + keyboardBuffer->end = 0; + } keyboardBuffer->count++; @@ -77,11 +83,12 @@ bool_t pushKeyToKeyboardBuffer(SDL_keysym key){ } /* - * Vyjme prvni klavesu z bufferu a vrati ji. Pokud je buffer prazdny, - * vypise chybu na chybovy vystup a vrati SDLK_UNKNOWN + * Takes out first key from the buffer and returns it. If the buffer is empty, + * an error is printed to stderr and SDLK_UNKNOWN is returned. */ -SDL_keysym popKeyFromKeyboardBuffer(){ - assert(keyboardBuffer!=NULL); +SDL_keysym popKeyFromKeyboardBuffer() +{ + assert(keyboardBuffer != NULL); if (keyboardBuffer->count <= 0){ fprintf(stderr, _("Keyboard Buffer underrun!\n")); @@ -89,11 +96,12 @@ SDL_keysym popKeyFromKeyboardBuffer(){ } SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin]; - keyboardBuffer->buff[keyboardBuffer->begin]=emptyKey; + keyboardBuffer->buff[keyboardBuffer->begin] = emptyKey; keyboardBuffer->begin++; - if (keyboardBuffer->begin>=keyboardBuffer->size) - keyboardBuffer->begin=0; + if (keyboardBuffer->begin >= keyboardBuffer->size) { + keyboardBuffer->begin = 0; + } keyboardBuffer->count--; @@ -101,38 +109,43 @@ SDL_keysym popKeyFromKeyboardBuffer(){ } /* - * Velikost bufferu. + * The buffer size */ -int getKeyboardBufferSize(){ - assert(keyboardBuffer!=NULL); +int getKeyboardBufferSize() +{ + assert(keyboardBuffer != NULL); return keyboardBuffer->size; } /* - * Pocet klaves v bufferu. + * Number of keys in the buffer */ -int KeyboardBufferCount(){ - assert(keyboardBuffer!=NULL); +int KeyboardBufferCount() +{ + assert(keyboardBuffer != NULL); return keyboardBuffer->count; } -bool_t isAnyKeyInKeyboardBuffer(){ - return KeyboardBufferCount()>0 ? TRUE : FALSE; +bool_t isAnyKeyInKeyboardBuffer() +{ + return KeyboardBufferCount() > 0 ? TRUE : FALSE; } /* - * Uvolni buffer. Pokud neni prazdny, vypise predtim - * info o zaplneni na chybovy vystup. + * Frees the buffer. If it is not empty, information + * about filling is prined to stderr first. */ -void quitKeyboardBuffer(){ - assert(keyboardBuffer!=NULL); +void quitKeyboardBuffer() +{ + assert(keyboardBuffer != NULL); - if (keyboardBuffer->count>0){ + if (keyboardBuffer->count > 0){ fprintf(stderr, _("Keyboard buffer is not empty!\n")); } free(keyboardBuffer->buff); free(keyboardBuffer); - keyboardBuffer=NULL; + keyboardBuffer = NULL; } + diff --git a/src/screen/screen_downArena.c b/src/screen/screen_downArena.c index d393250..f7534b5 100644 --- a/src/screen/screen_downArena.c +++ b/src/screen/screen_downArena.c @@ -1,5 +1,6 @@ #include +#include #include #include @@ -53,7 +54,7 @@ static void setStatusString(char *s) { //printf("status -> %s\n", s); destroyWidgetLabel(label_status); - label_status = newWidgetLabel(s, WINDOW_SIZE_X/2, 250, WIDGET_LABEL_CENTER); + label_status = newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); } static void connectToDownServer() @@ -63,8 +64,7 @@ static void connectToDownServer() sock_server_tcp = connectTcpSocket(getSettingIP(), getSettingPort(), PROTO_TCPv4); - if( sock_server_tcp == NULL ) - { + if (sock_server_tcp == NULL) { sprintf(status, "I do not connect to %s %d TCP down server", getSettingIP(), getSettingPort()); setStatusString(status); return; @@ -102,8 +102,7 @@ static void sendStatusToGameServer() { char *msg = "status\n"; - if( countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS ) - { + if (countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS) { char status[STR_SIZE]; sprintf(status, "Game server %s %d is down", getSettingIP(), getSettingPort()); setStatusString(status); @@ -114,8 +113,7 @@ static void sendStatusToGameServer() countSendMsg++; printf("countSendMsg = %d\n", countSendMsg++); - if( writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0 ) - { + if (writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0) { char status[STR_SIZE]; sprintf(status, "I do not send message to %s %d UDP game server", getSettingIP(), getSettingPort()); setStatusString(status); @@ -131,8 +129,7 @@ void startScreenDownArena() sock_server_udp = connectUdpSocket(getSettingIP(), getSettingPort(), PROTO_UDPv4); - if( sock_server_udp == NULL ) - { + if (sock_server_udp == NULL) { sprintf(status, "I do not connect to %s %d UDP game server", getSettingIP(), getSettingPort()); setStatusString(status); return; @@ -173,13 +170,11 @@ static void proto_err(char *line) static void eventProto(char *line) { - if( strncmp(line, "OK", 2) == 0 ) - { + if (strncmp(line, "OK", 2) == 0) { proto_ok(line); } - if( strncmp(line, "ERR", 3) == 0 ) - { + if (strncmp(line, "ERR", 3) == 0) { proto_err(line); } } @@ -212,15 +207,13 @@ static int eventRecvBuffer() memset(buffer, 0, STR_PROTO_SIZE); ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE-1); - //if( ret <= 0 )printf("readTcpSocket = %d\n", ret); + //if (ret <= 0) printf("readTcpSocket = %d\n", ret); - if( ret < 0 ) - { + if (ret < 0) { return -1; } - if( addBuffer(recvBuffer, buffer, ret) < 0 ) - { + if (addBuffer(recvBuffer, buffer, ret) < 0) { char status[STR_SIZE]; sprintf(status, "Error -- recv buffer is full"); setStatusString(status); @@ -228,14 +221,12 @@ static int eventRecvBuffer() return -1; } - if( file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0 ) - { + if (file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0) { eventProto(line); return ret; } - if( file != NULL ) - { + if (file != NULL) { return downArenaFile(); } @@ -250,8 +241,7 @@ static int eventSendBuffer() len = getBufferSize(sendBuffer); - if( len == 0 ) - { + if (len == 0) { return -1; } @@ -259,8 +249,7 @@ static int eventSendBuffer() res = writeTcpSocket(sock_server_tcp, data, len); - if( res < 0 ) - { + if (res < 0) { return -1; } @@ -277,13 +266,11 @@ static void readArenaFromStatus() offset_begin = strstr(str_status, str_arena); - if( offset_begin != NULL ) - { + if (offset_begin != NULL) { offset_begin += strlen(str_arena); offset_end = strstr(offset_begin, "\n"); - if( offset_end != NULL ) - { + if (offset_end != NULL) { closeUdpSocket(sock_server_udp); sock_server_udp = NULL; strncpy(arenaNetName, offset_begin, offset_end-offset_begin); @@ -303,13 +290,11 @@ static void readArenaFromStatus() static void eventStatus() { - if( getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT ) - { + if (getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT) { sendStatusToGameServer(); } - if( readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE-1) > 0 ) - { + if (readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE - 1) > 0) { //printf("str_status = %s\n", str_status); readArenaFromStatus(); } @@ -319,29 +304,23 @@ void eventScreenDownArena() { int i; - if( strcmp(str_status, "none") == 0 ) - { + if (strcmp(str_status, "none") == 0) { eventStatus(); } - if( recvBuffer != NULL ) - { - for( i = 0 ; i < DOWN_ARENA_COUNT_READ_SOCKET ; i++ ) - { - if( eventRecvBuffer() <= 0 ) - { + if (recvBuffer != NULL) { + for (i = 0; i < DOWN_ARENA_COUNT_READ_SOCKET; i++) { + if (eventRecvBuffer() <= 0) { break; } } } - if( sendBuffer != NULL ) - { + if (sendBuffer != NULL) { eventSendBuffer(); } - if( file != NULL && fileSize == fileOffset && fileSize > 0 ) - { + if (file != NULL && fileSize == fileOffset && fileSize > 0) { fclose(file); file = NULL; closeConnectFromDownServer(); @@ -354,18 +333,15 @@ void eventScreenDownArena() void stopScreenDownArena() { - if( file != NULL ) - { + if (file != NULL) { unlink(path); } - if( sock_server_tcp != NULL ) - { + if (sock_server_tcp != NULL) { closeConnectFromDownServer(); } - if( sock_server_udp != NULL ) - { + if (sock_server_udp != NULL) { closeUdpSocket(sock_server_udp); } @@ -377,8 +353,7 @@ static void eventWidget(void *p) button = (widget_t *)(p); - if( button == button_back ) - { + if (button == button_back) { setScreen("mainMenu"); } } @@ -388,13 +363,13 @@ void initScreenDownArena() image_t *image; image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); + image_backgorund = newWidgetImage(0, 0, image); - button_back = newWidgetButton(_("back"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, WINDOW_SIZE_Y-80, eventWidget); + button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 -WIDGET_BUTTON_WIDTH / 2, WINDOW_SIZE_Y - 80, eventWidget); - label_status = newWidgetLabel("none", WINDOW_SIZE_X/2, 250, WIDGET_LABEL_CENTER); + label_status = newWidgetLabel("none", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); - registerScreen( newScreen("downArena", startScreenDownArena, eventScreenDownArena, + registerScreen(newScreen("downArena", startScreenDownArena, eventScreenDownArena, drawScreenDownArena, stopScreenDownArena) ); } @@ -404,3 +379,4 @@ void quitScreenDownArena() destroyWidgetButton(button_back); destroyWidgetLabel(label_status); } + -- cgit v1.2.3