Allow for progress bar completion

This commit is contained in:
Marcus Minhorst 2025-08-06 17:58:02 -04:00 committed by Ricardo Luís Vaz Silva
commit 54b80b96cd
6 changed files with 18 additions and 20 deletions

View file

@ -50,7 +50,7 @@ public:
virtual ~FStartupScreen() = default;
virtual void Progress() {}
virtual void Progress(int advance = 1) {}
virtual void AppendStatusLine(const char* status) {}
virtual void LoadingStatus(const char* message, int colors) {}
@ -77,7 +77,7 @@ public:
FBasicStartupScreen(int max_progress);
~FBasicStartupScreen();
void Progress() override;
void Progress(int advance = 1) override;
void NetInit(const char* message, bool host) override;
void NetMessage(const char* message) override;

View file

@ -84,13 +84,9 @@ FBasicStartupScreen::~FBasicStartupScreen()
}
void FBasicStartupScreen::Progress()
void FBasicStartupScreen::Progress(int advance)
{
if (CurPos < MaxPos)
{
++CurPos;
}
CurPos = min(CurPos + advance, MaxPos);
FConsoleWindow::GetInstance().Progress(CurPos, MaxPos);
}

View file

@ -216,10 +216,15 @@ void CleanProgressBar()
}
static int ProgressBarCurPos, ProgressBarMaxPos;
static bool ProgressBarComplete;
void RedrawProgressBar(int CurPos, int MaxPos)
{
if (!isatty(STDOUT_FILENO)) return;
if (ProgressBarComplete && CurPos >= MaxPos) return;
ProgressBarComplete = CurPos >= MaxPos; // draw once
CleanProgressBar();
struct winsize sizeOfWindow;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &sizeOfWindow);

View file

@ -53,7 +53,7 @@ class FTTYStartupScreen : public FStartupScreen
FTTYStartupScreen(int max_progress);
~FTTYStartupScreen();
void Progress() override;
void Progress(int amount = 1) override;
void NetInit(const char* message, bool host) override;
void NetMessage(const char* message) override;
@ -137,12 +137,9 @@ FTTYStartupScreen::~FTTYStartupScreen()
//
//===========================================================================
void FTTYStartupScreen::Progress()
void FTTYStartupScreen::Progress(int advance)
{
if (CurPos < MaxPos)
{
++CurPos;
}
CurPos = min(CurPos + advance, MaxPos);
RedrawProgressBar(CurPos, MaxPos);
}
@ -240,6 +237,7 @@ void FTTYStartupScreen::NetProgress(int cur, int limit)
void FTTYStartupScreen::NetDone()
{
CurPos = MaxPos;
CleanProgressBar();
// Restore stdin settings
if (DidNetInit)

View file

@ -117,12 +117,9 @@ FBasicStartupScreen::~FBasicStartupScreen()
//
//==========================================================================
void FBasicStartupScreen::Progress()
void FBasicStartupScreen::Progress(int advance)
{
if (CurPos < MaxPos)
{
CurPos++;
}
CurPos = min(CurPos + advance, MaxPos);
}
//==========================================================================

View file

@ -3366,7 +3366,7 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
if (!batchrun) Printf ("ST_Init: Init startup screen.\n");
if (!restart)
{
StartWindow = FStartupScreen::CreateInstance (TexMan.GuesstimateNumTextures() + 5);
StartWindow = FStartupScreen::CreateInstance(max_progress);
}
else
{
@ -3581,7 +3581,9 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
}
S_Sound (CHAN_BODY, 0, "misc/startupdone", 1, ATTN_NONE);
if (!batchrun) Printf ("Init complete.\n");
StartWindow->Progress(max_progress);
if (StartScreen)
{
StartScreen->Progress(max_progress); // advance progress bar to the end.