CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Debugger/WebSocket/GameBroadcaster.cpp
Views: 1401
1
// Copyright (c) 2018- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Core/Debugger/WebSocket/GameBroadcaster.h"
19
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
20
#include "Core/ELF/ParamSFO.h"
21
#include "Core/System.h"
22
23
struct GameStatusEvent {
24
const char *ev;
25
26
operator std::string() {
27
JsonWriter j;
28
j.begin();
29
j.writeString("event", ev);
30
if (PSP_IsInited()) {
31
j.pushDict("game");
32
j.writeString("id", g_paramSFO.GetDiscID());
33
j.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
34
j.writeString("title", g_paramSFO.GetValueString("TITLE"));
35
j.pop();
36
} else {
37
j.writeNull("game");
38
}
39
j.end();
40
return j.str();
41
}
42
};
43
44
// Game started (game.start)
45
//
46
// Sent unexpectedly with these properties:
47
// - game: null or an object with properties:
48
// - id: string disc ID (such as ULUS12345.)
49
// - version: string disc version.
50
// - title: string game title.
51
52
// Game quit / ended (game.quit)
53
//
54
// Sent unexpectedly with these properties:
55
// - game: null
56
57
// Game paused (game.pause)
58
//
59
// Note: this is not the same as stepping. This means the user went to the pause menu.
60
//
61
// Sent unexpectedly with these properties:
62
// - game: null or an object with properties:
63
// - id: string disc ID (such as ULUS12345.)
64
// - version: string disc version.
65
// - title: string game title.
66
67
// Game resumed (game.resume)
68
//
69
// Note: this is not the same as stepping. This means the user resumed from the pause menu.
70
//
71
// Sent unexpectedly with these properties:
72
// - game: null or an object with properties:
73
// - id: string disc ID (such as ULUS12345.)
74
// - version: string disc version.
75
// - title: string game title.
76
void GameBroadcaster::Broadcast(net::WebSocketServer *ws) {
77
// TODO: This is ugly. Callbacks instead?
78
GlobalUIState state = GetUIState();
79
if (prevState_ != state) {
80
if (state == UISTATE_PAUSEMENU) {
81
ws->Send(GameStatusEvent{"game.pause"});
82
prevState_ = state;
83
} else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) {
84
ws->Send(GameStatusEvent{"game.resume"});
85
prevState_ = state;
86
} else if (state == UISTATE_INGAME && PSP_IsInited()) {
87
ws->Send(GameStatusEvent{"game.start"});
88
prevState_ = state;
89
} else if (state == UISTATE_MENU && !PSP_IsInited() && !PSP_IsQuitting() && !PSP_IsRebooting()) {
90
ws->Send(GameStatusEvent{"game.quit"});
91
prevState_ = state;
92
}
93
}
94
}
95
96