diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-19 19:28:04 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-19 19:28:04 +0000 |
| commit | a370d2f5860a0f89ac44af857d1059885ad1d60f (patch) | |
| tree | 5ad5112a884e41367b271a8ea3509dec04524819 | |
| parent | fadf9365dba24b680db5cb8750c53e264ff1ec27 (diff) | |
- upravy v kode
- prepis stirel pre space_t *
- v kode su dva vyhladavacie algortmy, implicitne sa pouziva ten ktory funguje :)
ten co nefunguje je zamakrovany makrom SUPPORT_ERROR a este ho musim doladit
git-svn-id: http://opensvn.csie.org/tuxanci_ng@66 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | include/arena.h | 2 | ||||
| -rw-r--r-- | include/hashTable.h | 24 | ||||
| -rw-r--r-- | include/shot.h | 4 | ||||
| -rwxr-xr-x | modules/modPipe.c | 35 | ||||
| -rwxr-xr-x | modules/modTeleport.c | 37 | ||||
| -rwxr-xr-x | modules/modWall.c | 27 | ||||
| -rw-r--r-- | modules/space.c | 664 | ||||
| -rw-r--r-- | modules/space.h | 38 | ||||
| -rw-r--r-- | server.conf | 3 | ||||
| -rwxr-xr-x | src/Makefile | 2 | ||||
| -rw-r--r-- | src/arena.c | 24 | ||||
| -rw-r--r-- | src/gun.c | 3 | ||||
| -rw-r--r-- | src/hashTable.c | 221 | ||||
| -rw-r--r-- | src/item.c | 6 | ||||
| -rw-r--r-- | src/proto.c | 18 | ||||
| -rw-r--r-- | src/shot.c | 161 | ||||
| -rw-r--r-- | src/space.c | 75 | ||||
| -rw-r--r-- | src/tux.c | 8 |
19 files changed, 1184 insertions, 172 deletions
@@ -6,8 +6,8 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn65" +#define TUXANCI_NG_VERSION "svn67" -//#define DESTDIR "/usr/local/" +#define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP //#define PUBLIC_SERVER diff --git a/include/arena.h b/include/arena.h index 2c06659..837fade 100644 --- a/include/arena.h +++ b/include/arena.h @@ -22,7 +22,7 @@ typedef struct arena_struct int w, h; list_t *listTimer; //list_t *listTux; - list_t *listShot; + space_t *spaceShot; space_t *spaceTux; space_t *spaceItem; } arena_t; diff --git a/include/hashTable.h b/include/hashTable.h new file mode 100644 index 0000000..b872cfb --- /dev/null +++ b/include/hashTable.h @@ -0,0 +1,24 @@ + +#ifndef HASHTABLE_H + +#define HASHTABLE_H + +typedef struct hashTable_struct +{ + struct hashTable_struct *table[256]; + void *data; +} hashtable_t; + +extern hashtable_t* newHashTable(); +extern void addHashTable(hashtable_t *p, char *key, void *item); +extern void addHashTableWithIndex(hashtable_t *p, int index, void *item); +extern void* getHashTable(hashtable_t *p, char *key); +extern void* getHashTableWithIndex(hashtable_t *p, int index); +extern void delHashTable(hashtable_t *p, char *key); +extern void delHashTableWithIndex(hashtable_t *p, int index); +extern void delHashTableWithMem(hashtable_t *p, char *key, void *f); +extern void delHashTableWithMemWithIndex(hashtable_t *p, int index); +extern void destroyHashTable(hashtable_t *p); +extern void destroyHashTableWithMem(hashtable_t *p, void *f); + +#endif diff --git a/include/shot.h b/include/shot.h index fa7516a..7eae9cd 100644 --- a/include/shot.h +++ b/include/shot.h @@ -40,12 +40,14 @@ extern void initShot(); extern shot_t* newShot(int x,int y, int px, int py, int gun, int author_id); extern shot_t* getShotID(list_t *listShot, int id); extern void replaceShotID(shot_t *shot, int id); +extern void getStatusShot(void *p, int *id, int *x,int *y, int *w, int *h); +extern void setStatusShot(void *p, int x, int y, int w, int h); #ifndef PUBLIC_SERVER extern void drawShot(shot_t *p); extern void drawListShot(list_t *listShot); #endif extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h); -extern void eventMoveListShot(list_t *listShot); +extern void eventMoveListShot(arena_t *arena); extern void checkShotIsInTuxScreen(arena_t *arena); extern void boundBombBall(shot_t *shot); diff --git a/modules/modPipe.c b/modules/modPipe.c index e5f628d..2c1a6e5 100755 --- a/modules/modPipe.c +++ b/modules/modPipe.c @@ -218,6 +218,7 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, int dist_x, int dist_y, int dist_w, int dist_h) { int offset = 0; + int new_x, new_y; switch( shot->position ) { @@ -237,34 +238,35 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, switch( shot->position ) { case TUX_UP : - shot->x = dist_x + offset; - shot->y = dist_y; + new_x = dist_x + offset; + new_y = dist_y; break; case TUX_LEFT : - shot->x = dist_x; - shot->y = dist_y + offset; + new_x = dist_x; + new_y = dist_y + offset; break; case TUX_RIGHT : - shot->x = dist_x + dist_w; - shot->y = dist_y + offset; + new_x = dist_x + dist_w; + new_y = dist_y + offset; break; case TUX_DOWN : - shot->x = dist_x + offset; - shot->y = dist_y + dist_h; + new_x = dist_x + offset; + new_y = dist_y + dist_h; break; } - shot->x += shot->px; - shot->y += shot->py; + new_y += shot->px; + new_y += shot->py; + + moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) { export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); } - } static void moveShotFromPipe(shot_t *shot, pipe_t *pipe) @@ -360,12 +362,12 @@ int event() */ arena = export_fce->fce_getCurrentArena(); - for( i = 0 ; i < arena->listShot->count ; i++ ) + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { shot_t *thisShot; int j; - thisShot = (shot_t *)arena->listShot->list[i]; + thisShot = (shot_t *) arena->spaceShot->list->list[i]; assert( thisShot != NULL ); listDoEmpty(listPipe); @@ -394,7 +396,9 @@ int event() { if( thisShot->gun != GUN_BOMBBALL ) { - delListItem(arena->listShot, i, export_fce->fce_destroyShot); + delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, + thisShot, export_fce->fce_destroyShot); + //delListItem(arena->listShot, i, export_fce->fce_destroyShot); i--; } } @@ -414,7 +418,8 @@ int event() } else { - delListItem(arena->listShot, i, export_fce->fce_destroyShot); + delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, + thisShot, export_fce->fce_destroyShot); i--; } } diff --git a/modules/modTeleport.c b/modules/modTeleport.c index a6b4a1d..2b94e2f 100755 --- a/modules/modTeleport.c +++ b/modules/modTeleport.c @@ -23,6 +23,8 @@ typedef struct teleport_struct { + int id; + int x; // poloha steny int y; @@ -49,6 +51,8 @@ teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img) teleport_t* newTeleport(int x, int y, int w, int h, int layer) #endif { + static int last_id = 0; + teleport_t *new; #ifndef PUBLIC_SERVER @@ -58,6 +62,7 @@ teleport_t* newTeleport(int x, int y, int w, int h, int layer) new = malloc( sizeof(teleport_t) ); assert( new != NULL ); + new->id = ++last_id; new->x = x; new->y = y; new->w = w; @@ -85,10 +90,9 @@ static void setStatusTeleport(void *p, int x, int y, int w, int h) static void getStatusTeleport(void *p, int *id, int *x, int *y, int *w, int *h) { teleport_t *teleport; - teleport = p; - *id = -1; + *id = teleport->id; *x = teleport->x; *y = teleport->y; *w = teleport->w; @@ -315,6 +319,7 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, int dist_x, int dist_y, int dist_w, int dist_h) { int offset = 0; + int new_x, new_y; switch( shot->position ) { @@ -334,34 +339,35 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, switch( shot->position ) { case TUX_UP : - shot->x = dist_x + offset; - shot->y = dist_y; + new_x = dist_x + offset; + new_y = dist_y; break; case TUX_LEFT : - shot->x = dist_x; - shot->y = dist_y + offset; + new_x = dist_x; + new_y = dist_y + offset; break; case TUX_RIGHT : - shot->x = dist_x + dist_w; - shot->y = dist_y + offset; + new_x = dist_x + dist_w; + new_y = dist_y + offset; break; case TUX_DOWN : - shot->x = dist_x + offset; - shot->y = dist_y + dist_h; + new_x = dist_x + offset; + new_y = dist_y + dist_h; break; } - shot->x += shot->px; - shot->y += shot->py; + new_y += shot->px; + new_y += shot->py; + + moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) { export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); } - } static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *list) @@ -396,7 +402,6 @@ int draw(int x, int y, int w, int h) listDoEmpty(listTeleport); getObjectFromSpace(spaceTeleport, x, y, w, h, listTeleport); - //printSpace(spaceTeleport); for( i = 0 ; i < listTeleport->count ; i++ ) { @@ -446,12 +451,12 @@ int event() } } - for( i = 0 ; i < arena->listShot->count ; i++ ) + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { shot_t *thisShot; int j; - thisShot = (shot_t *)arena->listShot->list[i]; + thisShot = (shot_t *)arena->spaceShot->list->list[i]; assert( thisShot != NULL ); listDoEmpty(listTeleport); diff --git a/modules/modWall.c b/modules/modWall.c index 5a83fbd..2bed2ef 100755 --- a/modules/modWall.c +++ b/modules/modWall.c @@ -23,6 +23,8 @@ typedef struct wall_struct { + int id; + int x; // poloha steny int y; @@ -59,6 +61,7 @@ wall_t* newWall(int x, int y, int w, int h, int img_x, int img_y, int layer) #endif { + static int last_id = 0; wall_t *new; #ifndef PUBLIC_SERVER @@ -67,6 +70,7 @@ wall_t* newWall(int x, int y, int w, int h, new = malloc( sizeof(wall_t) ); assert( new != NULL ); + new->id = ++last_id; new->x = x; new->y = y; new->w = w; @@ -107,15 +111,18 @@ void drawListWall(list_t *list) #endif -void eventConflictShotWithWall(list_t *listShot) +void eventConflictShotWithWall() { + arena_t *arena; shot_t *thisShot; tux_t *author; int i; - for( i = 0 ; i < listShot->count ; i++ ) + arena = export_fce->fce_getCurrentArena(); + + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { - thisShot = (shot_t *)listShot->list[i]; + thisShot = (shot_t *)arena->spaceShot->list->list[i]; assert( thisShot != NULL ); if( isConflictWithObjectFromSpace(spaceWall, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) @@ -136,7 +143,10 @@ void eventConflictShotWithWall(list_t *listShot) continue; } - delListItem(listShot, i, export_fce->fce_destroyShot); + delObjectFromSpaceWithObject(export_fce->fce_getCurrentArena()->spaceShot, + thisShot, export_fce->fce_destroyShot); + + //delListItem(listShot, i, export_fce->fce_destroyShot); i--; } } @@ -154,7 +164,7 @@ static void getStatusWall(void *p, int *id, int *x, int *y, int *w, int *h) wall = p; - *id = -1; + *id = wall->id; *x = wall->x; *y = wall->y; *w = wall->w; @@ -181,7 +191,7 @@ static void getStatusImgWall(void *p, int *id, int *x, int *y, int *w, int *h) wall = p; - *id = -1; + *id = wall->id; *x = wall->img_x; *y = wall->img_y; *w = wall->img->w; @@ -291,7 +301,7 @@ int event() return 0; } - eventConflictShotWithWall(export_fce->fce_getCurrentArena()->listShot); + eventConflictShotWithWall(export_fce->fce_getCurrentArena()->spaceShot->list); return 0; } @@ -313,8 +323,9 @@ void cmd(char *line) int destroy() { destroySpace(spaceWall); +#ifndef PUBLIC_SERVER destroySpace(spaceImgWall); +#endif destroyListItem(listWall, destroyWall); - return 0; } diff --git a/modules/space.c b/modules/space.c new file mode 100644 index 0000000..c9688a8 --- /dev/null +++ b/modules/space.c @@ -0,0 +1,664 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#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 + +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 addToList(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("addToList (%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++ ) + { + addList(p->area[j][i], item); + } + } + +#ifdef ERROR_SUPPORT + addToList(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++ ) + { + 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); + } + } + } + } +} + +void* getObjectFromSpaceWithID(space_t *space, int id) +{ +#ifdef ERROR_SUPPORT + 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 NULL; + } + + 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 space->list->list[point]; + } + + if( id > point_id ) + { + min = point + 1; + continue; + } + + if( id < point_id ) + { + max = point - 1; + continue; + } + } + +#endif + +#ifndef ERROR_SUPPORT + int this_id, x, y, w, h; + void *this; + int i; + + for( i = 0 ; i < space->list->count ; i++ ) + { + this = space->list->list[i]; + assert( this != NULL ); + + space->getStatus(this, &this_id, &x, &y, &w, &h); + + if( this_id == id ) + { + return this; + } + } + + return NULL; +#endif +} + +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++ ) + { + 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++ ) + { + 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++ ) + { + index = searchListItem(p->area[j][i], item); + assert( index != -1 ); + delList(p->area[j][i], index); + } + } + + index = searchListItem(p->list, item); + 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(6, 0, 0, 1, 1) ); + addObjectToSpace(space, newRecv(3, 0, 0, 1, 1) ); + addObjectToSpace(space, newRecv(4, 0, 0, 1, 1) ); + + //printListID(space); +/* + recv = getObjectFromSpaceWithID(space, 6); + if( recv != NULL )printf("id = %d\n", recv->id); +*/ + recv = getObjectFromSpaceWithID(space, 3); + + if( recv != NULL ) + { + printf("id = %d\n", recv->id); + } + else + { + printf("recv = %p\n", recv); + } + +/* + recv = getObjectFromSpaceWithID(space, 4); + if( recv != NULL )printf("id = %d\n", recv->id); + recv = getObjectFromSpaceWithID(space, 1); + if( recv != NULL )printf("id = %d\n", recv->id); +*/ + +#if 0 + for( i = 1 ; i < 16 ; i++ ) + for( j = 1 ; j < 16 ; j++ ) + { + recv_t *this; + + this = newRecv(j*160, i*120, 32, 32); + //addToSpace(space, newRecv(j*550, i*550, 1, 1) ); + addObjectToSpace(space, this ); + delObjectFromSpaceWithMem(space, this, destroyRecv); + } +#endif +/* + list = newList(); + getObjectFromSpace(space, 640, 480, 800 , 600, list); + + printf("list->count = %d\n", list->count); + + for( i = 0 ; i < list->count ; i++ ) + { + recv_t *recv; + recv = list->list[i]; + + printf("%3d %3d %3d %3d\n", recv->x, recv->y, recv->w, recv->h); + } +*/ +/* + destroyList(list); + + printSpace(space); + + destroySpace(space); +*/ +} + +#endif + diff --git a/modules/space.h b/modules/space.h new file mode 100644 index 0000000..de31768 --- /dev/null +++ b/modules/space.h @@ -0,0 +1,38 @@ + +#ifndef SPACE_H + +#define SPACE_H + +#include "main.h" +#include "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/server.conf b/server.conf index 0155ddd..1c24934 100644 --- a/server.conf +++ b/server.conf @@ -1,5 +1,6 @@ IP 0.0.0.0 PORT 2200 MAX_CLIENTS 32 -ARENA IACO8B +ARENA FAGN + diff --git a/src/Makefile b/src/Makefile index 1c7a1ab..d730826 100755 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ CFLAGS = -g -O0 -std=c99 -I../include -Wall `sdl-config --cflags` BUILD_DIR = . LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_net -FILES = interface.o space.o hashTable.o idManager.o storage.o font.o list.o modules.o\ +FILES = interface.o space.o idManager.o storage.o font.o list.o modules.o\ image.o layer.o director.o configFile.o tux.o main.o checkFront.o\ screen.o screen_world.o shot.o myTimer.o panel.o net_multiplayer.o \ buffer.o arena.o arenaFile.o textFile.o audio.o sound.o music.o gun.o \ diff --git a/src/arena.c b/src/arena.c index 1a8e803..75e94b4 100644 --- a/src/arena.c +++ b/src/arena.c @@ -44,12 +44,9 @@ arena_t* newArena(int w, int h) new->listTimer = newList(); - //new->listTux = newList(); - //new->listItem = newList(); new->spaceTux = newSpace(w, h, 320, 240, getStatusTux, setStatusTux); new->spaceItem = newSpace(w, h, 320, 240, getStatusItem, setStatusItem); - - new->listShot = newList(); + new->spaceShot = newSpace(w, h, 320, 240, getStatusShot, setStatusShot); return new; } @@ -62,12 +59,11 @@ int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) int isFreeSpace(arena_t *arena, int x, int y, int w, int h) { if( isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) )return 0; - if( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0; + if( isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h) )return 0; if( isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h) )return 0; + if( isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h) )return 0; + if( isConflictModule(x, y, w, h) )return 0; - //if( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; - //if( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; - //if( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; return 1; } @@ -162,13 +158,17 @@ void drawArena(arena_t *arena) getObjectFromSpace(arena->spaceItem, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp); drawListItem(listHelp); - //printSpace(arena->spaceItem); + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceShot, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp); + drawListShot(listHelp); + + //printSpace(arena->spaceShot); //drawListTux(arena->listTux); //drawListWall(arena->listWall); //drawListTeleport(arena->listTeleport); //drawListPipe(arena->listPipe); - drawListShot(arena->listShot); + //drawListShot(arena->listShot); //drawListItem(arena->listItem); drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); @@ -200,7 +200,7 @@ void eventArena(arena_t *arena) for( i = 0 ; i < 8 ; i++) { - eventMoveListShot(arena->listShot); + eventMoveListShot(arena); checkShotIsInTuxScreen(arena); //eventConflictShotWithWall(arena->listWall, arena->listShot); //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); @@ -221,7 +221,7 @@ void destroyArena(arena_t *p) { destroySpaceWithObject(p->spaceTux, destroyTux); destroySpaceWithObject(p->spaceItem, destroyItem); - destroyListItem(p->listShot, destroyShot); + destroySpaceWithObject(p->spaceShot, destroyShot); destroyTimer(p->listTimer); free(p); } @@ -89,7 +89,8 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun) return; } */ - addList( getCurrentArena()->listShot, shot ); + //addList( getCurrentArena()->listShot, shot ); + addObjectToSpace(getCurrentArena()->spaceShot, shot); if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { diff --git a/src/hashTable.c b/src/hashTable.c new file mode 100644 index 0000000..cc67225 --- /dev/null +++ b/src/hashTable.c @@ -0,0 +1,221 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "hashTable.h" + +hashtable_t* newHashTable() +{ + hashtable_t *new; + + new = malloc( sizeof(hashtable_t) ); + memset(new, 0, sizeof(hashtable_t) ); + + return new; +} + +void addHashTable(hashtable_t *p, char *key, void *item) +{ + hashtable_t *this; + hashtable_t *next; + int len; + int i; + + this = p; + next = p; + + len = strlen(key); + + for( i = 0 ; i < len ; i++ ) + { + //printf("addHashTable key[%d] = %c\n", i , key[i]); + + next = this->table[ (int)key[i] ]; + + if( next == NULL ) + { + next = newHashTable(); + this->table[ (int)key[i] ] = next; + } + + this = next; + } + + next->data = item; +} + +void addHashTableWithIndex(hashtable_t *p, int index, void *item) +{ + char str[16]; + sprintf(str, "%d", index); + addHashTable(p, str, item); +} + +void* getHashTable(hashtable_t *p, char *key) +{ + hashtable_t *this; + hashtable_t *next; + int len; + int i; + + this = p; + next = p; + + len = strlen(key); + + for( i = 0 ; i < len ; i++ ) + { + //printf("getHashTable key[%d] = %c\n", i , key[i]); + + next = this->table[ (int)key[i] ]; + + //printf("next = %p\n", next); + + if( next == NULL ) + { + return NULL; + } + + this = next; + } + + return next->data; +} + +void* getHashTableWithIndex(hashtable_t *p, int index) +{ + char str[16]; + sprintf(str, "%d", index); + return getHashTable(p, str); +} + +void delHashTable(hashtable_t *p, char *key) +{ + hashtable_t *this; + hashtable_t *next; + int len; + int i; + + this = p; + next = p; + + len = strlen(key); + + for( i = 0 ; i < len ; i++ ) + { + //printf("getHashTable key[%d] = %c\n", i , key[i]); + + next = this->table[ (int)key[i] ]; + + //printf("next = %p\n", next); + + if( next == NULL ) + { + return; + } + + this = next; + } + + next->data = NULL; + +} + +void delHashTableWithIndex(hashtable_t *p, int index) +{ + char str[16]; + sprintf(str, "%d", index); + delHashTable(p, str); +} + +void delHashTableWithMem(hashtable_t *p, char *key, void *f) +{ + void (*fce)(void *p); + + delHashTable(p, key); + + fce = f; + fce(key); +} + +void delHashTableWithMemWithIndex(hashtable_t *p, int index) +{ + char str[16]; + sprintf(str, "%d", index); + delHashTable(p, str); +} + +void destroyHashTable(hashtable_t *p) +{ + hashtable_t *this; + hashtable_t *next; + int i; + + this = p; + + for( i = 0 ; i < 256 ; i++ ) + { + next = this->table[i]; + + if( next != NULL ) + { + destroyHashTable(next); + } + } + + free(p); +} + +void destroyHashTableWithMem(hashtable_t *p, void *f) +{ + void (*fce)(void *p); + hashtable_t *this; + hashtable_t *next; + int i; + + this = p; + fce = f; + + for( i = 0 ; i < 256 ; i++ ) + { + next = this->table[i]; + + if( next != NULL ) + { + destroyHashTableWithMem(next, f); + } + } + + if( p->data != NULL ) + { + fce(p->data); + } + + free(p); +} + +int test_main(int argc, char **argv) +{ + hashtable_t *p; + int max = 10000; + int i; + + p = newHashTable(); + + for( i = 0 ; i < max ; i++ ) + { + addHashTableWithIndex(p, i, NULL); + } + + for( i = 0 ; i < max ; i++ ) + { + printf("%d -> %s\n", i, (char *)getHashTableWithIndex(p, i) ); + } + + //printHashTable(p); + + destroyHashTableWithMem(p, free); + + return 0; +} @@ -482,12 +482,12 @@ void eventConflictShotWithItem(arena_t *arena) return; } - for( i = 0 ; i < arena->listShot->count ; i++ ) + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { bool_t isDelShot; isDelShot = FALSE; - thisShot = (shot_t *)arena->listShot->list[i]; + thisShot = (shot_t *)arena->spaceShot->list->list[i]; assert( thisShot != NULL ); listDoEmpty(listHelp); @@ -526,7 +526,7 @@ void eventConflictShotWithItem(arena_t *arena) proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot); } - delListItem(arena->listShot, i, destroyShot); + delObjectFromSpaceWithObject(arena->spaceShot, thisItem, destroyShot); i--; } } diff --git a/src/proto.c b/src/proto.c index e14db9f..72e8f16 100644 --- a/src/proto.c +++ b/src/proto.c @@ -753,10 +753,9 @@ void proto_recv_shot_client(char *msg) proto_send_check_client(check_id); - if( ( shot = getShotID(getCurrentArena()->listShot, shot_id) ) != NULL ) + if( ( shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, shot_id) ) != NULL ) { - delListItem(getCurrentArena()->listShot, - searchListItem(getCurrentArena()->listShot, shot), destroyShot); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); //return; } @@ -772,7 +771,7 @@ void proto_recv_shot_client(char *msg) transformOnlyLasser(shot); } - addList(getCurrentArena()->listShot, shot); + addObjectToSpace(getCurrentArena()->spaceShot, shot); } #endif @@ -807,18 +806,11 @@ void proto_recv_delshot_client(char *msg) proto_send_check_client(check_id); - shot = getShotID(getCurrentArena()->listShot, id); + shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); if( shot != NULL ) { - int index; - - index = searchListItem(getCurrentArena()->listShot, shot); - - if( index >= 0 ) - { - delListItem(getCurrentArena()->listShot, index, destroyShot); - } + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); } } @@ -130,33 +130,35 @@ shot_t* newShot(int x,int y, int px, int py, int gun, int author_id) return new; } -shot_t* getShotID(list_t *listShot, int id) +void replaceShotID(shot_t *shot, int id) { - shot_t *thisShot; - int i; - - assert( listShot != NULL ); - - for( i = 0 ; i < listShot->count ; i++ ) - { - thisShot = (shot_t *)listShot->list[i]; - assert( thisShot != NULL ); + replaceID(shot->id, id); + shot->id = id; +} - if( thisShot->id == id ) - { - return thisShot; - } - } - return NULL; +void getStatusShot(void *p, int *id, int *x,int *y, int *w, int *h) +{ + shot_t *shot; + + shot = p; + *id = shot->id; + *x = shot->x; + *y = shot->y; + *w = shot->w; + *h = shot->h; } -void replaceShotID(shot_t *shot, int id) +void setStatusShot(void *p, int x, int y, int w, int h) { - replaceID(shot->id, id); - shot->id = id; -} + shot_t *shot; + shot = p; + shot->x = x; + shot->y = y; + shot->w = w; + shot->h = h; +} #ifndef PUBLIC_SERVER @@ -183,28 +185,6 @@ void drawListShot(list_t *listShot) #endif -int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h) -{ - shot_t *thisShot; - int i; - - assert( listShot != NULL ); - - for( i = 0 ; i < listShot->count ; i++ ) - { - thisShot = (shot_t *)listShot->list[i]; - assert( thisShot != NULL ); - - if( conflictSpace(x, y, w, h, - thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) - { - return 1; - } - } - - return 0; -} - static int getRandomCourse(int x, int y) { int ret; @@ -267,44 +247,27 @@ void transformOnlyLasser(shot_t *shot) } } -void eventMoveListShot(list_t *listShot) +void eventMoveListShot(arena_t *arena) { - arena_t *arena; shot_t *thisShot; + int new_x, new_y; int i; - assert( listShot != NULL ); - - arena = getCurrentArena(); - - for( i = 0 ; i < listShot->count ; i++ ) + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { - thisShot = (shot_t *)listShot->list[i]; + thisShot = (shot_t *) arena->spaceShot->list->list[i]; assert( thisShot != NULL ); - thisShot->x += thisShot->px; - thisShot->y += thisShot->py; -/* - if( thisShot->gun == GUN_BOMBBALL && ( - isConflictWithListWall(getCurrentArena()->listWall, thisShot->x, thisShot->y, thisShot->w, thisShot->h) || - isConflictWithListPipe(getCurrentArena()->listPipe, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) ) - { - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - boundBombBall(thisShot); - } - else - { - delListItem(listShot, i, destroyShot); - i--; - continue; - } - } -*/ + new_x = thisShot->x + thisShot->px; + new_y = thisShot->y + thisShot->py; + + moveObjectInSpace(getCurrentArena()->spaceShot, thisShot, new_x, new_y); + if( thisShot->x+thisShot->w < 0 || thisShot->x > arena->w || thisShot->y+thisShot->h < 0 || thisShot->y > arena->h ) { - delListItem(listShot, i, destroyShot); + delObjectFromSpaceWithObject(arena->spaceShot, + thisShot, destroyShot); i--; continue; } @@ -316,7 +279,6 @@ static int myAbs(int n) return ( n > 0 ? n : -n ); } - static int getSppedShot(shot_t *shot) { return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); @@ -325,8 +287,6 @@ static int getSppedShot(shot_t *shot) void checkShotIsInTuxScreen(arena_t *arena) { - return; -/* int screen_x, screen_y; shot_t *thisShot; tux_t *thisTux; @@ -338,9 +298,10 @@ void checkShotIsInTuxScreen(arena_t *arena) return; } - for( i = 0 ; i < arena->listTux->count ; i++ ) + for( i = 0 ; i < arena->spaceTux->list->count ; i++ ) { - thisTux = (tux_t *)arena->listTux->list[i]; + thisTux = (tux_t *)arena->spaceTux->list->list[i]; + speed = 25; if( thisTux->control != TUX_CONTROL_NET ) { @@ -349,9 +310,53 @@ void checkShotIsInTuxScreen(arena_t *arena) getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y); - for( j = 0 ; j < arena->listShot->count ; j++ ) + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceShot, screen_x-speed, screen_y, speed, WINDOW_SIZE_Y, listHelp); + + for( j = 0 ; j <listHelp->count ; j++ ) + { + thisShot = (shot_t *)listHelp->list[j]; + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceShot, screen_x+WINDOW_SIZE_X, screen_y, speed, WINDOW_SIZE_Y, listHelp); + + for( j = 0 ; j <listHelp->count ; j++ ) + { + thisShot = (shot_t *)listHelp->list[j]; + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceShot, screen_x, screen_y-speed, WINDOW_SIZE_X, speed, listHelp); + + for( j = 0 ; j <listHelp->count ; j++ ) + { + thisShot = (shot_t *)listHelp->list[j]; + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } + + listDoEmpty(listHelp); + getObjectFromSpace(arena->spaceShot, screen_x, screen_y+WINDOW_SIZE_Y, WINDOW_SIZE_X, speed, listHelp); + + for( j = 0 ; j <listHelp->count ; j++ ) { - thisShot = (shot_t *)arena->listShot->list[j]; + thisShot = (shot_t *)listHelp->list[j]; + client_t *thisClient; + thisClient = getClientFromTux(thisTux); + proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); + } +#if 0 + for( j = 0 ; j <listHelp->count ; j++ ) + { + thisShot = (shot_t *)listHelp->list[j]; speed = getSppedShot(thisShot); @@ -387,8 +392,8 @@ void checkShotIsInTuxScreen(arena_t *arena) proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); } } +#endif } -*/ } /* diff --git a/src/space.c b/src/space.c index dfe38a7..c9688a8 100644 --- a/src/space.c +++ b/src/space.c @@ -9,7 +9,7 @@ #include "space.h" #define DEBUG_SPACE -#define ERROR_SUPPORT +//#define ERROR_SUPPORT #ifdef DEBUG_SPACE @@ -122,6 +122,49 @@ static void getSegment(space_t *p, int x, int y, int w, int h, #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 addToList(space_t *space, void *p) { int id, point_id, inc_point_id; @@ -130,9 +173,15 @@ static void addToList(space_t *space, void *p) int min, max; int point; + len = space->list->count; space->getStatus(p, &id, &x, &y, &w, &h); +/* + printf("addToList (%d)\n", id); + printListID(space); + assert( id >= 0 ); +*/ if( len == 0 ) { @@ -175,12 +224,13 @@ static void addToList(space_t *space, void *p) 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); + 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; } @@ -188,6 +238,7 @@ static void addToList(space_t *space, void *p) { addList(space->list, p); //printf("OK height\n"); + checkList(space); return; } @@ -198,6 +249,7 @@ static void addToList(space_t *space, void *p) { //printf("OK\n"); insList(space->list, min, p); + checkList(space); return; } @@ -205,6 +257,7 @@ static void addToList(space_t *space, void *p) { //printf("OK\n"); insList(space->list, point+1, p); + checkList(space); return; } @@ -224,19 +277,6 @@ static void addToList(space_t *space, void *p) #endif -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); - } -} - void addObjectToSpace(space_t *p, void *item) { int segX, segY, segW, segH; @@ -301,6 +341,9 @@ void* getObjectFromSpaceWithID(space_t *space, int id) int min, max; int point; + printf("getObjectFromSpaceWithID %d\n", id); + printListID(space); + len = space->list->count; min = 0; @@ -559,7 +602,7 @@ void test_space() addObjectToSpace(space, newRecv(3, 0, 0, 1, 1) ); addObjectToSpace(space, newRecv(4, 0, 0, 1, 1) ); - printListID(space); + //printListID(space); /* recv = getObjectFromSpaceWithID(space, 6); if( recv != NULL )printf("id = %d\n", recv->id); @@ -560,9 +560,9 @@ void eventConflictTuxWithShot(arena_t *arena) tux_t *thisTux; int i, j; - for( i = 0 ; i < arena->listShot->count ; i++ ) + for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) { - thisShot = (shot_t *)arena->listShot->list[i]; + thisShot = (shot_t *)arena->spaceShot->list->list[i]; assert( thisShot != NULL ); listDoEmpty(listHelp); @@ -592,7 +592,7 @@ void eventConflictTuxWithShot(arena_t *arena) if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) { bombBallExplosion(thisShot); - delListItem(arena->listShot, i, destroyShot); + delObjectFromSpaceWithObject(arena->spaceShot, thisShot, destroyShot); i--; } @@ -605,7 +605,7 @@ void eventConflictTuxWithShot(arena_t *arena) } } - delListItem(arena->listShot, i, destroyShot); + delObjectFromSpaceWithObject(arena->spaceShot, thisShot, destroyShot); i--; continue; |