Skip to content

Commit

Permalink
Merge pull request #18696 from hrydgard/notification-on-sceKernelExit…
Browse files Browse the repository at this point in the history
…Game

Show a notification if a game exits with sceKernelExitGame.
  • Loading branch information
hrydgard committed Jan 15, 2024
2 parents ddeb211 + 3ce8438 commit e474f8f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions Common/System/OSD.cpp
Expand Up @@ -48,7 +48,7 @@ void OnScreenDisplay::DismissEntry(size_t index, double now) {
}
}

void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s, const char *id) {
void OnScreenDisplay::Show(OSDType type, std::string_view text, std::string_view text2, std::string_view icon, float duration_s, const char *id) {
// Automatic duration based on type.
if (duration_s <= 0.0f) {
switch (type) {
Expand Down Expand Up @@ -103,9 +103,12 @@ void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::str
entries_.insert(entries_.begin(), msg);
}

void OnScreenDisplay::ShowOnOff(const std::string &message, bool on, float duration_s) {
void OnScreenDisplay::ShowOnOff(std::string_view message, bool on, float duration_s) {
std::string msg(message);
msg += ": ";
msg += on ? "on" : "off";
// TODO: translate "on" and "off"? Or just get rid of this whole thing?
Show(OSDType::MESSAGE_INFO, message + ": " + (on ? "on" : "off"), duration_s);
Show(OSDType::MESSAGE_INFO, msg, duration_s);
}

void OnScreenDisplay::ShowAchievementUnlocked(int achievementID) {
Expand Down
9 changes: 5 additions & 4 deletions Common/System/OSD.h
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <string_view>
#include <vector>
#include <mutex>

Expand Down Expand Up @@ -33,15 +34,15 @@ enum class OSDType {
class OnScreenDisplay {
public:
// If you specify 0.0f as duration, a duration will be chosen automatically depending on type.
void Show(OSDType type, const std::string &text, float duration_s = 0.0f, const char *id = nullptr) {
void Show(OSDType type, std::string_view text, float duration_s = 0.0f, const char *id = nullptr) {
Show(type, text, "", duration_s, id);
}
void Show(OSDType type, const std::string &text, const std::string &text2, float duration_s = 0.0f, const char *id = nullptr) {
void Show(OSDType type, std::string_view text, std::string_view text2, float duration_s = 0.0f, const char *id = nullptr) {
Show(type, text, text2, "", duration_s, id);
}
void Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s = 0.0f, const char *id = nullptr);
void Show(OSDType type, std::string_view text, std::string_view text2, std::string_view icon, float duration_s = 0.0f, const char *id = nullptr);

void ShowOnOff(const std::string &message, bool on, float duration_s = 0.0f);
void ShowOnOff(std::string_view message, bool on, float duration_s = 0.0f);

bool IsEmpty() const { return entries_.empty(); } // Shortcut to skip rendering.

Expand Down
6 changes: 3 additions & 3 deletions Core/Core.cpp
Expand Up @@ -424,13 +424,13 @@ void Core_MemoryException(u32 address, u32 accessSize, u32 pc, MemoryExceptionTy
}
}

void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, const std::string &additionalInfo, bool forceReport) {
void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, std::string_view additionalInfo, bool forceReport) {
const char *desc = MemoryExceptionTypeAsString(type);
// In jit, we only flush PC when bIgnoreBadMemAccess is off.
if ((g_Config.iCpuCore == (int)CPUCore::JIT || g_Config.iCpuCore == (int)CPUCore::JIT_IR) && g_Config.bIgnoreBadMemAccess) {
WARN_LOG(MEMMAP, "%s: Invalid access at %08x (size %08x). %s", desc, address, accessSize, additionalInfo.c_str());
WARN_LOG(MEMMAP, "%s: Invalid access at %08x (size %08x). %.*s", desc, address, accessSize, (int)additionalInfo.length(), additionalInfo.data());
} else {
WARN_LOG(MEMMAP, "%s: Invalid access at %08x (size %08x) PC %08x LR %08x %s", desc, address, accessSize, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA], additionalInfo.c_str());
WARN_LOG(MEMMAP, "%s: Invalid access at %08x (size %08x) PC %08x LR %08x %.*s", desc, address, accessSize, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA], (int)additionalInfo.length(), additionalInfo.data());
}

if (!g_Config.bIgnoreBadMemAccess || forceReport) {
Expand Down
3 changes: 2 additions & 1 deletion Core/Core.h
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <string>
#include <string_view>

#include "Core/System.h"
#include "Core/CoreParameter.h"
Expand Down Expand Up @@ -107,7 +108,7 @@ enum class ExecExceptionType {
// Separate one for without info, to avoid having to allocate a string
void Core_MemoryException(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type);

void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, const std::string &additionalInfo, bool forceReport);
void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, std::string_view additionalInfo, bool forceReport);

void Core_ExecException(u32 address, u32 pc, ExecExceptionType type);
void Core_Break(u32 pc);
Expand Down
6 changes: 6 additions & 0 deletions Core/HLE/sceKernel.cpp
Expand Up @@ -17,6 +17,8 @@

#include "Common/Serialize/SerializeFuncs.h"
#include "Common/LogManager.h"
#include "Common/System/OSD.h"

#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/CwCheat.h"
Expand Down Expand Up @@ -314,13 +316,17 @@ void sceKernelExitGame()
INFO_LOG(SCEKERNEL, "sceKernelExitGame");
__KernelSwitchOffThread("game exited");
Core_Stop();

g_OSD.Show(OSDType::MESSAGE_INFO, "sceKernelExitGame()");
}

void sceKernelExitGameWithStatus()
{
INFO_LOG(SCEKERNEL, "sceKernelExitGameWithStatus");
__KernelSwitchOffThread("game exited");
Core_Stop();

g_OSD.Show(OSDType::MESSAGE_INFO, "sceKernelExitGameWithStatus()");
}

u32 sceKernelDevkitVersion()
Expand Down

0 comments on commit e474f8f

Please sign in to comment.