| 39 | } |
| 40 | |
| 41 | void AMjReplayManager::BeginPlay() |
| 42 | { |
| 43 | Super::BeginPlay(); |
| 44 | |
| 45 | // Ensure live session exists |
| 46 | Sessions.FindOrAdd(LiveSessionName); |
| 47 | ActiveSessionName = LiveSessionName; |
| 48 | |
| 49 | // Auto-connect to manager if possible |
| 50 | Manager = AAMjManager::GetManager(); |
| 51 | if (Manager) |
| 52 | { |
| 53 | // Sets OnPostStep directly rather than RegisterPostStepCallback -- replay |
| 54 | // needs exclusive control of the callback, not append-to behavior. |
| 55 | if (Manager->PhysicsEngine) |
| 56 | { |
| 57 | Manager->PhysicsEngine->OnPostStep = [this](mjModel* m, mjData* d) { |
| 58 | this->OnPostStep(m, d); |
| 59 | }; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (bAutoRecord) |
| 64 | { |
| 65 | StartRecording(); |
| 66 | } |
| 67 | |
| 68 | // Auto-load any CSV/JSON replays from Saved/URLab/Replays/ |
| 69 | { |
| 70 | FString ReplayDir = FPaths::ProjectSavedDir() / TEXT("URLab") / TEXT("Replays"); |
| 71 | IFileManager::Get().MakeDirectory(*ReplayDir, true); |
| 72 | |
| 73 | TArray<FString> FoundFiles; |
| 74 | IFileManager::Get().FindFiles(FoundFiles, *(ReplayDir / TEXT("*.csv")), true, false); |
| 75 | |
| 76 | TArray<FString> JsonFiles; |
| 77 | IFileManager::Get().FindFiles(JsonFiles, *(ReplayDir / TEXT("*.json")), true, false); |
| 78 | FoundFiles.Append(JsonFiles); |
| 79 | |
| 80 | for (const FString& FileName : FoundFiles) |
| 81 | { |
| 82 | FString FullPath = ReplayDir / FileName; |
| 83 | FString SessionName = FPaths::GetBaseFilename(FileName); |
| 84 | |
| 85 | if (Sessions.Contains(SessionName)) |
| 86 | continue; |
| 87 | |
| 88 | if (FileName.EndsWith(TEXT(".csv"))) |
| 89 | { |
| 90 | LoadFromCSV(FullPath); |
| 91 | } |
| 92 | else if (FileName.EndsWith(TEXT(".json"))) |
| 93 | { |
| 94 | FString JsonString; |
| 95 | if (FFileHelper::LoadFileToString(JsonString, *FullPath)) |
| 96 | { |
| 97 | TSharedPtr<FJsonObject> RootObject; |
| 98 | TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString); |
nothing calls this directly
no test coverage detected