Always update current physical object if there was live join

This commit is contained in:
Benau 2019-01-02 15:30:56 +08:00
parent 314c37ce0b
commit eb342b2707
3 changed files with 29 additions and 4 deletions

View File

@ -250,6 +250,7 @@ void ServerLobby::setup()
m_item_seed = 0;
m_winner_peer_id = 0;
m_client_starting_time = 0;
m_last_live_join_util_ticks = 0;
auto players = STKHost::get()->getPlayersForNewGame();
if (m_game_setup->isGrandPrix() && !m_game_setup->isGrandPrixStarted())
{
@ -841,7 +842,7 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
assert(w);
// Give 3 seconds for all peers to get new kart info
const int live_join_util_ticks = w->getTicksSinceStart() +
m_last_live_join_util_ticks = w->getTicksSinceStart() +
stk_config->time2Ticks(3.0f);
uint64_t live_join_start_time = STKHost::get()->getNetworkTimer();
live_join_start_time -= m_server_delay;
@ -851,7 +852,7 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
{
World::getWorld()->addReservedKart(id);
const RemoteKartInfo& rki = race_manager->getKartInfo(id);
addLiveJoiningKart(id, rki, live_join_util_ticks);
addLiveJoiningKart(id, rki, m_last_live_join_util_ticks);
}
Log::info("ServerLobby", "%s live-joining succeeded.",
peer->getAddress().toString().c_str());
@ -859,7 +860,8 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
NetworkString* ns = getNetworkString(10);
ns->setSynchronous(true);
ns->addUInt8(LE_LIVE_JOIN_ACK).addUInt64(m_client_starting_time)
.addUInt64(live_join_start_time).addUInt32(live_join_util_ticks);
.addUInt64(live_join_start_time)
.addUInt32(m_last_live_join_util_ticks);
NetworkItemManager* nim =
dynamic_cast<NetworkItemManager*>(ItemManager::get());
@ -3322,3 +3324,14 @@ void ServerLobby::handleKartInfo(Event* event)
peer->sendPacket(ns, true/*reliable*/);
delete ns;
} // handleKartInfo
//-----------------------------------------------------------------------------
bool ServerLobby::hasLiveJoiningRecently() const
{
World* w = World::getWorld();
if (!w)
return false;
return m_last_live_join_util_ticks != 0 &&
w->getTicksSinceStart() - m_last_live_join_util_ticks > 0 &&
w->getTicksSinceStart() - m_last_live_join_util_ticks < 120;
} // hasLiveJoiningRecently

View File

@ -173,6 +173,10 @@ private:
uint64_t m_client_starting_time;
// Save the last live join ticks, for physical objects to update current
// transformation
int m_last_live_join_util_ticks;
// connection management
void clientDisconnected(Event* event);
void connectionRequested(Event* event);
@ -309,6 +313,7 @@ public:
float getStartupBoostOrPenaltyForKart(uint32_t ping, unsigned kart_id);
int getDifficulty() const { return m_difficulty.load(); }
int getGameMode() const { return m_game_mode.load(); }
bool hasLiveJoiningRecently() const;
}; // class ServerLobby
#endif // SERVER_LOBBY_HPP

View File

@ -28,6 +28,7 @@
#include "io/xml_node.hpp"
#include "physics/physics.hpp"
#include "physics/triangle_mesh.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/compress_network_body.hpp"
#include "network/rewind_manager.hpp"
#include "tracks/track.hpp"
@ -803,11 +804,17 @@ void PhysicalObject::computeError()
// ----------------------------------------------------------------------------
BareNetworkString* PhysicalObject::saveState(std::vector<std::string>* ru)
{
bool has_live_join = false;
if (auto sl = LobbyProtocol::get<ServerLobby>())
has_live_join = sl->hasLiveJoiningRecently();
btTransform cur_transform = m_body->getWorldTransform();
if ((cur_transform.getOrigin() - m_last_transform.getOrigin())
.length() < 0.01f &&
(m_body->getLinearVelocity() - m_last_lv).length() < 0.01f &&
(m_body->getLinearVelocity() - m_last_av).length() < 0.01f)
(m_body->getLinearVelocity() - m_last_av).length() < 0.01f &&
!has_live_join)
return nullptr;
ru->push_back(getUniqueIdentity());