--------------------------------- AssetDatabase::Merge Merge another asset database into this one.
| 282 | // Merge another asset database into this one. |
| 283 | // |
| 284 | void AssetDatabase::Merge(AssetDatabase const& other) |
| 285 | { |
| 286 | // add packages |
| 287 | for (PackageDescriptor const& desc : other.packages) |
| 288 | { |
| 289 | auto packageIt = std::find_if(packages.cbegin(), packages.cend(), [&desc](PackageDescriptor const& lhs) |
| 290 | { |
| 291 | return lhs.GetId() == desc.GetId(); |
| 292 | }); |
| 293 | |
| 294 | // if the other DB contains a package that this DB doesn't know of, add it |
| 295 | if (packageIt == packages.cend()) |
| 296 | { |
| 297 | packages.emplace_back(desc); |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | // if both have the same package, ensure they agree on its details |
| 302 | ET_ASSERT(packageIt->GetPath() == desc.GetPath(), |
| 303 | "DBs disagree on paths for package '%s'! this: '%s' - other: '%s'", |
| 304 | desc.GetName().c_str(), |
| 305 | packageIt->GetPath().c_str(), |
| 306 | desc.GetPath().c_str()); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // add caches |
| 311 | for (AssetCache const& rhCache : other.caches) |
| 312 | { |
| 313 | auto cacheIt = std::find_if(caches.begin(), caches.end(), [&rhCache](AssetCache const& lhCache) |
| 314 | { |
| 315 | return lhCache.GetType() == rhCache.GetType(); |
| 316 | }); |
| 317 | |
| 318 | if (cacheIt == caches.cend()) |
| 319 | { |
| 320 | caches.emplace_back(rhCache); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | AssetCache& lhCache = *cacheIt; |
| 325 | |
| 326 | // insert assets |
| 327 | for (I_Asset* const rhAsset : rhCache.cache) |
| 328 | { |
| 329 | // Ensure the asset doesn't already exist |
| 330 | auto assetIt = std::find_if(lhCache.cache.cbegin(), lhCache.cache.cend(), [rhAsset](I_Asset const* const lhAsset) |
| 331 | { |
| 332 | return lhAsset->GetId() == rhAsset->GetId(); |
| 333 | }); |
| 334 | |
| 335 | // if the to merge asset is unique add it |
| 336 | if (assetIt == lhCache.cache.cend()) |
| 337 | { |
| 338 | // check we have a package descriptor for the new asset |
| 339 | ET_ASSERT(std::find_if(packages.cbegin(), packages.cend(), [rhAsset](PackageDescriptor const& lhPackage) |
| 340 | { |
| 341 | return lhPackage.GetId() == rhAsset->GetPackageId(); |
no test coverage detected