qmlFrontend/hwengine.cpp
branchqmlfrontend
changeset 10416 1c301054694d
parent 10404 1baaab44a0b2
child 10418 091d2c0216c3
--- a/qmlFrontend/hwengine.cpp	Fri Sep 19 14:27:41 2014 +0400
+++ b/qmlFrontend/hwengine.cpp	Sat Sep 20 00:56:54 2014 +0400
@@ -5,9 +5,11 @@
 #include "hwengine.h"
 
 extern "C" {
-    void (*RunEngine)(int argc, char ** argv);
+    RunEngine_t *RunEngine;
+    registerIPCCallback_t *registerIPCCallback;
+    ipcToEngine_t *ipcToEngine;
+    flibInit_t *flibInit;
 }
-
 HWEngine::HWEngine(QObject *parent) :
     QObject(parent)
 {
@@ -16,7 +18,13 @@
     if(!hwlib.load())
         qWarning() << "Engine library not found" << hwlib.errorString();
 
-    RunEngine = (void (*)(int, char **))hwlib.resolve("RunEngine");
+    RunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
+    registerIPCCallback = (registerIPCCallback_t*) hwlib.resolve("registerIPCCallback");
+    ipcToEngine = (ipcToEngine_t*) hwlib.resolve("ipcToEngine");
+    flibInit = (flibInit_t*) hwlib.resolve("flibInit");
+
+    flibInit();
+    registerIPCCallback(this, &engineMessageCallback);
 }
 
 HWEngine::~HWEngine()
@@ -26,8 +34,21 @@
 
 void HWEngine::run()
 {
-    char* args[2] = {"", "--help"};
-    RunEngine(2, args);
+    m_argsList.clear();
+    m_argsList << "";
+    m_argsList << "--internal";
+    //m_argsList << "--user-prefix";
+    //m_argsList << cfgdir->absolutePath();
+    //m_argsList << "--prefix";
+    //m_argsList << datadir->absolutePath();
+    m_argsList << "--landpreview";
+
+    m_args.resize(m_argsList.size());
+    for(int i = m_argsList.size() - 1; i >=0; --i)
+        m_args[i] = m_argsList[i].data();
+
+    RunEngine(m_args.size(), m_args.data());
+    sendIPC("!");
 }
 
 static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
@@ -44,3 +65,20 @@
     qDebug("HWEngine::exposeToQML");
     qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
 }
+
+void HWEngine::sendIPC(const QByteArray & b)
+{
+    string255 str;
+    str.len = b.size() > 255 ? 255 : b.size();
+    qDebug() << "semdIPC: len = " << str.len;
+    qCopy(b.data(), &(b.data()[str.len - 1]), &(str.str[0]));
+
+    ipcToEngine(str);
+}
+
+void HWEngine::engineMessageCallback(void *context, string255 str)
+{
+    QByteArray b = QByteArray::fromRawData((const char *)&str.s, str.len + 1);
+
+    qDebug() << "FLIPC in" << b;
+}