Skip to content

Commit

Permalink
Reverted sorting links by block number
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Feb 9, 2025
1 parent e42114b commit c6bb577
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 45 deletions.
26 changes: 8 additions & 18 deletions src/data/nifitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,11 @@ void NifItem::removeChildren( int row, int count )

size_t NifItem::findLinkRow( int n ) const
{
size_t i0 = 0;
size_t i = 0;
size_t i2 = linkRowsSize;
while ( i2 > i0 ) {
size_t i1 = ( i0 + i2 ) >> 1;
if ( linkRows[i1] < n )
i0 = i1 + 1;
else
i2 = i1;
}
// return the index of the first element of linkRows not less than 'n'
return i0;
while ( i < i2 && linkRows[i] != n )
i++;
return i;
}

void NifItem::insertLinkRow( int n )
Expand All @@ -171,13 +165,9 @@ void NifItem::insertLinkRow( int n )
linkRows = tmp + 1;
}

size_t i = linkRowsSize;
if ( i && linkRows[i - 1] >= n ) {
i = findLinkRow( n );
if ( linkRows[i] == n )
return;
std::memmove( linkRows + ( i + 1 ), linkRows + i, ( size_t( linkRowsSize ) - i ) * sizeof( int ) );
}
size_t i = findLinkRow( n );
if ( i < linkRowsSize )
return;
if ( linkRowsSize >= 65535U )
throw std::bad_alloc();
linkRows[i] = n;
Expand Down Expand Up @@ -212,7 +202,7 @@ void NifItem::unregisterInParentLinkCache()
void NifItem::removeLinkRow( int n )
{
size_t i = findLinkRow( n );
if ( i < linkRowsSize && linkRows[i] == n ) {
if ( i < linkRowsSize ) {
if ( ( i + 1 ) < linkRowsSize )
std::memmove( linkRows + i, linkRows + ( i + 1 ), ( size_t( linkRowsSize ) - ( i + 1 ) ) * sizeof( int ) );
linkRowsSize--;
Expand Down
34 changes: 8 additions & 26 deletions src/model/nifmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,27 +2579,6 @@ void NifModel::invalidateItemConditions( NifItem * item )
* link functions
*/

bool NifModel::insertLink( QList<int> & l, int n )
{
qsizetype n0 = 0;
qsizetype n2 = l.size();
while ( n2 > ( n0 + 1 ) ) {
qsizetype n1 = ( n0 + n2 ) >> 1;
if ( n < l.at( n1 ) )
n2 = n1;
else
n0 = n1;
}
if ( n0 < n2 ) {
if ( n == l.at( n0 ) )
return false;
if ( n > l.at( n0 ) )
n0++;
}
l.insert( n0, n );
return true;
}

void NifModel::updateLinks( int block )
{
if ( lockUpdates ) {
Expand Down Expand Up @@ -2642,7 +2621,7 @@ void NifModel::updateLinks( int block )
const NifItem * b;
if ( bsVersion >= 151 && ( b = getBlockItem( qint32(c) ) ) != nullptr && b->name() == "BSShaderTextureSet" ) {
if ( c > 0 && ( b = getBlockItem( qint32(c - 1) ) ) != nullptr && b->name() == "BSLightingShaderProperty" )
insertLink( childLinks[c - 1], c );
childLinks[c - 1] += c;
} else {
rootLinks.append( c );
}
Expand All @@ -2668,10 +2647,13 @@ void NifModel::updateLinks( int block, NifItem * parent )

int i = c->getLinkValue();
if ( i >= 0 ) {
if ( c->valueType() == NifValue::tUpLink )
insertLink( parentLinks[block], i );
else
insertLink( childLinks[block], i );
if ( c->valueType() == NifValue::tUpLink ) {
if ( !parentLinks[block].contains( i ) )
parentLinks[block].append( i );
} else {
if ( !childLinks[block].contains( i ) )
childLinks[block].append( i );
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/model/nifmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ public slots:
QHash<int, QList<int> > childLinks;
QHash<int, QList<int> > parentLinks;
QList<int> rootLinks;
static bool insertLink( QList<int> & l, int n );

bool lockUpdates;
bool batchProcessingMode = false;
Expand Down

0 comments on commit c6bb577

Please sign in to comment.