Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PlayerData
#1
I've done this in MR and showed a few others a better way to do PlayerData. If you ever change what gets sent in the playerdata packet, you have change it in like 4 places. With this you would only change it in 1 place.

I added it to modPlayer
Code:
Public Function PlayerData(ByVal Index As Long) As String
    PlayerData = SPlayerData & SEP_CHAR & Index & SEP_CHAR & GetPlayerName(Index) & SEP_CHAR & GetPlayerSprite(Index) & SEP_CHAR & GetPlayerMap(Index) & SEP_CHAR & GetPlayerX(Index) & SEP_CHAR & GetPlayerY(Index) & SEP_CHAR & GetPlayerDir(Index) & SEP_CHAR & GetPlayerAccess(Index) & SEP_CHAR & GetPlayerPK(Index) & END_CHAR
End Function

An example
Code:
Public Sub SendJoinMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
    
    ' Send all players on current map to index
    For i = 1 To High_Index
        If IsPlaying(i) Then
            If i  Index Then
                If GetPlayerMap(i) = GetPlayerMap(Index) Then
                    Call SendDataTo(Index, PlayerData(i))
                End If
            End If
        End If
    Next
    
    ' Send index's player data to everyone on the map including himself
    Call SendDataToMap(GetPlayerMap(Index), PlayerData(Index))
End Sub
Reply
#2
hmm it looks good dugor. i should try it out when i get a chance.
Reply
#3
You need to just make a SendPlayerData sub instead of just making a function that retrieves the string (which is probably slower than just putting the string in there, where as a sub that does it all might be faster).

@genusis: What?
Reply
#4
It may be a fraction slower not in lining the code, but it's much easier to maintain this way.

If you wanted to be a bit more hardcore, you could 'cache' the player data and only update it when a value gets changed.
Reply
#5
Yeah like how the maps are cached...it would be smart to cache everything.
Reply
#6
caching everything like that maps is a good idea. since it did speed the maps up.
Reply
#7
It doesn't speed the maps up, it speeds up sending the data. You don't have to do all that string concoction when a player requests the data.
Reply
#8
speeding up the sending the data speeds up the maps. the faster the data is sent and collected the faster and better new stuff or information on the maps will work. so it did speed them up.
Reply
#9
It didn't speed up the sending of them at all. They're still the same packet length, it just sped up the processing.
Reply
#10
Dugor Wrote:it speeds up sending the data
GIAKEN Wrote:It didn't speed up the sending of them at all. They're still the same packet length, it just sped up the processing.


HMMM? either way it speeds it up.
Reply
#11
genusis Wrote:
Dugor Wrote:it speeds up sending the data
GIAKEN Wrote:It didn't speed up the sending of them at all. They're still the same packet length, it just sped up the processing.


HMMM? either way it speeds it up.

It speeds up the processing. By storing the maps in a cache, it doesn't have to build the packet each time. The packet is already built, so the server just grabs the packet from the cache and sends it on it's way. It's like prepackaged food. However, it doesn't speed up the sending of maps. It's just less processing on the server.
Reply
#12
couldn't we find a way to speed up the sending of maps and packets?
Reply
#13
genusis Wrote:couldn't we find a way to speed up the sending of maps and packets?

Yeah. Convert the packet system to a proper byte array system.
Reply
#14
why don't we do this also for all the packets?
Reply
#15
genusis Wrote:why don't we do this also for all the packets?

If you're directing that at my last post, I said packet SYSTEM.

If it's directed at Dugor's original post, then you'll notice this is one of the more larger packets and it's used in a few different places. There's not many packets that are in different areas.
Reply
#16
ya i know packet system haha i been trying to make my post more simplified.

well ya we really should try to get a proper byte array system going. i know William started on it and never finished it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)