Core/Misc: reduced amount of string memory allocations (Step I)
This commit is contained in:
1 parent
ca85c3b475
commit
013fb1f4d9
91 files changed
+881
-890
No files matched your search
@@ -33,7 +33,7 @@
|
||||
#include "GameObjectModel.h"
|
||||
#include "DynamicTree.h"
|
||||
|
||||
GameObject::GameObject() : WorldObject(false), m_model(NULL), m_goValue(new GameObjectValue), m_AI(NULL)
|
||||
GameObject::GameObject(): WorldObject(false), m_model(NULL), m_goValue(), m_AI(NULL)
|
||||
{
|
||||
m_objectType |= TYPEMASK_GAMEOBJECT;
|
||||
m_objectTypeId = TYPEID_GAMEOBJECT;
|
||||
@@ -65,7 +65,6 @@ GameObject::GameObject() : WorldObject(false), m_model(NULL), m_goValue(new Game
|
||||
|
||||
GameObject::~GameObject()
|
||||
{
|
||||
delete m_goValue;
|
||||
delete m_AI;
|
||||
delete m_model;
|
||||
//if (m_uint32Values) // field array can be not exist if GameOBject not loaded
|
||||
@@ -226,8 +225,8 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map* map, uint32 phaseMa
|
||||
switch (goinfo->type)
|
||||
{
|
||||
case GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING:
|
||||
m_goValue->Building.Health = goinfo->building.intactNumHits + goinfo->building.damagedNumHits;
|
||||
m_goValue->Building.MaxHealth = m_goValue->Building.Health;
|
||||
m_goValue.Building.Health = goinfo->building.intactNumHits + goinfo->building.damagedNumHits;
|
||||
m_goValue.Building.MaxHealth = m_goValue.Building.Health;
|
||||
SetGoAnimProgress(255);
|
||||
break;
|
||||
case GAMEOBJECT_TYPE_TRANSPORT:
|
||||
@@ -1642,7 +1641,7 @@ void GameObject::Use(Unit* user)
|
||||
default:
|
||||
if (GetGoType() >= MAX_GAMEOBJECT_TYPE)
|
||||
sLog->outError(LOG_FILTER_GENERAL, "GameObject::Use(): unit (type: %u, guid: %u, name: %s) tries to use object (guid: %u, entry: %u, name: %s) of unknown type (%u)",
|
||||
user->GetTypeId(), user->GetGUIDLow(), user->GetName(), GetGUIDLow(), GetEntry(), GetGOInfo()->name.c_str(), GetGoType());
|
||||
user->GetTypeId(), user->GetGUIDLow(), user->GetName().c_str(), GetGUIDLow(), GetEntry(), GetGOInfo()->name.c_str(), GetGoType());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1756,14 +1755,14 @@ void GameObject::EventInform(uint32 eventId)
|
||||
}
|
||||
|
||||
// overwrite WorldObject function for proper name localization
|
||||
const char* GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const
|
||||
std::string const & GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const
|
||||
{
|
||||
if (loc_idx != DEFAULT_LOCALE)
|
||||
{
|
||||
uint8 uloc_idx = uint8(loc_idx);
|
||||
if (GameObjectLocale const* cl = sObjectMgr->GetGameObjectLocale(GetEntry()))
|
||||
if (cl->Name.size() > uloc_idx && !cl->Name[uloc_idx].empty())
|
||||
return cl->Name[uloc_idx].c_str();
|
||||
return cl->Name[uloc_idx];
|
||||
}
|
||||
|
||||
return GetName();
|
||||
@@ -1801,22 +1800,22 @@ void GameObject::UpdateRotationFields(float rotation2 /*=0.0f*/, float rotation3
|
||||
|
||||
void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= NULL*/, uint32 spellId /*= 0*/)
|
||||
{
|
||||
if (!GetGOValue()->Building.MaxHealth || !change)
|
||||
if (!m_goValue.Building.MaxHealth || !change)
|
||||
return;
|
||||
|
||||
// prevent double destructions of the same object
|
||||
if (change < 0 && !GetGOValue()->Building.Health)
|
||||
if (change < 0 && !m_goValue.Building.Health)
|
||||
return;
|
||||
|
||||
if (int32(GetGOValue()->Building.Health) + change <= 0)
|
||||
GetGOValue()->Building.Health = 0;
|
||||
else if (int32(GetGOValue()->Building.Health) + change >= int32(GetGOValue()->Building.MaxHealth))
|
||||
GetGOValue()->Building.Health = GetGOValue()->Building.MaxHealth;
|
||||
if (int32(m_goValue.Building.Health) + change <= 0)
|
||||
m_goValue.Building.Health = 0;
|
||||
else if (int32(m_goValue.Building.Health) + change >= int32(m_goValue.Building.MaxHealth))
|
||||
m_goValue.Building.Health = m_goValue.Building.MaxHealth;
|
||||
else
|
||||
GetGOValue()->Building.Health += change;
|
||||
m_goValue.Building.Health += change;
|
||||
|
||||
// Set the health bar, value = 255 * healthPct;
|
||||
SetGoAnimProgress(GetGOValue()->Building.Health * 255 / GetGOValue()->Building.MaxHealth);
|
||||
SetGoAnimProgress(m_goValue.Building.Health * 255 / m_goValue.Building.MaxHealth);
|
||||
|
||||
Player* player = attackerOrHealer->GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
|
||||
@@ -1835,11 +1834,11 @@ void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= NULL*/, u
|
||||
|
||||
GameObjectDestructibleState newState = GetDestructibleState();
|
||||
|
||||
if (!GetGOValue()->Building.Health)
|
||||
if (!m_goValue.Building.Health)
|
||||
newState = GO_DESTRUCTIBLE_DESTROYED;
|
||||
else if (GetGOValue()->Building.Health <= GetGOInfo()->building.damagedNumHits)
|
||||
else if (m_goValue.Building.Health <= GetGOInfo()->building.damagedNumHits)
|
||||
newState = GO_DESTRUCTIBLE_DAMAGED;
|
||||
else if (GetGOValue()->Building.Health == GetGOValue()->Building.MaxHealth)
|
||||
else if (m_goValue.Building.Health == m_goValue.Building.MaxHealth)
|
||||
newState = GO_DESTRUCTIBLE_INTACT;
|
||||
|
||||
if (newState == GetDestructibleState())
|
||||
@@ -1860,7 +1859,7 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
|
||||
SetDisplayId(m_goInfo->displayId);
|
||||
if (setHealth)
|
||||
{
|
||||
m_goValue->Building.Health = m_goValue->Building.MaxHealth;
|
||||
m_goValue.Building.Health = m_goValue.Building.MaxHealth;
|
||||
SetGoAnimProgress(255);
|
||||
}
|
||||
EnableCollision(true);
|
||||
@@ -1884,12 +1883,12 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
|
||||
|
||||
if (setHealth)
|
||||
{
|
||||
m_goValue->Building.Health = m_goInfo->building.damagedNumHits;
|
||||
uint32 maxHealth = m_goValue->Building.MaxHealth;
|
||||
m_goValue.Building.Health = m_goInfo->building.damagedNumHits;
|
||||
uint32 maxHealth = m_goValue.Building.MaxHealth;
|
||||
// in this case current health is 0 anyway so just prevent crashing here
|
||||
if (!maxHealth)
|
||||
maxHealth = 1;
|
||||
SetGoAnimProgress(m_goValue->Building.Health * 255 / maxHealth);
|
||||
SetGoAnimProgress(m_goValue.Building.Health * 255 / maxHealth);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1917,7 +1916,7 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
|
||||
|
||||
if (setHealth)
|
||||
{
|
||||
m_goValue->Building.Health = 0;
|
||||
m_goValue.Building.Health = 0;
|
||||
SetGoAnimProgress(0);
|
||||
}
|
||||
EnableCollision(false);
|
||||
@@ -1937,7 +1936,7 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
|
||||
// restores to full health
|
||||
if (setHealth)
|
||||
{
|
||||
m_goValue->Building.Health = m_goValue->Building.MaxHealth;
|
||||
m_goValue.Building.Health = m_goValue.Building.MaxHealth;
|
||||
SetGoAnimProgress(255);
|
||||
}
|
||||
EnableCollision(true);
|
||||
|
||||
Reference in new issue
Block a user