1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-11 01:52:32 +01:00

Fix #23348: console command bugfixes and refactor (#23369)

This commit fixes the graphics bug #23348 by introducing an asynchronous

command completion signalling system in InteractiveConsole. This causes the
console to stop accepting new inputs while a command is being executed.

The console command system was also refactored to reduce code duplication and
remove return codes, which were unused and also poor error handling.
This commit is contained in:
InvokeStatic (Brendan Heinonen)
2024-12-16 00:59:47 -05:00
committed by GitHub
parent 6ee798337a
commit a3691982b3
6 changed files with 216 additions and 365 deletions

View File

@@ -246,6 +246,7 @@ Appreciation for contributors who have provided substantial work, but are no lon
* Mike Harvey (harvito) * Mike Harvey (harvito)
* Robert Yan (lewyche) * Robert Yan (lewyche)
* Tom Matalenas (tmatale) * Tom Matalenas (tmatale)
* Brendan Heinonen (staticinvocation)
## Toolchain ## Toolchain
* (Balletie) - macOS * (Balletie) - macOS

View File

@@ -4,6 +4,7 @@
- Improved: [#23350] Increased the maximum width of the ride graph window. - Improved: [#23350] Increased the maximum width of the ride graph window.
- Improved: [#23404] Folders are now paired with an icon in the load/save window. - Improved: [#23404] Folders are now paired with an icon in the load/save window.
- Fix: [#23286] Currency formatted incorrectly in the in game console. - Fix: [#23286] Currency formatted incorrectly in the in game console.
- Fix: [#23348] Console set commands don't print output properly.
0.4.17 (2024-12-08) 0.4.17 (2024-12-08)
------------------------------------------------------------------------ ------------------------------------------------------------------------

View File

@@ -54,6 +54,12 @@ void InGameConsole::WritePrompt()
void InGameConsole::Input(ConsoleInput input) void InGameConsole::Input(ConsoleInput input)
{ {
if (_isCommandAwaitingCompletion)
{
// Do not process input while a command is running
return;
}
switch (input) switch (input)
{ {
case ConsoleInput::LineClear: case ConsoleInput::LineClear:
@@ -69,7 +75,14 @@ void InGameConsole::Input(ConsoleInput input)
_consoleLines.back().append(_consoleCurrentLine); _consoleLines.back().append(_consoleCurrentLine);
Execute(_consoleCurrentLine); Execute(_consoleCurrentLine);
WritePrompt(); if (IsExecuting())
{
_isCommandAwaitingCompletion = true;
}
else
{
WritePrompt();
}
ClearInput(); ClearInput();
RefreshCaret(); RefreshCaret();
} }
@@ -271,6 +284,12 @@ void InGameConsole::Update()
} }
} }
if (_isCommandAwaitingCompletion && !IsExecuting())
{
WritePrompt();
_isCommandAwaitingCompletion = false;
}
// Flash the caret // Flash the caret
_consoleCaretTicks = (_consoleCaretTicks + 1) % 30; _consoleCaretTicks = (_consoleCaretTicks + 1) % 30;
} }

View File

@@ -30,6 +30,7 @@ namespace OpenRCT2::Ui
bool _isInitialised = false; bool _isInitialised = false;
bool _isOpen = false; bool _isOpen = false;
bool _isCommandAwaitingCompletion = false;
ScreenCoordsXY _consoleTopLeft; ScreenCoordsXY _consoleTopLeft;
ScreenCoordsXY _consoleBottomRight; ScreenCoordsXY _consoleBottomRight;
ScreenCoordsXY _lastMainViewport; ScreenCoordsXY _lastMainViewport;

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@
#include "../localisation/FormatCodes.h" #include "../localisation/FormatCodes.h"
#include <atomic>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@@ -30,6 +31,9 @@ enum class ConsoleInput : uint8_t
class InteractiveConsole class InteractiveConsole
{ {
private:
std::atomic_flag _commandExecuting;
public: public:
virtual ~InteractiveConsole() virtual ~InteractiveConsole()
{ {
@@ -41,6 +45,11 @@ public:
void WriteLineWarning(const std::string& s); void WriteLineWarning(const std::string& s);
void WriteFormatLine(const char* format, ...); void WriteFormatLine(const char* format, ...);
void BeginAsyncExecution();
void EndAsyncExecution();
bool IsExecuting();
virtual void Clear() = 0; virtual void Clear() = 0;
virtual void Close() = 0; virtual void Close() = 0;
virtual void Hide() = 0; virtual void Hide() = 0;