Why does my game only speed up when firefox is running?

Okay, so I know that some of you are reading this subject line and
shaking your heads and thinking “man, another kid who can’t isolate
variables, and is totally confused about cause and effect.”

I assure you, I have methodically gone through my game and fiddled with
GetSurface and SetVideoMode flags alone and in combination. Each time I
run the game both with firefox running on another desktop, and again
without. The session with a firefox going runs smoothly, while the
framerate without firefox is much lower. I’m baffled!

I’m running on a T40 with this video chipset:

0000:01:00.0 VGA compatible controller: ATI Technologies Inc
Radeon Mobility M7 LW [Radeon Mobility 7500]

I’m in Ubuntu Dapper Drake, which means I have this X server:

ii  xserver-xorg   7.0.0-0ubuntu4 the X.Org X server

I can provide my xorg.conf and X session logs on request, if it would be
helpful.

The longer story is that I’m working on a game that was written in a
very DOS-like fashion, where the upstream authors wrote code to do
things like scale, rotate, and alpha-blend surfaces directly onto the
screen surface (no doubt expecting double-buffering to smooth out the
wrinkles). I am aware of the lack of reliable double-buffering in
modern systems, but the thing does run smoothly when I have a firefox
going (even when I don’t set the video mode to double-buffer!).

I’m happy to insert code to spit out more information on what sort of
video geegaws it’s managing to pry out of X11’s fingers; but I’m a bit
of a na?ve coder who’s been happily insulated by the elegance of SDL’s
API thus far, so I’ll need help dragging that stuff out. If you’d like
to play with the codebase yourself, I have a darcs repository available
via:

darcs get http://zork.net/~nick/sais/

Running “make” will grab everything needed to run the demo game. The
earliest indicator of a speed problem on my system is whether the
initial two logos do a visible “wipe” effect on fade-in, and then if the
subsequent purple starfield is jerky. I find that I notice these
artifacts when firefox is not running, but that the fade-in and
starfield zoom effect are both smooth when firefox is on.–
“N’aimez pas votre voiture? Nick Moffitt
Alor, l’heure est arrive pour la brul?!” @Nick_Moffitt
– Mark Jaroski

I wish that was the case here the last couple of releases of firefox
have crippled my simple x86 box :slight_smile:

This is going to be one of those threads that develops round some
really nice twists and never finds an agreed solution.

sparkesOn 5/9/06, Nick Moffitt wrote:

Okay, so I know that some of you are reading this subject line and
shaking your heads and thinking “man, another kid who can’t isolate
variables, and is totally confused about cause and effect.”


Steve ‘sparkes’ Parkes - tshirts http://nerd.ws - code http://zx-81.com
Autistic LUG http://autisticlug.org - blog http://sp.arkes.co.uk

Stephen Parkes:

This is going to be one of those threads that develops round some
really nice twists and never finds an agreed solution.

I just tested epiphany, and it doesn’t cause the speedup. Is there any
good information I could get my SDL program to spit out for diagnostic
purposes?–
We would do the world a great favor if we just deleted Nick Moffitt
all software projects that described themselves as @Nick_Moffitt
"frameworks".
A framework is just an unfinished program that nobody uses.

Nick Moffitt:

I just tested epiphany, and it doesn’t cause the speedup.

Even better: on a whim, I started firefox after running the game, and
the graphics sped up after it opened. Total madness.–
You are in an open field west of a big white house Nick Moffitt
with a boarded front door. nick at teh.entar.net
There is a small mailbox here.

_

Does other SDL based things run faster to?
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060510/f028d409/attachment.pgpOn Tue, May 09, 2006 at 09:58:21AM -0700, Nick Moffitt wrote:

I assure you, I have methodically gone through my game and fiddled with
GetSurface and SetVideoMode flags alone and in combination. Each time I
run the game both with firefox running on another desktop, and again
without. The session with a firefox going runs smoothly, while the
framerate without firefox is much lower. I’m baffled!

Mikael Eriksson:

Does other SDL based things run faster to?

It’s hard to test this, as I don’t have any SDL programs that run as
slowly as this game. Most SDL programs I have make intelligent use of
rects, whereas this game is definitely of the old DOS double-buffer
blit-to-video-ram school.–
We would do the world a great favor if we just deleted Nick Moffitt
all software projects that described themselves as @Nick_Moffitt
"frameworks".
A framework is just an unfinished program that nobody uses.

You know what it is?

