| 1157 | } |
| 1158 | |
| 1159 | void NavMeshBuilder::Update() |
| 1160 | { |
| 1161 | PROFILE_MEM(NavigationBuilding); |
| 1162 | ScopeLock lock(NavBuildQueueLocker); |
| 1163 | |
| 1164 | // Process nav mesh building requests and kick the tasks |
| 1165 | const auto now = DateTime::NowUTC(); |
| 1166 | bool didRebuild = false; |
| 1167 | for (int32 i = 0; NavBuildQueue.HasItems() && i < NavBuildQueue.Count(); i++) |
| 1168 | { |
| 1169 | auto req = NavBuildQueue.Get()[i]; |
| 1170 | if (now - req.Time >= 0) |
| 1171 | { |
| 1172 | NavBuildQueue.RemoveAt(i--); |
| 1173 | Scene* scene = req.Scene.Get(); |
| 1174 | if (!scene) |
| 1175 | continue; |
| 1176 | bool rebuild = req.DirtyBounds == BoundingBox::Empty; |
| 1177 | |
| 1178 | // Early out if scene has no bounds volumes to define nav mesh area |
| 1179 | if (scene->Navigation.Volumes.IsEmpty()) |
| 1180 | { |
| 1181 | ClearNavigation(scene); |
| 1182 | continue; |
| 1183 | } |
| 1184 | |
| 1185 | // Check if build a custom dirty bounds or whole scene |
| 1186 | if (rebuild) |
| 1187 | req.DirtyBounds = scene->Navigation.GetNavigationBounds(); // Compute total navigation area bounds |
| 1188 | if (didRebuild) |
| 1189 | rebuild = false; // When rebuilding navmesh for multiple scenes, rebuild only the first one (other scenes will use additive update) |
| 1190 | else |
| 1191 | didRebuild = true; |
| 1192 | BuildDirtyBounds(scene, req.DirtyBounds, rebuild); |
| 1193 | NavBuildCheckMissingNavMeshes = true; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | // Remove unused navmeshes (when all active tasks are done) |
| 1198 | // TODO: ignore AutoRemoveMissingNavMeshes in game and make it editor-only? |
| 1199 | if (NavBuildCheckMissingNavMeshes && NavBuildTasksMaxCount == 0 && NavigationSettings::Get()->AutoRemoveMissingNavMeshes) |
| 1200 | { |
| 1201 | NavBuildCheckMissingNavMeshes = false; |
| 1202 | NavBuildTasksLocker.Lock(); |
| 1203 | int32 taskCount = NavBuildTasks.Count(); |
| 1204 | NavBuildTasksLocker.Unlock(); |
| 1205 | if (taskCount == 0) |
| 1206 | { |
| 1207 | for (Scene* scene : Level::Scenes) |
| 1208 | { |
| 1209 | for (NavMesh* navMesh : scene->Navigation.Meshes) |
| 1210 | { |
| 1211 | if (!navMesh->Data.Tiles.HasItems()) |
| 1212 | { |
| 1213 | navMesh->DeleteObject(); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
nothing calls this directly
no test coverage detected