Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clear Player
#1
If you have a unedited ClearPlayer, replace this:
Code:
Sub ClearPlayer(ByVal Index As Long)
Dim i As Long
Dim n As Long

    Player(Index).Login = ""
    Player(Index).Password = ""
    
    For i = 1 To MAX_CHARS
        Player(Index).Char(i).Name = ""
        Player(Index).Char(i).Class = 0
        Player(Index).Char(i).Level = 0
        Player(Index).Char(i).Sprite = 0
        Player(Index).Char(i).Exp = 0
        Player(Index).Char(i).Access = 0
        Player(Index).Char(i).PK = NO
        Player(Index).Char(i).POINTS = 0
        Player(Index).Char(i).Guild = 0
        
        Player(Index).Char(i).HP = 0
        Player(Index).Char(i).MP = 0
        Player(Index).Char(i).SP = 0
        
        Player(Index).Char(i).STR = 0
        Player(Index).Char(i).DEF = 0
        Player(Index).Char(i).SPEED = 0
        Player(Index).Char(i).MAGI = 0
        
        For n = 1 To MAX_INV
            Player(Index).Char(i).Inv(n).Num = 0
            Player(Index).Char(i).Inv(n).Value = 0
            Player(Index).Char(i).Inv(n).Dur = 0
        Next n
        
        For n = 1 To MAX_PLAYER_SPELLS
            Player(Index).Char(i).Spell(n) = 0
        Next n
        
        Player(Index).Char(i).ArmorSlot = 0
        Player(Index).Char(i).WeaponSlot = 0
        Player(Index).Char(i).HelmetSlot = 0
        Player(Index).Char(i).ShieldSlot = 0
        
        Player(Index).Char(i).Map = 0
        Player(Index).Char(i).x = 0
        Player(Index).Char(i).y = 0
        Player(Index).Char(i).Dir = 0
        
        ' Temporary vars
        Player(Index).Buffer = ""
        Player(Index).IncBuffer = ""
        Player(Index).CharNum = 0
        Player(Index).InGame = False
        Player(Index).AttackTimer = 0
        Player(Index).DataTimer = 0
        Player(Index).DataBytes = 0
        Player(Index).DataPackets = 0
        Player(Index).PartyPlayer = 0
        Player(Index).InParty = 0
        Player(Index).Target = 0
        Player(Index).TargetType = 0
        Player(Index).CastedSpell = NO
        Player(Index).PartyStarter = NO
        Player(Index).GettingMap = NO
    Next i
End Sub
With this:
Code:
Sub ClearPlayer(ByVal Index As Long)
Dim i As Long
Dim n As Long

    Player(Index).Login = ""
    Player(Index).Password = ""
    
    For i = 1 To MAX_CHARS
        Player(Index).Char(i).Name = ""
        Player(Index).Char(i).Class = 0
        Player(Index).Char(i).Level = 0
        Player(Index).Char(i).Sprite = 0
        Player(Index).Char(i).Exp = 0
        Player(Index).Char(i).Access = 0
        Player(Index).Char(i).PK = NO
        Player(Index).Char(i).POINTS = 0
        Player(Index).Char(i).Guild = 0
        
        Player(Index).Char(i).HP = 0
        Player(Index).Char(i).MP = 0
        Player(Index).Char(i).SP = 0
        
        Player(Index).Char(i).STR = 0
        Player(Index).Char(i).DEF = 0
        Player(Index).Char(i).SPEED = 0
        Player(Index).Char(i).MAGI = 0
        
        For n = 1 To MAX_INV
            Player(Index).Char(i).Inv(n).Num = 0
            Player(Index).Char(i).Inv(n).Value = 0
            Player(Index).Char(i).Inv(n).Dur = 0
        Next n
        
        For n = 1 To MAX_PLAYER_SPELLS
            Player(Index).Char(i).Spell(n) = 0
        Next n
        
        Player(Index).Char(i).ArmorSlot = 0
        Player(Index).Char(i).WeaponSlot = 0
        Player(Index).Char(i).HelmetSlot = 0
        Player(Index).Char(i).ShieldSlot = 0
        
        Player(Index).Char(i).Map = 0
        Player(Index).Char(i).x = 0
        Player(Index).Char(i).y = 0
        Player(Index).Char(i).Dir = 0
    Next i
    ' Temporary vars
        Player(Index).Buffer = ""
        Player(Index).IncBuffer = ""
        Player(Index).CharNum = 0
        Player(Index).InGame = False
        Player(Index).AttackTimer = 0
        Player(Index).DataTimer = 0
        Player(Index).DataBytes = 0
        Player(Index).DataPackets = 0
        Player(Index).PartyPlayer = 0
        Player(Index).InParty = 0
        Player(Index).Target = 0
        Player(Index).TargetType = 0
        Player(Index).CastedSpell = NO
        Player(Index).PartyStarter = NO
        Player(Index).GettingMap = NO
End Sub

The change is that you put this:
Code:
' Temporary vars
        Player(Index).Buffer = ""
        Player(Index).IncBuffer = ""
        Player(Index).CharNum = 0
        Player(Index).InGame = False
        Player(Index).AttackTimer = 0
        Player(Index).DataTimer = 0
        Player(Index).DataBytes = 0
        Player(Index).DataPackets = 0
        Player(Index).PartyPlayer = 0
        Player(Index).InParty = 0
        Player(Index).Target = 0
        Player(Index).TargetType = 0
        Player(Index).CastedSpell = NO
        Player(Index).PartyStarter = NO
        Player(Index).GettingMap = NO
