Skip to content

Commit

Permalink
Merge pull request spelunky-fyi#378 from estebanfer/procedural-spawns…
Browse files Browse the repository at this point in the history
…-optimization

Skip script chance logic providers if their spawn chance is zero
  • Loading branch information
Dregu authored May 9, 2024
2 parents e4b2f7f + e9cf43a commit b65022e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/game_api/level_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,10 @@ bool handle_chance(SpawnInfo* spawn_info)

uint8_t layer = 0;
auto* layer_ptr = State::get().layer(layer);
LevelGenSystem* level_gen = State::get().ptr()->level_gen;
for (const CommunityChance& community_chance : g_community_chances)
{
if (community_chance.test_func(community_chance, spawn_info->x, spawn_info->y, layer_ptr))
if (level_gen->get_procedural_spawn_chance(community_chance.chance_id) != 0 && community_chance.test_func(community_chance, spawn_info->x, spawn_info->y, layer_ptr))
{
if (g_test_chance(&level_gen_data, community_chance.chance_id))
{
Expand All @@ -1294,7 +1295,7 @@ bool handle_chance(SpawnInfo* spawn_info)
std::lock_guard lock{g_chance_logic_providers_lock};
for (const ChanceLogicProviderImpl& chance_provider : g_chance_logic_providers)
{
if (chance_provider.provider.is_valid(spawn_info->x, spawn_info->y, layer))
if (level_gen->get_procedural_spawn_chance(chance_provider.chance_id) != 0 && chance_provider.provider.is_valid(spawn_info->x, spawn_info->y, layer))
{
if (g_test_chance(&level_gen_data, chance_provider.chance_id))
{
Expand Down

0 comments on commit b65022e

Please sign in to comment.