From a05f029a4d7ebcdc9915c994f589bbca6f072004 Mon Sep 17 00:00:00 2001 From: ultramage Date: Thu, 3 Jan 2008 20:43:25 +0000 Subject: Removed map_data's block_count, as (quote Yor/ja2160), "Perhaps useful for debug, but uses memory AND CPU for nothing." (block lists are linked lists, they don't need count tracking) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12001 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 4 + src/map/map.c | 260 +++++++++++++++++----------------------------------- src/map/map.h | 21 ++--- src/map/script.c | 16 ++-- src/map/unit.c | 6 +- 5 files changed, 104 insertions(+), 203 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index ddfca65fc..81387859a 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -3,6 +3,10 @@ Date Added AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. +2008/01/03 + * Removed map_data's block_count, as (quote Yor/ja2160), + "Perhaps useful for debug, but uses memory AND CPU for nothing." + (block lists are linked lists, they don't need count tracking) 2007/12/31 * Fixed a crash in txt char-servers that the memory manager was hiding. online_char_db being used after being destroyed (since r4026) diff --git a/src/map/map.c b/src/map/map.c index c57f76987..0a7bd952d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -310,7 +310,6 @@ int map_addblock_sub (struct block_list *bl, int flag) bl->prev = &bl_head; if (bl->next) bl->next->prev = bl; map[m].block_mob[pos] = bl; - map[m].block_mob_count[pos]++; } else { if (bl->type == BL_PC && flag) { @@ -331,7 +330,6 @@ int map_addblock_sub (struct block_list *bl, int flag) bl->prev = &bl_head; if (bl->next) bl->next->prev = bl; map[m].block[pos] = bl; - map[m].block_count[pos]++; } #ifdef CELL_NOSTACK @@ -376,12 +374,8 @@ int map_delblock_sub (struct block_list *bl, int flag) // リストの頭なので、map[]のblock_listを更新する if (bl->type == BL_MOB) { map[bl->m].block_mob[b] = bl->next; - if ((map[bl->m].block_mob_count[b]--) < 0) - map[bl->m].block_mob_count[b] = 0; } else { map[bl->m].block[b] = bl->next; - if((map[bl->m].block_count[b]--) < 0) - map[bl->m].block_count[b] = 0; } } else { bl->prev->next = bl->next; @@ -457,42 +451,13 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick) return 0; } -/*========================================== - * 周?のPC人?を?える (unused) - *------------------------------------------*/ -int map_countnearpc (int m, int x, int y) -{ - int bx, by, c = 0; - struct block_list *bl=NULL; - - if (map[m].users == 0) - return 0; - for (by = y/BLOCK_SIZE-AREA_SIZE/BLOCK_SIZE-1; by<=y/BLOCK_SIZE+AREA_SIZE/BLOCK_SIZE+1; by++) { - if (by < 0 || by >= map[m].bys) - continue; - for (bx = x/BLOCK_SIZE-AREA_SIZE/BLOCK_SIZE-1; bx <= x/BLOCK_SIZE+AREA_SIZE/BLOCK_SIZE+1; bx++) { - if (bx < 0 || bx >= map[m].bxs) - continue; - bl = map[m].block[bx+by*map[m].bxs]; - while(bl) { - if (bl->type == BL_PC) - c++; - bl = bl->next; - } - } - } - - return c; -} - /*========================================== * Counts specified number of objects on given cell. *------------------------------------------*/ int map_count_oncell(int m, int x, int y, int type) { int bx,by; - struct block_list *bl=NULL; - int i,c; + struct block_list *bl; int count = 0; if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys)) @@ -502,20 +467,15 @@ int map_count_oncell(int m, int x, int y, int type) by = y/BLOCK_SIZE; if (type&~BL_MOB) - { - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext) - if(bl->x == x && bl->y == y && bl->type&type) count++; - } + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + if(bl->x == x && bl->y == y && bl->type&type) + count++; if (type&BL_MOB) - { - bl = map[m].block_mob[bx+by*map[m].bxs]; - c = map[m].block_mob_count[bx+by*map[m].bxs]; - for(i=0;inext) - if(bl->x == x && bl->y == y) count++; - } + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + if(bl->x == x && bl->y == y) + count++; + return count; } /* @@ -525,23 +485,21 @@ struct skill_unit *map_find_skill_unit_oncell(struct block_list *target,int x,in { int m,bx,by; struct block_list *bl; - int i,c; struct skill_unit *unit; m = target->m; if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys)) return NULL; + bx = x/BLOCK_SIZE; by = y/BLOCK_SIZE; - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { if (bl->x != x || bl->y != y || bl->type != BL_SKILL) continue; unit = (struct skill_unit *) bl; - if (unit==out_unit || !unit->alive || - !unit->group || unit->group->skill_id!=skill_id) + if (unit==out_unit || !unit->alive || !unit->group || unit->group->skill_id!=skill_id) continue; if (battle_check_target(&unit->bl,target,unit->group->target_flag)>0) return unit; @@ -557,8 +515,8 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis va_list ap; int bx,by,m; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; - int blockcount=bl_list_count,i,c; + struct block_list *bl; + int blockcount=bl_list_count,i; int x0,x1,y0,y1; va_start(ap,type); @@ -570,11 +528,10 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis if (type&~BL_MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { - for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl && bl->type&type + for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 #ifdef CIRCULAR_AREA && check_distance_bl(center, bl, range) @@ -587,11 +544,9 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis if(type&BL_MOB) for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){ for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ - bl = map[m].block_mob[bx+by*map[m].bxs]; - c = map[m].block_mob_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl - && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 #ifdef CIRCULAR_AREA && check_distance_bl(center, bl, range) #endif @@ -625,12 +580,14 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block va_list ap; int bx,by,m; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; - int blockcount=bl_list_count,i,c; + struct block_list *bl; + int blockcount=bl_list_count,i; int x0,x1,y0,y1; + m = center->m; if (m < 0) return 0; + va_start(ap,type); x0 = max(center->x-range, 0); @@ -639,12 +596,11 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block y1 = min(center->y+range, map[m].ys-1); if (type&~BL_MOB) - for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { - for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl && bl->type&type + for(by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { + for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 #ifdef CIRCULAR_AREA && check_distance_bl(center, bl, range) @@ -658,11 +614,9 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block if(type&BL_MOB) for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){ for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ - bl = map[m].block_mob[bx+by*map[m].bxs]; - c = map[m].block_mob_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl - && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 #ifdef CIRCULAR_AREA && check_distance_bl(center, bl, range) #endif @@ -699,8 +653,8 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, in va_list ap; int bx,by; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; - int blockcount=bl_list_count,i,c; + struct block_list *bl; + int blockcount=bl_list_count,i; if (m < 0) return 0; @@ -723,27 +677,18 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, in if (y1 >= map[m].ys) y1 = map[m].ys-1; if (type&~BL_MOB) - for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { - for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl && bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countnext ) + if(bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countnext){ - if(bl && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countnext ) + if(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count=BL_LIST_MAX) ShowWarning("map_foreachinarea: block count too many!\n"); @@ -772,9 +717,9 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_ { int bx,by,m; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; + struct block_list *bl; va_list ap; - int blockcount=bl_list_count,i,c; + int blockcount=bl_list_count,i; int x0, x1, y0, y1; if (!range) return 0; @@ -819,9 +764,8 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_ for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){ for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ if (type&~BL_MOB) { - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { if(bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && @@ -830,9 +774,8 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_ } } if (type&BL_MOB) { - bl = map[m].block_mob[bx+by*map[m].bxs]; - c = map[m].block_mob_count[bx+by*map[m].bxs]; - for(i=0;inext){ + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { if(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countnext){ - if(!(bl->type&type && + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && - bl_list_count0 && bl->xx>x1+dx) || (dy>0 && bl->ynext){ - if(!( - bl->x>=x0 && bl->x<=x1 && + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + { + if( bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && - bl_list_count0 && bl->xx>x1+dx) || (dy>0 && bl->yy>y1+dy)) - bl_list[bl_list_count++]=bl; + bl_list[bl_list_count++]=bl; } } } @@ -910,9 +848,9 @@ int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int { int bx,by; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; + struct block_list *bl; va_list ap; - int blockcount=bl_list_count,i,c; + int blockcount=bl_list_count,i; if (x < 0 || y < 0 || x >= map[m].xs || y >= map[m].ys) return 0; @@ -922,26 +860,14 @@ int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int bx=x/BLOCK_SIZE; if(type&~BL_MOB) - { - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext) - { - if(bl && bl->type&type && bl->x==x && bl->y==y && bl_list_countnext ) + if(bl->type&type && bl->x==x && bl->y==y && bl_list_countnext) - { - if(bl && bl->x==x && bl->y==y && bl_list_countnext ) + if(bl->x==x && bl->y==y && bl_list_count=BL_LIST_MAX) ShowWarning("map_foreachincell: block count too many!\n"); @@ -1002,7 +928,7 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y va_list ap; int i, blockcount = bl_list_count; struct block_list *bl; - int c, bx, by; + int bx, by; //method specific variables int magnitude2, len_limit; //The square of the magnitude int k, xi, yi, xu, yu; @@ -1070,10 +996,9 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y if (type & ~BL_MOB) for (by = my0 / BLOCK_SIZE; by <= my1 / BLOCK_SIZE; by++) { for(bx=mx0/BLOCK_SIZE;bx<=mx1/BLOCK_SIZE;bx++){ - bl = map[m].block[bx+by*map[m].bxs]; - c = map[m].block_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl && bl->prev && bl->type&type && bl_list_countnext ) + { + if(bl->prev && bl->type&type && bl_list_countx; yi = bl->y; @@ -1103,13 +1028,13 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y } } } + if(type&BL_MOB) for(by=my0/BLOCK_SIZE;by<=my1/BLOCK_SIZE;by++){ for(bx=mx0/BLOCK_SIZE;bx<=mx1/BLOCK_SIZE;bx++){ - bl = map[m].block_mob[bx+by*map[m].bxs]; - c = map[m].block_mob_count[bx+by*map[m].bxs]; - for(i=0;inext){ - if(bl && bl->prev && bl_list_countnext ) + { + if(bl->prev && bl_list_countx; yi = bl->y; @@ -1159,38 +1084,25 @@ int map_foreachinmap(int (*func)(struct block_list*,va_list), int m, int type,.. { int b, bsize; int returnCount =0; //total sum of returned values of func() [Skotlex] - struct block_list *bl=NULL; + struct block_list *bl; va_list ap; - int blockcount=bl_list_count,i,c; + int blockcount=bl_list_count,i; va_start(ap,type); bsize = map[m].bxs * map[m].bys; + if(type&~BL_MOB) - { - for(b=0;bnext) - { - if(bl && bl->type&type && bl_list_countnext ) + if(bl->type&type && bl_list_countnext) - { - if(bl && bl_list_countnext ) + if(bl_list_count=BL_LIST_MAX) ShowWarning("map_foreachinmap: block count too many!\n"); @@ -1830,7 +1742,7 @@ struct map_session_data * map_nick2sd(const char *nick) *------------------------------------------*/ struct block_list * map_id2bl(int id) { - struct block_list *bl=NULL; + struct block_list *bl; if(id >= 0 && id < ARRAYLENGTH(objects)) bl = objects[id]; else @@ -2612,10 +2524,6 @@ int map_readallmaps (void) size = map[i].bxs * map[i].bys * sizeof(struct block_list*); map[i].block = (struct block_list**)aCalloc(size, 1); map[i].block_mob = (struct block_list**)aCalloc(size, 1); - - size = map[i].bxs * map[i].bys * sizeof(int); - map[i].block_count = (int*)aCallocA(size, 1); - map[i].block_mob_count = (int*)aCallocA(size, 1); } if( !enable_grf ) @@ -3093,8 +3001,6 @@ void do_final(void) #endif if(map[i].block) aFree(map[i].block); if(map[i].block_mob) aFree(map[i].block_mob); - if(map[i].block_count) aFree(map[i].block_count); - if(map[i].block_mob_count) aFree(map[i].block_mob_count); if(battle_config.dynamic_mobs) { //Dynamic mobs flag by [random] for (j=0; jnext){ + for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++) + for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++) + for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1) count++; - } - } - } + script_pushint(st,count); return 0; } diff --git a/src/map/unit.c b/src/map/unit.c index 6e0eed53c..c8ae55bc3 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -149,8 +149,7 @@ static int unit_walktoxy_timer(int tid,unsigned int tick,int id,int data) // バシリカ判定 - map_foreachinmovearea(clif_outsight, bl, AREA_SIZE, - dx, dy, sd?BL_ALL:BL_PC, bl); + map_foreachinmovearea(clif_outsight, bl, AREA_SIZE, dx, dy, sd?BL_ALL:BL_PC, bl); x += dx; y += dy; @@ -161,8 +160,7 @@ static int unit_walktoxy_timer(int tid,unsigned int tick,int id,int data) return 0; //map_moveblock has altered the object beyond what we expected (moved/warped it) ud->walktimer = 1; - map_foreachinmovearea(clif_insight, bl, AREA_SIZE, - -dx, -dy, sd?BL_ALL:BL_PC, bl); + map_foreachinmovearea(clif_insight, bl, AREA_SIZE, -dx, -dy, sd?BL_ALL:BL_PC, bl); ud->walktimer = -1; if(sd) { -- cgit v1.2.3-60-g2f50