Skip to content

Commit 315e58f

Browse files
committed
New feature: poll external file for console commands
The commit adds "-refreshfile" and "-refreshinterval" command-line arguments. Every refreshinterval tics (or once a second if not specified) a refreshfile is read and is evaluated if exists and not empty. Then it is truncated. This feature provides a facility for an external program to control the game.
1 parent 751f859 commit 315e58f

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/common/console/c_console.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
#include "g_input.h"
6666
#include "c_commandbuffer.h"
6767
#include "vm.h"
68+
#include "m_argv.h"
69+
#include "doomdef.h"
6870

6971
#define LEFTMARGIN 8
7072
#define RIGHTMARGIN 8
@@ -110,6 +112,9 @@ static int TopLine, InsertLine;
110112

111113
static void ClearConsole ();
112114

115+
static FString* RefreshFile;
116+
static int RefreshInterval = 0;
117+
113118
struct GameAtExit
114119
{
115120
GameAtExit(FString str) : Command(str) {}
@@ -235,6 +240,8 @@ void C_InitConback(FTextureID fallback, bool tile, double brightness)
235240
void C_InitConsole (int width, int height, bool ingame)
236241
{
237242
int cwidth, cheight;
243+
const char *v;
244+
int i;
238245

239246
vidactive = ingame;
240247
if (CurrentConsoleFont != NULL)
@@ -250,6 +257,18 @@ void C_InitConsole (int width, int height, bool ingame)
250257
CmdLine.ConCols = ConWidth / cwidth;
251258

252259
if (conbuffer == NULL) conbuffer = new FConsoleBuffer;
260+
261+
i = Args->CheckParm ("-refreshfile");
262+
if (i > 0 && i < (int)Args->NumArgs() - 1)
263+
{
264+
RefreshFile = Args->GetArgList(i + 1);
265+
RefreshInterval = TICRATE;
266+
v = Args->CheckValue ("-refreshinterval");
267+
if (v != NULL && (atoi(v) != 0))
268+
{
269+
RefreshInterval = atoi(v);
270+
}
271+
}
253272
}
254273

255274
//==========================================================================
@@ -534,9 +553,31 @@ void C_NewModeAdjust ()
534553
int consoletic = 0;
535554
void C_Ticker()
536555
{
556+
FileReader fr;
537557
static int lasttic = 0;
558+
long filesize = 1;
538559
consoletic++;
539560

561+
if (RefreshInterval > 0 && (consoletic % RefreshInterval) == 0)
562+
{
563+
if (fr.OpenFile (RefreshFile->GetChars()))
564+
{
565+
auto length = fr.GetLength();
566+
fr.Close();
567+
568+
if (length > 0)
569+
{
570+
C_ExecFile (RefreshFile->GetChars());
571+
572+
// Truncate the file
573+
FileWriter fw;
574+
if (fw.Open (RefreshFile->GetChars())) {
575+
fw.Close ();
576+
}
577+
}
578+
}
579+
}
580+
540581
if (lasttic == 0)
541582
lasttic = consoletic - 1;
542583

0 commit comments

Comments
 (0)