Skip to content

Commit

Permalink
Merge pull request Mudlet#269 from SlySven/Backport_entranceMapAndBul…
Browse files Browse the repository at this point in the history
…kRoomDeletion

Backport: merge ten commits
  • Loading branch information
SlySven committed Aug 22, 2015
2 parents 83e0272 + 11b9331 commit 6499130
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 108 deletions.
11 changes: 5 additions & 6 deletions src/T2DMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3002,11 +3002,10 @@ void T2DMap::slot_setImage()

void T2DMap::slot_deleteRoom()
{
mpMap->mpRoomDB->removeRoom( mMultiSelectionList );
// mMultiSelectionList gets cleared as rooms are removed by
// TRoomDB::removeRoom() so no need to clear it here!
mMultiRect = QRect(0,0,0,0);
for( int j=0; j<mMultiSelectionList.size(); j++ )
{
mpMap->mpRoomDB->removeRoom( mMultiSelectionList[j] );
}
mMultiSelectionListWidget.clear();
mMultiSelectionListWidget.hide();
repaint();
Expand Down Expand Up @@ -3300,8 +3299,8 @@ void T2DMap::slot_setArea()

int newAreaId = arealist_combobox->itemData( arealist_combobox->currentIndex() ).toInt();
mMultiRect = QRect(0,0,0,0);
uint maxRoomIndex = mMultiSelectionList.size() - 1;
for( int j = 0; j <= maxRoomIndex; j++ ) {
int maxRoomIndex = mMultiSelectionList.size() - 1;
for( unsigned int j = 0; j <= maxRoomIndex; j++ ) {
if( j < maxRoomIndex ) {
mpMap->setRoomArea( mMultiSelectionList.at(j), newAreaId, true );
}
Expand Down
20 changes: 15 additions & 5 deletions src/TArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "pre_guard.h"
#include <QApplication>
#include <QDebug>
#include <QTime>
#include <QElapsedTimer>
#include "post_guard.h"

// Previous direction #defines here did not match the DIR_ defines in TRoom.h,
Expand Down Expand Up @@ -254,6 +254,9 @@ void TArea::determineAreaExitsOfRoom( int id )

void TArea::determineAreaExits()
{
QElapsedTimer timer;
timer.start();

exits.clear();
for( int i=0; i<rooms.size(); i++ ) {
TRoom * pR = mpRoomDB->getRoom(rooms[i]);
Expand Down Expand Up @@ -337,6 +340,7 @@ void TArea::determineAreaExits()
}
}
//qDebug()<<"exits:"<<exits.size();
qDebug() << "TArea::determineAreaExits() area"<< mpRoomDB->getAreaID(this) << "took:" << timer.nsecsElapsed() * 1.0e-9 << "sec.";
}

void TArea::fast_calcSpan( int id )
Expand Down Expand Up @@ -517,12 +521,18 @@ void TArea::calcSpan()

void TArea::removeRoom( int room )
{
QTime time;
time.start();
static double cumulativeMean = 0.0;
static quint64 runCount = 0 ;
QElapsedTimer timer;
timer.start();
// TRoom * pR = mpRoomDB->getRoom( room );
rooms.removeOne( room );
exits.remove( room );
qDebug()<<"Area removal took"<<time.elapsed();
quint64 thisTime = timer.nsecsElapsed();
cumulativeMean += ( ( (thisTime * 1.0e-9) - cumulativeMean) / ++runCount );
if( runCount % 1000 == 0 ) {
qDebug()<<"TArea::removeRoom(" << room << ") from Area took" << thisTime * 1.0e-9 << "sec. this time and after" << runCount << "times the average is" << cumulativeMean << "sec.";
}
// int x = pR->x;
// int y = pR->y*-1;
// int z = pR->z;
Expand Down Expand Up @@ -575,7 +585,7 @@ const QMultiMap<int, QPair<QString, int> > TArea::getAreaExitRoomData() const
case DIR_OUT: exitData.first = QString("out"); break;
case DIR_OTHER: roomsWithOtherAreaSpecialExits.insert(itAreaExit.key()); break;
default:
qWarning("TArea::getAreaExitRoomData() Warning: unrecognised exit code %1 found for exit from room %2 to room %3.",
qWarning("TArea::getAreaExitRoomData() Warning: unrecognised exit code %i found for exit from room %i to room %i.",
itAreaExit.value().second, itAreaExit.key(), itAreaExit.value().first );
}
if( ! exitData.first.isEmpty() ) {
Expand Down
5 changes: 3 additions & 2 deletions src/TArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class TArea
QList<int> getCollisionNodes();
QList<int> getRoomsByPosition(int x, int y, int z);
QMap<int, QMap<int, QMultiMap<int, int> > > koordinatenSystem();
bool mIsDirty;


QList<int> rooms; // rooms of this area
Expand All @@ -78,7 +77,9 @@ class TArea
bool gridMode;
bool isZone;
int zoneAreaRef;
TRoomDB* mpRoomDB;
TRoomDB * mpRoomDB;
bool mIsDirty;


private:
TArea() { qFatal("FATAL: illegal default constructor use of TArea()"); };
Expand Down
52 changes: 49 additions & 3 deletions src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3917,6 +3917,54 @@ int TLuaInterpreter::getRoomExits( lua_State *L )
return 0;
}

// Given a room Id number, returns a lua list (monotonically increasing keys
// starting at 1) with (sorted) values being room Id numbers that have exit(s)
// that enter the given room (even one way routes).
// TODO: Provide exit details:
int TLuaInterpreter::getAllRoomEntrances( lua_State *L )
{
int roomId;
if( ! lua_isnumber( L, 1 ) ) {
lua_pushstring( L, tr( "getAllRoomEntrances: bad argument #1 type (room Id, as number expected, got %1)." ).arg( luaL_typename(L, 1)).toUtf8().constData());
lua_error( L );
}
else {
roomId = lua_tonumber( L, 1 );
}

Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
if( ! pHost ) {
lua_pushnil( L );
lua_pushstring( L, tr( "getAllRoomEntrances: NULL Host pointer - something is wrong!" ).toUtf8().constData() );
return 2;
}
else if( ! pHost->mpMap || ! pHost->mpMap->mpRoomDB ) {
lua_pushnil( L );
lua_pushstring( L, tr( "getAllRoomEntrances: no map present or loaded!" ).toUtf8().constData() );
return 2;
}
else {
TRoom * pR = pHost->mpMap->mpRoomDB->getRoom(roomId);
if( ! pR ) {
lua_pushnil( L );
lua_pushstring( L, tr( "getAllRoomEntrances: bad argument #1 value (number %1 is not a valid room Id)." ).arg(roomId).toUtf8().constData() );
return 2;
}
lua_newtable(L);
QList<int> entrances = pHost->mpMap->mpRoomDB->getEntranceHash().values( roomId );
// Could use a .toSet().toList() to remove duplicates values
if( entrances.count() > 1 ) {
std::sort( entrances.begin(), entrances.end() );
}
for( uint i = 0; i < entrances.size(); i++ ) {
lua_pushnumber( L, i+1 );
lua_pushnumber( L, entrances.at( i ) );
lua_settable(L, -3);
}
return 1;
}
}

// EITHER searchRoom( roomId ):
// Returns the room name for the given roomId number, or errors out if no such
// room exists.
Expand Down Expand Up @@ -8197,7 +8245,6 @@ int TLuaInterpreter::addSpecialExit( lua_State * L )
{
pR_from->setSpecialExit( id_to, _dir );
pR_from->setSpecialExitLock( id_to, _dir, false );
pHost->mpMap->mMapGraphNeedsUpdate = true;
}
return 0;
}
Expand Down Expand Up @@ -8232,7 +8279,6 @@ int TLuaInterpreter::removeSpecialExit( lua_State * L )
if( pR )
{
pR->setSpecialExit( -1, _dir );
pHost->mpMap->mMapGraphNeedsUpdate = true;
}
return 0;
}
Expand Down Expand Up @@ -8335,7 +8381,6 @@ int TLuaInterpreter::clearSpecialExits( lua_State * L )
if( pR )
{
pR->clearSpecialExits();
pHost->mpMap->mMapGraphNeedsUpdate = true;
}
return 0;
}
Expand Down Expand Up @@ -11546,6 +11591,7 @@ void TLuaInterpreter::initLuaGlobals()
lua_register( pGlobalLua, "openWebPage", TLuaInterpreter::openWebPage);
lua_register( pGlobalLua, "getRoomUserDataKeys", TLuaInterpreter::getRoomUserDataKeys );
lua_register( pGlobalLua, "getAllRoomUserData", TLuaInterpreter::getAllRoomUserData );
lua_register( pGlobalLua, "getAllRoomEntrances", TLuaInterpreter::getAllRoomEntrances );



Expand Down
1 change: 1 addition & 0 deletions src/TLuaInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ Q_OBJECT
static int openWebPage( lua_State * L );
static int getRoomUserDataKeys( lua_State * L );
static int getAllRoomUserData( lua_State * L );
static int getAllRoomEntrances( lua_State * L );


std::list<std::string> mCaptureGroupList;
Expand Down
16 changes: 8 additions & 8 deletions src/TMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ int TMap::createNewRoomID()

bool TMap::setExit( int from, int to, int dir )
{
// FIXME: This along with TRoom->setExit need to be unified to a controller.
TRoom * pR = mpRoomDB->getRoom( from );
TRoom * pR_to = mpRoomDB->getRoom( to );

Expand Down Expand Up @@ -337,13 +338,14 @@ bool TMap::setExit( int from, int to, int dir )
return false;
}
pA->determineAreaExitsOfRoom(pR->getId());
mpRoomDB->updateEntranceMap(pR);
return ret;
}

void TMap::init( Host * pH )
{
// init areas
QTime _time;
QElapsedTimer _time;
_time.start();

if( version < 14 ) {
Expand Down Expand Up @@ -399,7 +401,7 @@ void TMap::init( Host * pH )
}
}
}
qDebug("TMap::init() Initialize run time:%i milli-seconds.", _time.elapsed() );
qDebug() << "TMap::init() Initialize run time:" << _time.nsecsElapsed() * 1.0e-9 << "sec.";
}


