]> git.sesse.net Git - nageru/commitdiff
Small refactoring in Block.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Jun 2019 08:38:03 +0000 (10:38 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Jun 2019 08:48:35 +0000 (10:48 +0200)
nageru/scene.cpp
nageru/scene.h

index 8df9511276c65c8202e75c3ed84597dc078add7a..6c3a0393b8e83d47c7ca6fd202c668f69bf4bf38 100644 (file)
@@ -191,8 +191,7 @@ Effect *Scene::instantiate_effects(const Block *block, size_t chain_idx, Scene::
        }
 
        // Find the chosen alternative for this block in this instance.
-       size_t chosen_alternative = (chain_idx / block->cardinality_base) % block->alternatives.size();
-       EffectType chosen_type = block->alternatives[chosen_alternative]->effect_type;
+       EffectType chosen_type = block->alternatives[block->chosen_alternative(chain_idx)]->effect_type;
 
        Effect *effect;
        switch (chosen_type) {
@@ -225,7 +224,7 @@ Effect *Scene::instantiate_effects(const Block *block, size_t chain_idx, Scene::
                break;
        }
        default:
-               effect = instantiate_effect(instantiation->chain.get(), block->alternatives[chosen_alternative]->effect_type);
+               effect = instantiate_effect(instantiation->chain.get(), chosen_type);
                instantiation->chain->add_effect(effect, inputs);
                break;
        }
index bf23fbd1f2bb789d1fb350393fadf84ff2c5629c..b659429fbd5a8ef9a1ef54ec55cdc3175924739a 100644 (file)
@@ -76,6 +76,11 @@ struct Block {
        // (B_i is alternatives.size().) Not set before finalize() has run.
        size_t cardinality_base = 0;
 
+       // Find the chosen alternative for this block in a given instance.
+       size_t chosen_alternative(size_t chain_idx) const {
+               return (chain_idx / cardinality_base) % alternatives.size();
+       }
+
        std::vector<EffectBlueprint *> alternatives;  // Must all have the same amount of inputs. Pointers to make things easier for Lua.
        std::vector<Index> inputs;  // One for each input of alternatives[0] (ie., typically 0 or 1, occasionally 2).
        int currently_chosen_alternative = 0;