Changeset 510 for trunk


Ignore:
Timestamp:
07/27/16 19:06:49 (9 years ago)
Author:
epyon
Message:
  • choice a enum instead of boolean - pattern support
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/engine/model_manager.hh

    r509 r510  
    2727namespace nv
    2828{
     29        enum class model_node_choice
     30        {
     31                ALL,
     32                WEIGHTED,
     33                PATTERN_CHECKER
     34        };
    2935
    3036        struct model_node
     
    4046                float                        chance    = 1.0f;
    4147                bool                         force     = false;
    42                 bool                         choice    = false;
     48                model_node_choice            choice    = model_node_choice::ALL;
    4349
    4450                void clone_values_to( model_node* target ) const
     
    118124                virtual string_view get_storage_name() const { return "models"; }
    119125                virtual string_view get_resource_name() const { return "model"; }
    120                 static flat_model flatten( const model* m, random_base& rng, vector< const model_node* >* map = nullptr, uint32 gen_flags = 0, const model_node* select = nullptr )
     126                static flat_model flatten(
     127                        const model* m,
     128                        random_base& rng,
     129                        ivec2 control,
     130                        vector< const model_node* >* map = nullptr,
     131                        uint32 gen_flags = 0,
     132                        const model_node* select = nullptr )
    121133                {
    122134                        flat_model result;
     
    125137                        result.local = m->root;
    126138                        result.count = 0;
    127                         flatten( result, m, rng, transform(), -1, map, gen_flags, 0, select );
     139                        flatten( result, m, rng, control, transform(), -1, map, gen_flags, 0, select );
    128140                        return result;
    129141                }
     
    133145                        const model_node* m,
    134146                        random_base& rng,
     147                        ivec2 control,
    135148                        const transform& ptr,
    136149                        sint16 parent_id,
     
    198211                        }
    199212
    200                         if ( m->choice )
     213                        if ( m->choice != model_node_choice::ALL )
    201214                        {
    202                                 uint16 total_weight = 0;
    203                                 for ( auto c : m->children )
    204                                         total_weight += c->weight;
    205                                 if ( total_weight > 0 )
    206                                 {
     215                                model_node* pick = nullptr;
     216                                if ( m->choice == model_node_choice::WEIGHTED )
     217                                {
     218                                        uint16 total_weight = 0;
     219                                        for ( auto c : m->children )
     220                                                total_weight += c->weight;
     221                                        if ( total_weight == 0 ) return;
    207222                                        sint32 roll = rng.srand( total_weight );
    208                                         model_node* pick = nullptr;
    209223                                        for ( auto c : m->children )
    210224                                        {
    211225                                                roll -= c->weight;
    212                                                 if ( roll < 0 )
    213                                                 {
    214                                                         pick = c;
    215                                                         break;
    216                                                 }
     226                                                if ( roll < 0 ) { pick = c; break; }
    217227                                        }
    218                                         if ( gen_flags & FF_GENERATE_CHOICE )
    219                                                 for ( auto c : m->children )
    220                                                 {
    221                                                         uint32 flags = parent_flags;
    222                                                         if ( c != pick ) flags |= FMF_FAIL_CHOICE;
    223                                                         flatten( result, c, rng, tr, parent_id, map, gen_flags, flags, selected );
    224                                                 }
    225                                         else
    226                                                 flatten( result, pick, rng, tr, parent_id, map, gen_flags, parent_flags, selected );
    227                                 }
     228                                }
     229                                else if ( m->choice == model_node_choice::PATTERN_CHECKER )
     230                                {
     231                                        pick = m->children[( control.x + control.y ) % m->children.size()];
     232                                }
     233
     234                                if ( pick == nullptr ) return;
     235                                if ( gen_flags & FF_GENERATE_CHOICE )
     236                                        for ( auto c : m->children )
     237                                        {
     238                                                uint32 flags = parent_flags;
     239                                                if ( c != pick ) flags |= FMF_FAIL_CHOICE;
     240                                                flatten( result, c, rng, control, tr, parent_id, map, gen_flags, flags, selected );
     241                                        }
     242                                else
     243                                        flatten( result, pick, rng, control, tr, parent_id, map, gen_flags, parent_flags, selected );
    228244                        }
    229245                        else
    230246                                for ( auto c : m->children )
    231247                                {
    232                                         flatten( result, c, rng, tr, parent_id, map, gen_flags, parent_flags, selected );
     248                                        flatten( result, c, rng, control, tr, parent_id, map, gen_flags, parent_flags, selected );
    233249                                }
    234250                }
  • trunk/src/engine/default_resource_manager.cc

    r509 r510  
    6161        m_lua->register_enum( "EASING_SINE",    static_cast<int>( easing_type::SINE ) );
    6262
     63        m_lua->register_enum( "CHOICE_ALL", static_cast<int>( model_node_choice::ALL ) );
     64        m_lua->register_enum( "CHOICE_WEIGHTED", static_cast<int>( model_node_choice::WEIGHTED ) );
     65        m_lua->register_enum( "CHOICE_PATTERN_CHECKER", static_cast<int>( model_node_choice::PATTERN_CHECKER ) );
     66
    6367        m_materials->initialize( lua );
    6468        m_programs->initialize( lua );
  • trunk/src/engine/model_manager.cc

    r509 r510  
    104104
    105105        node->force     = table.get_boolean( "force", false );
    106         node->choice    = table.get_boolean( "choice", false );
     106        node->choice    = model_node_choice( table.get_unsigned( "choice", false ) );
    107107        node->chance    = table.get_float( "chance", 1.0f );
    108108        node->weight    = table.get_unsigned( "weight", 1 );
Note: See TracChangeset for help on using the changeset viewer.