Mirage Source
Tiny optimization - 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: Tiny optimization (/showthread.php?tid=2101)



Tiny optimization - Jacob - 16-09-2008

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



Re: Tiny optimization - skillzalot - 16-09-2008

Thanks for the small fix I added it already


Re: Tiny optimization - DarkC - 16-09-2008

Nice, I just added this.


Re: Tiny optimization - Joost - 16-09-2008

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.


Re: Tiny optimization - Vahz - 16-09-2008

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



Re: Tiny optimization - Jacob - 16-09-2008

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

[Image: stringopt2a.gif]

So using Left$ is faster than Mid$.


Re: Tiny optimization - Jacob - 16-09-2008

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.


Re: Tiny optimization - Rory - 16-09-2008

Vahz Wrote:i think Dugor forgot about these...

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

What about Normal Player commands.


Re: Tiny optimization - Jacob - 16-09-2008

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.


Re: Tiny optimization - Jacob - 16-09-2008

Like Verrigans source ?

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


Re: Tiny optimization - Jacob - 16-09-2008

[quote="DFA"]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 >


Re: Tiny optimization - Jacob - 16-09-2008

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.



Re: Tiny optimization - Matt - 18-09-2008

Lea Wrote:It said inside the stuff Dugor quoted Big Grin

Fixed.


Re: Tiny optimization - Robin - 18-09-2008

Perfekt Wrote:
Lea Wrote:Matt is black Big Grin

I'm black.

Fixed.


Re: Tiny optimization - Matt - 18-09-2008

Robin Wrote:
Perfekt Wrote:
Lea Wrote:Matt is black Big Grin

I'm black.

Fixed.

...