qmlFrontend/hwengine.cpp
branchqmlfrontend
changeset 10428 7c25297720f1
parent 10426 727a154cf784
child 10430 899a30018ede
--- a/qmlFrontend/hwengine.cpp	Sun Sep 28 00:18:01 2014 +0400
+++ b/qmlFrontend/hwengine.cpp	Sun Sep 28 00:49:04 2014 +0400
@@ -8,9 +8,9 @@
 #include "previewimageprovider.h"
 
 extern "C" {
-    RunEngine_t *RunEngine;
-    registerPreviewCallback_t *registerPreviewCallback;
-    ipcToEngine_t *ipcToEngine;
+    RunEngine_t *flibRunEngine;
+    registerGUIMessagesCallback_t *flibRegisterGUIMessagesCallback;
+    getPreview_t *flibGetPreview;
     flibInit_t *flibInit;
     flibFree_t *flibFree;
 }
@@ -24,14 +24,14 @@
     if(!hwlib.load())
         qWarning() << "Engine library not found" << hwlib.errorString();
 
-    RunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
-    registerPreviewCallback = (registerPreviewCallback_t*) hwlib.resolve("registerIPCCallback");
-    ipcToEngine = (ipcToEngine_t*) hwlib.resolve("ipcToEngine");
+    flibRunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
+    flibRegisterGUIMessagesCallback = (registerGUIMessagesCallback_t*) hwlib.resolve("registerGUIMessagesCallback");
+    flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
     flibInit = (flibInit_t*) hwlib.resolve("flibInit");
     flibFree = (flibFree_t*) hwlib.resolve("flibFree");
 
     flibInit(".", "~/.hedgewars");
-    registerPreviewCallback(this, &enginePreviewCallback);
+    flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
 }
 
 HWEngine::~HWEngine()
@@ -39,23 +39,10 @@
     flibFree();
 }
 
-void HWEngine::run()
+void HWEngine::getPreview()
 {
-    m_argsList.clear();
-    m_argsList << "";
-    m_argsList << "--internal";
-    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].constData();
-
-    m_seed = QUuid::createUuid().toString();
-
-    RunEngine(m_args.size(), m_args.data());
-    sendIPC("eseed " + m_seed.toLatin1());
-    sendIPC("e$mapgen 0");
-    sendIPC("!");
+    //m_seed = QUuid::createUuid().toString();
+    flibGetPreview();
 }
 
 static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
@@ -72,15 +59,8 @@
     qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
 }
 
-void HWEngine::sendIPC(const QByteArray & b)
-{
-    quint8 len = b.size() > 255 ? 255 : b.size();
-    qDebug() << "sendIPC: len = " << len;
 
-    ipcToEngine(b.constData(), len);
-}
-
-void HWEngine::enginePreviewCallback(void *context, const char * msg, quint32 len)
+void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len)
 {
     HWEngine * obj = (HWEngine *)context;
     QByteArray b = QByteArray::fromRawData(msg, len);