From a0f73cf7421e55e84b61065b4eb7ed13b05ce055 Mon Sep 17 00:00:00 2001 From: oroborus Date: Fri, 27 Jun 2008 16:46:09 +0000 Subject: - šetřit možnosti podvádění – rychlost pohybu - delObjectFromSpace ma casovu narocnost log(2,n) pri odstraneni objetu zo zonamu objektov ( btw. z hladiska programovania su veci pre 0.20 hotove ) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/tuxanci_ng@75 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/space.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/space.c') diff --git a/src/space.c b/src/space.c index 96ac81b..0d3060a 100644 --- a/src/space.c +++ b/src/space.c @@ -331,9 +331,8 @@ void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list) } } -void* getObjectFromSpaceWithID(space_t *space, int id) +int searchObjectInSpace(space_t *space, int id) { -#ifdef ERROR_SUPPORT int point_id; int x, y, w, h; int len; @@ -357,7 +356,7 @@ void* getObjectFromSpaceWithID(space_t *space, int id) if( max < 0 || point >= len || max < min ) { - return NULL; + return -1; } space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h); @@ -369,7 +368,7 @@ void* getObjectFromSpaceWithID(space_t *space, int id) if( point_id == id ) { - return space->list->list[point]; + return point; } if( id > point_id ) @@ -384,29 +383,15 @@ void* getObjectFromSpaceWithID(space_t *space, int id) 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); +void* getObjectFromSpaceWithID(space_t *space, int id) +{ + int index; - if( this_id == id ) - { - return this; - } - } + index = searchObjectInSpace(space, id); - return NULL; -#endif + return ( index != -1 ? space->list->list[index] : NULL ); } int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h) @@ -495,7 +480,7 @@ void delObjectFromSpace(space_t *p, void *item) } } - index = searchListItem(p->list, item); + index = searchObjectInSpace(p, id); assert( index != -1 ); delList(p->list, index); } -- cgit v1.2.3