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