author | unc0rr |
Fri, 04 Jan 2013 21:44:40 +0400 | |
branch | flibqtfrontend |
changeset 8363 | 0b4ac686fc44 |
parent 8304 | 620560c89284 |
parent 8325 | ecd51650d5d8 |
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() |
|
8094 | 51 |
, "" |
8092 | 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 |
} |
|
8094 | 71 |
qDebug(m_map->seed); |
8092 | 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; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
82 |
arguments << "--internal"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
83 |
arguments << "--port"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
84 |
arguments << QString("%1").arg(ipc_port); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
85 |
arguments << "--user-prefix"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
86 |
arguments << cfgdir->absolutePath(); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8070
diff
changeset
|
87 |
arguments << "--landpreview"; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
88 |
return arguments; |
177 | 89 |
} |
90 |
||
8092 | 91 |
void HWMap::onSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) |
164 | 92 |
{ |
8092 | 93 |
HWMap * hwMap = (HWMap *)context; |
94 |
||
95 |
QImage im(bitmap, MAPIMAGE_WIDTH, MAPIMAGE_HEIGHT, QImage::Format_Mono); |
|
96 |
im.setNumColors(2); |
|
97 |
emit hwMap->HHLimitReceived(numHedgehogs); |
|
98 |
emit hwMap->ImageReceived(im); |
|
99 |
||
100 |
hwMap->clientDisconnected(); |
|
164 | 101 |
} |
102 |
||
8092 | 103 |
void HWMap::onFailure(void *context, const char *errormessage) |
164 | 104 |
{ |
8092 | 105 |
HWMap * hwMap = (HWMap *)context; |
4489 | 106 |
|
8304 | 107 |
qWarning(errormessage); |
108 |
||
8092 | 109 |
hwMap->clientDisconnected(); |
110 |
} |
|
4489 | 111 |
|
8092 | 112 |
void HWMap::onEngineStart() |
113 |
{ |
|
114 |
m_conn = flib_mapconn_create(m_map); |
|
115 |
flib_mapconn_onSuccess(m_conn, onSuccess, this); |
|
116 |
flib_mapconn_onFailure(m_conn, onFailure, this); |
|
4489 | 117 |
|
8092 | 118 |
new FrontLibPoller((void (*)(void *))flib_mapconn_tick, m_conn, this); |
164 | 119 |
} |