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

Method OnDeserialize

Source/Engine/Level/Level.cpp:1269–1329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1267}
1268
1269SceneResult SceneLoader::OnDeserialize(Args& args)
1270{
1271 PROFILE_CPU_NAMED("Deserialize");
1272 const int32 dataCount = (int32)args.Data.Size();
1273 SceneObject** objects = SceneObjects->Get();
1274 bool wasAsync = Context.Async;
1275 Context.Async = false; // TODO: before doing full async for scene objects fix:
1276 // TODO: - fix Actor's Scripts and Children order when loading objects data out of order via async jobs
1277 // TODO: - add _loadNoAsync flag to SceneObject or Actor to handle non-async loading for those types (eg. UIControl/UICanvas)
1278
1279 // Load all scene objects
1280 if (Context.Async)
1281 {
1282 Level::ScenesLock.Unlock(); // Unlock scenes from Main Thread so Job Threads can use it to safely setup actors hierarchy (see Actor::Deserialize)
1283#if USE_EDITOR
1284 volatile int64 deprecated = 0;
1285#endif
1286 JobSystem::Execute([&](int32 i)
1287 {
1288 i++; // Start from 1. at index [0] was scene
1289 auto obj = objects[i];
1290 if (obj)
1291 {
1292 auto& idMapping = Scripting::ObjectsLookupIdMapping.Get();
1293 idMapping = &Context.GetModifier()->IdsMapping;
1294 SceneObjectsFactory::Deserialize(Context, obj, args.Data[i]);
1295#if USE_EDITOR
1296 if (ContentDeprecated::Clear())
1297 Platform::InterlockedIncrement(&deprecated);
1298#endif
1299 idMapping = nullptr;
1300 }
1301 }, dataCount - 1);
1302#if USE_EDITOR
1303 if (deprecated != 0)
1304 ContentDeprecated::Mark();
1305#endif
1306 Level::ScenesLock.Lock();
1307 }
1308 else
1309 {
1310 Scripting::ObjectsLookupIdMapping.Set(&Modifier->IdsMapping);
1311 StageSlicer.BeginSync(args.TimeBudget, dataCount, 1); // start from 1. at index [0] was scene
1312 while (StageSlicer.Index < StageSlicer.Count)
1313 {
1314 auto& objData = args.Data[StageSlicer.Index];
1315 auto obj = objects[StageSlicer.Index];
1316 if (obj)
1317 SceneObjectsFactory::Deserialize(Context, obj, objData);
1318 if (StageSlicer.StepSync())
1319 break;
1320 }
1321 Scripting::ObjectsLookupIdMapping.Set(nullptr);
1322 }
1323 Context.Async = wasAsync;
1324
1325 auto result = StageSlicer.End();
1326 if (result != SceneResult::Wait)

Callers

nothing calls this directly

Calls 13

MarkFunction · 0.85
UnlockMethod · 0.80
GetModifierMethod · 0.80
LockMethod · 0.80
BeginSyncMethod · 0.80
StepSyncMethod · 0.80
DeserializeFunction · 0.50
ClearFunction · 0.50
InterlockedIncrementFunction · 0.50
SizeMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected