--- a/QTfrontend/hwmap.cpp Tue Sep 26 11:53:12 2006 +0000
+++ b/QTfrontend/hwmap.cpp Tue Sep 26 17:50:14 2006 +0000
@@ -4,11 +4,24 @@
#include <QMessageBox>
+#include <QMutex>
+#include <QDebug>
+
+#include <QList>
+
+int HWMap::isBusy(0); // initialize static variable
+QList<HWMap*> srvsList;
+QMutex tcpSrvMut;
+
HWMap::HWMap() :
m_isStarted(false)
{
}
+HWMap::~HWMap()
+{
+}
+
void HWMap::getImage(std::string seed)
{
m_seed=seed;
@@ -24,9 +37,17 @@
IPCSocket->deleteLater();
IPCSocket = 0;
IPCServer->close();
- deleteLater();
-
+ //deleteLater();
+
+
+ tcpSrvMut.lock();
+ if(isBusy) --isBusy;
+ //if(!isBusy) srvsList.pop_front();//lastStarted=0;
+ tcpSrvMut.unlock();
+ qDebug() << "image emitted with seed " << QString(m_seed.c_str());
emit ImageReceived(im);
+ readbuffer.clear();
+ emit isReadyNow();
}
void HWMap::ClientRead()
@@ -66,8 +87,40 @@
.arg(error) + bindir->absolutePath() + "/hwengine)");
}
+void HWMap::tcpServerReady()
+{
+ qDebug() << "received signal, i am " << this << ";";
+ qDebug() << srvsList.front() << " disconnected from " << *(++srvsList.begin());
+ tcpSrvMut.lock();
+ disconnect(srvsList.front(), SIGNAL(isReadyNow()), *(++srvsList.begin()), SLOT(tcpServerReady()));
+ srvsList.pop_front();
+ tcpSrvMut.unlock();
+
+ RealStart();
+}
+
void HWMap::Start()
{
+ tcpSrvMut.lock();
+ if(!isBusy) {
+ qDebug() << "notBusy, i am " << this;
+ ++isBusy;
+ srvsList.push_back(this);
+ tcpSrvMut.unlock();
+ } else {
+ qDebug() << "Busy, connected " << srvsList.back() << " to " << this;
+ connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+ srvsList.push_back(this);
+ //deleteLater();
+ tcpSrvMut.unlock();
+ return;
+ }
+
+ RealStart();
+}
+
+void HWMap::RealStart()
+{
IPCServer = new QTcpServer(this);
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
IPCServer->setMaxPendingConnections(1);
--- a/QTfrontend/hwmap.h Tue Sep 26 11:53:12 2006 +0000
+++ b/QTfrontend/hwmap.h Tue Sep 26 17:50:14 2006 +0000
@@ -53,12 +53,17 @@
public:
HWMap();
+ virtual ~HWMap();
void getImage(std::string seed);
signals:
void ImageReceived(const QImage newImage);
+ void isReadyNow();
private:
+ static int isBusy;
+ void RealStart();
+
bool m_isStarted;
std::string m_seed;
QTcpServer * IPCServer;
@@ -75,6 +80,8 @@
void ClientDisconnect();
void ClientRead();
void StartProcessError(QProcess::ProcessError error);
+
+ void tcpServerReady();
};
#endif // _HWMAP_INCLUDED
--- a/QTfrontend/main.cpp Tue Sep 26 11:53:12 2006 +0000
+++ b/QTfrontend/main.cpp Tue Sep 26 17:50:14 2006 +0000
@@ -73,7 +73,7 @@
Translator.load(":/translations/hedgewars_" + QLocale::system().name());
app.installTranslator(&Translator);
- QDir mydir(".");
+ QDir mydir("/home/igor/sources/hedgewars");
mydir.cd("bin");
bindir = new QDir(mydir);
--- a/QTfrontend/mapContainer.cpp Tue Sep 26 11:53:12 2006 +0000
+++ b/QTfrontend/mapContainer.cpp Tue Sep 26 17:50:14 2006 +0000
@@ -37,6 +37,8 @@
#include <QBuffer>
#include <QUuid>
+#include <QDebug>
+
HWMapContainer::HWMapContainer(QWidget * parent) :
QWidget(parent), mainLayout(this)
{
@@ -44,11 +46,13 @@
imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
mainLayout.addWidget(imageButt);
connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage()));
+ connect(&m_hwmap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
changeImage();
}
void HWMapContainer::setImage(const QImage newImage)
{
+ qDebug() << "image received";
// unfortunately QPixmap::fromImage doesn't work
// with this image in current (4.1.4) version of QT
QByteArray ba;
@@ -65,9 +69,8 @@
void HWMapContainer::changeImage()
{
m_seed = QUuid::createUuid().toString();
- pMap=new HWMap();
- connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
- pMap->getImage(m_seed.toStdString());
+ //pMap=new HWMap();
+ m_hwmap.getImage(m_seed.toStdString());
}
QString HWMapContainer::getCurrentSeed() const
--- a/QTfrontend/mapContainer.h Tue Sep 26 11:53:12 2006 +0000
+++ b/QTfrontend/mapContainer.h Tue Sep 26 17:50:14 2006 +0000
@@ -61,7 +61,7 @@
private:
QVBoxLayout mainLayout;
QPushButton* imageButt;
- HWMap* pMap;
+ HWMap m_hwmap;
QString m_seed;
};