Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tiny optimization
#1
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
Reply
#2
Thanks for the small fix I added it already
Reply
#3
Nice, I just added this.
Reply
#4
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.
Reply
#5
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
Reply
#6
From: http://www.aivosto.com/vbtips/stringopt2.html

[Image: stringopt2a.gif]

So using Left$ is faster than Mid$.
Reply
#7
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.
Reply
#8
Vahz Wrote:i think Dugor forgot about these...

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

What about Normal Player commands.
Reply
#9
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.
Reply
#10
Like Verrigans source ?

I may write up something for that ... who knows.
Reply
#11
[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 >
Reply
#12
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.
Reply
#13
Lea Wrote:It said inside the stuff Dugor quoted Big Grin

Fixed.
Reply
#14
Perfekt Wrote:
Lea Wrote:Matt is black Big Grin

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?
Reply
#15
Robin Wrote:
Perfekt Wrote:
Lea Wrote:Matt is black Big Grin

I'm black.

Fixed.

...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)