Hi
well, I dont think that sprites are of help here, because nearly the
entire screen has to be redrawn (because of the scroll), so a fullscreen
redraw is faster.
I just have rewritten some parts of it, just for testing, to use the
internal timer to draw at 30fps, and it is marginally using less cpu
than using the pygame.time.Clock() (see attachement).
Maybe the timer is not that precise as the clock.
Here my results (on a Pentium M 1.5GHz, 2 GB ram, Winxp Sp2, python 2.5,
pygame 1.8, pyglet1.2dev, rabbyt 0.7.5b):
shadow-pygame.py ~80% cpu
shadow-pygame-alternate.py ~18% cpu
shadow-pygame-alternate2.py ~17% cpu
shadow-pyglet.py ~32% cpu
shadow-pyglet-rabbyt.py ~30% cpu (difficult to say, because it changed
between 4% and 40% all the time)
The numbers can be wrong, because I had to more or less estimate an
average over the short period I run the demos.
The shadow-pyglet-rabbyt.py can not be terminated like the others.
~DR0ID
René Dudfield schrieb:
hi,
Cool, that's pretty good. Still could use some improving though.
DR0ID: feel like converting the example to use your sprite dirty layer classes?
Other interesting measurements would be:
- memory usage.
- computer temperature at the start of the test, and after X minutes
of running (maybe 5 minutes).
- battery drain after 1 hour of running.
One fun trick is to start the music playing before you bring the
window up, and before you start loading the images. That way they
hear the music first, whilst things are loading. so to do that, move
the music stuff above the set_mode call.
cu,
On Wed, Aug 13, 2008 at 8:31 AM, Python Nutter <[EMAIL PROTECTED]> wrote:
Thank you for the update Rene,
I have renamed it to shadow-pygame-alternate.py
I re-ran the tests, there is a CPU use reduction, but not as drastic,
but the initialisation is a lot faster and very much improved =)
CPU use of shadow-pygame-alternate.py is now averaging 43% CPU on the
same system used in the previous tests in this post. Initialisation of
the Pygame window is almost instantaneous.
I have yet to test the modified Pygame version on the Linux and Core 2
Duo Macbook Pro systems.
Cheers,
PN
#!/usr/bin/env python
# Shadow of the Beast
# Original port to pygame by Sebastian-Torsten Tillmann
# Little nostalgia for Amiga owners
# This is a quick little hack showing how to do some parallax scrolling and
# playing some music
import os, sys, pygame, random
from pygame.locals import *
pygame.display.init()
pygame.mixer.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Shadow of the Beast")
def load_image(fn_alpha):
fn,alpha = fn_alpha
if alpha:
return pygame.image.load(os.path.join("resources", fn)).convert_alpha()
else:
return pygame.image.load(os.path.join("resources", fn)).convert()
if hasattr(pygame, "threads"):
pygame.threads.init(8)
tmap = pygame.threads.tmap
else:
tmap = map
surfs = tmap(load_image,[("sky.png",0), ("mountains.png",0),
("ground1.png",0),
("ground2.png",0), ("ground3.png",0),
("clouds1.png",1),
("clouds2.png",1), ("clouds3.png",1),
("clouds4.png",1),
("barrier.png",1), ("titlecredit.png",1),
("tree.png",1),
("pygletcredit.png",1)])
s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13 = surfs
pygame.mixer.music.load(os.path.join("resources", "remix.ogg"))
pygame.mixer.music.play()
pygame.mouse.set_visible(False)
# Define the initial scrolling values
xspeed = 2
xscroll5 = random.random() % 640 + 640
xscroll5b = random.random() % 640 + 640
xscroll, xscrollb, xscroll1, xscroll2, xscroll3, xscroll4, xscroll6 =
(0,0,0,0,0,0,0)
clock = pygame.time.Clock()
going = True
def draw(events):
for event in events:
if event.type == QUIT:
global going
going = False
elif event.type == KEYDOWN and event.key == K_ESCAPE:
going = False
elif event.type == KEYDOWN and event.key == K_f:
pygame.display.toggle_fullscreen()
elif event.type == 31:
global xscroll, xscrollb, xscroll1, xscroll2, xscroll3, xscroll4,
xscroll6, xscroll5, xscroll5b, xspeed
xscroll = xscroll + xspeed
if xscroll == 320:
xspeed = -2
if xscroll == -960:
xspeed = 2
xscrollb = xscroll
if xscrollb < -640:
xscrollb = -640
if xscrollb > 0:
xscrollb = 0
xscroll1 = xscroll1 - 1
if xscroll1 == -640:
xscroll1 = 0
xscroll2 = xscroll2 - 2
if xscroll2 == -640:
xscroll2 = 0
xscroll3 = xscroll3 - 3
if xscroll3 < -640:
xscroll3 = xscroll3 + 640
xscroll4 = xscroll4 - 4
if xscroll4 < -640:
xscroll4 = xscroll4 + 640
xscroll5 = xscroll5 - 5
if xscroll5 < -640:
xscroll5 = xscroll5 + 1280
xscroll5b = xscroll5b - 2
if xscroll5b < -640:
xscroll5b = xscroll5b + 1280
xscroll6 = xscroll6 - 5
if xscroll6 < -640:
xscroll6 = xscroll6 + 640
# Paste the images
screen.blit(s1, (0, 0))
screen.blit(s2, (xscroll1, 200))
screen.blit(s2, (xscroll1 + 640, 200))
screen.blit(s3, (xscroll2, 420))
screen.blit(s3, (xscroll2 + 640, 420))
screen.blit(s4, (xscroll3, 430))
screen.blit(s4, (xscroll3 + 640, 430))
screen.blit(s5, (xscroll4, 450))
screen.blit(s5, (xscroll4 + 640, 450))
screen.blit(s10, (xscroll5, 440))
screen.blit(s6, (xscroll6, 0))
screen.blit(s6, (xscroll6 + 640, 0))
screen.blit(s7, (xscroll4, 82))
screen.blit(s7, (xscroll4 + 640, 82))
screen.blit(s8, (xscroll3, 120))
screen.blit(s8, (xscroll3 + 640, 120))
screen.blit(s9, (xscroll2, 138))
screen.blit(s9, (xscroll2 + 640, 138))
screen.blit(s12, (xscroll5b, 140))
screen.blit(s11, (xscrollb, 0))
screen.blit(s13, (xscrollb + 640, 0))
# This makes the changes visible
pygame.display.flip()
# clock.tick(30)
# Loop until the user hits escape
pygame.time.set_timer(31, int(round((1000.0/30.0))))
while going:
event = pygame.event.wait()
draw([event])
draw(pygame.event.get())
pygame.mixer.music.fadeout(100)
pygame.quit()
sys.exit(0)