[Performance] Character Save Optimizations (#4851)

This commit is contained in:
Chris Miles 2025-04-09 20:56:24 -05:00 committed by GitHub
parent 50ad97aa0b
commit b883888a19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 3 deletions

View File

@ -995,6 +995,8 @@ bool Client::Save(uint8 iCommitNow) {
if(!ClientDataLoaded())
return false;
BenchTimer timer;
/* Wrote current basics to PP for saves */
if (!m_lock_save_position) {
m_pp.x = m_Position.x;
@ -1022,6 +1024,8 @@ bool Client::Save(uint8 iCommitNow) {
m_pp.endurance = current_endurance;
}
database.TransactionBegin();
/* Save Character Currency */
database.SaveCharacterCurrency(CharacterID(), &m_pp);
@ -1105,6 +1109,10 @@ bool Client::Save(uint8 iCommitNow) {
database.botdb.SaveBotSettings(this);
}
database.TransactionCommit();
LogInfo("Save for [{}] took [{}]", GetCleanName(), timer.elapsed());
return true;
}

View File

@ -483,6 +483,9 @@ public:
virtual bool Save() { return Save(0); }
bool Save(uint8 iCommitNow); // 0 = delayed, 1=async now, 2=sync now
inline void SaveCharacterData() {
database.SaveCharacterData(this, &m_pp, &m_epp);
};
/* New PP Save Functions */
bool SaveCurrency(){ return database.SaveCharacterCurrency(this->CharacterID(), &m_pp); }

View File

@ -217,6 +217,8 @@ bool Client::Process() {
GetMerc()->Depop();
}
instalog = true;
camp_timer.Disable();
}
if (IsStunned() && stunned_timer.Check())

View File

@ -4621,8 +4621,12 @@ void Mob::SetZone(uint32 zone_id, uint32 instance_id)
{
CastToClient()->GetPP().zone_id = zone_id;
CastToClient()->GetPP().zoneInstance = instance_id;
CastToClient()->SaveCharacterData();
}
if (!IsClient()) {
Save(); // bots or other things might be covered here for some reason
}
Save();
}
void Mob::Kill() {

View File

@ -528,8 +528,12 @@ void Client::DoZoneSuccess(ZoneChange_Struct *zc, uint16 zone_id, uint32 instanc
m_pp.zone_id = zone_id;
m_pp.zoneInstance = instance_id;
//Force a save so its waiting for them when they zone
Save(2);
// save character position
m_pp.x = m_Position.x;
m_pp.y = m_Position.y;
m_pp.z = m_Position.z;
m_pp.heading = m_Position.w;
SaveCharacterData();
m_lock_save_position = true;