Jump to content
  • Advertisement
Sign in to follow this  
greystone

Interesting Performance Issue

This topic is 4057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so I have created a simple pong clone in Ubuntu using SDL. A friend of mine compiled the source on a win32 machine, no problem. However, when we run the executable (or whenever we run the app on a different machine with Ubuntu on it, for that matter), the performance just DIES. Any ideas? Source can be downloaded at: http://www.aaronknapp.com/downloads/Source.zip I'm not really sure what pertinent parts of the code to show, ask me and I will pass it along. Thanks, gs

Share this post


Link to post
Share on other sites
Advertisement
Sorry for the bump, the OP is a profile I no longer have access too apparantly...

So I programmed this Pong clone in SDL under Ubuntu. Game runs fine on my machine (athlon 64 3500+, 2GB ram, nvidia 7900 gt). Buddy of mine builds the source on a Windows machine, similar specs to mine. Game is unplayable on any Windows machine that I try. ~2 FPS, on average. Even tried to play the game on a different machine running Ubuntu, and I get the same problem.

So my question is, what do you think the source of the problem is? Is it something in the source code? Maybe in the way I compiled it? The game is ~1000 lines of code so I won't try and post it all here. My main loop looks like:


main(int argc, char* argv[])
{

// initialize the game
ConsoleInit();

// enter the main loop
for (;;)
{
if (SDL_PollEvent(&g_Event) == 0)
{
// run real-time functions
ConsoleMain();
}
else
{
if (g_Event.type == SDL_QUIT) break;
}
}

// shutdown the game
ConsoleShutdown();

// return success
return 0;
}






With ConsoleMain() looking like:

int ConsoleMain()
{
// draw the objects
ball.Draw(g_pDisplaySurface);
pc.Draw(g_pDisplaySurface);
npc.Draw(g_pDisplaySurface);
npc.Move();

// move the objects
ball.Move();

// grab the keyboard state
kbarray=SDL_GetKeyState(NULL);
if(kbarray[SDLK_a] == 1)
{
pc.SetXVel(-1);
pc.Move();
}

if(kbarray[SDLK_d] == 1)
{
pc.SetXVel(1);
pc.Move();
}

SDL_Rect rect1 = ball.GetBoundingRect();
SDL_Rect rect2 = pc.GetBoundingRect();
SDL_Rect rect3 = npc.GetBoundingRect();

if ( IsCollision( rect1, rect2 ) )
ball.SetYVel(-(ball.GetYVel() ));


if ( IsCollision( rect1, rect3 ) )
ball.SetYVel(-(ball.GetYVel() ));

time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
int rand_num = rand() % (10);

if (ball.GetX() < npc.GetX())
{
if (rand_num < 7)
npc.SetXVel(-1);
else
npc.SetXVel(1);
}
else
{
if (rand_num < 7)
npc.SetXVel(1);
else
npc.SetXVel(-1);
}

return 1;
}






Any thoughts?

EDIT: sorry, I don't know how to properly format blocks of code, if someone tells me how I will change it =)

EDIT EDIT: FIXED =)

[Edited by - greystone2 on November 5, 2007 8:49:44 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by greystone2
EDIT: sorry, I don't know how to properly format blocks of code, if someone tells me how I will change it =)

source tags :)

Share this post


Link to post
Share on other sites
For posting longer source code you should use the [ source lang="cpp" ][/ source ] tags.

Your problem is weird. On Windows it could be that the GDI graphics driver is beeing used which does not have hardware acceleration. You could try to "set SDL_VIDEODRIVER=directx" from a DOS box and then run the game from the DOS box to see if performance changes. You might also want to use a profiler to see where the bottleneck is.

Share this post


Link to post
Share on other sites
Yeah that's the tag I needed, thanks =)

As for the DOS command, I will try that when I get home. Any suggestions on how/which profiler to use? I don't have a lot of programming experience but I remember reading the Enginuity articles here on gamedev.net once upon a time that had some sort of class profiler in it. Probably way more than a pong clone will ever need, but is there anything else I can use?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!