Firefox is such a great browser it uses NEGATIVE cpu cycles, and your game
is grabbing those negative cpu cycles and using them for itself.

Ha! Don’t we wish?

Sorry for the OT :P> ----- Original Message -----

From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Mikael Eriksson
Sent: Tuesday, May 09, 2006 5:18 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] Why does my game only speed up when firefox is running?

On Tue, May 09, 2006 at 09:58:21AM -0700, Nick Moffitt wrote:

I assure you, I have methodically gone through my game and fiddled with
GetSurface and SetVideoMode flags alone and in combination. Each time I
run the game both with firefox running on another desktop, and again
without. The session with a firefox going runs smoothly, while the
framerate without firefox is much lower. I’m baffled!

Does other SDL based things run faster to?

Hello !

It’s hard to test this, as I don’t have any SDL programs that run as
slowly as this game. Most SDL programs I have make intelligent use of
rects, whereas this game is definitely of the old DOS double-buffer
blit-to-video-ram school.

What i would do to detect these timing problems is
to open a textfile and then sprinkle your main gameloop
with fprintf statements that output the current SDL_GetTicks ()
to this textfile.

For example that way :

Start Frame: 100
Checking Input: 102
GameLogic: 108
FrameBlitting: 110
LoopToWaitforFixedFramerate
End: 120

Think also that you should not trust SDL_Delay to wait a
specified time, for example you may want to wait 15 msecs
and it may only waits 10 msecs. You should always use SDL_GetTicks
to check that it is really waiting so long and not shorter or longer.

CU

Hello !

It’s hard to test this, as I don’t have any SDL programs that run as
slowly as this game. Most SDL programs I have make intelligent use of
rects, whereas this game is definitely of the old DOS double-buffer
blit-to-video-ram school.

What about for exmaple the SDL Doom Ports ?

They should also blast the whole frame
to the screen using doublebuffering ?

CU

Are you by any chance not sleeping properly ? Your game, I mean. Check
that you have “SDL_Delay(at least 1);” somewhere in your main loop.

  • Gerry

Gerry JJ:

Are you by any chance not sleeping properly ? Your game, I mean. Check
that you have “SDL_Delay(at least 1);” somewhere in your main loop.

No, that doesn’t seem to help. These loops don’t really sleep at all.
The initial effects just run as fast as possible.–
Hey, how come nobody here in the future Nick Moffitt
has a time machine except me? @Nick_Moffitt

Gerry JJ:

Are you by any chance not sleeping properly ? Your game, I mean. Check
that you have “SDL_Delay(at least 1);” somewhere in your main loop.

No, that doesn’t seem to help. These loops don’t really sleep at all.
The initial effects just run as fast as possible.

What I meant was that you should try adding a (short) sleep to the loops
if they don’t already have it (which it seems they don’t, judging by your
comment). Sleep once per frame or so. If you don’t sleep at all, you’ll
starve the CPU, and the OS will start treating you badly.

  • GerryOn Wed, 10 May 2006 06:30:08 +0200, Nick Moffitt wrote:

Gerry JJ:

What I meant was that you should try adding a (short) sleep to the loops
if they don’t already have it (which it seems they don’t, judging by your
comment). Sleep once per frame or so. If you don’t sleep at all, you’ll
starve the CPU, and the OS will start treating you badly.

I see the logic here, but I can’t quite find the right place to put the
SDL_Delay(). I’ll work on it.–
Though the great song return no more Nick Moffitt
There’s keen delight in what we have: nick at teh.entar.net
The rattle of pebbles on the shore
Under the receding wave. – W. B. Yeats

What I meant was that you should try adding a (short) sleep to the loops
if they don’t already have it (which it seems they don’t, judging by your
comment). Sleep once per frame or so. If you don’t sleep at all, you’ll
starve the CPU, and the OS will start treating you badly.

Are you telling me Linux puts your process in Time Out if it doesn’t
yield the CPU? And that Firefox fixes this?

Here are some notes, after looking at the darcs repo for a moment:

You have this:
putenv(“SDL_VIDEODRIVER=dga”);

Don’t do that. The X server probably has to do all sorts of tapdancing
for dga mode. I wouldn’t be surprised if there were strange interactions
with other X clients.

Also, you’re calling SDL_UnlockSurface() on the screen surface without
having locked it first (the LockSurface call is commented out). You
don’t need to lock the surface at all if it’s a software surface.

Try not to call SDL_Flip() more than once a frame (not sure if you are).

