Skip to content

Commit

Permalink
Add all registry classes to new save system
Browse files Browse the repository at this point in the history
  • Loading branch information
mnelenpridumivat committed Dec 9, 2024
1 parent f573367 commit 66b0fdf
Show file tree
Hide file tree
Showing 11 changed files with 494 additions and 162 deletions.
198 changes: 198 additions & 0 deletions src/xrGame/GameTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,62 @@ void CGameTask::load_task(IReader &stream)
CreateMapLocation (true);
}

void CGameTask::save_task(CSaveObjectSave* Object) const
{
Object->BeginChunk("CGameTask");
{
Object->GetCurrentChunk()->w_u8(m_task_state);
Object->GetCurrentChunk()->w_u8(m_task_type);
Object->GetCurrentChunk()->w_u64(m_ReceiveTime);
Object->GetCurrentChunk()->w_u64(m_FinishTime);
Object->GetCurrentChunk()->w_u64(m_TimeToComplete);
Object->GetCurrentChunk()->w_u64(m_timer_finish);
Object->GetCurrentChunk()->w_stringZ(m_Title);
Object->GetCurrentChunk()->w_stringZ(m_Description);
Object->GetCurrentChunk()->w_stringZ(m_Description);
m_pScriptHelper.save(Object);
Object->GetCurrentChunk()->w_stringZ(m_icon_texture_name);
Object->GetCurrentChunk()->w_stringZ(m_map_hint);
Object->GetCurrentChunk()->w_stringZ(m_map_location);
Object->GetCurrentChunk()->w_u16(m_map_object_id);
Object->GetCurrentChunk()->w_u32(m_priority);
}
Object->EndChunk();
}

void CGameTask::load_task(CSaveObjectLoad* Object)
{
Object->BeginChunk("CGameTask");
{
{
u8 Value;
Object->GetCurrentChunk()->r_u8(Value);
m_task_state = (ETaskState)Value;
}
{
u8 Value;
Object->GetCurrentChunk()->r_u8(Value);
m_task_type = (ETaskType)Value;
}
Object->GetCurrentChunk()->r_u64(m_ReceiveTime);
Object->GetCurrentChunk()->r_u64(m_FinishTime);
Object->GetCurrentChunk()->r_u64(m_TimeToComplete);
Object->GetCurrentChunk()->r_u64(m_timer_finish);
Object->GetCurrentChunk()->r_stringZ(m_Title);
Object->GetCurrentChunk()->r_stringZ(m_Description);
Object->GetCurrentChunk()->r_stringZ(m_Description);
m_pScriptHelper.load(Object);
Object->GetCurrentChunk()->r_stringZ(m_icon_texture_name);
Object->GetCurrentChunk()->r_stringZ(m_map_hint);
Object->GetCurrentChunk()->r_stringZ(m_map_location);
Object->GetCurrentChunk()->r_u16(m_map_object_id);
Object->GetCurrentChunk()->r_u32(m_priority);
CommitScriptHelperContents();
CreateMapLocation(true);
}
Object->EndChunk();
}

void CGameTask::CommitScriptHelperContents()
{
m_pScriptHelper.init_functors (m_pScriptHelper.m_s_complete_lua_functions, m_complete_lua_functions);
Expand Down Expand Up @@ -323,6 +379,126 @@ void SScriptTaskHelper::load(IReader &stream)
load_data(m_s_lua_functions_on_fail, stream);
}

