diff --git a/lib/app/include/app/application/ecs/component_meta_function.hpp b/lib/app/include/app/application/ecs/component_meta_function.hpp index e64f7705e..230a4d718 100644 --- a/lib/app/include/app/application/ecs/component_meta_function.hpp +++ b/lib/app/include/app/application/ecs/component_meta_function.hpp @@ -5,7 +5,7 @@ #include "app/application/ecs/registry_manager.hpp" #include "app/core/ecs/base_entity.hpp" #include "app/core/ecs/concepts.hpp" -#include "app/core/serialization/serialization.hpp" +#include "app/serialization/serialization_system.hpp" #include #include #include @@ -25,7 +25,7 @@ namespace VTX::App::Application::ECS { _mapSerializer[ p_id ] = []( const Core::ECS::BaseEntity & p_entity, const Application::ECS::RegistryManager & p_registry, - const Core::Serialization::Serialization & p_serializer ) + const Serialization::SerializationSystem & p_serializer ) { const T & component = p_registry.getComponent( p_entity ); @@ -40,7 +40,7 @@ namespace VTX::App::Application::ECS }; _mapDeserializer[ p_id ] = []( Application::ECS::RegistryManager & p_registry, - const Core::Serialization::Serialization & p_serializer, + const Serialization::SerializationSystem & p_serializer, const Util::JSon::Object & p_json, const Core::ECS::BaseEntity & p_target ) { @@ -66,10 +66,10 @@ namespace VTX::App::Application::ECS private: using ComponentSerializerFunction = std::function< const Util::JSon:: - Object( const Core::ECS::BaseEntity &, const Application::ECS::RegistryManager &, const Core::Serialization::Serialization & )>; + Object( const Core::ECS::BaseEntity &, const Application::ECS::RegistryManager &, const Serialization::SerializationSystem & )>; using ComponentDeserializerFunction = std::function< - void( Application::ECS::RegistryManager &, const Core::Serialization::Serialization &, const Util::JSon::Object &, const Core::ECS::BaseEntity & )>; + void( Application::ECS::RegistryManager &, const Serialization::SerializationSystem &, const Util::JSon::Object &, const Core::ECS::BaseEntity & )>; std::map _mapSerializer = std::map(); diff --git a/lib/app/include/app/application/settings/base_setting.hpp b/lib/app/include/app/application/settings/base_setting.hpp index 6ee9d8048..b03a79129 100644 --- a/lib/app/include/app/application/settings/base_setting.hpp +++ b/lib/app/include/app/application/settings/base_setting.hpp @@ -1,7 +1,7 @@ #ifndef __VTX_APP_APPLICATION_SETTINGS_BASE_SETTING__ #define __VTX_APP_APPLICATION_SETTINGS_BASE_SETTING__ -#include "app/application/system/serializer.hpp" +#include "app/serialization/serialization_system.hpp" #include #include #include @@ -37,10 +37,10 @@ namespace VTX::App::Application::Settings void set( const T & p_value ) { _value = p_value; } - Util::JSon::BasicJSon serialize() const override { return SERIALIZER().serialize( _value ); } + Util::JSon::BasicJSon serialize() const override { return SERIALIZATION_SYSTEM().serialize( _value ); } void deserialize( const Util::JSon::BasicJSon & p_json ) override { - SERIALIZER().deserialize( p_json, _value ); + SERIALIZATION_SYSTEM().deserialize( p_json, _value ); } void reset() override diff --git a/lib/app/include/app/application/system/serializer.hpp b/lib/app/include/app/application/system/serializer.hpp deleted file mode 100644 index 9d9207c3a..000000000 --- a/lib/app/include/app/application/system/serializer.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __VTX_APP_APPLICATION_SYSTEM_SERIALIZER__ -#define __VTX_APP_APPLICATION_SYSTEM_SERIALIZER__ - -#include "app/core/io/reader/serialized_object.hpp" -#include "app/core/io/writer/serialized_object.hpp" -#include "app/core/serialization/serialization.hpp" - -namespace VTX::App::Application::System -{ - class Serializer final : public Core::Serialization::Serialization - { - public: - // Directly read a file at path p_path and deserialize it in p_obj object. - template - void readObject( const FilePath & p_path, T & p_obj ) - { - const Core::IO::Reader::SerializedObject serializedObject - = Core::IO::Reader::SerializedObject( *this, p_path, &p_obj ); - - serializedObject.read(); - } - - // Directly serialize an object p_obj and write the json file at p_path - template - void writeObject( const FilePath & p_path, const T & p_obj ) - { - const Core::IO::Writer::SerializedObject serializedObject - = Core::IO::Writer::SerializedObject( *this, p_path, &p_obj ); - - serializedObject.write(); - } - }; -} // namespace VTX::App::Application::System - -namespace VTX::App -{ - // Access the serializer to serialize / deserialize objects, or directly read / write file in json. - inline Application::System::Serializer & SERIALIZER() - { - return Util::Singleton::get(); - } -} // namespace VTX::App - -#endif diff --git a/lib/app/include/app/core/io/reader/serialized_object.hpp b/lib/app/include/app/core/io/reader/serialized_object.hpp deleted file mode 100644 index eae8df2a1..000000000 --- a/lib/app/include/app/core/io/reader/serialized_object.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __VTX_APP_CORE_IO_READER_SERIALIZED_OBJECT__ -#define __VTX_APP_CORE_IO_READER_SERIALIZED_OBJECT__ - -#include "app/core/serialization/serialization.hpp" -#include "app/core/serialization/version.hpp" -#include -#include -#include -#include -#include -#include - -namespace VTX::App::Core::IO::Reader -{ - template - class SerializedObject - { - private: - public: - SerializedObject( - const Serialization::Serialization & p_serializer, - const FilePath & p_path, - T * const p_target - ) : - _serializer( p_serializer ), - _path( p_path ), _target( p_target ) - { - } - - void read() const - { - Util::JSon::Document fullDoc = Util::JSon::IO::open( _path ); - - if ( !fullDoc.json().contains( "VERSION" ) || !fullDoc.json().contains( "DATA" ) ) - throw IOException( "Ill-formed save file" ); - - Serialization::Version fileVersion; - _serializer.deserialize( fullDoc.json()[ "VERSION" ], fileVersion ); - - if ( fileVersion > Serialization::Version::CURRENT ) - throw IOException( "Can not read file, version is newer than VTX" ); - - VTX::Util::JSon::BasicJSon & dataJSon = fullDoc.json()[ "DATA" ]; - - if ( fileVersion < Serialization::Version::CURRENT ) - _serializer.upgrade( dataJSon, *_target, fileVersion ); - - _serializer.deserialize( dataJSon, *_target ); - } - - private: - const Serialization::Serialization & _serializer; - FilePath _path; - T * _target; - }; -} // namespace VTX::App::Core::IO::Reader - -#endif diff --git a/lib/app/include/app/core/io/writer/serialized_object.hpp b/lib/app/include/app/core/io/writer/serialized_object.hpp deleted file mode 100644 index 4558c6e82..000000000 --- a/lib/app/include/app/core/io/writer/serialized_object.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __VTX_APP_CORE_IO_WRITER_SERIALIZED_OBJECT__ -#define __VTX_APP_CORE_IO_WRITER_SERIALIZED_OBJECT__ - -#include "app/core/serialization/serialization.hpp" -#include "app/core/serialization/version.hpp" -#include -#include -#include -#include - -namespace VTX::App::Core::IO::Writer -{ - template - class SerializedObject - { - public: - SerializedObject( - const Serialization::Serialization & p_serializer, - const FilePath & p_path, - const T * p_obj, - const Serialization::Version & p_version = Serialization::Version::CURRENT - ) : - _serializer( p_serializer ), - _path( p_path ), _obj( p_obj ), _version( p_version ) - { - } - - void write() const - { - const VTX::Util::JSon::Document jsonDoc - = { { "VERSION", _serializer.serialize( _version ) }, { "DATA", _serializer.serialize( *_obj ) } }; - - Util::JSon::IO::write( _path, jsonDoc ); - } - - private: - const Serialization::Serialization & _serializer; - FilePath _path; - Serialization::Version _version; - - const T * _obj; - }; - -} // namespace VTX::App::Core::IO::Writer - -#endif diff --git a/lib/app/include/app/core/serialization/_fwd.hpp b/lib/app/include/app/core/serialization/_fwd.hpp deleted file mode 100644 index eb82d3b84..000000000 --- a/lib/app/include/app/core/serialization/_fwd.hpp +++ /dev/null @@ -1,5 +0,0 @@ -namespace VTX::App::Core::Serialization -{ - class Serialization; - class Version; -} // namespace VTX::App::Core::Serialization diff --git a/lib/app/include/app/core/serialization/serialization.hpp b/lib/app/include/app/core/serialization/serialization.hpp deleted file mode 100644 index bcb5ad1aa..000000000 --- a/lib/app/include/app/core/serialization/serialization.hpp +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef __VTX_APP_CORE_SERIALIZATION_SERIALIZATION__ -#define __VTX_APP_CORE_SERIALIZATION_SERIALIZATION__ - -#include "app/core/serialization/upgrade_stack.hpp" -#include "app/core/serialization/version.hpp" -#include "app/internal/serialization/all_serializers.hpp" -#include -#include -#include -#include -#include -#include -#include - -namespace VTX::App::Core::Serialization -{ - template - concept SerializableByDefaultConcept - = (!Util::JSon::BasicJSonConcept) && requires( T & p_obj ) { - { - Internal::Serialization::serialize( p_obj ) - } -> std::convertible_to; - }; - template - concept DeserializableByDefaultConcept - = (!Util::JSon::BasicJSonConcept) && requires( const Util::JSon::BasicJSon & p_json, T & p_obj ) { - Internal::Serialization::deserialize( p_json, p_obj ); - }; - - class Serialization - { - public: - template - using SerializeFunc = std::function; - - template - using DeserializeFunc = std::function; - - template - void registerSerializationFunction( SerializeFunc p_serializationFunction ) - { - _mapSerializeFunctions.emplace( typeid( T ), p_serializationFunction ); - } - template - void registerDeserializationFunction( DeserializeFunc p_deserializationFunction ) - { - _mapDeserializeFunctions.emplace( typeid( T ), p_deserializationFunction ); - } - - template - Util::JSon::BasicJSon serialize( const T & p_obj ) const - { - return Util::JSon::BasicJSon( p_obj ); - } - template - Util::JSon::BasicJSon serialize( const T & p_obj ) const - { - return App::Internal::Serialization::serialize( p_obj ); - } - template - Util::JSon::BasicJSon serialize( const T & p_obj ) const - { - if ( !_mapSerializeFunctions.contains( typeid( T ) ) ) - throw VTXException( "No serializer found for {}", typeid( T ).name() ); - - return std::any_cast &>( _mapSerializeFunctions.at( typeid( T ) ) )( p_obj ); - } - - template - void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const - { - p_obj = p_jsonObj.get(); - } - template - void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const - { - App::Internal::Serialization::deserialize( p_jsonObj, p_obj ); - } - template - void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const - { - if ( !_mapDeserializeFunctions.contains( typeid( T ) ) ) - throw VTXException( "No deserializer found for {}", typeid( T ).name() ); - - std::any_cast &>( _mapDeserializeFunctions.at( typeid( T ) ) - )( p_jsonObj.getObject(), p_obj ); - } - - template - T deserializeField( - const Util::JSon::Object & p_jsonObj, - const std::string & p_key, - const T & p_defaultValue = T() - ) - { - T res; - - if ( p_jsonObj.contains( p_key ) ) - { - try - { - deserialize( p_jsonObj[ p_key ], res ); - } - catch ( const std::exception & e ) - { - VTX_WARNING( "Issue during deserialization of {} ({}). Default value assigned.", p_key, e.what() ); - res = p_defaultValue; - } - } - else - { - res = p_defaultValue; - } - - return res; - } - - template - bool canSerialize() const - { - return true; - } - template - bool canSerialize() const - { - return true; - } - template - bool canSerialize() const - { - return _mapSerializeFunctions.contains( typeid( T ) ); - } - - template - void registerUpgrade( const Version & p_version, UpgradeFunc p_upgradeFunc ) - { - if ( !_mapUpgradeFunctions.contains( typeid( T ) ) ) - _mapUpgradeFunctions.emplace( typeid( T ), UpgradeStack() ); - - std::any & any = _mapUpgradeFunctions[ typeid( T ) ]; - UpgradeStack & stack = std::any_cast &>( any ); - stack.add( p_version, p_upgradeFunc ); - } - - template - void upgrade( Util::JSon::BasicJSon & p_jsonObj, T & p_obj, const Version & p_version ) const - { - if ( _mapUpgradeFunctions.contains( typeid( T ) ) ) - { - const std::any & any = _mapUpgradeFunctions.at( typeid( T ) ); - const UpgradeStack & stack = std::any_cast &>( any ); - stack.applyUpgrades( p_jsonObj, p_obj, p_version ); - } - } - - private: - std::map _mapSerializeFunctions = std::map(); - std::map _mapDeserializeFunctions = std::map(); - - std::map _mapUpgradeFunctions = std::map(); - }; -} // namespace VTX::App::Core::Serialization - -#endif diff --git a/lib/app/include/app/core/serialization/serialization_system.hpp b/lib/app/include/app/core/serialization/serialization_system.hpp new file mode 100644 index 000000000..cae70b0aa --- /dev/null +++ b/lib/app/include/app/core/serialization/serialization_system.hpp @@ -0,0 +1,84 @@ +#ifndef __VTX_APP_CORE_SERIALIZATION_SERIALIZATION__ +#define __VTX_APP_CORE_SERIALIZATION_SERIALIZATION__ + +#include "upgrade_stack.hpp" +#include "version.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace VTX::App::Core::Serialization +{ + + class SerializationSystem + { + public: + template + using SerializeFunc = std::function; + + template + using DeserializeFunc = std::function; + + template + void registerSerializationFunction( SerializeFunc p_serializationFunction ) + { + _mapSerializeFunctions.emplace( typeid( T ), p_serializationFunction ); + } + template + void registerDeserializationFunction( DeserializeFunc p_deserializationFunction ) + { + _mapDeserializeFunctions.emplace( typeid( T ), p_deserializationFunction ); + } + + template + Util::JSon::BasicJSon serialize( const T & p_obj ) const + { + return Util::JSon::BasicJSon( p_obj ); + } + + template + void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const + { + p_obj = p_jsonObj.get(); + } + + template + bool canSerialize() const + { + return true; + } + + template + void registerUpgrade( const Version & p_version, UpgradeFunc p_upgradeFunc ) + { + if ( !_mapUpgradeFunctions.contains( typeid( T ) ) ) + _mapUpgradeFunctions.emplace( typeid( T ), UpgradeStack() ); + + std::any & any = _mapUpgradeFunctions[ typeid( T ) ]; + UpgradeStack & stack = std::any_cast &>( any ); + stack.add( p_version, p_upgradeFunc ); + } + + template + void upgrade( Util::JSon::BasicJSon & p_jsonObj, T & p_obj, const Version & p_version ) const + { + if ( _mapUpgradeFunctions.contains( typeid( T ) ) ) + { + const std::any & any = _mapUpgradeFunctions.at( typeid( T ) ); + const UpgradeStack & stack = std::any_cast &>( any ); + stack.applyUpgrades( p_jsonObj, p_obj, p_version ); + } + } + + protected: + std::map _mapSerializeFunctions; + std::map _mapDeserializeFunctions; + std::map _mapUpgradeFunctions; + }; +} // namespace VTX::App::Core::Serialization + +#endif diff --git a/lib/app/include/app/core/threading/base_thread.hpp b/lib/app/include/app/core/threading/base_thread.hpp index 45caacf03..61bdb3aea 100644 --- a/lib/app/include/app/core/threading/base_thread.hpp +++ b/lib/app/include/app/core/threading/base_thread.hpp @@ -11,7 +11,7 @@ namespace VTX::App::Core::Threading { - class ThreadingManager; + class ThreadingSystem; class BaseThread { @@ -20,7 +20,7 @@ namespace VTX::App::Core::Threading using EndCallback = std::function; public: - BaseThread( ThreadingManager & p_manager ) : _manager( p_manager ) {}; + BaseThread( ThreadingSystem & p_manager ) : _manager( p_manager ) {}; ~BaseThread(); void start( const AsyncOp & p_function ); @@ -48,7 +48,7 @@ namespace VTX::App::Core::Threading } private: - ThreadingManager & _manager; + ThreadingSystem & _manager; std::thread _thread; float _progress = 0.f; @@ -58,5 +58,5 @@ namespace VTX::App::Core::Threading void _finish(); }; -} // namespace VTX::App::Core::Worker +} // namespace VTX::App::Core::Threading #endif diff --git a/lib/app/include/app/core/threading/threading_system.hpp b/lib/app/include/app/core/threading/threading_system.hpp index 37228ecf9..2c63b42c3 100644 --- a/lib/app/include/app/core/threading/threading_system.hpp +++ b/lib/app/include/app/core/threading/threading_system.hpp @@ -38,7 +38,7 @@ namespace VTX::App::Core::Threading namespace VTX::App { // Access to the worker manager class in order to launch thread. - inline Core::Threading::ThreadingSystem & THREADING() + inline Core::Threading::ThreadingSystem & THREADING_SYSTEM() { return Util::Singleton::get(); } diff --git a/lib/app/include/app/internal/serialization/all_serializers.hpp b/lib/app/include/app/internal/serialization/all_serializers.hpp deleted file mode 100644 index cf0b031d0..000000000 --- a/lib/app/include/app/internal/serialization/all_serializers.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __VTX_APP_INTERNAL_SERIALIZATION_ALL_SERIALIZERS__ -#define __VTX_APP_INTERNAL_SERIALIZATION_ALL_SERIALIZERS__ - -#include "app/internal/serialization/app_serializers.hpp" -#include "app/internal/serialization/scene_serializers.hpp" -#include "app/internal/serialization/util_serializers.hpp" - -#endif diff --git a/lib/app/include/app/internal/serialization/app_serializers.hpp b/lib/app/include/app/serialization/app_serializers.hpp similarity index 89% rename from lib/app/include/app/internal/serialization/app_serializers.hpp rename to lib/app/include/app/serialization/app_serializers.hpp index c2492b48f..45dc19d4f 100644 --- a/lib/app/include/app/internal/serialization/app_serializers.hpp +++ b/lib/app/include/app/serialization/app_serializers.hpp @@ -1,5 +1,5 @@ -#ifndef __VTX_APP_INTERNAL_SERIALIZATION_APP_SERIALIZERS__ -#define __VTX_APP_INTERNAL_SERIALIZATION_APP_SERIALIZERS__ +#ifndef __VTX_APP_SERIALIZATION_APP_SERIALIZERS__ +#define __VTX_APP_SERIALIZATION_APP_SERIALIZERS__ #include "app/application/_fwd.hpp" #include "app/application/settings/_fwd.hpp" @@ -12,7 +12,7 @@ namespace VTX::App class VTXApp; } -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Version Util::JSon::Object serialize( const App::Core::Serialization::Version & ); @@ -42,5 +42,5 @@ namespace VTX::App::Internal::Serialization Util::JSon::Object serialize( const App::Core::Player::PingPong & ); void deserialize( const Util::JSon::Object &, App::Core::Player::PingPong & ); -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization #endif diff --git a/lib/app/include/app/internal/io/reader/molecule_loader.hpp b/lib/app/include/app/serialization/io/reader/molecule_loader.hpp similarity index 80% rename from lib/app/include/app/internal/io/reader/molecule_loader.hpp rename to lib/app/include/app/serialization/io/reader/molecule_loader.hpp index 8a0b6dbe2..bbe7aabc6 100644 --- a/lib/app/include/app/internal/io/reader/molecule_loader.hpp +++ b/lib/app/include/app/serialization/io/reader/molecule_loader.hpp @@ -1,5 +1,5 @@ -#ifndef __VTX_APP_INTERNAL_IO_FLAT_MOLECULE_LOADER__ -#define __VTX_APP_INTERNAL_IO_FLAT_MOLECULE_LOADER__ +#ifndef __VTX_APP_SERIALIZATION_IO_READER_MOLECULE_LOADER__ +#define __VTX_APP_SERIALIZATION_IO_READER_MOLECULE_LOADER__ #include "app/component/chemistry/_fwd.hpp" #include "app/component/io/molecule_metadata.hpp" @@ -10,7 +10,7 @@ #include #include -namespace VTX::App::Internal::IO::Reader +namespace VTX::App::Serialization::IO::Reader { class MoleculeLoader : public VTX::IO::Core::Reader::BaseReader { @@ -25,5 +25,5 @@ namespace VTX::App::Internal::IO::Reader private: VTX::IO::Reader::Molecule _reader = VTX::IO::Reader::Molecule(); }; -} // namespace VTX::App::Internal::IO::Reader +} // namespace VTX::App::Serialization::IO::Reader #endif diff --git a/lib/app/include/app/internal/io/reader/scene_loader.hpp b/lib/app/include/app/serialization/io/reader/scene_loader.hpp similarity index 65% rename from lib/app/include/app/internal/io/reader/scene_loader.hpp rename to lib/app/include/app/serialization/io/reader/scene_loader.hpp index d6071c079..2c13c775f 100644 --- a/lib/app/include/app/internal/io/reader/scene_loader.hpp +++ b/lib/app/include/app/serialization/io/reader/scene_loader.hpp @@ -1,11 +1,11 @@ -#ifndef __VTX_APP_INTERNAL_IO_SCENE_LOADER__ -#define __VTX_APP_INTERNAL_IO_SCENE_LOADER__ +#ifndef __VTX_APP_SERIALIZATION_IO_READER_SCENE_LOADER__ +#define __VTX_APP_SERIALIZATION_IO_READER_SCENE_LOADER__ #include "app/application/scene.hpp" #include #include -namespace VTX::App::Internal::IO::Reader +namespace VTX::App::Serialization::IO::Reader { class SceneLoader : public VTX::IO::Core::Reader::BaseReader { @@ -14,5 +14,5 @@ namespace VTX::App::Internal::IO::Reader void readFile( const FilePath & p_path, App::Application::Scene & p_scene ) override; }; -} // namespace VTX::App::Internal::IO::Reader +} // namespace VTX::App::Serialization::IO::Reader #endif diff --git a/lib/app/include/app/internal/io/writer/scene_writer.hpp b/lib/app/include/app/serialization/io/writer/scene_writer.hpp similarity index 57% rename from lib/app/include/app/internal/io/writer/scene_writer.hpp rename to lib/app/include/app/serialization/io/writer/scene_writer.hpp index 86349b770..ed9b47583 100644 --- a/lib/app/include/app/internal/io/writer/scene_writer.hpp +++ b/lib/app/include/app/serialization/io/writer/scene_writer.hpp @@ -1,10 +1,10 @@ -#ifndef __VTX_APP_INTERNAL_IO_WRITER_SCENE_WRITER__ -#define __VTX_APP_INTERNAL_IO_WRITER_SCENE_WRITER__ +#ifndef __VTX_APP_SERIALLIZATION_IO_WRITER_SCENE_WRITER__ +#define __VTX_APP_SERIALLIZATION_IO_WRITER_SCENE_WRITER__ #include "app/application/_fwd.hpp" #include -namespace VTX::App::Internal::IO::Writer +namespace VTX::App::Serialization::IO::Writer { class SceneWriter // : public VTX::IO::Core::Writer::BaseWriter { @@ -13,5 +13,5 @@ namespace VTX::App::Internal::IO::Writer void writeFile( const FilePath & p_path, const App::Application::Scene & p_scene ); }; -} // namespace VTX::App::Internal::IO::Writer +} // namespace VTX::App::Serialization::IO::Writer #endif diff --git a/lib/app/include/app/internal/serialization/scene_serializers.hpp b/lib/app/include/app/serialization/scene_serializers.hpp similarity index 86% rename from lib/app/include/app/internal/serialization/scene_serializers.hpp rename to lib/app/include/app/serialization/scene_serializers.hpp index 199d8dbd9..afd4767b8 100644 --- a/lib/app/include/app/internal/serialization/scene_serializers.hpp +++ b/lib/app/include/app/serialization/scene_serializers.hpp @@ -1,5 +1,5 @@ -#ifndef __VTX_APP_INTERNAL_SERIALIZATION_SCENE_SERIALIZERS__ -#define __VTX_APP_INTERNAL_SERIALIZATION_SCENE_SERIALIZERS__ +#ifndef __VTX_APP_SERIALIZATION_SCENE_SERIALIZERS__ +#define __VTX_APP_SERIALIZATION_SCENE_SERIALIZERS__ #include "app/application/_fwd.hpp" #include "app/component/chemistry/_fwd.hpp" @@ -7,7 +7,7 @@ #include "app/component/scene/_fwd.hpp" #include -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Scene Util::JSon::Object serialize( const App::Application::Scene & ); @@ -33,5 +33,5 @@ namespace VTX::App::Internal::Serialization Util::JSon::Object serialize( const Component::Chemistry::Trajectory & p_component ); void deserialize( const Util::JSon::Object & p_json, Component::Chemistry::Trajectory & p_component ); -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization #endif diff --git a/lib/app/include/app/serialization/serialization_system.hpp b/lib/app/include/app/serialization/serialization_system.hpp new file mode 100644 index 000000000..471d1605e --- /dev/null +++ b/lib/app/include/app/serialization/serialization_system.hpp @@ -0,0 +1,192 @@ +#ifndef __VTX_APP_SERIALIZATION_SERIALIZATION_SYSTEM__ +#define __VTX_APP_SERIALIZATION_SERIALIZATION_SYSTEM__ + +#include "app/core/serialization/serialization_system.hpp" +#include "app_serializers.hpp" +#include "scene_serializers.hpp" +#include "util_serializers.hpp" +#include + +namespace VTX::App::Serialization +{ + template + concept SerializableByDefaultConcept = ( not Util::JSon::BasicJSonConcept ) && requires( T & p_obj ) { + { App::Serialization::serialize( p_obj ) } -> std::convertible_to; + }; + template + concept DeserializableByDefaultConcept + = ( not Util::JSon::BasicJSonConcept ) && requires( const Util::JSon::BasicJSon & p_json, T & p_obj ) { + App::Serialization::deserialize( p_json, p_obj ); + }; + + class SerializationSystem : public Core::Serialization::SerializationSystem + { + public: + template + class Reader + { + private: + public: + Reader( const SerializationSystem & p_serializer, const FilePath & p_path, T * const p_target ) : + _serializer( p_serializer ), _path( p_path ), _target( p_target ) + { + } + + void read() const + { + Util::JSon::Document fullDoc = Util::JSon::IO::open( _path ); + + if ( not fullDoc.json().contains( "VERSION" ) || not fullDoc.json().contains( "DATA" ) ) + throw IOException( "Ill-formed save file" ); + + Core::Serialization::Version fileVersion; + _serializer.deserialize( fullDoc.json()[ "VERSION" ], fileVersion ); + + if ( fileVersion > Core::Serialization::Version::CURRENT ) + throw IOException( "Can not read file, version is newer than VTX" ); + + VTX::Util::JSon::BasicJSon & dataJSon = fullDoc.json()[ "DATA" ]; + + if ( fileVersion < Core::Serialization::Version::CURRENT ) + _serializer.upgrade( dataJSon, *_target, fileVersion ); + + _serializer.deserialize( dataJSon, *_target ); + } + + private: + const SerializationSystem & _serializer; + FilePath _path; + T * _target; + }; + + template + class Writer + { + public: + Writer( + const SerializationSystem & p_serializer, + const FilePath & p_path, + const T * p_obj, + const Core::Serialization::Version & p_version = Core::Serialization::Version::CURRENT + ) : _serializer( p_serializer ), _path( p_path ), _obj( p_obj ), _version( p_version ) + { + } + + void write() const + { + const VTX::Util::JSon::Document jsonDoc + = { { "VERSION", _serializer.serialize( _version ) }, { "DATA", _serializer.serialize( *_obj ) } }; + + Util::JSon::IO::write( _path, jsonDoc ); + } + + private: + const SerializationSystem & _serializer; + FilePath _path; + Core::Serialization::Version _version; + + const T * _obj; + }; + + public: + // Directly read a file at path p_path and deserialize it in p_obj object. + template + void readObject( const FilePath & p_path, T & p_obj ) + { + const auto serializedObject = Reader( *this, p_path, &p_obj ); + + serializedObject.read(); + } + + // Directly serialize an object p_obj and write the json file at p_path + template + void writeObject( const FilePath & p_path, const T & p_obj ) + { + const auto serializedObject = Writer( *this, p_path, &p_obj ); + + serializedObject.write(); + } + + template + Util::JSon::BasicJSon serialize( const T & p_obj ) const + { + return App::Serialization::serialize( p_obj ); + } + + template + Util::JSon::BasicJSon serialize( const T & p_obj ) const + { + if ( !_mapSerializeFunctions.contains( typeid( T ) ) ) + throw VTXException( "No serializer found for {}", typeid( T ).name() ); + + return std::any_cast &>( _mapSerializeFunctions.at( typeid( T ) ) )( p_obj ); + } + + template + void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const + { + App::Serialization::deserialize( p_jsonObj, p_obj ); + } + + template + void deserialize( const Util::JSon::BasicJSon & p_jsonObj, T & p_obj ) const + { + if ( !_mapDeserializeFunctions.contains( typeid( T ) ) ) + throw VTXException( "No deserializer found for {}", typeid( T ).name() ); + + std::any_cast &>( _mapDeserializeFunctions.at( typeid( T + ) ) )( p_jsonObj.getObject(), p_obj ); + } + + template + T deserializeField( + const Util::JSon::Object & p_jsonObj, + const std::string & p_key, + const T & p_defaultValue = T() + ) + { + T res; + + if ( p_jsonObj.contains( p_key ) ) + { + try + { + deserialize( p_jsonObj[ p_key ], res ); + } + catch ( const std::exception & e ) + { + VTX_WARNING( "Issue during deserialization of {} ({}). Default value assigned.", p_key, e.what() ); + res = p_defaultValue; + } + } + else + { + res = p_defaultValue; + } + + return res; + } + + template + bool canSerialize() const + { + return true; + } + + template + bool canSerialize() const + { + return _mapSerializeFunctions.contains( typeid( T ) ); + } + }; +} // namespace VTX::App::Serialization + +namespace VTX::App +{ + inline Serialization::SerializationSystem & SERIALIZATION_SYSTEM() + { + return Util::Singleton::get(); + } +} // namespace VTX::App + +#endif diff --git a/lib/app/include/app/internal/serialization/util_serializers.hpp b/lib/app/include/app/serialization/util_serializers.hpp similarity index 95% rename from lib/app/include/app/internal/serialization/util_serializers.hpp rename to lib/app/include/app/serialization/util_serializers.hpp index 86a15ad70..a450b1661 100644 --- a/lib/app/include/app/internal/serialization/util_serializers.hpp +++ b/lib/app/include/app/serialization/util_serializers.hpp @@ -1,5 +1,5 @@ -#ifndef __VTX_APP_INTERNAL_SERIALIZATION_UTIL_SERIALIZERS__ -#define __VTX_APP_INTERNAL_SERIALIZATION_UTIL_SERIALIZERS__ +#ifndef __VTX_APP_SERIALIZATION_UTIL_SERIALIZERS__ +#define __VTX_APP_SERIALIZATION_UTIL_SERIALIZERS__ #include #include @@ -12,7 +12,7 @@ #include #include -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Enum template @@ -158,5 +158,5 @@ namespace VTX::App::Internal::Serialization } } -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization #endif diff --git a/lib/app/src/app/action/application.cpp b/lib/app/src/app/action/application.cpp index 76aeaae59..53ac3787f 100644 --- a/lib/app/src/app/action/application.cpp +++ b/lib/app/src/app/action/application.cpp @@ -1,13 +1,12 @@ #include "app/action/application.hpp" #include "app/action/scene.hpp" #include "app/application/scene.hpp" -#include "app/application/system/serializer.hpp" #include "app/application/system/settings_system.hpp" #include "app/core/renderer/renderer_system.hpp" #include "app/filesystem.hpp" -#include "app/internal/io/reader/scene_loader.hpp" -#include "app/internal/io/writer/scene_writer.hpp" -#include "app/internal/serialization/all_serializers.hpp" +#include "app/serialization/io/reader/scene_loader.hpp" +#include "app/serialization/io/writer/scene_writer.hpp" +#include "app/serialization/serialization_system.hpp" #include namespace VTX::App::Action::Application @@ -37,7 +36,7 @@ namespace VTX::App::Action::Application { SCENE().clear(); - Internal::IO::Reader::SceneLoader loader = Internal::IO::Reader::SceneLoader(); + Serialization::IO::Reader::SceneLoader loader = Serialization::IO::Reader::SceneLoader(); loader.readFile( _path, SCENE() ); // App::Old::APP::getScenePathData().setCurrentPath( _path, true ); @@ -45,7 +44,7 @@ namespace VTX::App::Action::Application void SaveScene::execute() { - Internal::IO::Writer::SceneWriter writer = Internal::IO::Writer::SceneWriter(); + Serialization::IO::Writer::SceneWriter writer = Serialization::IO::Writer::SceneWriter(); writer.writeFile( _path, SCENE() ); // VTX_THREAD( saver, _callback ); @@ -63,15 +62,18 @@ namespace VTX::App::Action::Application void ClearScene::execute() { SCENE().reset(); } LoadSettings::LoadSettings() : _path( VTX::App::Filesystem::getSettingJsonFile() ) {} - void LoadSettings::execute() { SERIALIZER().readObject( _path, SETTINGS() ); } + void LoadSettings::execute() + { + SERIALIZATION_SYSTEM().readObject( _path, SETTINGS() ); + } SaveSettings::SaveSettings() : _path( VTX::App::Filesystem::getSettingJsonFile() ) {} void SaveSettings::execute() { - SERIALIZER().writeObject( _path, SETTINGS() ); + SERIALIZATION_SYSTEM().writeObject( _path, SETTINGS() ); } void ReloadSettings::execute() { - SERIALIZER().readObject( + SERIALIZATION_SYSTEM().readObject( VTX::App::Filesystem::getSettingJsonFile(), SETTINGS() ); } diff --git a/lib/app/src/app/application/ecs/component_meta_function.cpp b/lib/app/src/app/application/ecs/component_meta_function.cpp index 276e66d35..506f2d9ce 100644 --- a/lib/app/src/app/application/ecs/component_meta_function.cpp +++ b/lib/app/src/app/application/ecs/component_meta_function.cpp @@ -1,6 +1,6 @@ #include "app/application/ecs/component_meta_function.hpp" #include "app/application/system/ecs_system.hpp" -#include "app/application/system/serializer.hpp" +#include "app/serialization/serialization_system.hpp" #include "app/vtx_app.hpp" namespace VTX::App::Application::ECS @@ -13,7 +13,7 @@ namespace VTX::App::Application::ECS { // Ensure that this component is referenced in this version if ( _mapDeserializer.contains( p_id ) ) - _mapDeserializer.at( p_id )( MAIN_REGISTRY(), SERIALIZER(), p_json, p_entity ); + _mapDeserializer.at( p_id )( MAIN_REGISTRY(), SERIALIZATION_SYSTEM(), p_json, p_entity ); }; const Util::JSon::Object ComponentMetaFunction::serializeComponent( @@ -21,6 +21,6 @@ namespace VTX::App::Application::ECS const ComponentStaticID & p_componentID ) { - return _mapSerializer.at( p_componentID )( p_entity, MAIN_REGISTRY(), SERIALIZER() ); + return _mapSerializer.at( p_componentID )( p_entity, MAIN_REGISTRY(), SERIALIZATION_SYSTEM() ); } } // namespace VTX::App::Application::ECS diff --git a/lib/app/src/app/component/behaviour/molecule_behaviour.cpp b/lib/app/src/app/component/behaviour/molecule_behaviour.cpp index d515c907e..7cbea86fd 100644 --- a/lib/app/src/app/component/behaviour/molecule_behaviour.cpp +++ b/lib/app/src/app/component/behaviour/molecule_behaviour.cpp @@ -14,7 +14,7 @@ #include "app/core/player/players.hpp" #include "app/core/renderer/renderer_system.hpp" #include "app/internal/application/settings.hpp" -#include "app/internal/io/reader/molecule_loader.hpp" +#include "app/serialization/io/reader/molecule_loader.hpp" namespace VTX::App::Component::Behaviour { @@ -100,8 +100,8 @@ namespace VTX::App::Component::Behaviour return; } - Internal::IO::Reader::MoleculeLoader loader = Internal::IO::Reader::MoleculeLoader(); - const FilePath path = FilePath( filepathProperty->second.get() ); + Serialization::IO::Reader::MoleculeLoader loader = Serialization::IO::Reader::MoleculeLoader(); + const FilePath path = FilePath( filepathProperty->second.get() ); const Core::ECS::BaseEntity & entity = MAIN_REGISTRY().getEntity( _moleculeComponent ); Component::IO::MoleculeMetadata & metaData diff --git a/lib/app/src/app/internal/io/reader/scene_loader.cpp b/lib/app/src/app/internal/io/reader/scene_loader.cpp deleted file mode 100644 index 46b7485e9..000000000 --- a/lib/app/src/app/internal/io/reader/scene_loader.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "app/internal/io/reader/scene_loader.hpp" -#include "app/application/system/serializer.hpp" -#include "app/vtx_app.hpp" - -namespace VTX::App::Internal::IO::Reader -{ - void SceneLoader::readFile( const FilePath & p_path, App::Application::Scene & p_scene ) - { - SERIALIZER().readObject( p_path, p_scene ); - } - -} // namespace VTX::App::Internal::IO::Reader diff --git a/lib/app/src/app/internal/io/writer/scene_writer.cpp b/lib/app/src/app/internal/io/writer/scene_writer.cpp deleted file mode 100644 index e45b9d4ec..000000000 --- a/lib/app/src/app/internal/io/writer/scene_writer.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "app/internal/io/writer/scene_writer.hpp" -#include "app/application/scene.hpp" -#include "app/application/system/serializer.hpp" - -namespace VTX::App::Internal::IO::Writer -{ - void SceneWriter::writeFile( const FilePath & p_path, const App::Application::Scene & p_scene ) - { - SERIALIZER().writeObject( p_path, p_scene ); - } - -} // namespace VTX::App::Internal::IO::Writer diff --git a/lib/app/src/app/internal/serialization/app_serializers.cpp b/lib/app/src/app/serialization/app_serializers.cpp similarity index 64% rename from lib/app/src/app/internal/serialization/app_serializers.cpp rename to lib/app/src/app/serialization/app_serializers.cpp index c51b6abc8..cf49f1b81 100644 --- a/lib/app/src/app/internal/serialization/app_serializers.cpp +++ b/lib/app/src/app/serialization/app_serializers.cpp @@ -1,16 +1,16 @@ -#include "app/internal/serialization/app_serializers.hpp" +#include "app/serialization/app_serializers.hpp" #include "app/application/settings/base_setting.hpp" #include "app/application/settings/settings.hpp" -#include "app/application/system/serializer.hpp" #include "app/core/player/loop.hpp" #include "app/core/player/once.hpp" #include "app/core/player/ping_pong.hpp" #include "app/core/player/revert_loop.hpp" #include "app/core/player/revert_once.hpp" #include "app/core/player/stop.hpp" +#include "app/serialization/serialization_system.hpp" #include "app/vtx_app.hpp" -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Version Util::JSon::Object serialize( const App::Core::Serialization::Version & p_version ) @@ -19,9 +19,9 @@ namespace VTX::App::Internal::Serialization } void deserialize( const Util::JSon::Object & p_json, App::Core::Serialization::Version & p_version ) { - p_version.major = SERIALIZER().deserializeField( p_json, "MAJOR" ); - p_version.minor = SERIALIZER().deserializeField( p_json, "MINOR" ); - p_version.revision = SERIALIZER().deserializeField( p_json, "REVISION" ); + p_version.major = SERIALIZATION_SYSTEM().deserializeField( p_json, "MAJOR" ); + p_version.minor = SERIALIZATION_SYSTEM().deserializeField( p_json, "MINOR" ); + p_version.revision = SERIALIZATION_SYSTEM().deserializeField( p_json, "REVISION" ); } // VTX App @@ -88,64 +88,64 @@ namespace VTX::App::Internal::Serialization } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::BasePlayer & p_player ) { - p_player.setCount( SERIALIZER().deserializeField( p_json, "COUNT" ) ); - p_player.setCurrent( SERIALIZER().deserializeField( p_json, "CURRENT" ) ); - p_player.setFPS( SERIALIZER().deserializeField( p_json, "FPS" ) ); + p_player.setCount( SERIALIZATION_SYSTEM().deserializeField( p_json, "COUNT" ) ); + p_player.setCurrent( SERIALIZATION_SYSTEM().deserializeField( p_json, "CURRENT" ) ); + p_player.setFPS( SERIALIZATION_SYSTEM().deserializeField( p_json, "FPS" ) ); - if ( SERIALIZER().deserializeField( p_json, "IS_PLAYING", false ) ) + if ( SERIALIZATION_SYSTEM().deserializeField( p_json, "IS_PLAYING", false ) ) p_player.play(); } Util::JSon::Object serialize( const App::Core::Player::Stop & p_player ) { - return SERIALIZER().serialize( static_cast( p_player ) ); + return SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::Stop & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); } Util::JSon::Object serialize( const App::Core::Player::Loop & p_player ) { - return SERIALIZER().serialize( static_cast( p_player ) ); + return SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::Loop & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); } Util::JSon::Object serialize( const App::Core::Player::RevertLoop & p_player ) { - return SERIALIZER().serialize( static_cast( p_player ) ); + return SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::RevertLoop & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); } Util::JSon::Object serialize( const App::Core::Player::Once & p_player ) { - return SERIALIZER().serialize( static_cast( p_player ) ); + return SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::Once & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); } Util::JSon::Object serialize( const App::Core::Player::RevertOnce & p_player ) { - return SERIALIZER().serialize( static_cast( p_player ) ); + return SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::RevertOnce & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); } Util::JSon::Object serialize( const App::Core::Player::PingPong & p_player ) { Util::JSon::Object res - = SERIALIZER().serialize( static_cast( p_player ) ); + = SERIALIZATION_SYSTEM().serialize( static_cast( p_player ) ); res.appendField( "IS_PLAYING_FORWARD", p_player.isPlayingForward() ); return res; } void deserialize( const Util::JSon::Object & p_json, App::Core::Player::PingPong & p_player ) { - SERIALIZER().deserialize( p_json, static_cast( p_player ) ); - p_player.setPlayingForward( SERIALIZER().deserializeField( p_json, "IS_PLAYING_FORWARD" ) ); + SERIALIZATION_SYSTEM().deserialize( p_json, static_cast( p_player ) ); + p_player.setPlayingForward( SERIALIZATION_SYSTEM().deserializeField( p_json, "IS_PLAYING_FORWARD" ) ); } -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization diff --git a/lib/app/src/app/internal/io/reader/molecule_loader.cpp b/lib/app/src/app/serialization/io/reader/molecule_loader.cpp similarity index 90% rename from lib/app/src/app/internal/io/reader/molecule_loader.cpp rename to lib/app/src/app/serialization/io/reader/molecule_loader.cpp index 06c0a37c3..90b78b4d6 100644 --- a/lib/app/src/app/internal/io/reader/molecule_loader.cpp +++ b/lib/app/src/app/serialization/io/reader/molecule_loader.cpp @@ -1,4 +1,4 @@ -#include "app/internal/io/reader/molecule_loader.hpp" +#include "app/serialization/io/reader/molecule_loader.hpp" #include "app/component/chemistry/atom.hpp" #include "app/component/chemistry/bond.hpp" #include "app/component/chemistry/chain.hpp" @@ -18,7 +18,7 @@ #include #include -namespace VTX::App::Internal::IO::Reader +namespace VTX::App::Serialization::IO::Reader { namespace Core = VTX::Core; namespace ChemDB = VTX::Core::ChemDB; @@ -49,4 +49,4 @@ namespace VTX::App::Internal::IO::Reader p_molecule.setMoleculeStruct( moleculeStruct ); } -} // namespace VTX::App::Internal::IO::Reader +} // namespace VTX::App::Serialization::IO::Reader diff --git a/lib/app/src/app/serialization/io/reader/scene_loader.cpp b/lib/app/src/app/serialization/io/reader/scene_loader.cpp new file mode 100644 index 000000000..90a08cb8e --- /dev/null +++ b/lib/app/src/app/serialization/io/reader/scene_loader.cpp @@ -0,0 +1,12 @@ +#include "app/serialization/io/reader/scene_loader.hpp" +#include "app/serialization/serialization_system.hpp" +#include "app/vtx_app.hpp" + +namespace VTX::App::Serialization::IO::Reader +{ + void SceneLoader::readFile( const FilePath & p_path, App::Application::Scene & p_scene ) + { + SERIALIZATION_SYSTEM().readObject( p_path, p_scene ); + } + +} // namespace VTX::App::Serialization::IO::Reader diff --git a/lib/app/src/app/serialization/io/writer/scene_writer.cpp b/lib/app/src/app/serialization/io/writer/scene_writer.cpp new file mode 100644 index 000000000..a3457d741 --- /dev/null +++ b/lib/app/src/app/serialization/io/writer/scene_writer.cpp @@ -0,0 +1,12 @@ +#include "app/serialization/io/writer/scene_writer.hpp" +#include "app/application/scene.hpp" +#include "app/serialization/serialization_system.hpp" + +namespace VTX::App::Serialization::IO::Writer +{ + void SceneWriter::writeFile( const FilePath & p_path, const App::Application::Scene & p_scene ) + { + SERIALIZATION_SYSTEM().writeObject( p_path, p_scene ); + } + +} // namespace VTX::App::Serialization::IO::Writer diff --git a/lib/app/src/app/internal/serialization/scene_serializers.cpp b/lib/app/src/app/serialization/scene_serializers.cpp similarity index 67% rename from lib/app/src/app/internal/serialization/scene_serializers.cpp rename to lib/app/src/app/serialization/scene_serializers.cpp index dfde98eba..8d177b012 100644 --- a/lib/app/src/app/internal/serialization/scene_serializers.cpp +++ b/lib/app/src/app/serialization/scene_serializers.cpp @@ -1,7 +1,6 @@ -#include "app/internal/serialization/scene_serializers.hpp" +#include "app/serialization/scene_serializers.hpp" #include "app/application/ecs/component_meta_function.hpp" #include "app/application/scene.hpp" -#include "app/application/system/serializer.hpp" #include "app/component/chemistry/molecule.hpp" #include "app/component/chemistry/trajectory.hpp" #include "app/component/ecs/entity_info.hpp" @@ -12,12 +11,13 @@ #include "app/core/ecs/base_entity.hpp" #include "app/core/player/base_player.hpp" #include "app/core/player/players.hpp" -#include "app/internal/io/reader/molecule_loader.hpp" +#include "app/serialization/io/reader/molecule_loader.hpp" +#include "app/serialization/serialization_system.hpp" #include #include #include -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Scene Util::JSon::Object serialize( const Application::Scene & p_scene ) @@ -43,17 +43,19 @@ namespace VTX::App::Internal::Serialization entities.emplace_back( jsonComponents ); } - return { { "CAMERA_POSITION", SERIALIZER().serialize( p_scene.getCamera().getTransform().getPosition() ) }, - { "CAMERA_ROTATION", SERIALIZER().serialize( p_scene.getCamera().getTransform().getRotation() ) }, - { "ENTITIES", entities } }; + return { + { "CAMERA_POSITION", SERIALIZATION_SYSTEM().serialize( p_scene.getCamera().getTransform().getPosition() ) }, + { "CAMERA_ROTATION", SERIALIZATION_SYSTEM().serialize( p_scene.getCamera().getTransform().getRotation() ) }, + { "ENTITIES", entities } + }; } void deserialize( const Util::JSon::Object & p_json, Application::Scene & p_scene ) { p_scene.getCamera().getTransform().setPosition( - SERIALIZER().deserializeField( p_json, "CAMERA_POSITION" ) + SERIALIZATION_SYSTEM().deserializeField( p_json, "CAMERA_POSITION" ) ); p_scene.getCamera().getTransform().setRotation( - SERIALIZER().deserializeField( p_json, "CAMERA_ROTATION" ) + SERIALIZATION_SYSTEM().deserializeField( p_json, "CAMERA_ROTATION" ) ); const Util::JSon::Array & items = p_json[ "ENTITIES" ]; @@ -67,7 +69,7 @@ namespace VTX::App::Internal::Serialization for ( const Util::JSon::Object & component : componentsArray ) { const Application::ECS::ComponentStaticID componentID - = SERIALIZER().deserializeField( component, "ID" ); + = SERIALIZATION_SYSTEM().deserializeField( component, "ID" ); const Util::JSon::Object & componentData = component[ "DATA" ]; COMPONENT_META_FUNCTION().deserializeComponent( componentID, entity, componentData ); @@ -84,29 +86,31 @@ namespace VTX::App::Internal::Serialization } void deserialize( const Util::JSon::Object & p_json, Component::Scene::SceneItemComponent & p_component ) { - p_component.setName( SERIALIZER().deserializeField( p_json, "NAME" ) ); + p_component.setName( SERIALIZATION_SYSTEM().deserializeField( p_json, "NAME" ) ); } // Chemistry::MoleculeComponent Util::JSon::Object serialize( const Component::Chemistry::Molecule & p_component ) { return { { "PDB_ID", p_component.getPdbIdCode() }, - { "TRANSFORM", SERIALIZER().serialize( p_component.getTransform() ) } }; + { "TRANSFORM", SERIALIZATION_SYSTEM().serialize( p_component.getTransform() ) } }; } void deserialize( const Util::JSon::Object & p_json, Component::Chemistry::Molecule & p_component ) { - p_component.setPdbIdCode( SERIALIZER().deserializeField( p_json, "PDB_ID" ) ); - SERIALIZER().deserialize( p_json[ "TRANSFORM" ], p_component.getTransform() ); + p_component.setPdbIdCode( SERIALIZATION_SYSTEM().deserializeField( p_json, "PDB_ID" ) ); + SERIALIZATION_SYSTEM().deserialize( p_json[ "TRANSFORM" ], p_component.getTransform() ); } // TransformComponent Util::JSon::Object serialize( const Component::Scene::Transform & p_component ) { - return { { "TRANSFORM", SERIALIZER().serialize( p_component.getTransform() ) } }; + return { { "TRANSFORM", SERIALIZATION_SYSTEM().serialize( p_component.getTransform() ) } }; } void deserialize( const Util::JSon::Object & p_json, Component::Scene::Transform & p_component ) { - p_component.applyTransform( SERIALIZER().deserializeField( p_json, "TRANSFORM" ) ); + p_component.applyTransform( + SERIALIZATION_SYSTEM().deserializeField( p_json, "TRANSFORM" ) + ); } // MoleculeMetadata @@ -115,20 +119,21 @@ namespace VTX::App::Internal::Serialization const Component::Chemistry::Molecule & moleculeComponent = MAIN_REGISTRY().getComponent( MAIN_REGISTRY().getEntity( p_component ) ); - return { { "PATH", SERIALIZER().serialize( p_component.path ) }, + return { { "PATH", SERIALIZATION_SYSTEM().serialize( p_component.path ) }, { "PDB_ID", p_component.pdbIDCode }, { "SECONDARY_STRUCTURE_FROM_FILE", p_component.isSecondaryStructureLoadedFromFile }, - { "VISIBILITY", SERIALIZER().serialize( moleculeComponent.getAtomVisibilities() ) } }; + { "VISIBILITY", SERIALIZATION_SYSTEM().serialize( moleculeComponent.getAtomVisibilities() ) } }; } void deserialize( const Util::JSon::Object & p_json, Component::IO::MoleculeMetadata & p_component ) { - p_component.path = SERIALIZER().deserializeField( p_json, "PATH" ); - p_component.pdbIDCode = SERIALIZER().deserializeField( p_json, "PDB_ID", p_component.pdbIDCode ); + p_component.path = SERIALIZATION_SYSTEM().deserializeField( p_json, "PATH" ); + p_component.pdbIDCode + = SERIALIZATION_SYSTEM().deserializeField( p_json, "PDB_ID", p_component.pdbIDCode ); p_component.isSecondaryStructureLoadedFromFile - = SERIALIZER().deserializeField( p_json, "SECONDARY_STRUCTURE_FROM_FILE", false ); + = SERIALIZATION_SYSTEM().deserializeField( p_json, "SECONDARY_STRUCTURE_FROM_FILE", false ); - Internal::IO::Reader::MoleculeLoader loader = Internal::IO::Reader::MoleculeLoader(); - const FilePath path = FilePath( p_component.path ); + Serialization::IO::Reader::MoleculeLoader loader = Serialization::IO::Reader::MoleculeLoader(); + const FilePath path = FilePath( p_component.path ); Component::Chemistry::Molecule & moleculeComponent = MAIN_REGISTRY().getComponent( MAIN_REGISTRY().getEntity( p_component ) ); @@ -136,7 +141,7 @@ namespace VTX::App::Internal::Serialization loader.readFile( path, moleculeComponent ); const Component::Chemistry::AtomIndexRangeList visibilities - = SERIALIZER().deserializeField( p_json, "VISIBILITY" ); + = SERIALIZATION_SYSTEM().deserializeField( p_json, "VISIBILITY" ); moleculeComponent.setAtomVisibilities( visibilities ); } @@ -151,7 +156,7 @@ namespace VTX::App::Internal::Serialization void deserialize( const Util::JSon::Object & p_json, Component::Chemistry::Trajectory & p_component ) { - const std::string playerName = SERIALIZER().deserializeField( p_json, "PLAYER_NAME" ); + const std::string playerName = SERIALIZATION_SYSTEM().deserializeField( p_json, "PLAYER_NAME" ); if ( playerName.empty() ) { @@ -165,6 +170,6 @@ namespace VTX::App::Internal::Serialization // ); // p_component.setPlayer( playerPtr ); - SERIALIZER().deserialize( p_json[ "PLAYER_DATA" ], p_component.getPlayer() ); + SERIALIZATION_SYSTEM().deserialize( p_json[ "PLAYER_DATA" ], p_component.getPlayer() ); } -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization diff --git a/lib/app/src/app/internal/serialization/util_serializers.cpp b/lib/app/src/app/serialization/util_serializers.cpp similarity index 56% rename from lib/app/src/app/internal/serialization/util_serializers.cpp rename to lib/app/src/app/serialization/util_serializers.cpp index 54dc40039..9fb8e9246 100644 --- a/lib/app/src/app/internal/serialization/util_serializers.cpp +++ b/lib/app/src/app/serialization/util_serializers.cpp @@ -1,7 +1,7 @@ -#include "app/internal/serialization/util_serializers.hpp" -#include "app/application/system/serializer.hpp" +#include "app/serialization/util_serializers.hpp" +#include "app/serialization/serialization_system.hpp" -namespace VTX::App::Internal::Serialization +namespace VTX::App::Serialization { // Filesystem std::string serialize( const FilePath & p_filepath ) { return p_filepath.string(); } @@ -14,10 +14,10 @@ namespace VTX::App::Internal::Serialization } void deserialize( const Util::JSon::Object & p_json, Util::Color::Rgba & p_color ) { - p_color.setR( SERIALIZER().deserializeField( p_json, "R", 0.f ) ); - p_color.setG( SERIALIZER().deserializeField( p_json, "G", 0.f ) ); - p_color.setB( SERIALIZER().deserializeField( p_json, "B", 0.f ) ); - p_color.setA( SERIALIZER().deserializeField( p_json, "A", 1.f ) ); + p_color.setR( SERIALIZATION_SYSTEM().deserializeField( p_json, "R", 0.f ) ); + p_color.setG( SERIALIZATION_SYSTEM().deserializeField( p_json, "G", 0.f ) ); + p_color.setB( SERIALIZATION_SYSTEM().deserializeField( p_json, "B", 0.f ) ); + p_color.setA( SERIALIZATION_SYSTEM().deserializeField( p_json, "A", 1.f ) ); } // Math - Transform @@ -29,13 +29,13 @@ namespace VTX::App::Internal::Serialization } void deserialize( const Util::JSon::Object & p_json, Util::Math::Transform & p_transform ) { - const Vec3f position = SERIALIZER().deserializeField( p_json, "POSITION", VEC3F_ZERO ); + const Vec3f position = SERIALIZATION_SYSTEM().deserializeField( p_json, "POSITION", VEC3F_ZERO ); p_transform.setTranslation( position ); - const Vec3f euler = SERIALIZER().deserializeField( p_json, "ROTATION", VEC3F_ZERO ); + const Vec3f euler = SERIALIZATION_SYSTEM().deserializeField( p_json, "ROTATION", VEC3F_ZERO ); p_transform.setRotation( euler ); - const Vec3f scale = SERIALIZER().deserializeField( p_json, "SCALE", VEC3F_XYZ ); + const Vec3f scale = SERIALIZATION_SYSTEM().deserializeField( p_json, "SCALE", VEC3F_XYZ ); p_transform.setScale( scale ); } -} // namespace VTX::App::Internal::Serialization +} // namespace VTX::App::Serialization diff --git a/lib/app/src/app/vtx_app.cpp b/lib/app/src/app/vtx_app.cpp index 6f18ad515..43a156fd8 100644 --- a/lib/app/src/app/vtx_app.cpp +++ b/lib/app/src/app/vtx_app.cpp @@ -18,7 +18,6 @@ #include "app/core/ecs/registry.hpp" #include "app/core/mode/mode_system.hpp" #include "app/core/renderer/renderer_system.hpp" -#include "app/core/serialization/serialization.hpp" #include "app/core/threading/base_thread.hpp" #include "app/core/threading/threading_system.hpp" #include "app/entity/all_entities.hpp" @@ -27,7 +26,6 @@ #include "app/internal/application/settings.hpp" #include "app/internal/ecs/setup_entity_director.hpp" #include "app/internal/monitoring/all_metrics.hpp" -#include "app/internal/serialization/all_serializers.hpp" #include "app/mode/visualization.hpp" #include #include @@ -60,7 +58,7 @@ namespace VTX::App // Register loop events. onUpdate += []( const float p_deltaTime, const float p_elapsedTime ) { SCENE().update( p_elapsedTime ); }; - onPostUpdate += []( const float p_elapsedTime ) { THREADING().lateUpdate(); }; + onPostUpdate += []( const float p_elapsedTime ) { THREADING_SYSTEM().lateUpdate(); }; // TODO: remove polymorphism. onUpdate += []( const float p_deltaTime, const float p_elapsedTime ) { ANIMATION_SYSTEM().update( p_deltaTime ); }; diff --git a/lib/app/test/serialization.cpp b/lib/app/test/serialization.cpp index 6d0899d1f..4b63a44b9 100644 --- a/lib/app/test/serialization.cpp +++ b/lib/app/test/serialization.cpp @@ -6,12 +6,10 @@ #include #include #include -#include -#include -#include #include #include #include +#include #include #include #include @@ -169,13 +167,13 @@ TEST_CASE( "VTX_APP - Serialization - Custom Obj", "[unit]" ) App::Fixture app; - SERIALIZER().registerSerializationFunction( &CustomClass::serialize ); - SERIALIZER().registerDeserializationFunction( &CustomClass::deserialize ); + SERIALIZATION_SYSTEM().registerSerializationFunction( &CustomClass::serialize ); + SERIALIZATION_SYSTEM().registerDeserializationFunction( &CustomClass::deserialize ); const CustomClass custom = CustomClass( COLOR_BLUE, "strValue", 42, { 1.f, 2.f, 3.f }, CustomClass::CustomEnum::TWO ); - const VTX::Util::JSon::Document jsonDoc = { { "CUSTOM_CLASS", SERIALIZER().serialize( custom ) } }; + const VTX::Util::JSon::Document jsonDoc = { { "CUSTOM_CLASS", SERIALIZATION_SYSTEM().serialize( custom ) } }; REQUIRE( jsonDoc.json().contains( "CUSTOM_CLASS" ) ); REQUIRE( jsonDoc.json()[ "CUSTOM_CLASS" ].contains( "COLOR" ) ); @@ -204,21 +202,21 @@ TEST_CASE( "VTX_APP - Serialization - Read&Write", "[unit]" ) App::Fixture app; - SERIALIZER().registerSerializationFunction( &CustomClass::serialize ); - SERIALIZER().registerDeserializationFunction( &CustomClass::deserialize ); + SERIALIZATION_SYSTEM().registerSerializationFunction( &CustomClass::serialize ); + SERIALIZATION_SYSTEM().registerDeserializationFunction( &CustomClass::deserialize ); const CustomClass custom = CustomClass( COLOR_BLUE, "strValue", 42, { 1.f, 2.f, 3.f }, CustomClass::CustomEnum::TWO ); const FilePath jsonPath = Util::Filesystem::getExecutableDir() / "data/serialization/jsonTest.json"; - SERIALIZER().writeObject( jsonPath, custom ); + SERIALIZATION_SYSTEM().writeObject( jsonPath, custom ); REQUIRE( std::filesystem::exists( jsonPath ) ); CustomClass loadedCustom = CustomClass(); CHECK( custom != loadedCustom ); - SERIALIZER().readObject( jsonPath, loadedCustom ); + SERIALIZATION_SYSTEM().readObject( jsonPath, loadedCustom ); CHECK( custom == loadedCustom ); } @@ -340,8 +338,8 @@ TEST_CASE( "VTX_APP - Serialization - Settings", "[unit]" ) App::Fixture app; - SERIALIZER().registerSerializationFunction( &CustomClass::serialize ); - SERIALIZER().registerDeserializationFunction( &CustomClass::deserialize ); + SERIALIZATION_SYSTEM().registerSerializationFunction( &CustomClass::serialize ); + SERIALIZATION_SYSTEM().registerDeserializationFunction( &CustomClass::deserialize ); App::Application::Settings::Settings settings = App::Application::Settings::Settings(); @@ -372,7 +370,7 @@ TEST_CASE( "VTX_APP - Serialization - Settings", "[unit]" ) CHECK( settings.get( "VEC3F_SETTING" ) == VEC3F_Z ); CHECK( settings.get( "CUSTOM_CLASS_SETTING" ) == newCustomClass ); - const Util::JSon::BasicJSon json = SERIALIZER().serialize( settings ); + const Util::JSon::BasicJSon json = SERIALIZATION_SYSTEM().serialize( settings ); settings.reset(); @@ -382,7 +380,7 @@ TEST_CASE( "VTX_APP - Serialization - Settings", "[unit]" ) CHECK( settings.get( "VEC3F_SETTING" ) == VEC3F_ZERO ); CHECK( settings.get( "CUSTOM_CLASS_SETTING" ) == defaultCustomClass ); - SERIALIZER().deserialize( json, settings ); + SERIALIZATION_SYSTEM().deserialize( json, settings ); CHECK( settings.get( "INT_SETTING" ) == 10 ); CHECK( settings.get( "FLOAT_SETTING" ) == 10.f ); @@ -405,7 +403,7 @@ TEST_CASE( "VTX_APP - Serialization - Settings", "[unit]" ) const FilePath jsonPath_0_0_0 = Util::Filesystem::getExecutableDir() / "data/serialization/json_settings_0_0_0.json"; - App::Core::IO::Reader::SerializedObject reader = { SERIALIZER(), jsonPath_0_0_0, &settingsV1 }; + App::Serialization::SerializationSystem::Reader reader = { SERIALIZATION_SYSTEM(), jsonPath_0_0_0, &settingsV1 }; reader.read(); CHECK( settingsV1.get( "SETTING_1" ) == 10 ); // Loaded @@ -413,7 +411,7 @@ TEST_CASE( "VTX_APP - Serialization - Settings", "[unit]" ) CHECK( settingsV1.get( "SETTING_3" ) == 0.f ); // Don't change (type issue) CHECK( settingsV1.get( "SETTING_4" ) == "" ); // Don't change (doesn't exists before) - SERIALIZER().registerUpgrade( + SERIALIZATION_SYSTEM().registerUpgrade( { 1, 0, 0 }, []( Util::JSon::Object & p_json, App::Application::Settings::Settings & p_settings ) { p_json[ "MAP" ][ "SETTING_3" ] = 12.f; } @@ -433,11 +431,11 @@ TEST_CASE( "VTX_APP - Serialization - Upgrade", "[unit]" ) App::Fixture app; - SERIALIZER().registerSerializationFunction( &CustomClass::serialize ); - SERIALIZER().registerDeserializationFunction( &CustomClass::deserialize ); + SERIALIZATION_SYSTEM().registerSerializationFunction( &CustomClass::serialize ); + SERIALIZATION_SYSTEM().registerDeserializationFunction( &CustomClass::deserialize ); - SERIALIZER().registerUpgrade( { 0, 1, 0 }, &CustomClass::upgrade_0_0_0_to_0_1_0 ); - SERIALIZER().registerUpgrade( { 1, 0, 0 }, &CustomClass::upgrade_0_1_0_to_1_0_0 ); + SERIALIZATION_SYSTEM().registerUpgrade( { 0, 1, 0 }, &CustomClass::upgrade_0_0_0_to_0_1_0 ); + SERIALIZATION_SYSTEM().registerUpgrade( { 1, 0, 0 }, &CustomClass::upgrade_0_1_0_to_1_0_0 ); const CustomClass custom = CustomClass( COLOR_BLUE, "strValue", 42, { 1.f, 2.f, 3.f }, CustomClass::CustomEnum::TWO ); @@ -445,14 +443,14 @@ TEST_CASE( "VTX_APP - Serialization - Upgrade", "[unit]" ) const FilePath jsonPath_0_1_0 = Util::Filesystem::getExecutableDir() / "data/serialization/jsonTest_0_1_0.json"; CustomClass loadedCustom_0_1_0 = CustomClass(); - SERIALIZER().readObject( jsonPath_0_1_0, loadedCustom_0_1_0 ); + SERIALIZATION_SYSTEM().readObject( jsonPath_0_1_0, loadedCustom_0_1_0 ); CHECK( custom == loadedCustom_0_1_0 ); const FilePath jsonPath_0_0_0 = Util::Filesystem::getExecutableDir() / "data/serialization/jsonTest_0_0_0.json"; CustomClass loadedCustom_0_0_0 = CustomClass(); - SERIALIZER().readObject( jsonPath_0_0_0, loadedCustom_0_0_0 ); + SERIALIZATION_SYSTEM().readObject( jsonPath_0_0_0, loadedCustom_0_0_0 ); CHECK( loadedCustom_0_0_0.color == custom.color ); CHECK( loadedCustom_0_0_0.enumValue == custom.enumValue ); @@ -463,7 +461,7 @@ TEST_CASE( "VTX_APP - Serialization - Upgrade", "[unit]" ) try { - SERIALIZER().readObject( jsonPath_0_0_0, loadedCustom_0_0_0 ); + SERIALIZATION_SYSTEM().readObject( jsonPath_0_0_0, loadedCustom_0_0_0 ); } catch ( const IOException & ) { diff --git a/lib/app/test/util/serialization.hpp b/lib/app/test/util/serialization.hpp index 5ebb92e3b..2f5244d5f 100644 --- a/lib/app/test/util/serialization.hpp +++ b/lib/app/test/util/serialization.hpp @@ -1,9 +1,8 @@ #ifndef __VTX_APP_TEST_UTIL_SERIALIZATION__ #define __VTX_APP_TEST_UTIL_SERIALIZATION__ -#include -#include #include +#include #include #include #include @@ -33,9 +32,7 @@ namespace VTX::App::Test::Util::Serialization const int p_intValue, const Vec3f & p_vector, CustomEnum p_enum - ) : - color( p_color ), - strValue( p_strValue ), intValue( p_intValue ), vector( p_vector ), enumValue( p_enum ) + ) : color( p_color ), strValue( p_strValue ), intValue( p_intValue ), vector( p_vector ), enumValue( p_enum ) { } @@ -58,19 +55,19 @@ namespace VTX::App::Test::Util::Serialization static VTX::Util::JSon::Object serialize( const CustomClass & p_obj ) { - return { { "COLOR", SERIALIZER().serialize( p_obj.color ) }, - { "STR", SERIALIZER().serialize( p_obj.strValue ) }, - { "INT", SERIALIZER().serialize( p_obj.intValue ) }, - { "VEC", SERIALIZER().serialize( p_obj.vector ) }, - { "ENUM", SERIALIZER().serialize( p_obj.enumValue ) } }; + return { { "COLOR", SERIALIZATION_SYSTEM().serialize( p_obj.color ) }, + { "STR", SERIALIZATION_SYSTEM().serialize( p_obj.strValue ) }, + { "INT", SERIALIZATION_SYSTEM().serialize( p_obj.intValue ) }, + { "VEC", SERIALIZATION_SYSTEM().serialize( p_obj.vector ) }, + { "ENUM", SERIALIZATION_SYSTEM().serialize( p_obj.enumValue ) } }; } static void deserialize( const VTX::Util::JSon::Object & p_jsonObj, CustomClass & p_obj ) { - p_obj.color = SERIALIZER().deserializeField( p_jsonObj, "COLOR", COLOR_BLACK ); - p_obj.strValue = SERIALIZER().deserializeField( p_jsonObj, "STR", std::string( "Default" ) ); - p_obj.intValue = SERIALIZER().deserializeField( p_jsonObj, "INT", 10 ); - p_obj.vector = SERIALIZER().deserializeField( p_jsonObj, "VEC", VEC3F_ZERO ); - p_obj.enumValue = SERIALIZER().deserializeField( p_jsonObj, "ENUM", CustomEnum::ONE ); + p_obj.color = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "COLOR", COLOR_BLACK ); + p_obj.strValue = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "STR", std::string( "Default" ) ); + p_obj.intValue = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "INT", 10 ); + p_obj.vector = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "VEC", VEC3F_ZERO ); + p_obj.enumValue = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "ENUM", CustomEnum::ONE ); } static void upgrade_0_1_0_to_1_0_0( VTX::Util::JSon::Object & p_jsonObj, CustomClass & p_obj ) @@ -97,11 +94,11 @@ namespace VTX::App::Test::Util::Serialization // Manage type change const std::string oldVecStr - = SERIALIZER().deserializeField( p_jsonObj, "OLD_NAME_VEC", std::string( "" ) ); + = SERIALIZATION_SYSTEM().deserializeField( p_jsonObj, "OLD_NAME_VEC", std::string( "" ) ); if ( oldVecStr == "Was a string before" ) { const Vec3f convertedVector = { 1.f, 2.f, 3.f }; - p_jsonObj[ "OLD_NAME_VEC" ] = SERIALIZER().serialize( convertedVector ); + p_jsonObj[ "OLD_NAME_VEC" ] = SERIALIZATION_SYSTEM().serialize( convertedVector ); } // Rename VERY_OLD_UNKNOWN_FIELD @@ -114,10 +111,10 @@ namespace VTX::App::Test::Util::Serialization template bool checkSerialization( const T & p_obj ) { - const VTX::Util::JSon::BasicJSon & json = SERIALIZER().serialize( p_obj ); + const VTX::Util::JSon::BasicJSon & json = SERIALIZATION_SYSTEM().serialize( p_obj ); T deserializedObj; - SERIALIZER().deserialize( json, deserializedObj ); + SERIALIZATION_SYSTEM().deserialize( json, deserializedObj ); return p_obj == deserializedObj; } @@ -128,10 +125,10 @@ namespace VTX::App::Test::Util::Serialization template bool checkSerialization( const T & p_obj, const ComparisonFunction & p_comparisonFunction ) { - const VTX::Util::JSon::BasicJSon & json = SERIALIZER().serialize( p_obj ); + const VTX::Util::JSon::BasicJSon & json = SERIALIZATION_SYSTEM().serialize( p_obj ); T deserializedObj; - SERIALIZER().deserialize( json, deserializedObj ); + SERIALIZATION_SYSTEM().deserialize( json, deserializedObj ); return p_comparisonFunction( p_obj, deserializedObj ); } diff --git a/lib/app/test/workers.cpp b/lib/app/test/workers.cpp index d862219a1..f6cb59de1 100644 --- a/lib/app/test/workers.cpp +++ b/lib/app/test/workers.cpp @@ -31,7 +31,7 @@ TEST_CASE( "VTX_APP - Workers", "[integration]" ) return 1; }; - Core::Threading::BaseThread & thread = THREADING().createThread( + Core::Threading::BaseThread & thread = THREADING_SYSTEM().createThread( asyncOp, []( Core::Threading::BaseThread & p_thread, uint p_res ) { @@ -51,7 +51,7 @@ TEST_CASE( "VTX_APP - Workers", "[integration]" ) lastProgress = p_progress; }; - Core::Threading::BaseThread & threadToWait = THREADING().createThread( asyncOp ); + Core::Threading::BaseThread & threadToWait = THREADING_SYSTEM().createThread( asyncOp ); CHECK( !threadToWait.isFinished() ); Util::Chrono chrono = Util::Chrono(); @@ -61,7 +61,7 @@ TEST_CASE( "VTX_APP - Workers", "[integration]" ) CHECK( threadToWait.isFinished() ); CHECK( chrono.elapsedTime() > 1.3f ); // Ensure wait sufficient time (sleep_for not really accurate). - Core::Threading::BaseThread & threadToStop = THREADING().createThread( asyncOp ); + Core::Threading::BaseThread & threadToStop = THREADING_SYSTEM().createThread( asyncOp ); CHECK( !threadToStop.isFinished() ); chrono.start();