mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Simplified the looging macros, and added logs in various key places.
This commit is contained in:
parent
674cd3e838
commit
0c76b9d781
30 changed files with 159 additions and 73 deletions
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
@ -65,7 +64,7 @@
|
|||
#define fmt(a) boost::format(a)
|
||||
|
||||
|
||||
INIT_LOGGER(CompDic::logger, "Compdic");
|
||||
INIT_LOGGER(dic, CompDic);
|
||||
|
||||
CompDic::CompDic()
|
||||
: m_currentRec(0), m_maxRec(0), m_loadTime(0), m_buildTime(0)
|
||||
|
@ -186,7 +185,7 @@ void CompDic::writeNode(uint32_t *ioEdges, unsigned int num, ostream &outFile)
|
|||
ioEdges[i] = htonl(ioEdges[i]);
|
||||
}
|
||||
|
||||
LOG_TRACE(logger, fmt("writing %1% edges") % num);
|
||||
LOG_TRACE(fmt("writing %1% edges") % num);
|
||||
outFile.write((char*)ioEdges, num * sizeof(DicEdge));
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ using namespace std;
|
|||
|
||||
class CompDic
|
||||
{
|
||||
DEFINE_LOGGER(logger);
|
||||
DEFINE_LOGGER();
|
||||
typedef boost::unordered_map<vector<DicEdge>, unsigned int> HashMap;
|
||||
|
||||
public:
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
|
|
|
@ -26,25 +26,29 @@
|
|||
#ifdef USE_LOGGING
|
||||
# include <log4cxx/logger.h>
|
||||
|
||||
# define DEFINE_LOGGER(logger) static log4cxx::LoggerPtr logger;
|
||||
# define INIT_LOGGER(logger, name) log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(name))
|
||||
# define DEFINE_LOGGER() static log4cxx::LoggerPtr logger
|
||||
# define INIT_LOGGER(prefix, className) log4cxx::LoggerPtr className::logger(log4cxx::Logger::getLogger(#prefix "." #className))
|
||||
|
||||
# define LOG_TRACE(a, b) LOG4CXX_TRACE(a, b)
|
||||
# define LOG_DEBUG(a, b) LOG4CXX_DEBUG(a, b)
|
||||
# define LOG_INFO(a, b) LOG4CXX_INFO(a, b)
|
||||
# define LOG_WARN(a, b) LOG4CXX_WARN(a, b)
|
||||
# define LOG_ERROR(a, b) LOG4CXX_ERROR(a, b)
|
||||
# define LOG_FATAL(a, b) LOG4CXX_FATAL(a, b)
|
||||
# define LOG_TRACE(a) LOG4CXX_TRACE(logger, a)
|
||||
# define LOG_DEBUG(a) LOG4CXX_DEBUG(logger, a)
|
||||
# define LOG_INFO(a) LOG4CXX_INFO(logger, a)
|
||||
# define LOG_WARN(a) LOG4CXX_WARN(logger, a)
|
||||
# define LOG_ERROR(a) LOG4CXX_ERROR(logger, a)
|
||||
# define LOG_FATAL(a) LOG4CXX_FATAL(logger, a)
|
||||
# define LOG_ROOT_ERROR(a) LOG4CXX_ERROR(log4cxx::Logger::getRootLogger(), a)
|
||||
# define LOG_ROOT_FATAL(a) LOG4CXX_FATAL(log4cxx::Logger::getRootLogger(), a)
|
||||
#else
|
||||
# define DEFINE_LOGGER(logger)
|
||||
# define INIT_LOGGER(logger, name)
|
||||
# define DEFINE_LOGGER()
|
||||
# define INIT_LOGGER(prefix, name)
|
||||
|
||||
# define LOG_TRACE(a, b)
|
||||
# define LOG_DEBUG(a, b)
|
||||
# define LOG_INFO(a, b)
|
||||
# define LOG_WARN(a, b)
|
||||
# define LOG_ERROR(a, b)
|
||||
# define LOG_FATAL(a, b)
|
||||
# define LOG_TRACE(a)
|
||||
# define LOG_DEBUG(a)
|
||||
# define LOG_INFO(a)
|
||||
# define LOG_WARN(a)
|
||||
# define LOG_ERROR(a)
|
||||
# define LOG_FATAL(a)
|
||||
# define LOG_ROOT_ERROR(a)
|
||||
# define LOG_ROOT_FATAL(a)
|
||||
#endif // USE_LOGGING
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#include "dic.h"
|
||||
#include <cwctype> // For towupper
|
||||
|
||||
#include "board_search.h"
|
||||
#include "dic.h"
|
||||
#include "board.h"
|
||||
#include "tile.h"
|
||||
#include "rack.h"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "matrix.h"
|
||||
|
||||
class Dictionary;
|
||||
class Tile;
|
||||
class Rack;
|
||||
class Results;
|
||||
class Round;
|
||||
|
|
|
@ -45,9 +45,13 @@
|
|||
#include "mark_played_cmd.h"
|
||||
#include "ai_player.h"
|
||||
#include "settings.h"
|
||||
#include "encoding.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, Duplicate);
|
||||
|
||||
|
||||
Duplicate::Duplicate(const Dictionary &iDic)
|
||||
: Game(iDic)
|
||||
{
|
||||
|
@ -177,6 +181,7 @@ void Duplicate::tryEndTurn()
|
|||
|
||||
void Duplicate::recordPlayerMove(const Move &iMove, Player &ioPlayer, bool isForHuman)
|
||||
{
|
||||
LOG_INFO("Player " << ioPlayer.getId() << " plays: " << convertToMb(iMove.toString()));
|
||||
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
|
||||
pCmd->setAutoExecution(!isForHuman);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
|
@ -278,6 +283,7 @@ void Duplicate::endTurn()
|
|||
|
||||
void Duplicate::endGame()
|
||||
{
|
||||
LOG_INFO("End of the game");
|
||||
m_finished = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "game.h"
|
||||
#include "command.h"
|
||||
#include "logging.h"
|
||||
|
||||
class Player;
|
||||
|
||||
|
@ -53,6 +54,7 @@ using std::wstring;
|
|||
*/
|
||||
class Duplicate: public Game
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
friend class GameFactory;
|
||||
friend class MarkPlayedCmd;
|
||||
public:
|
||||
|
|
|
@ -40,9 +40,12 @@
|
|||
#include "ai_player.h"
|
||||
#include "settings.h"
|
||||
#include "turn.h"
|
||||
#include "encoding.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
INIT_LOGGER(game, FreeGame);
|
||||
|
||||
|
||||
FreeGame::FreeGame(const Dictionary &iDic)
|
||||
: Game(iDic)
|
||||
|
@ -113,6 +116,7 @@ void FreeGame::playAI(unsigned int p)
|
|||
void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer,
|
||||
bool isForHuman)
|
||||
{
|
||||
LOG_INFO("Player " << ioPlayer.getId() << " plays: " << convertToMb(iMove.toString()));
|
||||
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
|
||||
pCmd->setAutoExecution(!isForHuman);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
|
@ -189,6 +193,8 @@ int FreeGame::endTurn()
|
|||
// Adjust the scores of the players with the points of the remaining tiles
|
||||
void FreeGame::endGame()
|
||||
{
|
||||
LOG_INFO("End of the game");
|
||||
|
||||
vector<Tile> tiles;
|
||||
|
||||
// TODO: According to the rules of the game in the ODS, a game can end in 3
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define FREEGAME_H_
|
||||
|
||||
#include "game.h"
|
||||
#include "logging.h"
|
||||
|
||||
class Player;
|
||||
|
||||
|
@ -42,6 +43,7 @@ using std::vector;
|
|||
*/
|
||||
class FreeGame: public Game
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
friend class GameFactory;
|
||||
public:
|
||||
virtual GameMode getMode() const { return kFREEGAME; }
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include "debug.h"
|
||||
|
||||
INIT_LOGGER(game, Game);
|
||||
|
||||
const unsigned int Game::RACK_SIZE = 7;
|
||||
const int Game::BONUS_POINTS = 50;
|
||||
|
||||
|
@ -77,6 +79,7 @@ const Player& Game::getPlayer(unsigned int iNum) const
|
|||
|
||||
void Game::shuffleRack()
|
||||
{
|
||||
LOG_DEBUG("Shuffling rack for player " << currPlayer());
|
||||
PlayedRack pld = getCurrentPlayer().getCurrentRack();
|
||||
pld.shuffle();
|
||||
m_players[currPlayer()]->setCurrentRack(pld);
|
||||
|
@ -340,11 +343,10 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
|
|||
|
||||
// Get the best word
|
||||
const Round & bestRound = res.get(0);
|
||||
#ifdef DEBUG
|
||||
cout << "helperSetRackRandom(): initial rack: "
|
||||
LOG_DEBUG("helperSetRackRandom(): initial rack: "
|
||||
<< convertToMb(pld.toString()) << " (best word: "
|
||||
<< convertToMb(bestRound.getWord()) << ")" << endl;
|
||||
#endif
|
||||
<< convertToMb(bestRound.getWord()) << ")");
|
||||
|
||||
// Identify the joker
|
||||
for (unsigned int i = 0; i < bestRound.getWordLen(); ++i)
|
||||
{
|
||||
|
@ -352,10 +354,9 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
|
|||
{
|
||||
const Tile &jokerTile = bestRound.getTile(i);
|
||||
Tile replacingTile(towupper(jokerTile.toChar()));
|
||||
#ifdef DEBUG
|
||||
cout << "helperSetRackRandom(): replacing Joker with "
|
||||
<< convertToMb(replacingTile.toChar()) << endl;
|
||||
#endif
|
||||
LOG_DEBUG("helperSetRackRandom(): replacing Joker with "
|
||||
<< convertToMb(replacingTile.toChar()));
|
||||
|
||||
// If the bag does not contain this letter anymore,
|
||||
// simply keep the joker in the rack.
|
||||
if (bag.in(replacingTile))
|
||||
|
@ -457,6 +458,10 @@ void Game::addPlayer(Player *iPlayer)
|
|||
// The ID of the player is its position in the m_players vector
|
||||
iPlayer->setId(getNPlayers());
|
||||
m_players.push_back(iPlayer);
|
||||
|
||||
LOG_INFO("Adding player '" << convertToMb(iPlayer->getName())
|
||||
<< "' (" << (iPlayer->isHuman() ? "human" : "AI") << ")"
|
||||
<< " with ID " << iPlayer->getId());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "logging.h"
|
||||
#include "bag.h"
|
||||
#include "board.h"
|
||||
#include "history.h"
|
||||
|
@ -48,6 +48,7 @@ using namespace std;
|
|||
*/
|
||||
class Game
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
/// Game specs.
|
||||
static const unsigned int RACK_SIZE;
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "xml_reader.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, GameFactory);
|
||||
|
||||
GameFactory *GameFactory::m_factory = NULL;
|
||||
|
||||
|
||||
|
@ -76,6 +78,7 @@ void GameFactory::Destroy()
|
|||
|
||||
Training *GameFactory::createTraining(const Dictionary &iDic)
|
||||
{
|
||||
LOG_INFO("Creating a training game");
|
||||
Training *game = new Training(iDic);
|
||||
return game;
|
||||
}
|
||||
|
@ -83,6 +86,7 @@ Training *GameFactory::createTraining(const Dictionary &iDic)
|
|||
|
||||
FreeGame *GameFactory::createFreeGame(const Dictionary &iDic)
|
||||
{
|
||||
LOG_INFO("Creating a free game");
|
||||
FreeGame *game = new FreeGame(iDic);
|
||||
return game;
|
||||
}
|
||||
|
@ -90,6 +94,7 @@ FreeGame *GameFactory::createFreeGame(const Dictionary &iDic)
|
|||
|
||||
Duplicate *GameFactory::createDuplicate(const Dictionary &iDic)
|
||||
{
|
||||
LOG_INFO("Creating a duplicate game");
|
||||
Duplicate *game = new Duplicate(iDic);
|
||||
return game;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "logging.h"
|
||||
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
@ -44,6 +45,7 @@ class Duplicate;
|
|||
*/
|
||||
class GameFactory
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
static GameFactory *Instance();
|
||||
static void Destroy();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <cstdlib> // For atoi
|
||||
#include <cwctype> // For iswlower
|
||||
#include <cstdio>
|
||||
|
||||
#include "dic.h"
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "encoding.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, Navigation);
|
||||
|
||||
Navigation::Navigation()
|
||||
: m_currTurn(0)
|
||||
{
|
||||
|
@ -46,6 +48,7 @@ Navigation::~Navigation()
|
|||
|
||||
void Navigation::newTurn()
|
||||
{
|
||||
LOG_INFO("New turn");
|
||||
lastTurn();
|
||||
m_turnCommands.push_back(new TurnCmd);
|
||||
++m_currTurn;
|
||||
|
@ -98,6 +101,7 @@ void Navigation::prevTurn()
|
|||
{
|
||||
if (m_currTurn > 1)
|
||||
{
|
||||
LOG_DEBUG("Navigating to the previous turn");
|
||||
--m_currTurn;
|
||||
m_turnCommands[m_currTurn]->undo();
|
||||
// Special case: when the last turn is empty, automatically
|
||||
|
@ -115,6 +119,7 @@ void Navigation::nextTurn()
|
|||
{
|
||||
if (m_currTurn < m_turnCommands.size())
|
||||
{
|
||||
LOG_DEBUG("Navigating to the next turn");
|
||||
m_turnCommands[m_currTurn]->execute();
|
||||
++m_currTurn;
|
||||
// Special case: when the last turn is empty, automatically
|
||||
|
@ -130,6 +135,7 @@ void Navigation::nextTurn()
|
|||
|
||||
void Navigation::firstTurn()
|
||||
{
|
||||
LOG_DEBUG("Navigating to the first turn");
|
||||
while (m_currTurn > 1)
|
||||
{
|
||||
prevTurn();
|
||||
|
@ -139,6 +145,7 @@ void Navigation::firstTurn()
|
|||
|
||||
void Navigation::lastTurn()
|
||||
{
|
||||
LOG_DEBUG("Navigating to the last turn");
|
||||
while (m_currTurn < m_turnCommands.size())
|
||||
{
|
||||
nextTurn();
|
||||
|
@ -148,6 +155,8 @@ void Navigation::lastTurn()
|
|||
|
||||
void Navigation::clearFuture()
|
||||
{
|
||||
LOG_DEBUG("Erasing all the future turns");
|
||||
|
||||
// Replay the auto-execution turns
|
||||
// (i.e. turns where only the AI was involved)
|
||||
while (!isLastTurn() && m_turnCommands[m_currTurn]->isAutoExecution())
|
||||
|
@ -180,12 +189,12 @@ const vector<TurnCmd *> & Navigation::getCommands() const
|
|||
|
||||
void Navigation::print() const
|
||||
{
|
||||
cout << "=== Commands history ===" << endl;
|
||||
cout << "Current position right after turn " << m_currTurn - 1 << endl;
|
||||
LOG_DEBUG("=== Commands history ===");
|
||||
LOG_DEBUG("Current position right after turn " << m_currTurn - 1);
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const Command *c, m_turnCommands)
|
||||
{
|
||||
cout << index << " " << convertToMb(c->toString()) << endl;
|
||||
LOG_DEBUG(index << " " << convertToMb(c->toString()));
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define NAVIGATION_H_
|
||||
|
||||
#include <vector>
|
||||
#include "logging.h"
|
||||
|
||||
class TurnCmd;
|
||||
class Command;
|
||||
|
@ -31,6 +32,7 @@ using namespace std;
|
|||
|
||||
class Navigation
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
Navigation();
|
||||
~Navigation();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cwctype> // For towupper
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
|
@ -45,6 +46,9 @@
|
|||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, Training);
|
||||
|
||||
|
||||
Training::Training(const Dictionary &iDic)
|
||||
: Game(iDic), m_results(1000)
|
||||
{
|
||||
|
@ -105,6 +109,7 @@ int Training::play(const wstring &iCoord, const wstring &iWord)
|
|||
|
||||
void Training::recordPlayerMove(const Move &iMove, Player &ioPlayer)
|
||||
{
|
||||
LOG_INFO("Player " << ioPlayer.getId() << " plays: " << convertToMb(iMove.toString()));
|
||||
// Update the rack and the score of the current player
|
||||
// PlayerMoveCmd::execute() must be called before Game::helperPlayMove()
|
||||
// (called in this class in endTurn()).
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "game.h"
|
||||
#include "round.h"
|
||||
#include "results.h"
|
||||
#include "logging.h"
|
||||
|
||||
class Player;
|
||||
|
||||
|
@ -44,6 +45,7 @@ using std::wstring;
|
|||
*/
|
||||
class Training: public Game
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
friend class GameFactory;
|
||||
public:
|
||||
virtual GameMode getMode() const { return kTRAINING; }
|
||||
|
|
|
@ -83,10 +83,10 @@ bool TurnCmd::isAutoExecution() const
|
|||
wstring TurnCmd::toString() const
|
||||
{
|
||||
wostringstream oss;
|
||||
oss << L"TurnCmd:" << endl;
|
||||
oss << L"TurnCmd:";
|
||||
BOOST_FOREACH(Command *cmd, m_commands)
|
||||
{
|
||||
oss << L" " << cmd->toString() << endl;
|
||||
oss << endl << L" " << cmd->toString();
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
|
|
@ -40,12 +40,17 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
INIT_LOGGER(game, XmlReader);
|
||||
|
||||
|
||||
Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
|
||||
{
|
||||
// Try to load the old format first
|
||||
LOG_INFO("Parsing savegame '" << iFileName << "'");
|
||||
|
||||
try
|
||||
{
|
||||
LOG_DEBUG("Trying old format");
|
||||
FILE *fin = fopen(iFileName.c_str(), "r");
|
||||
if (fin != NULL)
|
||||
{
|
||||
|
@ -53,14 +58,20 @@ Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
|
|||
fclose(fin);
|
||||
|
||||
if (game != NULL)
|
||||
{
|
||||
LOG_INFO("Savegame parsed successfully");
|
||||
return game;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const GameException &e)
|
||||
{
|
||||
// Ignore the exception
|
||||
LOG_DEBUG("This doesn't look like the old format");
|
||||
}
|
||||
|
||||
LOG_DEBUG("Trying XML format");
|
||||
|
||||
ifstream is(iFileName.c_str());
|
||||
if (!is.is_open())
|
||||
throw LoadGameException("Cannot open file '" + iFileName + "'");
|
||||
|
@ -79,6 +90,8 @@ Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
|
|||
Game *game = handler.getGame();
|
||||
if (game == NULL)
|
||||
throw LoadGameException(handler.errorMessage);
|
||||
|
||||
LOG_INFO("Savegame parsed successfully");
|
||||
return game;
|
||||
}
|
||||
|
||||
|
@ -155,12 +168,8 @@ void XmlReader::startElement(const string& namespaceURI,
|
|||
{
|
||||
(void) namespaceURI;
|
||||
(void) qName;
|
||||
#if 0
|
||||
if (!localName.empty())
|
||||
std::cout << "Start Element: " << namespaceURI << ":" << localName << std::endl;
|
||||
else
|
||||
std::cout << "Start Element: " << qName << std::endl;
|
||||
#endif
|
||||
LOG_DEBUG("Start Element: " << (localName.empty() ? qName : namespaceURI + ":" + localName));
|
||||
|
||||
m_data.clear();
|
||||
const string &tag = localName;
|
||||
if (tag == "Player")
|
||||
|
@ -196,9 +205,8 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
const string&)
|
||||
{
|
||||
(void) namespaceURI;
|
||||
#if 0
|
||||
std::cout << "endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")" << std::endl;
|
||||
#endif
|
||||
LOG_DEBUG("endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")");
|
||||
|
||||
const string &tag = localName;
|
||||
if (tag == "Mode")
|
||||
{
|
||||
|
@ -276,16 +284,12 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
throw LoadGameException("Rack invalid for the current dictionary: " + m_data);
|
||||
}
|
||||
pldrack.setManual(rackStr);
|
||||
#if 0
|
||||
cerr << "loaded rack: " << convertToMb(pldrack.toString()) << endl;
|
||||
#endif
|
||||
LOG_DEBUG("loaded rack: " << convertToMb(pldrack.toString()));
|
||||
|
||||
Player &p = getPlayer(m_players, m_attributes["playerid"]);
|
||||
PlayerRackCmd *cmd = new PlayerRackCmd(p, pldrack);
|
||||
m_game->accessNavigation().addAndExecute(cmd);
|
||||
#if 0
|
||||
cerr << "rack: " << convertToMb(pldrack.toString()) << endl;
|
||||
#endif
|
||||
LOG_DEBUG("rack: " << convertToMb(pldrack.toString()));
|
||||
}
|
||||
|
||||
else if (tag == "PlayerMove")
|
||||
|
@ -310,15 +314,14 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
void XmlReader::characters(const string& ch)
|
||||
{
|
||||
m_data += ch;
|
||||
#if 0
|
||||
std::cout << "Characters: " << ch << std::endl;
|
||||
#endif
|
||||
LOG_DEBUG("Characters: " << ch);
|
||||
}
|
||||
|
||||
|
||||
void XmlReader::warning(const Arabica::SAX::SAXParseException<string>& exception)
|
||||
{
|
||||
errorMessage = string("warning: ") + exception.what();
|
||||
LOG_WARN(errorMessage);
|
||||
//throw LoadGameException(string("warning: ") + exception.what());
|
||||
}
|
||||
|
||||
|
@ -326,6 +329,7 @@ void XmlReader::warning(const Arabica::SAX::SAXParseException<string>& exception
|
|||
void XmlReader::error(const Arabica::SAX::SAXParseException<string>& exception)
|
||||
{
|
||||
errorMessage = string("error: ") + exception.what();
|
||||
LOG_ERROR(errorMessage);
|
||||
//throw LoadGameException(string("error: ") + exception.what());
|
||||
}
|
||||
|
||||
|
@ -333,6 +337,7 @@ void XmlReader::error(const Arabica::SAX::SAXParseException<string>& exception)
|
|||
void XmlReader::fatalError(const Arabica::SAX::SAXParseException<string>& exception)
|
||||
{
|
||||
errorMessage = string("fatal error: ") + exception.what();
|
||||
LOG_FATAL(errorMessage);
|
||||
//throw LoadGameException(string("fatal error: ") + exception.what());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <SAX/Locator.hpp>
|
||||
#include <SAX/Attributes.hpp>
|
||||
#include <SAX/SAXException.hpp>
|
||||
#include "logging.h"
|
||||
|
||||
class Dictionary;
|
||||
class Game;
|
||||
|
@ -36,6 +37,7 @@ using std::map;
|
|||
|
||||
class XmlReader : public Arabica::SAX::DefaultHandler<string>
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
virtual ~XmlReader() {}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
INIT_LOGGER(game, XmlWriter);
|
||||
|
||||
static void addIndent(string &s)
|
||||
{
|
||||
|
@ -81,6 +82,7 @@ static void writeMove(ostream &out, const Move &iMove,
|
|||
|
||||
void XmlWriter::write(const Game &iGame, const string &iFileName)
|
||||
{
|
||||
LOG_INFO("Saving game into '" << iFileName << "'");
|
||||
ofstream out(iFileName.c_str());
|
||||
if (!out.is_open())
|
||||
throw SaveGameException("Cannot open file for writing: '" + iFileName + "'");
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define XML_WRITER_H_
|
||||
|
||||
#include <iosfwd>
|
||||
#include "logging.h"
|
||||
|
||||
class Game;
|
||||
|
||||
|
@ -29,6 +30,7 @@ using std::string;
|
|||
|
||||
class XmlWriter
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
static void write(const Game &iGame, const string &iFileName);
|
||||
};
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QHeaderView>
|
||||
|
|
10
qt/main.cpp
10
qt/main.cpp
|
@ -22,10 +22,10 @@
|
|||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <QApplication>
|
||||
#include <QLocale>
|
||||
#include <QTranslator>
|
||||
#include "logging.h"
|
||||
#include "base_exception.h"
|
||||
#include "stacktrace.h"
|
||||
#include "main_window.h"
|
||||
|
@ -63,8 +63,7 @@ public:
|
|||
}
|
||||
catch (const BaseException &e)
|
||||
{
|
||||
cerr << "Exception caught: " << e.what() << endl;
|
||||
cerr << e.getStackTrace() << endl;
|
||||
LOG_ROOT_ERROR("Exception caught: " << e.what() << "\n" << e.getStackTrace());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -166,9 +165,8 @@ int main(int argc, char **argv)
|
|||
#ifdef HAVE_EXECINFO_H
|
||||
static void bt_sighandler(int signum)
|
||||
{
|
||||
cerr << "Segmentation fault!" << endl;
|
||||
cerr << "Backtrace:" << endl;
|
||||
cerr << StackTrace::GetStack() << endl;
|
||||
LOG_ROOT_FATAL("Segmentation fault!");
|
||||
LOG_ROOT_FATAL("Backtrace:\n" << StackTrace::GetStack());
|
||||
|
||||
// Restore the default handler to generate a nice core dump
|
||||
signal(signum, SIG_DFL);
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
#include "coord.h"
|
||||
|
||||
|
||||
INIT_LOGGER(qt, MainWindow);
|
||||
|
||||
const char *MainWindow::m_windowName = "MainWindow";
|
||||
|
||||
MainWindow::MainWindow(QWidget *iParent)
|
||||
|
@ -67,6 +69,7 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
m_prefsDialog(NULL), m_bagWindow(NULL), m_boardWindow(NULL),
|
||||
m_historyWindow(NULL), m_dicToolsWindow(NULL), m_dicNameLabel(NULL)
|
||||
{
|
||||
LOG_DEBUG("Creating main window");
|
||||
m_ui.setupUi(this);
|
||||
createMenu();
|
||||
readSettings();
|
||||
|
@ -79,10 +82,9 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
// but we would lose the desktop integration...
|
||||
unsigned int val = time(NULL);
|
||||
srand(val);
|
||||
#ifdef DEBUG
|
||||
|
||||
// Make it easier to reproduce bugs
|
||||
cout << "Rand seed: " << val << endl;
|
||||
#endif
|
||||
LOG_DEBUG("Rand seed: " << val);
|
||||
|
||||
QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)),
|
||||
this, SLOT(updateForGame(const PublicGame*)));
|
||||
|
@ -162,6 +164,7 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
QString dicPath = qs.value(PrefsDialog::kINTF_DIC_PATH, "").toString();
|
||||
if (dicPath != "")
|
||||
{
|
||||
LOG_INFO("Using dictionary " << qtl(dicPath));
|
||||
try
|
||||
{
|
||||
m_dic = new Dictionary(qtl(dicPath));
|
||||
|
@ -193,6 +196,8 @@ void MainWindow::destroyCurrentGame()
|
|||
if (m_game == NULL)
|
||||
return;
|
||||
|
||||
LOG_DEBUG("Destroying current game");
|
||||
|
||||
// Some controls, like the board, can live when there is no game.
|
||||
// We only have to give them a NULL handler instead of the current one.
|
||||
emit gameChangedNonConst(NULL);
|
||||
|
@ -202,6 +207,8 @@ void MainWindow::destroyCurrentGame()
|
|||
|
||||
delete m_game;
|
||||
m_game = NULL;
|
||||
|
||||
LOG_DEBUG("Game destroyed");
|
||||
}
|
||||
|
||||
|
||||
|
@ -217,8 +224,7 @@ void MainWindow::refresh()
|
|||
m_actionHistoryLastTurn->setEnabled(!isLastTurn);
|
||||
m_actionHistoryReplayTurn->setEnabled(!isLastTurn);
|
||||
#ifdef DEBUG
|
||||
cout << endl << endl;
|
||||
m_game->printTurns();
|
||||
//m_game->printTurns();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -226,6 +232,7 @@ void MainWindow::refresh()
|
|||
|
||||
void MainWindow::prefsUpdated()
|
||||
{
|
||||
LOG_DEBUG("Preferences updated");
|
||||
// Disconnect the training rack updates from the "Plus 1" tab of the
|
||||
// dictionary tools
|
||||
m_playersWidget->disconnect(SIGNAL(trainingRackUpdated(const QString&)));
|
||||
|
@ -295,6 +302,7 @@ void MainWindow::updateStatusBar(const Dictionary *iDic)
|
|||
|
||||
void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
|
||||
{
|
||||
LOG_ERROR("Displayed error: " << qtl(iMsg));
|
||||
if (iContext == "")
|
||||
iContext = _q("Eliot - Error");
|
||||
|
||||
|
@ -304,6 +312,7 @@ void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
|
|||
|
||||
void MainWindow::displayInfoMsg(QString iMsg)
|
||||
{
|
||||
LOG_INFO("Displayed message: " << qtl(iMsg));
|
||||
statusBar()->showMessage(iMsg);
|
||||
}
|
||||
|
||||
|
@ -364,6 +373,8 @@ void MainWindow::changeDictionary(QString iFileName)
|
|||
return;
|
||||
}
|
||||
|
||||
LOG_INFO("Loading new dictionary file: " << qtl(iFileName));
|
||||
|
||||
destroyCurrentGame();
|
||||
|
||||
try
|
||||
|
@ -437,7 +448,7 @@ void MainWindow::createMenu()
|
|||
false, QIcon(":/images/printer.png"));
|
||||
menuFile->addSeparator();
|
||||
addMenuAction(menuFile, _q("&Quit"), _q("Ctrl+Q"),
|
||||
_q("Quit Eliot"), SLOT(close()),
|
||||
_q("Quit Eliot"), SLOT(onGameQuit()),
|
||||
false, QIcon(":/images/quit_16px.png"));
|
||||
|
||||
QMenu *menuHistory = new QMenu(m_ui.menubar);
|
||||
|
@ -505,6 +516,8 @@ void MainWindow::createMenu()
|
|||
|
||||
void MainWindow::onGameNew()
|
||||
{
|
||||
LOG_DEBUG("Starting a new game (unconfirmed)");
|
||||
|
||||
if (m_dic == NULL)
|
||||
{
|
||||
displayErrorMsg(_q("You have to select a dictionary (.dawg file) "
|
||||
|
@ -538,11 +551,11 @@ void MainWindow::onGameNew()
|
|||
|
||||
m_ui.groupBoxPlayers->show();
|
||||
|
||||
displayInfoMsg(_q("Game started"));
|
||||
m_game->start();
|
||||
emit gameChangedNonConst(m_game);
|
||||
emit gameChanged(m_game);
|
||||
emit gameUpdated();
|
||||
displayInfoMsg(_q("Game started"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -600,6 +613,7 @@ void MainWindow::onGameSaveAs()
|
|||
|
||||
void MainWindow::onGamePrint()
|
||||
{
|
||||
LOG_DEBUG("Printing game (unconfirmed)");
|
||||
if (m_game == NULL)
|
||||
return;
|
||||
|
||||
|
@ -607,6 +621,8 @@ void MainWindow::onGamePrint()
|
|||
QPrintDialog printDialog(&printer, this);
|
||||
if (printDialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
LOG_INFO("Printing game");
|
||||
|
||||
QPainter painter(&printer);
|
||||
const History &history = m_game->getHistory();
|
||||
|
||||
|
@ -740,10 +756,19 @@ void MainWindow::onGamePrint()
|
|||
// Total score
|
||||
nextHeight += LINE_HEIGHT;
|
||||
painter.drawText(curWidth, nextHeight, QString("%1").arg(score));
|
||||
|
||||
LOG_INFO("Game printed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::onGameQuit()
|
||||
{
|
||||
LOG_INFO("Exiting");
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::onSettingsPreferences()
|
||||
{
|
||||
if (m_prefsDialog == NULL)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QMainWindow>
|
||||
|
||||
#include <ui/main_window.ui.h>
|
||||
#include "logging.h"
|
||||
#include "coord_model.h"
|
||||
|
||||
|
||||
|
@ -41,6 +42,7 @@ class QAction;
|
|||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
|
@ -67,6 +69,7 @@ private slots:
|
|||
void onGameLoad();
|
||||
void onGameSaveAs();
|
||||
void onGamePrint();
|
||||
void onGameQuit();
|
||||
void onSettingsChooseDic();
|
||||
void onSettingsCreateDic();
|
||||
void onSettingsPreferences();
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <cmath>
|
||||
// XXX: tmp
|
||||
#include <iostream>
|
||||
|
||||
#include "tile_layout.h"
|
||||
#include "tile_widget.h"
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <ctype.h>
|
||||
#include <cstring> // For strlen
|
||||
#include <cwctype> // For iswalnum
|
||||
#include <algorithm>
|
||||
|
||||
#include "ncurses.h"
|
||||
|
|
Loading…
Reference in a new issue