Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/23/2024 in all areas

  1. I have added a function and packed the whole thing into a speed comparison: #include <Array.au3> Global Const $aArrayRaw = Get_Array() Global $f_DecimalPlaces = 1 Global $iT, $a_Results[0][3] Func Get_Array() Local $aArray[1e6] For $i = 0 To UBound($aArray) - 1 $aArray[$i] = Random(0,2,1) = 2 ? " " : "x" Next Return $aArray EndFunc ;==>Get_Array ; the first measurement $aArray = $aArrayRaw ReDim $a_Results[UBound($a_Results) + 1][3] $a_Results[UBound($a_Results) - 1][0] = "Andreik" $iT = TimerInit() $aArray = _strip_Andreik($aArray) $iT = TimerDiff($iT) $a_Results[UBound($a_Results) - 1][1] = ($iT) ; the second measurement $aArray = $aArrayRaw ReDim $a_Results[UBound($a_Results) + 1][3] $a_Results[UBound($a_Results) - 1][0] = "SmOke_N" $iT = TimerInit() $aArray = _strip_SmOke_N($aArray) $iT = TimerDiff($iT) $a_Results[UBound($a_Results) - 1][1] = ($iT) ; the third measurement $aArray = $aArrayRaw ReDim $a_Results[UBound($a_Results) + 1][3] $a_Results[UBound($a_Results) - 1][0] = "Nine 1" $iT = TimerInit() $aArray = _stripNine1($aArray) $iT = TimerDiff($iT) $a_Results[UBound($a_Results) - 1][1] = ($iT) ; the fourth measurement $aArray = $aArrayRaw ReDim $a_Results[UBound($a_Results) + 1][3] $a_Results[UBound($a_Results) - 1][0] = "Nine 2" $iT = TimerInit() $aArray = _stripNine2($aArray) $iT = TimerDiff($iT) $a_Results[UBound($a_Results) - 1][1] = ($iT) ; the fifth measurement $aArray = $aArrayRaw ReDim $a_Results[UBound($a_Results) + 1][3] $a_Results[UBound($a_Results) - 1][0] = "AspirinJunkie" $iT = TimerInit() _strip_AspirinJunkie($aArray) $iT = TimerDiff($iT) $a_Results[UBound($a_Results) - 1][1] = ($iT) ; calculate results and print them out _ArraySort($a_Results, 0, 0, 0, 1) For $i = 0 To UBound($a_Results) - 1 $a_Results[$i][2] = Round($a_Results[$i][1] / $a_Results[0][1], 2) $a_Results[$i][1] = Round($a_Results[$i][1], $f_DecimalPlaces) Next _ArrayDisplay($a_Results, "Measurement Results", "", 16 + 64, Default, "name|time [ms]|factor") Func _strip_Andreik(ByRef $aData, $iStart = 0) If Not IsArray($aData) Then Return SetError(1, 0, False) Local $iElements = UBound($aData) If $iStart >= $iElements Then Return SetError(2, 0, False) Local $sResult For $Index = $iStart To $iElements - 1 $sResult &= (StringStripWS($aData[$Index], 8) ? $aData[$Index] & '|' : '') Next Return StringSplit(StringTrimRight($sResult, 1), '|', 2) EndFunc Func _stripNine1(ByRef $array, $iStart = 0) Local $sArray = StringRegExpReplace(_ArrayToString($array, Default, $iStart), "\|\s*$|(?<=\|)\s*\|", "") Return StringSplit(($iStart ? _ArrayToString($array, Default, 0, $iStart - 1) & "|" : "") & $sArray, "|", $STR_NOCOUNT) EndFunc Func _stripNine2(ByRef $array, $iStart = 0) Local $aTemp = _ArrayFindAll($array, "^\s*$", $iStart, Default, 0, 3) _ArrayInsert($aTemp, 0, UBound($aTemp)) _ArrayDelete($array, $aTemp) Return $array EndFunc ; $bNoWS = White spaces only count as empty element, true by default Func _strip_SmOke_N(ByRef $aArgs, $iStart = 0, $bNoWS = True) If UBound($aArgs, 2) Then Return SetError(1, 0, 0) ; out of bounds If $iStart = Default Or $iStart == -1 Then $iStart = 0 If $bNoWS = Default Or $bNoWS == -1 Then $bNoWS = True Local $iUB = UBound($aArgs) ; catch start out of bounds If $iStart < 0 Or $iStart > $iUB - 1 Then Return SetError(2, 0, 0) Local $aRet[$iUB] Local $iEnum = 0 ; build array without concatenation For $i = $iStart To $iUB - 1 If StringLen($aArgs[$i]) == 0 Then ContinueLoop If $bNoWS Then If StringRegExp($aArgs[$i], "(?m)^\s+$") Then ContinueLoop EndIf $aRet[$iEnum] = $aArgs[$i] $iEnum += 1 Next If $iEnum = 0 Then ; nothing found, but rather than return a false ; set error and return array where user can do what they want with it Return SetError(2, 0, $aArgs) EndIf ; resize return array ReDim $aRet[$iEnum] ; return extended as the ubound of new array Return SetExtended($iEnum, $aRet) EndFunc Func _strip_AspirinJunkie(ByRef $A, $iStart = 0, $iEnd = UBound($A) - 1) Local $x = $iStart For $i = $iStart To $iEnd If StringIsSpace($A[$i]) Then ContinueLoop $A[$x] = $A[$i] $x += 1 Next Redim $A[$x] EndFunc Nine`s first function performs best, but would still have to be adapted to certain special cases for which it currently does not work, depending on the type of data: 1. if first array element is empty it`s still in the array 2. only line breaks are not recognized as empty strings (which may be correct depending on the context) and 3. if pipes ("|") occur in the strings.
    3 points
  2. For comparative testing purposes I tried to translate the script created by @Numeric1 at this link which uses AutoitObject, so as to use AutoItObject_Internal.au3 by @genius257 instead. (The latter does not require additional DLLs.). Maybe it seems a little slower and slightly less responsive (?) P.S. I created a new thread just to not hijack @Numeric1's original thread. (any improvements and corrections relating to the translation of the listing are welcome) ; =============================================================================================================================== ; original script created by @Numeric1 at the link below ; https://www.autoitscript.com/forum/topic/211824-ping-pong-game-with-autoitobject/ ; =============================================================================================================================== ; Game Overview: ; - The game consists of a paddle and a ball. ; - The player controls the paddle using the left and right arrow keys. ; - The objective is to bounce the ball off the paddle and prevent it from hitting the bottom edge of the window. ; - If the ball hits the bottom edge, the game ends. ; - As the game progresses, the speed of the ball increases periodically, making it more challenging. ; Controls: ; - Left Arrow Key: Move the paddle to the left. ; - Right Arrow Key: Move the paddle to the right. ; - S Key: Pause the game. ; - When the game is paused, press Left or Right arrow key to resume. ; Enjoy playing Ping Pong! ; =============================================================================================================================== #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> ; #include "AutoItObject.au3" #include "AutoItObject_Internal.au3" ; <-- https://www.autoitscript.com/forum/topic/185720-autoitobject-pure-autoit #include <Misc.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() Const $COLOR_RED = 0xFFFF0000 Const $COLOR_GREEN = 0xFF00FF00 Func Ball($x = 0, $y = 0, $size = 5) Local $cBall = IDispatch() ; _AutoItObject_Class() With $cBall .dx = 10 .dy = -10 .size = $size .X = $x .Y = $y .__defineGetter("move", _move) EndWith Return $cBall ; .Object EndFunc ;==>Ball Func Paddle($x = 0, $size = 5) Local $cPaddle = IDispatch() ; _AutoItObject_Class() With $cPaddle .X = $x .size = $size .dx = 20 .__defineGetter("moveLeft", _moveLeft) .__defineGetter("moveRight", _moveRight) EndWith Return $cPaddle ; .Object EndFunc ;==>Paddle Func _moveLeft($this) $this.parent.X -= $this.parent.dx If $this.parent.X < 0 Then $this.parent.X = 0 EndFunc ;==>_moveLeft Func _moveRight($this) ; , $maxX) Local $maxX = $this.arguments.values[0] Local $paddleWidth = $this.parent.size If $this.parent.X + $this.parent.dx + $paddleWidth <= $maxX Then $this.parent.X += $this.parent.dx Else $this.parent.X = $maxX - $paddleWidth EndIf EndFunc ;==>_moveRight Func GamePanel() Local $hGUI = GUICreate("Ping Pong", 400, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) GUISetBkColor(0x000000) GUISetState() Local $aClient = WinGetClientSize($hGUI) If @error Then Return SetError(1, 0, 0) Local $iWidth = $aClient[0] Local $iHeight = $aClient[1] Local $aGDIMap[5] $aGDIMap[0] = _GDIPlus_GraphicsCreateFromHWND($hGUI) $aGDIMap[1] = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $aGDIMap[0]) $aGDIMap[2] = _GDIPlus_ImageGetGraphicsContext($aGDIMap[1]) $aGDIMap[3] = _GDIPlus_BrushCreateSolid($COLOR_RED) $aGDIMap[4] = _GDIPlus_HatchBrushCreate(4, $COLOR_GREEN) Local $Ball = Ball(40, 40) Local $paddleX = Paddle(150, 100) Local $cGamePanel = IDispatch() ; _AutoItObject_Class() With $cGamePanel .iWidth = $iWidth .iHeight = $iHeight .ball = $Ball .paddle = $paddleX .map = $aGDIMap .speedLevel = 100 .__defineGetter("move", _move) .__defineGetter("drawStage", _drawStage) .__defineGetter("cleanUpResources", _cleanUpResources) .__destructor(_cleanUpResources) .__defineGetter("runGameLoop", _runGameLoop) EndWith Return $cGamePanel ; .Object EndFunc ;==>GamePanel Func _move($this) Local $x = $this.parent.ball.X Local $y = $this.parent.ball.Y Local $dx = $this.parent.ball.dx Local $dy = $this.parent.ball.dy Local $Width = $this.parent.iWidth Local $Height = $this.parent.iHeight Local $BallSize = $this.parent.ball.size If $y + $dy >= ($Height - 40) And $x + $BallSize >= $this.parent.paddle.X And $x <= $this.parent.paddle.X + $this.parent.paddle.size Then $dy *= -1 EndIf If $y + $dy <= 0 Then $dy = Abs($dy) EndIf If $y + $dy >= $Height - $BallSize Then MsgBox(0, "Game Over", "You missed the ball! Game Over!") Exit EndIf If $x + $dx <= 0 Then $dx = Abs($dx) EndIf If $x + $dx >= $Width - $BallSize Then $dx = -Abs($dx) EndIf $x += $dx $y += $dy $this.parent.ball.dx = $dx $this.parent.ball.dy = $dy $this.parent.ball.X = $x $this.parent.ball.Y = $y $this.parent.drawStage() EndFunc ;==>_move Func _drawStage($this) Local $hGraphics = $this.parent.map[0] Local $hBitmap = $this.parent.map[1] Local $hGraphicsCtxt = $this.parent.map[2] Local $iX = $this.parent.ball.X Local $iY = $this.parent.ball.Y Local $iRadius = $this.parent.ball.size Local $padX = $this.parent.paddle.X Local $padH = $this.parent.iHeight - 40 _GDIPlus_GraphicsClear($hGraphicsCtxt, 0xFF000000) _GDIPlus_GraphicsFillEllipse($hGraphicsCtxt, $iX - $iRadius, $iY - $iRadius, $iRadius * 2, $iRadius * 2, $this.parent.map[3]) _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $padX, $padH, $this.parent.paddle.size, 10, $this.parent.map[4]) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $this.parent.iWidth, $this.parent.iHeight) EndFunc ;==>_drawStage Func _cleanUpResources($this) ConsoleWrite("clean up ressources...." & @CRLF) Local $map = $this.parent.map _GDIPlus_GraphicsDispose($map[0]) _GDIPlus_BitmapDispose($map[1]) _GDIPlus_GraphicsDispose($map[2]) _GDIPlus_BrushDispose($map[3]) $this.parent.map = 0 _GDIPlus_Shutdown() EndFunc ;==>_cleanUpResources Func _runGameLoop($this) Local $speedUpTime = 5000 Local $lastMoveTime = TimerInit() Local $maxX = $this.parent.iWidth While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $this.parent.paddle.moveLeft() If _IsPressed(27) Then $this.parent.paddle.moveRight($maxX) If _IsPressed(53) Then While 1 If _IsPressed(25) Or _IsPressed(27) Then ExitLoop Sleep(100) WEnd EndIf If TimerDiff($lastMoveTime) >= $speedUpTime Then $this.parent.speedLevel -= 5 If $this.parent.speedLevel < 0 Then $this.parent.speedLevel = 0 $lastMoveTime = TimerInit() EndIf $this.parent.move() Sleep($this.parent.speedLevel) WEnd EndFunc ;==>_runGameLoop Func _ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ;================================================ Global $game = GamePanel() $game.runGameLoop() ConsoleWrite("------> the end <-------" & @CRLF) ; $game = 0 ;=================================================
    2 points
  3. The tests previously conducted to assess the performance of the UDFs AutoItObject.au3 and AutoItObject_Internal.au3 under various conditions have highlighted discernible differences, albeit subtle. The analysis of the collected data underscores the slight preference in terms of speed for AutoItObject.au3. While this difference may not be considerable, it remains non-negligible in certain usage contexts. It is important to note that each UDF has its own advantages and disadvantages, which can influence their selection depending on the specific project requirements. The comparative table provided by @genius257 while informative, may spark debates and additional nuances regarding the evaluation of the performance and features of each UDF. Unfortunately, I no longer have the test code available.
    2 points
  4. I can't be responsible for any impact of your script or services you would run in production. | _Services_UDF v4 | | By Arcker | Run your script as a service | Req. AutoIt 3.3.8.1 min, last beta recommended ( tested in 3.3.9.21 ) |_______________________________________ ++ Preparing v5 !! Checked on 27/04/2015 <> Updated on 10/23/2013 <> Updated 07/29/2013 <> Best practices Updated 24/02/2012 -- Removed GUI code, and old codes. == Warning : 26/02/2012 <> New Version (v3 ) : 29/07/2013 | Thx to ShminkyBoy, wraithdu, Udgeen and HolmesShelock for their great contributions. Special thx to bitboy, Downloads see end of this post : ServiceExample_v4, Services.au3, ServicesConstants.au3 Presentation Here is my _Service _ UDF With this UDF, you can compile your autoit script and run it as service. Any comments are welcome. Hope you'll like it, 1 - changelog Update V4 : 23/10/2013,27/04/2015 Update : V3 on 29/07/2013 Compile the service example to see how to do then you can use the main function for your proper scriptChoose an appropriate location and copy the script here.open a command prompt, and execute the compiled script with option –I ( must be admin right since vista )start / execute "services.msc" . You will see a service called "Autoit_service". you can execute "sc query" in a command prompt too.Launch it : it will run the previous compile script. The main function will be executed after the service_init.stop and relaunch the service as you wish. Examples / Session Change / uses v1 (lock, logon, etc) By HolmesShelock. Awesome work. Edit : this example doesn't use v2 or v3 method SessionChange Service.zip Example output to give you an idea Examples demos Synoptic And for End Users, I've tried to explain the service control manager and the way it works with programs. see below Best Practice, by arcker : /! please read this if you encounter stability issues I've had to rework on services.au3 to reflect threadsafe. Threadsafe means each dll call must be on "dllopened" instead of calling dll directly for example, if you need a function in kernel32.dll, you have to open it and call it after. That's contraignant since a lot of integrated functions in autoit are not programmed this way. If you take my services.au3, at the end, you'll see reworked function to handle this change. I've not tried services for a while, since i don't need it for now, but i can help you only if your provide whole script, to see how you call every functions. I can tell that fix stability issues in callback, but i don't think it's need for your script, as far as you don't use callback. Best Practice, by udgeen : Good news! Probably i've found the working method of integrating service.au3 with other projects I realised it after ASock.au3 project by Zatorg (please, sorry if im wrong) - ASock is asynck socket - tcp on event (uses ws2_32.dll). Asock & sqlite didnt work together. The only reason for that was..._ArrayDisplay() func with gui!!! Ok. I made special sqlite.au3 without dependences. It works, but my udf seemed too be much heavy to use at another project. Few weeks ago I returned to service.au3 and found TCP UDF, Event driven project based on ASock.au3. It seemed to work as example, but didn't work at all as service. In my variant of service_example.au3 i posted msdn words about service_main procedure, that it must contain all global vars of project I'll try to post that project as an another service_example.au3 in some weeks here. If it will works. Some advice: use SysInternals Process Explorer (free gui based), or kill.exe from support tools to stop suspended service process. U can start-stop service even net start/net stop commands. Use file logging while debuging. No need to install-uninstall service after every recompilation: only stop, recompile, start. See, if it was suspended (while stopping) - kill process. The only reason not to stop service correctly i've found for today is unclean exit: opened sockets, maybe some dlls. Edit : Arcker note: too bad, that would be too easy. unclean exit is not due to opened dll, but by some more internal exit checks or something. FAQ. 1 - Hey, I've got error 1063 or error 0, what does that mean ? It simply means that you intend to run your script in scite or directly by executing it. Your script has to be installed as service and run from it. Several ways to do it : You have to combine all Globals in one place: for example at the the begining. You have to make it with other udfs too... silly workThen sort Global Const and other Global statements. If u see something like global $x = 1 do that way: global $x leeve at top. $x =1 insert into module's (udf or project) Init func.U have to do it even with standart udf... or use only necessary functions from it in your own include. Or... maybe u have another plan?Try to build your project with modified udfs - does it works now? Hmm... But it have to Maybe later after everything will work fine i'll say "msdn is wrong, microsoft lies"... But maybe i'll say that microsoft - is not so bad, because autoit works in itnet start "yourservicename"Services.mscUse API provided _Service_start, Service_stop. 2 - I want to make a GUI ! It's not possible in a service. Create another process and communicate with your service by using IPC. 3 - I've to let the main function that way ? That's contraignant. Hey, a script intended to run as service is special no ? Autoit is not C++. The only way to have a "Main" in autoit is to have a function. If you find another way, please share it ServiceExample_ThreadSafe.au3 Services.au3 ServiceExample_v4.au3 ServicesConstants.au3
    1 point
  5. This is it!!! I found why it stopped by itself !
    1 point
  6. It is a problem with the service trying to be launched, and the current lack of error checking, for such an important part experience, I'm looking into improving this The script for the taadd API calls a function that is responsible for sending the subscribe request to the process and launching the service if not available, here https://github.com/genius257/Manga/blob/main/www/api/taadd.au3#L35 The function is called, when you navigate to the subscription request page, via the subscribe link on a manga. The subscribe function is defined here: https://github.com/genius257/Manga/blob/main/mangaSvc/api.au3#L26
    1 point
  7. Hi @Gianni 🙂, AutoItObject_Internal is much slower than AutoitObject. An issue regarding speed exists on github: https://github.com/genius257/AutoItObject-Internal/issues/10
    1 point
  8. I have taken note of your valuable suggestion. What do you think about this idea? : instead of making poisoned food appear, I thought about making a speed reducer appear to give the player more luck. What do you think ?
    1 point
  9. In v4 there is a bug in services.au3: Case $SERVICE_CONTROL_STOP,$SERVICE_ACCEPT_SHUTDOWN ; new in v4, stop when system shutdown ( better mmm ? ) https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx should be: Case $SERVICE_CONTROL_STOP,$SERVICE_CONTROL_SHUTDOWN ; new in v4, stop when system shutdown ( better mmm ? )
    1 point
×
×
  • Create New...