mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-09 12:24:04 -05:00
Create a new NetplaySession each time we try to join a netplay game. Hold onto it in NetplayManager so its available to the different activities that need to access it. Close the session when backing out of the netplay UI. Some guardrails in case things go out of sync: creating a session closes the old one if it is still around for some reason, finalizer in NetplaySession to release native resources if not closed explicitly for some reason. Profiling done to ensure all kotlin and native objects are successfully cleared / garbage collected.
76 lines
3.1 KiB
C++
76 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <jni.h>
|
|
|
|
#include "Common/HookableEvent.h"
|
|
#include "Core/NetPlayClient.h"
|
|
#include "UICommon/GameFile.h"
|
|
|
|
namespace NetPlay {
|
|
|
|
class NetPlayUICallbacks : public NetPlay::NetPlayUI {
|
|
public:
|
|
NetPlayUICallbacks(jobject netplay_session,
|
|
std::vector<std::shared_ptr<const UICommon::GameFile>> games);
|
|
~NetPlayUICallbacks() override;
|
|
|
|
void BootGame(const std::string& filename,
|
|
std::unique_ptr<BootSessionData> boot_session_data) override;
|
|
void StopGame() override;
|
|
bool IsHosting() const override;
|
|
void Update() override;
|
|
void AppendChat(const std::string& msg) override;
|
|
void OnMsgChangeGame(const NetPlay::SyncIdentifier& sync_identifier,
|
|
const std::string& netplay_name) override;
|
|
void OnMsgChangeGBARom(int pad, const NetPlay::GBAConfig& config) override;
|
|
void OnMsgStartGame() override;
|
|
void OnMsgStopGame() override;
|
|
void OnMsgPowerButton() override;
|
|
void OnPlayerConnect(const std::string& player) override;
|
|
void OnPlayerDisconnect(const std::string& player) override;
|
|
void OnPadBufferChanged(u32 buffer) override;
|
|
void OnHostInputAuthorityChanged(bool enabled) override;
|
|
void OnDesync(u32 frame, const std::string& player) override;
|
|
void OnConnectionLost() override;
|
|
void OnConnectionError(const std::string& message) override;
|
|
void OnTraversalError(Common::TraversalClient::FailureReason error) override;
|
|
void OnTraversalStateChanged(Common::TraversalClient::State state) override;
|
|
void OnGameStartAborted() override;
|
|
void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override;
|
|
void OnTtlDetermined(u8 ttl) override;
|
|
void OnIndexAdded(bool success, std::string error) override;
|
|
void OnIndexRefreshFailed(std::string error) override;
|
|
bool IsRecording() override;
|
|
std::shared_ptr<const UICommon::GameFile>
|
|
FindGameFile(const NetPlay::SyncIdentifier& sync_identifier,
|
|
NetPlay::SyncIdentifierComparison* found = nullptr) override;
|
|
std::string FindGBARomPath(const std::array<u8, 20>& hash, std::string_view title,
|
|
int device_number) override;
|
|
void ShowGameDigestDialog(const std::string& title) override;
|
|
void SetGameDigestProgress(int pid, int progress) override;
|
|
void SetGameDigestResult(int pid, const std::string& result) override;
|
|
void AbortGameDigest() override;
|
|
void ShowChunkedProgressDialog(const std::string& title, u64 data_size,
|
|
std::span<const int> players) override;
|
|
void HideChunkedProgressDialog() override;
|
|
void SetChunkedProgress(int pid, u64 progress) override;
|
|
void SetHostWiiSyncData(std::vector<u64> titles, std::string redirect_folder) override;
|
|
|
|
private:
|
|
jobject GetNetplaySessionLocalRef(JNIEnv* env) const;
|
|
|
|
jweak m_netplay_session;
|
|
std::vector<std::shared_ptr<const UICommon::GameFile>> m_games;
|
|
NetPlay::SyncIdentifier m_current_game_identifier;
|
|
std::string m_current_game_name;
|
|
Common::EventHook m_state_changed_hook;
|
|
bool m_got_stop_request = true;
|
|
};
|
|
|
|
} // namespace NetPlay
|