Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: poll external file for console commands #1541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/common/console/c_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
#include "g_input.h"
#include "c_commandbuffer.h"
#include "vm.h"
#include "m_argv.h"
#include "doomdef.h"

#define LEFTMARGIN 8
#define RIGHTMARGIN 8
Expand Down Expand Up @@ -110,6 +112,9 @@ static int TopLine, InsertLine;

static void ClearConsole ();

static FString* RefreshFile;
static int RefreshInterval = 0;

struct GameAtExit
{
GameAtExit(FString str) : Command(str) {}
Expand Down Expand Up @@ -235,6 +240,8 @@ void C_InitConback(FTextureID fallback, bool tile, double brightness)
void C_InitConsole (int width, int height, bool ingame)
{
int cwidth, cheight;
const char *v;
int i;

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

if (conbuffer == NULL) conbuffer = new FConsoleBuffer;

i = Args->CheckParm ("-refreshfile");
if (i > 0 && i < (int)Args->NumArgs() - 1)
{
RefreshFile = Args->GetArgList(i + 1);
RefreshInterval = TICRATE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to merge this into QZDoom, I get the error that TICRATE isn't found.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, when doing this just on GZDoom, TICRATE isn't found. Please fix this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which toolchain are you using? It builds fine on my machine with GCC 11.2.0.
I have just added an #include "doomdef.h" statement in c_console.cpp, it should fix the problem, TICRATE is defined as enum in this file. Please try to reproduce the issue by building 315e58f.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using Visual Studio 2017. I'll try it again in a bit. If it works, then I'll put it in QZDoom.

v = Args->CheckValue ("-refreshinterval");
if (v != NULL && (atoi(v) != 0))
{
RefreshInterval = atoi(v);
}
}
}

//==========================================================================
Expand Down Expand Up @@ -534,9 +553,31 @@ void C_NewModeAdjust ()
int consoletic = 0;
void C_Ticker()
{
FileReader fr;
static int lasttic = 0;
long filesize = 1;
consoletic++;

if (RefreshInterval > 0 && (consoletic % RefreshInterval) == 0)
{
if (fr.OpenFile (RefreshFile->GetChars()))
{
auto length = fr.GetLength();
fr.Close();

if (length > 0)
{
C_ExecFile (RefreshFile->GetChars());

// Truncate the file
FileWriter fw;
if (fw.Open (RefreshFile->GetChars())) {
fw.Close ();
}
}
}
}

if (lasttic == 0)
lasttic = consoletic - 1;

Expand Down