Sign in to follow this  
Followers 0
botanic

Script gets slower and slower...

9 posts in this topic

any idea on why after the loop runs more and more it gets slower and slower? (like 40k times+ is how many it is run sometimes)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=parser.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
Global $jass, $file, $Progress, $ProgressID, $ProgressID2, $Percent2, $task, $fileout, $check, $current, $tmp1, $tmp2, $tmp3

global $difernce, $update, $somx, $i, $filelist, $filesize, $Progress,  $updt, $out, $no
Func CreateProgress($x, $y, $w, $h, $Label="")
    GUICreate("My GUI Progressbar",$w+30, $h+50)
     Dim $Progress[3]
     $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h, $PBS_SMOOTH  )
     $Progress[1] = GuiCtrlCreateLabel($Label, $x, $y+5, $w, $h, $SS_CENTER )
     $Progress[2] = GuiCtrlCreateLabel( " ", $x, $y+35, $w, $h, $SS_CENTER )
     GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT)
     GUISetState ()
     Return $Progress
 EndFunc
Func UpdateProgress($ProgressID, $line, $filesize, $content)
    $Percent = $line / $filesize * 100
     GUICtrlSetData($ProgressID[0], $Percent)
     if $Percent < 10 Then
         $Percent = " " & StringLeft( $Percent, 4)
     ElseIf $Percent < 100 then
         $Percent = StringLeft( $Percent, 5)
     EndIf
    
     GUICtrlSetData($ProgressID[1], $line & "/" & $filesize & "    " & $Percent & "%") 
     GUICtrlSetData($ProgressID[2],$content)
EndFunc
#include <File.au3>

global $file






Func _open()
while StringRight($file, 5) <> "world"
$file = FileOpenDialog("Please select a valid world file.", "", "")
_read()
WEnd
EndFunc

func _read()
$Progress = CreateProgress( 16, 16, 353, 25 )
$task = 0
$out = ""
MsgBox(0, "Export", "Hit OK and select a location to export to.")
$fileout = FileSelectFolder("Choose a location to save the parsed file.", "") & "\world.done"
$no = 0 

if FileExists($fileout) Then
    $check = MsgBox( 4, "Overwrite", "File exists overwrite?")
    if $check = 7 Then
        _read()
    Else
        FileDelete($fileout)
    EndIf
EndIf

$fileout = FileOpen($fileout, 1)

$jass = _FileCountLines($file)
For $i = 1 To $jass

$update = FileReadLine($file,$i)
if @error = 1 then 
$file = 0
MsgBox(0, "OPPS!", "Could not open that file please check the file and try again.") 
_open()
ExitLoop
elseIf @error = -1 then
MsgBox(0, "Done", "File is saved")
Exit
EndIf

UpdateProgress($Progress, $i, $jass, $update)

if $task = 5 Then    FileWrite($fileout, $update & @CRLF)


if $task = 4 Then
if StringInStr($update, "<cullerp>") = true Then
    FileWrite($fileout, $update & @CRLF)
    FileWrite($fileout,"        <renderloop>std_rloop_diffuse</renderloop>" & @CRLF)
    $task = $task +1
    EndIf
EndIf




