|
5 | 5 | #include <components/detournavigator/makenavmesh.hpp>
|
6 | 6 | #include <components/detournavigator/navmeshdbutils.hpp>
|
7 | 7 | #include <components/detournavigator/serialization.hpp>
|
| 8 | +#include <components/files/conversion.hpp> |
8 | 9 | #include <components/loadinglistener/loadinglistener.hpp>
|
| 10 | +#include <components/testing/util.hpp> |
9 | 11 |
|
10 | 12 | #include <BulletCollision/CollisionShapes/btBoxShape.h>
|
11 | 13 |
|
@@ -372,6 +374,106 @@ namespace
|
372 | 374 | }
|
373 | 375 | }
|
374 | 376 |
|
| 377 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, should_write_debug_recast_mesh) |
| 378 | + { |
| 379 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 380 | + addHeightFieldPlane(mRecastMeshManager); |
| 381 | + mSettings.mEnableWriteRecastMeshToFile = true; |
| 382 | + const std::filesystem::path dir = TestingOpenMW::outputDirPath("DetourNavigatorAsyncNavMeshUpdaterTest"); |
| 383 | + mSettings.mRecastMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 384 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 385 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 386 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 387 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 388 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 389 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 390 | + EXPECT_TRUE(std::filesystem::exists(dir / "0.0.recastmesh.obj")); |
| 391 | + } |
| 392 | + |
| 393 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, should_write_debug_recast_mesh_with_revision) |
| 394 | + { |
| 395 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 396 | + addHeightFieldPlane(mRecastMeshManager); |
| 397 | + mSettings.mEnableWriteRecastMeshToFile = true; |
| 398 | + mSettings.mEnableRecastMeshFileNameRevision = true; |
| 399 | + const std::filesystem::path dir = TestingOpenMW::outputDirPath("DetourNavigatorAsyncNavMeshUpdaterTest"); |
| 400 | + mSettings.mRecastMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 401 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 402 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 403 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 404 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 405 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 406 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 407 | + EXPECT_TRUE(std::filesystem::exists(dir / "0.0.recastmesh.1.2.obj")); |
| 408 | + } |
| 409 | + |
| 410 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, writing_recast_mesh_to_absent_file_should_not_fail_tile_generation) |
| 411 | + { |
| 412 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 413 | + addHeightFieldPlane(mRecastMeshManager); |
| 414 | + mSettings.mEnableWriteRecastMeshToFile = true; |
| 415 | + const std::filesystem::path dir = TestingOpenMW::outputDir() / "absent"; |
| 416 | + mSettings.mRecastMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 417 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 418 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 419 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 420 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 421 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 422 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 423 | + EXPECT_NE(navMeshCacheItem->lockConst()->getImpl().getTileRefAt(0, 0, 0), 0u); |
| 424 | + EXPECT_FALSE(std::filesystem::exists(dir)); |
| 425 | + } |
| 426 | + |
| 427 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, should_write_debug_navmesh) |
| 428 | + { |
| 429 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 430 | + addHeightFieldPlane(mRecastMeshManager); |
| 431 | + mSettings.mEnableWriteNavMeshToFile = true; |
| 432 | + const std::filesystem::path dir = TestingOpenMW::outputDirPath("DetourNavigatorAsyncNavMeshUpdaterTest"); |
| 433 | + mSettings.mNavMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 434 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 435 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 436 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 437 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 438 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 439 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 440 | + EXPECT_TRUE(std::filesystem::exists(dir / "all_tiles_navmesh.bin")); |
| 441 | + } |
| 442 | + |
| 443 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, should_write_debug_navmesh_with_revision) |
| 444 | + { |
| 445 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 446 | + addHeightFieldPlane(mRecastMeshManager); |
| 447 | + mSettings.mEnableWriteNavMeshToFile = true; |
| 448 | + mSettings.mEnableNavMeshFileNameRevision = true; |
| 449 | + const std::filesystem::path dir = TestingOpenMW::outputDirPath("DetourNavigatorAsyncNavMeshUpdaterTest"); |
| 450 | + mSettings.mNavMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 451 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 452 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 453 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 454 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 455 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 456 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 457 | + EXPECT_TRUE(std::filesystem::exists(dir / "all_tiles_navmesh.1.1.bin")); |
| 458 | + } |
| 459 | + |
| 460 | + TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, writing_navmesh_to_absent_file_should_not_fail_tile_generation) |
| 461 | + { |
| 462 | + mRecastMeshManager.setWorldspace(mWorldspace, nullptr); |
| 463 | + addHeightFieldPlane(mRecastMeshManager); |
| 464 | + mSettings.mEnableWriteNavMeshToFile = true; |
| 465 | + const std::filesystem::path dir = TestingOpenMW::outputDir() / "absent"; |
| 466 | + mSettings.mNavMeshPathPrefix = Files::pathToUnicodeString(dir) + "/"; |
| 467 | + Log(Debug::Verbose) << mSettings.mRecastMeshPathPrefix; |
| 468 | + AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, nullptr); |
| 469 | + const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings); |
| 470 | + const std::map<TilePosition, ChangeType> changedTiles{ { TilePosition{ 0, 0 }, ChangeType::add } }; |
| 471 | + updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles); |
| 472 | + updater.wait(WaitConditionType::allJobsDone, &mListener); |
| 473 | + EXPECT_NE(navMeshCacheItem->lockConst()->getImpl().getTileRefAt(0, 0, 0), 0u); |
| 474 | + EXPECT_FALSE(std::filesystem::exists(dir)); |
| 475 | + } |
| 476 | + |
375 | 477 | struct DetourNavigatorSpatialJobQueueTest : Test
|
376 | 478 | {
|
377 | 479 | const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, osg::Vec3f(1, 1, 1) };
|
|
0 commit comments