Reserve code for future auto checkline correction

This commit is contained in:
Benau 2019-03-03 14:11:29 +08:00
parent 3cee39aff7
commit e01393bff7
7 changed files with 61 additions and 14 deletions

View File

@ -64,6 +64,7 @@ LinearWorld::LinearWorld() : WorldWithRank()
m_valid_reference_time = false;
m_live_time_difference = 0.0f;
m_fastest_lap_kart_name = "";
m_check_structure_compatible = false;
} // LinearWorld
// ----------------------------------------------------------------------------
@ -1164,9 +1165,10 @@ void LinearWorld::restoreCompleteState(const BareNetworkString& b)
* current kart lap count, last triggered checkline and check structure status
* to all players in game (including spectators so that the lap count is
* correct)
* \param check_id The check structure it it triggered.
* \param kart_id The kart which triggered a checkline.
*/
void LinearWorld::updateCheckLinesServer(int kart_id)
void LinearWorld::updateCheckLinesServer(int check_id, int kart_id)
{
if (!NetworkConfig::get()->isNetworking() ||
NetworkConfig::get()->isClient())
@ -1174,7 +1176,7 @@ void LinearWorld::updateCheckLinesServer(int kart_id)
NetworkString cl(PROTOCOL_GAME_EVENTS);
cl.setSynchronous(true);
cl.addUInt8(GameEventsProtocol::GE_CHECK_LINE_KART)
cl.addUInt8(GameEventsProtocol::GE_CHECK_LINE).addUInt8((uint8_t)check_id)
.addUInt8((uint8_t)kart_id);
int8_t finished_laps = (int8_t)m_kart_info[kart_id].m_finished_laps;
@ -1199,6 +1201,9 @@ void LinearWorld::updateCheckLinesServer(int kart_id)
/* Synchronize with server from the above data. */
void LinearWorld::updateCheckLinesClient(const BareNetworkString& b)
{
// Reserve for future auto checkline correction
//int check_id = b.getUInt8();
b.getUInt8();
int kart_id = b.getUInt8();
int8_t finished_laps = b.getUInt8();
@ -1212,11 +1217,21 @@ void LinearWorld::updateCheckLinesClient(const BareNetworkString& b)
const unsigned cc = b.getUInt8();
if (cc != CheckManager::get()->getCheckStructureCount())
{
throw std::invalid_argument(
"Server has different check structures size.");
}
return;
for (unsigned i = 0; i < cc; i++)
CheckManager::get()->getCheckStructure(i)->restoreIsActive(kart_id, b);
} // updateCheckLinesClient
// ----------------------------------------------------------------------------
void LinearWorld::handleServerCheckStructureCount(unsigned count)
{
if (count != CheckManager::get()->getCheckStructureCount())
{
Log::warn("LinearWorld",
"Server has different check structures size.");
m_check_structure_compatible = false;
}
else
m_check_structure_compatible = true;
} // handleServerCheckStructureCount

View File

@ -43,6 +43,9 @@ private:
bool m_last_lap_sfx_playing;
/** True if clients and server has the same check structure. */
bool m_check_structure_compatible;
/** The fastest lap time, in ticks of physics dt. */
int m_fastest_lap_ticks;
@ -214,6 +217,12 @@ public:
m_fastest_lap_ticks = ticks;
}
// ------------------------------------------------------------------------
/** Network use: set fastest kart name */
void setFastestKartName(const stringw& name)
{
m_fastest_lap_kart_name = name;
}
// ------------------------------------------------------------------------
virtual std::pair<uint32_t, uint32_t> getGameStartedProgress() const
OVERRIDE;
// ------------------------------------------------------------------------
@ -221,9 +230,11 @@ public:
// ------------------------------------------------------------------------
virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
// ------------------------------------------------------------------------
void updateCheckLinesServer(int kart_id);
void updateCheckLinesServer(int check_id, int kart_id);
// ------------------------------------------------------------------------
void updateCheckLinesClient(const BareNetworkString& b);
// ------------------------------------------------------------------------
void handleServerCheckStructureCount(unsigned count);
}; // LinearWorld
#endif

View File