if $task = 3 Then
    
    if StringInStr($update, "<plugins>") = false Then 
        if StringInStr($update, "<material name") = True and StringInStr($update, "<materials>") = false Then 
            FileWrite($fileout, $update & @CRLF)
            FileWrite($fileout,FileReadLine($file,$i+1)& @CRLF)
            $tmp2 = StringTrimRight($update, 6)
            $tmp2 = StringTrimLeft($tmp2, 24)
            $tmp3 = StringRight($update, 6)
            $tmp3 = StringLeft($tmp3, 4)
            FileWrite($fileout, '      <shader type="diffuse">parallaxAtt</shader>'&@CRLF)
            FileWrite($fileout, '      <shader type="ambient">ambient</shader>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex normal compressed">'&$tmp2&"_nrm" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex height">'&$tmp2&"_disp" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex spec">'&$tmp2&"_spec" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '</material>'&@CRLF)
        Else
            if StringInStr($update, "<texture>") = false and StringInStr($update, "</material>") = false Then FileWrite($fileout, $update & @CRLF)
        EndIf

    Else
    FileWrite($fileout, $update & @CRLF)
    $task = 4
EndIf

EndIf






if $task = 2 Then
    if StringInStr($update, "<materials>") = false Then 
        if StringInStr($update, "<texture name=") = True  Then 
            FileWrite($fileout, $update & @CRLF)
            FileWrite($fileout,FileReadLine($file,$i+1)& @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
            $tmp2 = StringTrimRight($update, 6)
            $tmp3 = StringRight($update,6)
            $tmp2 = StringTrimLeft($tmp2, 23)
            $tmp1 = StringLeft($update, 23)
            FileWrite($fileout, $tmp1&$tmp2&"_nrm"&$tmp3&  @CRLF)
            FileWrite($fileout,"            <file>"&$tmp2&$tmp3&"</file>"&  @CRLF)      
            FileWrite($fileout,"            <class>normalmap</class>"&  @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
            FileWrite($fileout, $tmp1&$tmp2&"_disp"&$tmp3&  @CRLF)
            FileWrite($fileout,"            <file>"&$tmp2&$tmp3&"</file>"&  @CRLF)      
            FileWrite($fileout,"            <class>normalmap</class>"&  @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
        Else
            if StringInStr($update, "<file>") = false and StringInStr($update, "</texture>") = false Then FileWrite($fileout, $update & @CRLF)
        EndIf
    Else
    
    FileWrite($fileout, $update & @CRLF)
    $task = 3
    EndIf
    
EndIf

if $task = 1 Then

if $update <> "    <textures>" Then 
    FileWrite($fileout, $update & @CRLF)
Else
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"  <shaders>"& @CRLF)
FileWrite($fileout,"    <shader>"& @CRLF)
FileWrite($fileout,"      <file>/shader/parallaxAtt/parallaxAtt.xml</file>"& @CRLF)
FileWrite($fileout,"    </shader>"& @CRLF)
FileWrite($fileout,"  </shaders>"& @CRLF)
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"  <addon>"& @CRLF)
FileWrite($fileout,"    <plugin>crystalspace.renderloop.loop.loader</plugin>"& @CRLF)
FileWrite($fileout,"    <paramsfile>/shader/std_rloop_diffuse.xml</paramsfile>"& @CRLF)
FileWrite($fileout,"  </addon>"& @CRLF)
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"   <textures>"& @CRLF)
    $task = 2
EndIf
EndIf


if $task = 0 Then

    FileWrite($fileout, $update & @CRLF)
    FileWrite($fileout,""& @CRLF)
    $task = $task +1

EndIf

Next
EndFunc

_open()

Share this post


Link to post
Share on other sites



Try

Func _open()

while StringRight($file, 5) <> "world"

$file = FileOpenDialog("Please select a valid world file.", "", "")

_read()

WEnd

Sleep(100)

EndFunc


" I haven't failed. I've just found 10,000 ways that won't work." Thomas Edison "You cannot help men permanently by doing for them what they could and should do for themselves." Abraham Lincoln

Share this post


Link to post
Share on other sites

sry wrong loop forgot about that one its the _read() thats the problem

Share this post


Link to post
Share on other sites

There are alot of if's and then are not in order try doing something like if...elseif...elseif...elseif..elseif...endif


" I haven't failed. I've just found 10,000 ways that won't work." Thomas Edison "You cannot help men permanently by doing for them what they could and should do for themselves." Abraham Lincoln

Share this post


Link to post
Share on other sites

Are you sure its the for/next loop in _read(), or are you calling _read a lot of times? I'm not seeing anything that jumps out in the loop, but you have a fileopen and never close the file. Other then that, do you need all the global vars, or can you make any of them local? That might help.

But why is your _open func in a while/wend? That doesn't seem to make a ton of sense and could slow things down, especially since there is no sleep in the loop. (Flip, why did you put the sleep outside the loop??)


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ok i chenged the stuff it still slows down from 100 lines a sec to like 10 lines a sec at about the 30,000th line

also the RAM usage is going up and up... memory leak?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=parser.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
Func CreateProgress($x, $y, $w, $h, $Label="")
    GUICreate("My GUI Progressbar",$w+30, $h+50)
     Dim $Progress[3]
     $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h, $PBS_SMOOTH  )
     $Progress[1] = GuiCtrlCreateLabel($Label, $x, $y+5, $w, $h, $SS_CENTER )
     $Progress[2] = GuiCtrlCreateLabel( " ", $x, $y+35, $w, $h, $SS_CENTER )
     GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT)
     GUISetState ()
     Return $Progress
 EndFunc
Func UpdateProgress($ProgressID, $line, $filesize, $content)
    $Percent = $line / $filesize * 100
     GUICtrlSetData($ProgressID[0], $Percent)
     if $Percent < 10 Then
         $Percent = " " & StringLeft( $Percent, 4)
     ElseIf $Percent < 100 then
         $Percent = StringLeft( $Percent, 5)
     EndIf
    
     GUICtrlSetData($ProgressID[1], $line & "/" & $filesize & "    " & $Percent & "%") 
     GUICtrlSetData($ProgressID[2],$content)
EndFunc
#include <File.au3>

global $file






Func _open()
$file = FileOpenDialog("Please select a valid world file.", "", "")
_read()
EndFunc

func _read()
Local $jass,  $Progress, $ProgressID, $ProgressID2, $Percent2, $task, $fileout, $check, $current, $tmp1, $tmp2, $tmp3

Local $difernce, $update, $somx, $i, $filelist, $filesize, $Progress,  $updt, $out, $no
$Progress = CreateProgress( 16, 16, 353, 25 )
$task = 0
$out = ""
MsgBox(0, "Export", "Hit OK and select a location to export to.")
$fileout = FileSelectFolder("Choose a location to save the parsed file.", "") & "\world.done"
$no = 0 

if FileExists($fileout) Then
    $check = MsgBox( 4, "Overwrite", "File exists overwrite?")
    if $check = 7 Then
        _read()
    Else
        FileDelete($fileout)
    EndIf
EndIf

