| Mirage Source http://miragesource.net/forums/ |
|
| Major Lag... http://miragesource.net/forums/viewtopic.php?f=201&t=3104 |
Page 1 of 1 |
| Author: | Matt2 [ Sun Dec 02, 2007 10:07 pm ] |
| Post subject: | Major Lag... |
So, someone think they can help me optimize it? In Pokemon, we all know we have PC Boxes. Well, PDoA's goal is to recreate Pokemon to the best of it's ability. So, I code PC Boxes. This code's worked once before, I just found it and readded it. PC Boxes are written on Account Creation, and on log in[for existing users] if it doesn't already exist. The code: Code: Option Explicit Public Const MAX_BOXES = 20 Public Const POKEMON_PER_BOX = 30 Sub WriteNewBoxes(index) Dim Filename As String, Name As String, i As Byte, j As Byte Dim n As Byte, m As Long Filename = App.Path & "\trainers\(Info)\PC Boxes\" Name = GetPlayerName(index) Filename = Filename & Name & "\" Call MkDir(Filename) For i = 1 To MAX_BOXES For j = 1 To POKEMON_PER_BOX Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Name", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Number", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Type", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Type2", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Ability", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "HP", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Held Item", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Attack", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Defense", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "SpAtk", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "SpDef", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Speed", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Happiness", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Level", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Nature", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "OT", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "IDNo", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "TNL", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "LevelMet", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Cool", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Tough", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Beauty", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Cute", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Smart", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Sheen", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Gender", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Ball", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Status", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Condition", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Pokerus", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Confused", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Attract", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Exp", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "MaxHP", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j, "Shiney", "0") DoEvents 'moves For m = 1 To 4 Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j & "Move" & m, "Number", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j & "Move" & m, "PP", "0") Call PutVar(Filename & "Box" & i & ".ini", "Pokemon" & j & "Move" & m, "Max PP", "0") Next m Next j DoEvents Next i End Sub Now, I realize I've got over 1000, maybe 2000, I wouldn't be so shocked as to guess 5000+ strings written. Even with DoEvents thrown in there, it lags the server crazy when these boxes are written. Anyone think they can help me solve this? |
|
| Author: | Lea [ Sun Dec 02, 2007 10:10 pm ] |
| Post subject: | Re: Major Lag... |
dont do it? also, it would help to create these strings and just reference them when they're needed: Filename & "Box" & i & ".ini" "Pokemon" & j just do fn = Filename & "Box" & i & ".ini" pkmn = "Pokemon" & j and use the variables instead. Probably a little difference in speed with that |
|
| Author: | Matt [ Sun Dec 02, 2007 10:30 pm ] |
| Post subject: | Re: Major Lag... |
Or just write each slot, in each box, as the player finds a need for it. That way, it doesn't create the entire set all at once. Also, switching to Binary would speed this up.. |
|
| Author: | Spodi [ Mon Dec 03, 2007 5:18 am ] |
| Post subject: | Re: Major Lag... |
And don't add DoEvents in the middle of a single-threaded sub-loop. It does nothing but allow the GUI to redraw, which is hardly important... its a server. |
|
| Author: | Lea [ Mon Dec 03, 2007 1:55 pm ] |
| Post subject: | Re: Major Lag... |
DoEvents allows timers to trigger, and all that code to execute if it needs to be. |
|
| Author: | Spodi [ Mon Dec 03, 2007 2:45 pm ] |
| Post subject: | Re: Major Lag... |
Got to keep in mind that DoEvents does have a cost to run, even if it doesn't trigger any of those timers. Can at least add it on the outer loop if anything. |
|
| Author: | Robin [ Mon Dec 03, 2007 3:32 pm ] |
| Post subject: | Re: Major Lag... |
Convert to binary. It's faster, a lot less code and you don't have huge .ini files everywhere. |
|
| Author: | Spodi [ Mon Dec 03, 2007 3:47 pm ] |
| Post subject: | Re: Major Lag... |
Or you could just use a linear read combined with a Select Case, which I am sure will be a lot faster. |
|
| Author: | Robin [ Mon Dec 03, 2007 3:52 pm ] |
| Post subject: | Re: Major Lag... |
Spodi wrote: Or you could just use a linear read combined with a Select Case, which I am sure will be a lot faster. Pffft. |
|
| Author: | Lea [ Mon Dec 03, 2007 3:52 pm ] |
| Post subject: | Re: Major Lag... |
It does have some cost, as it passes control to windows and lets windows do it's thing aswell. In testing for Valkoria file loading, I would time the time it takes to start the server. When DoEvents every loop, it was slightly slower than doing it every so often. I found a nice balance doing If(i mod x) Then DoEvents where you tweak X to get optimum speed while not locking your computer. On some of the bigger loadings, like maps, I would do it every 5 loops. Shops I did it every 100, etc. |
|
| Author: | Spodi [ Mon Dec 03, 2007 4:57 pm ] |
| Post subject: | Re: Major Lag... |
Spodi wrote: Or you could just use a linear read combined with a Select Case, which I am sure will be a lot faster. Sorry, just wanted to clarify, not faster than binary, but faster than the INI APIs. Binary will always be fastest. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|