From e6d09620e4ba8e0b51316aa2561cf0b6112d19ab Mon Sep 17 00:00:00 2001 From: german77 Date: Thu, 14 Jul 2022 22:31:57 -0500 Subject: [PATCH] logger --- src/yuzu/debugger/console.cpp | 60 +++++++++++++++++++++++++++++++++++ src/yuzu/debugger/console.h | 30 ++++++++++++++++++ src/yuzu/main.cpp | 9 ++++++ src/yuzu/main.h | 5 +++ 4 files changed, 104 insertions(+) diff --git a/src/yuzu/debugger/console.cpp b/src/yuzu/debugger/console.cpp index 1c1342ff1..dc7bb1294 100644 --- a/src/yuzu/debugger/console.cpp +++ b/src/yuzu/debugger/console.cpp @@ -7,6 +7,11 @@ #include #endif +#include +#include +#include +#include + #include "common/logging/backend.h" #include "yuzu/debugger/console.h" #include "yuzu/uisettings.h" @@ -46,4 +51,59 @@ void ToggleConsole() { SetColorConsoleBackendEnabled(UISettings::values.show_console.GetValue()); #endif } + + +GameLogOuput::GameLogOuput(QWidget* parent) + : QWidget(parent, Qt::Dialog) { + setObjectName(QStringLiteral("Game Log Output")); + setWindowTitle(tr("Game Log Output")); + resize(500, 350); + setMinimumSize(500, 350); + // Remove the "?" button from the titlebar and enable the maximize button + setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | + Qt::WindowMaximizeButtonHint); + + log_output = new QPlainTextEdit(this); + log_output->setReadOnly(true); + QLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(log_output); + setLayout(layout); +} + +void GameLogOuput::AppendMessage(const QString& text) { + std::scoped_lock lock{mutex}; + if (log_output) { + log_output->appendPlainText(std::move(text)); + } + // Scrolls to the bottom + //log_output->verticalScrollBar()->setValue( + // log_output->verticalScrollBar()->maximum()); +} + +QAction* GameLogOuput::toggleViewAction() { + if (toggle_view_action == nullptr) { + toggle_view_action = new QAction(tr("&Game Log Ouput"), this); + toggle_view_action->setCheckable(true); + toggle_view_action->setChecked(isVisible()); + connect(toggle_view_action, &QAction::toggled, this, &GameLogOuput::setVisible); + } + + return toggle_view_action; +} + +void GameLogOuput::showEvent(QShowEvent* ev) { + if (toggle_view_action) { + toggle_view_action->setChecked(isVisible()); + } + QWidget::showEvent(ev); +} + +void GameLogOuput::hideEvent(QHideEvent* ev) { + if (toggle_view_action) { + toggle_view_action->setChecked(isVisible()); + } + QWidget::hideEvent(ev); +} + } // namespace Debugger diff --git a/src/yuzu/debugger/console.h b/src/yuzu/debugger/console.h index fdb7d174c..94b15213f 100644 --- a/src/yuzu/debugger/console.h +++ b/src/yuzu/debugger/console.h @@ -3,6 +3,15 @@ #pragma once +#include + +#include +#include + +namespace Core::HID { +class HIDCore; +} // namespace Core::HID + namespace Debugger { /** @@ -10,4 +19,25 @@ namespace Debugger { * get a real qt logging window which would work for all platforms. */ void ToggleConsole(); + +class GameLogOuput : public QWidget { + Q_OBJECT + +public: + explicit GameLogOuput(QWidget* parent = nullptr); + + void AppendMessage(const QString& text); + + /// Returns a QAction that can be used to toggle visibility of this dialog. + QAction* toggleViewAction(); + +protected: + void showEvent(QShowEvent* ev) override; + void hideEvent(QHideEvent* ev) override; + +private: + std::mutex mutex; + QAction* toggle_view_action = nullptr; + QPlainTextEdit* log_output = nullptr; +}; } // namespace Debugger \ No newline at end of file diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 6cd557c29..b6e25864f 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1248,6 +1248,10 @@ void GMainWindow::InitializeDebugWidgets() { controller_dialog->hide(); debug_menu->addAction(controller_dialog->toggleViewAction()); + game_log_ouput_widget = new Debugger::GameLogOuput(this); + game_log_ouput_widget->hide(); + debug_menu->addAction(game_log_ouput_widget->toggleViewAction()); + connect(this, &GMainWindow::EmulationStarting, waitTreeWidget, &WaitTreeWidget::OnEmulationStarting); connect(this, &GMainWindow::EmulationStopping, waitTreeWidget, @@ -1876,6 +1880,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t render_window->Exit(); }); + // Register an Exit callback such that Core can exit the currently running application. + system->RegisterGameLogCallback([this](std::string text) { + game_log_ouput_widget->AppendMessage(QString::fromStdString(text)); + }); + connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 2cfb96257..38e8b95e4 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -72,6 +72,10 @@ struct KeyboardInitializeParameters; struct ProfileSelectParameters; } // namespace Core::Frontend +namespace Debugger { +class GameLogOuput; +} + namespace DiscordRPC { class DiscordInterface; } @@ -468,6 +472,7 @@ private: MicroProfileDialog* microProfileDialog; WaitTreeWidget* waitTreeWidget; ControllerDialog* controller_dialog; + Debugger::GameLogOuput* game_log_ouput_widget; QAction* actions_recent_files[max_recent_files_item];