QTfrontend/net/tcpBase.cpp
changeset 8310 a98c349bc06b
parent 8082 675372256a01
child 8363 0b4ac686fc44
child 8635 c1c6b815691e
equal deleted inserted replaced
8309:edcfb5e43245 8310:a98c349bc06b
    27 
    27 
    28 #include "hwconsts.h"
    28 #include "hwconsts.h"
    29 
    29 
    30 #ifdef HWLIBRARY
    30 #ifdef HWLIBRARY
    31 extern "C" void Game(char**arguments);
    31 extern "C" void Game(char**arguments);
    32 
    32 extern "C" void GenLandPreview(int port);
    33 //NOTE: most likely subclassing QThread is wrong
    33 
    34 class EngineThread : public QThread
    34 
    35 {
    35 EngineInstance::EngineInstance(QObject *parent)
    36 protected:
    36     : QObject(parent)
    37     void run();
    37 {
    38 };
    38     port = 0;
    39 
    39 }
    40 void EngineThread::run()
    40 
    41 {
    41 EngineInstance::~EngineInstance()
    42     char *args[12];
    42 {
    43     args[0] = "1";      //cShowFPS
    43 }
    44     args[1] = "65000";  //ipcPort
    44 
    45     args[2] = "1024";   //cScreenWidth
    45 void EngineInstance::start()
    46     args[3] = "768";    //cScreenHeight
    46 {
    47     args[4] = "0";      //cReducedQuality
    47 #if 0
    48     args[5] = "en.txt"; //cLocaleFName
    48     char *args[11];
    49     args[6] = "koda";   //UserNick
    49     args[0] = "65000";  //ipcPort
    50     args[7] = "1";      //SetSound
    50     args[1] = "1024";   //cScreenWidth
    51     args[8] = "1";      //SetMusic
    51     args[2] = "768";    //cScreenHeight
    52     args[9] = "0";      //cAltDamage
    52     args[3] = "0";      //cReducedQuality
    53     args[10]= "../Resources/hedgewars/Data";   //cPathPrefix
    53     args[4] = "en.txt"; //cLocaleFName
    54     args[11]= NULL;     //recordFileName
    54     args[5] = "koda";   //UserNick
       
    55     args[6] = "1";      //SetSound
       
    56     args[7] = "1";      //SetMusic
       
    57     args[8] = "0";      //cAltDamage
       
    58     args[9]= datadir->absolutePath().toAscii().data(); //cPathPrefix
       
    59     args[10]= NULL;     //recordFileName
    55     Game(args);
    60     Game(args);
    56 }
    61 #endif
       
    62     GenLandPreview(port);
       
    63 }
       
    64 
    57 #endif
    65 #endif
    58 
    66 
    59 QList<TCPBase*> srvsList;
    67 QList<TCPBase*> srvsList;
    60 QPointer<QTcpServer> TCPBase::IPCServer(0);
    68 QPointer<QTcpServer> TCPBase::IPCServer(0);
    61 
    69 
    64     // make sure this object is not in the server list anymore
    72     // make sure this object is not in the server list anymore
    65     srvsList.removeOne(this);
    73     srvsList.removeOne(this);
    66 
    74 
    67     if (IPCSocket)
    75     if (IPCSocket)
    68         IPCSocket->deleteLater();
    76         IPCSocket->deleteLater();
       
    77 
    69 }
    78 }
    70 
    79 
    71 TCPBase::TCPBase(bool demoMode, QObject *parent) :
    80 TCPBase::TCPBase(bool demoMode, QObject *parent) :
    72     QObject(parent),
    81     QObject(parent),
    73     m_hasStarted(false),
    82     m_hasStarted(false),
    88             deniedMsg.exec();
    97             deniedMsg.exec();
    89 
    98 
    90             exit(0); // FIXME - should be graceful exit here (lower Critical -> Warning above when implemented)
    99             exit(0); // FIXME - should be graceful exit here (lower Critical -> Warning above when implemented)
    91         }
   100         }
    92     }
   101     }
    93 #ifdef HWLIBRARY
   102 
    94     ipc_port=65000; //HACK
       
    95 #else
       
    96     ipc_port=IPCServer->serverPort();
   103     ipc_port=IPCServer->serverPort();
    97 #endif
       
    98 }
   104 }
    99 
   105 
   100 void TCPBase::NewConnection()
   106 void TCPBase::NewConnection()
   101 {
   107 {
   102     if(IPCSocket)
   108     if(IPCSocket)
   116 {
   122 {
   117     connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   123     connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   118     IPCSocket = 0;
   124     IPCSocket = 0;
   119 
   125 
   120 #ifdef HWLIBRARY
   126 #ifdef HWLIBRARY
   121     EngineThread engineThread;// = new EngineThread(this);
   127     QThread *thread = new QThread;
   122     engineThread.start();
   128     EngineInstance *instance = new EngineInstance;
       
   129     instance->port = IPCServer->serverPort();
       
   130 
       
   131     instance->moveToThread(thread);
       
   132 
       
   133     connect(thread, SIGNAL(started()), instance, SLOT(start(void)));
       
   134     connect(instance, SIGNAL(finished()), thread, SLOT(quit()));
       
   135     connect(instance, SIGNAL(finished()), instance, SLOT(deleteLater()));
       
   136     connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater()));
       
   137     thread->start();
   123 #else
   138 #else
   124     QProcess * process;
   139     QProcess * process;
   125     process = new QProcess();
   140     process = new QProcess();
   126     connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
   141     connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
   127     QStringList arguments=getArguments();
   142     QStringList arguments=getArguments();