45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/Debug/ILogSink.h>
|
|
#include <XCEngine/Debug/LogEntry.h>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <mutex>
|
|
|
|
namespace XCEngine {
|
|
namespace Debug {
|
|
|
|
struct EditorConsoleRecord {
|
|
uint64_t serial = 0;
|
|
LogEntry entry = {};
|
|
};
|
|
|
|
class EditorConsoleSink : public ILogSink {
|
|
public:
|
|
static EditorConsoleSink* GetInstance();
|
|
|
|
EditorConsoleSink();
|
|
~EditorConsoleSink() override;
|
|
|
|
void Log(const LogEntry& entry) override;
|
|
void Flush() override;
|
|
|
|
std::vector<LogEntry> GetLogs() const;
|
|
std::vector<EditorConsoleRecord> GetRecords() const;
|
|
uint64_t GetRevision() const;
|
|
void Clear();
|
|
void SetCallback(std::function<void()> callback);
|
|
|
|
private:
|
|
mutable std::mutex m_mutex;
|
|
std::vector<EditorConsoleRecord> m_logs;
|
|
std::function<void()> m_callback;
|
|
uint64_t m_nextSerial = 1;
|
|
uint64_t m_revision = 0;
|
|
static EditorConsoleSink* s_instance;
|
|
static constexpr size_t MAX_LOGS = 1000;
|
|
};
|
|
|
|
} // namespace Debug
|
|
} // namespace XCEngine
|