pull in project-slippi/Ishiiruka/commit/abf44c428f91fa1f947bb44ce0b31b1b96c4f64f

This commit is contained in:
Nikhil Narayana 2022-05-30 00:49:23 -07:00
commit 7abc89b39c
4 changed files with 36 additions and 34 deletions

View file

@ -248,8 +248,7 @@ CEXISlippi::~CEXISlippi()
m_fileWriteThread.join();
}
SlippiSpectateServer::getInstance().write(&empty[0], 0);
SlippiSpectateServer::getInstance().endGame();
SlippiSpectateServer::getInstance().endGame(true);
localSelections.Reset();

View file

@ -40,15 +40,22 @@ void SlippiSpectateServer::startGame()
{
m_event_queue.Push("START_GAME");
}
json start_game_message;
start_game_message["type"] = "start_game";
m_event_queue.Push(start_game_message.dump());
}
// CALLED FROM DOLPHIN MAIN THREAD
void SlippiSpectateServer::endGame()
void SlippiSpectateServer::endGame(bool dolphin_closed)
{
if (isSpectatorEnabled())
{
m_event_queue.Push("END_GAME");
}
json end_game_message;
end_game_message["type"] = "end_game";
end_game_message["dolphin_closed"] = dolphin_closed;
m_event_queue.Push(end_game_message.dump());
}
// CALLED FROM SERVER THREAD
@ -95,39 +102,36 @@ void SlippiSpectateServer::popEvents()
std::string event;
m_event_queue.Pop(event);
// These two are meta-events, used to signify the start/end of a game
// They are not sent over the wire
if (event == "END_GAME")
json json_message = json::parse(event, nullptr, false);
if (!json_message.is_discarded() && (json_message.find("type") != json_message.end()))
{
if (json_message["type"] == "end_game")
{
u32 cursor = (u32)(m_event_buffer.size() + m_cursor_offset);
json_message["cursor"] = cursor;
json_message["next_cursor"] = cursor + 1;
m_menu_cursor = 0;
if (m_event_buffer.size() > 0)
{
m_event_buffer.push_back(json_message.dump());
m_cursor_offset += m_event_buffer.size();
}
m_menu_event.clear();
m_in_game = false;
continue;
}
if (event == "START_GAME")
else if (json_message["type"] == "start_game")
{
m_event_buffer.clear();
u32 cursor = (u32)(m_event_buffer.size() + m_cursor_offset);
m_in_game = true;
json_message["cursor"] = cursor;
json_message["next_cursor"] = cursor + 1;
m_event_buffer.push_back(json_message.dump());
continue;
}
}
// Make json wrapper for game event
json game_event;
// An SLP event with an empty payload is a quasi-event that signifies
// the unclean exit of a game. Send this out as its own event
// (Since you can't meaningfully concat it with other events)
if (event.empty())
{
game_event["payload"] = "";
game_event["type"] = "game_event";
m_event_buffer.push_back(game_event.dump());
continue;
}
if (!m_in_game)
{
game_event["payload"] = base64::Base64::Encode(event);
@ -168,6 +172,8 @@ SlippiSpectateServer::SlippiSpectateServer()
{
m_in_game = false;
m_menu_cursor = 0;
m_menu_event.clear();
m_cursor_offset = 0;
// Spawn thread for socket listener
m_stop_socket_thread = false;

View file

@ -56,7 +56,8 @@ public:
// when a new client connects to the server mid-match, it can recieve all
// the game events that have happened so far. This buffer needs to be
// cleared when a match ends.
void endGame();
// If this is called due to dolphin closing then dolphin_closed will be true
void endGame(bool dolphin_closed = false);
private:
// ACCESSED FROM BOTH DOLPHIN AND SERVER THREADS

View file

@ -10,7 +10,6 @@
#include <cstdio>
#endif
#include <OptionParser.h>
#include <QAbstractEventDispatcher>
#include <QApplication>
@ -197,10 +196,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
save_state_path = static_cast<const char*>(options.get("save_state"));
}
#ifndef IS_PLAYBACK
SlippiSpectateServer::getInstance().endGame();
#endif
std::unique_ptr<BootParameters> boot;
bool game_specified = false;
if (options.is_set("exec"))
@ -258,7 +253,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
#ifndef IS_PLAYBACK
if (Settings::Instance().IsBootDefaultISO() && !Settings::Instance().GetDefaultGame().isEmpty())
{
boot = BootParameters::GenerateFromFile(Settings::Instance().GetDefaultGame().toStdString(), save_state_path);
boot = BootParameters::GenerateFromFile(Settings::Instance().GetDefaultGame().toStdString(),
save_state_path);
}
#endif