Try unreliable state in network

This commit is contained in:
Benau 2018-07-27 21:47:07 +08:00
parent 4e35fe8fb8
commit d9cebc3991
4 changed files with 20 additions and 28 deletions

View File

@ -341,19 +341,15 @@ void GameProtocol::addState(BareNetworkString *buffer)
// ----------------------------------------------------------------------------
/** Called by a server to finalize the current state, which add updated
* names of rewinder using to the beginning of state buffer
* \param prev_rewinder List of previous rewinder using.
* \param cur_rewinder List of current rewinder using.
*/
void GameProtocol::finalizeState(std::vector<std::string>& prev_rewinder,
std::vector<std::string>& cur_rewinder)
void GameProtocol::finalizeState(std::vector<std::string>& cur_rewinder)
{
assert(NetworkConfig::get()->isServer());
auto& buffer = m_data_to_send->getBuffer();
auto pos = buffer.begin() + 1/*protocol type*/ + 1 /*gp event type*/+
4/*time*/;
if (prev_rewinder != cur_rewinder)
{
m_data_to_send->reset();
std::vector<uint8_t> names;
names.push_back((uint8_t)cur_rewinder.size());
@ -364,10 +360,6 @@ void GameProtocol::finalizeState(std::vector<std::string>& prev_rewinder,
names.insert(names.end(), rewinder.begin(), rewinder.end());
}
buffer.insert(pos, names.begin(), names.end());
std::swap(prev_rewinder, cur_rewinder);
}
else
buffer.insert(pos, 0);
} // finalizeState
// ----------------------------------------------------------------------------
@ -377,7 +369,7 @@ void GameProtocol::finalizeState(std::vector<std::string>& prev_rewinder,
void GameProtocol::sendState()
{
assert(NetworkConfig::get()->isServer());
sendMessageToPeers(m_data_to_send, /*reliable*/true);
sendMessageToPeers(m_data_to_send, /*reliable*/false);
} // sendState
// ----------------------------------------------------------------------------
@ -394,16 +386,15 @@ void GameProtocol::handleState(Event *event)
int ticks = data.getUInt32();
// Check for updated rewinder using
unsigned new_rewinder_size = data.getUInt8();
std::vector<std::string> new_rewinder_using;
for (unsigned i = 0; i < new_rewinder_size; i++)
unsigned rewinder_size = data.getUInt8();
std::vector<std::string> rewinder_using;
for (unsigned i = 0; i < rewinder_size; i++)
{
std::string name;
data.decodeString(&name);
new_rewinder_using.push_back(name);
rewinder_using.push_back(name);
}
if (!new_rewinder_using.empty())
RewindManager::get()->setRewinderUsing(new_rewinder_using);
RewindManager::get()->setRewinderUsing(rewinder_using);
// Now copy the state data (without ticks etc) to a new
// string, so it can be reset to the beginning easily

View File

@ -88,8 +88,7 @@ public:
void startNewState();
void addState(BareNetworkString *buffer);
void sendState();
void finalizeState(std::vector<std::string>& prev_rewinder,
std::vector<std::string>& cur_rewinder);
void finalizeState(std::vector<std::string>& cur_rewinder);
void adjustTimeForClient(STKPeer *peer, int ticks);
void sendItemEventConfirmation(int ticks);

View File

@ -165,7 +165,7 @@ void RewindManager::saveState()
}
delete buffer; // buffer can be freed
}
gp->finalizeState(m_current_rewinder_using, rewinder_using);
gp->finalizeState(rewinder_using);
PROFILER_POP_CPU_MARKER();
} // saveState

View File

@ -102,7 +102,9 @@ void STKPeer::sendPacket(NetworkString *data, bool reliable, bool encrypted)
{
packet = enet_packet_create(data->getData(),
data->getTotalSize(), (reliable ?
ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED));
ENET_PACKET_FLAG_RELIABLE :
(ENET_PACKET_FLAG_UNSEQUENCED |
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT)));
}
if (packet)