Changeset 510
- Timestamp:
- 07/27/16 19:06:49 (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/engine/model_manager.hh
r509 r510 27 27 namespace nv 28 28 { 29 enum class model_node_choice 30 { 31 ALL, 32 WEIGHTED, 33 PATTERN_CHECKER 34 }; 29 35 30 36 struct model_node … … 40 46 float chance = 1.0f; 41 47 bool force = false; 42 bool choice = false;48 model_node_choice choice = model_node_choice::ALL; 43 49 44 50 void clone_values_to( model_node* target ) const … … 118 124 virtual string_view get_storage_name() const { return "models"; } 119 125 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 ) 121 133 { 122 134 flat_model result; … … 125 137 result.local = m->root; 126 138 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 ); 128 140 return result; 129 141 } … … 133 145 const model_node* m, 134 146 random_base& rng, 147 ivec2 control, 135 148 const transform& ptr, 136 149 sint16 parent_id, … … 198 211 } 199 212 200 if ( m->choice )213 if ( m->choice != model_node_choice::ALL ) 201 214 { 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; 207 222 sint32 roll = rng.srand( total_weight ); 208 model_node* pick = nullptr;209 223 for ( auto c : m->children ) 210 224 { 211 225 roll -= c->weight; 212 if ( roll < 0 ) 213 { 214 pick = c; 215 break; 216 } 226 if ( roll < 0 ) { pick = c; break; } 217 227 } 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 ); 228 244 } 229 245 else 230 246 for ( auto c : m->children ) 231 247 { 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 ); 233 249 } 234 250 } -
trunk/src/engine/default_resource_manager.cc
r509 r510 61 61 m_lua->register_enum( "EASING_SINE", static_cast<int>( easing_type::SINE ) ); 62 62 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 63 67 m_materials->initialize( lua ); 64 68 m_programs->initialize( lua ); -
trunk/src/engine/model_manager.cc
r509 r510 104 104 105 105 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 ) ); 107 107 node->chance = table.get_float( "chance", 1.0f ); 108 108 node->weight = table.get_unsigned( "weight", 1 );
Note: See TracChangeset
for help on using the changeset viewer.