فهرست منبع

Rewrote and optimized clif_hpmeter to employ map_foreachinarea() rather than an iteration over every session (bugreport:3956).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14318 54d463be-8e91-2dee-dedb-b68131a5f0ec
Paradox924X 15 سال پیش
والد
کامیت
024b015009
3فایلهای تغییر یافته به همراه35 افزوده شده و 34 حذف شده
  1. 1 0
      Changelog-Trunk.txt
  2. 33 34
      src/map/clif.c
  3. 1 0
      src/map/clif.h

+ 1 - 0
Changelog-Trunk.txt

@@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2010/05/31
+	* Rewrote and optimized clif_hpmeter to employ map_foreachinarea() rather than an iteration over every session (bugreport:3956). [Paradox924X]
 	* Rewrote and reorganized checks in @autotrade to check and display most useful information first (bugreport:4253). [Paradox924X]
 2010/05/30
 	* Damaged reflected from skills will now be shown as multiple hits if the skill used was multi-hit. [Paradox924X]

+ 33 - 34
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;
 }

+ 1 - 0
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);