Mirage Source

Free ORPG making software.
It is currently Sat Apr 27, 2024 11:09 pm

All times are UTC




Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Clear Player
PostPosted: Sat Nov 25, 2006 12:11 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
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 :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 25, 2006 1:03 am 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
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:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 25, 2006 1:11 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Code:
Dim EmptyPlayer as PlayerRec


Does that really work? Seems logical though :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 25, 2006 1:12 am 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Works just fine. It is how I do it in vbGORE. :wink:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 25, 2006 1:13 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Seems cool :) Ill use it :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 26, 2006 6:28 am 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
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. :)

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 26, 2006 4:32 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
Not to mention less code, and much faster

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 4:14 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
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... :P


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 11:00 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Probably is faster, yeah. Thats a good idea, Verrigan. Why don't you just use ZeroMemory then, though? ZeroMemory is faster then FillMemory.

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 12:50 am 
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. >.<


Top
  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 1:01 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
DM said he got it from Verrigan.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 1:38 am 
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.


Top
  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 1:38 am 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Quote:
but it was someone from here(I think it was Verrigan):


:wink:

That sounds like something Verrigan would say, too. :wink:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:29 am 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
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. :P

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! :P

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. :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 7:03 am 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
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:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:58 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:10 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 10:34 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
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*

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 11:03 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
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

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 11:57 pm 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 9:42 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
That should work, just test it.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:31 pm 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
Can the same method be used for the other Clear subs, like ClearNPC?


Last edited by Xlithan on Mon Jan 22, 2007 2:38 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:33 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
GameBoy wrote:
Can the same method be used for the other Clear subs, like ClearNPC?

yes it can.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:39 pm 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
Cool, I can cut down on some lines then :P

Also, I get a type mismatch on Player(Index), should it be PlayerRec(Index) or something?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:47 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Then try the fillmemory instead.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group