|
Post by rosy on Feb 20, 2021 8:05:31 GMT -6
I added a "slower" to the game after UPDATE (assuming that it is performed in each loop ):
klatki=klatki+1
If hz>60 and Timer-cz < 1200/60 and klatki >= Round(60/(hz-60)) then klatki=0
update end if cz=Timer
Hz is the screen frequency, even if it is higher than 60 (and <= 120), the game will run at a speed of about 60 frames / s (or hz/2 if hz>120)
By the way, the question: Are all IF conditions checked, or are the rest after the first is met?
...
I wonder how the FPS function works ...
|
|
|
Post by rosy on Apr 23, 2021 12:43:45 GMT -6
|
|
|
Post by n00b on Apr 24, 2021 7:41:09 GMT -6
If conditions are checked until it finds a true condition and then it exits the if block.
|
|
|
Post by johnno56 on Apr 24, 2021 15:24:21 GMT -6
Rosy,
Please correct me if I have missed the point.
You referred to multiple "If"'s.... If the first "IF" condition is met, would the remaining "IF"'s be checked?
Yes and no. N00b is correct. When the condition of the IF statement is met then the IF statement exits.
It is possible that the remaining "IF"'s will not be processed if the condition of the first IF is say, "If the player runs out of lives. The player is dead. End of game." Obviously the remaining IF's will be ignored. The same will go for each following IF. Otherwise all IF's will accessed, conditions are checked, and the program goes through another clock tick.
I suppose that technically, 'all' IF's are being checked multiple times per second, but the condition of each IF, will determine whether or not the next IF will be checked.
Did that help?
|
|
|
Post by rosy on Apr 25, 2021 0:34:07 GMT -6
No. I meant a lot of conditions in one IF statement.
|
|
|
Post by J7M on Apr 25, 2021 9:40:24 GMT -6
I think rosy means: en.wikipedia.org/wiki/Short-circuit_evaluationklatki=klatki+1 If hz>60 and Timer-cz < 1200/60 and klatki >= Round(60/(hz-60)) then klatki=0 update end if cz=Timer in case hz is smaller than 60, will all the other conditions, which are chained with AND, evaluated or not?
|
|
|
Post by aurel on Apr 25, 2021 12:28:28 GMT -6
wow ..guest !!!
|
|
|
Post by rosy on Oct 1, 2021 12:10:41 GMT -6
And this is something to add after UPDATE, if the game is to run in about 30 frames:
If Timer-cz<25 then For tim=2 to Round(33.3/(Timer-cz)) Update Next End if cz=Timer
|
|
J7M
New Member
Posts: 18
|
Post by J7M on Oct 1, 2021 13:01:56 GMT -6
I do the timing a little bit different. In the following example the maximum frame rate would be 50fps.
WindowOpen(0, "Speedtest", 0 ,0, 640, 480, WINDOW_VISIBLE ,0) CanvasOpen(0,640,480,0,0,640,480,0)
TimeStep = 0 PositionX = 0 PositionY = 200 Velocity = 50 ' 50 Pixels per second
SetColor(rgb(255,255,255))
While(NOT key(K_ESCAPE)) TimeStart = Timer()
ClearCanvas()
PositionX = PositionX + Velocity*TimeStep if(PositionX > 640) then PositionX = 0 end if
Print(str(TimeStep) + "ms | " + str(1/TimeStep) + "fps") rectfill(PositionX, PositionY,50,50)
'wait(100) 'uncomment to simulate heavy computation
update()
'Do the timing TimeStep = ((Timer() - TimeStart))/1000 if(TimeStep < 0.02) then 'Throttle to 20ms per frame -> 50fps wait(20 - TimeStep*1000) TimeStep = 0.02 end if
wend
|
|
|
Post by rosy on Oct 1, 2021 13:34:10 GMT -6
IT'S SIMPLE WITHOUT VSYNC
My examples are with vsync
|
|
|
Post by rosy on Oct 11, 2021 2:24:55 GMT -6
I tested both methods on the ROKART game. The method without vsync causes the animation to jerk and the actual travel time will differ from the calculated frame by about 1 second per minute of playing. In my vsync method the animation is smooth when the frequency is optimal and the timing is usually as well.
And the FPS function gives bad results ...
|
|
|
Post by rosy on May 21, 2022 23:30:09 GMT -6
Applying an extra update to delay was causing some strange behavior in my Basic C game. Instead, I did this:
If (Display.refresh_rate>60) Pause(16) EndIf
This is another strange and incomprehensible SDL behavior, but in effect gives me a latency of up to 60 FPS on 75Hz monitor refresh. I don't know if it works like that in RC too ... This is probably not a good method ...
|
|