15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program; if not, write to the Free Software |
16 * along with this program; if not, write to the Free Software |
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 */ |
18 */ |
19 |
19 |
20 #include "tcpBase.h" |
|
21 |
|
22 #include <QList> |
20 #include <QList> |
23 #include <QImage> |
21 #include <QImage> |
24 #include <QThread> |
22 #include <QThread> |
25 |
23 #include <QApplication> |
|
24 |
|
25 #include "tcpBase.h" |
26 #include "hwconsts.h" |
26 #include "hwconsts.h" |
27 #include "MessageDialog.h" |
27 #include "MessageDialog.h" |
28 |
28 |
29 #ifdef HWLIBRARY |
29 #ifdef HWLIBRARY |
30 extern "C" void Game(char**arguments); |
30 extern "C" { |
31 extern "C" void GenLandPreview(int port); |
31 void RunEngine(int argc, char ** argv); |
|
32 |
|
33 int operatingsystem_parameter_argc; |
|
34 char ** operatingsystem_parameter_argv; |
|
35 } |
32 |
36 |
33 |
37 |
34 EngineInstance::EngineInstance(QObject *parent) |
38 EngineInstance::EngineInstance(QObject *parent) |
35 : QObject(parent) |
39 : QObject(parent) |
36 { |
40 { |
37 port = 0; |
41 |
38 } |
42 } |
39 |
43 |
40 EngineInstance::~EngineInstance() |
44 EngineInstance::~EngineInstance() |
41 { |
45 { |
42 } |
46 } |
43 |
47 |
|
48 void EngineInstance::setArguments(const QStringList & arguments) |
|
49 { |
|
50 m_arguments.clear(); |
|
51 m_arguments << qApp->arguments().at(0).toUtf8(); |
|
52 |
|
53 m_argv.resize(arguments.size() + 1); |
|
54 m_argv[0] = m_arguments.last().data(); |
|
55 |
|
56 int i = 1; |
|
57 foreach(const QString & s, arguments) |
|
58 { |
|
59 m_arguments << s.toUtf8(); |
|
60 m_argv[i] = m_arguments.last().data(); |
|
61 ++i; |
|
62 } |
|
63 } |
|
64 |
44 void EngineInstance::start() |
65 void EngineInstance::start() |
45 { |
66 { |
46 #if 0 |
67 RunEngine(m_argv.size(), m_argv.data()); |
47 char *args[11]; |
|
48 args[0] = "65000"; //ipcPort |
|
49 args[1] = "1024"; //cScreenWidth |
|
50 args[2] = "768"; //cScreenHeight |
|
51 args[3] = "0"; //cReducedQuality |
|
52 args[4] = "en.txt"; //cLocaleFName |
|
53 args[5] = "koda"; //UserNick |
|
54 args[6] = "1"; //SetSound |
|
55 args[7] = "1"; //SetMusic |
|
56 args[8] = "0"; //cAltDamage |
|
57 args[9]= datadir->absolutePath().toAscii().data(); //cPathPrefix |
|
58 args[10]= NULL; //recordFileName |
|
59 Game(args); |
|
60 #endif |
|
61 GenLandPreview(port); |
|
62 } |
68 } |
63 |
69 |
64 #endif |
70 #endif |
65 |
71 |
66 QList<TCPBase*> srvsList; |
72 QList<TCPBase*> srvsList; |
127 { |
133 { |
128 connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
134 connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
129 IPCSocket = 0; |
135 IPCSocket = 0; |
130 |
136 |
131 #ifdef HWLIBRARY |
137 #ifdef HWLIBRARY |
132 QThread *thread = new QThread; |
138 QThread *thread = new QThread(); |
133 EngineInstance *instance = new EngineInstance; |
139 EngineInstance *instance = new EngineInstance(); |
134 instance->port = IPCServer->serverPort(); |
140 instance->setArguments(getArguments()); |
135 |
141 |
136 instance->moveToThread(thread); |
142 instance->moveToThread(thread); |
137 |
143 |
138 connect(thread, SIGNAL(started()), instance, SLOT(start(void))); |
144 connect(thread, SIGNAL(started()), instance, SLOT(start(void))); |
139 connect(instance, SIGNAL(finished()), thread, SLOT(quit())); |
145 connect(instance, SIGNAL(finished()), thread, SLOT(quit())); |
142 thread->start(); |
148 thread->start(); |
143 #else |
149 #else |
144 QProcess * process; |
150 QProcess * process; |
145 process = new QProcess(); |
151 process = new QProcess(); |
146 connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); |
152 connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); |
147 QStringList arguments=getArguments(); |
153 QStringList arguments = getArguments(); |
148 |
154 |
149 #ifdef QT_DEBUG |
155 #ifdef QT_DEBUG |
150 // redirect everything written on stdout/stderr |
156 // redirect everything written on stdout/stderr |
151 process->setProcessChannelMode(QProcess::ForwardedChannels); |
157 process->setProcessChannelMode(QProcess::ForwardedChannels); |
152 #endif |
158 #endif |