author | unc0rr |
Sun, 28 Sep 2014 00:49:04 +0400 | |
branch | qmlfrontend |
changeset 10428 | 7c25297720f1 |
parent 10426 | 727a154cf784 |
child 10430 | 899a30018ede |
permissions | -rw-r--r-- |
10402 | 1 |
#include <QLibrary> |
2 |
#include <QtQml> |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
3 |
#include <QDebug> |
10420 | 4 |
#include <QPainter> |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
5 |
#include <QUuid> |
10402 | 6 |
|
7 |
#include "hwengine.h" |
|
10420 | 8 |
#include "previewimageprovider.h" |
10402 | 9 |
|
10 |
extern "C" { |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
11 |
RunEngine_t *flibRunEngine; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
12 |
registerGUIMessagesCallback_t *flibRegisterGUIMessagesCallback; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
13 |
getPreview_t *flibGetPreview; |
10416 | 14 |
flibInit_t *flibInit; |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
15 |
flibFree_t *flibFree; |
10402 | 16 |
} |
10420 | 17 |
|
18 |
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) : |
|
19 |
QObject(parent), |
|
20 |
m_engine(engine) |
|
10402 | 21 |
{ |
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
22 |
QLibrary hwlib("./libhwengine.so"); |
10402 | 23 |
|
24 |
if(!hwlib.load()) |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
25 |
qWarning() << "Engine library not found" << hwlib.errorString(); |
10402 | 26 |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
27 |
flibRunEngine = (RunEngine_t*) hwlib.resolve("RunEngine"); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
28 |
flibRegisterGUIMessagesCallback = (registerGUIMessagesCallback_t*) hwlib.resolve("registerGUIMessagesCallback"); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
29 |
flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview"); |
10416 | 30 |
flibInit = (flibInit_t*) hwlib.resolve("flibInit"); |
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
31 |
flibFree = (flibFree_t*) hwlib.resolve("flibFree"); |
10416 | 32 |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
33 |
flibInit(".", "~/.hedgewars"); |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
34 |
flibRegisterGUIMessagesCallback(this, &guiMessagesCallback); |
10402 | 35 |
} |
36 |
||
37 |
HWEngine::~HWEngine() |
|
38 |
{ |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
39 |
flibFree(); |
10402 | 40 |
} |
41 |
||
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
42 |
void HWEngine::getPreview() |
10402 | 43 |
{ |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
44 |
//m_seed = QUuid::createUuid().toString(); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
45 |
flibGetPreview(); |
10402 | 46 |
} |
47 |
||
48 |
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) |
|
49 |
{ |
|
50 |
Q_UNUSED(scriptEngine) |
|
51 |
||
10420 | 52 |
HWEngine *hwengine = new HWEngine(engine); |
10402 | 53 |
return hwengine; |
54 |
} |
|
55 |
||
56 |
void HWEngine::exposeToQML() |
|
57 |
{ |
|
58 |
qDebug("HWEngine::exposeToQML"); |
|
59 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider); |
|
60 |
} |
|
10416 | 61 |
|
62 |
||
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
63 |
void HWEngine::guiMessagesCallback(void *context, MessageType mt, const char * msg, uint32_t len) |
10420 | 64 |
{ |
65 |
HWEngine * obj = (HWEngine *)context; |
|
66 |
QByteArray b = QByteArray::fromRawData(msg, len); |
|
67 |
||
68 |
qDebug() << "FLIPC in" << b.size() << b; |
|
69 |
||
70 |
QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(QByteArray, b)); |
|
10416 | 71 |
} |
72 |
||
10420 | 73 |
void HWEngine::engineMessageHandler(const QByteArray &msg) |
10416 | 74 |
{ |
10426 | 75 |
if(msg.size() == 128 * 256) |
76 |
{ |
|
77 |
PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview")); |
|
78 |
preview->setPixmap(msg); |
|
79 |
emit previewImageChanged(); |
|
80 |
} |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
81 |
} |
10416 | 82 |
|
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
83 |
QString HWEngine::currentSeed() |
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
84 |
{ |
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
85 |
return m_seed; |
10416 | 86 |
} |