# HG changeset patch # User unc0rr # Date 1353791631 -14400 # Node ID 0e6fadf81a2cac5280f44a267f19cebc71104f16 # Parent 59a8feebec2c7370c44e11ab071188187921b499 - frontlib loads team config via physfs - some more work on frontlib port diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/CMakeLists.txt Sun Nov 25 01:13:51 2012 +0400 @@ -174,8 +174,8 @@ set(HW_LINK_LIBS + frontlib physfs - frontlib ${QT_LIBRARIES} ${SDL_LIBRARY} ${SDLMIXER_LIBRARY} diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/game.cpp --- a/QTfrontend/game.cpp Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/game.cpp Sun Nov 25 01:13:51 2012 +0400 @@ -30,16 +30,16 @@ #include "teamselect.h" #include "proto.h" #include "campaign.h" - -#include #include "ThemeModel.h" +#include "frontlibpoller.h" QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution? HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) : - TCPBase(0), - ammostr(ammo), - m_pTeamSelWidget(pTeamSelWidget) + TCPBase(0) + , ammostr(ammo) + , m_pTeamSelWidget(pTeamSelWidget) + , m_conn(NULL) { this->config = config; this->gamecfg = gamecfg; @@ -49,6 +49,9 @@ HWGame::~HWGame() { SetGameState(gsDestroyed); + + if(m_conn) + flib_gameconn_destroy(m_conn); } void HWGame::onClientDisconnect() @@ -318,7 +321,7 @@ arguments << QString::number(resolution.width()); arguments << QString::number(resolution.height()); arguments << QString::number(config->bitDepth()); // bpp - //arguments << QString("%1").arg(ipc_port); + arguments << QString::number(flib_gameconn_getport(m_conn)); arguments << (config->vid_Fullscreen() ? "1" : "0"); arguments << (config->isSoundEnabled() ? "1" : "0"); arguments << (config->isMusicEnabled() ? "1" : "0"); @@ -372,8 +375,27 @@ void HWGame::StartQuick() { + ThemeModel * themeModel = DataManager::instance().themeModel(); gameType = gtQLocal; - //demo.clear(); +/* +typedef struct { + char *style; // e.g. "Capture the Flag" + flib_scheme *gamescheme; + flib_map *map; + flib_teamlist *teamlist; +} flib_gamesetup; + */ + flib_gamesetup gameSetup; + gameSetup.style = NULL; + gameSetup.gamescheme = flib_scheme_create("Default"); + gameSetup.map = flib_map_create_regular( + QUuid::createUuid().toByteArray().constData() + , themeModel->rowCount() > 0 ? themeModel->index(rand() % themeModel->rowCount()).data().toString().toUtf8().constData() : "Sheep" + , 3); + gameSetup.teamlist = flib_teamlist_create(); + + m_conn = flib_gameconn_create(config->netNick().toUtf8().constData(), &gameSetup, false); + start(false); SetGameState(gsStarted); } @@ -442,5 +464,5 @@ void HWGame::onEngineStart() { - + new FrontLibPoller((void (*)(void *))flib_gameconn_tick, m_conn, this); } diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/game.h --- a/QTfrontend/game.h Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/game.h Sun Nov 25 01:13:51 2012 +0400 @@ -24,6 +24,7 @@ #include "namegen.h" #include "tcpBase.h" +#include "frontlib.h" class GameUIConfig; class GameCFGWidget; @@ -104,6 +105,8 @@ TeamSelWidget* m_pTeamSelWidget; GameType gameType; + flib_gameconn * m_conn; + void commonConfig(); void SendConfig(); void SendQuickConfig(); diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/team.cpp --- a/QTfrontend/team.cpp Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/team.cpp Sun Nov 25 01:13:51 2012 +0400 @@ -23,6 +23,7 @@ #include #include #include +#include #include "team.h" #include "hwform.h" @@ -33,6 +34,7 @@ , m_difficulty(0) , m_numHedgehogs(4) , m_isNetTeam(false) + , m_team(NULL) { m_name = teamname; OldTeamName = m_name; @@ -62,6 +64,7 @@ QObject(0) , m_numHedgehogs(4) , m_isNetTeam(true) + , m_team(NULL) { // net teams are configured from QStringList if(strLst.size() != 23) throw HWTeamConstructException(); @@ -92,6 +95,7 @@ , m_difficulty(0) , m_numHedgehogs(4) , m_isNetTeam(false) + , m_team(NULL) { m_name = QString("Team"); for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) @@ -129,6 +133,7 @@ , m_hedgehogs(other.m_hedgehogs) , m_difficulty(other.m_difficulty) , m_binds(other.m_binds) + , m_team(flib_team_copy(other.m_team)) , m_numHedgehogs(other.m_numHedgehogs) , m_color(other.m_color) , m_isNetTeam(other.m_isNetTeam) @@ -167,8 +172,20 @@ return *this; } +HWTeam::~HWTeam() +{ + if(m_team) + flib_team_destroy(m_team); +} + bool HWTeam::loadFromFile() { + if(m_team) + flib_team_destroy(m_team); + + m_team = flib_team_from_ini(QString("/config/Teams/%1.hwt").arg(m_name).toUtf8().constData()); + + /* QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0); teamfile.setIniCodec("UTF-8"); m_name = teamfile.value("Team/Name", m_name).toString(); @@ -196,8 +213,8 @@ if(achievements[i][0][0]) AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt(); else - break; - return true; + break;*/ + return m_team != NULL; } bool HWTeam::fileExists() diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/team.h --- a/QTfrontend/team.h Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/team.h Sun Nov 25 01:13:51 2012 +0400 @@ -25,6 +25,7 @@ #include "binds.h" #include "achievements.h" #include "hwconsts.h" +#include "frontlib.h" class HWForm; class GameUIConfig; @@ -53,6 +54,7 @@ HWTeam(const QStringList& strLst); HWTeam(); HWTeam(const HWTeam & other); + ~HWTeam(); // file operations static HWTeam loadFromFile(const QString & teamName); @@ -117,6 +119,8 @@ quint8 m_difficulty; QList m_binds; + flib_team * m_team; + // class members that contain info for the current game setup quint8 m_numHedgehogs; int m_color; diff -r 59a8feebec2c -r 0e6fadf81a2c QTfrontend/util/frontlibpoller.cpp --- a/QTfrontend/util/frontlibpoller.cpp Sat Nov 24 00:07:05 2012 +0400 +++ b/QTfrontend/util/frontlibpoller.cpp Sun Nov 25 01:13:51 2012 +0400 @@ -8,7 +8,8 @@ m_poll = poll; m_data = data; - m_timer.start(50, this); + if(m_data) + m_timer.start(50, this); } void FrontLibPoller::timerEvent(QTimerEvent *event) diff -r 59a8feebec2c -r 0e6fadf81a2c misc/physfs/CMakeLists.txt --- a/misc/physfs/CMakeLists.txt Sat Nov 24 00:07:05 2012 +0400 +++ b/misc/physfs/CMakeLists.txt Sun Nov 25 01:13:51 2012 +0400 @@ -141,6 +141,7 @@ extras/physfsrwops.c extras/physfslualoader.c extras/hwpacksmounter.c + extras/physfsfgets.c ${PHYSFS_BEOS_SRCS} ) diff -r 59a8feebec2c -r 0e6fadf81a2c misc/physfs/extras/physfsfgets.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/physfs/extras/physfsfgets.c Sun Nov 25 01:13:51 2012 +0400 @@ -0,0 +1,27 @@ +#include + +#include "physfsfgets.h" + +char * PHYSFS_fgets(char * str, int size, PHYSFS_file * f) +{ + int i = 0; + char c; + + if(size <= 0 || PHYSFS_eof(f)) + return NULL; + + do + { + if (PHYSFS_readBytes(f, &c, 1) < 1) + break; + + str[i] = c; + ++i; + } while(c != '\n' && i < size - 1); + + str[i] = '\0'; + if (i == 0) + return NULL; + else + return str; +} diff -r 59a8feebec2c -r 0e6fadf81a2c misc/physfs/extras/physfsfgets.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/physfs/extras/physfsfgets.h Sun Nov 25 01:13:51 2012 +0400 @@ -0,0 +1,17 @@ +#ifndef PHYSFS_FGETS_H +#define PHYSFS_FGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "physfs.h" + +char * PHYSFS_fgets(char * str, int size, PHYSFS_file * f); + + +#ifdef __cplusplus +} +#endif + +#endif diff -r 59a8feebec2c -r 0e6fadf81a2c project_files/frontlib/CMakeLists.txt --- a/project_files/frontlib/CMakeLists.txt Sat Nov 24 00:07:05 2012 +0400 +++ b/project_files/frontlib/CMakeLists.txt Sun Nov 25 01:13:51 2012 +0400 @@ -7,6 +7,7 @@ file(GLOB frontlib_src *.c *.h base64/*.c base64/*.h + iniparser/*.c iniparser/*.h ipc/*.c ipc/*.h md5/*.c md5/*.h model/*.c model/*.h @@ -17,5 +18,7 @@ include_directories(${SDL_INCLUDE_DIR}) include_directories(${SDLNET_INCLUDE_DIR}) include_directories(${ZLIB_INCLUDE_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/src) +include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/extras) add_library(frontlib STATIC ${frontlib_src}) diff -r 59a8feebec2c -r 0e6fadf81a2c project_files/frontlib/iniparser/iniparser.c --- a/project_files/frontlib/iniparser/iniparser.c Sat Nov 24 00:07:05 2012 +0400 +++ b/project_files/frontlib/iniparser/iniparser.c Sun Nov 25 01:13:51 2012 +0400 @@ -9,6 +9,8 @@ /*---------------------------- Includes ------------------------------------*/ #include #include "iniparser.h" +#include "physfs.h" +#include "physfsfgets.h" /*---------------------------- Defines -------------------------------------*/ #define ASCIILINESZ (1024) @@ -628,7 +630,7 @@ /*--------------------------------------------------------------------------*/ dictionary * iniparser_load(const char * ininame) { - FILE * in ; + PHYSFS_File * in ; char line [ASCIILINESZ+1] ; char section [ASCIILINESZ+1] ; @@ -643,14 +645,14 @@ dictionary * dict ; - if ((in=fopen(ininame, "r"))==NULL) { + if ((in = PHYSFS_openRead(ininame))==NULL) { fprintf(stderr, "iniparser: cannot open %s\n", ininame); return NULL ; } dict = dictionary_new(0) ; if (!dict) { - fclose(in); + PHYSFS_close(in); return NULL ; } @@ -660,7 +662,7 @@ memset(val, 0, ASCIILINESZ); last=0 ; - while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { + while (PHYSFS_fgets(line+last, ASCIILINESZ-last, in)!=NULL) { lineno++ ; len = (int)strlen(line)-1; if (len==0) @@ -672,7 +674,7 @@ ininame, lineno); dictionary_del(dict); - fclose(in); + PHYSFS_close(in); return NULL ; } /* Get rid of \n and spaces at end of line */ @@ -725,7 +727,7 @@ dictionary_del(dict); dict = NULL ; } - fclose(in); + PHYSFS_close(in); return dict ; } diff -r 59a8feebec2c -r 0e6fadf81a2c project_files/hedgewars.pro --- a/project_files/hedgewars.pro Sat Nov 24 00:07:05 2012 +0400 +++ b/project_files/hedgewars.pro Sun Nov 25 01:13:51 2012 +0400 @@ -236,7 +236,7 @@ RESOURCES += ../QTfrontend/hedgewars.qrc -LIBS += -L../bin -lphysfs -lfrontlib +LIBS += -L../bin -lfrontlib -lphysfs macx { QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6