From e792ee9cbe5191fcc81273b65bdb4ac9108435d5 Mon Sep 17 00:00:00 2001 From: oroborus Date: Sun, 13 Jul 2008 18:45:15 +0000 Subject: - ID manager pocita pocet referencii na ID - oprava chyb, suvisiaca so zlym spravovanim ID - oprava chyby, objekt sa neda pridat mimo priestor ( to uz pisem druhy krat do commnitu ;) ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@127 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/base/space.c | 78 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 28 deletions(-) (limited to 'src/base/space.c') diff --git a/src/base/space.c b/src/base/space.c index b32ae33..fb51c40 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -9,6 +9,24 @@ #include "space.h" #include "index.h" +zone_t* newZone() +{ + zone_t *new; + + new = malloc( sizeof(zone_t) ); + new->list = newList(); + + return new; +} + +void destroyZone(zone_t *p) +{ + assert( p != NULL ); + + destroyList(p->list); + free(p); +} + static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) { return (x1list = newList(); new->listIndex = newIndex(); - new->area = malloc( new->w * sizeof(list_t **) ); + new->zone = malloc( new->w * sizeof(list_t **) ); for( i = 0 ; i < new->w ; i++ ) { - new->area[i] = malloc( new->h * sizeof(list_t *) ); + new->zone[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(); + new->zone[j][i] = newZone(); } } @@ -79,7 +97,7 @@ void addObjectToSpace(space_t *p, void *item) continue; } - addList(p->area[j][i], item); + addList(p->zone[j][i]->list, item); } } @@ -101,14 +119,14 @@ void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list) { void *this; - for( k = 0 ; k < p->area[j][i]->count ; k++ ) + if( j < 0 || j >= p->w || i < 0 || i >= p->h ) { - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } + continue; + } - this = p->area[j][i]->list[k]; + for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) + { + this = p->zone[j][i]->list->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) && @@ -144,14 +162,14 @@ int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h) { void *this; - for( k = 0 ; k < p->area[j][i]->count ; k++ ) + if( j < 0 || j >= p->w || i < 0 || i >= p->h ) { - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } + continue; + } - this = p->area[j][i]->list[k]; + for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) + { + this = p->zone[j][i]->list->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) ) @@ -179,14 +197,14 @@ int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, voi { void *this; - for( k = 0 ; k < p->area[j][i]->count ; k++ ) + if( j < 0 || j >= p->w || i < 0 || i >= p->h ) { - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } + continue; + } - this = p->area[j][i]->list[k]; + for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) + { + this = p->zone[j][i]->list->list[k]; if( this == but ) { @@ -225,9 +243,9 @@ void delObjectFromSpace(space_t *p, void *item) continue; } - index = searchListItem(p->area[j][i], item); + index = searchListItem(p->zone[j][i]->list, item); assert( index != -1 ); - delList(p->area[j][i], index); + delList(p->zone[j][i]->list, index); } } @@ -285,13 +303,17 @@ void printSpace(space_t *p) { for( j = 0 ; j < p->w ; j++ ) { - printf("%3d ", p->area[j][i]->count); + printf("%3d ", p->zone[j][i]->list->count); } putchar('\n'); } } +void actionSpace(space_t *space) +{ +} + void destroySpace(space_t *p) { int j, i; @@ -303,16 +325,16 @@ void destroySpace(space_t *p) { for( j = 0 ; j < p->w ; j++ ) { - destroyList(p->area[j][i]); + destroyZone(p->zone[j][i]); } } for( i = 0 ; i < p->w ; i++ ) { - free(p->area[i]); + free(p->zone[i]); } - free(p->area); + free(p->zone); free(p); } -- cgit v1.2.3