author | raptor <buckyballreaction@gmail.com> |
Tue, 13 Aug 2019 13:20:28 -0600 | |
branch | 0.9.25 |
changeset 15337 | 9a545985360b |
parent 14303 | 00b56ec8b7df |
child 14376 | 90bd2c331703 |
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" |
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14278
diff
changeset
|
8 |
#include "game_view.h" |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
9 |
#include "preview_image_provider.h" |
14148 | 10 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
11 |
#include "hwengine.h" |
14148 | 12 |
|
13 |
HWEngine::HWEngine(QQmlEngine* engine, QObject* parent) |
|
14 |
: QObject(parent), |
|
15 |
m_engine(engine), |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
16 |
m_previewProvider(new PreviewImageProvider()) { |
14148 | 17 |
m_engine->addImageProvider(QLatin1String("preview"), m_previewProvider); |
18 |
} |
|
19 |
||
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
20 |
HWEngine::~HWEngine() {} |
14148 | 21 |
|
22 |
static QObject* hwengine_singletontype_provider(QQmlEngine* engine, |
|
23 |
QJSEngine* scriptEngine) { |
|
24 |
Q_UNUSED(scriptEngine) |
|
25 |
||
26 |
HWEngine* hwengine = new HWEngine(engine); |
|
27 |
return hwengine; |
|
28 |
} |
|
29 |
||
30 |
void HWEngine::exposeToQML() { |
|
31 |
qDebug("HWEngine::exposeToQML"); |
|
32 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", |
|
33 |
hwengine_singletontype_provider); |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14278
diff
changeset
|
34 |
qmlRegisterType<GameView>("Hedgewars.Engine", 1, 0, "GameView"); |
14303 | 35 |
qmlRegisterUncreatableType<EngineInstance>("Hedgewars.Engine", 1, 0, |
36 |
"EngineInstance", |
|
37 |
"Create by HWEngine run methods"); |
|
14148 | 38 |
} |
39 |
||
40 |
void HWEngine::getPreview() { |
|
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
41 |
emit previewIsRendering(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
42 |
|
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
43 |
m_gameConfig = GameConfig(); |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
44 |
m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray()); |
14148 | 45 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
46 |
EngineInstance engine; |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
47 |
engine.sendConfig(m_gameConfig); |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14159
diff
changeset
|
48 |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
49 |
Engine::PreviewInfo preview = engine.generatePreview(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
50 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
51 |
QVector<QRgb> colorTable; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
52 |
colorTable.resize(256); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
53 |
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
|
54 |
|
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
55 |
QImage previewImage(preview.land, static_cast<int>(preview.width), |
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14276
diff
changeset
|
56 |
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
|
57 |
QImage::Format_Indexed8); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
58 |
previewImage.setColorTable(colorTable); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
59 |
previewImage.detach(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
60 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
61 |
m_previewProvider->setImage(previewImage); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
62 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
63 |
emit previewImageChanged(); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
64 |
// m_runQueue->queue(m_gameConfig); |
14148 | 65 |
} |
66 |
||
14303 | 67 |
EngineInstance* HWEngine::runQuickGame() { |
14148 | 68 |
m_gameConfig.cmdTheme("Nature"); |
69 |
Team team1; |
|
70 |
team1.name = "team1"; |
|
71 |
Team team2; |
|
72 |
team2.name = "team2"; |
|
73 |
team2.color = "7654321"; |
|
74 |
m_gameConfig.cmdTeam(team1); |
|
75 |
m_gameConfig.cmdTeam(team2); |
|
76 |
||
14303 | 77 |
EngineInstance* engine = new EngineInstance(this); |
78 |
return engine; |
|
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
79 |
// m_runQueue->queue(m_gameConfig); |
14148 | 80 |
} |
81 |
||
82 |
int HWEngine::previewHedgehogsCount() const { return m_previewHedgehogsCount; } |