void Metadata::SetItem(BString name, MetadataItem* item) { int32 index = _Index(name); if (index < 0) { MetadataPair* pair = new MetadataPair; pair->key = name; pair->item = item; fPairList->AddItem(pair); } else { MetadataItem* it = fPairList->ItemAt(index)->item; fPairList->ItemAt(index)->item = item; delete it; // trash it, remove it, etc. } item->SetKey(name); }
//------------------------------------------------------------------------ // Stitch the edge which two sides have the different lod level. // This code is from the source of OGRE. //------------------------------------------------------------------------ UINT etTile::StitchEdge( etTile::Neighbor nb,int hiLod,int loLod,bool omitFirst, bool omitLast,WORD** ppIndex ) { WORD* pIndices = *ppIndex; int step = 1 << hiLod; // Step from one vertex to another in the low detail version int superstep = 1 << loLod; // Step half way between low detail steps int halfsuperstep = superstep >> 1; UINT nTileSize = m_pLevel->GetTileSize(); // Work out the starting points and sign of increments // We always work the strip clockwise int startx, starty, endx, rowstep; bool horizontal; switch( nb ) { case etTile::NB_SOUTH: startx = starty = 0; endx = nTileSize; rowstep = step; horizontal = true; break; case etTile::NB_NORTH: // invert x AND y direction, helps to keep same winding startx = starty = nTileSize; endx = 0; rowstep = -step; step = -step; superstep = -superstep; halfsuperstep = -halfsuperstep; horizontal = true; break; case etTile::NB_EAST: startx = 0; endx = nTileSize; starty = nTileSize; rowstep = -step; horizontal = false; break; case etTile::NB_WEST: startx = nTileSize; endx = 0; starty = 0; rowstep = step; step = -step; superstep = -superstep; halfsuperstep = -halfsuperstep; horizontal = false; break; }; #define _Index( a,b ) ((b)*(nTileSize+1)+(a)) UINT numIndexes = 0; for( int j=startx;j!=endx;j+=superstep ) { for( int k=0;k!=halfsuperstep;k+=step ) { int jk = j + k; //skip the first bit of the corner? if ( j!=startx || k!=0 || !omitFirst ) { if( horizontal ) { *pIndices++ = _Index( j,starty ); *pIndices++ = _Index( jk,starty+rowstep ); *pIndices++ = _Index( jk+step,starty+rowstep ); numIndexes += 3; } else { *pIndices++ = _Index( starty,j ); *pIndices++ = _Index( starty+rowstep,jk ); *pIndices++ = _Index( starty+rowstep,jk+step ); numIndexes += 3; } } } if( horizontal ) { *pIndices++ = _Index( j,starty ); *pIndices++ = _Index( j+halfsuperstep,starty+rowstep ); *pIndices++ = _Index( j+superstep,starty ); numIndexes += 3; } else { *pIndices++ = _Index( starty,j ); *pIndices++ = _Index( starty+rowstep,j+halfsuperstep ); *pIndices++ = _Index( starty,j+superstep ); numIndexes += 3; } for( k=halfsuperstep;k!=superstep;k+=step ) { int jk = j + k; if( j!=endx-superstep || k!=superstep-step || !omitLast ) { if( horizontal ) { *pIndices++ = _Index( j+superstep,starty ); *pIndices++ = _Index( jk,starty+rowstep ); *pIndices++ = _Index( jk+step,starty+rowstep ); numIndexes += 3; } else { *pIndices++ = _Index( starty,j+superstep ); *pIndices++ = _Index( starty+rowstep,jk ); *pIndices++ = _Index( starty+rowstep,jk+step ); numIndexes += 3; } } } } #undef _Index *ppIndex = pIndices; return numIndexes; }
//------------------------------------------------------------------------ // Generate the triangle list indices for the tile. // ---------------------------------------------------------------------- // Param -> IN: // UINT: Flags when generating the buffer. // FlyGraphicBuffer**: To store the index buffer. // UINT*: To store the count of indices. //------------------------------------------------------------------------ void etTile::GenerateListIndexData( UINT nStitchFlags,FlyGraphicBuffer** ppIB, UINT* pNumIndices ) { UINT nNumIndices = 0; int step = 1 << m_nLodLevel; int east = nStitchFlags & STITCH_EAST ? step : 0; int west = nStitchFlags & STITCH_WEST ? step : 0; int south = nStitchFlags & STITCH_SOUTH ? step : 0; int north = nStitchFlags & STITCH_NORTH ? step : 0; UINT nTileSize = m_pLevel->GetTileSize(); UINT nBufferLength = (nTileSize/step) * (nTileSize/step) * 6; // Get the resourceManager. FlyResourceManager* pResMgr = FlyKernel::Instance().GetResourceManager(); // Create the index buffer. FlyGraphicBuffer* pIB = pResMgr->MakeIndexBuffer( nBufferLength*sizeof(WORD), BU_WRITEONLY,MM_MANAGED,IF_INDEX16 ); if( !pIB ) return; WORD* pIndices = (WORD*)pIB->Lock( 0,nBufferLength*sizeof(WORD),LOCK_NORMAL ); if( !pIndices ) { SAFE_DELETE( pIB ); return; } #define _Index(a,b) ((b)*(nTileSize+1)+(a)) for( int j=south;j<nTileSize-north;j+=step ) { for( int i=west;i<nTileSize-east;i+=step ) { *pIndices++ = _Index( i,j ); *pIndices++ = _Index( i,j+step ); *pIndices++ = _Index( i+step,j ); *pIndices++ = _Index( i,j+step ); *pIndices++ = _Index( i+step,j+step ); *pIndices++ = _Index( i+step,j ); nNumIndices += 6; } } #undef _Index if( north > 0 ) { nNumIndices += StitchEdge( NB_NORTH,m_nLodLevel,m_pNeighbors[NB_NORTH]->m_nLodLevel, east>0,west>0,&pIndices ); } if( east > 0 ) { nNumIndices += StitchEdge( NB_EAST,m_nLodLevel,m_pNeighbors[NB_EAST]->m_nLodLevel, south>0,north>0,&pIndices ); } if( south > 0 ) { nNumIndices += StitchEdge( NB_SOUTH,m_nLodLevel,m_pNeighbors[NB_SOUTH]->m_nLodLevel, west>0,east>0,&pIndices ); } if( west > 0 ) { nNumIndices += StitchEdge( NB_WEST,m_nLodLevel,m_pNeighbors[NB_WEST]->m_nLodLevel, north>0,south>0,&pIndices ); } pIB->Unlock(); *ppIB = pIB; *pNumIndices = nNumIndices; }
MetadataItem* Metadata::GetItem(BString name) { return fPairList->ItemAt(_Index(name))->item; }