Mirage Source http://web.miragesource.net/forums/ |
|
Clear Player http://web.miragesource.net/forums/viewtopic.php?f=210&t=762 |
Page 1 of 2 |
Author: | William [ Sat Nov 25, 2006 12:11 am ] |
Post subject: | Clear Player |
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 |
Author: | Spodi [ Sat Nov 25, 2006 1:03 am ] |
Post subject: | |
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. |
Author: | William [ Sat Nov 25, 2006 1:11 am ] |
Post subject: | |
Code: Dim EmptyPlayer as PlayerRec
Does that really work? Seems logical though |
Author: | Spodi [ Sat Nov 25, 2006 1:12 am ] |
Post subject: | |
Works just fine. It is how I do it in vbGORE. |
Author: | William [ Sat Nov 25, 2006 1:13 am ] |
Post subject: | |
Seems cool Ill use it |
Author: | Obsidian [ Sun Nov 26, 2006 6:28 am ] |
Post subject: | |
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. |
Author: | Lea [ Sun Nov 26, 2006 4:32 pm ] |
Post subject: | |
Not to mention less code, and much faster |
Author: | Dragoons Master [ Mon Nov 27, 2006 4:14 pm ] |
Post subject: | |
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... |
Author: | Spodi [ Mon Nov 27, 2006 11:00 pm ] |
Post subject: | |
Probably is faster, yeah. Thats a good idea, Verrigan. Why don't you just use ZeroMemory then, though? ZeroMemory is faster then FillMemory. |
Author: | Matt [ Tue Nov 28, 2006 12:50 am ] |
Post subject: | |
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. >.< |
Author: | William [ Tue Nov 28, 2006 1:01 am ] |
Post subject: | |
DM said he got it from Verrigan. |
Author: | Matt [ Tue Nov 28, 2006 1:38 am ] |
Post subject: | |
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. |
Author: | Spodi [ Tue Nov 28, 2006 1:38 am ] |
Post subject: | |
Quote: but it was someone from here(I think it was Verrigan):
That sounds like something Verrigan would say, too. |
Author: | Verrigan [ Tue Nov 28, 2006 3:29 am ] |
Post subject: | |
It was me.. and I don't think ZeroMemory() is any faster than FillMemory()? One sets a predetermined byte (0) to the memloc for length.. The other sets a user determined byte (0, in this case) to the memloc for length.. It's possible that there is some method that can zeroize the memory faster than setting the memory to all 50s or whatever.. But as far as I know, they are both the same speed... Too tired to do a test on it. ZeroMemory() certainly would be easier to type out.. Anyways... Maybe I'll perform a speed test on it tomorrow.. Maybe I can get it down to the 1/10 of a millisecond! Okay... performed the test... Here was the code I used. Code: Option Explicit
Private Declare Sub CopyMemory Lib "Kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Sub FillMemory Lib "Kernel32.dll" Alias "RtlFillMemory" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte) Private Declare Sub ZeroMemory Lib "Kernel32.dll" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long) Private Declare Sub GetSystemTimeAsFileTime Lib "Kernel32.dll" (ByRef lpSystemTimeAsFileTime As FILETIME) Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Function GetTickCount() As Double Dim mSysTime As FILETIME Dim CurrVal As Currency Call GetSystemTimeAsFileTime(mSysTime) Call CopyMemory(CurrVal, mSysTime, 8) Debug.Print CDbl(CurrVal) GetTickCount = CDbl(CurrVal) End Function Private Sub Command1_Click() Dim mba(0 To 49999999) As Byte Dim i As Long Dim TickStart As Double TickStart = GetTickCount For i = 1 To 50 Call FillMemory(mba(0), 50000000, 50) Next Text1.Text = Text1.Text & "50 (Fill) loops took " & GetTickCount - TickStart & " milliseconds." & vbCrLf DoEvents TickStart = GetTickCount For i = 1 To 50 Call ZeroMemory(mba(0), 50000000) Next Text1.Text = Text1.Text & "50 (Zero) loops took " & GetTickCount - TickStart & " milliseconds." & vbCrLf End Sub This was the results in the IDE (Ran 4 times): Quote: 50 (Fill) loops took 4186.14453125 milliseconds. 50 (Zero) loops took 4196.16015625 milliseconds. 50 (Fill) loops took 4186.14453125 milliseconds. 50 (Zero) loops took 4206.173828125 milliseconds. 50 (Fill) loops took 4186.14453125 milliseconds. 50 (Zero) loops took 4176.130859375 milliseconds. 50 (Fill) loops took 4186.14453125 milliseconds. 50 (Zero) loops took 4166.115234375 milliseconds. This was the results compiled (No optimizations): Quote: 50 (Fill) loops took 4166.115234375 milliseconds. 50 (Zero) loops took 4196.158203125 milliseconds. 50 (Fill) loops took 4156.1015625 milliseconds. 50 (Zero) loops took 4156.099609375 milliseconds. 50 (Fill) loops took 4146.0859375 milliseconds. 50 (Zero) loops took 4146.0859375 milliseconds. 50 (Fill) loops took 4146.0859375 milliseconds. 50 (Zero) loops took 4166.115234375 milliseconds. This was the results compiled (all optimizations): Quote: 50 (Fill) loops took 4266.26171875 milliseconds.
50 (Zero) loops took 4216.1875 milliseconds. 50 (Fill) loops took 4176.130859375 milliseconds. 50 (Zero) loops took 4176.130859375 milliseconds. 50 (Fill) loops took 4176.130859375 milliseconds. 50 (Zero) loops took 4176.12890625 milliseconds. 50 (Fill) loops took 4166.115234375 milliseconds. 50 (Zero) loops took 4176.130859375 milliseconds. My conclusion.. The 2 functions are the same speed. |
Author: | Spodi [ Tue Nov 28, 2006 7:03 am ] |
Post subject: | |
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. |
Author: | Verrigan [ Tue Nov 28, 2006 2:58 pm ] |
Post subject: | |
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? |
Author: | Dragoons Master [ Tue Nov 28, 2006 4:10 pm ] |
Post subject: | |
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 |
Author: | Spodi [ Tue Nov 28, 2006 10:34 pm ] |
Post subject: | |
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* |
Author: | Lea [ Tue Nov 28, 2006 11:03 pm ] |
Post subject: | |
Make a randomly sized block get zero'd, repick the random number every time. Run this a few times, and record the results.. Use these as a sample of the population of infinate samples, then do the same with FillMemory. Use a chi-squared test to determine which is faster ;d |
Author: | Xlithan [ Sun Jan 21, 2007 11:57 pm ] |
Post subject: | |
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. That's all we need for the entire sub? |
Author: | William [ Mon Jan 22, 2007 9:42 am ] |
Post subject: | |
That should work, just test it. |
Author: | Xlithan [ Mon Jan 22, 2007 2:31 pm ] |
Post subject: | |
Can the same method be used for the other Clear subs, like ClearNPC? |
Author: | William [ Mon Jan 22, 2007 2:33 pm ] |
Post subject: | |
GameBoy wrote: Can the same method be used for the other Clear subs, like ClearNPC?
yes it can. |
Author: | Xlithan [ Mon Jan 22, 2007 2:39 pm ] |
Post subject: | |
Cool, I can cut down on some lines then Also, I get a type mismatch on Player(Index), should it be PlayerRec(Index) or something? |
Author: | William [ Mon Jan 22, 2007 2:47 pm ] |
Post subject: | |
Then try the fillmemory instead. |
Page 1 of 2 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |