12862
|
1 |
#include "hwengine.h"
|
|
2 |
|
|
3 |
#include <QDebug>
|
|
4 |
#include <QLibrary>
|
|
5 |
|
|
6 |
extern "C" {
|
|
7 |
RunEngine_t* flibRunEngine;
|
|
8 |
registerUIMessagesCallback_t* flibRegisterUIMessagesCallback;
|
|
9 |
flibInit_t* flibInit;
|
|
10 |
flibFree_t* flibFree;
|
|
11 |
passFlibEvent_t* flibPassFlibEvent;
|
|
12 |
}
|
|
13 |
|
|
14 |
HWEngine::HWEngine(QQmlEngine* engine, QObject* parent)
|
|
15 |
: QObject(parent)
|
|
16 |
, m_engine(engine)
|
|
17 |
{
|
|
18 |
qRegisterMetaType<MessageType>("MessageType");
|
|
19 |
|
|
20 |
#ifdef Q_OS_WIN
|
|
21 |
QLibrary hwlib("./libhwengine.dll");
|
|
22 |
#else
|
|
23 |
QLibrary hwlib("./libhwengine.so");
|
|
24 |
#endif
|
|
25 |
|
|
26 |
if (!hwlib.load())
|
|
27 |
qWarning() << "Engine library not found" << hwlib.errorString();
|
|
28 |
|
|
29 |
flibRunEngine = (RunEngine_t*)hwlib.resolve("RunEngine");
|
|
30 |
flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*)hwlib.resolve("registerUIMessagesCallback");
|
|
31 |
flibInit = (flibInit_t*)hwlib.resolve("flibInit");
|
|
32 |
flibFree = (flibFree_t*)hwlib.resolve("flibFree");
|
|
33 |
|
|
34 |
flibInit("/usr/home/unC0Rr/Sources/Hedgewars/MainRepo/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
|
|
35 |
flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
|
|
36 |
}
|
|
37 |
|
|
38 |
HWEngine::~HWEngine()
|
|
39 |
{
|
|
40 |
flibFree();
|
|
41 |
}
|
|
42 |
|
|
43 |
void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
|
|
44 |
{
|
|
45 |
HWEngine* obj = reinterpret_cast<HWEngine*>(context);
|
|
46 |
QByteArray b = QByteArray(msg, len);
|
|
47 |
|
|
48 |
qDebug() << "FLIPC in" << mt << " size = " << b.size();
|
|
49 |
|
|
50 |
QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
|
|
51 |
}
|
|
52 |
|
|
53 |
void HWEngine::engineMessageHandler(MessageType mt, const QByteArray& msg)
|
|
54 |
{
|
|
55 |
switch (mt) {
|
|
56 |
case MSG_RENDERINGPREVIEW: {
|
|
57 |
emit previewIsRendering();
|
|
58 |
break;
|
|
59 |
}
|
|
60 |
case MSG_PREVIEW: {
|
|
61 |
emit previewImageChanged();
|
|
62 |
break;
|
|
63 |
}
|
|
64 |
case MSG_PREVIEWHOGCOUNT: {
|
|
65 |
emit previewHogCountChanged((quint8)msg.data()[0]);
|
|
66 |
break;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
}
|