seltsame Geschwindigkeitsdifferenzen...

  • ich habe mich mal in ner Art Spiel versucht,
    wobei mir eine kleine Macke aufgefallen ist.

    Die Geschwindigkeit der Schleife bleibt einfach nicht konstant
    könnt ihr mir sagen wieso?


    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $x2 = 200
    Global $x3 = 432
    Global $x4 = 560
    $y1 = 19
    $y2 = 19
    $y3 = 19
    $Form1 = GUICreate("Form1", 446, 836, 444, 12)
    $Button1 = GUICtrlCreateButton("o", 216, 752, 17, 17, 0)
    $Button2 = GUICtrlCreateButton("<", 560, 560, 19, 17, 0)
    $Button3 = GUICtrlCreateButton(">", 432, 432, 19, 17, 0)
    $Button4 = GUICtrlCreateButton("<", 200, 256, 19, 17, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(2)
    $x2 = $x2 + 1
    $x3 = $x3 + 1
    $x4 = $x4 + 1
    GUICtrlSetPos($Button2, $y1,$x2)
    GUICtrlSetPos($Button3, $y2,$x3)
    GUICtrlSetPos($Button4, $y3,$x4)
    $nMsg = GUIGetMsg()

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If $x2 > 800 then
    GUICtrlSetPos($Button2, $y1, 5)
    $x2 = 5
    $y1 = Random(10,400,50)
    EndIf
    If $x3 > 800 then
    GUICtrlSetPos($Button3, $y2, 5)
    $x3 = 5
    $y2 = Random(10,400,50)
    EndIf
    If $x4 > 800 then
    GUICtrlSetPos($Button4, $y3, 5)
    $x4 = 5
    $y3 = random(10,400,50)
    EndIf
    WEnd

    [/autoit]


    Nicht wundern;
    den unteren Button wird man später noch bewegen können,
    und die Grafiken liegen bei mir auch schon vor,
    ich hab sie allerdings der Einfachheit halber durch Buttons ersetzt,
    Also hier geht's nur um's Prinzip.


    Danke vorweg


    Gruß,

    Buckiuxx

    :thumbup::thumbup::thumbup:

    Einmal editiert, zuletzt von Buckiuxx (6. Juni 2010 um 18:19)

  • Also das die Geschwindigkeit nicht konstant bleibt ist klar denn der Prozi arbeitet ja immer noch für andere Prozesse

    //Edit: hier guck wie dolle das schwankt

    [autoit]


    #include <Timers.au3>
    Global $x = 0
    Opt("GUIOnEventMode", 1)
    $hGui = GUICreate("LPM Meter", 238, 127, -1, -1)
    GUISetOnEvent(-3, "_Exit")
    $Input = GUICtrlCreateInput("", 32, 40, 169, 21, 0x0800)
    GUISetState(@SW_SHOW)
    $hTimer = _Timer_Init()
    AdlibRegister("UPDTimer", 1000)

    [/autoit][autoit][/autoit][autoit]

    While 1
    $x += 1
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func UPDTimer()
    GUICtrlSetData($Input, "Loops per min: " & Int($x / (_Timer_Diff($hTimer) / 1000) ))
    EndFunc ;==>UPDTimer

    [/autoit][autoit][/autoit][autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]
  • Ich mein andere GUI-Spiele schaffen es doch auch mit konstanter Geschwindigkeit.


    Gruß,
    Buckuixx
    :thumbup::thumbup::thumbup:

  • Mit der Auslastung hat das hier nichts zu tun.
    Durch das Sleep(2) ist die CPU-Auslastung gering und es stehen für den Rest genügend Reserven bereit.
    Das GUIGetMsg() ist hier der variierende Term.
    Es wirkt ähnlich wie ein Sleep - nur halt nicht konstant sondern leicht schwankend.
    Wenn du es also in den OnEvent-Modus umschreibst fällt dieser Effekt weg:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $x2 = 200, $x3 = 432, $x4 = 560
    Global $y1 = 19, $y2 = 19, $y3 = 19

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("GUI", 446, 836, 444, 12)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Ende")
    $Button1 = GUICtrlCreateButton("o", 216, 752, 17, 17, 0)
    $Button2 = GUICtrlCreateButton("<", 560, 560, 19, 17, 0)
    $Button3 = GUICtrlCreateButton(">", 432, 432, 19, 17, 0)
    $Button4 = GUICtrlCreateButton("<", 200, 256, 19, 17, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(2)
    $x2 += 1
    $x3 += 1
    $x4 += 1
    GUICtrlSetPos($Button2, $y2, $x2)
    GUICtrlSetPos($Button3, $y3, $x3)
    GUICtrlSetPos($Button4, $y3, $x4)

    [/autoit] [autoit][/autoit] [autoit]

    If $x2 > 800 Then
    GUICtrlSetPos($Button2, $y1, 5)
    $x2 = 5
    $y1 = Random(10, 400, 50)
    EndIf
    If $x3 > 800 Then
    GUICtrlSetPos($Button3, $y2, 5)
    $x3 = 5
    $y2 = Random(10, 400, 50)
    EndIf
    If $x4 > 800 Then
    GUICtrlSetPos($Button4, $y3, 5)
    $x4 = 5
    $y3 = Random(10, 400, 50)
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Ende()
    Exit
    EndFunc

    [/autoit]
  • mit der Geschwindigkeit klappt's nun.

    die ist konstant, danke


    Aber, wieso ändern sich die x-Koordinaten von allen Buttons wenn nur einer den unteren Rand zu nahe kommt?

    Liegt das an dem OnEvent-Modus ??
    Ich gugg mir den nochmal an...

    Gruß,
    Buckiuxx
    :thumbup::thumbup::thumbup:

  • Spoiler anzeigen
    [autoit]

    GUICtrlSetPos($Button2, $y2, $x2)
    GUICtrlSetPos($Button3, $y3, $x3)
    GUICtrlSetPos($Button4, $y3, $x4)

    [/autoit]


    Das musste meines Erachtens nach so bleiben:


    Spoiler anzeigen
    [autoit]

    GUICtrlSetPos($Button2, $y1,$x2)
    GUICtrlSetPos($Button3, $y2,$x3)
    GUICtrlSetPos($Button4, $y3,$x4)

    [/autoit]


    Danke

  • ich denke mal das liegt daran:

    GUICtrlSetPos($Button3, $y3, $x3)
    GUICtrlSetPos($Button4, $y3, $x4)

    ;)


    und ich würde die x koordinate nicht unbedingt y nennen, das machts nicht unbedingt leichter^^

    vorschlag :

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $y1 = 200, $y2 = 432, $y3 = 560
    Global $x1 = 19, $x2 = 19, $x3 = 19

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("GUI", 446, 836, 444, 12)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Ende")
    $Button1 = GUICtrlCreateButton("o", 216, 752, 17, 17, 0)
    $Button2 = GUICtrlCreateButton("<", 560, 560, 19, 17, 0)
    $Button3 = GUICtrlCreateButton(">", 432, 432, 19, 17, 0)
    $Button4 = GUICtrlCreateButton("<", 200, 256, 19, 17, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister("MoveButtons", 10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Ende()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func MoveButtons()
    $y1 += 1
    $y2 += 1
    $y3 += 1
    GUICtrlSetPos($Button2, $x1, $y1)
    GUICtrlSetPos($Button3, $x2, $y2)
    GUICtrlSetPos($Button4, $x3, $y3)
    If $y1 > 800 Then
    $y1 = 5
    $x1 = Random(10, 400, 50)
    EndIf
    If $y2 > 800 Then
    $y2 = 5
    $x2 = Random(10, 400, 50)
    EndIf
    If $y3 > 800 Then
    $y3 = 5
    $x3 = Random(10, 400, 50)
    EndIf
    EndFunc

    [/autoit]
  • stimmt...klar...egal^^

    Danke


    eins versteh ich noch nicht:

    Die 'While-Sleep-WEnd'-Schleife wird doch ewig wiederholt,
    hab ich gelernt.
    Wie können trozdem die Funktionen 'Ende' und 'MoveButtons' ausgeführt werden?


    Danke

  • das haste richtig gelernt ;)

    aber:
    der oneventmodus und auch adlibregister sind da ausnahmen.
    die halten alles andere an und führen dann ersteinmal ihre funktion aus.
    nachdem die funktion ausgeführt ist gehts da weiter wo zuvor angehalten wurde

    die 2 sind so spezielle fälle. sonst isses aber richtig dass eine endlosschleife endlos ist :D

  • Die Schleife ist ja auch weiter undendlich.
    Das andere Funktionen noch ausgeführt werden, die entweder wegen der Zeit (Adlib Register) oder wegen GuiOnEventMode (also eines klicks).

    Grundsätzlich hat Schnitzel aber recht: oneventmodus und auch adlibregister sind ausnahmen bei denen der Script nicht einfach von oben nach unten ausgeführt wird.

    mfg Ubuntu