2010-04-11 03:25:06 +02:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001-2008 Martio 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 "console.h"
|
|
|
|
|
|
|
|
#include "lang.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "game_constants.h"
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
#include "core_data.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Console
|
|
|
|
// =====================================================
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
Console::Console() {
|
2010-04-11 03:25:06 +02:00
|
|
|
//config
|
2010-10-22 09:28:55 +02:00
|
|
|
maxLines = Config::getInstance().getInt("ConsoleMaxLines");
|
|
|
|
maxStoredLines = Config::getInstance().getInt("ConsoleMaxLinesStored");
|
|
|
|
timeout = Config::getInstance().getInt("ConsoleTimeout");
|
|
|
|
timeElapsed = 0.0f;
|
2010-04-11 03:25:06 +02:00
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
void Console::addStdMessage(const string &s) {
|
2010-04-11 03:25:06 +02:00
|
|
|
addLine(Lang::getInstance().get(s));
|
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
void Console::addLine(string line, bool playSound, int playerIndex) {
|
|
|
|
try {
|
|
|
|
if(playSound == true) {
|
2010-04-11 03:25:06 +02:00
|
|
|
SoundRenderer::getInstance().playFx(CoreData::getInstance().getClickSoundA());
|
|
|
|
}
|
2010-10-22 09:28:55 +02:00
|
|
|
lines.insert(lines.begin(), StringTimePair(line, StringTimePairData(timeElapsed,playerIndex)));
|
|
|
|
if(lines.size() > maxLines) {
|
2010-04-11 03:25:06 +02:00
|
|
|
lines.pop_back();
|
|
|
|
}
|
2010-10-22 09:28:55 +02:00
|
|
|
storedLines.insert(storedLines.begin(), StringTimePair(line, StringTimePairData(timeElapsed,playerIndex)));
|
|
|
|
if(storedLines.size() > maxStoredLines) {
|
2010-04-14 22:49:14 +02:00
|
|
|
storedLines.pop_back();
|
|
|
|
}
|
2010-04-11 03:25:06 +02:00
|
|
|
}
|
|
|
|
catch(const exception &ex) {
|
|
|
|
char szBuf[1024]="";
|
|
|
|
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
2010-10-06 22:22:06 +02:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
2010-04-11 03:25:06 +02:00
|
|
|
throw runtime_error(szBuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
void Console::clearStoredLines() {
|
|
|
|
while(storedLines.empty() == false) {
|
2010-04-14 22:49:14 +02:00
|
|
|
storedLines.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
void Console::update() {
|
|
|
|
timeElapsed += 1.f / GameConstants::updateFps;
|
2010-04-11 03:25:06 +02:00
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
if(lines.empty() == false) {
|
|
|
|
if(lines.back().second.first < (timeElapsed - timeout)) {
|
2010-04-11 03:25:06 +02:00
|
|
|
lines.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:55 +02:00
|
|
|
bool Console::isEmpty() {
|
2010-04-11 03:25:06 +02:00
|
|
|
return lines.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|