Warum braucht kleines Prog so viel CPU?
Übersicht

![]() |
maboxBetreff: Warum braucht kleines Prog so viel CPU? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich hab hier ein kleines Programm welches komischerweise sehr viel CPU beansprucht. Wo ist der Fehler???
Danke fürs helfen! Code: [AUSKLAPPEN] Global graph_x = 800
Global graph_y = 600 Graphics graph_x, graph_y,32,2 SetBuffer BackBuffer() ;wird später zum rechteck erstellen benötigt (timer) Global counter Global ms%=MilliSecs() Global timescale Global fallgeschwindigkeit# = 200 Global max_speed# = 4 Global min_speed# = 1 Global Punkte Global ycor = graph_y-30 ;y Koordinate spieler Global xcor = graph_x/2-25 ;x koordinate spieler Color 255,255,255 ;das ist der rechteck type mit seinen "feldern"(eigenschaften) Type rechteck Field grosse Field speed Field rechteck_x Field rechteck_y End Type ;;Hauptschleife ------------------------- Repeat Cls Geschwindigkeitsnormung() rechtecke_erstellen() rechtecke_machen_lassen() Rect xcor,ycor,50,2 ;rechteck If xcor >= 745 Then xcor = 745 If xcor <= 5 Then xcor = 5 If KeyDown(203) Then xcor = (xcor -5-(.1*timescale));Links If KeyDown(205) Then xcor = (xcor +5+(.1*timescale));Rechts Text 10,10,fallgeschwindigkeit Text 10,25,"maximaler speed: " + max_speed# Text 10,40,"minimaler speed: " + min_speed# Text 10,55,"Punkte: " + Punkte Flip Until KeyHit(1) ;--------------------------------------- ;hier werden die rechtecke in zeitichen abständen erstellt Function rechtecke_erstellen() counter = (counter +1+(.1*timescale)) If counter >= fallgeschwindigkeit# Then counter = 0 info.rechteck = New rechteck info\grosse = 15 info\speed = Rnd(min_speed#,max_speed#) info\rechteck_x = Rnd(0,graph_x-info\grosse) info\rechteck_y = -5 End If End Function Function rechtecke_machen_lassen() For info.rechteck = Each rechteck info\rechteck_y = info\rechteck_y + info\speed Rect info\rechteck_x , info\rechteck_y , info\grosse , info\grosse ;Rechteck erstellen ;Wenn der rechteck das ander rechteck berührt oder aus dem Bildschirm fährt: löschen If RectsOverlap (info\rechteck_x , info\rechteck_y , info\grosse , info\grosse, xcor,ycor,50,2) Then Delete info.rechteck fallgeschwindigkeit# = fallgeschwindigkeit# -.8 max_speed# = max_speed# +.05 min_speed# = min_speed# +.05 Punkte = Punkte + 10 ElseIf info\rechteck_y >graph_y Then fallgeschwindigkeit# = fallgeschwindigkeit# -.8 Delete info.rechteck Punkte = Punkte - 5 EndIf Next End Function Function Geschwindigkeitsnormung() msa=MilliSecs() timescale=msa-ms ms=msa End Function |
||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
![]() |
Noobody |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hm mach mal Flip 0 rein und ein Waittimer.
Da gibts im FAQ und Turorials sogar nen Thread dazu... Guck da mal rein. |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
![]() |
The_Nici |
![]() Antworten mit Zitat ![]() |
---|---|---|
Dein Spiel braucht eine Begrenzung, einen Frametimer.
Code: [AUSKLAPPEN] frametimer=Createtimer(45) ;Die Zahl ist die Anzahl Frames/s ;etc.etc. While not Keydown(1) ;irgendwendwas machen Flip cls waittimer (frametimer) ;auf den Timer warten. Wend |
||
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
Also jetzt hab ich einen Frametimer eingebaut und der CPU ist auch nurnoch auf 2% aber das Bild flackert jetzt etwas und stockelt ein bisschen. Wenn ich flip auf 1 stelle stockelt und flackert es nicht mehr aber es braucht wieder viel CPU. Was soll ich machen???
hier nochmal der aktuelle Code: [AUSKLAPPEN] timer = CreateTimer (60)
Global graph_x = 800 Global graph_y = 600 Graphics graph_x, graph_y,32,1 SetBuffer BackBuffer() ;wird später zum rechteck erstellen benötigt (timer) Global counter Global ms%=MilliSecs() Global timescale Global fallgeschwindigkeit# = 200 Global max_speed# = 4 Global min_speed# = 1 Global Punkte Global fpsrate,loops, fpstime Global ycor = graph_y-30 ;y Koordinate spieler Global xcor = graph_x/2-25 ;x koordinate spieler Color 255,255,255 ;das ist der rechteck type mit seinen "feldern"(eigenschaften) Type rechteck Field grosse Field speed Field rechteck_x Field rechteck_y End Type ;;Hauptschleife ------------------------- Repeat Geschwindigkeitsnormung() rechtecke_erstellen() rechtecke_machen_lassen() Rect xcor,ycor,50,2 ;rechteck If xcor >= 745 Then xcor = 745 If xcor <= 5 Then xcor = 5 If KeyDown(203) Then xcor = (xcor -5-(.1*timescale));Links If KeyDown(205) Then xcor = (xcor +5+(.1*timescale));Rechts Text 10,10,fallgeschwindigkeit Text 10,25,"maximaler speed: " + max_speed# Text 10,40,"minimaler speed: " + min_speed# Text 10,55,"Punkte: " + Punkte Text 10,70,"Frames: " + fps() Flip 0 Cls WaitTimer timer Until KeyHit(1) ;--------------------------------------- ;hier werden die rechtecke in zeitichen abständen erstellt Function rechtecke_erstellen() counter = (counter +1+(.1*timescale)) If counter >= fallgeschwindigkeit# Then counter = 0 info.rechteck = New rechteck info\grosse = 15 info\speed = Rnd(min_speed#,max_speed#) info\rechteck_x = Rnd(0,graph_x-info\grosse) info\rechteck_y = -5 End If End Function Function rechtecke_machen_lassen() For info.rechteck = Each rechteck info\rechteck_y = info\rechteck_y + info\speed Rect info\rechteck_x , info\rechteck_y , info\grosse , info\grosse ;Rechteck erstellen ;Wenn der rechteck das ander rechteck berührt oder aus dem Bildschirm fährt: löschen If RectsOverlap (info\rechteck_x , info\rechteck_y , info\grosse , info\grosse, xcor,ycor,50,2) Then Delete info.rechteck fallgeschwindigkeit# = fallgeschwindigkeit# -.8 max_speed# = max_speed# +.05 min_speed# = min_speed# +.05 Punkte = Punkte + 10 ElseIf info\rechteck_y >graph_y Then fallgeschwindigkeit# = fallgeschwindigkeit# -.8 Delete info.rechteck Punkte = Punkte - 5 EndIf Next End Function Function Geschwindigkeitsnormung() msa=MilliSecs() timescale=msa-ms ms=msa End Function Function fps() loops = loops+1 If MilliSecs() - fpstime > 1000 Then fpsrate = loops loops = 0 fpstime = MilliSecs() End If Return fpsrate End Function |
||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
![]() |
The_Nici |
![]() Antworten mit Zitat ![]() |
---|---|---|
Versuch mal, den Frametimer auf 45 zu stellen. Vll. wirds dann besser. | ||
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
ist kein unterschied | ||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
![]() |
The_Nici |
![]() Antworten mit Zitat ![]() |
---|---|---|
mmh, bei mir läufts flüssig. Hast du das programm zufälligerweise zwei mal gestartet? | ||
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
nein.........aber vllt liegts daran, dass ich nen Laptop hab und der immer auf so wenig CPU wie möglich läuft und dann das Flip 0 nicht richtig fuktioniert.
Ich versuchs gleich mal auf einem anderen Rechner. |
||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
![]() |
peacemaker |
![]() Antworten mit Zitat ![]() |
---|---|---|
Naja, das mit dem Timer funktioniert so:
Dieser Timer macht das es z.B. 30 FPS sind. Er versucht diese zu erreichen, koste es was es wolle. Hast du einen starken PC, braucht das kaum CPU-Leistung, hast du einen sehr schwachen PC brauchts halt einfach mehr. Desshalb musst du den Wert vielleicht kleiner stellen = dann stockts aber... MfG |
||
~Tehadon~
www.tehadon.de http://www.blitzforum.de/worklogs/14/ |
![]() |
Abrexxes |
![]() Antworten mit Zitat ![]() |
---|---|---|
Wenn du deine Fallgeschwindigkeit etc mit floats rechnest dann muss es ja ruckeln. Da ein Bildschirm keine halbe oder 3/4 Pixel haben, wird bei einem Durchgang das Rechteck gar nicht bewegt, beim nächsten Durchgang dann wieder einen oder zwei Pixel etc. jenachdem was gerade hinter dem Komma rauskommt.
cu |
||
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
@Peacemaker1 Ich glaub nicht, dass es an meinem Rechner liegt. Schau mal meine Signatur an.
@Abrexxes Ok das leuchtet mit ein! ich versuchs gleich mal ~EDIT: Hm..... das macht irgendwie keinen Unterschied - sieht genauso aus wie vorher. Aktueller Code: [AUSKLAPPEN] timer = CreateTimer (60)
Global graph_x = 1280 Global graph_y = 800 Graphics graph_x, graph_y,32,1 SetBuffer BackBuffer() ;wird später zum rechteck erstellen benötigt (timer) Global counter Global ms%=MilliSecs() Global timescale Global fallgeschwindigkeit# = 200 Global max_speed# = 5 Global min_speed# = 2 Global Punkte Global fpsrate,loops, fpstime Global ycor = graph_y-30 ;y Koordinate spieler Global xcor = graph_x/2-25 ;x koordinate spieler Color 255,255,255 ;das ist der rechteck type mit seinen "feldern"(eigenschaften) Type rechteck Field grosse Field speed Field rechteck_x Field rechteck_y End Type ;;Hauptschleife ------------------------- Repeat Geschwindigkeitsnormung() rechtecke_erstellen() rechtecke_machen_lassen() Rect xcor,ycor,50,2 ;rechteck If xcor >= graph_x-55 Then xcor = graph_x-55 If xcor <= 5 Then xcor = 5 If KeyDown(203) Then xcor = (xcor -5-(.1*timescale));Links If KeyDown(205) Then xcor = (xcor +5+(.1*timescale));Rechts Text 10,10,fallgeschwindigkeit Text 10,25,"maximaler speed: " + Floor (max_speed#) Text 10,40,"minimaler speed: " + Floor (min_speed#) Text 10,55,"Punkte: " + Punkte Text 10,70,"Frames: " + fps() Flip 0 Cls WaitTimer timer Until KeyHit(1) ;--------------------------------------- ;hier werden die rechtecke in zeitichen abständen erstellt Function rechtecke_erstellen() counter = (counter +1+(.1*timescale)) If counter >= fallgeschwindigkeit# Then counter = 0 info.rechteck = New rechteck info\grosse = 15 info\speed = Rnd(Floor (min_speed#), Floor (max_speed#)) info\rechteck_x = Rnd(0,graph_x-info\grosse) info\rechteck_y = -5 End If End Function Function rechtecke_machen_lassen() For info.rechteck = Each rechteck info\rechteck_y = info\rechteck_y + info\speed Rect info\rechteck_x , info\rechteck_y , info\grosse , info\grosse ;Rechteck erstellen ;Wenn der rechteck das ander rechteck berührt oder aus dem Bildschirm fährt: löschen If RectsOverlap (info\rechteck_x , info\rechteck_y , info\grosse , info\grosse, xcor,ycor,50,2) Then Delete info.rechteck fallgeschwindigkeit# = fallgeschwindigkeit# -.8 max_speed# = max_speed# +.05 min_speed# = min_speed# +.05 Punkte = Punkte + 10 ElseIf info\rechteck_y >graph_y Then fallgeschwindigkeit# = fallgeschwindigkeit# -.8 Delete info.rechteck Punkte = Punkte - 5 EndIf Next End Function Function Geschwindigkeitsnormung() msa=MilliSecs() timescale=msa-ms ms=msa End Function Function fps() loops = loops+1 If MilliSecs() - fpstime > 1000 Then fpsrate = loops loops = 0 fpstime = MilliSecs() End If Return fpsrate End Function |
||
![]() |
Abrexxes |
![]() Antworten mit Zitat ![]() |
---|---|---|
Also wenn ich waittimer vor Flip setzte (wie immer) und meine Monitorfrequenz einstelle geht es einwandfrei. ![]() Du simulierst hier den grössten Möglichen Kontrast. Was da noch stottert sollte nicht stören, denn solche Kontraste hat man in einem normalen Spiel nicht. Der Versuch dieses Experiment auf jedem Monitor ohne Gezitter hinzukriegen ist weder durch Code noch technisch machbar. Es sei denn du investierst ein paar tausend Euro in einen Spezialmonitor der Zwischen Bilder berechnen kann. Also, lass dich da von nicht verwirren, falsch machst du nichts. cu |
||
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ok vielen Dank! ich bin beruhigt und schau mir das ganze gleich nochmal mit bildern statt den Rechtecken an. | ||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
![]() |
Thunder |
![]() Antworten mit Zitat ![]() |
---|---|---|
also Ich habe vor etwas längerer Zeit ein änliches Spiel Programmiert.
Ich bin aber kein guter Programmierer. allerdings ist mein Quelltext viel kürzer. Code: [AUSKLAPPEN] Graphics 800,600 Rect 390,500,20,20,1 a=300 h#=5 punkte=0 g=0 la=100 xx=0 While Not KeyHit(1) .zu If h=10 Then h=5 lav=lav+1 EndIf If lav>9 Then la=la/2 EndIf If la < 25 Then la= 100 If h=15 Then xx=1 y= 0 x= Rnd(788) s= Rnd(788) Repeat SetBuffer BackBuffer() Cls Rect x,y,2,30,1 y= y + h Rect a,500,la,20,1 If xx=1 Then Rect s,d,200,600,1 d=d-7 If KeyDown(203) Then a=a-10 If KeyDown(205) Then a=a+10 If g < 3 And KeyHit(57) Then g=g+1:Goto zu Flip Until RectsOverlap(x,y,2,30, a,500,100,20) Or y > 600 Wend End |
||
Meine Sachen: https://bitbucket.org/chtisgit https://github.com/chtisgit |
![]() |
mabox |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hm....ich finde deinen Code etwas unübersichtlicher (vllt nur weil ich meinen besser kenn) aber du hast keine Standardgeschwindigkeit (dein Programm läuft auf jedem PC mit einer anderen Geschwindigkeit) und keine Types. | ||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group