QTfrontend/game.cpp
branchflibqtfrontend
changeset 8100 0e6fadf81a2c
parent 8092 08960209db8c
child 8103 c247346d296f
equal deleted inserted replaced
8097:59a8feebec2c 8100:0e6fadf81a2c
    28 #include "gameuiconfig.h"
    28 #include "gameuiconfig.h"
    29 #include "gamecfgwidget.h"
    29 #include "gamecfgwidget.h"
    30 #include "teamselect.h"
    30 #include "teamselect.h"
    31 #include "proto.h"
    31 #include "proto.h"
    32 #include "campaign.h"
    32 #include "campaign.h"
    33 
       
    34 #include <QTextStream>
       
    35 #include "ThemeModel.h"
    33 #include "ThemeModel.h"
       
    34 #include "frontlibpoller.h"
    36 
    35 
    37 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
    36 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
    38 
    37 
    39 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
    38 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
    40     TCPBase(0),
    39     TCPBase(0)
    41     ammostr(ammo),
    40     , ammostr(ammo)
    42     m_pTeamSelWidget(pTeamSelWidget)
    41     , m_pTeamSelWidget(pTeamSelWidget)
       
    42     , m_conn(NULL)
    43 {
    43 {
    44     this->config = config;
    44     this->config = config;
    45     this->gamecfg = gamecfg;
    45     this->gamecfg = gamecfg;
    46     netSuspend = false;
    46     netSuspend = false;
    47 }
    47 }
    48 
    48 
    49 HWGame::~HWGame()
    49 HWGame::~HWGame()
    50 {
    50 {
    51     SetGameState(gsDestroyed);
    51     SetGameState(gsDestroyed);
       
    52 
       
    53     if(m_conn)
       
    54         flib_gameconn_destroy(m_conn);
    52 }
    55 }
    53 
    56 
    54 void HWGame::onClientDisconnect()
    57 void HWGame::onClientDisconnect()
    55 {/*
    58 {/*
    56     switch (gameType)
    59     switch (gameType)
   316     QRect resolution = config->vid_Resolution();
   319     QRect resolution = config->vid_Resolution();
   317     arguments << cfgdir->absolutePath();
   320     arguments << cfgdir->absolutePath();
   318     arguments << QString::number(resolution.width());
   321     arguments << QString::number(resolution.width());
   319     arguments << QString::number(resolution.height());
   322     arguments << QString::number(resolution.height());
   320     arguments << QString::number(config->bitDepth()); // bpp
   323     arguments << QString::number(config->bitDepth()); // bpp
   321     //arguments << QString("%1").arg(ipc_port);
   324     arguments << QString::number(flib_gameconn_getport(m_conn));
   322     arguments << (config->vid_Fullscreen() ? "1" : "0");
   325     arguments << (config->vid_Fullscreen() ? "1" : "0");
   323     arguments << (config->isSoundEnabled() ? "1" : "0");
   326     arguments << (config->isSoundEnabled() ? "1" : "0");
   324     arguments << (config->isMusicEnabled() ? "1" : "0");
   327     arguments << (config->isMusicEnabled() ? "1" : "0");
   325     arguments << QString::number(config->volume()); // sound volume
   328     arguments << QString::number(config->volume()); // sound volume
   326     arguments << QString::number(config->timerInterval());
   329     arguments << QString::number(config->timerInterval());
   370     SetGameState(gsStarted);
   373     SetGameState(gsStarted);
   371 }
   374 }
   372 
   375 
   373 void HWGame::StartQuick()
   376 void HWGame::StartQuick()
   374 {
   377 {
       
   378     ThemeModel * themeModel = DataManager::instance().themeModel();
   375     gameType = gtQLocal;
   379     gameType = gtQLocal;
   376     //demo.clear();
   380 /*
       
   381 typedef struct {
       
   382     char *style;				// e.g. "Capture the Flag"
       
   383     flib_scheme *gamescheme;
       
   384     flib_map *map;
       
   385     flib_teamlist *teamlist;
       
   386 } flib_gamesetup;
       
   387  */
       
   388     flib_gamesetup gameSetup;
       
   389     gameSetup.style = NULL;
       
   390     gameSetup.gamescheme = flib_scheme_create("Default");
       
   391     gameSetup.map = flib_map_create_regular(
       
   392                 QUuid::createUuid().toByteArray().constData()
       
   393                 , themeModel->rowCount() > 0 ? themeModel->index(rand() % themeModel->rowCount()).data().toString().toUtf8().constData() : "Sheep"
       
   394                 , 3);
       
   395     gameSetup.teamlist = flib_teamlist_create();
       
   396 
       
   397     m_conn = flib_gameconn_create(config->netNick().toUtf8().constData(), &gameSetup, false);
       
   398 
   377     start(false);
   399     start(false);
   378     SetGameState(gsStarted);
   400     SetGameState(gsStarted);
   379 }
   401 }
   380 
   402 
   381 void HWGame::StartTraining(const QString & file)
   403 void HWGame::StartTraining(const QString & file)
   440     teamfile.setValue("Campaign " + campaign + "/" + varToWrite, varValue);
   462     teamfile.setValue("Campaign " + campaign + "/" + varToWrite, varValue);
   441 }
   463 }
   442 
   464 
   443 void HWGame::onEngineStart()
   465 void HWGame::onEngineStart()
   444 {
   466 {
   445 
   467     new FrontLibPoller((void (*)(void *))flib_gameconn_tick, m_conn, this);
   446 }
   468 }