Exemplo n.º 1
0
void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha)
{
	BucketList::iterator bit;
	list<RAS_MeshSlot>::iterator mit;
	size_t size = 0, i = 0;

	/* Camera's near plane equation: pnorm.dot(point) + pval,
	 * but we leave out pval since it's constant anyway */
	const MT_Vector3 pnorm(cameratrans.getBasis()[2]);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		SG_DList::iterator<RAS_MeshSlot> mit((*bit)->GetActiveMeshSlots());
		for(mit.begin(); !mit.end(); ++mit)
			size++;
	}

	slots.resize(size);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		RAS_MaterialBucket* bucket = *bit;
		RAS_MeshSlot* ms;
		// remove the mesh slot form the list, it culls them automatically for next frame
		while((ms = bucket->GetNextActiveMeshSlot())) {
			slots[i++].set(ms, bucket, pnorm);
		}
	}
		
	if(alpha)
		sort(slots.begin(), slots.end(), backtofront());
	else
		sort(slots.begin(), slots.end(), fronttoback());
}
Exemplo n.º 2
0
// This code was copied from bulk data and used to remove entities
// from buckets.  In order to remove an entity, an appropriate entity
// must be found to copy into the hole.  This logic will find the
// appropriate bucket which has an entity to copy into the bucket.
void Transaction::remove_entity_from_bucket ( Entity &e , BucketList &buckets )
{
  Bucket *k = e.m_trans_bucket;
  unsigned i = e.m_trans_bucket_ord;

  Bucket * const first = k->m_key[ *k->m_key ] ? k->m_bucket : k ;
  Bucket * const last  = first->m_bucket ;

  // Only move if not the last entity being removed

  if ( last != k || k->m_size != i + 1 ) {

    // Not the same bucket or not the last entity

    // Copy last entity in last to ik slot i

    Entity * const entity = last->m_entities[ last->m_size - 1 ];

    k->m_entities[i]     = entity ;
    entity->m_trans_bucket     = k ;
    entity->m_trans_bucket_ord = i ;

  }

  --( last->m_size );

  if ( last->m_size != 0 ) {
    last->m_entities[ last->m_size ] = NULL ;
  }
  else {

    // The current 'last' bucket is to be deleted.
    // The previous 'last' bucket becomes the
    // new 'last' bucket in the family:

    std::vector<Bucket*>::iterator ik = lower_bound(buckets, last->m_key);

    ThrowRequireMsg( ik != buckets.end() && last == *ik,
        "Internal failure during removal of entity " << print_entity_key(e) );

    ik = buckets.erase( ik );

    if ( first != last ) { first->m_bucket = *--ik ; }

    Bucket::destroy_bucket( last );
  }

  e.m_trans_bucket = NULL;
}
Exemplo n.º 3
0
void print_bucket_list ( const BucketList &bl , std::ostream &os )
{
  BucketList::const_iterator  cur_bucket = bl.begin();
  while ( cur_bucket != bl.end() )
  {
    os << "Bucket key: ";
//This is bad code, no longer works. Re-visit this if/when the
//Transaction class is ever resurrected.
//    for ( unsigned i = 0 ; i <= (*cur_bucket)->m_key[0] ; i++ )
//      os << (*cur_bucket)->m_key[i] << " ";
//    os << "\n";
//    os << "Entities: ";
//    for ( unsigned i = 0 ; i != (*cur_bucket)->m_size ; i++ )
//      os << (*cur_bucket)->m_entities[i]->identifier() << " ";
//    os << "\n-------------------\n";
    cur_bucket++;
  }
}