And more refactoring... qmlfrontend
authorunc0rr
Sun, 24 Dec 2017 16:56:22 +0100
branchqmlfrontend
changeset 12859 a03f245243b0
parent 12858 0c6fb706f747
child 12860 e33bcb9d5e9c
And more refactoring...
hedgewars/hwLibrary.pas
hedgewars/uFLIPC.pas
qmlfrontend/flib.h
qmlfrontend/gameconfig.cpp
qmlfrontend/gameconfig.h
qmlfrontend/hwengine.cpp
--- a/hedgewars/hwLibrary.pas	Sun Dec 24 00:44:16 2017 +0100
+++ b/hedgewars/hwLibrary.pas	Sun Dec 24 16:56:22 2017 +0100
@@ -60,7 +60,10 @@
     registerUIMessagesCallback,
     flibInit,
     flibFree,
-    queueExecution
+    ipcToEngineRaw,
+    ipcSetEngineBarrier,
+    ipcRemoveBarrierFromEngineQueue,
+    RunEngine
     ;
 
 begin
--- a/hedgewars/uFLIPC.pas	Sun Dec 24 00:44:16 2017 +0100
+++ b/hedgewars/uFLIPC.pas	Sun Dec 24 16:56:22 2017 +0100
@@ -6,9 +6,9 @@
 procedure freeIPC;
 
 procedure ipcToEngine(s: shortstring);
-procedure ipcToEngineRaw(p: pointer; len: Longword);
-procedure ipcSetEngineBarrier();
-procedure ipcRemoveBarrierFromEngineQueue();
+procedure ipcToEngineRaw(p: pointer; len: Longword); cdecl;
+procedure ipcSetEngineBarrier(); cdecl;
+procedure ipcRemoveBarrierFromEngineQueue(); cdecl;
 //function  ipcReadFromEngine: shortstring;
 //function  ipcCheckFromEngine: boolean;
 
@@ -105,7 +105,7 @@
     ipcSend(msg, queueFrontend)
 end;
 
-procedure ipcSetEngineBarrier();
+procedure ipcSetEngineBarrier(); cdecl;
 begin
     SDL_LockMutex(queueEngine^.mut);
 
@@ -114,7 +114,7 @@
     SDL_UnlockMutex(queueEngine^.mut);
 end;
 
-procedure ipcRemoveBarrierFromEngineQueue();
+procedure ipcRemoveBarrierFromEngineQueue(); cdecl;
 var pmsg, t: PIPCMessage;
     q: PIPCQueue;
 begin
@@ -167,7 +167,7 @@
     SDL_UnlockMutex(q^.mut);
 end;
 
-procedure ipcToEngineRaw(p: pointer; len: Longword);
+procedure ipcToEngineRaw(p: pointer; len: Longword); cdecl;
 var msg: TIPCMessage;
 begin
     msg.str[0]:= #0;
--- a/qmlfrontend/flib.h	Sun Dec 24 00:44:16 2017 +0100
+++ b/qmlfrontend/flib.h	Sun Dec 24 16:56:22 2017 +0100
@@ -24,6 +24,10 @@
 } string255;
 
 typedef void RunEngine_t(int argc, const char** argv);
+typedef void ipcToEngineRaw_t(const char* msg, uint32_t len);
+typedef void ipcSetEngineBarrier_t();
+typedef void ipcRemoveBarrierFromEngineQueue_t();
+
 typedef void registerUIMessagesCallback_t(void* context, void (*)(void* context, MessageType mt, const char* msg, uint32_t len));
 typedef void flibInit_t(const char* localPrefix, const char* userPrefix);
 typedef void flibFree_t();
--- a/qmlfrontend/gameconfig.cpp	Sun Dec 24 00:44:16 2017 +0100
+++ b/qmlfrontend/gameconfig.cpp	Sun Dec 24 16:56:22 2017 +0100
@@ -1,6 +1,46 @@
 #include "gameconfig.h"
 
