Major Lag... - Matt2 - 02-12-2007
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?
Re: Major Lag... - Matt - 02-12-2007
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..
Re: Major Lag... - Spodi - 03-12-2007
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.
Re: Major Lag... - Spodi - 03-12-2007
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.
Re: Major Lag... - Robin - 03-12-2007
Convert to binary.
:roll:
It's faster, a lot less code and you don't have huge .ini files everywhere.
Re: Major Lag... - Spodi - 03-12-2007
Or you could just use a linear read combined with a Select Case, which I am sure will be a lot faster.
Re: Major Lag... - Robin - 03-12-2007
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.
Re: Major Lag... - Spodi - 03-12-2007
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.
|