QTfrontend/net/recorder.cpp
changeset 7180 53ffc8853008
child 7198 5debd5fe526e
equal deleted inserted replaced
7176:fb4b0c6dfdbd 7180:53ffc8853008
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #include <QString>
       
    20 #include <QByteArray>
       
    21 
       
    22 #include "recorder.h"
       
    23 #include "gameuiconfig.h"
       
    24 #include "hwconsts.h"
       
    25 #include "game.h"
       
    26 
       
    27 HWRecorder::HWRecorder(GameUIConfig * config) :
       
    28     TCPBase(false)
       
    29 {
       
    30     this->config = config;
       
    31 }
       
    32 
       
    33 HWRecorder::~HWRecorder()
       
    34 {
       
    35 }
       
    36 
       
    37 void HWRecorder::onClientDisconnect()
       
    38 {
       
    39 }
       
    40      
       
    41 void HWRecorder::onClientRead()
       
    42 {
       
    43     quint8 msglen;
       
    44     quint32 bufsize;
       
    45     while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) &&
       
    46             ((msglen = readbuffer.data()[0]) < bufsize))
       
    47     {
       
    48         QByteArray msg = readbuffer.left(msglen + 1);
       
    49         readbuffer.remove(0, msglen + 1);
       
    50         if (msg.at(1) == '?')
       
    51             SendIPC("!");
       
    52     }
       
    53 }
       
    54 
       
    55 void HWRecorder::EncodeVideo( const QByteArray & record, const QString & prefix )
       
    56 {
       
    57     this->prefix = prefix;
       
    58 
       
    59     toSendBuf = record;
       
    60     toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV"));
       
    61     toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV"));
       
    62     toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV"));
       
    63     toSendBuf.replace(QByteArray("\x02TS"), QByteArray("\x02TV"));
       
    64 
       
    65     // run engine
       
    66     Start();
       
    67 }
       
    68 
       
    69 QStringList HWRecorder::getArguments()
       
    70 {
       
    71     QStringList arguments;
       
    72     QRect resolution = config->vid_Resolution();
       
    73     arguments << cfgdir->absolutePath();
       
    74     arguments << QString::number(resolution.width());
       
    75     arguments << QString::number(resolution.height());
       
    76     arguments << QString::number(config->bitDepth()); // bpp
       
    77     arguments << QString("%1").arg(ipc_port);
       
    78     arguments << "0"; // fullscreen
       
    79     arguments << "0"; // sound
       
    80     arguments << "0"; // music
       
    81     arguments << "0"; // sound volume
       
    82     arguments << QString::number(config->timerInterval());
       
    83     arguments << datadir->absolutePath();
       
    84     arguments << (config->isShowFPSEnabled() ? "1" : "0");
       
    85     arguments << (config->isAltDamageEnabled() ? "1" : "0");
       
    86     arguments << config->netNick().toUtf8().toBase64();
       
    87     arguments << QString::number(config->translateQuality());
       
    88     arguments << QString::number(config->stereoMode());
       
    89     arguments << HWGame::tr("en.txt");
       
    90     arguments << prefix;
       
    91 
       
    92     return arguments;
       
    93 }