mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-09-18 10:50:05 +00:00
Implement player list
This commit is contained in:
@@ -33,6 +33,10 @@ static jfieldID s_net_play_client_pointer;
|
||||
static jfieldID s_netplay_boot_session_data_pointer;
|
||||
static jmethodID s_netplay_on_boot_game;
|
||||
static jmethodID s_netplay_on_connection_error;
|
||||
static jmethodID s_netplay_update;
|
||||
|
||||
static jclass s_netplay_player_class;
|
||||
static jmethodID s_netplay_player_constructor;
|
||||
|
||||
static jclass s_analytics_class;
|
||||
static jmethodID s_get_analytics_value;
|
||||
@@ -264,6 +268,21 @@ jmethodID GetNetplayOnConnectionError()
|
||||
return s_netplay_on_connection_error;
|
||||
}
|
||||
|
||||
jmethodID GetNetplayUpdate()
|
||||
{
|
||||
return s_netplay_update;
|
||||
}
|
||||
|
||||
jclass GetNetplayPlayerClass()
|
||||
{
|
||||
return s_netplay_player_class;
|
||||
}
|
||||
|
||||
jmethodID GetNetplayPlayerConstructor()
|
||||
{
|
||||
return s_netplay_player_constructor;
|
||||
}
|
||||
|
||||
jclass GetPairClass()
|
||||
{
|
||||
return s_pair_class;
|
||||
@@ -675,8 +694,15 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
s_netplay_boot_session_data_pointer = env->GetStaticFieldID(netplay_class, "bootSessionDataPointer", "J");
|
||||
s_netplay_on_boot_game = env->GetStaticMethodID(netplay_class, "onBootGame", "(Ljava/lang/String;J)V");
|
||||
s_netplay_on_connection_error = env->GetStaticMethodID(netplay_class, "onConnectionError", "(Ljava/lang/String;)V");
|
||||
s_netplay_update = env->GetStaticMethodID(netplay_class, "onUpdate", "([Lorg/dolphinemu/dolphinemu/features/netplay/model/Player;)V");
|
||||
env->DeleteLocalRef(netplay_class);
|
||||
|
||||
const jclass netplay_player_class =
|
||||
env->FindClass("org/dolphinemu/dolphinemu/features/netplay/model/Player");
|
||||
s_netplay_player_class = reinterpret_cast<jclass>(env->NewGlobalRef(netplay_player_class));
|
||||
s_netplay_player_constructor = env->GetMethodID(netplay_player_class, "<init>", "(ILjava/lang/String;Ljava/lang/String;IZLjava/lang/String;)V");
|
||||
env->DeleteLocalRef(netplay_player_class);
|
||||
|
||||
const jclass analytics_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Analytics");
|
||||
s_analytics_class = reinterpret_cast<jclass>(env->NewGlobalRef(analytics_class));
|
||||
s_get_analytics_value = env->GetStaticMethodID(s_analytics_class, "getValue",
|
||||
@@ -892,6 +918,7 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
|
||||
env->DeleteGlobalRef(s_game_file_cache_class);
|
||||
env->DeleteGlobalRef(s_game_file_cache_manager_class);
|
||||
env->DeleteGlobalRef(s_netplay_class);
|
||||
env->DeleteGlobalRef(s_netplay_player_class);
|
||||
env->DeleteGlobalRef(s_analytics_class);
|
||||
env->DeleteGlobalRef(s_pair_class);
|
||||
env->DeleteGlobalRef(s_hash_map_class);
|
||||
|
||||
@@ -36,6 +36,10 @@ jfieldID GetNetPlayClientPointer();
|
||||
jfieldID GetNetplayBootSessionDataPointer();
|
||||
jmethodID GetNetplayOnBootGame();
|
||||
jmethodID GetNetplayOnConnectionError();
|
||||
jmethodID GetNetplayUpdate();
|
||||
|
||||
jclass GetNetplayPlayerClass();
|
||||
jmethodID GetNetplayPlayerConstructor();
|
||||
|
||||
jclass GetPairClass();
|
||||
jmethodID GetPairConstructor();
|
||||
|
||||
@@ -24,7 +24,41 @@ void NetPlayUICallbacks::BootGame(const std::string& filename, std::unique_ptr<B
|
||||
|
||||
void NetPlayUICallbacks::StopGame() {}
|
||||
bool NetPlayUICallbacks::IsHosting() const { return false; }
|
||||
void NetPlayUICallbacks::Update() {}
|
||||
|
||||
void NetPlayUICallbacks::Update()
|
||||
{
|
||||
JNIEnv* env = IDCache::GetEnvForThread();
|
||||
auto* client = reinterpret_cast<NetPlay::NetPlayClient*>(
|
||||
env->GetStaticLongField(IDCache::GetNetplayClass(), IDCache::GetNetPlayClientPointer()));
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
const std::vector<const NetPlay::Player*> players = client->GetPlayers();
|
||||
|
||||
jobjectArray player_array =
|
||||
env->NewObjectArray(static_cast<jsize>(players.size()), IDCache::GetNetplayPlayerClass(), nullptr);
|
||||
|
||||
for (jsize i = 0; i < static_cast<jsize>(players.size()); i++)
|
||||
{
|
||||
const NetPlay::Player* player = players[i];
|
||||
const std::string mapping = NetPlay::GetPlayerMappingString(
|
||||
player->pid, client->GetPadMapping(), client->GetGBAConfig(), client->GetWiimoteMapping());
|
||||
jobject player_obj = env->NewObject(
|
||||
IDCache::GetNetplayPlayerClass(), IDCache::GetNetplayPlayerConstructor(),
|
||||
static_cast<jint>(player->pid),
|
||||
ToJString(env, player->name),
|
||||
ToJString(env, player->revision),
|
||||
static_cast<jint>(player->ping),
|
||||
static_cast<jboolean>(player->IsHost()),
|
||||
ToJString(env, mapping));
|
||||
env->SetObjectArrayElement(player_array, i, player_obj);
|
||||
env->DeleteLocalRef(player_obj);
|
||||
}
|
||||
|
||||
env->CallStaticVoidMethod(IDCache::GetNetplayClass(), IDCache::GetNetplayUpdate(), player_array);
|
||||
env->DeleteLocalRef(player_array);
|
||||
}
|
||||
|
||||
void NetPlayUICallbacks::AppendChat(const std::string&) {}
|
||||
|
||||
void NetPlayUICallbacks::OnMsgChangeGame(const NetPlay::SyncIdentifier& sync_identifier,
|
||||
|
||||
Reference in New Issue
Block a user