mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-06 06:55:09 +00:00
add back fused gui log classes, this needs to be redone another way
also, add back wx requirement for strfmt
This commit is contained in:
parent
10e10de98d
commit
ed10ea7544
12 changed files with 332 additions and 333 deletions
|
|
@ -15,17 +15,171 @@
|
|||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
|
||||
LogWriter ConLog;
|
||||
class LogFrame;
|
||||
extern LogFrame* ConLogFrame;
|
||||
|
||||
std::mutex g_cs_conlog;
|
||||
|
||||
const uint max_item_count = 500;
|
||||
const uint buffer_size = 1024 * 64;
|
||||
|
||||
static const std::string g_log_colors[] =
|
||||
{
|
||||
"Black", "Green", "White", "Yellow", "Red",
|
||||
};
|
||||
|
||||
|
||||
struct LogPacket
|
||||
{
|
||||
const std::string m_prefix;
|
||||
const std::string m_text;
|
||||
const std::string m_colour;
|
||||
|
||||
LogPacket(const std::string& prefix, const std::string& text, const std::string& colour)
|
||||
: m_prefix(prefix)
|
||||
, m_text(text)
|
||||
, m_colour(colour)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct _LogBuffer : public MTPacketBuffer<LogPacket>
|
||||
{
|
||||
_LogBuffer() : MTPacketBuffer<LogPacket>(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
void _push(const LogPacket& data)
|
||||
{
|
||||
const u32 sprefix = data.m_prefix.length();
|
||||
const u32 stext = data.m_text.length();
|
||||
const u32 scolour = data.m_colour.length();
|
||||
|
||||
m_buffer.resize(m_buffer.size() +
|
||||
sizeof(u32) + sprefix +
|
||||
sizeof(u32) + stext +
|
||||
sizeof(u32) + scolour);
|
||||
|
||||
u32 c_put = m_put;
|
||||
|
||||
memcpy(&m_buffer[c_put], &sprefix, sizeof(u32));
|
||||
c_put += sizeof(u32);
|
||||
memcpy(&m_buffer[c_put], data.m_prefix.c_str(), sprefix);
|
||||
c_put += sprefix;
|
||||
|
||||
memcpy(&m_buffer[c_put], &stext, sizeof(u32));
|
||||
c_put += sizeof(u32);
|
||||
memcpy(&m_buffer[c_put], data.m_text.c_str(), stext);
|
||||
c_put += stext;
|
||||
|
||||
memcpy(&m_buffer[c_put], &scolour, sizeof(u32));
|
||||
c_put += sizeof(u32);
|
||||
memcpy(&m_buffer[c_put], data.m_colour.c_str(), scolour);
|
||||
c_put += scolour;
|
||||
|
||||
m_put = c_put;
|
||||
CheckBusy();
|
||||
}
|
||||
|
||||
LogPacket _pop()
|
||||
{
|
||||
u32 c_get = m_get;
|
||||
|
||||
const u32& sprefix = *(u32*)&m_buffer[c_get];
|
||||
c_get += sizeof(u32);
|
||||
const std::string prefix((const char*)&m_buffer[c_get], sprefix);
|
||||
c_get += sprefix;
|
||||
|
||||
const u32& stext = *(u32*)&m_buffer[c_get];
|
||||
c_get += sizeof(u32);
|
||||
const std::string text((const char*)&m_buffer[c_get], stext);
|
||||
c_get += stext;
|
||||
|
||||
const u32& scolour = *(u32*)&m_buffer[c_get];
|
||||
c_get += sizeof(u32);
|
||||
const std::string colour((const char*)&m_buffer[c_get], scolour);
|
||||
c_get += scolour;
|
||||
|
||||
m_get = c_get;
|
||||
if (!HasNewPacket()) Flush();
|
||||
|
||||
return LogPacket(prefix, text, colour);
|
||||
}
|
||||
};
|
||||
|
||||
_LogBuffer LogBuffer;
|
||||
|
||||
LogWriter::LogWriter()
|
||||
{
|
||||
if (!m_logfile.Open(_PRGNAME_ ".log", rFile::write))
|
||||
{
|
||||
rMessageBox("Can't create log file! (" _PRGNAME_ ".log)", rMessageBoxCaptionStr, rICON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void LogWriter::WriteToLog(const std::string& prefix, const std::string& value, u8 lvl/*, wxColour bgcolour*/)
|
||||
{
|
||||
std::string new_prefix = prefix;
|
||||
if (!prefix.empty())
|
||||
{
|
||||
if (NamedThreadBase* thr = GetCurrentNamedThread())
|
||||
{
|
||||
new_prefix += " : " + thr->GetThreadName();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_logfile.IsOpened() && !new_prefix.empty())
|
||||
m_logfile.Write("[" + new_prefix + "]: " + value + "\n");
|
||||
|
||||
if (!ConLogFrame || Ini.HLELogLvl.GetValue() == 4 || (lvl != 0 && lvl <= Ini.HLELogLvl.GetValue()))
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(g_cs_conlog);
|
||||
|
||||
// TODO: Use ThreadBase instead, track main thread id
|
||||
if (rThread::IsMain())
|
||||
{
|
||||
while (LogBuffer.IsBusy())
|
||||
{
|
||||
// need extra break condition?
|
||||
rYieldIfNeeded();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (LogBuffer.IsBusy())
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
{
|
||||
break;
|
||||
}
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
//if(LogBuffer.put == LogBuffer.get) LogBuffer.Flush();
|
||||
|
||||
LogBuffer.Push(LogPacket(new_prefix, value, g_log_colors[lvl]));
|
||||
}
|
||||
|
||||
|
||||
void LogWriter::SkipLn()
|
||||
{
|
||||
WriteToLog("", "", 0);
|
||||
}
|
||||
|
||||
LogFrame* ConLogFrame;
|
||||
|
||||
BEGIN_EVENT_TABLE(LogFrame, wxPanel)
|
||||
EVT_CLOSE(LogFrame::OnQuit)
|
||||
EVT_CLOSE(LogFrame::OnQuit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
LogFrame::LogFrame(wxWindow* parent)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(600, 500))
|
||||
, ThreadBase("LogThread")
|
||||
, m_log(*new wxListView(this))
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(600, 500))
|
||||
, ThreadBase("LogThread")
|
||||
, m_log(*new wxListView(this))
|
||||
{
|
||||
m_log.InsertColumn(0, "Thread");
|
||||
m_log.InsertColumn(1, "Log");
|
||||
|
|
@ -35,7 +189,7 @@ LogFrame::LogFrame(wxWindow* parent)
|
|||
s_main->Add(&m_log, 1, wxEXPAND);
|
||||
SetSizer(s_main);
|
||||
Layout();
|
||||
|
||||
|
||||
Show();
|
||||
ThreadBase::Start();
|
||||
}
|
||||
|
|
@ -53,9 +207,9 @@ bool LogFrame::Close(bool force)
|
|||
|
||||
void LogFrame::Task()
|
||||
{
|
||||
while(!TestDestroy())
|
||||
while (!TestDestroy())
|
||||
{
|
||||
if(!LogBuffer.HasNewPacket())
|
||||
if (!LogBuffer.HasNewPacket())
|
||||
{
|
||||
Sleep(1);
|
||||
continue;
|
||||
|
|
@ -99,4 +253,4 @@ void LogFrame::OnQuit(wxCloseEvent& event)
|
|||
Stop(false);
|
||||
ConLogFrame = nullptr;
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue