QTfrontend/hwmap.cpp
author nemo
Wed, 08 Dec 2010 14:46:17 -0500
changeset 4491 dbd332f86dac
parent 4489 c4ca9ced258b
child 4494 9585435e20f7
permissions -rw-r--r--
pngcrush the new 2x previews. This "make the preview look a bit crisper at same size in iphone 4" is now costing us 2,916,716 bytes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
172
5294ada3910b working map preview
displacer
parents: 171
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 497
diff changeset
     2
 * Hedgewars, a free turn based strategy game
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 443
diff changeset
     3
 * Copyright (c) 2006, 2007 Igor Ulyanov <iulyanov@gmail.com>
172
5294ada3910b working map preview
displacer
parents: 171
diff changeset
     4
 *
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
172
5294ada3910b working map preview
displacer
parents: 171
diff changeset
     8
 *
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    12
 * GNU General Public License for more details.
172
5294ada3910b working map preview
displacer
parents: 171
diff changeset
    13
 *
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 180
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */
172
5294ada3910b working map preview
displacer
parents: 171
diff changeset
    17
497
adf1aee202c6 merge fixes from branch
displacer
parents: 486
diff changeset
    18
#include "hwconsts.h"
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    19
#include "hwmap.h"
1797
fedd8649fdd9 Templates filter by nemo
unc0rr
parents: 1791
diff changeset
    20
180
ea83b9e9057f tcp sockets are incapsulated in TCPBase class now
displacer
parents: 177
diff changeset
    21
HWMap::HWMap() :
ea83b9e9057f tcp sockets are incapsulated in TCPBase class now
displacer
parents: 177
diff changeset
    22
  TCPBase(false)
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    23
{
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    24
}
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    25
168
679e9b8912f5 multiple server starting improved
displacer
parents: 164
diff changeset
    26
HWMap::~HWMap()
679e9b8912f5 multiple server starting improved
displacer
parents: 164
diff changeset
    27
{
679e9b8912f5 multiple server starting improved
displacer
parents: 164
diff changeset
    28
}
679e9b8912f5 multiple server starting improved
displacer
parents: 164
diff changeset
    29
4489
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    30
void HWMap::getImage(std::string seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData)
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    31
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    32
    m_seed = seed;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    33
    templateFilter = filter;
3133
1ab5f18f4df8 prg's maze generator
nemo
parents: 2948
diff changeset
    34
    m_mapgen = mapgen;
1ab5f18f4df8 prg's maze generator
nemo
parents: 2948
diff changeset
    35
    m_maze_size = maze_size;
4489
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    36
    m_drawMapData = drawMapData;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    37
    Start();
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    38
}
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    39
177
c67c15e6fae3 prepare uniting tcp classes
displacer
parents: 172
diff changeset
    40
QStringList HWMap::setArguments()
c67c15e6fae3 prepare uniting tcp classes
displacer
parents: 172
diff changeset
    41
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    42
    QStringList arguments;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    43
    arguments << cfgdir->absolutePath();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    44
    arguments << QString("%1").arg(ipc_port);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    45
    arguments << "landpreview";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    46
    return arguments;
177
c67c15e6fae3 prepare uniting tcp classes
displacer
parents: 172
diff changeset
    47
}
c67c15e6fae3 prepare uniting tcp classes
displacer
parents: 172
diff changeset
    48
c67c15e6fae3 prepare uniting tcp classes
displacer
parents: 172
diff changeset
    49
void HWMap::onClientDisconnect()
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    50
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    51
    if (readbuffer.size() == 128 * 32 + 1)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    52
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    53
        quint8 *buf = (quint8*) readbuffer.constData();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    54
        QImage im(buf, 256, 128, QImage::Format_Mono);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    55
        im.setNumColors(2);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    56
        emit HHLimitReceived(buf[128 * 32]);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    57
        emit ImageReceived(im);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    58
    }
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    59
}
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    60
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    61
void HWMap::SendToClientFirst()
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    62
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    63
    SendIPC(QString("eseed %1").arg(m_seed.c_str()).toLatin1());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    64
    SendIPC(QString("e$template_filter %1").arg(templateFilter).toLatin1());
3133
1ab5f18f4df8 prg's maze generator
nemo
parents: 2948
diff changeset
    65
    SendIPC(QString("e$mapgen %1").arg(m_mapgen).toLatin1());
4489
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    66
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    67
    switch (m_mapgen)
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    68
    {
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    69
        case MAPGEN_MAZE:
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    70
            SendIPC(QString("e$maze_size %1").arg(m_maze_size).toLatin1());
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    71
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    72
        case MAPGEN_DRAWN:
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    73
        {
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    74
            QByteArray data = m_drawMapData;
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    75
            while(data.size() > 0)
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    76
            {
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    77
                QByteArray tmp = data;
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    78
                tmp.truncate(230);
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    79
                SendIPC("edraw " + tmp);
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    80
                data.remove(0, 230);
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    81
            }
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    82
        }
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    83
        default: ;
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    84
    }
c4ca9ced258b - Pass map drawing data to engine
unc0rr
parents: 3133
diff changeset
    85
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1797
diff changeset
    86
    SendIPC("!");
164
92cff18a3ab6 first map preview added (still experimental)
displacer
parents:
diff changeset
    87
}