Prechádzať zdrojové kódy

Changed the dynamic mobs system to also unload mobs that have respawn time but are already spawned - 22M less mem usage (bugreport:1197).
Also added a check to not respawn mobs on maps with no players (potentially unsafe operation, needs further inspection).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12402 54d463be-8e91-2dee-dedb-b68131a5f0ec

ultramage 17 rokov pred
rodič
commit
3d6f2af01c
3 zmenil súbory, kde vykonal 13 pridanie a 1 odobranie
  1. 5 0
      Changelog-Trunk.txt
  2. 7 0
      src/map/mob.c
  3. 1 1
      src/map/npc.c

+ 5 - 0
Changelog-Trunk.txt

@@ -3,6 +3,11 @@ 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/03/19
+	* Changed the dynamic mobs system to also unload mobs that have respawn
+	  time but are already spawned - 22M less mem usage (bugreport:1197)
+	- also added a check to not respawn mobs on maps with no players
+	  (potentially unsafe operation, needs further inspection)
 2008/03/18
 	* Fixed invited party members not displaying correctly (bugreport:1199)
 	* Fixed OnPCLoginEvent not working correctly (bugreport:1182) [ultramage]

+ 7 - 0
src/map/mob.c

@@ -888,6 +888,13 @@ int mob_spawn (struct mob_data *md)
 		md->bl.x = md->spawn->x;
 		md->bl.y = md->spawn->y;
 
+		if( map[md->spawn->m].users == 0 && md->spawn->state.dynamic )
+		{// cache the mob instead of spawning it
+			//FIXME: deleting 'md' is a potentially dangerous operation
+			unit_free(&md->bl,0);
+			return 0;
+		}
+
 		if ((md->bl.x == 0 && md->bl.y == 0) || md->spawn->xs || md->spawn->ys)
 		{	//Monster can be spawned on an area.
 			if (!map_search_freecell(&md->bl, -1,

+ 1 - 1
src/map/npc.c

@@ -2335,7 +2335,7 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
 	data = aMalloc(sizeof(struct spawn_data));
 	memcpy(data, &mob, sizeof(struct spawn_data));
 	
-	if( !battle_config.dynamic_mobs || data->delay1 || data->delay2 ) {
+	if( !battle_config.dynamic_mobs ) {
 		data->state.dynamic = false;
 		npc_parse_mob2(data);
 		npc_delay_mob += data->num;