Try to restore CheckStructure status for spectating

This commit is contained in:
Benau 2019-01-08 04:12:10 +08:00
parent 10dbac9149
commit dbe5c22622
5 changed files with 76 additions and 3 deletions

View File

@ -36,6 +36,8 @@
#include "network/server_config.hpp"
#include "race/history.hpp"
#include "states_screens/race_gui_base.hpp"
#include "tracks/check_manager.hpp"
#include "tracks/check_structure.hpp"
#include "tracks/drive_graph.hpp"
#include "tracks/drive_node.hpp"
#include "tracks/track_sector.hpp"
@ -1117,6 +1119,11 @@ void LinearWorld::saveCompleteState(BareNetworkString* bns)
ki.saveCompleteState(bns);
for (TrackSector* ts : m_kart_track_sector)
ts->saveCompleteState(bns);
const uint8_t cc = (uint8_t)CheckManager::get()->getCheckStructureCount();
bns->addUInt8(cc);
for (unsigned i = 0; i < cc; i++)
CheckManager::get()->getCheckStructure(i)->saveCompleteState(bns);
} // saveCompleteState
// ----------------------------------------------------------------------------
@ -1139,4 +1146,13 @@ void LinearWorld::restoreCompleteState(const BareNetworkString& b)
ts->restoreCompleteState(b);
updateRacePosition();
const unsigned cc = b.getUInt8();
if (cc != CheckManager::get()->getCheckStructureCount())
{
Log::warn("LinearWorld",
"Server has different check structures size.");
return;
}
for (unsigned i = 0; i < cc; i++)
CheckManager::get()->getCheckStructure(i)->restoreCompleteState(b);
} // restoreCompleteState

View File

@ -28,6 +28,7 @@
#include "modes/linear_world.hpp"
#include "modes/profile_world.hpp"
#include "modes/world.hpp"
#include "network/network_string.hpp"
#include "race/race_manager.hpp"
#include "irrlicht.h"
@ -218,3 +219,25 @@ bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
}
return result;
} // isTriggered
// ----------------------------------------------------------------------------
void CheckLine::saveCompleteState(BareNetworkString* bns)
{
CheckStructure::saveCompleteState(bns);
World* world = World::getWorld();
for (unsigned int i = 0; i < world->getNumKarts(); i++)
bns->addUInt8(m_previous_sign[i] ? 1 : 0);
} // saveCompleteState
// ----------------------------------------------------------------------------
void CheckLine::restoreCompleteState(const BareNetworkString& b)
{
CheckStructure::restoreCompleteState(b);
m_previous_sign.clear();
World* world = World::getWorld();
for (unsigned int i = 0; i < world->getNumKarts(); i++)
{
bool previous_sign = b.getUInt8() == 1;
m_previous_sign.push_back(previous_sign);
}
} // restoreCompleteState

View File

@ -101,6 +101,10 @@ public:
* if a line is crossed. Used for basket calls in cannon (the ball can
* be too heigh to otherwise trigger he cannon). */
void setIgnoreHeight(bool b) { m_ignore_height = b; }
// ------------------------------------------------------------------------
virtual void saveCompleteState(BareNetworkString* bns);
// ------------------------------------------------------------------------
virtual void restoreCompleteState(const BareNetworkString& b);
}; // CheckLine
#endif

View File

@ -23,6 +23,7 @@
#include "karts/abstract_kart.hpp"
#include "modes/linear_world.hpp"
#include "modes/world.hpp"
#include "network/network_string.hpp"
#include "race/race_manager.hpp"
#include "tracks/check_lap.hpp"
#include "tracks/check_manager.hpp"
@ -228,3 +229,26 @@ void CheckStructure::trigger(unsigned int kart_index)
} // switch m_check_type
changeStatus(m_same_group, kart_index, CS_DEACTIVATE);
} // trigger
// ----------------------------------------------------------------------------
void CheckStructure::saveCompleteState(BareNetworkString* bns)
{
World* world = World::getWorld();
for (unsigned int i = 0; i < world->getNumKarts(); i++)
bns->add(m_previous_position[i]).addUInt8(m_is_active[i] ? 1 : 0);
} // saveCompleteState
// ----------------------------------------------------------------------------
void CheckStructure::restoreCompleteState(const BareNetworkString& b)
{
m_previous_position.clear();
m_is_active.clear();
World* world = World::getWorld();
for (unsigned int i = 0; i < world->getNumKarts(); i++)
{
Vec3 xyz = b.getVec3();
bool is_active = b.getUInt8() == 1;
m_previous_position.push_back(xyz);
m_is_active.push_back(is_active);
}
} // restoreCompleteState

View File

@ -24,9 +24,10 @@
#include "utils/aligned_array.hpp"
#include "utils/vec3.hpp"
class XMLNode;
class Track;
class BareNetworkString;
class CheckManager;
class Track;
class XMLNode;
/**
* \brief Virtual base class for a check structure.
@ -125,9 +126,14 @@ public:
// ------------------------------------------------------------------------
/** Adds the index of a successor check structure which will get triggered
* by this check structure. */
void addSuccessor(unsigned int i) {
void addSuccessor(unsigned int i)
{
m_check_structures_to_change_state.push_back(i);
} // addSuccessor
// ------------------------------------------------------------------------
virtual void saveCompleteState(BareNetworkString* bns);
// ------------------------------------------------------------------------
virtual void restoreCompleteState(const BareNetworkString& b);
}; // CheckStructure
#endif