QTfrontend/net/tcpBase.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8092 08960209db8c
parent 8310 a98c349bc06b
--- a/QTfrontend/net/tcpBase.cpp	Tue Dec 18 20:48:37 2012 +0400
+++ b/QTfrontend/net/tcpBase.cpp	Fri Jan 04 21:44:40 2013 +0400
@@ -29,31 +29,39 @@
 
 #ifdef HWLIBRARY
 extern "C" void Game(char**arguments);
+extern "C" void GenLandPreview(int port);
 
-//NOTE: most likely subclassing QThread is wrong
-class EngineThread : public QThread
+
+EngineInstance::EngineInstance(QObject *parent)
+    : QObject(parent)
 {
-protected:
-    void run();
-};
+    port = 0;
+}
 
-void EngineThread::run()
+EngineInstance::~EngineInstance()
+{
+}
+
+void EngineInstance::start()
 {
-    char *args[12];
-    args[0] = "1";      //cShowFPS
-    args[1] = "65000";  //ipcPort
-    args[2] = "1024";   //cScreenWidth
-    args[3] = "768";    //cScreenHeight
-    args[4] = "0";      //cReducedQuality
-    args[5] = "en.txt"; //cLocaleFName
-    args[6] = "koda";   //UserNick
-    args[7] = "1";      //SetSound
-    args[8] = "1";      //SetMusic
-    args[9] = "0";      //cAltDamage
-    args[10]= "../Resources/hedgewars/Data";   //cPathPrefix
-    args[11]= NULL;     //recordFileName
+#if 0
+    char *args[11];
+    args[0] = "65000";  //ipcPort
+    args[1] = "1024";   //cScreenWidth
+    args[2] = "768";    //cScreenHeight
+    args[3] = "0";      //cReducedQuality
+    args[4] = "en.txt"; //cLocaleFName
+    args[5] = "koda";   //UserNick
+    args[6] = "1";      //SetSound
+    args[7] = "1";      //SetMusic
+    args[8] = "0";      //cAltDamage
+    args[9]= datadir->absolutePath().toAscii().data(); //cPathPrefix
+    args[10]= NULL;     //recordFileName
     Game(args);
+#endif
+    GenLandPreview(port);
 }
+
 #endif
 
 QList<TCPBase*> srvsList;
@@ -76,8 +84,17 @@
     onEngineStart();
 
 #ifdef HWLIBRARY
-    EngineThread engineThread;// = new EngineThread(this);
-    engineThread.start();
+    QThread *thread = new QThread;
+    EngineInstance *instance = new EngineInstance;
+    instance->port = IPCServer->serverPort();
+
+    instance->moveToThread(thread);
+
+    connect(thread, SIGNAL(started()), instance, SLOT(start(void)));
+    connect(instance, SIGNAL(finished()), thread, SLOT(quit()));
+    connect(instance, SIGNAL(finished()), instance, SLOT(deleteLater()));
+    connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater()));
+    thread->start();
 #else
     QProcess * process;