author | unc0rr |
Tue, 21 Jan 2014 00:09:06 +0400 | |
changeset 10027 | 403b86a1d05f |
parent 9998 | 736015b847e3 |
child 10108 | c68cf030eded |
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> |
9998 | 4 |
* Copyright (c) 2004-2014 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 |
|
4976 | 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
18 |
*/ |
|
172 | 19 |
|
497 | 20 |
#include "hwconsts.h" |
164 | 21 |
#include "hwmap.h" |
1797 | 22 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
23 |
HWMap::HWMap(QObject * parent) : |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
24 |
TCPBase(false, parent) |
164 | 25 |
{ |
26 |
} |
|
27 |
||
168 | 28 |
HWMap::~HWMap() |
29 |
{ |
|
30 |
} |
|
31 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
32 |
bool HWMap::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
33 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
34 |
return !m_hasStarted; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
35 |
} |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
36 |
|
4534 | 37 |
void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) |
164 | 38 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
39 |
m_seed = seed; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
40 |
templateFilter = filter; |
3133 | 41 |
m_mapgen = mapgen; |
42 |
m_maze_size = maze_size; |
|
4572 | 43 |
if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
44 |
Start(true); |
164 | 45 |
} |
46 |
||
5213
a86768368309
make the associate button use the user's settings for loading demos/saves
nemo
parents:
4976
diff
changeset
|
47 |
QStringList HWMap::getArguments() |
177 | 48 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
49 |
QStringList arguments; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
50 |
arguments << "--internal"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
51 |
arguments << "--port"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
52 |
arguments << QString("%1").arg(ipc_port); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
53 |
arguments << "--user-prefix"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
54 |
arguments << cfgdir->absolutePath(); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
55 |
arguments << "--landpreview"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
56 |
return arguments; |
177 | 57 |
} |
58 |
||
59 |
void HWMap::onClientDisconnect() |
|
164 | 60 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
61 |
if (readbuffer.size() == 128 * 32 + 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
62 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
63 |
quint8 *buf = (quint8*) readbuffer.constData(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
64 |
QImage im(buf, 256, 128, QImage::Format_Mono); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
65 |
im.setNumColors(2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
66 |
emit HHLimitReceived(buf[128 * 32]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
67 |
emit ImageReceived(im); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
68 |
} |
164 | 69 |
} |
70 |
||
71 |
void HWMap::SendToClientFirst() |
|
72 |
{ |
|
4534 | 73 |
SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); |
74 |
SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); |
|
75 |
SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); |
|
4489 | 76 |
|
77 |
switch (m_mapgen) |
|
78 |
{ |
|
79 |
case MAPGEN_MAZE: |
|
4534 | 80 |
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
|
81 |
break; |
4489 | 82 |
|
83 |
case MAPGEN_DRAWN: |
|
84 |
{ |
|
85 |
QByteArray data = m_drawMapData; |
|
86 |
while(data.size() > 0) |
|
87 |
{ |
|
88 |
QByteArray tmp = data; |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
89 |
tmp.truncate(200); |
4489 | 90 |
SendIPC("edraw " + tmp); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
91 |
data.remove(0, 200); |
4489 | 92 |
} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
93 |
break; |
4489 | 94 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
95 |
default: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
96 |
; |
4489 | 97 |
} |
98 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
99 |
SendIPC("!"); |
164 | 100 |
} |