CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Debugger/WebSocket/GameBroadcaster.cpp
Views: 1401
// Copyright (c) 2018- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Core/Debugger/WebSocket/GameBroadcaster.h"18#include "Core/Debugger/WebSocket/WebSocketUtils.h"19#include "Core/ELF/ParamSFO.h"20#include "Core/System.h"2122struct GameStatusEvent {23const char *ev;2425operator std::string() {26JsonWriter j;27j.begin();28j.writeString("event", ev);29if (PSP_IsInited()) {30j.pushDict("game");31j.writeString("id", g_paramSFO.GetDiscID());32j.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));33j.writeString("title", g_paramSFO.GetValueString("TITLE"));34j.pop();35} else {36j.writeNull("game");37}38j.end();39return j.str();40}41};4243// Game started (game.start)44//45// Sent unexpectedly with these properties:46// - game: null or an object with properties:47// - id: string disc ID (such as ULUS12345.)48// - version: string disc version.49// - title: string game title.5051// Game quit / ended (game.quit)52//53// Sent unexpectedly with these properties:54// - game: null5556// Game paused (game.pause)57//58// Note: this is not the same as stepping. This means the user went to the pause menu.59//60// Sent unexpectedly with these properties:61// - game: null or an object with properties:62// - id: string disc ID (such as ULUS12345.)63// - version: string disc version.64// - title: string game title.6566// Game resumed (game.resume)67//68// Note: this is not the same as stepping. This means the user resumed from the pause menu.69//70// Sent unexpectedly with these properties:71// - game: null or an object with properties:72// - id: string disc ID (such as ULUS12345.)73// - version: string disc version.74// - title: string game title.75void GameBroadcaster::Broadcast(net::WebSocketServer *ws) {76// TODO: This is ugly. Callbacks instead?77GlobalUIState state = GetUIState();78if (prevState_ != state) {79if (state == UISTATE_PAUSEMENU) {80ws->Send(GameStatusEvent{"game.pause"});81prevState_ = state;82} else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) {83ws->Send(GameStatusEvent{"game.resume"});84prevState_ = state;85} else if (state == UISTATE_INGAME && PSP_IsInited()) {86ws->Send(GameStatusEvent{"game.start"});87prevState_ = state;88} else if (state == UISTATE_MENU && !PSP_IsInited() && !PSP_IsQuitting() && !PSP_IsRebooting()) {89ws->Send(GameStatusEvent{"game.quit"});90prevState_ = state;91}92}93}949596