Skip to content

Commit e036db0

Browse files
committed
Merge branch 'master' of github.com:gwaldron/osgearth
2 parents fb74b78 + 540abe1 commit e036db0

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/osgEarthProcedural/BiomeLayer.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,28 @@ BiomeLayer::createImageImplementation(
354354
}
355355
}
356356

357+
// Make a small l2 cache of biomes that we've already looked up and search the vector
358+
// before going to the catalog. This is a performance optimization to avoid repeated queries into a potentially large catalog.
359+
std::vector< const Biome* > biomeCache;
360+
auto getBiome = [&](const std::string& id) -> const Biome*
361+
{
362+
// Search the cache first
363+
for (auto i : biomeCache)
364+
{
365+
if (i->id() == id)
366+
{
367+
return i;
368+
}
369+
}
370+
371+
auto result = getBiomeCatalog()->getBiome(id);
372+
if (result)
373+
{
374+
biomeCache.push_back(result);
375+
}
376+
return result;
377+
};
378+
357379
iter.forEachPixelOnCenter([&]()
358380
{
359381
const Biome* biome = nullptr;
@@ -381,7 +403,7 @@ BiomeLayer::createImageImplementation(
381403
{
382404
if (sample->biomeid().isSet())
383405
{
384-
biome = getBiomeCatalog()->getBiome(sample->biomeid().get());
406+
biome = getBiome(sample->biomeid().get());
385407
}
386408
}
387409
}
@@ -408,7 +430,7 @@ BiomeLayer::createImageImplementation(
408430
// if the biomeid() is set, we are overriding the biome expressly:
409431
if (sample->biomeid().isSet())
410432
{
411-
biome = getBiomeCatalog()->getBiome(sample->biomeid().get());
433+
biome = getBiome(sample->biomeid().get());
412434
}
413435

414436
// If we have a biome, but there are traits set, we need to
@@ -422,7 +444,7 @@ BiomeLayer::createImageImplementation(
422444
std::string implicit_biome_id =
423445
biome->id() + "." + AssetTraits::toString(sorted);
424446

425-
const Biome* implicit_biome = getBiomeCatalog()->getBiome(implicit_biome_id);
447+
const Biome* implicit_biome = getBiome(implicit_biome_id);
426448

427449
if (implicit_biome)
428450
{

0 commit comments

Comments
 (0)