| 1267 | } |
| 1268 | |
| 1269 | SceneResult 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) |
nothing calls this directly
no test coverage detected