Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gwaldron/osgearth
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 15, 2024
2 parents fb74b78 + 540abe1 commit e036db0
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/osgEarthProcedural/BiomeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,28 @@ BiomeLayer::createImageImplementation(
}
}

// Make a small l2 cache of biomes that we've already looked up and search the vector
// before going to the catalog. This is a performance optimization to avoid repeated queries into a potentially large catalog.
std::vector< const Biome* > biomeCache;
auto getBiome = [&](const std::string& id) -> const Biome*
{
// Search the cache first
for (auto i : biomeCache)
{
if (i->id() == id)
{
return i;
}
}

auto result = getBiomeCatalog()->getBiome(id);
if (result)
{
biomeCache.push_back(result);
}
return result;
};

iter.forEachPixelOnCenter([&]()
{
const Biome* biome = nullptr;
Expand Down Expand Up @@ -381,7 +403,7 @@ BiomeLayer::createImageImplementation(
{
if (sample->biomeid().isSet())
{
biome = getBiomeCatalog()->getBiome(sample->biomeid().get());
biome = getBiome(sample->biomeid().get());
}
}
}
Expand All @@ -408,7 +430,7 @@ BiomeLayer::createImageImplementation(
// if the biomeid() is set, we are overriding the biome expressly:
if (sample->biomeid().isSet())
{
biome = getBiomeCatalog()->getBiome(sample->biomeid().get());
biome = getBiome(sample->biomeid().get());
}

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

const Biome* implicit_biome = getBiomeCatalog()->getBiome(implicit_biome_id);
const Biome* implicit_biome = getBiome(implicit_biome_id);

if (implicit_biome)
{
Expand Down

0 comments on commit e036db0

Please sign in to comment.