diff options
author | Paradox924X <Paradox924X@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2010-06-01 00:10:31 +0000 |
---|---|---|
committer | Paradox924X <Paradox924X@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2010-06-01 00:10:31 +0000 |
commit | 693f6765c3f9ea234862d58f9e3b3aa2428ca986 (patch) | |
tree | f02c3518906322950b0ef12d1e14dee691e813c3 /src/map | |
parent | 3410b900c6a31d04f75b4e527b2656117029edc7 (diff) | |
download | hercules-693f6765c3f9ea234862d58f9e3b3aa2428ca986.tar.gz hercules-693f6765c3f9ea234862d58f9e3b3aa2428ca986.tar.bz2 hercules-693f6765c3f9ea234862d58f9e3b3aa2428ca986.tar.xz hercules-693f6765c3f9ea234862d58f9e3b3aa2428ca986.zip |
Rewrote and optimized clif_hpmeter to employ map_foreachinarea() rather than an iteration over every session (bugreport:3956).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14318 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/clif.c | 67 | ||||
-rw-r--r-- | src/map/clif.h | 1 |
2 files changed, 34 insertions, 34 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index 5f49ac039..ec8cbddac 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5974,50 +5974,49 @@ void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp) } /*========================================== - * GMへ場所とHP通知 + * *------------------------------------------*/ -int clif_hpmeter(struct map_session_data *sd) +int clif_hpmeter_sub(struct block_list *bl, va_list ap) { - struct map_session_data *sd2; - unsigned char buf[16]; - int i, x0, y0, x1, y1; + struct map_session_data *sd, *tsd; int level; - nullpo_retr(0, sd); + sd = va_arg(ap, struct map_session_data *); + tsd = (TBL_PC *)bl; - x0 = sd->bl.x - AREA_SIZE; - y0 = sd->bl.y - AREA_SIZE; - x1 = sd->bl.x + AREA_SIZE; - y1 = sd->bl.y + AREA_SIZE; + nullpo_retr(0, sd); + nullpo_retr(0, tsd); - WBUFW(buf,0) = 0x106; - WBUFL(buf,2) = sd->status.account_id; - if( sd->battle_status.max_hp > SHRT_MAX ) - { //To correctly display the %hp bar. [Skotlex] - WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100); - WBUFW(buf,8) = 100; - } - else - { - WBUFW(buf,6) = sd->battle_status.hp; - WBUFW(buf,8) = sd->battle_status.max_hp; - } + if( !tsd->fd ) + return 0; - //TODO: replace with map_foreachinarea? - for( i = 0; i < fd_max; i++ ) + if( (level = pc_isGM(tsd)) >= battle_config.disp_hpmeter && level >= pc_isGM(sd) ) { - if( session[i] && session[i]->func_parse == clif_parse && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.active ) - { - if( sd2->bl.m != sd->bl.m || sd2->bl.x < x0 || sd2->bl.y < y0 || sd2->bl.x > x1 || sd2->bl.y > y1 ) - continue; // Not in the Visual Area - if( battle_config.disp_hpmeter && (level = pc_isGM(sd2)) >= battle_config.disp_hpmeter && level >= pc_isGM(sd) ) - { - WFIFOHEAD(i,packet_len(0x106)); - memcpy(WFIFOP(i,0),buf,packet_len(0x106)); - WFIFOSET(i,packet_len(0x106)); - } + WFIFOHEAD(tsd->fd,packet_len(0x106)); + WFIFOW(tsd->fd,0) = 0x106; + WFIFOL(tsd->fd,2) = sd->status.account_id; + if( sd->battle_status.max_hp > SHRT_MAX ) + { //To correctly display the %hp bar. [Skotlex] + WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100); + WFIFOW(tsd->fd,8) = 100; + } else { + WFIFOW(tsd->fd,6) = sd->battle_status.hp; + WFIFOW(tsd->fd,8) = sd->battle_status.max_hp; } + WFIFOSET(tsd->fd,packet_len(0x106)); } + return 0; +} + +/*========================================== + * GMへ場所とHP通知 + *------------------------------------------*/ +int clif_hpmeter(struct map_session_data *sd) +{ + nullpo_retr(0, sd); + + if( battle_config.disp_hpmeter ) + map_foreachinarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd); return 0; } diff --git a/src/map/clif.h b/src/map/clif.h index 958acc5ee..c1522db96 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -284,6 +284,7 @@ int clif_party_xy_single(int fd, struct map_session_data *sd); int clif_party_hp(struct map_session_data *sd); void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp); int clif_hpmeter(struct map_session_data *sd); +int clif_hpmeter_sub(struct block_list *bl, va_list ap); // guild int clif_guild_created(struct map_session_data *sd,int flag); |