qmlfrontend/hwengine.cpp
author unc0rr
Sun, 24 Dec 2017 16:56:22 +0100
branchqmlfrontend
changeset 12859 a03f245243b0
parent 12858 0c6fb706f747
child 12860 e33bcb9d5e9c
permissions -rw-r--r--
And more refactoring...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12857
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     1
#include "hwengine.h"
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     2
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     3
#include <QDebug>
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     4
#include <QLibrary>
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     5
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     6
extern "C" {
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
     7
RunEngine_t* flibRunEngine;
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     8
ipcToEngineRaw_t* flibIpcToEngineRaw;
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     9
ipcSetEngineBarrier_t* flibIpcSetEngineBarrier;
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    10
ipcRemoveBarrierFromEngineQueue_t* flibIpcRemoveBarrierFromEngineQueue;
12857
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    11
registerUIMessagesCallback_t* flibRegisterUIMessagesCallback;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    12
flibInit_t* flibInit;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    13
flibFree_t* flibFree;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    14
passFlibEvent_t* flibPassFlibEvent;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    15
}
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    16
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    17
HWEngine::HWEngine(QQmlEngine* engine, QObject* parent)
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    18
    : QObject(parent)
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    19
    , m_engine(engine)
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    20
{
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    21
    qRegisterMetaType<MessageType>("MessageType");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    22
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    23
#ifdef Q_OS_WIN
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    24
    QLibrary hwlib("./libhwengine.dll");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    25
#else
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    26
    QLibrary hwlib("./libhwengine.so");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    27
#endif
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    28
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    29
    if (!hwlib.load())
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    30
        qWarning() << "Engine library not found" << hwlib.errorString();
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    31
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    32
    flibRunEngine = (RunEngine_t*)hwlib.resolve("RunEngine");
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    33
    flibIpcToEngineRaw = (ipcToEngineRaw_t*)hwlib.resolve("ipcToEngineRaw");
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    34
    flibIpcSetEngineBarrier = (ipcSetEngineBarrier_t*)hwlib.resolve("ipcSetEngineBarrier");
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    35
    flibIpcRemoveBarrierFromEngineQueue = (ipcRemoveBarrierFromEngineQueue_t*)hwlib.resolve("ipcRemoveBarrierFromEngineQueue");
12857
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    36
    flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*)hwlib.resolve("registerUIMessagesCallback");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    37
    flibInit = (flibInit_t*)hwlib.resolve("flibInit");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    38
    flibFree = (flibFree_t*)hwlib.resolve("flibFree");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    39
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    40
    flibInit("/usr/home/unC0Rr/Sources/Hedgewars/MainRepo/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    41
    flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    42
}
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    43
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    44
HWEngine::~HWEngine()
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    45
{
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    46
    flibFree();
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    47
}
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    48
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    49
void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    50
{
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    51
    HWEngine* obj = reinterpret_cast<HWEngine*>(context);
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    52
    QByteArray b = QByteArray(msg, len);
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    53
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    54
    qDebug() << "FLIPC in" << mt << " size = " << b.size();
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    55
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    56
    QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    57
}
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    58
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    59
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray& msg)
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    60
{
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    61
    switch (mt) {
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    62
    case MSG_RENDERINGPREVIEW: {
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    63
        emit previewIsRendering();
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    64
        break;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    65
    }
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    66
    case MSG_PREVIEW: {
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    67
        emit previewImageChanged();
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    68
        break;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    69
    }
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    70
    case MSG_PREVIEWHOGCOUNT: {
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    71
        emit previewHogCountChanged((quint8)msg.data()[0]);
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    72
        break;
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    73
    }
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    74
    }
90f927b4b9e1 Start hacking new frontend
unc0rr
parents:
diff changeset
    75
}
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    76
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    77
void HWEngine::getPreview()
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    78
{
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    79
    m_runQueue.append(GameConfig());
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    80
    flibRunEngine(m_runQueue[0].argc(), m_runQueue[0].argv());
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    81
}
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    82
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    83
void HWEngine::runQuickGame()
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    84
{
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 12857
diff changeset
    85
}