Expand Down Expand Up @@ -1032,14 +1034,14 @@ bool TMap::serialize( QDataStream & ofs )
ofs << pR->getExitWeights();
ofs << pR->doors;
}

return true;
}

bool TMap::restore(QString location)
{
qDebug()<<"restoring map of profile:"<<mpHost->getName()<<" url:"<<mpHost->getUrl();
QTime _time; _time.start();
QElapsedTimer _time;
_time.start();
QString folder;
QStringList entries;
qDebug()<<"RESTORING MAP";
Expand Down Expand Up @@ -1192,10 +1194,8 @@ bool TMap::restore(QString location)
int i;
ifs >> i;
TRoom * pT = new TRoom(mpRoomDB);
mpRoomDB->restoreSingleRoom( ifs, i, pT );
pT->restore( ifs, i, version );


mpRoomDB->restoreSingleRoom( ifs, i, pT );
}
customEnvColors[257] = mpHost->mRed_2;
customEnvColors[258] = mpHost->mGreen_2;
Expand All @@ -1213,7 +1213,7 @@ bool TMap::restore(QString location)
customEnvColors[270] = mpHost->mLightCyan_2;
customEnvColors[271] = mpHost->mLightWhite_2;
customEnvColors[272] = mpHost->mLightBlack_2;
qDebug()<<"LOADED rooms:"<<mpRoomDB->size()<<" loading time:"<<_time.elapsed();
qDebug() << "TMap::restore() Loaded" << mpRoomDB->size() << "rooms in:" << _time.nsecsElapsed()* 1.0e-9 << "sec.";
if( canRestore )
{
return true;
Expand Down
55 changes: 37 additions & 18 deletions src/TRoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QDataStream>
#include <QDebug>
#include <QStringBuilder>
#include <QTime>
#include <QElapsedTimer>
#include "post_guard.h"


Expand Down Expand Up @@ -70,10 +70,16 @@ TRoom::TRoom(TRoomDB * pRDB)

TRoom::~TRoom()
{
QTime timer;
static double cumulativeMean = 0.0;
static quint64 runCount = 0 ;
QElapsedTimer timer;
timer.start();
mpRoomDB->__removeRoom( id );
qDebug()<<"room destructor took"<<timer.elapsed();
quint64 thisTime = timer.nsecsElapsed();
cumulativeMean += ( ( (thisTime * 1.0e-9) - cumulativeMean) / ++runCount );
if( runCount % 1000 == 0 ) {
qDebug()<<"TRoom::~TRoom() took" << thisTime * 1.0e-9 << "Sec this time and after" << runCount <<"times the average is" << cumulativeMean << "Sec.";
}
}

bool TRoom::hasExitStub(int direction)
Expand Down Expand Up @@ -225,7 +231,7 @@ bool TRoom::setArea( int areaID, bool isToDeferAreaRelatedRecalculations )
pA->addRoom( id );

dirtyAreas.insert( pA );
pA->mIsDirty;
pA->mIsDirty = true;

if( ! isToDeferAreaRelatedRecalculations ) {
QSetIterator<TArea *> itpArea = dirtyAreas;
Expand All @@ -243,21 +249,24 @@ bool TRoom::setArea( int areaID, bool isToDeferAreaRelatedRecalculations )

bool TRoom::setExit( int to, int direction )
{
// FIXME: This along with TRoom->setExit need to be unified to a controller.
switch(direction){
case DIR_NORTH: north = to; return true; break;
case DIR_NORTHEAST: northeast = to; return true; break;
case DIR_NORTHWEST: northwest = to; return true; break;
case DIR_EAST: east = to; return true; break;
case DIR_WEST: west = to; return true; break;
case DIR_SOUTH: south = to; return true; break;
case DIR_SOUTHEAST: southeast = to; return true; break;
case DIR_SOUTHWEST: southwest = to; return true; break;
case DIR_UP: up = to; return true; break;
case DIR_DOWN: down = to; return true; break;
case DIR_IN: in = to; return true; break;
case DIR_OUT: out = to; return true;
}
return false;
case DIR_NORTH: north = to; break;
case DIR_NORTHEAST: northeast = to; break;
case DIR_NORTHWEST: northwest = to; break;
case DIR_EAST: east = to; break;
case DIR_WEST: west = to; break;
case DIR_SOUTH: south = to; break;
case DIR_SOUTHEAST: southeast = to; break;
case DIR_SOUTHWEST: southwest = to; break;
case DIR_UP: up = to; break;
case DIR_DOWN: down = to; break;
case DIR_IN: in = to; break;
case DIR_OUT: out = to; break;
default: return false;
}
mpRoomDB->updateEntranceMap(this);
return true;
}

bool TRoom::hasExit( int direction )
Expand Down Expand Up @@ -549,7 +558,15 @@ void TRoom::setSpecialExit( int to, const QString& cmd )
pA->determineAreaExitsOfRoom( id );
// This updates the (TArea *)->exits map even for exit REMOVALS
}
mpRoomDB->updateEntranceMap(this);
mpRoomDB->mpMap->mMapGraphNeedsUpdate = true;
}

void TRoom::clearSpecialExits()
{
other.clear();
mpRoomDB->updateEntranceMap(this);
mpRoomDB->mpMap->mMapGraphNeedsUpdate = true;
}

void TRoom::removeAllSpecialExitsToRoom( int _id )
Expand All @@ -569,6 +586,8 @@ void TRoom::removeAllSpecialExitsToRoom( int _id )
{
pA->determineAreaExitsOfRoom( id );
}
mpRoomDB->updateEntranceMap(this);
mpRoomDB->mpMap->mMapGraphNeedsUpdate = true;
}

void TRoom::calcRoomDimensions()
Expand Down
2 changes: 1 addition & 1 deletion src/TRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TRoom
bool hasSpecialExitLock( int, const QString& );
void removeAllSpecialExitsToRoom(int _id );
void setSpecialExit( int to, const QString& cmd );
void clearSpecialExits() { other.clear(); }
void clearSpecialExits();
const QMultiMap<int, QString> & getOtherMap() const { return other; }
const QMap<QString, int> & getExitWeights() const { return exitWeights; }
void setExitWeight(const QString& cmd, int w );
Expand Down
Loading

0 comments on commit 6499130

Please sign in to comment.