summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base/Makefile5
-rw-r--r--src/base/index.c249
-rw-r--r--src/base/index.h15
-rw-r--r--src/base/protect.c3
-rw-r--r--src/base/space.c292
-rw-r--r--src/base/space.h5
-rw-r--r--src/client/game.c3
-rwxr-xr-xsrc/modules/Makefile27
-rwxr-xr-xsrc/modules/list.c241
-rwxr-xr-xsrc/modules/list.h33
-rw-r--r--src/modules/space.c625
-rw-r--r--src/modules/space.h38
-rw-r--r--src/screen/Makefile6
-rw-r--r--src/screen/screen_browser.c396
-rw-r--r--src/screen/screen_browser.h36
-rw-r--r--src/screen/screen_gameType.c33
-rw-r--r--src/screen/screen_gameType.h3
-rw-r--r--src/widget/widget_textfield.c74
-rw-r--r--src/widget/widget_textfield.h2
19 files changed, 839 insertions, 1247 deletions
diff --git a/src/base/Makefile b/src/base/Makefile
index 6de422d..d9998a6 100644
--- a/src/base/Makefile
+++ b/src/base/Makefile
@@ -1,5 +1,5 @@
-all: arena.o arenaFile.o director.o gun.o homeDirector.o checkFront.o idManager.o item.o list.o main.o modules.o myTimer.o net_multiplayer.o protect.o proto.o server.o shot.o space.o storage.o textFile.o tux.o
+all: arena.o arenaFile.o director.o gun.o homeDirector.o checkFront.o idManager.o item.o index.o list.o main.o modules.o myTimer.o net_multiplayer.o protect.o proto.o server.o shot.o space.o storage.o textFile.o tux.o
arena.o: arena.c arena.h
$(CC) $(CFLAGS) -o arena.o -c arena.c
@@ -25,6 +25,9 @@ idManager.o: idManager.c idManager.h
item.o: item.c item.h
$(CC) $(CFLAGS) -o item.o -c item.c
+index.o: index.c index.h
+ $(CC) $(CFLAGS) -o index.o -c index.c
+
list.o: list.c list.h
$(CC) $(CFLAGS) -o list.o -c list.c
diff --git a/src/base/index.c b/src/base/index.c
new file mode 100644
index 0000000..d3f75a5
--- /dev/null
+++ b/src/base/index.c
@@ -0,0 +1,249 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "index.h"
+
+static int* index_newInt(int x)
+{
+ int *new;
+ new = malloc( sizeof(int) );
+ *new = x;
+ return new;
+}
+
+static void printIndex(list_t *list)
+{
+ int i;
+
+ printf("printIndex\n");
+
+ for( i = 0 ; i < list->count ; i++ )
+ {
+ int thisIndex;
+
+ thisIndex = *(int *)list->list[i];
+ printf("%d\n", thisIndex);
+ }
+}
+
+static void checkIndex(list_t *list)
+{
+ int index, thisIndex;
+ int i;
+
+ if( list->count == 0 )
+ {
+ printf("nothing\n");
+ return;
+ }
+
+ thisIndex = *(int *)list->list[0];
+
+ for( i = 1 ; i < list->count ; i++ )
+ {
+ index = *(int *)list->list[i];
+
+ if( index <= thisIndex )
+ {
+ printIndex(list);
+ assert( ! "error" );
+ }
+
+ thisIndex = index;
+ }
+}
+
+list_t* newIndex()
+{
+ return newList();
+}
+
+int addToIndex(list_t *list, int index)
+{
+ int point_index, inc_point_index;
+ int len;
+ int min, max;
+ int point;
+
+ len = list->count;
+
+ //printf("addToIndex (%p, %d)\n", list, index);
+ //printIndex(list);
+
+ if( len == 0 )
+ {
+ //printf("OK first\n");
+ addList(list, index_newInt(index));
+ checkIndex(list);
+ return 0;
+ }
+
+ if( len == 1 )
+ {
+ //space->getStatus(space->list->list[0], &point_id, &x, &y, &w, &h);
+ point_index = *(int *)list->list[0];
+
+ if( index > point_index )
+ {
+ addList(list, index_newInt(index));
+ //checkIndex(list);
+ return 1;
+ }
+
+ if( index < point_index )
+ {
+ insList(list, 0, index_newInt(index));
+ //checkIndex(list);
+ return 0;
+ }
+
+ //printf("OK\n")
+ return -1;
+ }
+
+ min = 0;
+ max = len-1;
+/*
+ if( max < 0 )
+ {
+ max = 0;
+ }
+*/
+ for(;;)
+ {
+ point = min + ( max - min ) / 2;
+/*
+ space->getStatus(space->list->list[min], &id_min, &x, &y, &w, &h);
+ space->getStatus(space->list->list[max], &id_max, &x, &y, &w, &h);
+*/
+ //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
+
+ if( max < 0 )
+ {
+ //printf("OK first\n");
+ insList(list, 0, index_newInt(index));
+ //checkIndex(list);
+ return 0;
+ }
+
+ if( point+1 >= len /*|| min >= len*/ )
+ {
+ addList(list, index_newInt(index) );
+ //printf("OK height\n");
+ //checkIndex(list);
+ return len;
+ }
+
+// space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
+// space->getStatus(space->list->list[point+1], &inc_point_id, &x, &y, &w, &h);
+
+ point_index = *(int *)list->list[point];
+ inc_point_index = *(int *)list->list[point+1];
+/*
+ if( min == max )
+ {
+ //printf("OK\n");
+ insList(space->list, min, p);
+ checkList(space);
+ return;
+ }
+*/
+ if( point_index < index && index < inc_point_index )
+ {
+ //printf("OK\n");
+ insList(list, point+1, index_newInt(index) );
+ //checkIndex(list);
+ return point+1;
+ }
+
+ if( index > inc_point_index )
+ {
+ min = point + 1;
+ continue;
+ }
+
+ if( index < point_index )
+ {
+ max = point - 1;
+ continue;
+ }
+ }
+}
+
+int getFormIndex(list_t *list, int index)
+{
+ int point_index;
+ int len;
+ int min, max;
+ int point;
+
+
+ //printf("getFormIndex %d\n", index);
+ //printIndex(list);
+
+ len =list->count;
+
+ min = 0;
+ max = len-1;
+
+ for(;;)
+ {
+ point = min + ( max - min ) / 2;
+
+ //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
+
+ if( max < 0 || point >= len || max < min )
+ {
+ return -1;
+ }
+
+ //space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
+
+ point_index = *(int *)list->list[point];
+
+ if( min == max )
+ {
+ //space->getStatus(space->list->list[min], &point_id, &x, &y, &w, &h);
+ point_index = *(int *)list->list[point];
+ }
+
+ if( point_index == index )
+ {
+ return point;
+ }
+
+ if( index > point_index )
+ {
+ min = point + 1;
+ continue;
+ }
+
+ if( index < point_index )
+ {
+ max = point - 1;
+ continue;
+ }
+ }
+}
+
+void delFromIndex(list_t *list, int index)
+{
+ int offset;
+
+ offset = getFormIndex(list, index);
+ assert( offset != -1 );
+
+ delListItem(list, offset, free);
+}
+
+void destroyIndex(list_t *list)
+{
+ assert( list != NULL);
+
+ destroyListItem(list, free);
+}
diff --git a/src/base/index.h b/src/base/index.h
new file mode 100644
index 0000000..3799aa3
--- /dev/null
+++ b/src/base/index.h
@@ -0,0 +1,15 @@
+
+#ifndef INDEX_H
+
+#define INDEX_H
+
+#include "main.h"
+#include "list.h"
+
+extern list_t* newIndex();
+extern int addToIndex(list_t *list, int index);
+extern int getFormIndex(list_t *list, int index);
+extern void delFromIndex(list_t *list, int index);
+extern void destroyIndex(list_t *list);
+
+#endif
diff --git a/src/base/protect.c b/src/base/protect.c
index 074873a..7da70bb 100644
--- a/src/base/protect.c
+++ b/src/base/protect.c
@@ -42,11 +42,12 @@ void refreshLastMove(protect_t *p)
p->avarage = 0;
p->count = 0;
+#if 0
if( index < PROTECT_SPEED_INTERVAL_TIMEOUT )
{
p->isDown = TRUE;
}
-
+#endif
//printf("speed index = %d\n", index);
}
}
diff --git a/src/base/space.c b/src/base/space.c
index aeae784..b32ae33 100644
--- a/src/base/space.c
+++ b/src/base/space.c
@@ -7,68 +7,7 @@
#include "main.h"
#include "list.h"
#include "space.h"
-
-#define DEBUG_SPACE
-#define ERROR_SUPPORT
-
-#ifdef DEBUG_SPACE
-
-
-typedef struct recv_struct
-{
- int id;
- int x, y;
- int w, h;
-} recv_t;
-
-recv_t* newRecv(int id, int x , int y, int w, int h)
-{
- recv_t *new;
-
- new = malloc( sizeof(recv_t) );
- memset(new, 0, sizeof(recv_t));
-
- new->id = id;
- new->x = x;
- new->y = y;
- new->w = w;
- new->h = h;
-
- return new;
-}
-
-void getStatus(void *p, int *id, int *x, int *y, int *w, int *h)
-{
- recv_t *recv;
-
- recv = p;
-
- *id = recv->id;
- *x = recv->x;
- *y = recv->y;
- *w = recv->w;
- *h = recv->h;
-}
-
-void setStatus(void *p, int x, int y, int w, int h)
-{
- recv_t *recv;
-
- recv = p;
-
- recv->x = x;
- recv->y = y;
- recv->w = w;
- recv->h = h;
- recv->x = x;
-}
-
-void destroyRecv(recv_t *p)
-{
- free(p);
-}
-
-#endif
+#include "index.h"
static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
{
@@ -92,6 +31,7 @@ space_t *newSpace(int w, int h, int segW, int segH,
new->getStatus = getStatus;
new->setStatus = setStatus;
new->list = newList();
+ new->listIndex = newIndex();
new->area = malloc( new->w * sizeof(list_t **) );
@@ -120,167 +60,12 @@ static void getSegment(space_t *p, int x, int y, int w, int h,
*segH = ( (y+h) / p->segH + 1 ) - *segY;
}
-#ifdef ERROR_SUPPORT
-
-void printListID(space_t *space)
-{
- int i;
-
- for( i = 0 ; i < space->list->count ; i++ )
- {
- int id, x, y, w, h;
-
- space->getStatus(space->list->list[i], &id, &x, &y, &w, &h);
- printf("%d\n", id);
- }
-
- putchar('\n');
-}
-
-static void checkList(space_t *space)
-{
- int id, x, y, w, h;
- int thisId;
- int i;
-
- if( space->list->count == 0 )
- {
- printf("nothing\n");
- return;
- }
-
- space->getStatus(space->list->list[0], &thisId, &x, &y, &w, &h);
-
- for( i = 1 ; i < space->list->count ; i++ )
- {
- space->getStatus(space->list->list[i], &id, &x, &y, &w, &h);
-
- if( id <= thisId )
- {
- printListID(space);
- assert( ! "error" );
- }
-
- thisId = id;
- }
-}
-
-static void addToListOnTheBaseIndex(space_t *space, void *p)
-{
- int id, point_id, inc_point_id;
- int x, y, w, h;
- int len;
- int min, max;
- int point;
-
-
- len = space->list->count;
-
- space->getStatus(p, &id, &x, &y, &w, &h);
-/*
- printf("addToListOnTheBaseIndex (%d)\n", id);
- printListID(space);
- assert( id >= 0 );
-*/
- if( len == 0 )
- {
- //printf("OK first\n");
- addList(space->list, p);
- return;
- }
-
- if( len == 1 )
- {
- space->getStatus(space->list->list[0], &point_id, &x, &y, &w, &h);
-
- if( id > point_id )
- {
- addList(space->list, p);
- }
-
- if( id < point_id )
- {
- insList(space->list, 0, p);
- }
-
- //printf("OK\n");
-
- return;
- }
-
- min = 0;
- max = len-1;
-/*
- if( max < 0 )
- {
- max = 0;
- }
-*/
- for(;;)
- {
- point = min + ( max - min ) / 2;
-/*
- space->getStatus(space->list->list[min], &id_min, &x, &y, &w, &h);
- space->getStatus(space->list->list[max], &id_max, &x, &y, &w, &h);
-*/
- //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
-
- if( max < 0 )
- {
- //printf("OK first\n");
- insList(space->list, 0, p);
- //checkList(space);
- return;
- }
-
- if( point+1 >= len /*|| min >= len*/ )
- {
- addList(space->list, p);
- //printf("OK height\n");
- //checkList(space);
- return;
- }
-
- space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
- space->getStatus(space->list->list[point+1], &inc_point_id, &x, &y, &w, &h);
-/*
- if( min == max )
- {
- //printf("OK\n");
- insList(space->list, min, p);
- checkList(space);
- return;
- }
-*/
- if( point_id < id && id < inc_point_id )
- {
- //printf("OK\n");
- insList(space->list, point+1, p);
- //checkList(space);
- return;
- }
-
- if( id > inc_point_id )
- {
- min = point + 1;
- continue;
- }
-
- if( id < point_id )
- {
- max = point - 1;
- continue;
- }
- }
-}
-
-#endif
-
void addObjectToSpace(space_t *p, void *item)
{
int segX, segY, segW, segH;
int id, x, y, w, h;
int i, j;
+ int offset;
p->getStatus(item, &id, &x, &y, &w, &h);
getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
@@ -298,13 +83,8 @@ void addObjectToSpace(space_t *p, void *item)
}
}
-#ifdef ERROR_SUPPORT
- addToListOnTheBaseIndex(p, item);
-#endif
-
-#ifndef ERROR_SUPPORT
- addList(p->list, item);
-#endif
+ offset = addToIndex(p->listIndex, id);
+ insList(p->list, offset, item);
}
void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
@@ -341,65 +121,11 @@ void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
}
}
-int searchObjectInSpace(space_t *space, int id)
-{
- int point_id;
- int x, y, w, h;
- int len;
- int min, max;
- int point;
-
-/*
- printf("getObjectFromSpaceWithID %d\n", id);
- printListID(space);
-*/
- len = space->list->count;
-
- min = 0;
- max = len-1;
-
- for(;;)
- {
- point = min + ( max - min ) / 2;
-
- //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
-
- if( max < 0 || point >= len || max < min )
- {
- return -1;
- }
-
- space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
-
- if( min == max )
- {
- space->getStatus(space->list->list[min], &point_id, &x, &y, &w, &h);
- }
-
- if( point_id == id )
- {
- return point;
- }
-
- if( id > point_id )
- {
- min = point + 1;
- continue;
- }
-
- if( id < point_id )
- {
- max = point - 1;
- continue;
- }
- }
-}
-
void* getObjectFromSpaceWithID(space_t *space, int id)
{
int index;
- index = searchObjectInSpace(space, id);
+ index = getFormIndex(space->listIndex, id);
return ( index != -1 ? space->list->list[index] : NULL );
}
@@ -505,9 +231,12 @@ void delObjectFromSpace(space_t *p, void *item)
}
}
- index = searchObjectInSpace(p, id);
+ index = getFormIndex(p->listIndex, id);
assert( index != -1 );
+
delList(p->list, index);
+
+ delFromIndex(p->listIndex, id);
}
void delObjectFromSpaceWithObject(space_t *p, void *item, void *f)
@@ -568,6 +297,7 @@ void destroySpace(space_t *p)
int j, i;
destroyList(p->list);
+ destroyIndex(p->listIndex);
for( i = 0 ; i < p->h ; i++ )
{
diff --git a/src/base/space.h b/src/base/space.h
index de31768..be21411 100644
--- a/src/base/space.h
+++ b/src/base/space.h
@@ -10,10 +10,15 @@ typedef struct space_struct
{
int w;
int h;
+
int segW;
int segH;
+
list_t ***area;
+
list_t *list;
+ list_t *listIndex;
+
void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h);
void (*setStatus)(void *p, int x, int y, int w, int h);
} space_t;
diff --git a/src/client/game.c b/src/client/game.c
index 9ea50ab..7ea9145 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -36,6 +36,7 @@
#include "screen/screen_choiceArena.h"
#include "screen/screen_table.h"
#include "screen/screen_credits.h"
+#include "screen/screen_browser.h"
static void initGame()
{
@@ -72,6 +73,7 @@ static void initGame()
initScreenChoiceArena();
initScreenCredits();
initScreenTable();
+ initScreenBrowser();
}
void quitGame()
@@ -101,6 +103,7 @@ void quitGame()
quitScreenChoiceArena();
quitScreenCredits();
quitScreenTable();
+ quitScreenBrowser();
destroyList(listHelp);
diff --git a/src/modules/Makefile b/src/modules/Makefile
index ba52738..81f6c54 100755
--- a/src/modules/Makefile
+++ b/src/modules/Makefile
@@ -1,27 +1,30 @@
all: modWall.so modPipe.so modTeleport.so modAI.so
-list.o: list.c list.h
- $(CC) $(CFLAGS) -fPIC -o list.o -c list.c
+list.o: ../base/list.c ../base/list.h
+ $(CC) $(CFLAGS) -fPIC -o list.o -c ../base/list.c
-space.o: space.c space.h
- $(CC) $(CFLAGS) -fPIC -o space.o -c space.c
+space.o: ../base/space.c ../base/space.h
+ $(CC) $(CFLAGS) -fPIC -o space.o -c ../base/space.c
-modWall.so: list.o space.o
+index.o: ../base/index.c ../base/index.h
+ $(CC) $(CFLAGS) -fPIC -o index.o -c ../base/index.c
+
+modWall.so: list.o space.o index.o
gcc $(CFLAGS) -fPIC -c modWall.c -o modWall.o
- gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o space.o
+ gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o space.o index.o
-modPipe.so: list.o space.o
+modPipe.so: list.o space.o index.o
gcc $(CFLAGS) -fPIC -c modPipe.c -o modPipe.o
- gcc $(CFLAGS) -I../include -shared -fPIC -o modPipe.so modPipe.o list.o space.o
+ gcc $(CFLAGS) -I../include -shared -fPIC -o modPipe.so modPipe.o list.o space.o index.o
-modTeleport.so: list.o space.o
+modTeleport.so: list.o space.o index.o
gcc $(CFLAGS) -fPIC -c modTeleport.c -o modTeleport.o
- gcc $(CFLAGS) -I../include -shared -fPIC -o modTeleport.so modTeleport.o list.o space.o
+ gcc $(CFLAGS) -I../include -shared -fPIC -o modTeleport.so modTeleport.o list.o space.o index.o
-modAI.so: list.o space.o
+modAI.so: list.o space.o index.o
gcc $(CFLAGS) -fPIC -c modAI.c -o modAI.o
- gcc $(CFLAGS) -I../include -shared -fPIC -o modAI.so modAI.o list.o space.o
+ gcc $(CFLAGS) -I../include -shared -fPIC -o modAI.so modAI.o list.o space.o index.o
clean:
rm -rf *.o
diff --git a/src/modules/list.c b/src/modules/list.c
deleted file mode 100755
index d182210..0000000
--- a/src/modules/list.c
+++ /dev/null
@@ -1,241 +0,0 @@
-
-#include "base/main.h"
-#include "base/list.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-list_t* newList()
-{
- list_t *new;
-
- new = malloc( sizeof(list_t) );
- memset(new, 0, sizeof(list_t) );
-
- return new;
-}
-
-list_t* cloneList(list_t *p)
-{
- list_t *new;
-
- assert( p != NULL );
-
- new = malloc( sizeof(list_t) );
- memcpy(new, p, sizeof(list_t) );
-
- if( p->list != NULL )
- {
- new->list = malloc( p->alloc * sizeof(void *) );
- memcpy(new->list, p->list, p->alloc * sizeof(void *));
- }
-
- return new;
-}
-
-list_t* cloneListItem(list_t *p, void *f)
-{
- list_t *new;
- void* (*fce)(void *);
- int i;
-
- assert( p != NULL );
- assert( f != NULL );
-
- new = cloneList(p);
- fce = f;
-
- for(i = 0 ; i < p->count ; i++)
- new->list[i] = fce(p->list[i]);
-
- return new;
-}
-
-void addList(list_t *p, void *item)
-{
- assert( p != NULL );
-
- if( p->alloc == 0 )
- {
- p->alloc = LIST_ALLOC_LIMIT;
- p->count = 1;
- p->list = malloc(p->alloc * sizeof(void *) );
- p->list[0] = item;
-
- return;
- }
-
- if( p->count + 1 <= p->alloc )
- {
- p->list[p->count] = item;
- p->count += 1;
-
- return;
- }
-
- if( p->count + 1 > p->alloc )
- {
- void **new;
-
-#ifdef DEBUG_LIST
- printf("realokujem z %d na %d (count=%d)\n",
- p->alloc, p->alloc+LIST_ALLOC_LIMIT, p->count);
-#endif
-
- p->alloc += LIST_ALLOC_LIMIT;
- new = malloc(p->alloc * sizeof(void *) );
- memcpy(new, p->list, p->count * sizeof(void *) );
- free(p->list);
- p->list = new;
- p->list[p->count] = item;
- p->count++;
-
- return;
- }
-}
-
-void insList(list_t *p, int n, void *item)
-{
- assert( p != NULL );
-
- addList(p, NULL); // :)
-
- assert( n >= 0 || n < p->count );
-
- memmove(p->list+n+1, p->list+n, ( (p->count-1) - n ) * sizeof(void *));
-
- p->list[n] = item;
-}
-
-void *getList(list_t *p, int n)
-{
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
- return p->list[n];
-}
-
-int searchListItem(list_t *p, void *n)
-{
- int i;
-
- assert( p != NULL );
-
- for( i = 0 ; i < p->count ; i++ )
- if( p->list[i] == n )return i;
-
- return -1;
-}
-
-void delList(list_t *p, int n)
-{
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
- memmove(p->list+n, p->list+n+1, ( (p->count-1) - n ) * sizeof(void *));
-
- p->count--;
-
- if( p->count + LIST_ALLOC_LIMIT < p->alloc )
- {
- void **new;
-
-#ifdef DEBUG_LIST
- printf("realokujem z %d na %d (count=%d)\n",
- p->alloc, p->alloc-LIST_ALLOC_LIMIT, p->count);
-#endif
-
- p->alloc -= LIST_ALLOC_LIMIT;
- new = malloc(p->alloc * sizeof(void *) );
- memcpy(new, p->list, p->count * sizeof(void *) );
- free(p->list);
- p->list = new;
- }
-}
-
-void delListItem(list_t *p, int n, void *f)
-{
- int (*fce)(void *);
-
- assert( p != NULL );
- assert( n >= 0 || n < p->count );
-
- fce = f;
- if( fce != NULL )fce(p->list[n]);
-
- delList(p, n);
-}
-
-void listDoEmpty(list_t *p)
-{
- p->count = 0;
-}
-
-void destroyList(list_t *p)
-{
- assert( p != NULL );
-
- if( p->list != NULL )free(p->list);
- free(p);
-}
-
-void destroyListItem(list_t *p, void *f)
-{
- void (*fce)(void *);
- int i;
-
- assert( p != NULL );
- assert( f != NULL );
-
- fce = f;
-
- for(i = 0 ; i < p->count ; i++)
- fce(p->list[i]);
-
- destroyList(p);
-}
-
-/*
-typedef struct pokus_str
-{
- int x;
-} pokus;
-
-pokus* newPokus(int n)
-{
- pokus *new;
- new = malloc(sizeof(pokus));
- new->x = n;
- return new;
-}
-
-pokus *clonePokus(pokus *p)
-{
- pokus *new;
- new = malloc(sizeof(pokus));
- memcpy(new, p, sizeof(pokus));
- return new;
-}
-
-void destroyPokus(pokus *p)
-{
- free(p);
-}
-
-int main()
-{
- list_t *my;
- int i;
-
- my = newList();
-
- for(i = 0; i < 100; i++)
- addList(my, newPokus(i));
-
- destroyListItem(my, destroyPokus);
-
- return 0;
-}
-*/
diff --git a/src/modules/list.h b/src/modules/list.h
deleted file mode 100755
index 17a8e2d..0000000
--- a/src/modules/list.h
+++ /dev/null
@@ -1,33 +0,0 @@
-
-#ifndef LIST_H
-
-#define LIST_H
-
-#include "base/main.h"
-
-#define LIST_ALLOC_LIMIT 16
-
-typedef struct list_str
-{
- void **list;
- int count;
- int alloc;
-} list_t;
-
-extern list_t* newList();
-extern list_t* cloneList(list_t *p);
-extern list_t* cloneListItem(list_t *p, void *f);
-
-extern void addList(list_t *p, void *item);
-extern void insList(list_t *p, int n, void *item);
-extern void *getList(list_t *p,int n);
-extern int searchListItem(list_t *p, void *n);
-
-extern void delList(list_t *p,int n);
-extern void delListItem(list_t *p,int n,void *f);
-extern void listDoEmpty(list_t *p);
-
-extern void destroyList(list_t *p);
-extern void destroyListItem(list_t *p,void *f);
-
-#endif
diff --git a/src/modules/space.c b/src/modules/space.c
deleted file mode 100644
index 62cfa48..0000000
--- a/src/modules/space.c
+++ /dev/null
@@ -1,625 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "base/main.h"
-#include "modules/list.h"
-#include "modules/space.h"
-
-#define DEBUG_SPACE
-#define ERROR_SUPPORT
-
-#ifdef DEBUG_SPACE
-
-
-typedef struct recv_struct
-{
- int id;
- int x, y;
- int w, h;
-} recv_t;
-
-recv_t* newRecv(int id, int x , int y, int w, int h)
-{
- recv_t *new;
-
- new = malloc( sizeof(recv_t) );
- memset(new, 0, sizeof(recv_t));
-
- new->id = id;
- new->x = x;
- new->y = y;
- new->w = w;
- new->h = h;
-
- return new;
-}
-
-void getStatus(void *p, int *id, int *x, int *y, int *w, int *h)
-{
- recv_t *recv;
-
- recv = p;
-
- *id = recv->id;
- *x = recv->x;
- *y = recv->y;
- *w = recv->w;
- *h = recv->h;
-}
-
-void setStatus(void *p, int x, int y, int w, int h)
-{
- recv_t *recv;
-
- recv = p;
-
- recv->x = x;
- recv->y = y;
- recv->w = w;
- recv->h = h;
- recv->x = x;
-}
-
-void destroyRecv(recv_t *p)
-{
- free(p);
-}
-
-#endif
-
-static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
-{
- return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1);
-}
-
-space_t *newSpace(int w, int h, int segW, int segH,
- void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h),
- void (*setStatus)(void *p, int x, int y, int w, int h))
-{
- space_t *new;
- int i, j;
-
- new = malloc( sizeof(space_t) );
- memset(new, 0, sizeof(space_t));
-
- new->w = w / segW + 1;
- new->h = h / segH + 1;
- new->segW = segW;
- new->segH = segH;
- new->getStatus = getStatus;
- new->setStatus = setStatus;
- new->list = newList();
-
- new->area = malloc( new->w * sizeof(list_t **) );
-
- for( i = 0 ; i < new->w ; i++ )
- {
- new->area[i] = malloc( new->h * sizeof(list_t *) );
- }
-
- for( i = 0 ; i < new->h ; i++ )
- {
- for( j = 0 ; j < new->w ; j++ )
- {
- new->area[j][i] = newList();
- }
- }
-
- return new;
-}
-
-static void getSegment(space_t *p, int x, int y, int w, int h,
- int *segX, int *segY, int *segW, int *segH)
-{
- *segX = x / p->segW;
- *segY = y / p->segH;
- *segW = ( (x+w) / p->segW + 1 ) - *segX;
- *segH = ( (y+h) / p->segH + 1 ) - *segY;
-}
-
-#ifdef ERROR_SUPPORT
-
-void printListID(space_t *space)
-{
- int i;
-
- for( i = 0 ; i < space->list->count ; i++ )
- {
- int id, x, y, w, h;
-
- space->getStatus(space->list->list[i], &id, &x, &y, &w, &h);
- printf("%d\n", id);
- }
-
- putchar('\n');
-}
-
-static void checkList(space_t *space)
-{
- int id, x, y, w, h;
- int thisId;
- int i;
-
- if( space->list->count == 0 )
- {
- printf("nothing\n");
- return;
- }
-
- space->getStatus(space->list->list[0], &thisId, &x, &y, &w, &h);
-
- for( i = 1 ; i < space->list->count ; i++ )
- {
- space->getStatus(space->list->list[i], &id, &x, &y, &w, &h);
-
- if( id <= thisId )
- {
- printListID(space);
- assert( ! "error" );
- }
-
- thisId = id;
- }
-}
-
-static void addToListOnTheBaseIndex(space_t *space, void *p)
-{
- int id, point_id, inc_point_id;
- int x, y, w, h;
- int len;
- int min, max;
- int point;
-
-
- len = space->list->count;
-
- space->getStatus(p, &id, &x, &y, &w, &h);
-/*
- printf("addToListOnTheBaseIndex (%d)\n", id);
- printListID(space);
- assert( id >= 0 );
-*/
- if( len == 0 )
- {
- //printf("OK first\n");
- addList(space->list, p);
- return;
- }
-
- if( len == 1 )
- {
- space->getStatus(space->list->list[0], &point_id, &x, &y, &w, &h);
-
- if( id > point_id )
- {
- addList(space->list, p);
- }
-
- if( id < point_id )
- {
- insList(space->list, 0, p);
- }
-
- //printf("OK\n");
-
- return;
- }
-
- min = 0;
- max = len-1;
-/*
- if( max < 0 )
- {
- max = 0;
- }
-*/
- for(;;)
- {
- point = min + ( max - min ) / 2;
-/*
- space->getStatus(space->list->list[min], &id_min, &x, &y, &w, &h);
- space->getStatus(space->list->list[max], &id_max, &x, &y, &w, &h);
-*/
- //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
-
- if( max < 0 )
- {
- //printf("OK first\n");
- insList(space->list, 0, p);
- //checkList(space);
- return;
- }
-
- if( point+1 >= len /*|| min >= len*/ )
- {
- addList(space->list, p);
- //printf("OK height\n");
- //checkList(space);
- return;
- }
-
- space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
- space->getStatus(space->list->list[point+1], &inc_point_id, &x, &y, &w, &h);
-/*
- if( min == max )
- {
- //printf("OK\n");
- insList(space->list, min, p);
- checkList(space);
- return;
- }
-*/
- if( point_id < id && id < inc_point_id )
- {
- //printf("OK\n");
- insList(space->list, point+1, p);
- //checkList(space);
- return;
- }
-
- if( id > inc_point_id )
- {
- min = point + 1;
- continue;
- }
-
- if( id < point_id )
- {
- max = point - 1;
- continue;
- }
- }
-}
-
-#endif
-
-void addObjectToSpace(space_t *p, void *item)
-{
- int segX, segY, segW, segH;
- int id, x, y, w, h;
- int i, j;
-
- p->getStatus(item, &id, &x, &y, &w, &h);
- getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
-
- for( i = segY ; i < segY + segH ; i++ )
- {
- for( j = segX ; j < segX + segW ; j++ )
- {
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
-
- addList(p->area[j][i], item);
- }
- }
-
-#ifdef ERROR_SUPPORT
- addToListOnTheBaseIndex(p, item);
-#endif
-
-#ifndef ERROR_SUPPORT
- addList(p->list, item);
-#endif
-}
-
-void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list)
-{
- int segX, segY, segW, segH;
- int id, this_x, this_y, this_w, this_h;
- int i, j, k;
-
- getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
-
- for( i = segY ; i < segY + segH ; i++ )
- {
- for( j = segX ; j < segX + segW ; j++ )
- {
- void *this;
-
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
- {
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
-
- this = p->area[j][i]->list[k];
- p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h);
-
- if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) &&
- searchListItem(list, this) == -1 )
- {
- addList(list, this);
- }
- }
- }
- }
-}
-
-int searchObjectInSpace(space_t *space, int id)
-{
- int point_id;
- int x, y, w, h;
- int len;
- int min, max;
- int point;
-
-/*
- printf("getObjectFromSpaceWithID %d\n", id);
- printListID(space);
-*/
- len = space->list->count;
-
- min = 0;
- max = len-1;
-
- for(;;)
- {
- point = min + ( max - min ) / 2;
-
- //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id);
-
- if( max < 0 || point >= len || max < min )
- {
- return -1;
- }
-
- space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h);
-
- if( min == max )
- {
- space->getStatus(space->list->list[min], &point_id, &x, &y, &w, &h);
- }
-
- if( point_id == id )
- {
- return point;
- }
-
- if( id > point_id )
- {
- min = point + 1;
- continue;
- }
-
- if( id < point_id )
- {
- max = point - 1;
- continue;
- }
- }
-}
-
-void* getObjectFromSpaceWithID(space_t *space, int id)
-{
- int index;
-
- index = searchObjectInSpace(space, id);
-
- return ( index != -1 ? space->list->list[index] : NULL );
-}
-
-int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h)
-{
- int segX, segY, segW, segH;
- int id, this_x, this_y, this_w, this_h;
- int i, j, k;
-
- getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
-
- for( i = segY ; i < segY + segH ; i++ )
- {
- for( j = segX ; j < segX + segW ; j++ )
- {
- void *this;
-
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
- {
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
-
- this = p->area[j][i]->list[k];
- p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h);
-
- if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) )
- {
- return 1;
- }
- }
- }
- }
-
- return 0;
-}
-
-int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, void *but)
-{
- int segX, segY, segW, segH;
- int id, this_x, this_y, this_w, this_h;
- int i, j, k;
-
- getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
-
- for( i = segY ; i < segY + segH ; i++ )
- {
- for( j = segX ; j < segX + segW ; j++ )
- {
- void *this;
-
- for( k = 0 ; k < p->area[j][i]->count ; k++ )
- {
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
-
- this = p->area[j][i]->list[k];
-
- if( this == but )
- {
- continue;
- }
-
- p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h);
-
- if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) )
- {
- return 1;
- }
- }
- }
- }
-
- return 0;
-}
-
-void delObjectFromSpace(space_t *p, void *item)
-{
- int segX, segY, segW, segH;
- int id, x, y, w, h;
- int index;
- int i, j;
-
- p->getStatus(item, &id, &x, &y, &w, &h);
- getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH);
-
- for( i = segY ; i < segY + segH ; i++ )
- {
- for( j = segX ; j < segX + segW ; j++ )
- {
- if( j < 0 || j >= p->w || i < 0 || i >= p->h )
- {
- continue;
- }
-
- index = searchListItem(p->area[j][i], item);
- assert( index != -1 );
- delList(p->area[j][i], index);
- }
- }
-
- index = searchObjectInSpace(p, id);
- assert( index != -1 );
- delList(p->list, index);
-}
-
-void delObjectFromSpaceWithObject(space_t *p, void *item, void *f)
-{
- void (*fce)(void *param);
-
- fce = f;
-
- delObjectFromSpace(p, item);
- fce(item);
-}
-
-void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y)
-{
- int old_segX, old_segY, old_segW, old_segH;
- int new_segX, new_segY, new_segW, new_segH;
- int id, x, y, w, h;
-
- p->getStatus(item, &id, &x, &y, &w, &h);
- getSegment(p, x, y, w, h, &old_segX, &old_segY, &old_segW, &old_segH);
- getSegment(p, move_x, move_y, w, h, &new_segX, &new_segY, &new_segW, &new_segH);
-/*
- printf("%d %d %d %d -> %d %d %d %d \n",
- old_segX, old_segY, old_segW, old_segH,
- new_segX, new_segY, new_segW, new_segH);
-*/
- if( old_segX != new_segX || old_segY != new_segY ||
- old_segW != new_segW || old_segH != new_segH )
- {
- delObjectFromSpace(p, item);
- p->setStatus(item, move_x, move_y, w, h);
- addObjectToSpace(p, item);
- return;
- }
-
- p->setStatus(item, move_x, move_y, w, h);
-}
-
-void printSpace(space_t *p)
-{
- int i, j;
-
- printf("print space : \n");
-
- for( i = 0 ; i < p->h ; i++ )
- {
- for( j = 0 ; j < p->w ; j++ )
- {
- printf("%3d ", p->area[j][i]->count);
- }
-
- putchar('\n');
- }
-}
-
-void destroySpace(space_t *p)
-{
- int j, i;
-
- destroyList(p->list);
-
- for( i = 0 ; i < p->h ; i++ )
- {
- for( j = 0 ; j < p->w ; j++ )
- {
- destroyList(p->area[j][i]);
- }
- }
-
- for( i = 0 ; i < p->w ; i++ )
- {
- free(p->area[i]);
- }
-
- free(p->area);
- free(p);
-}
-
-void destroySpaceWithObject(space_t *p, void *f)
-{
- void (*fce)(void *param);
- int i;
-
- fce = f;
-
- for( i = 0 ; i < p->list->count ; i++ )
- fce(p->list->list[i]);
-
- destroySpace(p);
-}
-
-#ifdef DEBUG_SPACE
-
-void test_space()
-{/*
- space_t *space;
- recv_t *recv;
-
- space = newSpace(5000, 2500, 320, 240, getStatus, setStatus);
-
- addObjectToSpace(space, newRecv(5, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(7, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(8, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(9, 0, 0, 1, 1) );
- addObjectToSpace(space, newRecv(6, 0, 0, 1, 1) );
-*/
-/*
- recv = getObjectFromSpaceWithID(space, 6);
- if( recv != NULL )printf("id = %d\n", recv->id);
-*/
-// printListID(space);
-}
-
-#endif
-
diff --git a/src/modules/space.h b/src/modules/space.h
deleted file mode 100644
index 35d55a4..0000000
--- a/src/modules/space.h
+++ /dev/null
@@ -1,38 +0,0 @@
-
-#ifndef SPACE_H
-
-#define SPACE_H
-
-#include "base/main.h"
-#include "modules/list.h"
-
-typedef struct space_struct
-{
- int w;
- int h;
- int segW;
- int segH;
- list_t ***area;
- list_t *list;
- void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h);
- void (*setStatus)(void *p, int x, int y, int w, int h);
-} space_t;
-
-extern space_t *newSpace(int w, int h, int segW, int segH,
- void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h),
- void (*setStatus)(void *p, int x, int y, int w, int h));
-
-extern void addObjectToSpace(space_t *p, void *item);
-extern void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list);
-extern void* getObjectFromSpaceWithID(space_t *p, int id);
-extern int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h);
-extern int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, void *but);
-extern void delObjectFromSpace(space_t *p, void *item);
-extern void delObjectFromSpaceWithObject(space_t *p, void *item, void *f);
-extern void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y);
-extern void printSpace(space_t *p);
-extern void destroySpace(space_t *p);
-extern void destroySpaceWithObject(space_t *p, void *f);
-
-#endif
-
diff --git a/src/screen/Makefile b/src/screen/Makefile
index 41c8ae1..32fb758 100644
--- a/src/screen/Makefile
+++ b/src/screen/Makefile
@@ -1,9 +1,12 @@
-all: screen_analyze.o screen_credits.o screen_gameType.o screen_choiceArena.o screen_mainMenu.o screen_setting.o screen_table.o screen_world.o
+all: screen_analyze.o screen_browser.o screen_credits.o screen_gameType.o screen_choiceArena.o screen_mainMenu.o screen_setting.o screen_table.o screen_world.o
screen_analyze.o: screen_analyze.c screen_analyze.h
$(CC) $(CFLAGS) -o screen_analyze.o -c screen_analyze.c
+screen_browser.o: screen_browser.c screen_browser.h
+ $(CC) $(CFLAGS) -o screen_browser.o -c screen_browser.c
+
screen_credits.o: screen_credits.c screen_credits.h
$(CC) $(CFLAGS) -o screen_credits.o -c screen_credits.c
@@ -22,7 +25,6 @@ screen_table.o: screen_table.c screen_table.h
screen_world.o: screen_world.c screen_world.h
$(CC) $(CFLAGS) -o screen_world.o -c screen_world.c
-
clean:
rm -rf *.o
diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c
new file mode 100644
index 0000000..602881f
--- /dev/null
+++ b/src/screen/screen_browser.c
@@ -0,0 +1,396 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/textFile.h"
+#include "base/homeDirector.h"
+#include "base/net_multiplayer.h"
+
+#include "client/language.h"
+#include "client/interface.h"
+#include "client/screen.h"
+#include "client/image.h"
+
+#ifdef SUPPORT_NET_UNIX_UDP
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "net_unix/udp.h"
+#endif
+
+#ifndef NO_SOUND
+#include "audio/music.h"
+#endif
+
+#include "screen/screen_gameType.h"
+#include "screen/screen_browser.h"
+
+#include "widget/widget_image.h"
+#include "widget/widget_label.h"
+#include "widget/widget_button.h"
+#include "widget/widget_select.h"
+
+#define SERVER_TIMEOUT 200
+
+static widget_image_t *image_backgorund;
+
+static widget_button_t *button_play;
+static widget_button_t *button_back;
+
+static widget_label_t *label_server;
+
+static widget_select_t *select_server;
+
+static server_t server_list;
+
+static int LoadServers ();
+static server_t *server_getcurr ();
+
+void startScreenBrowser()
+{
+#ifndef NO_SOUND
+ playMusic("menu", MUSIC_GROUP_BASE);
+#endif
+
+ LoadServers ();
+}
+
+void drawScreenBrowser()
+{
+ drawWidgetImage(image_backgorund);
+
+ drawWidgetLabel(label_server);
+
+ drawWidgetSelect(select_server);
+
+ drawWidgetButton(button_play);
+ drawWidgetButton(button_back);
+}
+
+void eventScreenBrowser()
+{
+ eventWidgetSelect(select_server);
+
+ eventWidgetButton(button_play);
+ eventWidgetButton(button_back);
+}
+
+void stopScreenBrowser()
+{
+ unsigned i = 0;
+ server_t *server;
+
+ listDoEmpty(select_server->list);
+
+ while (1) {
+ i = 0;
+ for (server = server_list.next; server != &server_list; server = server->next) {
+ server->next->prev = server->prev;
+ server->prev->next = server->next;
+
+ //if (server->version)
+ // free (server->version);
+
+ //if (server->arena)
+ //free (server->arena);
+
+ free (server);
+
+ i ++;
+ break;
+ }
+
+ if (!i)
+ return;
+ }
+}
+
+static void eventWidget(void *p)
+{
+ widget_button_t *button;
+
+ button = (widget_button_t *)(p);
+
+ if( button == button_play )
+ {
+ server_t *server = server_getcurr ();
+
+ if (!server)
+ return;
+
+ /* server je offline */
+ if (!server->state)
+ return;
+#ifdef SUPPORT_NET_UNIX_UDP
+ struct sockaddr_in srv;
+ srv.sin_addr.s_addr = server->ip;
+#endif
+ setSettingGameType (NET_GAME_TYPE_CLIENT);
+ setSettingIP(inet_ntoa (srv.sin_addr));
+ setSettingPort(server->port);
+
+ setScreen("world");
+ }
+
+ if( button == button_back )
+ {
+ setScreen("gameType");
+ }
+}
+
+server_t *server_getcurr ()
+{
+ unsigned i = 0;
+ server_t *server;
+
+ for (server = server_list.next; server != &server_list; server = server->next) {
+ if (i == select_server->select)
+ return server;
+
+ i ++;
+ }
+
+ return 0;
+}
+
+int server_getinfo (server_t *server)
+{
+#ifdef SUPPORT_NET_UNIX_UDP
+ struct sockaddr_in srv;
+ srv.sin_addr.s_addr = server->ip;
+
+ sock_udp_t *sock = connectUdpSocket(inet_ntoa (srv.sin_addr), server->port, PROTO_UDPv4);
+
+ char request[8];
+ memcpy (request, "status\n", 7);
+
+ writeUdpSocket(sock, sock, request, 7);
+
+ char *str = (char *) malloc (sizeof (char) * 257);
+
+ // Lets make socket non-blocking
+ int oldFlag = fcntl (sock->sock, F_GETFL, 0);
+ if (fcntl (sock->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) {
+ return -1;
+ }
+#else
+ return 0;
+#endif
+ /* 500ms timeout */
+ unsigned timeout = SERVER_TIMEOUT;
+ int ret = 0;
+
+ while (timeout) {
+ usleep (1);
+#ifdef SUPPORT_NET_UNIX_UDP
+ ret = readUdpSocket(sock, sock, str, 256);
+#endif
+ if (ret > 0)
+ break;
+
+ timeout --;
+ }
+
+ /* server not respond */
+ if (timeout < 1) {
+ free (str);
+ server->state = 0;
+ return 0;
+ }
+
+ server->ping = SERVER_TIMEOUT - timeout;
+
+/*
+ "version: svnX\n"
+ "clients: N\n"
+ "maxclients: M\n"
+ "uptime: D\n"
+*/
+
+ typedef struct {
+ char *version;
+ unsigned char clients;
+ unsigned char maxclients;
+ unsigned uptime;
+ } server_info;
+
+ server_info *info = (server_info *) malloc (sizeof (server_info));
+
+ if (!info)
+ return 0;
+
+ unsigned i = 0;
+
+ while (i < ret) {
+ if (str[i] == '\n')
+ str[i] = '\0';
+
+ i ++;
+ }
+
+ unsigned len = strlen (str);
+ if (!strncmp (str, "version: ", 9)) {
+ unsigned ver_len = strlen (str+9);
+ server->version = (char *) malloc (sizeof (char) * (ver_len + 1));
+
+ if (!server->version)
+ return 0;
+
+ memcpy (server->version, str+9, ver_len+1);
+ }
+
+ if (!strncmp (str+len+1, "clients: ", 9))
+ server->clients = atoi (str+len+10);
+
+ len += strlen (str+len+1) + 1;
+
+ if (!strncmp (str+len+1, "maxclients: ", 12))
+ server->maxclients = atoi (str+len+13);
+
+ len += strlen (str+len+1) + 1;
+
+ if (!strncmp (str+len+1, "uptime: ", 8))
+ server->uptime = atoi (str+len+9);
+
+ len += strlen (str+len+1) + 1;
+
+ if (!strncmp (str+len+1, "arena: ", 7)) {
+ unsigned arena_len = strlen (str+9);
+ server->arena = (char *) malloc (sizeof (char) * (arena_len + 1));
+
+ if (!server->arena)
+ return 0;
+
+ memcpy (server->arena, str+len+8, arena_len+1);
+ }
+
+ free (str);
+
+ server->state = 1;
+
+ return 1;
+}
+
+static int LoadServers ()
+// Get server list
+{
+ int s;
+ char buf[1025];
+
+ /* TODO: dodelat TCP makro */
+#ifdef SUPPORT_NET_UNIX_UDP
+ struct sockaddr_in server;
+
+ server.sin_family = AF_INET;
+ server.sin_port = htons (MASTER_PORT);
+ server.sin_addr.s_addr = inet_addr (MASTER_SERVER);
+
+ if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
+ close (s);
+ return 0;
+ }
+
+ if (connect (s, (struct sockaddr *) &server, sizeof (server)) == -1)
+ return 0;
+
+ /* send request for server list */
+ send (s, "l", 1, 0);
+
+ /* receive server list if exist */
+ int len = recv (s, buf, 1024, 0);
+
+ close (s);
+#else
+ return -1;
+#endif
+
+ if (len <= 0)
+ return 0;
+
+ unsigned i = 0;
+ char list[256];
+
+ struct sockaddr_in srv;
+
+ typedef struct {
+ unsigned port;
+ unsigned ip;
+ } response_head;
+
+ while (1) {
+ response_head *header = (response_head *) ((char *) buf + i);
+
+ server_t *ctx;
+
+ // alloc and init context
+ ctx = (server_t *) malloc (sizeof (server_t));
+
+ ctx->ip = header->ip;
+ ctx->port = header->port;
+
+ srv.sin_addr.s_addr = ctx->ip;
+
+ int ret = server_getinfo (ctx);
+
+ if (ret) {
+ sprintf (list, "%s:%d (%s) - %s - %d/%d - %dms", inet_ntoa (srv.sin_addr), ctx->port, ctx->version,
+ ctx->arena, ctx->clients, ctx->maxclients, ctx->ping);
+ } else
+ sprintf (list, "%s:%d - Offline", inet_ntoa (srv.sin_addr), ctx->port);
+
+ addToWidgetSelect(select_server, list);
+
+ // add into list
+ ctx->next = &server_list;
+ ctx->prev = server_list.prev;
+ ctx->prev->next = ctx;
+ ctx->next->prev = ctx;
+
+ i += sizeof (response_head) + 1;
+
+ if (buf[i-1] != '\n' || (i+1) > len)
+ break;
+ }
+
+ return 1;
+}
+
+void initScreenBrowser()
+{
+ SDL_Surface *image;
+
+ image = addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_browser", IMAGE_GROUP_BASE);
+ image_backgorund = newWidgetImage(0, 0, image);
+
+ button_back = newWidgetButton(getMyText("BACK"), 100, WINDOW_SIZE_Y-100, eventWidget);
+ button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);;
+
+ label_server = newWidgetLabel("Server list", 50, 145, WIDGET_LABEL_LEFT);
+
+ select_server = newWidgetSelect(label_server->x, label_server->y+40, eventWidget);
+
+ registerScreen( newScreen("browser", startScreenBrowser, eventScreenBrowser,
+ drawScreenBrowser, stopScreenBrowser) );
+
+ server_list.next = &server_list;
+ server_list.prev = &server_list;
+}
+
+void quitScreenBrowser()
+{
+ destroyWidgetImage(image_backgorund);
+
+ destroyWidgetButton(button_play);
+ destroyWidgetButton(button_back);
+ destroyWidgetLabel(label_server);
+ destroyWidgetSelect(select_server);
+}
+
diff --git a/src/screen/screen_browser.h b/src/screen/screen_browser.h
new file mode 100644
index 0000000..a3f88e7
--- /dev/null
+++ b/src/screen/screen_browser.h
@@ -0,0 +1,36 @@
+
+#ifndef SCREEN_BROWSER_H
+
+#define SCREEN_BROWSER_H
+
+#define MASTER_SERVER "193.85.244.165"
+#define MASTER_PORT 2200
+
+typedef struct server_context {
+ struct server_context *next, *prev;
+
+ unsigned char state;
+
+ unsigned char ping;
+
+ unsigned ip;
+ unsigned port;
+
+ char *name;
+
+ char *version;
+ unsigned char clients;
+ unsigned char maxclients;
+ unsigned uptime;
+ char *arena;
+} server_t;
+
+
+extern void startScreenBrowser();
+extern void drawScreenBrowser();
+extern void eventScreenBrowser();
+extern void stopScreenBrowser();
+extern void initScreenBrowser();
+extern void quitScreenBrowser();
+
+#endif
diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c
index 5545fc1..df3d4dc 100644
--- a/src/screen/screen_gameType.c
+++ b/src/screen/screen_gameType.c
@@ -30,6 +30,7 @@ static widget_image_t *image_backgorund;
static widget_button_t *button_back;
static widget_button_t *button_play;
+static widget_button_t *button_browser;
static widget_label_t *label_none;
static widget_label_t *label_server;
@@ -74,6 +75,9 @@ void drawScreenGameType()
drawWidgetButton(button_back);
drawWidgetButton(button_play);
+
+ if( check_client->status == TRUE )
+ drawWidgetButton(button_browser);
}
void eventScreenGameType()
@@ -87,6 +91,7 @@ void eventScreenGameType()
eventWidgetButton(button_back);
eventWidgetButton(button_play);
+ eventWidgetButton(button_browser);
}
void stopScreenGameType()
@@ -141,6 +146,11 @@ static void eventWidget(void *p)
setScreen("chiceArena");
}
}
+
+ if( button == button_browser )
+ {
+ setScreen("browser");
+ }
}
void initScreenGameType()
@@ -152,6 +162,7 @@ void initScreenGameType()
button_back = newWidgetButton(getMyText("BACK"), 100, WINDOW_SIZE_Y-100, eventWidget);
button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
+ button_browser = newWidgetButton(getMyText("BROWSER"), 300, 345, eventWidget);
check_none = newWidgetCheck(100, 150, FALSE, eventWidget);
check_server = newWidgetCheck(100, 200, FALSE, eventWidget);
@@ -184,6 +195,13 @@ void initScreenGameType()
drawScreenGameType, stopScreenGameType) );
}
+int setSettingGameType(int status)
+{
+ check_none->status = status;
+
+ return 0;
+}
+
int getSettingGameType()
{
if( check_none->status == TRUE )
@@ -206,11 +224,25 @@ int getSettingGameType()
return -1;
}
+int setSettingIP(char *address)
+{
+ strcpy (textfield_ip->text, address);
+
+ return 1;
+}
+
char* getSettingIP()
{
return textfield_ip->text;
}
+int setSettingPort(int port)
+{
+ sprintf (textfield_port->text, "%d", port);
+
+ return 0;
+}
+
int getSettingPort()
{
return atoi( textfield_port->text );
@@ -248,6 +280,7 @@ void quitScreenGameType()
destroyWidgetButton(button_back);
destroyWidgetButton(button_play);
+ destroyWidgetButton(button_browser);
destroyWidgetCheck(check_none);
destroyWidgetCheck(check_server);
diff --git a/src/screen/screen_gameType.h b/src/screen/screen_gameType.h
index 93d38ee..02e2338 100644
--- a/src/screen/screen_gameType.h
+++ b/src/screen/screen_gameType.h
@@ -8,8 +8,11 @@
extern void drawScreenGameType();
extern void eventScreenGameType();
extern void initScreenGameType();
+extern int setSettingGameType(int status);
extern int getSettingGameType();
+extern int setSettingIP(char *address);
extern char* getSettingIP();
+extern int setSettingPort(int port);
extern int getSettingPort();
extern int getSettingProto();
extern void quitScreenGameType();
diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c
index f9186c9..2e4a9ec 100644
--- a/src/widget/widget_textfield.c
+++ b/src/widget/widget_textfield.c
@@ -87,17 +87,14 @@ static void readKey(widget_textfield_t *p)
int len;
int i;
- if( p->time > 0 )
- {
- p->time--;
- return;
- }
-
if( p->active == FALSE )
{
return;
}
+ if (p->atime < 100)
+ p->atime ++;
+
mapa = SDL_GetKeyState(NULL);
len = strlen(p->text);
@@ -106,7 +103,7 @@ static void readKey(widget_textfield_t *p)
{
if( len > 0 )
{
- p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+ p->time = 0;
p->text[len-1]='\0';
getTextSize(p->text, &p->w, &p->h);
}
@@ -125,9 +122,30 @@ static void readKey(widget_textfield_t *p)
//if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED)
if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
{
- p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+ if (i == SDLK_SPACE)
+ {
+ strcat( p->text, " " );
+ getTextSize(p->text, &p->w, &p->h);
+ return;
+ }
+
+ const char *c = (const char *) SDL_GetKeyName(i);
- strcat( p->text, SDL_GetKeyName(i) );
+ if (len) {
+ if (p->text[len-1] == *c) {
+ p->time ++;
+
+ if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) {
+ if (p->atime < 3)
+ return;
+ }
+ } else
+ p->time = 0;
+ }
+
+ p->atime = 0;
+
+ strcat( p->text, c );
getTextSize(p->text, &p->w, &p->h);
if( mapa[SDLK_LSHIFT] == SDL_PRESSED ||
@@ -145,8 +163,23 @@ static void readKey(widget_textfield_t *p)
{
if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
{
- p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
- strcat( p->text, SDL_GetKeyName(i) );
+ const char *c = (const char *) SDL_GetKeyName(i);
+
+ if (len) {
+ if (p->text[len-1] == *c) {
+ p->time ++;
+
+ if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) {
+ if (p->atime < 3)
+ return;
+ }
+ } else
+ p->time = 0;
+ }
+
+ p->atime = 0;
+
+ strcat( p->text, c );
getTextSize(p->text, &p->w, &p->h);
return;
}
@@ -157,8 +190,23 @@ static void readKey(widget_textfield_t *p)
{
if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
{
- p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
- strncat( p->text, SDL_GetKeyName(i)+1, 1 ); // napr. "[4]"
+ const char *c = (const char *) SDL_GetKeyName(i)+1;
+
+ if (len) {
+ if (p->text[len-1] == *c) {
+ p->time ++;
+
+ if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) {
+ if (p->atime < 3)
+ return;
+ }
+ } else
+ p->time = 0;
+ }
+
+ p->atime = 0;
+
+ strncat( p->text, c, 1 ); // napr. "[4]"
getTextSize(p->text, &p->w, &p->h);
return;
}
diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h
index 368f329..9300bce 100644
--- a/src/widget/widget_textfield.h
+++ b/src/widget/widget_textfield.h
@@ -10,6 +10,7 @@
#define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10
+#define WIDGET_TEXTFIELD_TIME_MULTIPLE 10
#define WIDGET_TEXTFIELD_TIME_READ_KEY 2
#define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20
@@ -20,6 +21,7 @@ typedef struct widget_textfield
int canWrite;
int timeBlick;
int time;
+ int atime;
char text[STR_SIZE];
bool_t active;
} widget_textfield_t;