TheGuardian Posted August 18, 2011 Share Posted August 18, 2011 (edited) SOLVED!!! Until GUIGetMsg() = $btngenerate was the culprit slowing it down. This is the project I've been working on, I wrote newer code for it that allows it to continually generate land until you press the button again. Now I never realized it until now that when my mouse was moving/moved recently. The script/computer/cpu (not sure which) started running faster! I'm not sure if it's all my programs or Autoit scripts but it's a weird behavior that I've never seen before. Heres the code to test and see if you guys notice it too. (You may want to go to options and set Line size, Step size, and dirt offset to 1) expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> reloadoptions(0) ;Load the options GUI #Region ### START Koda GUI section ### Form=C:\Users\Matt\Pictures\Gimp\GUI\Form1.kxf $Form1 = GUICreate("Generate Level", 1102, 502, 194, 139, BitOR($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetBkColor(0x000000) $btngenerate = GUICtrlCreateButton("Generate!", 464, 472, 179, 25, $WS_GROUP) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $statuslbl = GUICtrlCreateLabel("Generating 0/0", 648, 472, 172, 17) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUICtrlSetColor(-1, 0x00FF00) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetState($checkcontinue,$GUI_CHECKED) GUICtrlSetState($checkrandom,$GUI_CHECKED) _GDIPlus_Startup() $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btngenerate If GUICtrlRead($checkrandom) = $GUI_CHECKED then randomgenops() If GUICtrlRead($checkcontinue) = $GUI_CHECKED then Generateinfinite() Else Generateland() EndIf Case $btndefault reloadoptions(1) EndSwitch WEnd Func Generateland() _GDIPlus_GraphicsClear($hwnd) $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) $linewidth = GUICtrlRead($inlinesize) $greenpen = _GDIPlus_PenCreate(0xFF00FF00,$linewidth) $greypen = _GDIPlus_PenCreate(0xFF2B2B2B,$linewidth) $brownpen = _GDIPlus_PenCreate(0xFF733D1A,$linewidth) $winsize = WinGetPos("Generate Level") ;YAY! lets do some math... $y = Round(($winsize[3]-50)/2,0) ;offset for bottom, get middle $yoff = Round(($winsize[3]-60)/4,0) ; get the quarters $y = Random($y-$yoff,$y+$yoff,1) ;use the 2 interquarters $x = Round($linewidth/2,0) $bottom = $winsize[3]-80 $bottomlimit = GUICtrlRead($inhmin) $counter = 1 Do GUICtrlSetData($statuslbl,"Generating "&$counter&"/"&Round($winsize[2]/$linewidth,0)) $ran = Random(GUICtrlRead($inmainran1),GUICtrlRead($inmainran2),1) $toolow = 0 $tooh = 0 If $toolow = 1 and $y <= $winsize[3]-$yoff Then $toolow = 0 ;this is to bring level back to normal elevation randomgenops() EndIf If $tooh = 1 and $y >= $yoff Then $tooh = 0 ;this is to bring level back to normal elevation ;Generate Flat If $ran >= GUICtrlRead($ingenflat1) And $ran <= GUICtrlRead($ingenflat2) Then _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Up If $ran >= GUICtrlRead($ingenelup1) And $ran <= GUICtrlRead($ingenelup2) Then If $y - GUICtrlRead($insteph) <= GUICtrlRead($inhmax) Then $tooh = 1;Lets not go too far up yea? GUICtrlSetData($ingenelup2,"3") GUICtrlSetData($ingenflat1,"4") GUICtrlSetData($ingenflat2,"7") GUICtrlSetData($ingeneldn1,"8") EndIf ;its too high make it have little chance of going back up until a certain elevation is met ;this gives it a smaller chance to go back up until its low enough If $tooh = 1 And Random(GUICtrlRead($intoohupchance1),GUICtrlRead($intoohupchance2),1) = GUICtrlRead($intoohupchance1) Then $y = $y - GUICtrlRead($insteph) If $tooh = 0 Then $y = $y - GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Down If $ran >= GUICtrlRead($ingeneldn1) And $ran <= GUICtrlRead($ingeneldn2) Then If $y + GUICtrlRead($insteph) >= $bottom - $bottomlimit Then $toolow = 1;Lets not go too far down yea? GUICtrlSetData($ingenelup2,"4") GUICtrlSetData($ingenflat1,"5") GUICtrlSetData($ingenflat2,"8") GUICtrlSetData($ingeneldn1,"9") EndIf ;its too low make it have little chance of going down until a certain hight is met ;this gives it a smaller chance to go back down until its high enough If $toolow = 1 and Random(GUICtrlRead($intoolowdnchance1),GUICtrlRead($intoolowdnchance2),1) = GUICtrlRead($intoolowdnchance1) Then $y = $y + GUICtrlRead($insteph) If $toolow = 0 Then $y = $y + GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf $counter = $counter + 1 $x = $x + $linewidth Until $x >= $winsize[2] GUICtrlSetData($statuslbl,"Generated!") EndFunc Func Generateinfinite() _GDIPlus_GraphicsClear($hwnd) $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) $linewidth = GUICtrlRead($inlinesize) $greenpen = _GDIPlus_PenCreate(0xFF00FF00,$linewidth) $greypen = _GDIPlus_PenCreate(0xFF2B2B2B,$linewidth) $brownpen = _GDIPlus_PenCreate(0xFF733D1A,$linewidth) $blackpen = _GDIPlus_PenCreate(0xFF000000,$linewidth) $winsize = WinGetPos("Generate Level") ;YAY! lets do some math... $y = Round(($winsize[3]-50)/2,0) ;offset for bottom, get middle $yoff = Round(($winsize[3]-60)/4,0) ; get the quarters $y = Random($y-$yoff,$y+$yoff,1) ;use the 2 interquarters $x = Round($linewidth/2,0) $bottom = $winsize[3]-80 $bottomlimit = GUICtrlRead($inhmin) $counter = 1 Do GUICtrlSetData($statuslbl,"Generating "&$counter) $ran = Random(GUICtrlRead($inmainran1),GUICtrlRead($inmainran2),1) $toolow = 0 $tooh = 0 If $toolow = 1 and $y <= $winsize[3]-$yoff Then $toolow = 0 ;this is to bring level back to normal elevation randomgenops() EndIf If $tooh = 1 and $y >= $yoff Then $tooh = 0 ;this is to bring level back to normal elevation _GDIPlus_GraphicsDrawLine($hwnd,$x+20,$bottom,$x+20,1,$blackpen) ;get rid of land infront ;Generate Flat If $ran >= GUICtrlRead($ingenflat1) And $ran <= GUICtrlRead($ingenflat2) Then _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Up If $ran >= GUICtrlRead($ingenelup1) And $ran <= GUICtrlRead($ingenelup2) Then If $y - GUICtrlRead($insteph) <= GUICtrlRead($inhmax) Then $tooh = 1;Lets not go too far up yea? GUICtrlSetData($ingenelup2,"3") GUICtrlSetData($ingenflat1,"4") GUICtrlSetData($ingenflat2,"7") GUICtrlSetData($ingeneldn1,"8") EndIf ;its too high make it have little chance of going back up until a certain elevation is met ;this gives it a smaller chance to go back up until its low enough If $tooh = 1 And Random(GUICtrlRead($intoohupchance1),GUICtrlRead($intoohupchance2),1) = GUICtrlRead($intoohupchance1) Then $y = $y - GUICtrlRead($insteph) If $tooh = 0 Then $y = $y - GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Down If $ran >= GUICtrlRead($ingeneldn1) And $ran <= GUICtrlRead($ingeneldn2) Then If $y + GUICtrlRead($insteph) >= $bottom - $bottomlimit Then $toolow = 1;Lets not go too far down yea? GUICtrlSetData($ingenelup2,"4") GUICtrlSetData($ingenflat1,"5") GUICtrlSetData($ingenflat2,"8") GUICtrlSetData($ingeneldn1,"9") EndIf ;its too low make it have little chance of going down until a certain hight is met ;this gives it a smaller chance to go back down until its high enough If $toolow = 1 and Random(GUICtrlRead($intoolowdnchance1),GUICtrlRead($intoolowdnchance2),1) = GUICtrlRead($intoolowdnchance1) Then $y = $y + GUICtrlRead($insteph) If $toolow = 0 Then $y = $y + GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf $counter = $counter + 1 $x = $x + $linewidth If $x >= $winsize[2] then $x = Round($linewidth/2,0) $blackpen = _GDIPlus_PenCreate(0xFF000000,40) _GDIPlus_GraphicsDrawLine($hwnd,1,$bottom,1,1,$blackpen) ;get rid of land infront in the beginning $blackpen = _GDIPlus_PenCreate(0xFF000000,$linewidth) EndIf Until GUIGetMsg() = $btngenerate GUICtrlSetData($statuslbl,"Generated!") EndFunc Func randomgenops() $ran = Random(2,5,1) GUICtrlSetData($ingenelup2,$ran) GUICtrlSetData($ingenflat1,$ran+1) $ran = Random($ran+2,$ran+5,1) GUICtrlSetData($ingenflat2,$ran) GUICtrlSetData($ingeneldn1,$ran+1) ;Random(7,11,1) EndFunc Func reloadoptions($x) If $x = 1 Then GUIDelete($Form2) #Region ### START Koda GUI section ### Form= Global $Form2 = GUICreate("Options", 392, 418, 515, 140) Global $inmainran1 = GUICtrlCreateInput("1", 80, 8, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label1 = GUICtrlCreateLabel("Main Random", 8, 8, 70, 17) $Label2 = GUICtrlCreateLabel("--", 120, 8, 10, 17) Global $inmainran2 = GUICtrlCreateInput("11", 128, 8, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenflat1 = GUICtrlCreateInput("4", 80, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label3 = GUICtrlCreateLabel("Gen Flat", 32, 40, 44, 17) $Label4 = GUICtrlCreateLabel("--", 120, 40, 10, 17) Global $ingenflat2 = GUICtrlCreateInput("8", 128, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenelup1 = GUICtrlCreateInput("1", 80, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label5 = GUICtrlCreateLabel("Gen Elev. Up", 8, 64, 68, 17) $Label6 = GUICtrlCreateLabel("--", 120, 64, 10, 17) Global $ingenelup2 = GUICtrlCreateInput("3", 128, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingeneldn1 = GUICtrlCreateInput("9", 80, 88, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label7 = GUICtrlCreateLabel("Gen Elev. Dn", 8, 88, 68, 17) $Label8 = GUICtrlCreateLabel("--", 120, 88, 10, 17) Global $ingeneldn2 = GUICtrlCreateInput("11", 128, 88, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenhill1 = GUICtrlCreateInput("X", 80, 112, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label9 = GUICtrlCreateLabel("Gen Hill", 32, 112, 41, 17) $Label10 = GUICtrlCreateLabel("--", 120, 112, 10, 17) Global $ingenhill2 = GUICtrlCreateInput("X", 128, 112, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingendip1 = GUICtrlCreateInput("X", 80, 136, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label11 = GUICtrlCreateLabel("Gen Dip", 32, 136, 43, 17) $Label12 = GUICtrlCreateLabel("--", 120, 136, 10, 17) Global $ingendip2 = GUICtrlCreateInput("X", 128, 136, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label13 = GUICtrlCreateLabel("Height Min.", 16, 184, 59, 17) Global $inhmin = GUICtrlCreateInput("10", 80, 184, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) GUICtrlSetTip(-1, "This is pixels from bottom of drawing area") $Label14 = GUICtrlCreateLabel("Line Size", 24, 232, 47, 17) Global $inlinesize = GUICtrlCreateInput("4", 80, 232, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $inhillstop = GUICtrlCreateInput("X", 288, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label15 = GUICtrlCreateLabel("Hill Stop Chance", 200, 40, 84, 17) Global $inrand1 = GUICtrlCreateInput("1", 288, 16, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label16 = GUICtrlCreateLabel("Random", 240, 16, 46, 17) $Label17 = GUICtrlCreateLabel("--", 328, 16, 10, 17) Global $inrand2 = GUICtrlCreateInput("9", 336, 16, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $indipstop = GUICtrlCreateInput("X", 288, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label18 = GUICtrlCreateLabel("Dip Stop Chance", 200, 64, 84, 17) Global $maxhillh = GUICtrlCreateInput("X", 288, 104, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label19 = GUICtrlCreateLabel("Max Hill Height", 208, 104, 76, 17) Global $maxhillw = GUICtrlCreateInput("X", 288, 128, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label20 = GUICtrlCreateLabel("Max Hill Width", 208, 128, 76, 17) Global $maxdiph = GUICtrlCreateInput("X", 288, 152, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label21 = GUICtrlCreateLabel("Max Dip Height", 208, 152, 76, 17) Global $maxdipw = GUICtrlCreateInput("X", 288, 176, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label22 = GUICtrlCreateLabel("Max Dip Width", 208, 176, 76, 17) $Label23 = GUICtrlCreateLabel("Step Size", 24, 256, 49, 17) Global $insteph = GUICtrlCreateInput("4", 80, 256, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $indirtlayer = GUICtrlCreateInput("4", 240, 216, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label24 = GUICtrlCreateLabel("Dirt Offset", 188, 216, 49, 17) Global $inrocklayer1 = GUICtrlCreateInput("X", 240, 240, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label26 = GUICtrlCreateLabel("Rock Layer", 176, 240, 62, 17) $Label27 = GUICtrlCreateLabel("--", 280, 240, 10, 17) Global $inrocklayer2 = GUICtrlCreateInput("X", 288, 240, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $intoolowdnchance1 = GUICtrlCreateInput("1", 160, 296, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label25 = GUICtrlCreateLabel("Elev. Dn chance if toolow =1", 8, 298, 148, 17) $Label28 = GUICtrlCreateLabel("of", 192, 298, 13, 17) Global $intoolowdnchance2 = GUICtrlCreateInput("20", 208, 296, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $intoohupchance1 = GUICtrlCreateInput("1", 160, 320, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label29 = GUICtrlCreateLabel("Elev. Up chance if tooh =1", 8, 322, 147, 17) $Label30 = GUICtrlCreateLabel("of", 192, 322, 13, 17) Global $intoohupchance2 = GUICtrlCreateInput("20", 208, 320, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label31 = GUICtrlCreateLabel("Height Max", 16, 208, 58, 17) Global $inhmax = GUICtrlCreateInput("20", 80, 208, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) GUICtrlSetTip(-1, "This is pixels from the top of the drawing area") Global $checkrandom = GUICtrlCreateCheckbox("Randomize Gen. #", 48, 160, 113, 17) Global $btndefault = GUICtrlCreateButton("Default Values", 280, 312, 99, 25, $WS_GROUP) Global $checkcontinue = GUICtrlCreateCheckbox("Continuously Generate", 248, 288, 129, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### EndFunc I run a laptop (not on power save) if you were wondering. This glitch may only be for slower-CPU computers, honestly I'm not sure. This has me baffled. Edited August 18, 2011 by TheGuardian Link to comment Share on other sites More sharing options...
monoscout999 Posted August 18, 2011 Share Posted August 18, 2011 (edited) First of all... you didn`t dispose any GDI object... that is wrong.. see the help file for every GDI function you use, in the remarks it says the way to dispose that particular object. It is a BIG mistake in this case, where you are creating objects all the time. Edited August 18, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
TheGuardian Posted August 18, 2011 Author Share Posted August 18, 2011 First of all... you didn`t dispose any GDI object... that is wrong.. see the help file for every GDI function you use, in the remarks it says the way to dispose that particular object.It is a BIG mistake in this case, where you are creating objects all the time.I want my program to continuously generate and scroll it acrossGraphicsDispose would cause all the graphics to be trashed which I would like to do but not all at the same time.But also how would my mouse moving cause it to run faster? Link to comment Share on other sites More sharing options...
monoscout999 Posted August 18, 2011 Share Posted August 18, 2011 GraphicDispose where the script closes... and pendispose too... it is important to store the handles of those objects in Global Variables, so before exit you can dispose them.. also maybe you can use few pens and change the color of it. Link to comment Share on other sites More sharing options...
TheGuardian Posted August 18, 2011 Author Share Posted August 18, 2011 (edited) Ok, I made:-the pens at the beginning of the script (had $linewidth issues)-It disposes the Graphics and pens when closing-removed grey pen (it was originally for stone)-oh I also made the variables used for closing GlobalBut wouldn't resetting the color of the pen every loop slow it down more?I only have 3 pens now.Heres the new code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=C:\Users\Matt\Pictures\Icons\Elements\leaf.ico #AutoIt3Wrapper_outfile=C:\Users\Matt\Desktop\Generator.exe #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> reloadoptions(0) ;Load the options GUI #Region ### START Koda GUI section ### Form=C:\Users\Matt\Pictures\Gimp\GUI\Form1.kxf $Form1 = GUICreate("Generate Level", 1102, 502, 194, 139, BitOR($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetBkColor(0x000000) $btngenerate = GUICtrlCreateButton("Generate!", 464, 472, 179, 25, $WS_GROUP) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $statuslbl = GUICtrlCreateLabel("Generating 0/0", 648, 472, 172, 17) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUICtrlSetColor(-1, 0x00FF00) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetState($checkcontinue,$GUI_CHECKED) GUICtrlSetState($checkrandom,$GUI_CHECKED) _GDIPlus_Startup() $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) Global $greenpen, $blackpen ,$brownpen While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIPlus_GraphicsDispose($hwnd) _GDIPlus_PenDispose($greenpen) _GDIPlus_PenDispose($brownpen) _GDIPlus_PenDispose($blackpen) Exit Case $btngenerate If GUICtrlRead($checkrandom) = $GUI_CHECKED then randomgenops() If GUICtrlRead($checkcontinue) = $GUI_CHECKED then Generateinfinite() Else Generateland() EndIf Case $btndefault reloadoptions(1) EndSwitch WEnd Func Generateland() _GDIPlus_GraphicsClear($hwnd) Global $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) $linewidth = GUICtrlRead($inlinesize) $greenpen = _GDIPlus_PenCreate(0xFF00FF00,$linewidth) $brownpen = _GDIPlus_PenCreate(0xFF733D1A,$linewidth) $blackpen = _GDIPlus_PenCreate(0xFF000000,$linewidth) $winsize = WinGetPos("Generate Level") ;YAY! lets do some math... $y = Round(($winsize[3]-50)/2,0) ;offset for bottom, get middle $yoff = Round(($winsize[3]-60)/4,0) ; get the quarters $y = Random($y-$yoff,$y+$yoff,1) ;use the 2 interquarters $x = Round($linewidth/2,0) $bottom = $winsize[3]-80 $bottomlimit = GUICtrlRead($inhmin) $counter = 1 Do GUICtrlSetData($statuslbl,"Generating "&$counter&"/"&Round($winsize[2]/$linewidth,0)) $ran = Random(GUICtrlRead($inmainran1),GUICtrlRead($inmainran2),1) $toolow = 0 $tooh = 0 If $toolow = 1 and $y <= $winsize[3]-$yoff Then $toolow = 0 ;this is to bring level back to normal elevation randomgenops() EndIf If $tooh = 1 and $y >= $yoff Then $tooh = 0 ;this is to bring level back to normal elevation ;Generate Flat If $ran >= GUICtrlRead($ingenflat1) And $ran <= GUICtrlRead($ingenflat2) Then _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Up If $ran >= GUICtrlRead($ingenelup1) And $ran <= GUICtrlRead($ingenelup2) Then If $y - GUICtrlRead($insteph) <= GUICtrlRead($inhmax) Then $tooh = 1;Lets not go too far up yea? GUICtrlSetData($ingenelup2,"3") GUICtrlSetData($ingenflat1,"4") GUICtrlSetData($ingenflat2,"7") GUICtrlSetData($ingeneldn1,"8") EndIf ;its too high make it have little chance of going back up until a certain elevation is met ;this gives it a smaller chance to go back up until its low enough If $tooh = 1 And Random(GUICtrlRead($intoohupchance1),GUICtrlRead($intoohupchance2),1) = GUICtrlRead($intoohupchance1) Then $y = $y - GUICtrlRead($insteph) If $tooh = 0 Then $y = $y - GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Down If $ran >= GUICtrlRead($ingeneldn1) And $ran <= GUICtrlRead($ingeneldn2) Then If $y + GUICtrlRead($insteph) >= $bottom - $bottomlimit Then $toolow = 1;Lets not go too far down yea? GUICtrlSetData($ingenelup2,"4") GUICtrlSetData($ingenflat1,"5") GUICtrlSetData($ingenflat2,"8") GUICtrlSetData($ingeneldn1,"9") EndIf ;its too low make it have little chance of going down until a certain hight is met ;this gives it a smaller chance to go back down until its high enough If $toolow = 1 and Random(GUICtrlRead($intoolowdnchance1),GUICtrlRead($intoolowdnchance2),1) = GUICtrlRead($intoolowdnchance1) Then $y = $y + GUICtrlRead($insteph) If $toolow = 0 Then $y = $y + GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf $counter = $counter + 1 $x = $x + $linewidth Until $x >= $winsize[2] GUICtrlSetData($statuslbl,"Generated!") EndFunc Func Generateinfinite() _GDIPlus_GraphicsClear($hwnd) Global $hwnd = _GDIPlus_GraphicsCreateFromHWND($Form1) $linewidth = GUICtrlRead($inlinesize) $greenpen = _GDIPlus_PenCreate(0xFF00FF00,$linewidth) $brownpen = _GDIPlus_PenCreate(0xFF733D1A,$linewidth) $blackpen = _GDIPlus_PenCreate(0xFF000000,$linewidth) $winsize = WinGetPos("Generate Level") ;YAY! lets do some math... $y = Round(($winsize[3]-50)/2,0) ;offset for bottom, get middle $yoff = Round(($winsize[3]-60)/4,0) ; get the quarters $y = Random($y-$yoff,$y+$yoff,1) ;use the 2 interquarters $x = Round($linewidth/2,0) $bottom = $winsize[3]-80 $bottomlimit = GUICtrlRead($inhmin) $counter = 1 Do GUICtrlSetData($statuslbl,"Generating "&$counter) $ran = Random(GUICtrlRead($inmainran1),GUICtrlRead($inmainran2),1) $toolow = 0 $tooh = 0 If $toolow = 1 and $y <= $winsize[3]-$yoff Then $toolow = 0 ;this is to bring level back to normal elevation randomgenops() EndIf If $tooh = 1 and $y >= $yoff Then $tooh = 0 ;this is to bring level back to normal elevation _GDIPlus_GraphicsDrawLine($hwnd,$x+20,$bottom,$x+20,1,$blackpen) ;get rid of land infront ;Generate Flat If $ran >= GUICtrlRead($ingenflat1) And $ran <= GUICtrlRead($ingenflat2) Then _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Up If $ran >= GUICtrlRead($ingenelup1) And $ran <= GUICtrlRead($ingenelup2) Then If $y - GUICtrlRead($insteph) <= GUICtrlRead($inhmax) Then $tooh = 1;Lets not go too far up yea? GUICtrlSetData($ingenelup2,"3") GUICtrlSetData($ingenflat1,"4") GUICtrlSetData($ingenflat2,"7") GUICtrlSetData($ingeneldn1,"8") EndIf ;its too high make it have little chance of going back up until a certain elevation is met ;this gives it a smaller chance to go back up until its low enough If $tooh = 1 And Random(GUICtrlRead($intoohupchance1),GUICtrlRead($intoohupchance2),1) = GUICtrlRead($intoohupchance1) Then $y = $y - GUICtrlRead($insteph) If $tooh = 0 Then $y = $y - GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf ;Generate Elevate Down If $ran >= GUICtrlRead($ingeneldn1) And $ran <= GUICtrlRead($ingeneldn2) Then If $y + GUICtrlRead($insteph) >= $bottom - $bottomlimit Then $toolow = 1;Lets not go too far down yea? GUICtrlSetData($ingenelup2,"4") GUICtrlSetData($ingenflat1,"5") GUICtrlSetData($ingenflat2,"8") GUICtrlSetData($ingeneldn1,"9") EndIf ;its too low make it have little chance of going down until a certain hight is met ;this gives it a smaller chance to go back down until its high enough If $toolow = 1 and Random(GUICtrlRead($intoolowdnchance1),GUICtrlRead($intoolowdnchance2),1) = GUICtrlRead($intoolowdnchance1) Then $y = $y + GUICtrlRead($insteph) If $toolow = 0 Then $y = $y + GUICtrlRead($insteph) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0),$greenpen) _GDIPlus_GraphicsDrawLine($hwnd,$x,$bottom,$x,$y + Round($linewidth/2,0)+GUICtrlRead($indirtlayer),$brownpen) EndIf $counter = $counter + 1 $x = $x + $linewidth If $x >= $winsize[2] then $x = Round($linewidth/2,0) $blackpen = _GDIPlus_PenCreate(0xFF000000,40) _GDIPlus_GraphicsDrawLine($hwnd,1,$bottom,1,1,$blackpen) ;get rid of land infront in the beginning $blackpen = _GDIPlus_PenCreate(0xFF000000,$linewidth) EndIf Until GUIGetMsg() = $btngenerate GUICtrlSetData($statuslbl,"Generated!") EndFunc Func randomgenops() $ran = Random(2,5,1) GUICtrlSetData($ingenelup2,$ran) GUICtrlSetData($ingenflat1,$ran+1) $ran = Random($ran+2,$ran+5,1) GUICtrlSetData($ingenflat2,$ran) GUICtrlSetData($ingeneldn1,$ran+1) ;Random(7,11,1) EndFunc Func reloadoptions($x) If $x = 1 Then GUIDelete($Form2) #Region ### START Koda GUI section ### Form= Global $Form2 = GUICreate("Options", 392, 418, 515, 140) Global $inmainran1 = GUICtrlCreateInput("1", 80, 8, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label1 = GUICtrlCreateLabel("Main Random", 8, 8, 70, 17) $Label2 = GUICtrlCreateLabel("--", 120, 8, 10, 17) Global $inmainran2 = GUICtrlCreateInput("11", 128, 8, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenflat1 = GUICtrlCreateInput("4", 80, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label3 = GUICtrlCreateLabel("Gen Flat", 32, 40, 44, 17) $Label4 = GUICtrlCreateLabel("--", 120, 40, 10, 17) Global $ingenflat2 = GUICtrlCreateInput("8", 128, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenelup1 = GUICtrlCreateInput("1", 80, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label5 = GUICtrlCreateLabel("Gen Elev. Up", 8, 64, 68, 17) $Label6 = GUICtrlCreateLabel("--", 120, 64, 10, 17) Global $ingenelup2 = GUICtrlCreateInput("3", 128, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingeneldn1 = GUICtrlCreateInput("9", 80, 88, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label7 = GUICtrlCreateLabel("Gen Elev. Dn", 8, 88, 68, 17) $Label8 = GUICtrlCreateLabel("--", 120, 88, 10, 17) Global $ingeneldn2 = GUICtrlCreateInput("11", 128, 88, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingenhill1 = GUICtrlCreateInput("X", 80, 112, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label9 = GUICtrlCreateLabel("Gen Hill", 32, 112, 41, 17) $Label10 = GUICtrlCreateLabel("--", 120, 112, 10, 17) Global $ingenhill2 = GUICtrlCreateInput("X", 128, 112, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $ingendip1 = GUICtrlCreateInput("X", 80, 136, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label11 = GUICtrlCreateLabel("Gen Dip", 32, 136, 43, 17) $Label12 = GUICtrlCreateLabel("--", 120, 136, 10, 17) Global $ingendip2 = GUICtrlCreateInput("X", 128, 136, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label13 = GUICtrlCreateLabel("Height Min.", 16, 184, 59, 17) Global $inhmin = GUICtrlCreateInput("10", 80, 184, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) GUICtrlSetTip(-1, "This is pixels from bottom of drawing area") $Label14 = GUICtrlCreateLabel("Line Size", 24, 232, 47, 17) Global $inlinesize = GUICtrlCreateInput("4", 80, 232, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $inhillstop = GUICtrlCreateInput("X", 288, 40, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label15 = GUICtrlCreateLabel("Hill Stop Chance", 200, 40, 84, 17) Global $inrand1 = GUICtrlCreateInput("1", 288, 16, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label16 = GUICtrlCreateLabel("Random", 240, 16, 46, 17) $Label17 = GUICtrlCreateLabel("--", 328, 16, 10, 17) Global $inrand2 = GUICtrlCreateInput("9", 336, 16, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $indipstop = GUICtrlCreateInput("X", 288, 64, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label18 = GUICtrlCreateLabel("Dip Stop Chance", 200, 64, 84, 17) Global $maxhillh = GUICtrlCreateInput("X", 288, 104, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label19 = GUICtrlCreateLabel("Max Hill Height", 208, 104, 76, 17) Global $maxhillw = GUICtrlCreateInput("X", 288, 128, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label20 = GUICtrlCreateLabel("Max Hill Width", 208, 128, 76, 17) Global $maxdiph = GUICtrlCreateInput("X", 288, 152, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label21 = GUICtrlCreateLabel("Max Dip Height", 208, 152, 76, 17) Global $maxdipw = GUICtrlCreateInput("X", 288, 176, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label22 = GUICtrlCreateLabel("Max Dip Width", 208, 176, 76, 17) $Label23 = GUICtrlCreateLabel("Step Size", 24, 256, 49, 17) Global $insteph = GUICtrlCreateInput("4", 80, 256, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $indirtlayer = GUICtrlCreateInput("4", 240, 216, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label24 = GUICtrlCreateLabel("Dirt Offset", 188, 216, 49, 17) Global $inrocklayer1 = GUICtrlCreateInput("X", 240, 240, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label26 = GUICtrlCreateLabel("Rock Layer", 176, 240, 62, 17) $Label27 = GUICtrlCreateLabel("--", 280, 240, 10, 17) Global $inrocklayer2 = GUICtrlCreateInput("X", 288, 240, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $intoolowdnchance1 = GUICtrlCreateInput("1", 160, 296, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label25 = GUICtrlCreateLabel("Elev. Dn chance if toolow =1", 8, 298, 148, 17) $Label28 = GUICtrlCreateLabel("of", 192, 298, 13, 17) Global $intoolowdnchance2 = GUICtrlCreateInput("20", 208, 296, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) Global $intoohupchance1 = GUICtrlCreateInput("1", 160, 320, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label29 = GUICtrlCreateLabel("Elev. Up chance if tooh =1", 8, 322, 147, 17) $Label30 = GUICtrlCreateLabel("of", 192, 322, 13, 17) Global $intoohupchance2 = GUICtrlCreateInput("20", 208, 320, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) $Label31 = GUICtrlCreateLabel("Height Max", 16, 208, 58, 17) Global $inhmax = GUICtrlCreateInput("20", 80, 208, 41, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER)) GUICtrlSetTip(-1, "This is pixels from the top of the drawing area") Global $checkrandom = GUICtrlCreateCheckbox("Randomize Gen. #", 48, 160, 113, 17) Global $btndefault = GUICtrlCreateButton("Default Values", 280, 312, 99, 25, $WS_GROUP) Global $checkcontinue = GUICtrlCreateCheckbox("Continuously Generate", 248, 288, 129, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### EndFunc Edited August 18, 2011 by TheGuardian Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 18, 2011 Share Posted August 18, 2011 (edited) Is this the first time you are using GUIGetMsg()? This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.So basically, if there is an event, do it. If there isn't, do a Sleep(10).If you want precision, use something other than GUIGetMsg(), e.g. OnEvent Mode.Edit: Well, precision is the wrong word but it will have to do. Edited August 18, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
TheGuardian Posted August 18, 2011 Author Share Posted August 18, 2011 (edited) Lol, no I just never looked into what it does besides spit out the guictrl handles when clicked and such. So it stops idling when the mouse is moved? Until GUIGetMsg() = $btngenerate is the culprit then .... EDIT: Indeed confirmed I switched Until GUIGetMsg() = $btngenerate to Until $counter = 10000 and it ran consistently. Thanks everybody! Edited August 18, 2011 by TheGuardian Link to comment Share on other sites More sharing options...
TheGuardian Posted August 19, 2011 Author Share Posted August 19, 2011 (edited) Another issue... After switching all my buttons to OnEvents GUICtrlSetOnEvent($btngenerate,"btngenerate") GUISetOnEvent($GUI_EVENT_CLOSE,"close",$Form1) GUISetOnEvent($GUI_EVENT_CLOSE,"close",$Form2) GUICtrlSetOnEvent($btndefault,"reloadoptions") They work, but not when the generation loop is running (doesn't that defeat the purpose of onevents?) EDIT: did a test and it waits until the generation is done before it does the event. any way to fix this? Edited August 19, 2011 by TheGuardian Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 19, 2011 Share Posted August 19, 2011 They work, but not when the generation loop is running (doesn't that defeat the purpose of onevents?)No, having multiple events running at the same time would be black magic.Look at Interrupting a running function in the wiki, basically, set a flag and return to the main-loop so you can process that AND continue running other events as usual. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Werty Posted August 19, 2011 Share Posted August 19, 2011 (edited) Is this the first time you are using GUIGetMsg()? Awww man, dont laugh at him I had the same yesterday Imagine some super-intelligent Alien, millions of years ahead of humans, landing in his spaceship next to you, then you show him your coffee mug and ask him, "What is this ? ", the Alien would look like one big question mark, saying "I dont know", and then you start laughing in his face "Bwaahahaaa, it's a coffee mug !!!" Edited August 19, 2011 by Werty Some guy's script +Â some other guy's script =Â my script! Link to comment Share on other sites More sharing options...
MvGulik Posted August 19, 2011 Share Posted August 19, 2011 So it stops idling when the mouse is moved?In a nutshell, Yes.Until GUIGetMsg() = $btngenerateis the culprit then ....Nope.1) Your not using GUIGetMsg() right here. (as your eating up half of the generated events.)GUIGetMsg() only generates one message per event, and after polling that event its removed from the GUIGetMsg() list/data. (Google FIFO + stack)2) "Until" has noting to do with it. Its just a the default GUIGetMsg() behavior. If there is nothing happening (no events) it will only fire Zero(value) messaged in a generally (lower) rate. Ergo: apparent slowdown. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
TheGuardian Posted August 19, 2011 Author Share Posted August 19, 2011 (edited) 1) Your not using GUIGetMsg() right here. (as your eating up half of the generated events.)GUIGetMsg() only generates one message per event, and after polling that event its removed from the GUIGetMsg() list/data. (Google FIFO + stack)2) "Until" has noting to do with it. Its just a the default GUIGetMsg() behavior. If there is nothing happening (no events) it will only fire Zero(value) messaged in a generally (lower) rate. Ergo: apparent slowdown.1. ????2. I know Until has nothing to do with it, I was referring to the line of code.But I did switch it to Until $counter = 10000And it ran without idling.___Also thank you for pointing me to http://www.autoitscript.com/wiki/Interrupting_a_running_functionI was searching the forum but I was getting a bunch of other issues has trouble nailing it down.____And on another note, AdmiralAlkex. I checked out your SDL library. Some hot shizz, you got there. I will probably start working on moving the gdi into SDL because I may turn this into some sort of game. Edited August 19, 2011 by TheGuardian Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now