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
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
// 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-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;
|
|
|
|
|
|
|
|
|
|
// ===================== PUBLIC ========================
|
|
|
|
|
|
|
|
|
|
Logger::Logger(){
|
|
|
|
|
fileName= "log.txt";
|
|
|
|
|
loadingTexture=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-05 21:38:50 +02:00
|
|
|
|
Logger::~Logger(){
|
|
|
|
|
cleanupLoadingTexture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::cleanupLoadingTexture() {
|
2010-06-24 12:52:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
if(loadingTexture!=NULL) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-04-05 21:48:26 +02:00
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
2010-06-24 12:52:58 +02:00
|
|
|
|
//renderer.endTexture(rsGlobal,loadingTexture);
|
|
|
|
|
loadingTexture->end();
|
|
|
|
|
delete loadingTexture;
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-04-05 21:48:26 +02:00
|
|
|
|
//delete loadingTexture;
|
2010-04-05 21:38:50 +02:00
|
|
|
|
loadingTexture=NULL;
|
|
|
|
|
}
|
2010-06-24 12:52:58 +02:00
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-05 21:38:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
Logger & Logger::getInstance(){
|
|
|
|
|
static Logger logger;
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::add(const string &str, bool renderScreen){
|
|
|
|
|
FILE *f=fopen(fileName.c_str(), "at+");
|
|
|
|
|
if(f!=NULL){
|
|
|
|
|
fprintf(f, "%s\n", str.c_str());
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
current= str;
|
|
|
|
|
if(renderScreen){
|
|
|
|
|
renderLoadingScreen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::clear(){
|
|
|
|
|
string s="Log file\n";
|
|
|
|
|
|
|
|
|
|
FILE *f= fopen(fileName.c_str(), "wt+");
|
|
|
|
|
if(f==NULL){
|
|
|
|
|
throw runtime_error("Error opening log file"+ fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(f, "%s", s.c_str());
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::loadLoadingScreen(string filepath){
|
|
|
|
|
|
2010-04-05 21:38:50 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
cleanupLoadingTexture();
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
if(filepath=="")
|
|
|
|
|
{
|
|
|
|
|
loadingTexture=NULL;
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
|
2010-04-05 19:43:04 +02:00
|
|
|
|
loadingTexture=GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
2010-04-05 21:38:50 +02:00
|
|
|
|
//loadingTexture = renderer.newTexture2D(rsGlobal);
|
2010-04-09 08:51:13 +02:00
|
|
|
|
loadingTexture->setMipmap(true);
|
|
|
|
|
//loadingTexture->getPixmap()->load(filepath);
|
|
|
|
|
loadingTexture->load(filepath);
|
2010-04-05 21:38:50 +02:00
|
|
|
|
|
2010-06-24 12:52:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-04-05 21:38:50 +02:00
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
renderer.initTexture(rsGlobal,loadingTexture);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== PRIVATE ====================
|
|
|
|
|
|
|
|
|
|
void Logger::renderLoadingScreen(){
|
|
|
|
|
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
|
|
|
|
|
renderer.reset2d();
|
|
|
|
|
renderer.clearBuffers();
|
|
|
|
|
if(loadingTexture==NULL){
|
|
|
|
|
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
renderer.renderBackground(loadingTexture);
|
|
|
|
|
}
|
|
|
|
|
renderer.renderText(
|
|
|
|
|
state, coreData.getMenuFontBig(), Vec3f(1.f),
|
|
|
|
|
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
|
|
|
|
|
|
|
|
|
|
renderer.renderText(
|
|
|
|
|
current, coreData.getMenuFontNormal(), 1.0f,
|
|
|
|
|
metrics.getVirtualW()/4,
|
|
|
|
|
62*metrics.getVirtualH()/100, false);
|
|
|
|
|
|
|
|
|
|
renderer.swapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|