Preview rendering seems to work now qmlfrontend
authorunc0rr
Mon, 25 Dec 2017 00:58:47 +0100
branchqmlfrontend
changeset 12865 e33bcb9d5e9c
parent 12864 a03f245243b0
child 12866 488782d9aba9
Preview rendering seems to work now
hedgewars/hwengine.pas
hedgewars/uFLIPC.pas
hedgewars/uFLTypes.pas
hedgewars/uIO.pas
qmlfrontend/flib.h
qmlfrontend/gameconfig.cpp
qmlfrontend/gameconfig.h
qmlfrontend/hwengine.cpp
qmlfrontend/main.cpp
--- a/hedgewars/hwengine.pas	Sun Dec 24 16:56:22 2017 +0100
+++ b/hedgewars/hwengine.pas	Mon Dec 25 00:58:47 2017 +0100
@@ -580,14 +580,12 @@
 end;
 
 function EngineThread(p: pointer): Longint; cdecl; export;
-var e: TFLIBEvent;
 begin
     if GameType = gmtLandPreview then
         GenLandPreview()
     else Game();
 
-    e:= flibGameFinished;
-    sendUI(mtFlibEvent, @e, sizeof(e));
+    sendUI(mtGameFinished, nil, 0);
     EngineThread:= 0
 end;
 
--- a/hedgewars/uFLIPC.pas	Sun Dec 24 16:56:22 2017 +0100
+++ b/hedgewars/uFLIPC.pas	Mon Dec 25 00:58:47 2017 +0100
@@ -173,6 +173,7 @@
     msg.str[0]:= #0;
     msg.len:= len;
     msg.buf:= GetMem(len);
+
     Move(p^, msg.buf^, len);
     ipcSend(msg, queueEngine)
 end;
--- a/hedgewars/uFLTypes.pas	Sun Dec 24 16:56:22 2017 +0100
+++ b/hedgewars/uFLTypes.pas	Mon Dec 25 00:58:47 2017 +0100
@@ -7,15 +7,7 @@
 
 type
     TMessageType = (mtRenderingPreview, mtPreview, mtPreviewHogCount
-                    , mtAddPlayingTeam, mtRemovePlayingTeam
-                    , mtAddTeam, mtRemoveTeam, mtTeamColor, mtHedgehogsNumber
-                    , mtNetData, mtToNet
-                    , mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
-                    , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
-                    , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
-                    , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
-                    , mtNickname, mtSeed, mtTheme, mtScript, mtFeatureSize, mtMapGen
-                    , mtMap, mtMazeSize, mtTemplate, mtAmmo, mtScheme);
+                    , mtToNet, mtGameFinished);
 
     TFLIBEvent = (flibGameFinished);
 
--- a/hedgewars/uIO.pas	Sun Dec 24 16:56:22 2017 +0100
+++ b/hedgewars/uIO.pas	Mon Dec 25 00:58:47 2017 +0100
@@ -123,6 +123,7 @@
     isProcessed: boolean;
 begin
 isProcessed := true;
+system.writeln('IPC:', s);
 
 case s[1] of
      '!': begin AddFileLog('Ping? Pong!'); isPonged:= true; end;
--- a/qmlfrontend/flib.h	Sun Dec 24 16:56:22 2017 +0100
+++ b/qmlfrontend/flib.h	Mon Dec 25 00:58:47 2017 +0100
@@ -11,6 +11,8 @@
     MSG_RENDERINGPREVIEW,
     MSG_PREVIEW,
     MSG_PREVIEWHOGCOUNT,
+    MSG_TONET,
+    MSG_GAMEFINISHED,
 };
 
 typedef union string255_ {
--- a/qmlfrontend/gameconfig.cpp	Sun Dec 24 16:56:22 2017 +0100
+++ b/qmlfrontend/gameconfig.cpp	Mon Dec 25 00:58:47 2017 +0100
@@ -23,6 +23,13 @@
     return m_arguments.size();
 }
 
