MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ToBytes

Method ToBytes

Source/Engine/Level/Actor.cpp:1786–1842  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1784}
1785
1786bool Actor::ToBytes(const Array<Actor*>& actors, MemoryWriteStream& output)
1787{
1788 if (actors.IsEmpty())
1789 {
1790 // Cannot serialize empty list
1791 return true;
1792 }
1793 PROFILE_CPU();
1794 PROFILE_MEM(Level);
1795
1796 // Collect object ids that exist in the serialized data to allow references mapping later
1797 Array<Guid> ids(actors.Count());
1798 for (int32 i = 0; i < actors.Count(); i++)
1799 {
1800 auto actor = actors[i];
1801 if (!actor)
1802 continue;
1803 ids.Add(actor->GetID());
1804 for (int32 j = 0; j < actor->Scripts.Count(); j++)
1805 {
1806 const auto script = actor->Scripts[j];
1807 if (script)
1808 ids.Add(script->GetID());
1809 }
1810 }
1811
1812 // Header
1813 output.WriteInt32(FLAXENGINE_VERSION_BUILD);
1814
1815 // Serialized objects ids (for references mapping)
1816 output.Write(ids);
1817
1818 // Objects data (JSON)
1819 rapidjson_flax::StringBuffer buffer;
1820 CompactJsonWriter writer(buffer);
1821 writer.StartArray();
1822 for (int32 i = 0; i < actors.Count(); i++)
1823 {
1824 Actor* actor = actors[i];
1825 if (!actor)
1826 continue;
1827 writer.SceneObject(actor);
1828 for (int32 j = 0; j < actor->Scripts.Count(); j++)
1829 {
1830 Script* script = actor->Scripts[j];
1831 if (!script)
1832 continue;
1833 writer.SceneObject(script);
1834 }
1835 }
1836 writer.EndArray();
1837 // TODO: compress json (LZ4) if it's big enough
1838 output.WriteInt32((int32)buffer.GetSize());
1839 output.WriteBytes((byte*)buffer.GetString(), (int32)buffer.GetSize());
1840
1841 return false;
1842}
1843

Callers 5

DeleteActorsActionMethod · 0.80
CopyMethod · 0.80
DuplicateMethod · 0.80
CopyMethod · 0.80
DuplicateMethod · 0.80

Calls 15

GetIDMethod · 0.80
MinFunction · 0.50
IsEmptyMethod · 0.45
CountMethod · 0.45
AddMethod · 0.45
WriteInt32Method · 0.45
WriteMethod · 0.45
StartArrayMethod · 0.45
SceneObjectMethod · 0.45
EndArrayMethod · 0.45
GetSizeMethod · 0.45
WriteBytesMethod · 0.45

Tested by

no test coverage detected