mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[6828] Added script name indexing for creature, gameobject, item, areatrigger and instance scripts.
* loaded all distinct script names into one vector at server startup * added custom loaders to convert the script names to indices * converted all the script lookup functions to use the index instead of the name
This commit is contained in:
parent
074bd3a08f
commit
766654c85d
16 changed files with 184 additions and 101 deletions
|
|
@ -19,6 +19,7 @@
|
|||
#include "Common.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
#include "Database/SQLStorage.h"
|
||||
#include "Database/SQLStorageImpl.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "MapManager.h"
|
||||
|
|
@ -562,7 +563,7 @@ void ObjectMgr::LoadCreatureLocales()
|
|||
sLog.outString();
|
||||
sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() );
|
||||
}
|
||||
|
||||
|
||||
void ObjectMgr::LoadNpcOptionLocales()
|
||||
{
|
||||
mNpcOptionLocaleMap.clear(); // need for reload case
|
||||
|
|
@ -631,9 +632,19 @@ void ObjectMgr::LoadNpcOptionLocales()
|
|||
sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() );
|
||||
}
|
||||
|
||||
struct SQLCreatureLoader : public SQLStorageLoaderBase<SQLCreatureLoader>
|
||||
{
|
||||
template<class D>
|
||||
void convert_from_str(uint32 field_pos, char *src, D &dst)
|
||||
{
|
||||
dst = D(objmgr.GetScriptId(src));
|
||||
}
|
||||
};
|
||||
|
||||
void ObjectMgr::LoadCreatureTemplates()
|
||||
{
|
||||
sCreatureStorage.Load();
|
||||
SQLCreatureLoader loader;
|
||||
loader.Load(sCreatureStorage);
|
||||
|
||||
sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount );
|
||||
sLog.outString();
|
||||
|
|
@ -1500,9 +1511,19 @@ void ObjectMgr::LoadItemLocales()
|
|||
sLog.outString( ">> Loaded %u Item locale strings", mItemLocaleMap.size() );
|
||||
}
|
||||
|
||||
struct SQLItemLoader : public SQLStorageLoaderBase<SQLItemLoader>
|
||||
{
|
||||
template<class D>
|
||||
void convert_from_str(uint32 field_pos, char *src, D &dst)
|
||||
{
|
||||
dst = D(objmgr.GetScriptId(src));
|
||||
}
|
||||
};
|
||||
|
||||
void ObjectMgr::LoadItemPrototypes()
|
||||
{
|
||||
sItemStorage.Load ();
|
||||
SQLItemLoader loader;
|
||||
loader.Load(sItemStorage);
|
||||
sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount );
|
||||
sLog.outString();
|
||||
|
||||
|
|
@ -4120,9 +4141,19 @@ void ObjectMgr::LoadPageTextLocales()
|
|||
sLog.outString( ">> Loaded %u PageText locale strings", mPageTextLocaleMap.size() );
|
||||
}
|
||||
|
||||
struct SQLInstanceLoader : public SQLStorageLoaderBase<SQLInstanceLoader>
|
||||
{
|
||||
template<class D>
|
||||
void convert_from_str(uint32 field_pos, char *src, D &dst)
|
||||
{
|
||||
dst = D(objmgr.GetScriptId(src));
|
||||
}
|
||||
};
|
||||
|
||||
void ObjectMgr::LoadInstanceTemplate()
|
||||
{
|
||||
sInstanceTemplate.Load();
|
||||
SQLInstanceLoader loader;
|
||||
loader.Load(sInstanceTemplate);
|
||||
|
||||
for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++)
|
||||
{
|
||||
|
|
@ -4536,7 +4567,7 @@ void ObjectMgr::LoadAreaTriggerScripts()
|
|||
Field *fields = result->Fetch();
|
||||
|
||||
uint32 Trigger_ID = fields[0].GetUInt32();
|
||||
std::string scriptName = fields[1].GetCppString();
|
||||
const char *scriptName = fields[1].GetString();
|
||||
|
||||
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
|
||||
if(!atEntry)
|
||||
|
|
@ -4544,7 +4575,7 @@ void ObjectMgr::LoadAreaTriggerScripts()
|
|||
sLog.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID);
|
||||
continue;
|
||||
}
|
||||
mAreaTriggerScripts[Trigger_ID] = scriptName;
|
||||
mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName);
|
||||
} while( result->NextRow() );
|
||||
|
||||
delete result;
|
||||
|
|
@ -5350,9 +5381,19 @@ void ObjectMgr::LoadGameObjectLocales()
|
|||
sLog.outString( ">> Loaded %u gameobject locale strings", mGameObjectLocaleMap.size() );
|
||||
}
|
||||
|
||||
struct SQLGameObjectLoader : public SQLStorageLoaderBase<SQLGameObjectLoader>
|
||||
{
|
||||
template<class D>
|
||||
void convert_from_str(uint32 field_pos, char *src, D &dst)
|
||||
{
|
||||
dst = D(objmgr.GetScriptId(src));
|
||||
}
|
||||
};
|
||||
|
||||
void ObjectMgr::LoadGameobjectInfo()
|
||||
{
|
||||
sGOStorage.Load();
|
||||
SQLGameObjectLoader loader;
|
||||
loader.Load(sGOStorage);
|
||||
|
||||
// some checks
|
||||
for(uint32 id = 1; id < sGOStorage.MaxEntry; id++)
|
||||
|
|
@ -6480,12 +6521,12 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* ObjectMgr::GetAreaTriggerScriptName(uint32 id)
|
||||
uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id)
|
||||
{
|
||||
AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(id);
|
||||
AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id);
|
||||
if(i!= mAreaTriggerScripts.end())
|
||||
return i->second.c_str();
|
||||
return "";
|
||||
return i->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Checks if player meets the condition
|
||||
|
|
@ -7196,6 +7237,42 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m
|
|||
return true;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadScriptNames()
|
||||
{
|
||||
m_scriptNames.push_back("");
|
||||
QueryResult *result = WorldDatabase.Query(
|
||||
"SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(script) FROM instance_template WHERE script <> ''");
|
||||
if(result)
|
||||
{
|
||||
do
|
||||
{
|
||||
m_scriptNames.push_back((*result)[0].GetString());
|
||||
} while (result->NextRow());
|
||||
delete result;
|
||||
}
|
||||
|
||||
std::sort(m_scriptNames.begin(), m_scriptNames.end());
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GetScriptId(const char *name)
|
||||
{
|
||||
// use binary search to find the script name in the sorted vector
|
||||
// assume "" is the first element
|
||||
if(!name) return 0;
|
||||
ScriptNameMap::const_iterator itr =
|
||||
std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name);
|
||||
if(itr == m_scriptNames.end()) return 0;
|
||||
return itr - m_scriptNames.begin();
|
||||
}
|
||||
|
||||
void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids)
|
||||
{
|
||||
for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM)
|
||||
|
|
@ -7234,11 +7311,10 @@ void ObjectMgr::LoadDbScriptStrings()
|
|||
sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr);
|
||||
}
|
||||
|
||||
|
||||
// Functions for scripting access
|
||||
const char* GetAreaTriggerScriptNameById(uint32 id)
|
||||
uint32 GetAreaTriggerScriptId(uint32 trigger_id)
|
||||
{
|
||||
return objmgr.GetAreaTriggerScriptName(id);
|
||||
return objmgr.GetAreaTriggerScriptId(trigger_id);
|
||||
}
|
||||
|
||||
bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value)
|
||||
|
|
@ -7253,3 +7329,13 @@ bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, in
|
|||
// for scripting localized strings allowed use _only_ negative entries
|
||||
return objmgr.LoadMangosStrings(db,table,end_value,start_value);
|
||||
}
|
||||
|
||||
uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
|
||||
{
|
||||
return objmgr.GetScriptId(name);
|
||||
}
|
||||
|
||||
ObjectMgr::ScriptNameMap & GetScriptNames()
|
||||
{
|
||||
return objmgr.GetScriptNames();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue