From 693f6765c3f9ea234862d58f9e3b3aa2428ca986 Mon Sep 17 00:00:00 2001 From: Paradox924X Date: Tue, 1 Jun 2010 00:10:31 +0000 Subject: 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 --- src/map/clif.c | 67 +++++++++++++++++++++++++++++----------------------------- src/map/clif.h | 1 + 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/map') 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); -- cgit v1.2.3-60-g2f50