void SScriptTaskHelper::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("SScriptTaskHelper");
{
Object->BeginChunk("SScriptTaskHelper::complete_cond");
{
Object->GetCurrentChunk()->WriteArray(m_s_complete_lua_functions.size());
{
for (const auto& elem : m_s_complete_lua_functions) {
Object->GetCurrentChunk()->w_stringZ(elem);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::fail_cond");
{
Object->GetCurrentChunk()->WriteArray(m_s_fail_lua_functions.size());
{
for (const auto& elem : m_s_fail_lua_functions) {
Object->GetCurrentChunk()->w_stringZ(elem);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::on_complete");
{
Object->GetCurrentChunk()->WriteArray(m_s_lua_functions_on_complete.size());
{
for (const auto& elem : m_s_lua_functions_on_complete) {
Object->GetCurrentChunk()->w_stringZ(elem);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::on_fail");
{
Object->GetCurrentChunk()->WriteArray(m_s_lua_functions_on_fail.size());
{
for (const auto& elem : m_s_lua_functions_on_fail) {
Object->GetCurrentChunk()->w_stringZ(elem);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
}
Object->EndChunk();
}

void SScriptTaskHelper::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("SScriptTaskHelper");
{
Object->BeginChunk("SScriptTaskHelper::complete_cond");
{
m_s_complete_lua_functions.clear();
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
shared_str Value;
Object->GetCurrentChunk()->r_stringZ(Value);
m_s_complete_lua_functions.emplace_back(Value);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::fail_cond");
{
m_s_fail_lua_functions.clear();
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
shared_str Value;
Object->GetCurrentChunk()->r_stringZ(Value);
m_s_fail_lua_functions.emplace_back(Value);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::on_complete");
{
m_s_lua_functions_on_complete.clear();
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
shared_str Value;
Object->GetCurrentChunk()->r_stringZ(Value);
m_s_lua_functions_on_complete.emplace_back(Value);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
Object->BeginChunk("SScriptTaskHelper::on_fail");
{
m_s_lua_functions_on_fail.clear();
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
shared_str Value;
Object->GetCurrentChunk()->r_stringZ(Value);
m_s_lua_functions_on_fail.emplace_back(Value);
}
}
Object->GetCurrentChunk()->EndArray();
}
Object->EndChunk();
}
Object->EndChunk();
}

void SScriptTaskHelper::save(IWriter &stream)
{
save_data(m_s_complete_lua_functions, stream);
Expand All @@ -346,6 +522,28 @@ void SGameTaskKey::load(IReader &stream)

}

void SGameTaskKey::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("SGameTaskKey");
{
Object->GetCurrentChunk()->w_stringZ(task_id);
game_task->save_task(Object);
}
Object->EndChunk();
}

void SGameTaskKey::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("SGameTaskKey");
{
game_task = new CGameTask();
Object->GetCurrentChunk()->r_stringZ(task_id);
game_task->m_ID = task_id;
game_task->load_task(Object);
}
Object->EndChunk();
}

void SGameTaskKey::destroy()
{
delete_data(game_task);
Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/GameTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class SScriptTaskHelper: public IPureSerializeObject<IReader,IWriter>

virtual void save (IWriter &stream);
virtual void load (IReader &stream);
virtual void save(CSaveObjectSave* Object) const;
virtual void load(CSaveObjectLoad* Object);

void init_functors (xr_vector<shared_str>& v_src, task_state_functors& v_dest);
};
Expand Down Expand Up @@ -74,6 +76,8 @@ class CGameTask

void save_task (IWriter &stream);
void load_task (IReader &stream);
void save_task(CSaveObjectSave* Object) const;
void load_task(CSaveObjectLoad* Object);


shared_str m_ID;
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/GameTaskDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct SGameTaskKey : public IPureSerializeObject<IReader,IWriter>,public IPureD

virtual void save (IWriter &stream);
virtual void load (IReader &stream);
virtual void save(CSaveObjectSave* Object) const;
virtual void load(CSaveObjectLoad* Object);
virtual void destroy ();
};

Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/actor_statistic_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct SStatDetailBData: public IPureSerializeObject<IReader,IWriter>

virtual void save (IWriter &stream);
virtual void load (IReader &stream);
virtual void save(CSaveObjectSave* Object) const;
virtual void load(CSaveObjectLoad* Object);
};


Expand All @@ -27,6 +29,8 @@ struct SStatSectionData: public IPureSerializeObject<IReader,IWriter>
s32 GetTotalPoints () const;
virtual void save (IWriter &stream);
virtual void load (IReader &stream);
virtual void save(CSaveObjectSave* Object) const;
virtual void load(CSaveObjectLoad* Object);
};

typedef xr_vector<SStatSectionData> vStatSectionData;
Expand Down
69 changes: 64 additions & 5 deletions src/xrGame/actor_statistic_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ void SStatDetailBData::load(IReader &stream)
load_data (str_value, stream);
}

void SStatDetailBData::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("SStatDetailBData");
{
Object->GetCurrentChunk()->w_stringZ(key);
Object->GetCurrentChunk()->w_s32(int_count);
Object->GetCurrentChunk()->w_s32(int_points);
Object->GetCurrentChunk()->w_stringZ(str_value);
}
Object->EndChunk();
}

void SStatDetailBData::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("SStatDetailBData");
{
Object->GetCurrentChunk()->r_stringZ(key);
Object->GetCurrentChunk()->r_s32(int_count);
Object->GetCurrentChunk()->r_s32(int_points);
Object->GetCurrentChunk()->r_stringZ(str_value);
}
Object->EndChunk();
}


////////////////////////////////////////////////
void SStatSectionData::save(IWriter &stream)
Expand All @@ -45,8 +69,8 @@ void SStatSectionData::load(IReader &stream)
load_data (data, stream);
if(ai().get_alife()->header().version()==0x0002)
{
int tmp;
load_data (tmp, stream);
int tmp;
load_data (tmp, stream);
switch(tmp)
{
case 100:
Expand All @@ -73,9 +97,44 @@ void SStatSectionData::load(IReader &stream)
}
s32 tmp2;
load_data (tmp2, stream);// old total_points
}else
load_data (key, stream);
};
}
else {
load_data(key, stream);
}
}

void SStatSectionData::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("SStatSectionData");
{
Object->GetCurrentChunk()->WriteArray(data.size());
for (const auto& elem : data) {
elem.save(Object);
}
Object->GetCurrentChunk()->EndArray();
Object->GetCurrentChunk()->w_stringZ(key);
}
Object->EndChunk();
}

void SStatSectionData::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("SStatSectionData");
{
data.clear();
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
for (u64 i = 0; i < ArraySize; ++i) {
SStatDetailBData&& Value = SStatDetailBData();
Value.load(Object);
data.emplace_back(Value);
}
Object->GetCurrentChunk()->EndArray();
Object->GetCurrentChunk()->r_stringZ(key);
}
Object->EndChunk();
}


SStatDetailBData& SStatSectionData::GetData (const shared_str& key_)
{
Expand Down
Loading

0 comments on commit 66b0fdf

Please sign in to comment.