Skip to content

Commit

Permalink
Reduce transient inclusion of <future> (#21944)
Browse files Browse the repository at this point in the history
  • Loading branch information
janisozaur committed May 1, 2024
1 parent 15ee7a2 commit ad79699
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/openrct2-ui/interface/InGameConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once

#include <deque>
#include <openrct2/core/String.hpp>
#include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/localisation/FormatCodes.h>
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "entity/EntityTweener.h"
#include "interface/Chat.h"
#include "interface/InteractiveConsole.h"
#include "interface/StdInOutConsole.h"
#include "interface/Viewport.h"
#include "localisation/Date.h"
#include "localisation/Formatter.h"
Expand Down
26 changes: 0 additions & 26 deletions src/openrct2/interface/InteractiveConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include "../common.h"
#include "../localisation/FormatCodes.h"

#include <atomic>
#include <future>
#include <queue>
#include <string>

struct DrawPixelInfo;
Expand Down Expand Up @@ -49,26 +46,3 @@ class InteractiveConsole
virtual void Hide() abstract;
virtual void WriteLine(const std::string& s, FormatToken colourFormat) abstract;
};

class StdInOutConsole final : public InteractiveConsole
{
private:
std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue;
std::atomic<bool> _isPromptShowing{};

public:
void Start();
std::future<void> Eval(const std::string& s);
void ProcessEvalQueue();

void Clear() override;
void Close() override;
void Hide() override
{
}
void WriteLine(const std::string& s)
{
InteractiveConsole::WriteLine(s);
}
void WriteLine(const std::string& s, FormatToken colourFormat) override;
};
3 changes: 2 additions & 1 deletion src/openrct2/interface/StdInOutConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#include "StdInOutConsole.h"

#include "../Context.h"
#include "../OpenRCT2.h"
#include "../platform/Platform.h"
#include "../scripting/ScriptEngine.h"
#include "InteractiveConsole.h"

#include <linenoise.hpp>

Expand Down
39 changes: 39 additions & 0 deletions src/openrct2/interface/StdInOutConsole.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#pragma once

#include "InteractiveConsole.h"

#include <atomic>
#include <future>
#include <queue>

class StdInOutConsole final : public InteractiveConsole
{
private:
std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue;
std::atomic<bool> _isPromptShowing{};

public:
void Start();
std::future<void> Eval(const std::string& s);
void ProcessEvalQueue();

void Clear() override;
void Close() override;
void Hide() override
{
}
void WriteLine(const std::string& s)
{
InteractiveConsole::WriteLine(s);
}
void WriteLine(const std::string& s, FormatToken colourFormat) override;
};

0 comments on commit ad79699

Please sign in to comment.