author | alfadur |
Wed, 07 Aug 2019 17:28:54 +0300 | |
changeset 15310 | 0076bf602969 |
parent 14378 | 4409344db447 |
permissions | -rw-r--r-- |
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
1 |
#include "hwengine.h" |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
2 |
|
14148 | 3 |
#include <QDebug> |
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
4 |
#include <QImage> |
14148 | 5 |
#include <QUuid> |
6 |
||
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
7 |
#include "engine_instance.h" |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
8 |
#include "engine_interface.h" |
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14278
diff
changeset
|
9 |
#include "game_view.h" |
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
10 |
#include "preview_acceptor.h" |
14148 | 11 |
|
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
12 |
HWEngine::HWEngine(QObject* parent) : QObject(parent) {} |
14148 | 13 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
14 |
HWEngine::~HWEngine() {} |
14148 | 15 |
|
16 |
void HWEngine::getPreview() { |
|
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
17 |
emit previewIsRendering(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
18 |
|
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
19 |
m_gameConfig = GameConfig(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
20 |
m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray()); |
14148 | 21 |
|
14377
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
22 |
EngineInstance engine(m_engineLibrary); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
23 |
if (!engine.isValid()) // TODO: error notification |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
24 |
return; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
25 |
|
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
26 |
engine.sendConfig(m_gameConfig); |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
27 |
|
14378
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14377
diff
changeset
|
28 |
QImage previewImage = engine.generatePreview(); |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
29 |
|
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
30 |
if (m_previewAcceptor) m_previewAcceptor->setImage(previewImage); |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
31 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
32 |
emit previewImageChanged(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
33 |
// m_runQueue->queue(m_gameConfig); |
14148 | 34 |
} |
35 |
||
14303 | 36 |
EngineInstance* HWEngine::runQuickGame() { |
14148 | 37 |
m_gameConfig.cmdTheme("Nature"); |
38 |
Team team1; |
|
39 |
team1.name = "team1"; |
|
40 |
Team team2; |
|
41 |
team2.name = "team2"; |
|
42 |
team2.color = "7654321"; |
|
43 |
m_gameConfig.cmdTeam(team1); |
|
44 |
m_gameConfig.cmdTeam(team2); |
|
45 |
||
14377
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
46 |
EngineInstance* engine = new EngineInstance(m_engineLibrary, this); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
47 |
|
14303 | 48 |
return engine; |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
49 |
// m_runQueue->queue(m_gameConfig); |
14148 | 50 |
} |
51 |
||
52 |
int HWEngine::previewHedgehogsCount() const { return m_previewHedgehogsCount; } |
|
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
53 |
|
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
54 |
PreviewAcceptor* HWEngine::previewAcceptor() const { return m_previewAcceptor; } |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
55 |
|
14377
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
56 |
QString HWEngine::engineLibrary() const { return m_engineLibrary; } |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
57 |
|
14376
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
58 |
void HWEngine::setPreviewAcceptor(PreviewAcceptor* previewAcceptor) { |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
59 |
if (m_previewAcceptor == previewAcceptor) return; |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
60 |
|
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
61 |
m_previewAcceptor = previewAcceptor; |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
62 |
emit previewAcceptorChanged(m_previewAcceptor); |
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14303
diff
changeset
|
63 |
} |
14377
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
64 |
|
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
65 |
void HWEngine::setEngineLibrary(const QString& engineLibrary) { |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
66 |
if (m_engineLibrary == engineLibrary) return; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
67 |
|
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
68 |
m_engineLibrary = engineLibrary; |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
69 |
emit engineLibraryChanged(m_engineLibrary); |
b6824a53d4b1
Allow to instantiate HWEngine with different library binaries
unC0Rr
parents:
14376
diff
changeset
|
70 |
} |