author | Wuzzy <almikes@aol.com> |
Tue, 12 Apr 2016 19:46:25 +0200 | |
changeset 11692 | 594016813e06 |
parent 11046 | 47a8c19ecb60 |
child 12902 | fc47fc4af6bd |
permissions | -rw-r--r-- |
172 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2006-2007 Ulyanov Igor <iulyanov@gmail.com> |
11046 | 4 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
172 | 5 |
* |
184 | 6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
172 | 9 |
* |
184 | 10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
172 | 14 |
* |
184 | 15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 18 |
*/ |
172 | 19 |
|
10161 | 20 |
#include <QPainter> |
21 |
#include <QBitmap> |
|
22 |
#include <QLinearGradient> |
|
23 |
||
497 | 24 |
#include "hwconsts.h" |
164 | 25 |
#include "hwmap.h" |
1797 | 26 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
27 |
HWMap::HWMap(QObject * parent) : |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
28 |
TCPBase(false, parent) |
164 | 29 |
{ |
10248 | 30 |
templateFilter = 0; |
31 |
m_mapgen = MAPGEN_REGULAR; |
|
32 |
m_maze_size = 0; |
|
10472
8d04cebedb16
Partially hook up feature size so horrorcat has something to test.
nemo
parents:
10391
diff
changeset
|
33 |
m_feature_size = 50; |
164 | 34 |
} |
35 |
||
168 | 36 |
HWMap::~HWMap() |
37 |
{ |
|
38 |
} |
|
39 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
40 |
bool HWMap::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
41 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
42 |
return !m_hasStarted; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
43 |
} |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
44 |
|
10959
1225f42f61e2
Pass ScriptParams to preview to support techracer. Proof of concept for techracer, generate a preview for m=4
nemo
parents:
10472
diff
changeset
|
45 |
void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData, QString & script, QString & scriptparam, int feature_size) |
164 | 46 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
47 |
m_seed = seed; |
10150
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10108
diff
changeset
|
48 |
m_script = script; |
10959
1225f42f61e2
Pass ScriptParams to preview to support techracer. Proof of concept for techracer, generate a preview for m=4
nemo
parents:
10472
diff
changeset
|
49 |
m_scriptparam = scriptparam; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
50 |
templateFilter = filter; |
3133 | 51 |
m_mapgen = mapgen; |
10959
1225f42f61e2
Pass ScriptParams to preview to support techracer. Proof of concept for techracer, generate a preview for m=4
nemo
parents:
10472
diff
changeset
|
52 |
m_maze_size = maze_size; |
10472
8d04cebedb16
Partially hook up feature size so horrorcat has something to test.
nemo
parents:
10391
diff
changeset
|
53 |
m_feature_size = feature_size; |
4572 | 54 |
if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
55 |
Start(true); |
164 | 56 |
} |
57 |
||
5213
a86768368309
make the associate button use the user's settings for loading demos/saves
nemo
parents:
4976
diff
changeset
|
58 |
QStringList HWMap::getArguments() |
177 | 59 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
60 |
QStringList arguments; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
61 |
arguments << "--internal"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
62 |
arguments << "--port"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
63 |
arguments << QString("%1").arg(ipc_port); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
64 |
arguments << "--user-prefix"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
65 |
arguments << cfgdir->absolutePath(); |
10166 | 66 |
arguments << "--prefix"; |
67 |
arguments << datadir->absolutePath(); |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
68 |
arguments << "--landpreview"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
69 |
return arguments; |
177 | 70 |
} |
71 |
||
72 |
void HWMap::onClientDisconnect() |
|
10161 | 73 |
{ |
74 |
QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128)); |
|
75 |
linearGrad.setColorAt(1, QColor(0, 0, 192)); |
|
76 |
linearGrad.setColorAt(0, QColor(66, 115, 225)); |
|
77 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
78 |
if (readbuffer.size() == 128 * 32 + 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
79 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
80 |
quint8 *buf = (quint8*) readbuffer.constData(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
81 |
QImage im(buf, 256, 128, QImage::Format_Mono); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
82 |
im.setNumColors(2); |
10161 | 83 |
|
84 |
QPixmap px(QSize(256, 128)); |
|
85 |
QPixmap pxres(px.size()); |
|
86 |
QPainter p(&pxres); |
|
87 |
||
88 |
px.fill(Qt::yellow); |
|
89 |
QBitmap bm = QBitmap::fromImage(im); |
|
90 |
px.setMask(bm); |
|
91 |
||
92 |
p.fillRect(pxres.rect(), linearGrad); |
|
93 |
p.drawPixmap(0, 0, px); |
|
94 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
95 |
emit HHLimitReceived(buf[128 * 32]); |
10161 | 96 |
emit ImageReceived(px); |
10162 | 97 |
} else if (readbuffer.size() == 128 * 256 + 1) |
98 |
{ |
|
99 |
QVector<QRgb> colorTable; |
|
100 |
colorTable.resize(256); |
|
101 |
for(int i = 0; i < 256; ++i) |
|
102 |
colorTable[i] = qRgba(255, 255, 0, i); |
|
103 |
||
104 |
const quint8 *buf = (const quint8*) readbuffer.constData(); |
|
105 |
QImage im(buf, 256, 128, QImage::Format_Indexed8); |
|
106 |
im.setColorTable(colorTable); |
|
107 |
||
108 |
QPixmap px = QPixmap::fromImage(im, Qt::ColorOnly); |
|
109 |
QPixmap pxres(px.size()); |
|
110 |
QPainter p(&pxres); |
|
111 |
||
112 |
p.fillRect(pxres.rect(), linearGrad); |
|
113 |
p.drawPixmap(0, 0, px); |
|
114 |
||
115 |
emit HHLimitReceived(buf[128 * 256]); |
|
116 |
emit ImageReceived(px); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
117 |
} |
164 | 118 |
} |
119 |
||
120 |
void HWMap::SendToClientFirst() |
|
121 |
{ |
|
4534 | 122 |
SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); |
123 |
SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); |
|
124 |
SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); |
|
10472
8d04cebedb16
Partially hook up feature size so horrorcat has something to test.
nemo
parents:
10391
diff
changeset
|
125 |
SendIPC(QString("e$feature_size %1").arg(m_feature_size).toUtf8()); |
10159 | 126 |
if (!m_script.isEmpty()) |
10150
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10108
diff
changeset
|
127 |
{ |
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10108
diff
changeset
|
128 |
SendIPC(QString("escript Scripts/Multiplayer/%1.lua").arg(m_script).toUtf8()); |
10959
1225f42f61e2
Pass ScriptParams to preview to support techracer. Proof of concept for techracer, generate a preview for m=4
nemo
parents:
10472
diff
changeset
|
129 |
SendIPC(QString("e$scriptparam %1").arg(m_scriptparam).toUtf8()); |
10150
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10108
diff
changeset
|
130 |
} |
4489 | 131 |
|
132 |
switch (m_mapgen) |
|
133 |
{ |
|
134 |
case MAPGEN_MAZE: |
|
10391 | 135 |
case MAPGEN_PERLIN: |
4534 | 136 |
SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8()); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
137 |
break; |
4489 | 138 |
|
139 |
case MAPGEN_DRAWN: |
|
140 |
{ |
|
141 |
QByteArray data = m_drawMapData; |
|
142 |
while(data.size() > 0) |
|
143 |
{ |
|
144 |
QByteArray tmp = data; |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
145 |
tmp.truncate(200); |
4489 | 146 |
SendIPC("edraw " + tmp); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
147 |
data.remove(0, 200); |
4489 | 148 |
} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
149 |
break; |
4489 | 150 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
151 |
default: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
152 |
; |
4489 | 153 |
} |
154 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
155 |
SendIPC("!"); |
164 | 156 |
} |