–ryan.

No, but sleeping puts you more in control of where the OS will interrupt
the execution of your game, so it’s less likely to swap out in the middle
of a screen update, for example, and in theory may do more short sleeps in
stead of fewer large ones. I’ve seen choppy games become smoother after
yielding was added, anyway. Maybe it was magic, I don’t know.

As for Firefox, I was thinking that as it is a CPU hog, it-- Nah, not
really, but I don’t have darcs installed, so I didn’t check out the source
code. So, taking shots in the dark. Maybe I should have mentioned that.

  • GerryOn Wed, 10 May 2006 09:20:06 +0200, Ryan C. Gordon wrote:

Are you telling me Linux puts your process in Time Out if it doesn’t
yield the CPU? And that Firefox fixes this?

Ryan C. Gordon:

You have this:
putenv(“SDL_VIDEODRIVER=dga”);

Haha yeah, it’s in the wrong place (needs to happen before the init). I
should take that back out, but know that it wasn’t there for my tests.

Also, you’re calling SDL_UnlockSurface() on the screen surface without
having locked it first (the LockSurface call is commented out). You
don’t need to lock the surface at all if it’s a software surface.

Gah, yeah, I need to fix that.

Try not to call SDL_Flip() more than once a frame (not sure if you are).

It’s an inherited codebase, so I’m still uncovering little gems. I’m
pretty sure I only have it once, but I’ll look into cleaning that up.–
“If, as they say, God spanked the town Nick Moffitt
for being over frisky, @Nick_Moffitt
why did He burn the churches down
and save Hotaling’s whisky?” – 1906 SF Earthquake rhyme

Gerry JJ:

really, but I don’t have darcs installed, so I didn’t check out the source
code. So, taking shots in the dark. Maybe I should have mentioned that.

Well if you don’t plan on submitting patches, wget -m -np or an
appropriate curl invocation works just as well. Or heck, just bring up
individual source files in your web browser.–
Though the great song return no more Nick Moffitt
There’s keen delight in what we have: nick at teh.entar.net
The rattle of pebbles on the shore
Under the receding wave. – W. B. Yeats

Hello !

really, but I don’t have darcs installed, so I didn’t check out the
source code. So, taking shots in the dark. Maybe I should have
mentioned that.

Well if you don’t plan on submitting patches, wget -m -np or an
appropriate curl invocation works just as well. Or heck, just bring up
individual source files in your web browser.

When other people should help you to find
bugs it is better to just ZIP or TAR.GZ up
the whole thing and put it online and post the
link. Or if it is possible put it in a public CVS
or SVN repo.

There maybe people too that cannot use wget
for example Windows Users do not have this installed
by standard.

CU

CU

[note: I have been trolled by Giebl. Feel free to skip this one]

Torsten Giebl:

I don’t have darcs installed, so I didn’t check out the source
code.

Well if you don’t plan on submitting patches, wget -m -np or an
appropriate curl invocation works just as well. Or heck, just bring
up individual source files in your web browser.

When other people should help you to find bugs it is better to just
ZIP or TAR.GZ up the whole thing and put it online and post the link.
Or if it is possible put it in a public CVS or SVN repo.

darcs is in all the major package repositories. It costs nothing to
simply go “apt-get install darcs” or “yum install darcs” or “emerge
darcs” or whatever.

I don’t use cvs or svn, because they’re ancient, and require all sorts
of hideous complicated server-side mucking. Modern VCSes are
peer-to-peer and just use ordinary apache/ssh/etc for best accesibility
and fallback to standard tools.

So have a look at http://zork.net/~nick/sais/ in your browser. It’s
just files.

There maybe people too that cannot use wget for example Windows Users
do not have this installed by standard.

It is not a Windows problem or a Windows build. That said, firefox
works on Windows. Darcs works on Windows. These tools are available to
people still running legacy proprietary operating systems.–
Support your droogs! Nick Moffitt
@Nick_Moffitt

Nick Moffitt wrote:

[note: I have been trolled by Giebl. Feel free to skip this one]

Let’s kill the inevitable “which version control rox0rs most” discussion
before it starts.

He wasn’t “trolling” you, he just pointed out that installing software
to give you free tech support was dissuading to him. And he’s right.

For what it’s worth, I used Firefox originally, but installed darcs
because I wanted to grep the source code in its entirety. This is the
point where most people would probably just hit the delete button and
hope someone else answers you, even though apt-get made the install
painless enough.

–ryan.