RakNet crash fixes, performance improvements, fix ordering channels for some RPCs #883
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. RakNet Crashes
There are many places in RakNet you seepacket data being deleted using
delete
ordelete[]
and while it works fine, there are cases where double deletion happens, it's very random so the cause isn't clear yet. But finding the actual problem and fixing was easier than reproducing it (Check here: openmultiplayer/RakNet@3efbe1b...7f4f20d#diff-dcf7bd2af9b6ecac1d8af94416ca373c3a6f7a9528852c176dc36ae02e02223f)2. RakNet related improvements
GetRemoteSystemFromPlayerID
works internally in RakNet, it loops through all available slots (not taken, not empty, all of them) and tries to search for the samePlayerID
and returnRemoteSystemStruct
ptr for it. A huge improvement can be made by just caching and storing a pointer ofRemoteSystemStruct
on connect and releasing it on disconnect on open.mp side of the project, to use it for re-implementingGetLastPing
forIPlayer::getPing
andINetwork::getPing
. This also massively helps ScoreAndPingsUpdate RPC since it loops through all players and callsgetPing
for each of them, resulting aplayer count * max players
loop, for full servers it's1000 * 1000
iterations for nothing.playerIndexes
flat hash map used internally in RakNet, for way fasterPlayerID
and playerindex
lookup and use it in different places in RakNet to, again, improve performance noticeably and get rid of unnecessary overhead of looping through all slots every time you want to find a player index based on theirRakNet::PlayerID
which is a linear search.2. Fix chat RPC ordering channels
Almost all chat related RPCs had wrong ordering channels defined, as
OrderingChannel_Unordered
, while they should be anything ordered, preferablyOrderingChannel_SyncRPC
.