author | unC0Rr |
Thu, 22 Nov 2018 13:40:58 +0100 | |
changeset 14278 | 645e4591361f |
parent 14276 | 1aac8a62be6f |
child 14299 | 21be7838a127 |
permissions | -rw-r--r-- |
14148 | 1 |
#include <QDebug> |
2 |
#include <QLibrary> |
|
3 |
#include <QQmlEngine> |
|
4 |
#include <QUuid> |
|
5 |
||
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
6 |
#include "engine_instance.h" |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
7 |
#include "engine_interface.h" |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
8 |
#include "preview_image_provider.h" |
14148 | 9 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
10 |
#include "hwengine.h" |
14148 | 11 |
|
12 |
HWEngine::HWEngine(QQmlEngine* engine, QObject* parent) |
|
13 |
: QObject(parent), |
|
14 |
m_engine(engine), |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
15 |
m_previewProvider(new PreviewImageProvider()) { |
14148 | 16 |
m_engine->addImageProvider(QLatin1String("preview"), m_previewProvider); |
17 |
} |
|
18 |
||
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
19 |
HWEngine::~HWEngine() {} |
14148 | 20 |
|
21 |
static QObject* hwengine_singletontype_provider(QQmlEngine* engine, |
|
22 |
QJSEngine* scriptEngine) { |
|
23 |
Q_UNUSED(scriptEngine) |
|
24 |
||
25 |
HWEngine* hwengine = new HWEngine(engine); |
|
26 |
return hwengine; |
|
27 |
} |
|
28 |
||
29 |
void HWEngine::exposeToQML() { |
|
30 |
qDebug("HWEngine::exposeToQML"); |
|
31 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", |
|
32 |
hwengine_singletontype_provider); |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
33 |
// qmlRegisterType<GameView>("Hedgewars.Engine", 1, 0, "GameView"); |
14148 | 34 |
} |
35 |
||
36 |
void HWEngine::getPreview() { |
|
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
37 |
emit previewIsRendering(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
38 |
|
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
39 |
m_gameConfig = GameConfig(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
40 |
m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray()); |
14148 | 41 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
42 |
EngineInstance engine; |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
43 |
engine.sendConfig(m_gameConfig); |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
44 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
45 |
Engine::PreviewInfo preview = engine.generatePreview(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
46 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
47 |
QVector<QRgb> colorTable; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
48 |
colorTable.resize(256); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
49 |
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:
14148
diff
changeset
|
50 |
|
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
51 |
QImage previewImage(preview.land, static_cast<int>(preview.width), |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
52 |
static_cast<int>(preview.height), |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
53 |
QImage::Format_Indexed8); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
54 |
previewImage.setColorTable(colorTable); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
55 |
previewImage.detach(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
56 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
57 |
m_previewProvider->setImage(previewImage); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
58 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
59 |
emit previewImageChanged(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
60 |
// m_runQueue->queue(m_gameConfig); |
14148 | 61 |
} |
62 |
||
63 |
void HWEngine::runQuickGame() { |
|
64 |
m_gameConfig.cmdTheme("Nature"); |
|
65 |
Team team1; |
|
66 |
team1.name = "team1"; |
|
67 |
Team team2; |
|
68 |
team2.name = "team2"; |
|
69 |
team2.color = "7654321"; |
|
70 |
m_gameConfig.cmdTeam(team1); |
|
71 |
m_gameConfig.cmdTeam(team2); |
|
72 |
||
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
73 |
// m_runQueue->queue(m_gameConfig); |
14148 | 74 |
} |
75 |
||
76 |
int HWEngine::previewHedgehogsCount() const { return m_previewHedgehogsCount; } |