@ -854,6 +854,11 @@ void ClientLobby::startGame(Event* event)
uint64_t start_time = event->data().getUInt64();
powerup_manager->setRandomSeed(start_time);
unsigned check_structure_count = event->data().getUInt8();
LinearWorld* lw = dynamic_cast<LinearWorld*>(World::getWorld());
if (lw)
lw->handleServerCheckStructureCount(check_structure_count);
NetworkItemManager* nim =
dynamic_cast<NetworkItemManager*>(ItemManager::get());
assert(nim);
@ -962,13 +967,19 @@ void ClientLobby::raceFinished(Event* event)
if (m_game_setup->isGrandPrix())
{
int t = data.getUInt32();
core::stringw kart_name;
data.decodeStringW(&kart_name);
lw->setFastestLapTicks(t);
lw->setFastestKartName(kart_name);
race_manager->configGrandPrixResultFromNetwork(data);
}
else if (race_manager->modeHasLaps())
{
int t = data.getUInt32();
core::stringw kart_name;
data.decodeStringW(&kart_name);
lw->setFastestLapTicks(t);
lw->setFastestKartName(kart_name);
}
if (lw)
@ -1084,6 +1095,12 @@ void ClientLobby::liveJoinAcknowledged(Event* event)
const NetworkString& data = event->data();
m_start_live_game_time = data.getUInt64();
powerup_manager->setRandomSeed(m_start_live_game_time);
unsigned check_structure_count = event->data().getUInt8();
LinearWorld* lw = dynamic_cast<LinearWorld*>(World::getWorld());
if (lw)
lw->handleServerCheckStructureCount(check_structure_count);
m_start_live_game_time = data.getUInt64();
m_last_live_join_util_ticks = data.getUInt32();
for (unsigned i = 0; i < w->getNumKarts(); i++)

View File

@ -129,9 +129,6 @@ bool GameEventsProtocol::notifyEvent(Event* event)
break;
}
case GE_CHECK_LINE:
// Old and unused now
break;
case GE_CHECK_LINE_KART:
{
if (!lw)
throw std::invalid_argument("No linear world");

View File

@ -17,8 +17,7 @@ public:
GE_CTF_SCORED = 4,
GE_RESET_BALL = 5,
GE_PLAYER_GOAL = 6,
GE_CHECK_LINE = 7,
GE_CHECK_LINE_KART = 8
GE_CHECK_LINE = 7
}; // GameEventType
private:
int m_last_finished_position;

View File

@ -46,6 +46,7 @@
#include "race/race_manager.hpp"
#include "states_screens/online/networking_lobby.hpp"
#include "states_screens/race_result_gui.hpp"
#include "tracks/check_manager.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/log.hpp"
@ -947,10 +948,11 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
spectator = true;
}
const uint8_t cc = (uint8_t)CheckManager::get()->getCheckStructureCount();
NetworkString* ns = getNetworkString(10);
ns->setSynchronous(true);
ns->addUInt8(LE_LIVE_JOIN_ACK).addUInt64(m_client_starting_time)
.addUInt64(live_join_start_time)
.addUInt8(cc).addUInt64(live_join_start_time)
.addUInt32(m_last_live_join_util_ticks);
NetworkItemManager* nim =
@ -1612,6 +1614,8 @@ void ServerLobby::checkRaceFinished()
int fastest_lap =
static_cast<LinearWorld*>(World::getWorld())->getFastestLapTicks();
m_result_ns->addUInt32(fastest_lap);
m_result_ns->encodeString(static_cast<LinearWorld*>(World::getWorld())
->getFastestLapKartName());
// all gp tracks
m_result_ns->addUInt8((uint8_t)m_game_setup->getTotalGrandPrixTracks())
@ -1644,6 +1648,8 @@ void ServerLobby::checkRaceFinished()
int fastest_lap =
static_cast<LinearWorld*>(World::getWorld())->getFastestLapTicks();
m_result_ns->addUInt32(fastest_lap);
m_result_ns->encodeString(static_cast<LinearWorld*>(World::getWorld())
->getFastestLapKartName());
}
if (ServerConfig::m_ranked)
{
@ -3032,6 +3038,8 @@ void ServerLobby::configPeersStartTime()
NetworkString* ns = getNetworkString(10);
ns->setSynchronous(true);
ns->addUInt8(LE_START_RACE).addUInt64(start_time);
const uint8_t cc = (uint8_t)CheckManager::get()->getCheckStructureCount();
ns->addUInt8(cc);
*ns += *m_items_complete_state;
m_client_starting_time = start_time;
sendMessageToPeers(ns, /*reliable*/true);

View File

@ -116,7 +116,7 @@ void CheckStructure::update(float dt)
World::getWorld()->getTime());
trigger(i);
if (triggeringCheckline() && lw)
lw->updateCheckLinesServer(i);
lw->updateCheckLinesServer(getIndex(), i);
}
m_previous_position[i] = xyz;
} // for i<getNumKarts