qmlfrontend/hwengine.cpp
branchqmlfrontend
changeset 12860 e33bcb9d5e9c
parent 12859 a03f245243b0
child 12861 488782d9aba9
equal deleted inserted replaced
12859:a03f245243b0 12860:e33bcb9d5e9c
     1 #include "hwengine.h"
     1 #include "hwengine.h"
     2 
     2 
     3 #include <QDebug>
     3 #include <QDebug>
     4 #include <QLibrary>
     4 #include <QLibrary>
       
     5 #include <QQmlEngine>
     5 
     6 
     6 extern "C" {
     7 extern "C" {
     7 RunEngine_t* flibRunEngine;
     8 RunEngine_t* flibRunEngine;
     8 ipcToEngineRaw_t* flibIpcToEngineRaw;
     9 ipcToEngineRaw_t* flibIpcToEngineRaw;
     9 ipcSetEngineBarrier_t* flibIpcSetEngineBarrier;
    10 ipcSetEngineBarrier_t* flibIpcSetEngineBarrier;
    44 HWEngine::~HWEngine()
    45 HWEngine::~HWEngine()
    45 {
    46 {
    46     flibFree();
    47     flibFree();
    47 }
    48 }
    48 
    49 
       
    50 static QObject* hwengine_singletontype_provider(QQmlEngine* engine, QJSEngine* scriptEngine)
       
    51 {
       
    52     Q_UNUSED(scriptEngine)
       
    53 
       
    54     HWEngine* hwengine = new HWEngine(engine);
       
    55     return hwengine;
       
    56 }
       
    57 
       
    58 void HWEngine::exposeToQML()
       
    59 {
       
    60     qDebug("HWEngine::exposeToQML");
       
    61     qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
       
    62 }
       
    63 
    49 void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
    64 void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
    50 {
    65 {
    51     HWEngine* obj = reinterpret_cast<HWEngine*>(context);
    66     HWEngine* obj = reinterpret_cast<HWEngine*>(context);
    52     QByteArray b = QByteArray(msg, len);
    67     QByteArray b = QByteArray(msg, len);
    53 
    68 
    58 
    73 
    59 void HWEngine::engineMessageHandler(MessageType mt, const QByteArray& msg)
    74 void HWEngine::engineMessageHandler(MessageType mt, const QByteArray& msg)
    60 {
    75 {
    61     switch (mt) {
    76     switch (mt) {
    62     case MSG_RENDERINGPREVIEW: {
    77     case MSG_RENDERINGPREVIEW: {
       
    78         qDebug("MSG_RENDERINGPREVIEW");
    63         emit previewIsRendering();
    79         emit previewIsRendering();
    64         break;
    80         break;
    65     }
    81     }
    66     case MSG_PREVIEW: {
    82     case MSG_PREVIEW: {
       
    83         qDebug("MSG_PREVIEW");
    67         emit previewImageChanged();
    84         emit previewImageChanged();
    68         break;
    85         break;
    69     }
    86     }
    70     case MSG_PREVIEWHOGCOUNT: {
    87     case MSG_PREVIEWHOGCOUNT: {
       
    88         qDebug("MSG_PREVIEWHOGCOUNT");
    71         emit previewHogCountChanged((quint8)msg.data()[0]);
    89         emit previewHogCountChanged((quint8)msg.data()[0]);
       
    90         break;
       
    91     }
       
    92     case MSG_TONET: {
       
    93         qDebug("MSG_TONET");
       
    94         break;
       
    95     }
       
    96     case MSG_GAMEFINISHED: {
       
    97         qDebug("MSG_GAMEFINISHED");
    72         break;
    98         break;
    73     }
    99     }
    74     }
   100     }
    75 }
   101 }
    76 
   102 
    77 void HWEngine::getPreview()
   103 void HWEngine::getPreview()
    78 {
   104 {
    79     m_runQueue.append(GameConfig());
   105     GameConfig cfg;
       
   106     cfg.cmdSeed("superseed");
       
   107     m_runQueue.append(cfg);
       
   108     flibIpcSetEngineBarrier();
       
   109     for (const QByteArray& b : m_runQueue[0].config()) {
       
   110         qDebug() << "[frontend] sending msg of size" << b.size();
       
   111         flibIpcToEngineRaw(b.data(), b.size());
       
   112     }
       
   113     flibIpcRemoveBarrierFromEngineQueue();
    80     flibRunEngine(m_runQueue[0].argc(), m_runQueue[0].argv());
   114     flibRunEngine(m_runQueue[0].argc(), m_runQueue[0].argv());
    81 }
   115 }
    82 
   116 
    83 void HWEngine::runQuickGame()
   117 void HWEngine::runQuickGame()
    84 {
   118 {