MCPcopy Create free account
hub / github.com/carbonengine/trinity / PullInOutsiders

Method PullInOutsiders

trinity/Tr2TextureAtlas.cpp:967–1034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

965}
966
967void Tr2TextureAtlas::PullInOutsiders( bool optimiseInsertion )
968{
969 std::list<Tr2AtlasTexture*> sorted( m_texturesOutsideAtlas.begin(), m_texturesOutsideAtlas.end() );
970
971 if( optimiseInsertion )
972 {
973 //todo: implement more options for sorting the list (squareness, power-of-two pref.)
974 struct SmallestFirst
975 {
976 bool operator()( const Tr2AtlasTexture* a, const Tr2AtlasTexture* b )
977 {
978 const int widthA = a->m_width;
979 const int heightA = a->m_height;
980 const int widthB = b->m_width;
981 const int heightB = b->m_height;
982
983 return ( widthA * heightA ) < ( widthB * heightB );
984 }
985 };
986
987 SmallestFirst smallestFirst;
988 sorted.sort( smallestFirst );
989 }
990
991 CollapseFreeAreas();
992
993 for( std::list<Tr2AtlasTexture*>::iterator it = sorted.begin(); it != sorted.end(); ++it )
994 {
995 Tr2AtlasTexture* tex = *it;
996
997 if( tex->IsStandAlone() )
998 {
999 // Texture prefers to be an outsider
1000 continue;
1001 }
1002
1003 CCP_ASSERT( !tex->m_atlasArea );
1004
1005 Tr2TextureAtlasArea* area = GetFreeArea( tex->m_width + m_margin * 2, tex->m_height + m_margin * 2 );
1006 if( area )
1007 {
1008 area->tex = tex;
1009 area->type = Tr2TextureAtlasArea::IN_USE;
1010 tex->m_atlasArea = area;
1011 if( CopyTextureIntoAtlas( tex ) )
1012 {
1013 // Set up the texture window into the atlas
1014 tex->m_texture = Tr2TextureAL();
1015 tex->m_renderTarget = nullptr;
1016 tex->m_x = area->rect.left + m_margin;
1017 tex->m_y = area->rect.top + m_margin;
1018 tex->m_textureWidth = m_width;
1019 tex->m_textureHeight = m_height;
1020
1021 tex->FinalizePrepare();
1022
1023 m_texturesOutsideAtlas.erase( tex );
1024 m_texturesInAtlas.insert( tex );

Callers

nothing calls this directly

Calls 5

IsStandAloneMethod · 0.80
FinalizePrepareMethod · 0.80
Tr2TextureALClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected