Remove the unneeded disconnected elimination event

It can be implictly told by server state if Kx rewinder is missing
This commit is contained in:
Benau 2018-12-25 00:51:31 +08:00
parent d6946198c5
commit f8f571e40e
5 changed files with 19 additions and 29 deletions

View File

@ -61,6 +61,7 @@ void KartRewinder::reset()
SmoothNetworkBody::setEnable(true);
SmoothNetworkBody::setSmoothRotation(true);
SmoothNetworkBody::setAdjustVerticalOffset(true);
m_has_server_state = false;
} // reset
// ----------------------------------------------------------------------------
@ -78,6 +79,7 @@ void KartRewinder::saveTransform()
}
m_prev_steering = getSteerPercent();
m_has_server_state = false;
} // saveTransform
// ----------------------------------------------------------------------------
@ -100,6 +102,16 @@ void KartRewinder::computeError()
}
else
m_steering_smoothing_dt = -1.0f;
if (!m_has_server_state && !isEliminated())
{
const int kartid = getWorldKartId();
Log::debug("KartRewinder", "Kart id %d disconnected", kartid);
World::getWorld()->eliminateKart(kartid,
false/*notify_of_elimination*/);
setPosition(World::getWorld()->getCurrentNumKarts() + 1);
finishedRace(World::getWorld()->getTime(), true/*from_server*/);
}
} // computeError
// ----------------------------------------------------------------------------
@ -195,6 +207,7 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
*/
void KartRewinder::restoreState(BareNetworkString *buffer, int count)
{
m_has_server_state = true;
// 1) Firing and related handling
// -----------

View File

@ -34,6 +34,7 @@ private:
float m_prev_steering, m_steering_smoothing_dt, m_steering_smoothing_time;
int m_last_animation_end_ticks;
bool m_has_server_state;
public:
KartRewinder(const std::string& ident, unsigned int world_kart_id,
int position, const btTransform& init_transform,

View File

@ -25,7 +25,6 @@
#include "network/network_config.hpp"
#include "network/network_player_profile.hpp"
#include "network/peer_vote.hpp"
#include "network/protocols/game_events_protocol.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/server_config.hpp"
#include "network/stk_host.hpp"
@ -126,10 +125,6 @@ void GameSetup::update(bool remove_disconnected_players)
k->setPosition(
World::getWorld()->getCurrentNumKarts() + 1);
k->finishedRace(World::getWorld()->getTime(), true/*from_server*/);
NetworkString p(PROTOCOL_GAME_EVENTS);
p.setSynchronous(true);
p.addUInt8(GameEventsProtocol::GE_PLAYER_DISCONNECT).addUInt8(i);
STKHost::get()->sendPacketToAllPeers(&p, true);
}
}
m_connected_players_count.store(total);

View File

@ -56,8 +56,6 @@ bool GameEventsProtocol::notifyEvent(Event* event)
{
case GE_KART_FINISHED_RACE:
kartFinishedRace(data); break;
case GE_PLAYER_DISCONNECT:
eliminatePlayer(data); break;
case GE_RESET_BALL:
{
if (!sw)
@ -132,22 +130,6 @@ bool GameEventsProtocol::notifyEvent(Event* event)
return true;
} // notifyEvent
// ----------------------------------------------------------------------------
void GameEventsProtocol::eliminatePlayer(const NetworkString &data)
{
assert(NetworkConfig::get()->isClient());
if (data.size() < 1)
{
Log::warn("GameEventsProtocol", "eliminatePlayer: Too short message.");
}
int kartid = data.getUInt8();
World::getWorld()->eliminateKart(kartid, false/*notify_of_elimination*/);
World::getWorld()->getKart(kartid)->setPosition(
World::getWorld()->getCurrentNumKarts() + 1);
World::getWorld()->getKart(kartid)->finishedRace(
World::getWorld()->getTime(), true/*from_server*/);
} // eliminatePlayer
// ----------------------------------------------------------------------------
/** This function is called from the server when a kart finishes a race. It
* sends a notification to all clients about this event.

View File

@ -12,12 +12,11 @@ public:
enum GameEventType : uint8_t
{
GE_KART_FINISHED_RACE = 1,
GE_PLAYER_DISCONNECT = 2,
GE_RESET_BALL = 3,
GE_PLAYER_GOAL = 4,
GE_BATTLE_KART_SCORE = 5,
GE_CTF_SCORED = 6,
GE_STARTUP_BOOST = 7,
GE_STARTUP_BOOST = 2,
GE_CTF_SCORED = 3,
GE_RESET_BALL = 4,
GE_PLAYER_GOAL = 5,
GE_BATTLE_KART_SCORE = 6,
}; // GameEventType
private:
int m_last_finished_position;