]> git.sesse.net Git - nageru/blobdiff - nageru/scene.h
Support submenus within theme menus.
[nageru] / nageru / scene.h
index fc36963cc9eebd3ae56943293e9c74ce71886ea5..83346647236eb0ecda7aa512ec1fead4172940bf 100644 (file)
@@ -9,10 +9,11 @@
 // ResizeEffect or IdentityEffect (effectively doing nothing), or many
 // different input types. On finalization, every different combination of
 // block alternatives are tried, and one EffectChain is generated for each.
-// This also goes for whether the chain is destined for preview outputs
+// This also goes for whether the scene is destined for preview outputs
 // (directly to screen, RGBA) or live (Y'CbCr output).
 
 #include <stddef.h>
+#include <bitset>
 #include <functional>
 #include <map>
 #include <memory>
@@ -64,7 +65,7 @@ struct Block {
        // where C_0 = 0 and C_(i+1) = C_i * B_i. In other words, C_i is
        // the product of the cardinalities of each previous effect; if we
        // are e.g. at the third index and there have been C_2 = 3 * 5 = 15
-       // different alternatives for constructing the chain so far
+       // different alternatives for constructing the scene so far
        // (with possible indexes 0..14), it is only logical that if we
        // want three new options (B_2 = 3), we must add 0, 15 or 30 to
        // the index. (Then the local possible indexes become 0..44 and
@@ -76,6 +77,15 @@ 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 {
+               if (chain_idx == size_t(-1)) {
+                       return currently_chosen_alternative;
+               } else {
+                       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;
@@ -105,6 +115,7 @@ struct Block {
 int Block_display(lua_State* L);
 int Block_choose(lua_State* L);
 int Block_enable(lua_State *L);
+int Block_enable_if(lua_State *L);
 int Block_disable(lua_State *L);
 int Block_set_int(lua_State *L);
 int Block_set_float(lua_State *L);
@@ -127,7 +138,26 @@ private:
        movit::ResourcePool *resource_pool;
 
        movit::Effect *instantiate_effects(const Block *block, size_t chain_idx, Instantiation *instantiation);
-       size_t compute_chain_number_for_block(size_t block_idx) const;
+       size_t compute_chain_number_for_block(size_t block_idx, const std::bitset<256> &disabled) const;
+       static void find_inputs_for_block(lua_State *L, Scene *scene, Block *block);
+
+       // Find out which blocks (indexed by position in the “blocks” array),
+       // if any, are disabled in a given instantiation. A disabled block is
+       // one that will not be instantiated at all, because it is a secondary
+       // (ie., not the first) input of some multi-input effect that was replaced
+       // with IdentityEffect in the given instantiation.
+       //
+       // Set chain_idx to size_t(-1) to use whatever is in each block's
+       // currently_chosen_alternative.
+       std::bitset<256> find_disabled_blocks(size_t chain_idx) const;
+       void find_disabled_blocks(size_t chain_idx, size_t block_idx, bool currently_disabled, std::bitset<256> *disabled) const;
+
+       // If a block is disabled, it should always have alternative 0 chosen,
+       // so that we don't instantiate a bunch of irrelevant duplicates that
+       // differ only in disabled blocks. You can check this property with
+       // is_noncanonical_chain() and then avoid instantiating the ones where
+       // it returns true.
+       bool is_noncanonical_chain(size_t chain_idx) const;
 
 public:
        Scene(Theme *theme, float aspect_nom, float aspect_denom);