Try unreliable state in network
This commit is contained in:
parent
4e35fe8fb8
commit
d9cebc3991
@ -341,33 +341,25 @@ 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());
|
||||
for (std::string& name : cur_rewinder)
|
||||
{
|
||||
m_data_to_send->reset();
|
||||
std::vector<uint8_t> names;
|
||||
names.push_back((uint8_t)cur_rewinder.size());
|
||||
for (std::string& name : cur_rewinder)
|
||||
{
|
||||
names.push_back((uint8_t)name.size());
|
||||
std::vector<uint8_t> rewinder(name.begin(), name.end());
|
||||
names.insert(names.end(), rewinder.begin(), rewinder.end());
|
||||
}
|
||||
buffer.insert(pos, names.begin(), names.end());
|
||||
std::swap(prev_rewinder, cur_rewinder);
|
||||
names.push_back((uint8_t)name.size());
|
||||
std::vector<uint8_t> rewinder(name.begin(), name.end());
|
||||
names.insert(names.end(), rewinder.begin(), rewinder.end());
|
||||
}
|
||||
else
|
||||
buffer.insert(pos, 0);
|
||||
buffer.insert(pos, names.begin(), names.end());
|
||||
} // 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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user