| Mirage Source http://miragesource.net/forums/ |
|
| Tiny optimization http://miragesource.net/forums/viewtopic.php?f=193&t=4331 |
Page 1 of 1 |
| Author: | Jacob [ Tue Sep 16, 2008 1:12 am ] |
| Post subject: | Tiny optimization |
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 |
|
| Author: | skillzalot [ Tue Sep 16, 2008 1:19 am ] |
| Post subject: | Re: Tiny optimization |
Thanks for the small fix I added it already |
|
| Author: | DarkC [ Tue Sep 16, 2008 1:29 am ] |
| Post subject: | Re: Tiny optimization |
Nice, I just added this. |
|
| Author: | Joost [ Tue Sep 16, 2008 11:01 am ] |
| Post subject: | Re: Tiny optimization |
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. |
|
| Author: | Vahz [ Tue Sep 16, 2008 12:16 pm ] |
| Post subject: | Re: Tiny optimization |
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
|
|
| Author: | Jacob [ Tue Sep 16, 2008 12:20 pm ] |
| Post subject: | Re: Tiny optimization |
From: http://www.aivosto.com/vbtips/stringopt2.html ![]() So using Left$ is faster than Mid$. |
|
| Author: | Jacob [ Tue Sep 16, 2008 12:22 pm ] |
| Post subject: | Re: Tiny optimization |
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. |
|
| Author: | Rory [ Tue Sep 16, 2008 1:22 pm ] |
| Post subject: | Re: Tiny optimization |
Vahz wrote: i think Dugor forgot about these... and add an access check Code: If GetPlayerAccess(MyIndex) >0 Then What about Normal Player commands. |
|
| Author: | Jacob [ Tue Sep 16, 2008 2:02 pm ] |
| Post subject: | Re: Tiny optimization |
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. |
|
| Author: | Lea [ Tue Sep 16, 2008 2:19 pm ] |
| Post subject: | Re: Tiny optimization |
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 |
|
| Author: | Jacob [ Tue Sep 16, 2008 2:21 pm ] |
| Post subject: | Re: Tiny optimization |
Like Verrigans source ? I may write up something for that ... who knows. |
|
| Author: | Lea [ Tue Sep 16, 2008 2:23 pm ] |
| Post subject: | Re: Tiny optimization |
I'll do it =3 |
|
| Author: | Jacob [ Tue Sep 16, 2008 3:45 pm ] |
| Post subject: | Re: Tiny optimization |
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. |
|
| Author: | Lea [ Tue Sep 16, 2008 4:00 pm ] |
| Post subject: | Re: Tiny optimization |
Actually, I think len() is a constant time slower than lenb() I've tested this before, I don't remember O(len()) = O(lenb()) + C |
|
| Author: | Jacob [ Tue Sep 16, 2008 4:03 pm ] |
| Post subject: | Re: Tiny optimization |
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.
|
|
| Author: | Lea [ Tue Sep 16, 2008 5:40 pm ] |
| Post subject: | Re: Tiny optimization |
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 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 |
|
| Author: | Lea [ Wed Sep 17, 2008 3:55 pm ] |
| Post subject: | Re: Tiny optimization |
It said inside the stuff you quoted |
|
| Author: | Matt [ Thu Sep 18, 2008 1:40 pm ] |
| Post subject: | Re: Tiny optimization |
Lea wrote: It said inside the stuff Dugor quoted Fixed. |
|
| Author: | Robin [ Thu Sep 18, 2008 2:06 pm ] |
| Post subject: | Re: Tiny optimization |
Perfekt wrote: Lea wrote: Matt is black I'm black. Fixed. |
|
| Author: | Matt [ Thu Sep 18, 2008 3:50 pm ] |
| Post subject: | Re: Tiny optimization |
Robin wrote: Perfekt wrote: Lea wrote: Matt is black I'm black. Fixed. ... |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|