Explorar o código

Minor performance improvement. server no longer wastes processing time creating the awfully long spawn packet when there is nobody in the map it is being spawned in (for mobs & npcs). this also makes server boot faster.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@15856 54d463be-8e91-2dee-dedb-b68131a5f0ec
shennetsind %!s(int64=13) %!d(string=hai) anos
pai
achega
8be0fbff1f
Modificáronse 2 ficheiros con 23 adicións e 16 borrados
  1. 2 1
      src/map/mob.c
  2. 21 15
      src/map/npc.c

+ 2 - 1
src/map/mob.c

@@ -915,7 +915,8 @@ int mob_spawn (struct mob_data *md)
 		md->sc.option = md->db->option;
 
 	map_addblock(&md->bl);
-	clif_spawn(&md->bl);
+	if( map[md->bl.m].users )
+		clif_spawn(&md->bl);
 	skill_unit_move(&md->bl,tick,1);
 	mobskill_use(md, tick, MSC_SPAWN);
 	return 0;

+ 21 - 15
src/map/npc.c

@@ -168,17 +168,14 @@ int npc_enable(const char* name, int flag)
 		return 0;
 	}
 
-	if (flag&1)
-	{
+	if (flag&1) {
 		nd->sc.option&=~OPTION_INVISIBLE;
 		clif_spawn(&nd->bl);
-	}
-	else if (flag&2)
+	} else if (flag&2)
 		nd->sc.option&=~OPTION_HIDE;
 	else if (flag&4)
 		nd->sc.option|= OPTION_HIDE;
-	else	//Can't change the view_data to invisible class because the view_data for all npcs is shared! [Skotlex]
-	{
+	else {	//Can't change the view_data to invisible class because the view_data for all npcs is shared! [Skotlex]
 		nd->sc.option|= OPTION_INVISIBLE;
 		clif_clearunit_area(&nd->bl,CLR_OUTSIGHT);  // Hack to trick maya purple card [Xazax]
 	}
@@ -1964,7 +1961,8 @@ struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, shor
 	status_set_viewdata(&nd->bl, nd->class_);
 	status_change_init(&nd->bl);
 	unit_dataset(&nd->bl);
-	clif_spawn(&nd->bl);
+	if( map[nd->bl.m].users )
+		clif_spawn(&nd->bl);
 	strdb_put(npcname_db, nd->exname, nd);
 
 	return nd;
@@ -2024,7 +2022,8 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
 	status_set_viewdata(&nd->bl, nd->class_);
 	status_change_init(&nd->bl);
 	unit_dataset(&nd->bl);
-	clif_spawn(&nd->bl);
+	if( map[nd->bl.m].users )
+		clif_spawn(&nd->bl);
 	strdb_put(npcname_db, nd->exname, nd);
 
 	return strchr(start,'\n');// continue
@@ -2131,7 +2130,8 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
 		status_change_init(&nd->bl);
 		unit_dataset(&nd->bl);
 		nd->ud.dir = dir;
-		clif_spawn(&nd->bl);
+		if( map[nd->bl.m].users )
+			clif_spawn(&nd->bl);
 	} else
 	{// 'floating' shop?
 		map_addiddb(&nd->bl);
@@ -2343,7 +2343,8 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 		if( class_ >= 0 )
 		{
 			status_set_viewdata(&nd->bl, nd->class_);
-			clif_spawn(&nd->bl);
+			if( map[nd->bl.m].users )
+				clif_spawn(&nd->bl);
 		}
 	}
 	else
@@ -2489,7 +2490,8 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
 		if( class_ >= 0 )
 		{
 			status_set_viewdata(&nd->bl, nd->class_);
-			clif_spawn(&nd->bl);
+			if( map[nd->bl.m].users )
+				clif_spawn(&nd->bl);
 		}
 	}
 	else
@@ -2567,7 +2569,8 @@ int npc_duplicate4instance(struct npc_data *snd, int m)
 		status_set_viewdata(&wnd->bl, wnd->class_);
 		status_change_init(&wnd->bl);
 		unit_dataset(&wnd->bl);
-		clif_spawn(&wnd->bl);
+		if( map[wnd->bl.m].users )
+			clif_spawn(&wnd->bl);
 		strdb_put(npcname_db, wnd->exname, wnd);
 	}
 	else
@@ -2684,7 +2687,8 @@ void npc_setdisplayname(struct npc_data* nd, const char* newname)
 	nullpo_retv(nd);
 
 	safestrncpy(nd->name, newname, sizeof(nd->name));
-	clif_charnameack(0, &nd->bl);
+	if( map[nd->bl.m].users )
+		clif_charnameack(0, &nd->bl);
 }
 
 /// Changes the display class of the npc.
@@ -2698,10 +2702,12 @@ void npc_setclass(struct npc_data* nd, short class_)
 	if( nd->class_ == class_ )
 		return;
 
-	clif_clearunit_area(&nd->bl, CLR_OUTSIGHT);// fade out
+	if( map[nd->bl.m].users )
+		clif_clearunit_area(&nd->bl, CLR_OUTSIGHT);// fade out
 	nd->class_ = class_;
 	status_set_viewdata(&nd->bl, class_);
-	clif_spawn(&nd->bl);// fade in
+	if( map[nd->bl.m].users )
+		clif_spawn(&nd->bl);// fade in
 }
 
 /// Parses a function.