Outside the For Loop, because that part of code doesn't have a 'i' in it Tongue
Reply
#2
How about this:

Code:
Sub ClearPlayer(ByVal Index As Long)
Dim EmptyPlayer As Player 'Not sure if Player is the right variable here - you want the same variable type as used for Player()

Player(Index) = EmptyPlayer
End Sub

Done. :wink:
Reply
#3
Code:
Dim EmptyPlayer as PlayerRec

Does that really work? Seems logical though Tongue
Reply
#4
Works just fine. It is how I do it in vbGORE. :wink:
Reply
#5
Seems cool Smile Ill use it Tongue
Reply
#6
Yeah that works. It's how i've been doing it for a while... after i rewrote all the MS stuff in binary i realized it was easier to clear everything that way than it was to go back and do it all by hand. Smile
Reply
#7
I use a diferent way. I can't remember who did it, but it was someone from here(I think it was Verrigan):
Declare this:
Code:
Public Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte)
And use it like this(example, npc):
Code:
Call FillMemory(ByVal VarPtr(Npc(Index)), LenB(Npc(Index)), 0)
I think it's much faster...

EDIT: Btw, I'm not using it only for Players, and I don't know why... Tongue
Reply
#8
Probably is faster, yeah. Thats a good idea, Verrigan. Why don't you just use ZeroMemory then, though? ZeroMemory is faster then FillMemory.
Reply
#9
Spodi, you realize, that was DM that posted that, not Verrigan. Lol.

Please don't edit your post, it will seriously make me look stupid. >.
Reply
#10
DM said he got it from Verrigan.
Reply
#11
He said he thinks he got it from Ver. And be that so, it was still DM that said it in this topic, not Ver.
Reply
#12
Quote:but it was someone from here(I think it was Verrigan):

:wink:

That sounds like something Verrigan would say, too. :wink:
Reply
#13
Your testing environment is pretty unrealistic, though. You're not going to be clearing 50000000 byte UDTs.

Using my speed template:

1 = Zero, 2 = Fill
Quote:%Faster -2.5| -3.7| -3.7| -3.7| -1.2| -2.5| -1.2| -1.2| -1.2| -1.2
Test1 79| 78| 78| 78| 79| 79| 79| 79| 79| 79
Test2 81| 81| 81| 81| 80| 81| 80| 80| 80| 80

1 = Fill, 2 = Zero
Quote:%Faster 1.3| 2.5| 2.5| 2.5| 1.3| 0| 2.5| 1.3| 2.5| 1.3
Test1 80| 81| 81| 81| 80| 80| 81| 80| 81| 80
Test2 79| 79| 79| 79| 79| 80| 79| 79| 79| 79

Specs:
Code:
Public t(0 To 999) As Byte

Code:
ZeroMemory t(0), 1000
Code:
FillMemory t(0), 1000, 0
Code:
Private Const lngIterations As Long = 1000000

The difference is hardly even noteable, though, like you said. Just nit-picking, though. :wink:
Reply
#14
Well, I'm having a problem with the FillMemory being used w/ the player array. When it clears a fixed-size string is does not set its text to vbnullstring, it changes to a lot of boxes, you know? so I need to use a diferent sub, like this one:
Code:
Sub ClearPlayer(ByVal Index As Long)
    Call FillMemory(ByVal VarPtr(Player(Index)), LenB(Player(Index)), 0)
    Player(Index).Login = vbNullString
End Sub
Reply
#15
Verrigan Wrote:I wonder why your ZeroMemory() calls are almost always faster, when mine are not.

Maybe it's faster with smaller bits of memory.. or maybe our systems are just completely different.. Do you have an AMD, or Intel processor?

AMD.

I also have a lot more loops going, while yours is just a few loops on a huge chunk of memory. FillMemory probably has a bit more of an overhead, but they both work at nearly the same speed, so since yours only has 50 calls and all the time went to the actual routine, mine has a lot more so the overhead is much more distinguishable.

*shrugs*
Reply
#16
Spodi Wrote:How about this:

Code:
Sub ClearPlayer(ByVal Index As Long)
Dim EmptyPlayer As Player 'Not sure if Player is the right variable here - you want the same variable type as used for Player()

Player(Index) = EmptyPlayer
End Sub

Done. :wink:

That's all we need for the entire sub?
Reply
#17
That should work, just test it.
Reply
#18
Can the same method be used for the other Clear subs, like ClearNPC?
Reply
#19
GameBoy Wrote:Can the same method be used for the other Clear subs, like ClearNPC?
yes it can.
Reply
#20
Cool, I can cut down on some lines then Tongue

Also, I get a type mismatch on Player(Index), should it be PlayerRec(Index) or something?
Reply
#21
Then try the fillmemory instead.
Reply
#22
I was giving a pseudo-code, not exactly how it should be.

And yes, using ZeroMemory (or FillMemory) would be better and faster.

Code:
ZeroMemory Player(Index), Len(Player(Index))

Something like that.
Reply
#23
If PlayerRec is public them Dim EmptyPlayer as PlayerRec player(index) = emptyplayer would work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)