mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Debugger: Add current game info.
This commit is contained in:
parent
77131e737b
commit
3dac5f2103
@ -1408,6 +1408,8 @@ add_library(${CoreLibName} ${CoreLinkType}
|
||||
Core/Debugger/WebSocket/CPUCoreSubscriber.h
|
||||
Core/Debugger/WebSocket/GameBroadcaster.cpp
|
||||
Core/Debugger/WebSocket/GameBroadcaster.h
|
||||
Core/Debugger/WebSocket/GameSubscriber.cpp
|
||||
Core/Debugger/WebSocket/GameSubscriber.h
|
||||
Core/Debugger/WebSocket/LogBroadcaster.cpp
|
||||
Core/Debugger/WebSocket/LogBroadcaster.h
|
||||
Core/Debugger/WebSocket/SteppingBroadcaster.cpp
|
||||
|
@ -187,6 +187,7 @@
|
||||
<ClCompile Include="Debugger\WebSocket.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\CPUCoreSubscriber.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\GameBroadcaster.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\GameSubscriber.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\LogBroadcaster.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\SteppingBroadcaster.cpp" />
|
||||
<ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp" />
|
||||
@ -539,6 +540,7 @@
|
||||
<ClInclude Include="..\ext\udis86\udis86.h" />
|
||||
<ClInclude Include="AVIDump.h" />
|
||||
<ClInclude Include="Debugger\WebSocket.h" />
|
||||
<ClInclude Include="Debugger\WebSocket\GameSubscriber.h" />
|
||||
<ClInclude Include="Debugger\WebSocket\WebSocketUtils.h" />
|
||||
<ClInclude Include="Debugger\WebSocket\CPUCoreSubscriber.h" />
|
||||
<ClInclude Include="Debugger\WebSocket\GameBroadcaster.h" />
|
||||
|
@ -713,6 +713,9 @@
|
||||
<ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp">
|
||||
<Filter>Debugger\WebSocket</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Debugger\WebSocket\GameSubscriber.cpp">
|
||||
<Filter>Debugger\WebSocket</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ELF\ElfReader.h">
|
||||
@ -1313,6 +1316,9 @@
|
||||
<ClInclude Include="Debugger\WebSocket\WebSocketUtils.h">
|
||||
<Filter>Debugger\WebSocket</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Debugger\WebSocket\GameSubscriber.h">
|
||||
<Filter>Debugger\WebSocket</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "Core/Debugger/WebSocket/SteppingBroadcaster.h"
|
||||
|
||||
#include "Core/Debugger/WebSocket/CPUCoreSubscriber.h"
|
||||
#include "Core/Debugger/WebSocket/GameSubscriber.h"
|
||||
|
||||
typedef void *(*SubscriberInit)(DebuggerEventHandlerMap &map);
|
||||
typedef void (*Subscribershutdown)(void *p);
|
||||
@ -54,6 +55,7 @@ struct SubscriberInfo {
|
||||
|
||||
static const std::vector<SubscriberInfo> subscribers({
|
||||
{ &WebSocketCPUCoreInit, nullptr },
|
||||
{ &WebSocketGameInit, nullptr },
|
||||
});
|
||||
|
||||
// To handle webserver restart, keep track of how many running.
|
||||
|
@ -17,22 +17,78 @@
|
||||
|
||||
#include "Core/Debugger/WebSocket/GameBroadcaster.h"
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
#include "Core/ELF/ParamSFO.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
struct GameStatusEvent {
|
||||
const char *ev;
|
||||
|
||||
operator std::string() {
|
||||
JsonWriter j;
|
||||
j.begin();
|
||||
j.writeString("event", ev);
|
||||
if (PSP_IsInited()) {
|
||||
j.pushDict("game");
|
||||
j.writeString("id", g_paramSFO.GetDiscID());
|
||||
j.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
|
||||
j.writeString("title", g_paramSFO.GetValueString("TITLE"));
|
||||
j.pop();
|
||||
} else {
|
||||
j.writeRaw("game", "null");
|
||||
}
|
||||
j.end();
|
||||
return j.str();
|
||||
}
|
||||
};
|
||||
|
||||
// Game started (game.start)
|
||||
//
|
||||
// Sent unexpectedly with these properties:
|
||||
// - game: null or an object with properties:
|
||||
// - id: string disc ID (such as ULUS12345.)
|
||||
// - version: string disc version.
|
||||
// - title: string game title.
|
||||
|
||||
// Game quit / ended (game.quit)
|
||||
//
|
||||
// Sent unexpectedly with these properties:
|
||||
// - game: null
|
||||
|
||||
// Game paused (game.pause)
|
||||
//
|
||||
// Note: this is not the same as stepping. This means the user went to the pause menu.
|
||||
//
|
||||
// Sent unexpectedly with these properties:
|
||||
// - game: null or an object with properties:
|
||||
// - id: string disc ID (such as ULUS12345.)
|
||||
// - version: string disc version.
|
||||
// - title: string game title.
|
||||
|
||||
// Game resumed (game.pause)
|
||||
//
|
||||
// Note: this is not the same as stepping. This means the user resumed from the pause menu.
|
||||
//
|
||||
// Sent unexpectedly with these properties:
|
||||
// - game: null or an object with properties:
|
||||
// - id: string disc ID (such as ULUS12345.)
|
||||
// - version: string disc version.
|
||||
// - title: string game title.
|
||||
void GameBroadcaster::Broadcast(net::WebSocketServer *ws) {
|
||||
// TODO: This is ugly. Implement proper information instead.
|
||||
// TODO: Should probably include info about which game, etc.
|
||||
// TODO: This is ugly. Callbacks instead?
|
||||
GlobalUIState state = GetUIState();
|
||||
if (prevState_ != state) {
|
||||
if (state == UISTATE_PAUSEMENU) {
|
||||
ws->Send(R"({"event":"game.pause"})");
|
||||
ws->Send(GameStatusEvent{"game.pause"});
|
||||
prevState_ = state;
|
||||
} else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) {
|
||||
ws->Send(R"({"event":"game.resume"})");
|
||||
} else if (state == UISTATE_INGAME) {
|
||||
ws->Send(R"({"event":"game.start"})");
|
||||
} else if (state == UISTATE_MENU) {
|
||||
ws->Send(R"({"event":"game.quit"})");
|
||||
ws->Send(GameStatusEvent{"game.resume"});
|
||||
prevState_ = state;
|
||||
} else if (state == UISTATE_INGAME && PSP_IsInited()) {
|
||||
ws->Send(GameStatusEvent{"game.start"});
|
||||
prevState_ = state;
|
||||
} else if (state == UISTATE_MENU && !PSP_IsInited() && !PSP_IsQuitting()) {
|
||||
ws->Send(GameStatusEvent{"game.quit"});
|
||||
prevState_ = state;
|
||||
}
|
||||
prevState_ = state;
|
||||
}
|
||||
}
|
||||
|
51
Core/Debugger/WebSocket/GameSubscriber.cpp
Normal file
51
Core/Debugger/WebSocket/GameSubscriber.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2018- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "Core/Debugger/WebSocket/GameSubscriber.h"
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
#include "Core/ELF/ParamSFO.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
void *WebSocketGameInit(DebuggerEventHandlerMap &map) {
|
||||
map["game.status"] = &WebSocketGameStatus;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Check game status (game.status)
|
||||
//
|
||||
// No parameters.
|
||||
//
|
||||
// Response (same event name):
|
||||
// - game: null or an object with properties:
|
||||
// - id: string disc ID (such as ULUS12345.)
|
||||
// - version: string disc version.
|
||||
// - title: string game title.
|
||||
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
|
||||
void WebSocketGameStatus(DebuggerRequest &req) {
|
||||
JsonWriter &json = req.Respond();
|
||||
if (PSP_IsInited()) {
|
||||
json.pushDict("game");
|
||||
json.writeString("id", g_paramSFO.GetDiscID());
|
||||
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
|
||||
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
|
||||
json.pop();
|
||||
} else {
|
||||
json.writeRaw("game", "null");
|
||||
}
|
||||
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
|
||||
}
|
24
Core/Debugger/WebSocket/GameSubscriber.h
Normal file
24
Core/Debugger/WebSocket/GameSubscriber.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2018- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
|
||||
void *WebSocketGameInit(DebuggerEventHandlerMap &map);
|
||||
|
||||
void WebSocketGameStatus(DebuggerRequest &req);
|
@ -385,6 +385,10 @@ bool PSP_IsInited() {
|
||||
return pspIsInited && !pspIsQuitting;
|
||||
}
|
||||
|
||||
bool PSP_IsQuitting() {
|
||||
return pspIsQuitting;
|
||||
}
|
||||
|
||||
void PSP_Shutdown() {
|
||||
// Do nothing if we never inited.
|
||||
if (!pspIsInited && !pspIsIniting && !pspIsQuitting) {
|
||||
|
@ -66,6 +66,7 @@ bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string);
|
||||
bool PSP_InitUpdate(std::string *error_string);
|
||||
bool PSP_IsIniting();
|
||||
bool PSP_IsInited();
|
||||
bool PSP_IsQuitting();
|
||||
void PSP_Shutdown();
|
||||
|
||||
void PSP_BeginHostFrame();
|
||||
|
@ -303,6 +303,7 @@ EXEC_AND_LIB_FILES := \
|
||||
$(SRC)/Core/Debugger/WebSocket.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/GameBroadcaster.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/GameSubscriber.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/LogBroadcaster.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/SteppingBroadcaster.cpp \
|
||||
$(SRC)/Core/Debugger/WebSocket/WebSocketUtils.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user