Mirage Source
PlayerData - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+----- Thread: PlayerData (/showthread.php?tid=2676)



PlayerData - Jacob - 02-04-2009

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



Re: PlayerData - genusis - 02-04-2009

hmm it looks good dugor. i should try it out when i get a chance.


Re: PlayerData - GIAKEN - 02-04-2009

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?


Re: PlayerData - Jacob - 02-04-2009

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.


Re: PlayerData - GIAKEN - 02-04-2009

Yeah like how the maps are cached...it would be smart to cache everything.


Re: PlayerData - genusis - 02-04-2009

caching everything like that maps is a good idea. since it did speed the maps up.


Re: PlayerData - Jacob - 02-04-2009

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.


Re: PlayerData - genusis - 02-04-2009

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.


Re: PlayerData - GIAKEN - 02-04-2009

It didn't speed up the sending of them at all. They're still the same packet length, it just sped up the processing.


Re: PlayerData - genusis - 02-04-2009

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.


Re: PlayerData - Matt - 02-04-2009

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.


Re: PlayerData - genusis - 02-04-2009

couldn't we find a way to speed up the sending of maps and packets?


Re: PlayerData - Matt - 02-04-2009

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.


Re: PlayerData - genusis - 02-04-2009

why don't we do this also for all the packets?


Re: PlayerData - Matt - 02-04-2009

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.


Re: PlayerData - genusis - 02-04-2009

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.