[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Strange fps throttling results with pygame.time.set_timer
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Strange fps throttling results with pygame.time.set_timer
- From: Tomi Kyöstilä <tomi.kyostila@xxxxxxxxx>
- Date: Tue, 01 Nov 2005 21:24:32 +0200
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 01 Nov 2005 14:24:38 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=aGE9eTFFOxmxN4UVvzWSGJeUIERuhZUivoBM27NwIX3e6IE38Z95x6n14VIfSKAg9RnTQfDKCN+c+5WQRl5DlE5Iwf3VdwYewaiWXyZFB4wOJuqWNqooxvn1IU75NLu0lQwVvzCr+uzMKZJLWehpF2mehIN/n7P2DLfrPKhZZzw=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 1.4 (Windows/20050908)
Hi,
When I added fps throttling to my engine, the actual fps I get seems to
be very off from the fps target. The engine steps when it gets a
EVT_STEP event. Those events are coming from a timer that I set by
calling pygame.time.set_timer(int(1000.0 / targetFPS + 0.5)).
If the targetFPS is set any higher than 95, I get a fps of ~100. If it's
95 or lower (down to 48), I get a fps of ~50.
Here are some of the ranges of the targetFPS values and the actual fps
values I get:
target fps real fps
25...32 ~25
33...48 ~34
49...95 ~51
>= 96 ~100
I'm using Windows XP, but in #pygame piman had the same problem
(although with differing ranges, e.g. he got 100 fps when the target fps
was anything over 50) with Linux.
Could it be that the clock is not precise enough? With this problem I
can only limit the fps to 50 or 100, nothing in between. Is there
another way to implement the throttling? I'd like to use the event
system because the engine is mostly event driven.
Here is the code that I used to get these results:
import pygame
EVT_STEP = pygame.USEREVENT
targetFPS = 60
pygame.init()
pygame.display.set_mode((1, 1))
pygame.time.set_timer(EVT_STEP, int(1000.0 / targetFPS + 0.5))
print "Stepping every %d ticks" % int(1000.0 / targetFPS + 0.5)
frames = 0
lastFPSTime = pygame.time.get_ticks()
quit = False
while not quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit = True
elif event.type == pygame.KEYDOWN and \
event.key == pygame.K_ESCAPE:
quit = True
elif event.type == EVT_STEP:
frames += 1
if pygame.time.get_ticks() - lastFPSTime >= 1000:
print "FPS:", frames
frames = 0
lastFPSTime = pygame.time.get_ticks()
--
dOb