#include "Core/EditorConsoleSink.h" namespace XCEngine { namespace Debug { EditorConsoleSink* EditorConsoleSink::s_instance = nullptr; EditorConsoleSink* EditorConsoleSink::GetInstance() { return s_instance; } EditorConsoleSink::EditorConsoleSink() { s_instance = this; } EditorConsoleSink::~EditorConsoleSink() { if (s_instance == this) { s_instance = nullptr; } } void EditorConsoleSink::Log(const LogEntry& entry) { std::function callback; { std::lock_guard lock(m_mutex); if (m_logs.size() >= MAX_LOGS) { m_logs.erase(m_logs.begin()); } m_logs.push_back(EditorConsoleRecord{ m_nextSerial++, entry }); ++m_revision; callback = m_callback; } if (callback) { callback(); } } void EditorConsoleSink::Flush() { } std::vector EditorConsoleSink::GetLogs() const { std::lock_guard lock(m_mutex); std::vector logs; logs.reserve(m_logs.size()); for (const EditorConsoleRecord& record : m_logs) { logs.push_back(record.entry); } return logs; } std::vector EditorConsoleSink::GetRecords() const { std::lock_guard lock(m_mutex); return m_logs; } uint64_t EditorConsoleSink::GetRevision() const { std::lock_guard lock(m_mutex); return m_revision; } void EditorConsoleSink::Clear() { std::function callback; { std::lock_guard lock(m_mutex); if (m_logs.empty()) { return; } m_logs.clear(); ++m_revision; callback = m_callback; } if (callback) { callback(); } } void EditorConsoleSink::SetCallback(std::function callback) { std::lock_guard lock(m_mutex); m_callback = std::move(callback); } } // namespace Debug } // namespace XCEngine