Skip to content

Commit

Permalink
Add support of new save system to more classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnelenpridumivat committed Dec 9, 2024
1 parent 592fb4e commit f573367
Show file tree
Hide file tree
Showing 21 changed files with 1,396 additions and 31 deletions.
18 changes: 18 additions & 0 deletions src/xrGame/GameTaskDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ struct CGameTaskRegistry : public CALifeAbstractRegistry<u16, vGameTasks>
CALifeAbstractRegistry<u16, vGameTasks>::load(stream);
load_data (g_active_task_id, stream);
};
virtual void save(CSaveObjectSave* Object) const
{
Object->BeginChunk("CGameTaskRegistry");
{
CALifeAbstractRegistry<u16, vGameTasks>::save(Object);
Object->GetCurrentChunk()->w_stringZ(g_active_task_id);
}
Object->EndChunk();
};
virtual void load(CSaveObjectLoad* Object)
{
Object->BeginChunk("CGameTaskRegistry");
{
CALifeAbstractRegistry<u16, vGameTasks>::load(Object);
Object->GetCurrentChunk()->r_stringZ(g_active_task_id);
}
Object->EndChunk();
};
};
20 changes: 20 additions & 0 deletions src/xrGame/InfoPortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ void INFO_DATA::save (IWriter& stream)
save_data(receive_time, stream);
}

void INFO_DATA::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("INFO_DATA");
{
Object->GetCurrentChunk()->r_stringZ(info_id);
Object->GetCurrentChunk()->r_u64(receive_time);
}
Object->EndChunk();
}

void INFO_DATA::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("INFO_DATA");
{
Object->GetCurrentChunk()->w_stringZ(info_id);
Object->GetCurrentChunk()->w_u64(receive_time);
}
Object->EndChunk();
}


