mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
// ==============================================================
|
|
// 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
|
|
// =====================================================
|
|
|
|
Console::Console(){
|
|
//config
|
|
maxLines= Config::getInstance().getInt("ConsoleMaxLines");
|
|
maxStoredLines= Config::getInstance().getInt("ConsoleMaxLinesStored");
|
|
timeout= Config::getInstance().getInt("ConsoleTimeout");
|
|
|
|
timeElapsed= 0.0f;
|
|
}
|
|
|
|
void Console::addStdMessage(const string &s){
|
|
addLine(Lang::getInstance().get(s));
|
|
}
|
|
|
|
void Console::addLine(string line, bool playSound){
|
|
try
|
|
{
|
|
if(playSound){
|
|
SoundRenderer::getInstance().playFx(CoreData::getInstance().getClickSoundA());
|
|
}
|
|
lines.insert(lines.begin(), StringTimePair(line, timeElapsed));
|
|
if(lines.size()>maxLines){
|
|
lines.pop_back();
|
|
}
|
|
storedLines.insert(storedLines.begin(), StringTimePair(line, timeElapsed));
|
|
if(storedLines.size()>maxStoredLines){
|
|
storedLines.pop_back();
|
|
}
|
|
}
|
|
catch(const exception &ex) {
|
|
char szBuf[1024]="";
|
|
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
throw runtime_error(szBuf);
|
|
}
|
|
}
|
|
|
|
void Console::clearStoredLines(){
|
|
while(!storedLines.empty()){
|
|
storedLines.pop_back();
|
|
}
|
|
}
|
|
|
|
void Console::update(){
|
|
timeElapsed+= 1.f/GameConstants::updateFps;
|
|
|
|
if(!lines.empty()){
|
|
if(lines.back().second<timeElapsed-timeout){
|
|
lines.pop_back();
|
|
}
|
|
}
|
|
}
|
|
|
|
bool Console::isEmpty(){
|
|
return lines.empty();
|
|
}
|
|
|
|
|
|
}}//end namespace
|