[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] BUG: mixer.music resets volume level after looping and others



I'm about to complete my second pygame project and release both games on
itch.io, but I'm having a few problems with both pygame 1.91 and 1.94. My
development platform is Python 2.7.12 on Linux Mint 18.3 with pygame 1.9.1.
I've also built Windows Installers for Windows 10 using pygame 1.9.4,
pyinstaller, and NSIS. My hardware is an Acer Aspire E5-57G-572 with an
Intel Core i5-8250U, 8GB ram, and an nVidia GeForce MX150(although I usually
run with onboard Intel video).

I'm not sure where to report bugs. I listed 4 separate issues together so
not to flood pygame-users with several messages from a new user.

*BUG: mixer.music resets volume level after looping.*

My game has theme music that plays during the intro and menu screens. A
random track from a music subdirectory plays at the start of each level,
restarting upon death. I use pygame.mixer.music.play() with a -1 loop value
to keep the music playing until I tell it otherwise. Whenever the music
starts over it plays at full volume instead of the volume level set by in
music.play(). This behavior never occurs in pygame 1.9.1 or in pygame 1.9.4
for Windows.


*PERFORMANCE*

After upgrading from pygame 1.9.1 to 1.9.4 I noticed a significant increase
to the CPU utilization of my games. Despite Flyboy's additional complexity
and an increase in size from 3000 to 8000 lines of code over Cooties, in
version 1.9.1 for Linux Mint 18.3, both games ran at 5-8% CPU utilization on
a 30fps clock. Now, running in pygame 1.9.4, I get about 15-20% utilization
and my laptop's fan kicks on(which is why I immediately noticed the
difference). When I change from High to Low resolution from my in-game menu
it drops down to about 10-15% utilization, which suggests to me that slower
blitting is the culprit. Note that my resolutions are 1600x900 and 960x540
at 32-bit color using surface alpha transparency for all surfaces and font
rendering.

After profiling my code I learned that less than 1% of CPU time is used in
my movement, physics, collision, and AI code. All of the time is spent in
pygame.tick(), pygame.blit(), and pygame.flip(). The following measurements
were taken while playing through the first three HARD levels in Flyboy on
Linux Mint 18.3 using pygame 2.7.12. The only changes are the pygame
versions, which are 1.9.1 downloaded from the standard Mint repository and
1.9.4 downloaded using 'pip2 install pygame'.

                1.9.1        1.9.4
CPU use  7%          18%
tick()         85.6%     59.5%
blit()	         9.4%       29.4%
flip()          5%          11.1%

So on my device pygame 1.9.4 spends 2-3 times longer handling graphics
instead of just ticking away the time it did in 1.9.1

*BUG: scaling error when first switching to fullscreen*

I believe this is a known issue with the version of SDL pygame is using in
Linux. For the first second of my game's intro screen when the game starts
in full screen mode, only part of the animation is visible. It looks like
the resolution changes before the new scaling factor is applied, although I
imagine the resolution doesn't actually change at all but that various
kernel drivers are simulating it somewhere between pygame and x11(the only
driver that seems to work in Linux at the moment). This problem occurs
whether the game starts in fullscreen or is changed to it from the in-game
menu.

*UNEXPECTED RESULTS: Sound.get_number_channels*

Is there any intention to fix the Sound.get_num_channels() method so that it
returns the expected results? It counts not only channels that are currently
playing the sound, but also channels that finished playing the sound but
haven't played anything else yet. A quick google search found a solution
that loops through the channels to see if the sound is playing on them. I
would rather let pygame do that in C.

I started programming using C in 16-bit real mode DOS, and while I love the
ease of developing in Python, I try not to waste cycles. Looping through
every channel every time my PlaySound class tries to play a sound in 'once'
mode is inefficient. I hoped that a simple call to mixer.stop would prevent
the sound from showing up as active in the channel so I wouldn't have to
loop through the channels again each time a new sound plays, but it doesn't
work. Sound.get_num_channels still reports a channel after I call the
channel's stop() method.




--
Sent from: http://pygame-users.25799.x6.nabble.com/