2010-04-05 19:43:04 +02:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
|
|
|
|
//
|
2010-12-09 21:41:11 +01:00
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
2010-04-05 19:43:04 +02:00
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "metrics.h"
|
|
|
|
|
#include "lang.h"
|
|
|
|
|
#include "graphics_interface.h"
|
2010-12-09 21:41:11 +01:00
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
#include "game_util.h"
|
2010-04-05 21:38:50 +02:00
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace Shared::Graphics;
|
2010-04-05 21:38:50 +02:00
|
|
|
|
using namespace Shared::Util;
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class Logger
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
const int Logger::logLineCount= 15;
|
|
|
|
|
|
2010-12-09 21:41:11 +01:00
|
|
|
|
// ===================== PUBLIC ========================
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
Logger::Logger() {
|
2010-12-09 21:41:11 +01:00
|
|
|
|
string logs_path = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey);
|
|
|
|
|
|
|
|
|
|
fileName= logs_path + "log.txt";
|
2010-04-05 19:43:04 +02:00
|
|
|
|
loadingTexture=NULL;
|
2011-01-11 23:09:46 +01:00
|
|
|
|
showProgressBar = false;
|
2010-04-05 19:43:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
Logger::~Logger() {
|
2010-04-05 21:38:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
Logger & Logger::getInstance() {
|
2010-04-05 19:43:04 +02:00
|
|
|
|
static Logger logger;
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
void Logger::add(const string &str, bool renderScreen) {
|
2010-04-05 19:43:04 +02:00
|
|
|
|
FILE *f=fopen(fileName.c_str(), "at+");
|
|
|
|
|
if(f!=NULL){
|
|
|
|
|
fprintf(f, "%s\n", str.c_str());
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
current= str;
|
|
|
|
|
if(renderScreen){
|
|
|
|
|
renderLoadingScreen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
void Logger::clear() {
|
2010-04-05 19:43:04 +02:00
|
|
|
|
string s="Log file\n";
|
|
|
|
|
|
|
|
|
|
FILE *f= fopen(fileName.c_str(), "wt+");
|
|
|
|
|
if(f==NULL){
|
|
|
|
|
throw runtime_error("Error opening log file"+ fileName);
|
|
|
|
|
}
|
2010-12-09 21:41:11 +01:00
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
fprintf(f, "%s", s.c_str());
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
void Logger::loadLoadingScreen(string filepath) {
|
2010-12-09 21:41:11 +01:00
|
|
|
|
|
2010-04-05 21:38:50 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
if(filepath=="")
|
|
|
|
|
{
|
2010-12-09 21:41:11 +01:00
|
|
|
|
loadingTexture=NULL;
|
2010-04-05 19:43:04 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-04-05 21:38:50 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str());
|
2011-01-26 10:09:59 +01:00
|
|
|
|
loadingTexture = Renderer::findFactionLogoTexture(filepath);
|
2010-06-24 12:52:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-05 19:43:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-09 21:41:11 +01:00
|
|
|
|
// ==================== PRIVATE ====================
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
2011-01-09 11:03:33 +01:00
|
|
|
|
void Logger::renderLoadingScreen() {
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
|
|
|
|
|
renderer.reset2d();
|
|
|
|
|
renderer.clearBuffers();
|
2011-01-26 10:09:59 +01:00
|
|
|
|
if(loadingTexture == NULL) {
|
2010-04-05 19:43:04 +02:00
|
|
|
|
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
renderer.renderBackground(loadingTexture);
|
2010-12-09 21:41:11 +01:00
|
|
|
|
}
|
2010-04-05 19:43:04 +02:00
|
|
|
|
renderer.renderText(
|
2010-12-09 21:41:11 +01:00
|
|
|
|
state, coreData.getMenuFontBig(), Vec3f(1.f),
|
2010-04-05 19:43:04 +02:00
|
|
|
|
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
|
|
|
|
|
|
|
|
|
|
renderer.renderText(
|
2010-12-09 21:41:11 +01:00
|
|
|
|
current, coreData.getMenuFontNormal(), 1.0f,
|
|
|
|
|
metrics.getVirtualW()/4,
|
2010-04-05 19:43:04 +02:00
|
|
|
|
62*metrics.getVirtualH()/100, false);
|
2010-12-09 21:41:11 +01:00
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
if(showProgressBar == true) {
|
|
|
|
|
renderer.renderProgressBar(
|
|
|
|
|
progress,
|
|
|
|
|
metrics.getVirtualW()/4,
|
|
|
|
|
59*metrics.getVirtualH()/100,
|
|
|
|
|
coreData.getDisplayFontSmall(),
|
|
|
|
|
350,""); // no string here, because it has to be language specific and does not give much information
|
|
|
|
|
}
|
2011-01-09 11:03:33 +01:00
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
renderer.swapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|