author | unc0rr |
Thu, 22 Nov 2012 01:19:16 +0400 | |
branch | flibqtfrontend |
changeset 8092 | 08960209db8c |
parent 8070 | 66bc20d089fc |
child 8094 | 6c5b4e69f03d |
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> |
6952 | 4 |
* Copyright (c) 2004-2012 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" |
8092 | 22 |
#include "frontlibpoller.h" |
1797 | 23 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
24 |
HWMap::HWMap(QObject * parent) : |
8092 | 25 |
TCPBase(parent) |
164 | 26 |
{ |
8092 | 27 |
m_conn = NULL; |
28 |
m_map = NULL; |
|
164 | 29 |
} |
30 |
||
168 | 31 |
HWMap::~HWMap() |
32 |
{ |
|
8092 | 33 |
if(m_conn) |
34 |
flib_mapconn_destroy(m_conn); |
|
35 |
if(m_map) |
|
36 |
flib_map_destroy(m_map); |
|
168 | 37 |
} |
38 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
39 |
bool HWMap::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
40 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
41 |
return !m_hasStarted; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
42 |
} |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
6952
diff
changeset
|
43 |
|
8092 | 44 |
void HWMap::getImage(const QString & seed, int filter, int mapgen, int maze_size, const QByteArray & drawMapData) |
164 | 45 |
{ |
8092 | 46 |
switch(mapgen) |
47 |
{ |
|
48 |
case MAPGEN_REGULAR: m_map = |
|
49 |
flib_map_create_regular( |
|
50 |
seed.toUtf8().constData() |
|
51 |
, "" // theme? here? |
|
52 |
, filter); |
|
53 |
break; |
|
54 |
case MAPGEN_MAZE: m_map = |
|
55 |
flib_map_create_maze( |
|
56 |
seed.toUtf8().constData() |
|
57 |
, "" |
|
58 |
, maze_size); |
|
59 |
break; |
|
60 |
case MAPGEN_DRAWN: m_map = |
|
61 |
flib_map_create_drawn( |
|
62 |
seed.toUtf8().constData() |
|
63 |
, "" |
|
64 |
, (const uint8_t*)drawMapData.constData() |
|
65 |
, drawMapData.size() |
|
66 |
); |
|
67 |
break; |
|
68 |
default: |
|
69 |
Q_ASSERT_X(false, "HWMap::getImage", "Unknown generator"); |
|
70 |
} |
|
71 |
||
72 |
start(true); |
|
164 | 73 |
} |
74 |
||
5213
a86768368309
make the associate button use the user's settings for loading demos/saves
nemo
parents:
4976
diff
changeset
|
75 |
QStringList HWMap::getArguments() |
177 | 76 |
{ |
8092 | 77 |
Q_ASSERT(m_conn); |
78 |
||
79 |
int ipc_port = flib_mapconn_getport(m_conn); |
|
80 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
81 |
QStringList arguments; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
82 |
arguments << cfgdir->absolutePath(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
83 |
arguments << QString("%1").arg(ipc_port); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
84 |
arguments << "landpreview"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
85 |
return arguments; |
177 | 86 |
} |
87 |
||
8092 | 88 |
void HWMap::onSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) |
164 | 89 |
{ |
8092 | 90 |
qDebug("HWMap::onSuccess"); |
91 |
HWMap * hwMap = (HWMap *)context; |
|
92 |
||
93 |
QImage im(bitmap, MAPIMAGE_WIDTH, MAPIMAGE_HEIGHT, QImage::Format_Mono); |
|
94 |
im.setNumColors(2); |
|
95 |
emit hwMap->HHLimitReceived(numHedgehogs); |
|
96 |
emit hwMap->ImageReceived(im); |
|
97 |
||
98 |
hwMap->clientDisconnected(); |
|
164 | 99 |
} |
100 |
||
8092 | 101 |
void HWMap::onFailure(void *context, const char *errormessage) |
164 | 102 |
{ |
8092 | 103 |
qDebug("HWMap::onFailure"); |
104 |
HWMap * hwMap = (HWMap *)context; |
|
4489 | 105 |
|
8092 | 106 |
hwMap->clientDisconnected(); |
107 |
} |
|
4489 | 108 |
|
8092 | 109 |
void HWMap::onEngineStart() |
110 |
{ |
|
111 |
qDebug("HWMap::onEngineStart"); |
|
112 |
m_conn = flib_mapconn_create(m_map); |
|
113 |
flib_mapconn_onSuccess(m_conn, onSuccess, this); |
|
114 |
flib_mapconn_onFailure(m_conn, onFailure, this); |
|
4489 | 115 |
|
8092 | 116 |
new FrontLibPoller((void (*)(void *))flib_mapconn_tick, m_conn, this); |
164 | 117 |
} |