From 6e0a214bcc66d10e75d08b37bd8d5b65bd10cfd0 Mon Sep 17 00:00:00 2001 From: KimLS Date: Fri, 31 Jan 2014 20:38:32 -0800 Subject: [PATCH] Compiler option for playing with npctype_cache as was requested for a feature. Not entirely tested may need some work. Currently defaults to old behavior on #repop. --- CMakeLists.txt | 3 +++ zone/CMakeLists.txt | 4 ++++ zone/command.cpp | 28 +++++++++++++++++++++++++++- zone/command.h | 1 + zone/zone.cpp | 24 ++++++++++++++++++++++++ zone/zone.h | 1 + 6 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 606eaf253..06ca7c995 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,9 @@ SET(EQEMU_DEBUG_LEVEL 5 CACHE STRING "EQEmu debug level: 10 - More errors than you ever wanted to see" ) +#NPC Types Cache Behavior +OPTION(EQEMU_DEPOP_INVALIDATES_CACHE "#repop invalidates the npc_types cache (will cause a larger database hit on #repop but is more convienent)." ON) + #Bots are a compile time option so on/off OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 9e45b698a..49410f0f2 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -200,6 +200,10 @@ SET(zone_headers zonedump.h ) +IF(EQEMU_DEPOP_INVALIDATES_CACHE) + ADD_DEFINITIONS(-DDEPOP_INVALIDATES_NPC_TYPES_CACHE) +ENDIF(EQEMU_DEPOP_INVALIDATES_CACHE) + ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) INSTALL(TARGETS zone RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/zone/command.cpp b/zone/command.cpp index 35f292605..8af940a32 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -448,7 +448,8 @@ int command_init(void) { command_add("augmentitem", "Force augments an item. Must have the augment item window open.", 250, command_augmentitem) || command_add("questerrors", "Shows quest errors.", 100, command_questerrors) || command_add("enablerecipe", "[recipe_id] - Enables a recipe using the recipe id.", 80, command_enablerecipe) || - command_add("disablerecipe", "[recipe_id] - Disables a recipe using the recipe id.", 80, command_disablerecipe) + command_add("disablerecipe", "[recipe_id] - Disables a recipe using the recipe id.", 80, command_disablerecipe) || + command_add("npctype_cache", "[id] or all - Clears the npc type cache for either the id or all npcs.", 250, command_npctype_cache) ) { command_deinit(); @@ -11452,3 +11453,28 @@ void command_disablerecipe(Client *c, const Seperator *sep) } } } + +void command_npctype_cache(Client *c, const Seperator *sep) +{ + if (sep->argnum > 0) { + for (int i = 0; i < sep->argnum; ++i) { + if (strcasecmp(sep->arg[i + 1], "all") == 0) { + c->Message(0, "Clearing all npc types from the cache."); + zone->ClearNPCTypeCache(-1); + } + else { + int id = atoi(sep->arg[i + 1]); + if (id > 0) { + c->Message(0, "Clearing npc type %d from the cache.", id); + zone->ClearNPCTypeCache(id); + return; + } + } + } + } + else { + c->Message(0, "Usage:"); + c->Message(0, "#npctype_cache [npctype_id] ..."); + c->Message(0, "#npctype_cache all"); + } +} \ No newline at end of file diff --git a/zone/command.h b/zone/command.h index 116ac4fe5..48ca51b58 100644 --- a/zone/command.h +++ b/zone/command.h @@ -323,6 +323,7 @@ void command_questerrors(Client *c, const Seperator *sep); void command_enablerecipe(Client *c, const Seperator *sep); void command_disablerecipe(Client *c, const Seperator *sep); void command_showspellslist(Client *c, const Seperator *sep); +void command_npctype_cache(Client *c, const Seperator *sep); #ifdef EQPROFILE void command_profiledump(Client *c, const Seperator *sep); diff --git a/zone/zone.cpp b/zone/zone.cpp index cadd1b472..1ed951ee2 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1518,16 +1518,40 @@ bool Zone::Depop(bool StartSpawnTimer) { std::map::iterator itr; entity_list.Depop(StartSpawnTimer); +#ifdef DEPOP_INVALIDATES_NPC_TYPES_CACHE // Refresh npctable, getting current info from database. while(npctable.size()) { itr=npctable.begin(); delete itr->second; npctable.erase(itr); } +#endif return true; } +void Zone::ClearNPCTypeCache(int id) { + if (id <= 0) { + auto iter = npctable.begin(); + while (iter != npctable.end()) { + delete iter->second; + ++iter; + } + npctable.clear(); + } + else { + auto iter = npctable.begin(); + while (iter != npctable.end()) { + if (iter->first == (uint32)id) { + delete iter->second; + npctable.erase(iter); + return; + } + ++iter; + } + } +} + void Zone::Repop(uint32 delay) { if(!Depop()) diff --git a/zone/zone.h b/zone/zone.h index 981e448b8..1553b72e8 100644 --- a/zone/zone.h +++ b/zone/zone.h @@ -144,6 +144,7 @@ public: bool Depop(bool StartSpawnTimer = false); void Repop(uint32 delay = 0); + void ClearNPCTypeCache(int id); void SpawnStatus(Mob* client); void ShowEnabledSpawnStatus(Mob* client); void ShowDisabledSpawnStatus(Mob* client);