SInfoPortionData::SInfoPortionData ()
{
Expand Down
5 changes: 4 additions & 1 deletion src/xrGame/alife_abstract_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "object_interfaces.h"
#include "object_broker.h"
#include "Save/SaveObject.h"

template <typename _index_type, typename _data_type>
class CALifeAbstractRegistry : public IPureSerializeObject<IReader,IWriter> {
Expand All @@ -28,10 +29,12 @@ class CALifeAbstractRegistry : public IPureSerializeObject<IReader,IWriter> {
virtual ~CALifeAbstractRegistry ();
virtual void save (IWriter &memory_stream);
virtual void load (IReader &file_stream);
virtual void save(CSaveObjectSave* Object) const;
virtual void load(CSaveObjectLoad* Object);
IC const OBJECT_REGISTRY &objects () const;
IC void add (const _index_type &index, _data_type &data, bool no_assert = false);
IC void remove (const _index_type &index, bool no_assert = false);
IC _data_type *object (const _index_type &index, bool no_assert = false);
};

#include "alife_abstract_registry_inline.h"
#include "alife_abstract_registry_inline.h"
192 changes: 192 additions & 0 deletions src/xrGame/alife_abstract_registry_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,163 @@
////////////////////////////////////////////////////////////////////////////

#pragma once
#include "game_news.h"
#include "encyclopedia_article_defs.h"
#include "character_info_defs.h"
#include "relation_registry_defs.h"
#include "InfoPortionDefs.h"
#include "_stl_extensions.h"
#include "map_location_defs.h"

namespace SaveSystemDefined {

template<typename K, typename V>
void Save(CSaveObjectSave* Obj, K Key, const V& Value) {
VERIFY2(false, "Not implemented for such template arguments!");
}

template<typename K, typename V>
void Load(CSaveObjectLoad* Obj, K& Key, V& Value) {
VERIFY2(false, "Not implemented for such template arguments!");
}

template<>
void Save<u16, KNOWN_INFO_VECTOR>(CSaveObjectSave* Obj, u16 Key, const KNOWN_INFO_VECTOR& Value) {
Obj->GetCurrentChunk()->w_u16(Key);
Obj->GetCurrentChunk()->WriteArray(Value.size());
{
for (const auto& elem : Value) {
elem.save(Obj);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Load<u16, KNOWN_INFO_VECTOR>(CSaveObjectLoad* Obj, u16& Key, KNOWN_INFO_VECTOR& Value) {
Obj->GetCurrentChunk()->r_u16(Key);
Value.clear();
u64 ArraySize;
Obj->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
INFO_DATA&& temp = INFO_DATA();
temp.load(Obj);
Value.emplace_back(temp);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Save<u16, RELATION_DATA>(CSaveObjectSave* Obj, u16 Key, const RELATION_DATA& Value) {
Obj->GetCurrentChunk()->w_u16(Key);
Value.save(Obj);
}

template<>
void Load<u16, RELATION_DATA>(CSaveObjectLoad* Obj, u16& Key, RELATION_DATA& Value) {
Obj->GetCurrentChunk()->r_u16(Key);
Value.load(Obj);
}

template<>
void Save<u16, ARTICLE_VECTOR>(CSaveObjectSave* Obj, u16 Key, const ARTICLE_VECTOR& Value) {
Obj->GetCurrentChunk()->w_u16(Key);
Obj->GetCurrentChunk()->WriteArray(Value.size());
{
for (const auto& elem : Value) {
elem.save(Obj);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Load<u16, ARTICLE_VECTOR>(CSaveObjectLoad* Obj, u16& Key, ARTICLE_VECTOR& Value) {
Obj->GetCurrentChunk()->r_u16(Key);
Value.clear();
u64 ArraySize;
Obj->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
ARTICLE_DATA&& temp = ARTICLE_DATA();
temp.load(Obj);
Value.emplace_back(temp);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Save<u16, GAME_NEWS_VECTOR>(CSaveObjectSave* Obj, u16 Key, const GAME_NEWS_VECTOR& Value) {
Obj->GetCurrentChunk()->w_u16(Key);
Obj->GetCurrentChunk()->WriteArray(Value.size());
{
for (const auto& elem : Value) {
elem.save(Obj);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Load<u16, GAME_NEWS_VECTOR>(CSaveObjectLoad* Obj, u16& Key, GAME_NEWS_VECTOR& Value) {
Obj->GetCurrentChunk()->r_u16(Key);
Value.clear();
u64 ArraySize;
Obj->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
GAME_NEWS_DATA&& temp = GAME_NEWS_DATA();
temp.load(Obj);
Value.emplace_back(temp);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Save<shared_str, int>(CSaveObjectSave* Obj, shared_str Key, const int& Value) {
Obj->GetCurrentChunk()->w_stringZ(Key);
Obj->GetCurrentChunk()->w_s32(Value);
}

template<>
void Load<shared_str, int>(CSaveObjectLoad* Obj, shared_str& Key, int& Value) {
Obj->GetCurrentChunk()->r_stringZ(Key);
Obj->GetCurrentChunk()->r_s32(Value);
}

template<>
void Save<u16, Locations>(CSaveObjectSave* Obj, u16 Key, const Locations& Value) {
Obj->GetCurrentChunk()->w_u16(Key);
Obj->GetCurrentChunk()->WriteArray(Value.size());
{
for (const auto& elem : Value) {
elem.save(Obj);
}
}
Obj->GetCurrentChunk()->EndArray();
}

template<>
void Load<u16, Locations>(CSaveObjectLoad* Obj, u16& Key, Locations& Value) {
Obj->GetCurrentChunk()->r_u16(Key);
Value.clear();
u64 ArraySize;
Obj->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
GAME_NEWS_DATA&& temp = GAME_NEWS_DATA();
temp.load(Obj);
Value.emplace_back(temp);
}
}
Obj->GetCurrentChunk()->EndArray();
}

};

#define TEMPLATE_SPECIALIZATION template <typename _index_type, typename _data_type>
#define CSALifeAbstractRegistry CALifeAbstractRegistry<_index_type,_data_type>
Expand Down Expand Up @@ -34,6 +191,41 @@ void CSALifeAbstractRegistry ::load (IReader &file_stream)
load_data (m_objects,file_stream);
}

TEMPLATE_SPECIALIZATION
void CSALifeAbstractRegistry::save(CSaveObjectSave* Object) const
{
Object->GetCurrentChunk()->WriteArray(m_objects.size());
{
for (const auto& elem : m_objects) {
Object->BeginChunk("CSALifeAbstractRegistry::elem");
{
SaveSystemDefined::Save<_index_type, _data_type>(Object, elem.first, elem.second);
}
Object->EndChunk();
}
}
Object->GetCurrentChunk()->EndArray();
}

TEMPLATE_SPECIALIZATION
void CSALifeAbstractRegistry::load(CSaveObjectLoad* Object)
{
u64 ArraySize;
Object->GetCurrentChunk()->ReadArray(ArraySize);
{
for (u64 i = 0; i < ArraySize; ++i) {
std::pair< _index_type, _data_type>&& temp = std::pair< _index_type, _data_type>();
Object->BeginChunk("CSALifeAbstractRegistry::elem");
{
SaveSystemDefined::Load<_index_type, _data_type>(Object, temp.first, temp.second);
}
Object->EndChunk();
m_objects.emplace(temp);
}
}
Object->GetCurrentChunk()->EndArray();
}

TEMPLATE_SPECIALIZATION
IC const typename CSALifeAbstractRegistry::OBJECT_REGISTRY &CSALifeAbstractRegistry::objects () const
{
Expand Down
25 changes: 25 additions & 0 deletions src/xrGame/alife_registry_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,28 @@ void CALifeRegistryContainer::save(IWriter &memory_stream)
>::process (this,memory_stream);
memory_stream.close_chunk ();
}

void CALifeRegistryContainer::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("CALifeRegistryContainer");
{
CInfoPortionRegistry::load(Object);
CRelationRegistry::load(Object);
CEncyclopediaRegistry::load(Object);
CGameNewsRegistry::load(Object);
CSpecificCharacterRegistry::load(Object);
CMapLocationRegistry::load(Object);
CGameTaskRegistry::load(Object);
CActorStatisticRegistry::load(Object);
}
Object->EndChunk();
}

void CALifeRegistryContainer::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("CALifeRegistryContainer");
{

}
Object->EndChunk();
}
3 changes: 3 additions & 0 deletions src/xrGame/alife_registry_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alife_registry_container_space.h"
#include "alife_registry_container_composition.h"
#include "alife_abstract_registry.h"
#include "Save/SaveObject.h"

template <typename _type, typename _base>
struct CLinearRegistryType : public _base, public _type {};
Expand All @@ -26,6 +27,8 @@ class CALifeRegistryContainer : public Loki::GenLinearHierarchy<registry_type_li
IC const T &operator() (const T*) const;
virtual void load (IReader &file_stream);
virtual void save (IWriter &memory_stream);
virtual void load(CSaveObjectLoad* Object);
virtual void save(CSaveObjectSave* Object) const;
};

#include "alife_registry_container_inline.h"
28 changes: 28 additions & 0 deletions src/xrGame/encyclopedia_article.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ void ARTICLE_DATA::save (IWriter& stream)
save_data(article_type, stream);
}

void ARTICLE_DATA::load(CSaveObjectLoad* Object)
{
Object->BeginChunk("ARTICLE_DATA");
{
Object->GetCurrentChunk()->r_u64(receive_time);
Object->GetCurrentChunk()->r_stringZ(article_id);
Object->GetCurrentChunk()->r_bool(readed);
{
u8 type;
Object->GetCurrentChunk()->r_u8(type);
article_type = (EArticleType)type;
}
}
Object->EndChunk();
}

void ARTICLE_DATA::save(CSaveObjectSave* Object) const
{
Object->BeginChunk("ARTICLE_DATA");
{
Object->GetCurrentChunk()->w_u64(receive_time);
Object->GetCurrentChunk()->w_stringZ(article_id);
Object->GetCurrentChunk()->w_bool(readed);
Object->GetCurrentChunk()->w_u8((u8)article_type);
}
Object->EndChunk();
}

CEncyclopediaArticle::CEncyclopediaArticle()
{
}
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/encyclopedia_article_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct ARTICLE_DATA : public IPureSerializeObject<IReader,IWriter>

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

ALife::_TIME_ID receive_time;
shared_str article_id;
Expand Down
Loading

0 comments on commit f573367

Please sign in to comment.