$fileout = FileOpen($fileout, 1)

$jass = _FileCountLines($file)
For $i = 1 To $jass

$update = FileReadLine($file,$i)
if @error = 1 then 
$file = 0
MsgBox(0, "OPPS!", "Could not open that file please check the file and try again.") 
_open()
ExitLoop
elseIf @error = -1 then
MsgBox(0, "Done", "File is saved")
Exit
EndIf

UpdateProgress($Progress, $i, $jass, $update)

if $task = 5 Then    
FileWrite($fileout, $update & @CRLF)


ElseIf $task = 4 Then
if StringInStr($update, "<cullerp>") = true Then
    FileWrite($fileout, $update & @CRLF)
    FileWrite($fileout,"        <renderloop>std_rloop_diffuse</renderloop>" & @CRLF)
    $task = $task +1
    EndIf
ElseIf $task = 3 Then
    
    if StringInStr($update, "<plugins>") = false Then 
        if StringInStr($update, "<material name") = True and StringInStr($update, "<materials>") = false Then 
            FileWrite($fileout, $update & @CRLF)
            FileWrite($fileout,FileReadLine($file,$i+1)& @CRLF)
            $tmp2 = StringTrimRight($update, 6)
            $tmp2 = StringTrimLeft($tmp2, 24)
            $tmp3 = StringRight($update, 6)
            $tmp3 = StringLeft($tmp3, 4)
            FileWrite($fileout, '      <shader type="diffuse">parallaxAtt</shader>'&@CRLF)
            FileWrite($fileout, '      <shader type="ambient">ambient</shader>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex normal compressed">'&$tmp2&"_nrm" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex height">'&$tmp2&"_disp" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '      <shadervar type="texture" name="tex spec">'&$tmp2&"_spec" &$tmp3&'</shadervar>'&@CRLF)
            FileWrite($fileout, '</material>'&@CRLF)
        Else
            if StringInStr($update, "<texture>") = false and StringInStr($update, "</material>") = false Then FileWrite($fileout, $update & @CRLF)
        EndIf

    Else
    FileWrite($fileout, $update & @CRLF)
    $task = 4
EndIf

ElseIf $task = 2 Then
    if StringInStr($update, "<materials>") = false Then 
        if StringInStr($update, "<texture name=") = True  Then 
            FileWrite($fileout, $update & @CRLF)
            FileWrite($fileout,FileReadLine($file,$i+1)& @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
            $tmp2 = StringTrimRight($update, 6)
            $tmp3 = StringRight($update,6)
            $tmp2 = StringTrimLeft($tmp2, 23)
            $tmp1 = StringLeft($update, 23)
            FileWrite($fileout, $tmp1&$tmp2&"_nrm"&$tmp3&  @CRLF)
            FileWrite($fileout,"            <file>"&$tmp2&$tmp3&"</file>"&  @CRLF)      
            FileWrite($fileout,"            <class>normalmap</class>"&  @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
            FileWrite($fileout, $tmp1&$tmp2&"_disp"&$tmp3&  @CRLF)
            FileWrite($fileout,"            <file>"&$tmp2&$tmp3&"</file>"&  @CRLF)      
            FileWrite($fileout,"            <class>normalmap</class>"&  @CRLF)
            FileWrite($fileout,"        </texture>"&  @CRLF)
        Else
            if StringInStr($update, "<file>") = false and StringInStr($update, "</texture>") = false Then FileWrite($fileout, $update & @CRLF)
        EndIf
    Else
    
    FileWrite($fileout, $update & @CRLF)
    $task = 3
    EndIf
    
ElseIf $task = 1 Then

if $update <> "    <textures>" Then 
    FileWrite($fileout, $update & @CRLF)
Else
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"  <shaders>"& @CRLF)
FileWrite($fileout,"    <shader>"& @CRLF)
FileWrite($fileout,"      <file>/shader/parallaxAtt/parallaxAtt.xml</file>"& @CRLF)
FileWrite($fileout,"    </shader>"& @CRLF)
FileWrite($fileout,"  </shaders>"& @CRLF)
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"  <addon>"& @CRLF)
FileWrite($fileout,"    <plugin>crystalspace.renderloop.loop.loader</plugin>"& @CRLF)
FileWrite($fileout,"    <paramsfile>/shader/std_rloop_diffuse.xml</paramsfile>"& @CRLF)
FileWrite($fileout,"  </addon>"& @CRLF)
FileWrite($fileout,""& @CRLF)
FileWrite($fileout,"   <textures>"& @CRLF)
    $task = 2
EndIf
ElseIf $task = 0 Then

    FileWrite($fileout, $update & @CRLF)
    FileWrite($fileout,""& @CRLF)
    $task = $task +1

EndIf

Next
EndFunc

_open()
Edited by botanic

Share this post


Link to post
Share on other sites

how should i do it then open and close the file in the loop?

Share this post


Link to post
Share on other sites

Your code is so poorly structured it's hard to follow it.

1. Just use _FileReadToArray to get not only the total lines but each line of the file in an array.

2. Use tidy on the code, and use some comments on what you think you are doing in each area if you want some help... Making us wade through that is painful.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0