Mirage Source

Free ORPG making software.
It is currently Sun May 12, 2024 5:16 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Tiny optimization
PostPosted: Tue Sep 16, 2008 1:12 am 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I didn't get a chance to work on MS4 much because my baby has been sick.

I saw one tiny thing in modGameLogic. When you hit enter it checks every command even if you don't have the "/", so why not check for that first?

Sub HandleKeyPresses

Add:
Code:
If Left$(MyText, 1) = "/" Then

Right before:
Code:
' // Commands //


Add:
Code:
End If

Right After
Code:
' Ban destroy
                If Mid$(MyText, 1, 15) = "/destroybanlist" Then
                    Call SendBanDestroy
                    MyText = vbNullString
                    frmMirage.txtMyChat.Text = vbNullString
                    Exit Sub
                End If
            End If
       


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 1:19 am 
Offline
Regular

Joined: Sat Sep 13, 2008 1:41 am
Posts: 97
Thanks for the small fix I added it already


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 1:29 am 
Offline
Regular
User avatar

Joined: Tue Jun 17, 2008 12:39 pm
Posts: 55
Nice, I just added this.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 11:01 am 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
To add on to this,

Instead of using Mid(1, somthing

Use Left(something)

Using Mid here is obviously quite stupid, and I (without any sources to back it up) assume Left is way faster than Mid.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 12:16 pm 
Offline
Newbie

Joined: Mon May 12, 2008 4:54 pm
Posts: 9
i think Dugor forgot about these...

Code:
If Mid$(MyText, 1, 1) = vbQuote Then

and
Code:
If Mid$(MyText, 1, 1) = "=" Then


you should place them right before
Code:
If Left$(MyText, 1) = "/" Then


and add an access check
Code:
If GetPlayerAccess(MyIndex) >0 Then


Last edited by Vahz on Tue Sep 16, 2008 12:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 12:20 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
From: http://www.aivosto.com/vbtips/stringopt2.html

Image

So using Left$ is faster than Mid$.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 12:22 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Vahz wrote:
i think Dugor forgot about these...

Code:
If Mid$(MyText, 1, 1) = vbQuote Then

and
Code:
If Mid$(MyText, 1, 1) = "=" Then


you should place them right before
Code:
If Left$(MyText, 1) = "/" Then


and add an access check
Code:
If GetPlayerAccess(MyIndex) >0 Then


You are correct, I did forget about those.

You would have to move those out of the 'Checking for commands' section and have another If Then statement to check for those.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 1:22 pm 
Offline
Knowledgeable
User avatar

Joined: Sat Dec 30, 2006 9:09 am
Posts: 252
Vahz wrote:
i think Dugor forgot about these...

and add an access check
Code:
If GetPlayerAccess(MyIndex) >0 Then


What about Normal Player commands.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 2:02 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Okay I was thinking of a little bit different way to do the commands. What i came up with is very similar to HandleData.
This method would make it easier for users to add commands without using left, mid and whatnot and counting letters.

HandleKeyPresses

Add
Code:
Dim Command() As String


After
Code:
If Left$(MyText, 1) = "/" Then


Add
Code:
Command = Split(MyText, " ")

This code will split the string when there is a space and sets to the Command array.

Add:
Code:
Select Case Command(0)

Now we add a select case statement that will do different things depending on the actual command.

The following is just a simple example:
Code:
Case "/help"
                    Call AddText("Social Commands:", HelpColor)
                    Call AddText("'msghere = Broadcast Message", HelpColor)
                    Call AddText("-msghere = Emote Message", HelpColor)
                    Call AddText("!namehere msghere = Player Message", HelpColor)
                    Call AddText("Available Commands: /help, /info, /who, /fps, /inv, /stats, /train, /trade, /party, /join, /leave", HelpColor)


The following will first check to make sure there's more than one string in our array so we don't error out, then it will send the second string in the array. The first string will always be the command.
Code:
Case "/info"
                    ' Checks to make sure we have more than one string in the array
                    If UBound(Command) >= 1 Then
                        Call SendData(CPlayerInfoRequest & SEP_CHAR & Command(1) & END_CHAR)
                    End If

Code:
' Party request
                Case "/party"
                    ' Make sure they are actually sending something
                    If UBound(Command) >= 1 Then
                        Call SendPartyRequest(Command(1))
                    Else
                        Call AddText("Usage: /party playernamehere", AlertColor)
                    End If


Code:
' Giving another player access
                Case "/setaccess"
                    ' Check access level
                    If GetPlayerAccess(MyIndex) >= ADMIN_CREATOR Then
                        ' Check to make sure we have the right amount of additional info
                        If UBound(Command) >= 2 Then
                            Call SendSetAccess(Command(2), Command(1))
                        End If
                    End If


Just a little something to tell someone they don't have a valid command.
Code:
Case Else
                    AddText "Not a valid command!", HelpColor


Then right before the
Code:
End If

for the
Code:
If Left$(MyText, 1) = "/" Then


Add
Code:
End Select
           
            MyText = vbNullString
            frmMirage.txtMyChat.Text = vbNullString
            Exit Sub


Just an idea. Let's hear what everyone thinks.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 2:19 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
Sure that should work better :)

I would create a Map that maps each command to a memory address, and call each command's unique function by address.

Then you get rid of mile long functions, and make debugging easier... kinda :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: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 2:21 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Like Verrigans source ?

I may write up something for that ... who knows.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 2:23 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
I'll do it =3

_________________
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: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 3:45 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
DFA wrote:
use LenB over Len coz LenB is just plain leet compared to Len
xD, na jk, they both serve 2 different purposes

if dugor does the next version, dont forget to finish the packet enumeration ><


Len and LenB are also the same speed.

But I started working on the next version a bit. I'm going to finish off Anthony's work then finish this.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 4:00 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
Actually, I think len() is a constant time slower than lenb()

I've tested this before, I don't remember :P

O(len()) = O(lenb()) + C

_________________
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: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 4:03 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I was just taking my info from:

http://www.aivosto.com/vbtips/stringopt2.html

Quote:
Len and LenB. The fastest functions are Len and LenB. These are lightning fast functions that simply read the 2 length bytes at the start of the string area. Len is implemented in 6 assembly instructions in the VB runtime. LenB is even shorter: it runs just 5 instructions. In principle, LenB should run faster. In practice, this is not the case. Their performance is equal on today's processors.


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Tue Sep 16, 2008 5:40 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
Len is implemented in 6 assembly instructions in the VB runtime. LenB is even shorter: it runs just 5 instructions

Hah I was right! Their preformance is not equal, but almost :P One more clock cycle to complete a Len instruction :P

Also, who knows how they tested that stuff? Is the time O(n) or is it O(n^2)? How do those functions vary with string length? That's important :P More important than the time to complete just one call, in many cases.

_________________
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: Re: Tiny optimization
PostPosted: Wed Sep 17, 2008 3:55 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
It said inside the stuff you quoted :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: Re: Tiny optimization
PostPosted: Thu Sep 18, 2008 1:40 pm 
Lea wrote:
It said inside the stuff Dugor quoted :D


Fixed.


Top
  
 
 Post subject: Re: Tiny optimization
PostPosted: Thu Sep 18, 2008 2:06 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Perfekt wrote:
Lea wrote:
Matt is black :D


I'm black.


Fixed.

_________________
Quote:
Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?


Image


Top
 Profile  
 
 Post subject: Re: Tiny optimization
PostPosted: Thu Sep 18, 2008 3:50 pm 
Robin wrote:
Perfekt wrote:
Lea wrote:
Matt is black :D


I'm black.


Fixed.


...


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 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