added maxhistory var

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4767 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2010-01-14 00:56:15 +00:00
parent e8157fd098
commit e883c41781
+13 -3
View File
@@ -336,6 +336,8 @@ struct hline
vector<hline *> history;
int histpos = 0;
VARP(maxhistory, 0, 1000, 10000);
void history_(int n)
{
static bool inhistory = false;
@@ -391,11 +393,12 @@ void consolekey(int code, bool isdown, int cooked)
break;
case SDLK_UP:
if(histpos>0) history[--histpos]->restore();
if(histpos > history.length()) histpos = history.length();
if(histpos > 0) history[--histpos]->restore();
break;
case SDLK_DOWN:
if(histpos+1<history.length()) history[++histpos]->restore();
if(histpos + 1 < history.length()) history[++histpos]->restore();
break;
case SDLK_TAB:
@@ -420,7 +423,14 @@ void consolekey(int code, bool isdown, int cooked)
if(cmdline.buf[0])
{
if(history.empty() || history.last()->shouldsave())
history.add(h = new hline)->save(); // cap this?
{
if(maxhistory && history.length() >= maxhistory)
{
loopi(history.length()-maxhistory+1) delete history[i];
history.remove(0, history.length()-maxhistory+1);
}
history.add(h = new hline)->save();
}
else h = history.last();
}
histpos = history.length();