mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-18 23:42:26 +00:00
Make console history persistent
The console history is saved to a file on quit and restored after starting the game. So the commands entered in the console the last times the game was run are still available in the console-history, just like commands that were just entered.
This commit is contained in:
parent
8c6e4eb38a
commit
04266eee5e
3 changed files with 44 additions and 0 deletions
|
@ -2853,6 +2853,9 @@ void idCommonLocal::Init( int argc, char **argv ) {
|
|||
|
||||
ClearCommandLine();
|
||||
|
||||
// load the persistent console history
|
||||
console->LoadHistory();
|
||||
|
||||
com_fullyInitialized = true;
|
||||
}
|
||||
|
||||
|
@ -2881,6 +2884,9 @@ void idCommonLocal::Shutdown( void ) {
|
|||
idAsyncNetwork::server.Kill();
|
||||
idAsyncNetwork::client.Shutdown();
|
||||
|
||||
// save persistent console history
|
||||
console->SaveHistory();
|
||||
|
||||
// game specific shut down
|
||||
ShutdownGame( false );
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
void Dump( const char *toFile );
|
||||
void Clear();
|
||||
|
||||
virtual void SaveHistory();
|
||||
virtual void LoadHistory();
|
||||
|
||||
//============================
|
||||
|
||||
const idMaterial * charSetShader;
|
||||
|
@ -516,6 +519,38 @@ void idConsoleLocal::Dump( const char *fileName ) {
|
|||
fileSystem->CloseFile( f );
|
||||
}
|
||||
|
||||
void idConsoleLocal::SaveHistory() {
|
||||
idFile *f = fileSystem->OpenFileWrite( "consolehistory.dat" );
|
||||
for ( int i=0; i < COMMAND_HISTORY; ++i ) {
|
||||
// make sure the history is in the right order
|
||||
int line = (nextHistoryLine + i) % COMMAND_HISTORY;
|
||||
const char *s = historyEditLines[line].GetBuffer();
|
||||
if ( s && s[0] ) {
|
||||
f->WriteString(s);
|
||||
}
|
||||
}
|
||||
fileSystem->CloseFile(f);
|
||||
}
|
||||
|
||||
void idConsoleLocal::LoadHistory() {
|
||||
idFile *f = fileSystem->OpenFileRead( "consolehistory.dat" );
|
||||
if ( f == NULL ) // file doesn't exist
|
||||
return;
|
||||
|
||||
historyLine = 0;
|
||||
idStr tmp;
|
||||
for ( int i=0; i < COMMAND_HISTORY; ++i ) {
|
||||
if ( f->Tell() >= f->Length() ) {
|
||||
break; // EOF is reached
|
||||
}
|
||||
f->ReadString(tmp);
|
||||
historyEditLines[i].SetBuffer(tmp.c_str());
|
||||
++historyLine;
|
||||
}
|
||||
nextHistoryLine = historyLine;
|
||||
fileSystem->CloseFile(f);
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
idConsoleLocal::PageUp
|
||||
|
|
|
@ -67,6 +67,9 @@ public:
|
|||
|
||||
virtual void Draw( bool forceFullScreen ) = 0;
|
||||
virtual void Print( const char *text ) = 0;
|
||||
|
||||
virtual void SaveHistory() = 0;
|
||||
virtual void LoadHistory() = 0;
|
||||
};
|
||||
|
||||
extern idConsole * console; // statically initialized to an idConsoleLocal
|
||||
|
|
Loading…
Reference in a new issue