mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	Added POD serialization
This commit is contained in:
		
							parent
							
								
									6940c99ed6
								
							
						
					
					
						commit
						dc04774ece
					
				
					 8 changed files with 68 additions and 20 deletions
				
			
		|  | @ -84,6 +84,7 @@ add_library(common STATIC | |||
|     misc.cpp | ||||
|     param_package.cpp | ||||
|     param_package.h | ||||
|     pod.h | ||||
|     quaternion.h | ||||
|     ring_buffer.h | ||||
|     scm_rev.cpp | ||||
|  |  | |||
							
								
								
									
										20
									
								
								src/common/pod.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/common/pod.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | |||
| #include "boost/serialization/split_member.hpp" | ||||
| 
 | ||||
| #define SERIALIZE_AS_POD                                             \ | ||||
|     private:                                                         \ | ||||
|     friend class boost::serialization::access;                       \ | ||||
|     template<typename Archive>                                       \ | ||||
|     void save(Archive & ar, const unsigned int file_version) const { \ | ||||
|         ar.save_binary(this, sizeof(*this));                         \ | ||||
|     }                                                                \ | ||||
|     template<typename Archive>                                       \ | ||||
|     void load(Archive & ar, const unsigned int file_version) {       \ | ||||
|         ar.load_binary(this, sizeof(*this));                         \ | ||||
|     }                                                                \ | ||||
|     template<class Archive>                                          \ | ||||
|     void serialize(                                                  \ | ||||
|         Archive &ar,                                                 \ | ||||
|         const unsigned int file_version                              \ | ||||
|     ){                                                               \ | ||||
|         boost::serialization::split_member(ar, *this, file_version); \ | ||||
|     } | ||||
|  | @ -15,6 +15,7 @@ | |||
| #include "core/memory.h" | ||||
| #include "core/perf_stats.h" | ||||
| #include "core/telemetry_session.h" | ||||
| class boost::serialization::access; | ||||
| 
 | ||||
| class ARM_Interface; | ||||
| 
 | ||||
|  | @ -338,6 +339,14 @@ private: | |||
| 
 | ||||
|     std::atomic<bool> reset_requested; | ||||
|     std::atomic<bool> shutdown_requested; | ||||
| 
 | ||||
|     friend class boost::serialization::access; | ||||
|     template<typename Archive> | ||||
|     void serialize(Archive & ar, const unsigned int file_version) | ||||
|     { | ||||
|         ar & GPU::g_regs; | ||||
|         ar & LCD::g_regs; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| inline ARM_Interface& CPU() { | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ | |||
| #include "common/bit_field.h" | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/pod.h" | ||||
| 
 | ||||
| // All the constants in this file come from http://3dbrew.org/wiki/Error_codes
 | ||||
| 
 | ||||
|  | @ -225,6 +226,8 @@ union ResultCode { | |||
|     constexpr bool IsError() const { | ||||
|         return is_error.ExtractValue(raw) == 1; | ||||
|     } | ||||
| 
 | ||||
|     SERIALIZE_AS_POD | ||||
| }; | ||||
| 
 | ||||
| constexpr bool operator==(const ResultCode& a, const ResultCode& b) { | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ | |||
| #include "common/bit_field.h" | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/pod.h" | ||||
| 
 | ||||
| namespace Memory { | ||||
| class MemorySystem; | ||||
|  | @ -296,6 +297,8 @@ private: | |||
|     static inline u32 DecodeAddressRegister(u32 register_value) { | ||||
|         return register_value * 8; | ||||
|     } | ||||
| 
 | ||||
|     SERIALIZE_AS_POD | ||||
| }; | ||||
| static_assert(std::is_standard_layout<Regs>::value, "Structure does not use standard layout"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ | |||
| #include "common/bit_field.h" | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/pod.h" | ||||
| 
 | ||||
| #define LCD_REG_INDEX(field_name) (offsetof(LCD::Regs, field_name) / sizeof(u32)) | ||||
| 
 | ||||
|  | @ -50,6 +51,8 @@ struct Regs { | |||
|         u32* content = reinterpret_cast<u32*>(this); | ||||
|         return content[index]; | ||||
|     } | ||||
| 
 | ||||
|     SERIALIZE_AS_POD | ||||
| }; | ||||
| static_assert(std::is_standard_layout<Regs>::value, "Structure does not use standard layout"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,7 +4,8 @@ | |||
| 
 | ||||
| #include <array> | ||||
| #include <cstring> | ||||
| #include "boost/serialization/split_member.hpp" | ||||
| #include "boost/serialization/array.hpp" | ||||
| #include "boost/serialization/nvp.hpp" | ||||
| #include "audio_core/dsp_interface.h" | ||||
| #include "common/archives.h" | ||||
| #include "common/assert.h" | ||||
|  | @ -54,6 +55,16 @@ private: | |||
|     std::array<bool, VRAM_SIZE / PAGE_SIZE> vram{}; | ||||
|     std::array<bool, LINEAR_HEAP_SIZE / PAGE_SIZE> linear_heap{}; | ||||
|     std::array<bool, NEW_LINEAR_HEAP_SIZE / PAGE_SIZE> new_linear_heap{}; | ||||
| 
 | ||||
|     static_assert(sizeof(bool) == 1); // TODO: Maybe this isn't true?
 | ||||
|     friend class boost::serialization::access; | ||||
|     template<typename Archive> | ||||
|     void serialize(Archive & ar, const unsigned int file_version) | ||||
|     { | ||||
|         ar & vram; | ||||
|         ar & linear_heap; | ||||
|         ar & new_linear_heap; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| class MemorySystem::Impl { | ||||
|  | @ -71,31 +82,29 @@ public: | |||
|     AudioCore::DspInterface* dsp = nullptr; | ||||
| 
 | ||||
| private: | ||||
| 
 | ||||
|     template<class Archive> | ||||
|     void add_blob(Archive & ar, std::unique_ptr<u8[]> & var, const char *name, std::size_t size) | ||||
|     { | ||||
|         ar & boost::serialization::make_nvp( | ||||
|             name, | ||||
|             *static_cast<u8 (*)[Memory::FCRAM_N3DS_SIZE]>(static_cast<void *>(var.get())) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     friend class boost::serialization::access; | ||||
|     template<class Archive> | ||||
|     void save(Archive & ar, const unsigned int file_version) const | ||||
|     void serialize(Archive & ar, const unsigned int file_version) | ||||
|     { | ||||
|         // TODO: Skip n3ds ram when not used?
 | ||||
|         ar.save_binary(fcram.get(), Memory::FCRAM_N3DS_SIZE); | ||||
|         ar.save_binary(vram.get(), Memory::VRAM_SIZE); | ||||
|         ar.save_binary(n3ds_extra_ram.get(), Memory::N3DS_EXTRA_RAM_SIZE); | ||||
|         // ar & cache_marker;
 | ||||
|         add_blob(ar, fcram, "fcram", Memory::FCRAM_N3DS_SIZE); | ||||
|         add_blob(ar, vram, "vram", Memory::VRAM_SIZE); | ||||
|         add_blob(ar, n3ds_extra_ram, "n3ds_extra_ram", Memory::N3DS_EXTRA_RAM_SIZE); | ||||
|         ar & cache_marker; | ||||
|         // TODO: How the hell to do page tables..
 | ||||
|         // ar & page_table_list;
 | ||||
|         // ar & current_page_table;
 | ||||
|     } | ||||
| 
 | ||||
|     template<class Archive> | ||||
|     void load(Archive & ar, const unsigned int file_version) | ||||
|     { | ||||
|         ar.load_binary(fcram.get(), Memory::FCRAM_N3DS_SIZE); | ||||
|         ar.load_binary(vram.get(), Memory::VRAM_SIZE); | ||||
|         ar.load_binary(n3ds_extra_ram.get(), Memory::N3DS_EXTRA_RAM_SIZE); | ||||
|         // ar & cache_marker;
 | ||||
|         // ar & page_table_list;
 | ||||
|         // ar & current_page_table;
 | ||||
|     } | ||||
| 
 | ||||
|     BOOST_SERIALIZATION_SPLIT_MEMBER() | ||||
| }; | ||||
| 
 | ||||
| SERIALIZE_IMPL(MemorySystem::Impl) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue