| 1853 | } |
| 1854 | |
| 1855 | bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeModifier* modifier) |
| 1856 | { |
| 1857 | PROFILE_CPU(); |
| 1858 | PROFILE_MEM(Level); |
| 1859 | output.Clear(); |
| 1860 | ASSERT(modifier); |
| 1861 | if (data.Length() <= 0) |
| 1862 | return true; |
| 1863 | MemoryReadStream stream(data.Get(), data.Length()); |
| 1864 | |
| 1865 | // Header |
| 1866 | int32 engineBuild; |
| 1867 | stream.ReadInt32(&engineBuild); |
| 1868 | if (engineBuild > FLAXENGINE_VERSION_BUILD || engineBuild < 6165) |
| 1869 | { |
| 1870 | LOG(Warning, "Unsupported actors data version."); |
| 1871 | return true; |
| 1872 | } |
| 1873 | |
| 1874 | // Serialized objects ids (for references mapping) |
| 1875 | #if 0 |
| 1876 | Array<Guid> ids; |
| 1877 | stream.Read(ids); |
| 1878 | int32 objectsCount = ids.Count(); |
| 1879 | #else |
| 1880 | int32 objectsCount; |
| 1881 | stream.ReadInt32(&objectsCount); |
| 1882 | stream.Move<Guid>(objectsCount); |
| 1883 | #endif |
| 1884 | if (objectsCount < 0) |
| 1885 | return true; |
| 1886 | |
| 1887 | // Load objects data (JSON) |
| 1888 | int32 bufferSize; |
| 1889 | stream.ReadInt32(&bufferSize); |
| 1890 | const char* buffer = (const char*)stream.Move(bufferSize); |
| 1891 | rapidjson_flax::Document document; |
| 1892 | { |
| 1893 | PROFILE_CPU_NAMED("Json.Parse"); |
| 1894 | document.Parse(buffer, bufferSize); |
| 1895 | } |
| 1896 | if (document.HasParseError()) |
| 1897 | { |
| 1898 | Log::JsonParseException(document.GetParseError(), document.GetErrorOffset()); |
| 1899 | return true; |
| 1900 | } |
| 1901 | |
| 1902 | // Prepare |
| 1903 | modifier->EngineBuild = engineBuild; |
| 1904 | CollectionPoolCache<ActorsCache::SceneObjectsListType>::ScopeCache sceneObjects = ActorsCache::SceneObjectsListCache.Get(); |
| 1905 | sceneObjects->Resize(objectsCount); |
| 1906 | SceneObjectsFactory::Context context(modifier); |
| 1907 | |
| 1908 | // Fix root linkage for prefab instances (eg. when user duplicates a sub-prefab actor but not a root one) |
| 1909 | SceneObjectsFactory::PrefabSyncData prefabSyncData(*sceneObjects.Value, document, modifier); |
| 1910 | SceneObjectsFactory::SetupPrefabInstances(context, prefabSyncData); |
| 1911 | for (auto& instance : context.Instances) |
| 1912 | { |
no test coverage detected