Browse Source

Added regen_db to reduce hp/sp processing delays (bugreport:2256).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13443 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 16 years ago
parent
commit
b80a8cdc87
4 changed files with 37 additions and 5 deletions
  1. 2 0
      Changelog-Trunk.txt
  2. 32 0
      src/map/map.c
  3. 2 1
      src/map/map.h
  4. 1 4
      src/map/status.c

+ 2 - 0
Changelog-Trunk.txt

@@ -3,6 +3,8 @@ 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.
 
+2009/01/12
+	* Added regen_db to reduce hp/sp processing delays (bugreport:2256) [ultramage]
 2009/01/05
 	* Fixed @mobsearch and @showmobs (bugreport:2481) [ultramage]
 	- now only search for mobs on the same map as the caller

+ 32 - 0
src/map/map.c

@@ -99,6 +99,7 @@ static DBMap* bossid_db=NULL; // int id -> struct mob_data* (MVP db)
 static DBMap* map_db=NULL; // unsigned int mapindex -> struct map_data*
 static DBMap* nick_db=NULL; // int char_id -> struct charid2nick* (requested names of offline characters)
 static DBMap* charid_db=NULL; // int char_id -> struct map_session_data*
+static DBMap* regen_db=NULL; // int id -> struct block_list* (status_natural_heal processing)
 
 static int map_users=0;
 static struct block_list *objects[MAX_FLOORITEM];
@@ -1547,6 +1548,9 @@ void map_addiddb(struct block_list *bl)
 			idb_put(bossid_db, bl->id, bl);
 	}
 
+	if( bl->type & BL_REGEN )
+		idb_put(regen_db, bl->id, bl);
+
 	idb_put(id_db,bl->id,bl);
 }
 
@@ -1568,6 +1572,10 @@ void map_deliddb(struct block_list *bl)
 		idb_remove(mobid_db,bl->id);
 		idb_remove(bossid_db,bl->id);
 	}
+
+	if( bl->type & BL_REGEN )
+		idb_remove(regen_db,bl->id);
+
 	idb_remove(id_db,bl->id);
 }
 
@@ -1865,6 +1873,28 @@ void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...)
 	dbi_destroy(iter);
 }
 
+/// Applies func to everything in the db.
+/// Stops iteratin gif func returns -1.
+void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...)
+{
+	DBIterator* iter;
+	struct block_list* bl;
+
+	iter = db_iterator(regen_db);
+	for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) )
+	{
+		va_list args;
+		int ret;
+
+		va_start(args, func);
+		ret = func(bl, args);
+		va_end(args);
+		if( ret == -1 )
+			break;// stop iterating
+	}
+	dbi_destroy(iter);
+}
+
 /// Applies func to everything in the db.
 /// Stops iterating if func returns -1.
 void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...)
@@ -3349,6 +3379,7 @@ void do_final(void)
 	nick_db->destroy(nick_db, nick_db_final);
 	charid_db->destroy(charid_db, NULL);
 	iwall_db->destroy(iwall_db, NULL);
+	regen_db->destroy(regen_db, NULL);
 
 #ifndef TXT_ONLY
     map_sql_close();
@@ -3519,6 +3550,7 @@ int do_init(int argc, char *argv[])
 	map_db = uidb_alloc(DB_OPT_BASE);
 	nick_db = idb_alloc(DB_OPT_BASE);
 	charid_db = idb_alloc(DB_OPT_BASE);
+	regen_db = idb_alloc(DB_OPT_BASE); // efficient status_natural_heal processing
 
 	iwall_db = strdb_alloc(DB_OPT_RELEASE_DATA,2*NAME_LENGTH+2+1); // [Zephyrus] Invisible Walls
 

+ 2 - 1
src/map/map.h

@@ -570,7 +570,8 @@ void map_addiddb(struct block_list *);
 void map_deliddb(struct block_list *bl);
 void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...);
 void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...);
-void map_foreachnpc(int (*func)(struct npc_data* bl, va_list args), ...);
+void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...);
+void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...);
 void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...);
 struct map_session_data * map_nick2sd(const char*);
 struct mob_data * map_getmob_boss(int m);

+ 1 - 4
src/map/status.c

@@ -7461,9 +7461,6 @@ static int status_natural_heal(struct block_list* bl, va_list args)
 	struct map_session_data *sd;
 	int val,rate,bonus = 0,flag;
 
-	if (!(bl->type&BL_REGEN))
-		return 0;
-
 	regen = status_get_regen_data(bl);
 	if (!regen) return 0;
 	status = status_get_status_data(bl);
@@ -7647,7 +7644,7 @@ static int status_natural_heal(struct block_list* bl, va_list args)
 static int status_natural_heal_timer(int tid, unsigned int tick, int id, intptr data)
 {
 	natural_heal_diff_tick = DIFF_TICK(tick,natural_heal_prev_tick);
-	map_foreachiddb(status_natural_heal);
+	map_foreachregen(status_natural_heal);
 	natural_heal_prev_tick = tick;
 	return 0;
 }