summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-03 18:46:22 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-03 18:46:22 +0000
commitb5723cbd822b2359850c121ca69e682a607d91bd (patch)
treec731a5c07d6188b1bdce6e90b5ac02e35800716d
parent00c9cebac684c42741e924d11038d5591e87dacd (diff)
- pridany kapov patch na klavesy
- widget na nastavovanie klaves sa rozsvieti, ked je aktivny git-svn-id: http://opensvn.csie.org/tuxanci_ng@189 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
-rw-r--r--config.h2
-rw-r--r--data/conf/server.conf2
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/base/exportFunction.c72
-rw-r--r--src/base/exportFunction.h13
-rwxr-xr-xsrc/base/modules.c10
-rw-r--r--src/base/modules.h4
-rw-r--r--src/base/shareFunction.c72
-rw-r--r--src/base/shareFunction.h13
-rw-r--r--src/client/chat.c226
-rw-r--r--src/client/chat.h2
-rwxr-xr-xsrc/client/interface.c22
-rwxr-xr-xsrc/client/interface.h5
-rw-r--r--src/client/keyboardBuffer.c138
-rw-r--r--src/client/keyboardBuffer.h34
-rwxr-xr-xsrc/modules/modMove.c4
-rwxr-xr-xsrc/modules/modPipe.c2
-rwxr-xr-xsrc/modules/modTeleport.c4
-rw-r--r--src/server/logFile.c46
-rw-r--r--src/server/logFile.h18
-rw-r--r--src/widget/widget_catchkey.c9
21 files changed, 407 insertions, 295 deletions
diff --git a/config.h b/config.h
index f66740a..bcb921f 100644
--- a/config.h
+++ b/config.h
@@ -1 +1 @@
-#define TUXANCI_VERSION "svn188"
+#define TUXANCI_VERSION "svn189"
diff --git a/data/conf/server.conf b/data/conf/server.conf
index 329188b..b50f11c 100644
--- a/data/conf/server.conf
+++ b/data/conf/server.conf
@@ -15,4 +15,4 @@ MAX_ITEM 10
LOG_FILE tuxanci-server.log
SCORE_FILE height-score.txt
-SUPPORT_CLIENTS 0.20.0 svn188 svn187 svn186
+SUPPORT_CLIENTS 0.20.0 svn189 svn188 svn187 svn186
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e931dc2..8bf07dc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,13 +3,13 @@ SET ( WORKDIR ${CMAKE_SOURCE_DIR}/src )
# find ./ -maxdepth 1 -type f -name \*.c |grep "$" |sed -e 's/^\.\//\$\{WORKDIR\}\/DIR\//' -e 's/\.c//' |tr '\n' ' ' > DIRfiles
# nahradte DIR potrebnym adresarem a pak vemte vse co je v DIRfiles a vlozte to sem
SET ( SRC_base
-${WORKDIR}/base/main ${WORKDIR}/base/shot ${WORKDIR}/base/space ${WORKDIR}/base/checkFront ${WORKDIR}/base/storage ${WORKDIR}/base/myTimer ${WORKDIR}/base/protect ${WORKDIR}/base/list ${WORKDIR}/base/arena ${WORKDIR}/base/server ${WORKDIR}/base/udp_server ${WORKDIR}/base/tcp_server ${WORKDIR}/base/serverSelect ${WORKDIR}/base/serverSendMsg ${WORKDIR}/base/textFile ${WORKDIR}/base/gun ${WORKDIR}/base/arenaFile ${WORKDIR}/base/modules ${WORKDIR}/base/net_multiplayer ${WORKDIR}/base/index ${WORKDIR}/base/item ${WORKDIR}/base/tux ${WORKDIR}/base/director ${WORKDIR}/base/idManager ${WORKDIR}/base/homeDirector ${WORKDIR}/base/proto ${WORKDIR}/base/exportFunction ${WORKDIR}/base/buffer
+${WORKDIR}/base/main ${WORKDIR}/base/shot ${WORKDIR}/base/space ${WORKDIR}/base/checkFront ${WORKDIR}/base/storage ${WORKDIR}/base/myTimer ${WORKDIR}/base/protect ${WORKDIR}/base/list ${WORKDIR}/base/arena ${WORKDIR}/base/server ${WORKDIR}/base/udp_server ${WORKDIR}/base/tcp_server ${WORKDIR}/base/serverSelect ${WORKDIR}/base/serverSendMsg ${WORKDIR}/base/textFile ${WORKDIR}/base/gun ${WORKDIR}/base/arenaFile ${WORKDIR}/base/modules ${WORKDIR}/base/net_multiplayer ${WORKDIR}/base/index ${WORKDIR}/base/item ${WORKDIR}/base/tux ${WORKDIR}/base/director ${WORKDIR}/base/idManager ${WORKDIR}/base/homeDirector ${WORKDIR}/base/proto ${WORKDIR}/base/shareFunction ${WORKDIR}/base/buffer
${WORKDIR}/net/udp ${WORKDIR}/net/tcp ${WORKDIR}/net/dns
)
SET ( SRC_client
-${WORKDIR}/client/layer ${WORKDIR}/client/term ${WORKDIR}/client/screen ${WORKDIR}/client/interface ${WORKDIR}/client/client ${WORKDIR}/client/chat ${WORKDIR}/client/configFile ${WORKDIR}/client/language ${WORKDIR}/client/font ${WORKDIR}/client/game ${WORKDIR}/client/radar ${WORKDIR}/client/panel ${WORKDIR}/client/image
+${WORKDIR}/client/layer ${WORKDIR}/client/term ${WORKDIR}/client/screen ${WORKDIR}/client/interface ${WORKDIR}/client/client ${WORKDIR}/client/chat ${WORKDIR}/client/configFile ${WORKDIR}/client/language ${WORKDIR}/client/font ${WORKDIR}/client/game ${WORKDIR}/client/radar ${WORKDIR}/client/panel ${WORKDIR}/client/image ${WORKDIR}/client/keyboardBuffer
${WORKDIR}/screen/screen_choiceArena ${WORKDIR}/screen/screen_settingKeys ${WORKDIR}/screen/screen_table ${WORKDIR}/screen/screen_setting ${WORKDIR}/screen/screen_credits ${WORKDIR}/screen/screen_world ${WORKDIR}/screen/screen_analyze ${WORKDIR}/screen/screen_mainMenu ${WORKDIR}/screen/screen_browser ${WORKDIR}/screen/screen_gameType
diff --git a/src/base/exportFunction.c b/src/base/exportFunction.c
deleted file mode 100644
index 550e4ec..0000000
--- a/src/base/exportFunction.c
+++ /dev/null
@@ -1,72 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "exportFunction.h"
-
-typedef struct export_fce_item_struct
-{
- char *name;
- void *function;
-} export_fce_item_t;
-
-static list_t *listExportFce;
-
-static export_fce_item_t* newExportFceItem(char *name, void *function)
-{
- export_fce_item_t *new;
-
- new = malloc( sizeof(export_fce_item_t) );
- new->name = strdup(name);
- new->function = function;
-
- return new;
-}
-
-static void destroyExportFce(export_fce_item_t *p)
-{
- free(p->name);
- free(p);
-}
-
-void initExortFunction()
-{
- listExportFce = newList();
-}
-void addToExportFce(char *name, void *function)
-{
- printf("add to export function %s\n", name);
-
- addList(listExportFce, newExportFceItem(name, function) );
-}
-
-void* getExportFce(char *name)
-{
- int i;
-
- for( i = 0 ; i < listExportFce->count ; i++ )
- {
- export_fce_item_t *this;
-
- this = (export_fce_item_t *)listExportFce->list[i];
-
- if( strcmp(this->name, name) == 0 )
- {
- return this->function;
- }
- }
-
- return NULL;
-}
-
-void quitExportFunction()
-{
- destroyListItem(listExportFce, destroyExportFce);
-}
-
-
-
diff --git a/src/base/exportFunction.h b/src/base/exportFunction.h
deleted file mode 100644
index 8e01fc9..0000000
--- a/src/base/exportFunction.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-#ifndef EXPORT_FUNCTION_H
-
-#define EXPORT_FUNCTION_H
-
-extern void initExortFunction();
-extern void addToExportFce(char *name, void *function);
-
-extern void* getExportFce(char *name);
-extern void quitExportFunction();
-
-#endif
-
diff --git a/src/base/modules.c b/src/base/modules.c
index 13b0ff2..1443f21 100755
--- a/src/base/modules.c
+++ b/src/base/modules.c
@@ -15,7 +15,7 @@
#include "arena.h"
#include "arenaFile.h"
#include "proto.h"
-#include "exportFunction.h"
+#include "shareFunction.h"
#ifndef PUBLIC_SERVER
#include "interface.h"
@@ -31,8 +31,8 @@ static export_fce_t export_fce =
.fce_getImage = getImage,
#endif
.fce_loadDepModule = loadDepModule,
- .fce_addToExportFce = addToExportFce,
- .fce_getExportFce = getExportFce,
+ .fce_addToShareFce = addToShareFce,
+ .fce_getShareFce = getShareFce,
.fce_getValue = getArenaValue,
.fce_getNetTypeGame = getNetTypeGame,
@@ -210,7 +210,7 @@ static int destroyModule(module_t *p)
void initModule()
{
listModule = newList();
- initExortFunction();
+ initShareFunction();
}
int isModuleLoaded(char *name)
@@ -341,5 +341,5 @@ int recvMsgModule(char *msg)
void quitModule()
{
destroyListItem(listModule, destroyModule);
- quitExportFunction();
+ quitShareFunction();
}
diff --git a/src/base/modules.h b/src/base/modules.h
index 9329dbd..e5a15f1 100644
--- a/src/base/modules.h
+++ b/src/base/modules.h
@@ -31,8 +31,8 @@ typedef struct export_fce_s
int (*fce_getNetTypeGame)();
int (*fce_loadDepModule)(char *name);
- void (*fce_addToExportFce)(char *name, void *function);
- void* (*fce_getExportFce)(char *name);
+ void (*fce_addToShareFce)(char *name, void *function);
+ void* (*fce_getShareFce)(char *name);
void (*fce_getTuxProportion)(tux_t *tux, int *x,int *y, int *w, int *h);
void (*fce_setTuxProportion)(tux_t *tux, int x, int y);
diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c
new file mode 100644
index 0000000..6250519
--- /dev/null
+++ b/src/base/shareFunction.c
@@ -0,0 +1,72 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "shareFunction.h"
+
+typedef struct share_fce_item_struct
+{
+ char *name;
+ void *function;
+} share_fce_item_t;
+
+static list_t *listShareFce;
+
+static share_fce_item_t* newShareFceItem(char *name, void *function)
+{
+ share_fce_item_t *new;
+
+ new = malloc( sizeof(share_fce_item_t) );
+ new->name = strdup(name);
+ new->function = function;
+
+ return new;
+}
+
+static void destroyShareFce(share_fce_item_t *p)
+{
+ free(p->name);
+ free(p);
+}
+
+void initShareFunction()
+{
+ listShareFce = newList();
+}
+void addToShareFce(char *name, void *function)
+{
+ printf("add to share function %s\n", name);
+
+ addList(listShareFce, newShareFceItem(name, function) );
+}
+
+void* getShareFce(char *name)
+{
+ int i;
+
+ for( i = 0 ; i < listShareFce->count ; i++ )
+ {
+ share_fce_item_t *this;
+
+ this = (share_fce_item_t *)listShareFce->list[i];
+
+ if( strcmp(this->name, name) == 0 )
+ {
+ return this->function;
+ }
+ }
+
+ return NULL;
+}
+
+void quitShareFunction()
+{
+ destroyListItem(listShareFce, destroyShareFce);
+}
+
+
+
diff --git a/src/base/shareFunction.h b/src/base/shareFunction.h
new file mode 100644
index 0000000..fe1907a
--- /dev/null
+++ b/src/base/shareFunction.h
@@ -0,0 +1,13 @@
+
+#ifndef SHARE_FUNCTION_H
+
+#define SHARE_FUNCTION_H
+
+extern void initShareFunction();
+extern void addToShareFce(char *name, void *function);
+
+extern void* getShareFce(char *name);
+extern void quitShareFunction();
+
+#endif
+
diff --git a/src/client/chat.c b/src/client/chat.c
index ade5452..f0bf7a3 100644
--- a/src/client/chat.c
+++ b/src/client/chat.c
@@ -1,11 +1,13 @@
#include <stdlib.h>
#include <assert.h>
+#include <SDL.h>
#include "main.h"
#include "list.h"
#include "myTimer.h"
#include "image.h"
+#include "serverSendMsg.h"
#include "net_multiplayer.h"
#include "screen_world.h"
@@ -13,7 +15,7 @@
#include "interface.h"
#include "chat.h"
#include "font.h"
-#include "serverSendMsg.h"
+#include "keyboardBuffer.h"
static image_t *g_chat;
@@ -25,7 +27,7 @@ static int line_time, line_atime;
static int timeBlick;
static bool_t chat_active;
-static bool_t revicedNewMsg;
+static bool_t receivedNewMsg;
static my_time_t lastActive;
@@ -36,7 +38,7 @@ void initChat()
listText = newList();
strcpy(line, "");
chat_active = FALSE;
- revicedNewMsg = FALSE;
+ receivedNewMsg = FALSE;
line_time = 0;
line_atime = 0;
timeBlick = 0;
@@ -62,7 +64,7 @@ void drawChat()
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);
@@ -85,109 +87,46 @@ void drawChat()
drawFont(str, CHAT_LOCATION_X+5, CHAT_LOCATION_Y+5 + CHAT_MAX_LINES*20, COLOR_WHITE);
}
-static void readKey()
+static void processMessageKey(SDL_keysym keysym)
{
- Uint8 *mapa;
int w, h;
int len;
- int i;
-
- const int len_shift_map = 20;
-
- char shift_map[] =
- {
- '-', '_',
- '=', '+',
- '[', '{',
- ']', '}',
- ';', ':',
- '/', '\"',
- '\\', '|',
- ',', '<',
- '.', '>',
- '/', '?'
- };
+ //int i;
if (line_atime < 100)
line_atime ++;
- mapa = SDL_GetKeyState(NULL);
len = strlen(line);
getTextSize(line, &w, &h);
- for( i = SDLK_FIRST ; i <= SDLK_F15 ; i++ )
+ if( w > CHAT_SIZE_X-40 )
{
- if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
- {
- char *name = (char *) SDL_GetKeyName(i);
- char c = '\0';
-
- if( name == NULL )continue;
-
- if( strlen(name) == 1 )c = name[0];
- if( strlen(name) == 3 )c = name[1];
- if( strcmp(name, "space") == 0 )c = ' ';
-
- //printf("name %s\n", name);
-
- if( strcmp(name, "backspace") == 0 && len > 0 )
- {
- line_time = 0;
- line[len-1]='\0';
- return;
- }
-
- if( c == '\0' || w > CHAT_SIZE_X-40 )
- {
- continue;
- }
-
- if( len > 0 )
- {
- if( line[len-1] == c )
- {
- line_time++;
-
- if( line_time < CHAT_TIME_MULTIPLE )
- {
- if( line_atime < 3 )return;
- }
- }
- else
- {
- line_time = 0;
- }
- }
-
- line_atime = 0;
-
- line[len] = c;
-
- if( mapa[SDLK_LSHIFT] == SDL_PRESSED ||
- mapa[SDLK_RSHIFT] == SDL_PRESSED)
- {
- int i;
-
- for( i = 0 ; i < len_shift_map ; i+= 2 )
- {
- if( c == shift_map[i] )
- {
- line[len] = shift_map[i+1];
- }
- }
+ return;
+ }
- return;
- }
+ /* zpracovani backspace */
+ if (keysym.sym == SDLK_BACKSPACE){
+ line[len-1]='\0';
+ return;
+ }
- if( mapa[SDLK_LSHIFT] == SDL_PRESSED ||
- mapa[SDLK_RSHIFT] == SDL_PRESSED)
- {
- line[len] -= 32;
- }
+ /* 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 */
+ }
- return;
- }
+ /* zpracovani pismenek */
+ if ( keysym.sym >= SDLK_a && keysym.sym <= SDLK_z){
+ char c = keysym.sym;
+ 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 */
}
+
+ return;
}
static void switchChatActive()
@@ -202,52 +141,87 @@ static void switchChatActive()
}
}
-void eventChat()
+static void sendNewMessage()
{
- Uint8 *mapa;
- my_time_t currentTime;
+ if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
+ {
+ proto_send_chat_client(line);
+ }
- mapa = SDL_GetKeyState(NULL);
- currentTime = getMyTime();
-
- if( mapa[SDLK_RETURN] == SDL_PRESSED &&
- strcmp(line, "") == 0 &&
- currentTime - lastActive > CHAT_LAST_ENTER_INTERVAL )
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- lastActive = getMyTime();
- revicedNewMsg = FALSE;
+ char out[STR_PROTO_SIZE];
+
+ snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n",
+ getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line);
+
+ proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
+ }
+}
+
+static void eventChatDisable()
+{
+ Uint8 *mapa;
+ mapa = SDL_GetKeyState(NULL);
+
+ if( mapa[SDLK_RETURN] == SDL_PRESSED )
+ { /* chat neni aktivni, tak jej aktivujeme */
+ receivedNewMsg = FALSE;
switchChatActive();
memset(line, '\0', STR_SIZE);
- return;
+ /* zapneme zachytavani klaves do bufferu a vycistime buffer */
+ enableKeyboardBuffer();
+ clearKeyboardBuffer();
}
+}
- if( chat_active == FALSE )
- {
- return;
- }
+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
+ */
- if( mapa[SDLK_RETURN] == SDL_PRESSED && strcmp(line, "") != 0 )
+ while( isAnyKeyInKeyboardBuffer() == TRUE )
{
- if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
- {
- proto_send_chat_client(line);
- }
+ SDL_keysym key;
+ key = popKeyFromKeyboardBuffer();
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ if ( key.sym == SDLK_RETURN )
{
- char out[STR_PROTO_SIZE];
-
- snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n",
- getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)->name, line);
-
- proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
+ if ( strcmp(line, "") != 0 )
+ { /* mame napsany radek: je potreba jej odeslat */
+ sendNewMessage();
+ memset(line, '\0', STR_SIZE);
+ continue; /* pokracovat s dalsimi klavesami */
+ }
+ else
+ { /* radek je prazdny, je potreba vypnout okno chatu */
+ switchChatActive();
+ memset(line, '\0', STR_SIZE);
+ /* vypneme zachytavani klaves do bufferu a vycistime buffer */
+ disableKeyboardBuffer();
+ clearKeyboardBuffer();
+ }
}
- memset(line, '\0', STR_SIZE);
- return;
+ processMessageKey(key);
}
+}
- readKey();
+/**
+ * Zpracovani "udalosti" chatu?
+ */
+void eventChat()
+{
+ if (isChatActive() == FALSE)
+ { /* okno chatu neni aktivni */
+ eventChatDisable();
+ }
+ else
+ {
+ eventChatEnable();
+ }
}
bool_t isChatActive()
@@ -257,13 +231,13 @@ bool_t isChatActive()
bool_t isRecivedNewMsg()
{
- return revicedNewMsg;
+ return receivedNewMsg;
}
void addToChat(char *s)
{
addList(listText, strdup(s) );
-
+
if( listText->count > CHAT_MAX_LINES )
{
delListItem(listText, 0, free);
@@ -271,7 +245,7 @@ void addToChat(char *s)
if( chat_active == FALSE )
{
- revicedNewMsg = TRUE;
+ receivedNewMsg = TRUE;
}
}
diff --git a/src/client/chat.h b/src/client/chat.h
index f2e1770..fc6abc3 100644
--- a/src/client/chat.h
+++ b/src/client/chat.h
@@ -14,8 +14,6 @@
#define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2)
#define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2)
-#define CHAT_LAST_ENTER_INTERVAL 50
-
extern void initChat();
extern void drawChat();
extern void eventChat();
diff --git a/src/client/interface.c b/src/client/interface.c
index 2c45110..37aa361 100755
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -6,6 +6,7 @@
#include "interface.h"
#include "screen.h"
+#include "keyboardBuffer.h"
// window surface
static SDL_Surface *screen;
@@ -19,6 +20,9 @@ static Uint32 g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
static bool_t isInterfaceInit = FALSE;
+// flag, kterym se ridi zarazovani klaves do bufferu
+bool_t keyboardBufferEnabled = FALSE;
+
bool_t isInterfaceInicialized()
{
return isInterfaceInit;
@@ -37,6 +41,14 @@ static Uint32 TimerCallback(Uint32 interval, void *param)
return interval;
}
+void enableKeyboardBuffer(){
+ keyboardBufferEnabled=TRUE;
+}
+
+void disableKeyboardBuffer(){
+ keyboardBufferEnabled=FALSE;
+}
+
int initSDL()
{
printf("init SDL..\n");
@@ -70,9 +82,11 @@ int initSDL()
SDL_WM_SetCaption(WINDOW_TITLE, NULL);
//SDL_ShowCursor(0);
- SDL_EnableKeyRepeat(1,1);
+ SDL_EnableKeyRepeat(0,1);
timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
+ initKeyboardBuffer(KEYBOARD_BUFFER_SIZE);
+
srand((unsigned)time(NULL));
isInterfaceInit = TRUE;
@@ -199,6 +213,9 @@ int eventAction()
break;
default:
+ //neni potreba vyuzivat frontu stale
+ if (keyboardBufferEnabled==TRUE)
+ pushKeyToKeyboardBuffer(event.key.keysym);
break;
}
break;
@@ -252,6 +269,9 @@ void eventSDL()
void quitSDL()
{
printf("quit SDL..\n");
+ quitKeyboardBuffer();
+
SDL_Quit();
+
isInterfaceInit = FALSE;
}
diff --git a/src/client/interface.h b/src/client/interface.h
index cabc2a7..29d51af 100755
--- a/src/client/interface.h
+++ b/src/client/interface.h
@@ -26,7 +26,12 @@
// interval (in ms) of triggering akcia();
#define INTERVAL 50
+// velikost klavesoveho bufferu (ve znacich)
+#define KEYBOARD_BUFFER_SIZE 256
+
extern bool_t isInterfaceInicialized();
+extern void enableKeyboardBuffer();
+extern void disableKeyboardBuffer();
extern int initSDL();
extern SDL_Surface* getSDL_Screen();
extern void getMousePosition(int *x, int *y);
diff --git a/src/client/keyboardBuffer.c b/src/client/keyboardBuffer.c
new file mode 100644
index 0000000..29cd9d4
--- /dev/null
+++ b/src/client/keyboardBuffer.c
@@ -0,0 +1,138 @@
+/*
+ * keyboardBuffer.c
+ *
+ * Created on: 1.8.2008
+ * Author: Karel Podvolecky
+ *
+ * Jednoducha fronta stisknutych klaves.
+ *
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <SDL.h>
+
+#include "keyboardBuffer.h"
+
+static keyboardBuffer_t *keyboardBuffer=NULL;
+
+static SDL_keysym emptyKey;
+
+/*
+ * Inicializuje klavesovy buffer. Parametr udava pocet klaves.
+ */
+void initKeyboardBuffer(uint32_t size){
+ assert(size>0);
+ assert(keyboardBuffer==NULL);
+
+ keyboardBuffer = malloc(sizeof(keyboardBuffer_t));
+ assert(keyboardBuffer!=NULL);
+ memset(keyboardBuffer, 0, sizeof(keyboardBuffer_t));
+
+ keyboardBuffer->buff = malloc(size * sizeof(SDL_keysym));
+ assert(keyboardBuffer->buff!=NULL);
+ memset(keyboardBuffer->buff, 0, size * sizeof(SDL_keysym));
+
+ keyboardBuffer->begin=0;
+ keyboardBuffer->end=0;
+ keyboardBuffer->count=0;
+ keyboardBuffer->size=size;
+
+ emptyKey.sym = SDLK_UNKNOWN;
+}
+
+/*
+ * Vyprazdni buffer.
+ */
+void clearKeyboardBuffer(){
+ assert(keyboardBuffer!=NULL);
+
+ 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.
+ */
+bool_t pushKeyToKeyboardBuffer(SDL_keysym key){
+ assert(keyboardBuffer!=NULL);
+
+ if (keyboardBuffer->count >= keyboardBuffer->size){
+ fprintf(stderr, "Preteceni klavesoveho bufferu! Zahazuji klavesu: %02x\n", key.sym);
+ return FALSE;
+ }
+
+ keyboardBuffer->buff[keyboardBuffer->end] = key;
+
+ keyboardBuffer->end++;
+ if (keyboardBuffer->end>=keyboardBuffer->size)
+ keyboardBuffer->end=0;
+
+ keyboardBuffer->count++;
+
+ return TRUE;
+}
+
+/*
+ * Vyjme prvni klavesu z bufferu a vrati ji. Pokud je buffer prazdny,
+ * vypise chybu na chybovy vystup a vrati SDLK_UNKNOWN
+ */
+SDL_keysym popKeyFromKeyboardBuffer(){
+ assert(keyboardBuffer!=NULL);
+
+ if (keyboardBuffer->count <= 0){
+ fprintf(stderr, "Podteceni klavesoveho bufferu!\n");
+ return emptyKey;
+ }
+
+ SDL_keysym key = keyboardBuffer->buff[keyboardBuffer->begin];
+ keyboardBuffer->buff[keyboardBuffer->begin]=emptyKey;
+
+ keyboardBuffer->begin++;
+ if (keyboardBuffer->begin>=keyboardBuffer->size)
+ keyboardBuffer->begin=0;
+
+ keyboardBuffer->count--;
+
+ return key;
+}
+
+/*
+ * Velikost bufferu.
+ */
+uint32_t getKeyboardBufferSize(){
+ assert(keyboardBuffer!=NULL);
+ return keyboardBuffer->size;
+}
+
+/*
+ * Pocet klaves v bufferu.
+ */
+uint32_t KeyboardBufferCount(){
+ assert(keyboardBuffer!=NULL);
+ return keyboardBuffer->count;
+}
+
+
+bool_t isAnyKeyInKeyboardBuffer(){
+ return KeyboardBufferCount()>0 ? TRUE : FALSE;
+}
+
+/*
+ * Uvolni buffer. Pokud neni prazdny, vypise predtim
+ * info o zaplneni na chybovy vystup.
+ */
+void quitKeyboardBuffer(){
+ assert(keyboardBuffer!=NULL);
+
+ if (keyboardBuffer->count>0){
+ fprintf(stderr, "Klavesovy buffer neni prazdny!\n");
+ }
+
+ free(keyboardBuffer->buff);
+ free(keyboardBuffer);
+ keyboardBuffer=NULL;
+}
diff --git a/src/client/keyboardBuffer.h b/src/client/keyboardBuffer.h
new file mode 100644
index 0000000..13b1183
--- /dev/null
+++ b/src/client/keyboardBuffer.h
@@ -0,0 +1,34 @@
+/*
+ * keyboardBuffer.h
+ *
+ * Created on: 1.8.2008
+ * Author: Karel Podvolecky
+ *
+ * Jednoducha fronta stisknutych klaves.
+ */
+
+#ifndef KEYBOARD_BUFFER_H
+
+#define KEYBOARD_BUFFER_H
+
+#include <SDL.h>
+#include "main.h"
+
+typedef struct {
+ SDL_keysym *buff; /* buffer klaves (kod dle SDLKey enumu) */
+ uint32_t size; /* aktualni velikost alokovaneho bufferu (v poctu uchovatelnych klaves) */
+ uint32_t count; /* pocet klaves aktualne v bufferu */
+ uint32_t begin; /* ukazatel na zacatek bufferu (tj. kam se pridavaji klavesy) */
+ uint32_t end; /* ukazatel na konec bufferu (tj. odkud se odebiraji klavesy) */
+} keyboardBuffer_t;
+
+extern void initKeyboardBuffer(uint32_t size);
+extern void clearKeyboardBuffer();
+extern bool_t pushKeyToKeyboardBuffer(SDL_keysym key);
+extern SDL_keysym popKeyFromKeyboardBuffer();
+extern uint32_t getKeyboardBufferSize();
+extern uint32_t KeyboardBufferCount();
+extern bool_t isAnyKeyInKeyboardBuffer();
+extern void quitKeyboardBuffer();
+
+#endif /* KEYBOARDBUFFER_H_ */
diff --git a/src/modules/modMove.c b/src/modules/modMove.c
index 0f7c0d9..ed42886 100755
--- a/src/modules/modMove.c
+++ b/src/modules/modMove.c
@@ -202,8 +202,8 @@ int init(export_fce_t *p)
{
export_fce = p;
- export_fce->fce_addToExportFce("move_tux", (void *)move_tux);
- export_fce->fce_addToExportFce("move_shot", (void *)move_shot);
+ export_fce->fce_addToShareFce("move_tux", (void *)move_tux);
+ export_fce->fce_addToShareFce("move_shot", (void *)move_shot);
return 0;
}
diff --git a/src/modules/modPipe.c b/src/modules/modPipe.c
index 50db335..fb7eaf2 100755
--- a/src/modules/modPipe.c
+++ b/src/modules/modPipe.c
@@ -195,7 +195,7 @@ int init(export_fce_t *p)
return -1;
}
- if( ( fce_move_shot = export_fce->fce_getExportFce("move_shot") ) == NULL )
+ if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL )
{
return -1;
}
diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c
index 53b3369..3dafd77 100755
--- a/src/modules/modTeleport.c
+++ b/src/modules/modTeleport.c
@@ -228,12 +228,12 @@ int init(export_fce_t *p)
return -1;
}
- if( ( fce_move_tux = export_fce->fce_getExportFce("move_tux") ) == NULL )
+ if( ( fce_move_tux = export_fce->fce_getShareFce("move_tux") ) == NULL )
{
return -1;
}
- if( ( fce_move_shot = export_fce->fce_getExportFce("move_shot") ) == NULL )
+ if( ( fce_move_shot = export_fce->fce_getShareFce("move_shot") ) == NULL )
{
return -1;
}
diff --git a/src/server/logFile.c b/src/server/logFile.c
deleted file mode 100644
index 12a4df8..0000000
--- a/src/server/logFile.c
+++ /dev/null
@@ -1,46 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <assert.h>
-
-typedef struct logFile_struct
-{
- char *name;
- FILE *file;
-} logFile_t;
-
-logFile_t* newLogFile(char *s)
-{
- logFile_t *new;
-
- assert( s != NULL );
-
- new = malloc( sizeof(logFile_t) );
- memset(new, 0, sizeof(logFile_t) );
-
- new->name = strdup(s);
- new->file = fopen(new->name, "a+");
-
- assert( new->file != NULL );
-
- return new;
-}
-
-int writeLog(logFile_t *p, char *s)
-{
- assert( p != NULL );
- assert( s != NULL );
-
- return fprintf(p->file, s);
-}
-
-void destroyLogFile(logFile_t *p)
-{
- assert( p != NULL );
-
- free(p->name);
- fclose(p->file);
- free(p);
-}
diff --git a/src/server/logFile.h b/src/server/logFile.h
deleted file mode 100644
index 12f5606..0000000
--- a/src/server/logFile.h
+++ /dev/null
@@ -1,18 +0,0 @@
-
-#ifndef LOGFILE_H
-
-#define LOGFILE_H
-
-#include "main.h"
-
-typedef struct logFile_struct
-{
- char *name;
- FILE *file;
-} logFile_t;
-
-extern logFile_t* newLogFile(char *s);
-extern int writeLog(logFile_t *p, char *s);
-extern void destroyLogFile(logFile_t *p);
-
-#endif
diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c
index 5b6f82d..793c76a 100644
--- a/src/widget/widget_catchkey.c
+++ b/src/widget/widget_catchkey.c
@@ -47,7 +47,14 @@ void drawWidgetCatchkey(widget_catchkey_t *p)
name = "no key";
}
- drawFont(name, p->x, p->y, COLOR_WHITE);
+ if( p->active )
+ {
+ drawFont(name, p->x, p->y, COLOR_RED);
+ }
+ else
+ {
+ drawFont(name, p->x, p->y, COLOR_WHITE);
+ }
}
static int getPessAnyKey()