Core/ObjectMgr: Refactor sInstanceTemplate

This commit is contained in:
leak
2011-04-28 22:16:13 +02:00
parent 19cab2c508
commit 5aeb4fe794
14 changed files with 81 additions and 58 deletions
-4
View File
@@ -2847,10 +2847,6 @@ DROP TABLE IF EXISTS `instance_template`;
CREATE TABLE `instance_template` (
`map` smallint(5) unsigned NOT NULL,
`parent` int(10) unsigned NOT NULL,
`startLocX` float DEFAULT NULL,
`startLocY` float DEFAULT NULL,
`startLocZ` float DEFAULT NULL,
`startLocO` float DEFAULT NULL,
`script` varchar(128) NOT NULL DEFAULT '',
`allowMount` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`map`)
@@ -0,0 +1,6 @@
ALTER TABLE `instance_template`
DROP COLUMN `startLocX`,
DROP COLUMN `startLocY`,
DROP COLUMN `startLocZ`,
DROP COLUMN `startLocO`,
CHANGE `parent` `parent` SMALLINT(5) UNSIGNED NOT NULL;
+1 -1
View File
@@ -6922,7 +6922,7 @@ void Player::RewardReputation(Unit *pVictim, float rate)
Map const *pMap = GetMap();
if (pMap && pMap->IsDungeon())
{
InstanceTemplate const *pInstance = ObjectMgr::GetInstanceTemplate(pMap->GetId());
InstanceTemplate const *pInstance = sObjectMgr->GetInstanceTemplate(pMap->GetId());
if (pInstance)
{
AccessRequirement const *pAccessRequirement = sObjectMgr->GetAccessRequirement(pMap->GetId(), ((InstanceMap*)pMap)->GetDifficulty());
+42 -18
View File
@@ -5600,29 +5600,53 @@ void ObjectMgr::LoadInstanceTemplate()
{
uint32 oldMSTime = getMSTime();
SQLInstanceLoader loader;
loader.Load(sInstanceTemplate);
QueryResult result = WorldDatabase.Query("SELECT map, parent, script, allowMount FROM instance_template");
for (uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++)
if (!result)
{
InstanceTemplate* temp = const_cast<InstanceTemplate*>(ObjectMgr::GetInstanceTemplate(i));
if (!temp)
continue;
if (!MapManager::IsValidMAP(temp->map))
sLog->outErrorDb("ObjectMgr::LoadInstanceTemplate: bad mapid %d for template!", temp->map);
if (!MapManager::IsValidMapCoord(temp->parent,temp->startLocX,temp->startLocY,temp->startLocZ,temp->startLocO))
{
sLog->outErrorDb("ObjectMgr::LoadInstanceTemplate: bad parent entrance coordinates for map id %d template!", temp->map);
temp->parent = 0; // will have wrong continent 0 parent, at least existed
}
sLog->outString(">> Loaded 0 instance templates. DB table `page_text` is empty!");
sLog->outString();
return;
}
sLog->outString(">> Loaded %u Instance Template definitions in %u ms", sInstanceTemplate.RecordCount, GetMSTimeDiffToNow(oldMSTime));
uint32 count = 0;
do
{
Field* fields = result->Fetch();
uint16 mapID = fields[0].GetUInt16();
if (!MapManager::IsValidMAP(mapID, true))
{
sLog->outErrorDb("ObjectMgr::LoadInstanceTemplate: bad mapid %d for template!", mapID);
continue;
}
InstanceTemplate instanceTemplate;
instanceTemplate.AllowMount = fields[3].GetBool();
instanceTemplate.Parent = fields[1].GetUInt16();
instanceTemplate.ScriptId = sObjectMgr->GetScriptId(fields[2].GetCString());
InstanceTemplateStore[mapID] = instanceTemplate;
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u instance templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
InstanceTemplate const* ObjectMgr::GetInstanceTemplate(uint32 mapID)
{
InstanceTemplateContainer::const_iterator itr = InstanceTemplateStore.find(uint16(mapID));
if (itr != InstanceTemplateStore.end())
return &(itr->second);
return NULL;
}
void ObjectMgr::LoadInstanceEncounters()
{
uint32 oldMSTime = getMSTime();
@@ -6608,12 +6632,12 @@ AreaTrigger const* ObjectMgr::GetGoBackTrigger(uint32 Map) const
if (mapEntry->IsDungeon())
{
const InstanceTemplate *iTemplate = ObjectMgr::GetInstanceTemplate(Map);
const InstanceTemplate *iTemplate = sObjectMgr->GetInstanceTemplate(Map);
if (!iTemplate)
return NULL;
parentId = iTemplate->parent;
parentId = iTemplate->Parent;
useParentDbValue = true;
}
+6 -6
View File
@@ -49,7 +49,6 @@ extern SQLStorage sCreatureInfoAddonStorage;
extern SQLStorage sEquipmentStorage;
extern SQLStorage sGOStorage;
extern SQLStorage sItemStorage;
extern SQLStorage sInstanceTemplate;
class Group;
class Guild;
@@ -76,9 +75,12 @@ struct PageText
#pragma pack(pop)
#endif
// Faster (insert/find) than UNORDERED_MAP in this case
// Benchmarked: Faster than UNORDERED_MAP (insert/find)
typedef std::map<uint32, PageText> PageTextContainer;
// Benchmarked: Faster than std::map (insert/find)
typedef UNORDERED_MAP<uint16, InstanceTemplate> InstanceTemplateContainer;
struct GameTele
{
float position_x;
@@ -698,10 +700,7 @@ class ObjectMgr
return NULL;
}
static InstanceTemplate const* GetInstanceTemplate(uint32 map)
{
return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
}
InstanceTemplate const* GetInstanceTemplate(uint32 mapID);
PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint8 level) const;
@@ -1367,6 +1366,7 @@ class ObjectMgr
LocaleConstant DBCLocaleIndex;
PageTextContainer PageTextStore;
InstanceTemplateContainer InstanceTemplateStore;
private:
void LoadScripts(ScriptsType type);
@@ -201,7 +201,7 @@ time_t InstanceSave::GetResetTimeForDB()
// to cache or not to cache, that is the question
InstanceTemplate const* InstanceSave::GetTemplate()
{
return ObjectMgr::GetInstanceTemplate(m_mapid);
return sObjectMgr->GetInstanceTemplate(m_mapid);
}
MapEntry const* InstanceSave::GetMapEntry()
+2 -2
View File
@@ -2402,10 +2402,10 @@ void InstanceMap::CreateInstanceData(bool load)
if (i_data != NULL)
return;
InstanceTemplate const* mInstance = ObjectMgr::GetInstanceTemplate(GetId());
InstanceTemplate const* mInstance = sObjectMgr->GetInstanceTemplate(GetId());
if (mInstance)
{
i_script_id = mInstance->script_id;
i_script_id = mInstance->ScriptId;
i_data = sScriptMgr->CreateInstanceData(this);
}
+3 -8
View File
@@ -216,14 +216,9 @@ struct CreatureMover
struct InstanceTemplate
{
uint32 map;
uint32 parent;
float startLocX;
float startLocY;
float startLocZ;
float startLocO;
uint32 script_id;
bool allowMount;
uint32 Parent;
uint32 ScriptId;
bool AllowMount;
};
enum LevelRequirementVsMode
+1 -1
View File
@@ -179,7 +179,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save,
sLog->outError("CreateInstance: no entry for map %d", GetId());
ASSERT(false);
}
const InstanceTemplate * iTemplate = ObjectMgr::GetInstanceTemplate(GetId());
const InstanceTemplate * iTemplate = sObjectMgr->GetInstanceTemplate(GetId());
if (!iTemplate)
{
sLog->outError("CreateInstance: no instance template for map %d", GetId());
+10 -5
View File
@@ -151,7 +151,7 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck)
if (!entry->IsDungeon())
return true;
InstanceTemplate const* instance = ObjectMgr::GetInstanceTemplate(mapid);
InstanceTemplate const* instance = sObjectMgr->GetInstanceTemplate(mapid);
if (!instance)
return false;
@@ -201,8 +201,8 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck)
if (corpseMap == mapid)
break;
InstanceTemplate const* instance = ObjectMgr::GetInstanceTemplate(corpseMap);
corpseMap = instance ? instance->parent : 0;
InstanceTemplate const* instance = sObjectMgr->GetInstanceTemplate(corpseMap);
corpseMap = instance ? instance->Parent : 0;
} while (corpseMap);
if (!corpseMap)
@@ -298,10 +298,15 @@ bool MapManager::ExistMapAndVMap(uint32 mapid, float x,float y)
return Map::ExistMap(mapid,gx,gy) && Map::ExistVMap(mapid,gx,gy);
}
bool MapManager::IsValidMAP(uint32 mapid)
bool MapManager::IsValidMAP(uint32 mapid, bool startUp)
{
MapEntry const* mEntry = sMapStore.LookupEntry(mapid);
return mEntry && (!mEntry->IsDungeon() || ObjectMgr::GetInstanceTemplate(mapid));
if (startUp)
return mEntry ? true : false;
else
return mEntry && (!mEntry->IsDungeon() || sObjectMgr->GetInstanceTemplate(mapid));
// TODO: add check for battleground template
}
+4 -4
View File
@@ -84,21 +84,21 @@ class MapManager
void UnloadAll();
static bool ExistMapAndVMap(uint32 mapid, float x, float y);
static bool IsValidMAP(uint32 mapid);
static bool IsValidMAP(uint32 mapid, bool startUp);
static bool IsValidMapCoord(uint32 mapid, float x,float y)
{
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y);
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x,y);
}
static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
{
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z);
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x,y,z);
}
static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
{
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z,o);
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x,y,z,o);
}
static bool IsValidMapCoord(WorldLocation const& loc)
@@ -57,7 +57,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
// get the destination map entry, not the current one, this will fix homebind and reset greeting
MapEntry const* mEntry = sMapStore.LookupEntry(loc.GetMapId());
InstanceTemplate const* mInstance = ObjectMgr::GetInstanceTemplate(loc.GetMapId());
InstanceTemplate const* mInstance = sObjectMgr->GetInstanceTemplate(loc.GetMapId());
// reset instance validity, except if going to an instance inside an instance
if (GetPlayer()->m_InstanceValid == false && !mInstance)
@@ -161,7 +161,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
}
}
}
allowMount = mInstance->allowMount;
allowMount = mInstance->AllowMount;
}
// mount allow check
+3 -3
View File
@@ -5346,7 +5346,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (targetBind->perm && targetBind != m_caster->ToPlayer()->GetBoundInstance(mapId, difficulty))
return SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE;
InstanceTemplate const* instance = ObjectMgr::GetInstanceTemplate(mapId);
InstanceTemplate const* instance = sObjectMgr->GetInstanceTemplate(mapId);
if (!instance)
return SPELL_FAILED_TARGET_NOT_IN_INSTANCE;
if (!target->Satisfy(sObjectMgr->GetAccessRequirement(mapId, difficulty), mapId))
@@ -5513,9 +5513,9 @@ SpellCastResult Spell::CheckCast(bool strict)
// Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
bool AllowMount = !m_caster->GetMap()->IsDungeon() || m_caster->GetMap()->IsBattlegroundOrArena();
InstanceTemplate const *it = ObjectMgr::GetInstanceTemplate(m_caster->GetMapId());
InstanceTemplate const *it = sObjectMgr->GetInstanceTemplate(m_caster->GetMapId());
if (it)
AllowMount = it->allowMount;
AllowMount = it->AllowMount;
if (m_caster->GetTypeId() == TYPEID_PLAYER && !AllowMount && !m_IsTriggeredSpell && !m_spellInfo->AreaGroupId)
return SPELL_FAILED_NO_MOUNTS_ALLOWED;
@@ -28,8 +28,6 @@ const char GameObjectInfosrcfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiissi";
const char GameObjectInfodstfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisii";
const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiisiiiii";
const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiiii";
const char InstanceTemplatesrcfmt[]="iiffffsb";
const char InstanceTemplatedstfmt[]="iiffffib";
SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template");
SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon");
@@ -37,7 +35,6 @@ SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_
SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template");
SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template");
SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template");
SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template");
void SQLStorage::Free ()
{