From 1427ad8d171523acf31be57337f02b0e04ab5a5a Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sun, 29 Apr 2012 15:47:57 +0000 Subject: reasonably-sized performance improvement: @reloadscript is about to 3 times faster. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16004 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 2 +- src/map/map.c | 2 +- src/map/mob.c | 2 +- src/map/npc.c | 52 +++++++++++++++++++++++++++++----------------------- src/map/npc.h | 2 +- src/map/script.c | 4 +--- 6 files changed, 34 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 6d5190d6e..691cf2560 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4548,7 +4548,7 @@ ACMD_FUNC(unloadnpc) } npc_unload_duplicates(nd); - npc_unload(nd); + npc_unload(nd,true); npc_read_event_script(); clif_displaymessage(fd, msg_txt(112)); // Npc Disabled. return 0; diff --git a/src/map/map.c b/src/map/map.c index 72ee4b0b6..0ce364c69 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3533,7 +3533,7 @@ int cleanup_sub(struct block_list *bl, va_list ap) map_quit((struct map_session_data *) bl); break; case BL_NPC: - npc_unload((struct npc_data *)bl); + npc_unload((struct npc_data *)bl,true); break; case BL_MOB: unit_free(bl,CLR_OUTSIGHT); diff --git a/src/map/mob.c b/src/map/mob.c index 48dd67100..3e8df661f 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -168,7 +168,7 @@ void mvptomb_destroy(struct mob_data *md) struct npc_data *nd = (struct npc_data *)map_id2bl(md->tomb_nid); if (nd) - npc_unload(nd); + npc_unload(nd,true); md->tomb_nid = 0; } diff --git a/src/map/npc.c b/src/map/npc.c index 66635543a..44b29ad21 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1725,7 +1725,7 @@ static int npc_unload_dup_sub(struct npc_data* nd, va_list args) src_id = va_arg(args, int); if (nd->src_id == src_id) - npc_unload(nd); + npc_unload(nd, true); return 0; } @@ -1735,12 +1735,12 @@ void npc_unload_duplicates(struct npc_data* nd) map_foreachnpc(npc_unload_dup_sub,nd->bl.id); } -int npc_unload(struct npc_data* nd) -{ +int npc_unload(struct npc_data* nd, bool single) { nullpo_ret(nd); npc_remove_map(nd); map_deliddb(&nd->bl); + if( single ) strdb_remove(npcname_db, nd->exname); if (nd->chat_id) // remove npc chatroom object and kick users @@ -1752,20 +1752,17 @@ int npc_unload(struct npc_data* nd) if( (nd->subtype == SHOP || nd->subtype == CASHSHOP) && nd->src_id == 0) //src check for duplicate shops [Orcao] aFree(nd->u.shop.shop_item); - else - if( nd->subtype == SCRIPT ) - { + else if( nd->subtype == SCRIPT ) { struct s_mapiterator* iter; struct block_list* bl; - ev_db->foreach(ev_db,npc_unload_ev,nd->exname); //Clean up all events related + if( single ) + ev_db->foreach(ev_db,npc_unload_ev,nd->exname); //Clean up all events related iter = mapit_geteachpc(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) - { - struct map_session_data *sd = map_id2sd(bl->id); - if( sd && sd->npc_timer_id != INVALID_TIMER ) - { + for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { + struct map_session_data *sd = ((TBL_PC*)bl); + if( sd && sd->npc_timer_id != INVALID_TIMER ) { const struct TimerData *td = get_timer(sd->npc_timer_id); if( td && td->id != nd->bl.id ) @@ -3435,14 +3432,18 @@ int npc_reload(void) struct s_mapiterator* iter; struct block_list* bl; + ShowDebug("Oi4-1 %u\n",gettick()); + db_clear(npcname_db); + ShowDebug("Oi4-2 %u\n",gettick()); + db_clear(ev_db); //Remove all npcs/mobs. [Skotlex] + ShowDebug("Oi5 %u\n",gettick()); iter = mapit_geteachiddb(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) - { + for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { switch(bl->type) { case BL_NPC: if( bl->id != fake_nd->bl.id )// don't remove fake_nd - npc_unload((struct npc_data *)bl); + npc_unload((struct npc_data *)bl, false); break; case BL_MOB: unit_free(bl,CLR_OUTSIGHT); @@ -3450,7 +3451,7 @@ int npc_reload(void) } } mapit_free(iter); - + ShowDebug("Oi6 %u\n",gettick()); if(battle_config.dynamic_mobs) {// dynamic check by [random] for (m = 0; m < map_num; m++) { @@ -3469,19 +3470,21 @@ int npc_reload(void) if (map[m].npc_num > 0) ShowWarning("npc_reload: %d npcs weren't removed at map %s!\n", map[m].npc_num, map[m].name); } - + ShowDebug("Oi7 %u\n",gettick()); // clear mob spawn lookup index mob_clear_spawninfo(); - + ShowDebug("Oi8 %u\n",gettick()); // clear npc-related data structures ev_db->clear(ev_db,NULL); + ShowDebug("Oi9 %u\n",gettick()); npcname_db->clear(npcname_db,NULL); + ShowDebug("Oi10 %u\n",gettick()); npc_warp = npc_shop = npc_script = 0; npc_mob = npc_cache_mob = npc_delay_mob = 0; // reset mapflags map_flags_init(); - + ShowDebug("Oi11 %u\n",gettick()); //TODO: the following code is copy-pasted from do_init_npc(); clean it up // Reloading npcs now for (nsl = npc_src_files; nsl; nsl = nsl->next) @@ -3489,7 +3492,7 @@ int npc_reload(void) ShowStatus("Loading NPC file: %s"CL_CLL"\r", nsl->name); npc_parsesrcfile(nsl->name); } - + ShowDebug("Oi12 %u\n",gettick()); ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n" "\t-'"CL_WHITE"%d"CL_RESET"' Warps\n" "\t-'"CL_WHITE"%d"CL_RESET"' Shops\n" @@ -3501,10 +3504,10 @@ int npc_reload(void) for( i = 0; i < ARRAYLENGTH(instance); ++i ) instance_init(instance[i].instance_id); - + ShowDebug("Oi13 %u\n",gettick()); //Re-read the NPC Script Events cache. npc_read_event_script(); - + ShowDebug("Oi14 %u\n",gettick()); //Execute the OnInit event for freshly loaded npcs. [Skotlex] ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n",npc_event_doall("OnInit")); // Execute rest of the startup events if connected to char-server. [Lance] @@ -3523,10 +3526,13 @@ int do_final_npc(void) int i; struct block_list *bl; + db_clear(npcname_db); + db_clear(ev_db); + for (i = START_NPC_NUM; i < npc_id; i++){ if ((bl = map_id2bl(i))){ if (bl->type == BL_NPC) - npc_unload((struct npc_data *)bl); + npc_unload((struct npc_data *)bl, false); else if (bl->type&(BL_MOB|BL_PET|BL_HOM|BL_MER)) unit_free(bl, CLR_OUTSIGHT); } diff --git a/src/map/npc.h b/src/map/npc.h index 81491eeb3..da5f0a295 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -152,7 +152,7 @@ int npc_gettimerevent_tick(struct npc_data* nd); int npc_settimerevent_tick(struct npc_data* nd, int newtimer); int npc_remove_map(struct npc_data* nd); void npc_unload_duplicates (struct npc_data* nd); -int npc_unload(struct npc_data* nd); +int npc_unload(struct npc_data* nd, bool); int npc_reload(void); void npc_read_event_script(void); int npc_script_event(struct map_session_data* sd, enum npce_event type); diff --git a/src/map/script.c b/src/map/script.c index 269230b38..4b3ab3d93 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4017,8 +4017,7 @@ int do_init_script() return 0; } -int script_reload() -{ +int script_reload() { userfunc_db->clear(userfunc_db, db_script_free_code_sub); db_clear(scriptlabel_db); @@ -4031,7 +4030,6 @@ int script_reload() } linkdb_final(&sleep_db); } - mapreg_reload(); return 0; } -- cgit v1.2.3-70-g09d2