[Logger]: Refactor pipe (#570)

* [Logger]: Refactor pipe

* [Logger]: Remove unused function
This commit is contained in:
Edo 2022-11-17 23:06:47 +00:00 committed by GitHub
parent 45bd4e027c
commit 7a2f72f69c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 22 deletions

View File

@ -7,7 +7,7 @@ namespace Components
std::unordered_map<std::string, Game::LocalizeEntry*> Localization::LocalizeMap; std::unordered_map<std::string, Game::LocalizeEntry*> Localization::LocalizeMap;
std::optional<std::string> Localization::PrefixOverride; std::optional<std::string> Localization::PrefixOverride;
std::function<void(Game::LocalizeEntry*)> Localization::ParseCallback = nullptr; std::function<void(Game::LocalizeEntry*)> Localization::ParseCallback;
void Localization::Set(const std::string& psLocalReference, const std::string& psNewString) void Localization::Set(const std::string& psLocalReference, const std::string& psNewString)
{ {

View File

@ -5,7 +5,8 @@ namespace Components
std::mutex Logger::MessageMutex; std::mutex Logger::MessageMutex;
std::vector<std::string> Logger::MessageQueue; std::vector<std::string> Logger::MessageQueue;
std::vector<Network::Address> Logger::LoggingAddresses[2]; std::vector<Network::Address> Logger::LoggingAddresses[2];
void(*Logger::PipeCallback)(const std::string&) = nullptr;
std::function<void(const std::string&)> Logger::PipeCallback;
bool Logger::IsConsoleReady() bool Logger::IsConsoleReady()
{ {
@ -106,21 +107,6 @@ namespace Components
Logger::MessagePrint(channel, msg); Logger::MessagePrint(channel, msg);
} }
void Logger::Flush()
{
// if (!Game::Sys_IsMainThread())
// {
// while (!Logger::MessageQueue.empty())
// {
// std::this_thread::sleep_for(10ms);
// }
// }
// else
{
Logger::Frame();
}
}
void Logger::Frame() void Logger::Frame()
{ {
std::unique_lock _(Logger::MessageMutex); std::unique_lock _(Logger::MessageMutex);
@ -138,7 +124,7 @@ namespace Components
} }
} }
void Logger::PipeOutput(void(*callback)(const std::string&)) void Logger::PipeOutput(const std::function<void(const std::string&)>& callback)
{ {
Logger::PipeCallback = callback; Logger::PipeCallback = callback;
} }

View File

@ -12,9 +12,7 @@ namespace Components
static void Print_Stub(int channel, const char* message, ...); static void Print_Stub(int channel, const char* message, ...);
static void PipeOutput(void(*callback)(const std::string&)); static void PipeOutput(const std::function<void(const std::string&)>& callback);
static void Flush();
static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args); static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args);
static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args); static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args);
@ -96,10 +94,13 @@ namespace Components
static std::mutex MessageMutex; static std::mutex MessageMutex;
static std::vector<std::string> MessageQueue; static std::vector<std::string> MessageQueue;
static std::vector<Network::Address> LoggingAddresses[2]; static std::vector<Network::Address> LoggingAddresses[2];
static void(*PipeCallback)(const std::string&);
static std::function<void(const std::string&)> PipeCallback;
static void MessagePrint(int channel, const std::string& msg); static void MessagePrint(int channel, const std::string& msg);
static void Frame(); static void Frame();
static void G_LogPrintf_Hk(const char* fmt, ...); static void G_LogPrintf_Hk(const char* fmt, ...);
static void PrintMessage_Stub(); static void PrintMessage_Stub();
static void PrintMessagePipe(const char* data); static void PrintMessagePipe(const char* data);