From e17cba85f3c0662c3636eda8cf1e9ffd14e8a1e7 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 3 Aug 2021 23:26:51 -0700 Subject: [PATCH] Allow host to own objects when no one else is connected --- src/pc/network/network.c | 2 +- src/pc/network/network_player.c | 2 +- src/pc/network/packets/packet_object.c | 6 ++++-- src/pc/network/packets/packet_player.c | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pc/network/network.c b/src/pc/network/network.c index e4c15c3c..0b926dae 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -269,7 +269,7 @@ void network_update(void) { gNetworkAreaTimer = (clock_elapsed_ticks() - gNetworkAreaTimerClock); // send out update packets - if (gNetworkType != NT_NONE && network_player_any_connected()) { + if (gNetworkType != NT_NONE) { network_player_update(); if (sCurrPlayMode == PLAY_MODE_NORMAL || sCurrPlayMode == PLAY_MODE_PAUSED) { network_update_player(); diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index bde91cd5..88aba2c9 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -112,7 +112,7 @@ struct NetworkPlayer* get_network_player_smallest_global(void) { } void network_player_update(void) { - + if (!network_player_any_connected()) { return; } //#ifndef DEVELOPMENT if (gNetworkType == NT_SERVER) { for (int i = 1; i < MAX_PLAYERS; i++) { diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 95da6f01..2d368929 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -58,7 +58,7 @@ static bool should_own_object(struct SyncObject* so) { } if (so->o->oHeldState == HELD_HELD && so->o->heldByPlayerIndex == 0) { return true; } for (int i = 0; i < MAX_PLAYERS; i++) { - if (!is_player_active(&gMarioStates[i])) { continue; } + if (i != 0 && !is_player_active(&gMarioStates[i])) { continue; } if (player_distance(&gMarioStates[0], so->o) > player_distance(&gMarioStates[i], so->o)) { return false; } } if (so->o->oHeldState == HELD_HELD && so->o->heldByPlayerIndex != 0) { return false; } @@ -570,7 +570,9 @@ void network_update_objects(void) { if (timeSinceUpdate < updateRate) { continue; } // update! - network_send_object(gSyncObjects[i].o); + if (network_player_any_connected()) { + network_send_object(gSyncObjects[i].o); + } } } diff --git a/src/pc/network/packets/packet_player.c b/src/pc/network/packets/packet_player.c index 9b144ed6..bbe5480e 100644 --- a/src/pc/network/packets/packet_player.c +++ b/src/pc/network/packets/packet_player.c @@ -338,5 +338,6 @@ void network_receive_player(struct Packet* p) { } void network_update_player(void) { + if (!network_player_any_connected()) { return; } network_send_player(0); }