Added read/write template functions for save data, small Load/Save arguments unification

This commit is contained in:
Sergeanur
2019-10-08 23:07:11 +03:00
parent 69963cea68
commit 101192dd32
12 changed files with 197 additions and 191 deletions

View File

@@ -65,27 +65,19 @@ CPhoneInfo::IsMessageBeingDisplayed(int phoneId)
}
void
CPhoneInfo::Load(CPhoneInfo *source, uint8 buffer)
CPhoneInfo::Load(uint8 *buf, uint32 size)
{
// Buffer isn't used.
m_nMax = source->m_nMax;
m_nNum = source->m_nNum;
for (int phoneId = 0; phoneId < 50; phoneId++) {
CPhone *phone = &source->m_aPhones[phoneId];
m_aPhones[phoneId].m_vecPos = phone->m_vecPos;
memcpy(m_aPhones[phoneId].m_apMessages, phone->m_apMessages, sizeof(wchar*) * 6);
m_aPhones[phoneId].m_lastTimeRepeatedMsgShown = phone->m_lastTimeRepeatedMsgShown;
m_aPhones[phoneId].m_pEntity = phone->m_pEntity;
m_aPhones[phoneId].m_nState = phone->m_nState;
m_aPhones[phoneId].field_30 = phone->field_30;
INITSAVEBUF
m_nMax = ReadSaveBuf<int32>(buf);
m_nNum = ReadSaveBuf<int32>(buf);
for (int i = 0; i < 50; i++) {
m_aPhones[i] = ReadSaveBuf<CPhone>(buf);
// It's saved as building pool index in save file, convert it to true entity
if (phone->m_pEntity) {
m_aPhones[phoneId].m_pEntity = CPools::GetBuildingPool()->GetSlot((int)phone->m_pEntity - 1);
if (m_aPhones[i].m_pEntity) {
m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((int)m_aPhones[i].m_pEntity - 1);
}
}
VALIDATESAVEBUF(size)
}
void
@@ -174,26 +166,21 @@ CPhoneInfo::Initialise(void)
}
void
CPhoneInfo::Save(CPhoneInfo *destination, uint32 *size)
CPhoneInfo::Save(uint8 *buf, uint32 *size)
{
*size = sizeof(CPhoneInfo);
destination->m_nMax = this->m_nMax;
destination->m_nNum = m_nNum;
INITSAVEBUF
WriteSaveBuf(buf, m_nMax);
WriteSaveBuf(buf, m_nNum);
for(int phoneId = 0; phoneId < 50; phoneId++) {
CPhone* phone = &destination->m_aPhones[phoneId];
phone->m_vecPos = m_aPhones[phoneId].m_vecPos;
memcpy(phone->m_apMessages, m_aPhones[phoneId].m_apMessages, sizeof(wchar*) * 6);
phone->m_lastTimeRepeatedMsgShown = m_aPhones[phoneId].m_lastTimeRepeatedMsgShown;
phone->m_pEntity = m_aPhones[phoneId].m_pEntity;
phone->m_nState = m_aPhones[phoneId].m_nState;
phone->field_30 = m_aPhones[phoneId].field_30;
CPhone* phone = WriteSaveBuf(buf, m_aPhones[phoneId]);
// Convert entity pointer to building pool index while saving
if (phone->m_pEntity) {
phone->m_pEntity = (CEntity*) (CPools::GetBuildingPool()->GetJustIndex((CBuilding*)phone->m_pEntity) + 1);
}
}
VALIDATESAVEBUF(*size)
}
void