-GameConfig::GameConfig(QObject *parent) : QObject(parent)
+GameConfig::GameConfig()
+{
+    m_arguments
+        << ""
+        << "--internal"
+        << "--landpreview";
+}
+
+const char** GameConfig::argv() const
+{
+    m_argv.resize(m_arguments.size());
+
+    for (int i = 0; i < m_arguments.size(); ++i)
+        m_argv[i] = m_arguments[i].data();
+
+    return m_argv.data();
+}
+
+int GameConfig::argc() const
 {
+    return m_arguments.size();
+}
 
+void GameConfig::clear()
+{
+    m_arguments.clear();
+    m_cfg.clear();
 }
+
+void GameConfig::cmdSeed(const QByteArray& seed)
+{
+    cfgAppend("eseed " + seed);
+}
+
+void GameConfig::cmdMapgen(int mapgen)
+{
+    cfgAppend("e$mapgen " + QByteArray::number(mapgen));
+}
+
+void GameConfig::cfgAppend(const QByteArray& cmd)
+{
+    quint8 len = cmd.size();
+    m_cfg.append(QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1) + cmd);
+}
--- a/qmlfrontend/gameconfig.h	Sun Dec 24 00:44:16 2017 +0100
+++ b/qmlfrontend/gameconfig.h	Sun Dec 24 16:56:22 2017 +0100
@@ -1,17 +1,27 @@
 #ifndef GAMECONFIG_H
 #define GAMECONFIG_H
 
-#include <QObject>
+#include <QList>
+#include <QVector>
 
-class GameConfig : public QObject
-{
-  Q_OBJECT
+class GameConfig {
 public:
-  explicit GameConfig(QObject *parent = nullptr);
+    explicit GameConfig();
+
+    const char** argv() const;
+    int argc() const;
+    const QList<QByteArray> config();
 
-signals:
+    void clear();
+    void cmdSeed(const QByteArray& seed);
+    void cmdMapgen(int mapgen);
 
-public slots:
+private:
+    mutable QVector<const char*> m_argv;
+    QList<QByteArray> m_arguments;
+    QList<QByteArray> m_cfg;
+
+    void cfgAppend(const QByteArray& cmd);
 };
 
-#endif // GAMECONFIG_H
\ No newline at end of file
+#endif // GAMECONFIG_H
--- a/qmlfrontend/hwengine.cpp	Sun Dec 24 00:44:16 2017 +0100
+++ b/qmlfrontend/hwengine.cpp	Sun Dec 24 16:56:22 2017 +0100
@@ -5,6 +5,9 @@
 
 extern "C" {
 RunEngine_t* flibRunEngine;
+ipcToEngineRaw_t* flibIpcToEngineRaw;
+ipcSetEngineBarrier_t* flibIpcSetEngineBarrier;
+ipcRemoveBarrierFromEngineQueue_t* flibIpcRemoveBarrierFromEngineQueue;
 registerUIMessagesCallback_t* flibRegisterUIMessagesCallback;
 flibInit_t* flibInit;
 flibFree_t* flibFree;
@@ -27,6 +30,9 @@
         qWarning() << "Engine library not found" << hwlib.errorString();
 
     flibRunEngine = (RunEngine_t*)hwlib.resolve("RunEngine");
+    flibIpcToEngineRaw = (ipcToEngineRaw_t*)hwlib.resolve("ipcToEngineRaw");
+    flibIpcSetEngineBarrier = (ipcSetEngineBarrier_t*)hwlib.resolve("ipcSetEngineBarrier");
+    flibIpcRemoveBarrierFromEngineQueue = (ipcRemoveBarrierFromEngineQueue_t*)hwlib.resolve("ipcRemoveBarrierFromEngineQueue");
     flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*)hwlib.resolve("registerUIMessagesCallback");
     flibInit = (flibInit_t*)hwlib.resolve("flibInit");
     flibFree = (flibFree_t*)hwlib.resolve("flibFree");
@@ -70,9 +76,8 @@
 
 void HWEngine::getPreview()
 {
-    int argc;
-    const char** argv;
-    flibRunEngine(argc, argv);
+    m_runQueue.append(GameConfig());
+    flibRunEngine(m_runQueue[0].argc(), m_runQueue[0].argv());
 }
 
 void HWEngine::runQuickGame()