author | unC0Rr |
Fri, 07 Dec 2018 13:56:45 +0100 | |
changeset 14372 | b6824a53d4b1 |
parent 14371 | 90bd2c331703 |
child 14373 | 4409344db447 |
permissions | -rw-r--r-- |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
1 |
#include "hwengine.h" |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
2 |
|
14143 | 3 |
#include <QDebug> |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
4 |
#include <QImage> |
14143 | 5 |
#include <QLibrary> |
6 |
#include <QQmlEngine> |
|
7 |
#include <QUuid> |
|
8 |
||
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
9 |
#include "engine_instance.h" |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
10 |
#include "engine_interface.h" |
14294
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14273
diff
changeset
|
11 |
#include "game_view.h" |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
12 |
#include "preview_acceptor.h" |
14143 | 13 |
|
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
14 |
HWEngine::HWEngine(QObject* parent) : QObject(parent) {} |
14143 | 15 |
|
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
16 |
HWEngine::~HWEngine() {} |
14143 | 17 |
|
18 |
void HWEngine::getPreview() { |
|
14273
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
19 |
emit previewIsRendering(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
20 |
|
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
21 |
m_gameConfig = GameConfig(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
22 |
m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray()); |
14143 | 23 |
|
14372
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
24 |
EngineInstance engine(m_engineLibrary); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
25 |
if (!engine.isValid()) // TODO: error notification |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
26 |
return; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
27 |
|
14271
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14154
diff
changeset
|
28 |
engine.sendConfig(m_gameConfig); |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14154
diff
changeset
|
29 |
|
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
30 |
Engine::PreviewInfo preview = engine.generatePreview(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
31 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
32 |
QVector<QRgb> colorTable; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
33 |
colorTable.resize(256); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
34 |
for (int i = 0; i < 256; ++i) colorTable[i] = qRgba(255, 255, 0, i); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
35 |
|
14273
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
36 |
QImage previewImage(preview.land, static_cast<int>(preview.width), |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14271
diff
changeset
|
37 |
static_cast<int>(preview.height), |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
38 |
QImage::Format_Indexed8); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
39 |
previewImage.setColorTable(colorTable); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
40 |
previewImage.detach(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
41 |
|
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
42 |
if (m_previewAcceptor) m_previewAcceptor->setImage(previewImage); |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
43 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
44 |
emit previewImageChanged(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
45 |
// m_runQueue->queue(m_gameConfig); |
14143 | 46 |
} |
47 |
||
14298 | 48 |
EngineInstance* HWEngine::runQuickGame() { |
14143 | 49 |
m_gameConfig.cmdTheme("Nature"); |
50 |
Team team1; |
|
51 |
team1.name = "team1"; |
|
52 |
Team team2; |
|
53 |
team2.name = "team2"; |
|
54 |
team2.color = "7654321"; |
|
55 |
m_gameConfig.cmdTeam(team1); |
|
56 |
m_gameConfig.cmdTeam(team2); |
|
57 |
||
14372
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
58 |
EngineInstance* engine = new EngineInstance(m_engineLibrary, this); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
59 |
|
14298 | 60 |
return engine; |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14143
diff
changeset
|
61 |
// m_runQueue->queue(m_gameConfig); |
14143 | 62 |
} |
63 |
||
64 |
int HWEngine::previewHedgehogsCount() const { return m_previewHedgehogsCount; } |
|
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
65 |
|
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
66 |
PreviewAcceptor* HWEngine::previewAcceptor() const { return m_previewAcceptor; } |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
67 |
|
14372
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
68 |
QString HWEngine::engineLibrary() const { return m_engineLibrary; } |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
69 |
|
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
70 |
void HWEngine::setPreviewAcceptor(PreviewAcceptor* previewAcceptor) { |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
71 |
if (m_previewAcceptor == previewAcceptor) return; |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
72 |
|
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
73 |
m_previewAcceptor = previewAcceptor; |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
74 |
emit previewAcceptorChanged(m_previewAcceptor); |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
75 |
} |
14372
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
76 |
|
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
77 |
void HWEngine::setEngineLibrary(const QString& engineLibrary) { |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
78 |
if (m_engineLibrary == engineLibrary) return; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
79 |
|
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
80 |
m_engineLibrary = engineLibrary; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
81 |
emit engineLibraryChanged(m_engineLibrary); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14371
diff
changeset
|
82 |
} |