Skip to content

Commit

Permalink
calcSpan changed to use fewer loops, room removal now checks for the …
Browse files Browse the repository at this point in the history
…min/max spans of each z level.
  • Loading branch information
Chris7 committed Dec 25, 2013
1 parent caf973a commit 8d15f2d
Showing 1 changed file with 47 additions and 64 deletions.
111 changes: 47 additions & 64 deletions src/TArea.cpp
Expand Up @@ -373,6 +373,12 @@ void TArea::addRoom( int id )

void TArea::calcSpan()
{
xminEbene.clear();
yminEbene.clear();
zminEbene.clear();
xmaxEbene.clear();
ymaxEbene.clear();
zmaxEbene.clear();
if( rooms.size() > 0 )
{
int id = rooms[0];
Expand All @@ -391,74 +397,36 @@ void TArea::calcSpan()
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->x;
if( _m < min_x )
int _m_xmin = pR->x;
if( _m_xmin < min_x )
min_x = _m_xmin;
int _m_ymin = pR->y*-1;
if( _m_ymin < min_y )
min_y = _m_ymin;
int _m_zmin = pR->z;
if( _m_zmin < min_z )
{
min_x = _m;
}
}
for( int i=0; i<rooms.size(); i++ )
{
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->y*-1;
if( _m < min_y )
{
min_y = _m;
}
}
for( int i=0; i<rooms.size(); i++ )
{
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->z;
if( _m < min_z )
{
min_z = _m;
if( ! ebenen.contains( _m ) )
min_z = _m_zmin;
if( ! ebenen.contains( _m_zmin ) )
{
ebenen.push_back( _m );
ebenen.push_back( _m_zmin );
}
}
}
for( int i=0; i<rooms.size(); i++ )
{
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->x;
if( _m > max_x )
{
max_x = _m;
}
}
for( int i=0; i<rooms.size(); i++ )
{
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->y*-1;
if( _m > max_y )
int _m_xmax = pR->x;
if( _m_xmax > max_x )
max_x = _m_xmax;
int _m_ymax = pR->y*-1;
if( _m_ymax > max_y )
max_y = _m_ymax;
int _m_zmax = pR->z;
if( _m_zmax > max_z )
{
max_y = _m;
}
}
for( int i=0; i<rooms.size(); i++ )
{
int id = rooms[i];
TRoom * pR = mpRoomDB->getRoom( id );
if( !pR ) continue;
int _m = pR->z;
if( _m > max_z )
{
max_z = _m;
max_z = _m_zmax;
}
// ebenenliste anlegen
if( ! ebenen.contains( _m ) )
if( ! ebenen.contains( _m_zmax ) )
{
ebenen.push_back( _m );
ebenen.push_back( _m_zmax );
}
}

Expand Down Expand Up @@ -544,12 +512,27 @@ void TArea::calcSpan()

void TArea::removeRoom( int room )
{
rooms.removeOne( room );
TRoom * pR = mpRoomDB->getRoom( room );
rooms.removeAll( room );
exits.remove( room );
int x = pR->x;
int y = pR->y;
int y = pR->y*-1;
int z = pR->z;
if( max_x == x || min_x == x || max_y == y ||
min_y == y || max_z == z || min_z == z)
int xmin=x;int ymin=y;int zmin=z;
int xmax=x;int ymax=y;int zmax=z;
if ( xminEbene.contains(z) )
xmin = xminEbene[z];
if ( yminEbene.contains(z))
ymin = yminEbene[z];
if ( zminEbene.contains(z))
zmin = zminEbene[z];
if ( xmaxEbene.contains(z))
xmax = xmaxEbene[z];
if ( ymaxEbene.contains(z))
ymax = ymaxEbene[z];
if ( zmaxEbene.contains(z))
zmax = zmaxEbene[z];
if( xmin == x || xmax == x || ymax == y ||
ymin == y || zmin == z || zmax == z)
calcSpan();
}

3 comments on commit 8d15f2d

@vadi2
Copy link
Member

@vadi2 vadi2 commented on 8d15f2d Dec 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping the fewer loops would be able to speed up room removal (or batch room removal, but we've got no mechanism specifically for that) - it is still slow. The bug that is tracking the progress of that is this one: https://bugs.launchpad.net/mudlet/+bug/1226481

Just an observation related to this. Deleting rooms seems safe now, thanks a ton!

@Chris7
Copy link
Member Author

@Chris7 Chris7 commented on 8d15f2d Dec 25, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadi2
Copy link
Member

@vadi2 vadi2 commented on 8d15f2d Dec 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned elsewhere, recording it here - this was on release, ~20ms was the time per room as well. Future commits improved on this time.

Please sign in to comment.