+const QList<QByteArray> GameConfig::config() const
+{
+    QList<QByteArray> cfg = m_cfg;
+    cfg.append("\x01!");
+    return cfg;
+}
+
 void GameConfig::clear()
 {
     m_arguments.clear();
--- a/qmlfrontend/gameconfig.h	Sun Dec 24 16:56:22 2017 +0100
+++ b/qmlfrontend/gameconfig.h	Mon Dec 25 00:58:47 2017 +0100
@@ -10,7 +10,7 @@
 
     const char** argv() const;
     int argc() const;
-    const QList<QByteArray> config();
+    const QList<QByteArray> config() const;
 
     void clear();
     void cmdSeed(const QByteArray& seed);
--- a/qmlfrontend/hwengine.cpp	Sun Dec 24 16:56:22 2017 +0100
+++ b/qmlfrontend/hwengine.cpp	Mon Dec 25 00:58:47 2017 +0100
@@ -2,6 +2,7 @@
 
 #include <QDebug>
 #include <QLibrary>
+#include <QQmlEngine>
 
 extern "C" {
 RunEngine_t* flibRunEngine;
@@ -46,6 +47,20 @@
     flibFree();
 }
 
+static QObject* hwengine_singletontype_provider(QQmlEngine* engine, QJSEngine* scriptEngine)
+{
+    Q_UNUSED(scriptEngine)
+
+    HWEngine* hwengine = new HWEngine(engine);
+    return hwengine;
+}
+
+void HWEngine::exposeToQML()
+{
+    qDebug("HWEngine::exposeToQML");
+    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
+}
+
 void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
 {
     HWEngine* obj = reinterpret_cast<HWEngine*>(context);
@@ -60,23 +75,42 @@
 {
     switch (mt) {
     case MSG_RENDERINGPREVIEW: {
+        qDebug("MSG_RENDERINGPREVIEW");
         emit previewIsRendering();
         break;
     }
     case MSG_PREVIEW: {
+        qDebug("MSG_PREVIEW");
         emit previewImageChanged();
         break;
     }
     case MSG_PREVIEWHOGCOUNT: {
+        qDebug("MSG_PREVIEWHOGCOUNT");
         emit previewHogCountChanged((quint8)msg.data()[0]);
         break;
     }
+    case MSG_TONET: {
+        qDebug("MSG_TONET");
+        break;
+    }
+    case MSG_GAMEFINISHED: {
+        qDebug("MSG_GAMEFINISHED");
+        break;
+    }
     }
 }
 
 void HWEngine::getPreview()
 {
-    m_runQueue.append(GameConfig());
+    GameConfig cfg;
+    cfg.cmdSeed("superseed");
+    m_runQueue.append(cfg);
+    flibIpcSetEngineBarrier();
+    for (const QByteArray& b : m_runQueue[0].config()) {
+        qDebug() << "[frontend] sending msg of size" << b.size();
+        flibIpcToEngineRaw(b.data(), b.size());
+    }
+    flibIpcRemoveBarrierFromEngineQueue();
     flibRunEngine(m_runQueue[0].argc(), m_runQueue[0].argv());
 }
 
--- a/qmlfrontend/main.cpp	Sun Dec 24 16:56:22 2017 +0100
+++ b/qmlfrontend/main.cpp	Mon Dec 25 00:58:47 2017 +0100
@@ -3,15 +3,18 @@
 
 #include "hwengine.h"
 
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
 {
-  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
-  QGuiApplication app(argc, argv);
+    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+    QGuiApplication app(argc, argv);
+
+    QQmlApplicationEngine engine;
 
-  QQmlApplicationEngine engine;
-  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
-  if (engine.rootObjects().isEmpty())
-    return -1;
+    HWEngine::exposeToQML();
 
-  return app.exec();
+    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
+    if (engine.rootObjects().isEmpty())
+        return -1;
+
+    return app.exec();
 }