Jump to content
  • Advertisement
Sign in to follow this  
McGrane

Why do my games run so slow?

This topic is 5475 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

... Is it because of a lack of time based movement, or bad coding? My progs start out at normal speed (usually) but than the speed half's ... than half's again, and so on till it freezes Can somebody explain why? Here is an example ... Game Source (Drag links to ToolBar) Also i cant promise that the game wont crash our comp if you leave it running for to long Any help would be greatly appreciated --mcgrane66

Share this post


Link to post
Share on other sites
Advertisement
eww... indent your code better.. it will look much nicer.

Anyway, it doesn't run fast on my computer (800mHz 448MB RAM, radeon 9200) and doesn't seem to slow down.

It looks like you've got a bottleneck somewhere - try removing random elements of it until it gets back to the desired speed. When it does, the one you removed is the problem. I'd help out, but I don't use OGL - I'm a DX junkie [wink]

good luck with your woes!

Share this post


Link to post
Share on other sites
Thanks for the reply, but i dont know what i can remove :S,
Its all very basic, putting the maps into a txt file might help, but i dont see it making too much of a difernce ... and i'd indent my code better ... if i knew what you ment :P lol

Share this post


Link to post
Share on other sites
Don't remove random elements! Use a profiler! That's what they're for: determining where the bottlenecks in your application are, where your code spends the most time.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Don't remove random elements! Use a profiler! That's what they're for: determining where the bottlenecks in your application are, where your code spends the most time.
profilers cost money :/ or can you suggest a good free one?ok, one could build something like a profiler into his program and just write
time used to execute function xyz : ....ms into a file but that would suck ..

Share this post


Link to post
Share on other sites
If it were me writing the code, I'ld create a display list for drawing the quads:

unsigned int QuadDisplayListID;

void CreateQuadDisplayList(void)
{
 // Gennerate a display list 'QuadDisplayListID'
 QuadDisplayListID = glGenLists(1);

 // Fill the display list with commands
 glNewList(QuadDisplayListID, GL_COMPILE);
   {
   glBegin(GL_QUADS);
     {
      glTexCoord2f(0.0f,0.0f); glVertex2i(0,0);
      glTexCoord2f(1.0f,0.0f); glVertex2i(64,0);
      glTexCoord2f(1.0f,1.0f); glVertex2i(64,64);
      glTexCoord2f(0.0f,1.0f); glVertex2i(0,64);
    }
   glEnd();
   }
 glEndList();
}

And I would change the drawing function to this:

void DrawQuad(unsigned int tex,int x,int y)
{
 glLoadIdentity();
 glTranslatef(x, y, 0.0f);
 glBindTexture(GL_TEXTURE_2D, tex);
 glCallList(QuadDisplayListID);
}

That little change could speed up your program because it now makes fewer GL calls pr draw(4 instead of 14). Also no more stack pushes and pops(if not managed correctly you could be overflowing the stack); besides unless your doing compound joint type animation, its usually a waist to use the stack.

Just my 2cents though. Good Luck.

-Linolium

EDIT:

WOAH! I just noticed you load your textures every frame! Do that only at startup! This stuff goes before the message loop:
------------------------------------------------
Initialize();
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
TEXTUREINFO[0] = LoadBitmapFile("Data\\Pics\\Mario.bmp", &BIH[0]);
TEXTUREINFO[1] = LoadBitmapFile("Data\\Pics\\Green Koopa.bmp", &BIH[1]);
TEXTUREINFO[2] = LoadBitmapFile("Data\\Pics\\Ground.bmp", &BIH[2]);
TEXTUREINFO[3] = LoadBitmapFile("Data\\Pics\\Box.bmp", &BIH[3]);
TEXTUREINFO[4] = LoadBitmapFile("Data\\Pics\\Pipe.bmp", &BIH[4]);
TEXTUREINFO[5] = LoadBitmapFile("Data\\Pics\\Time.bmp", &BIH[5]);
TEXTUREINFO[6] = LoadBitmapFile("Data\\Pics\\MBox.bmp", &BIH[6]);
TEXTUREINFO[7] = LoadBitmapFile("Data\\Pics\\BSky.bmp", &BIH[7]);
TEXTUREINFO[8] = LoadBitmapFile("Data\\Pics\\Cloud.bmp", &BIH[8]);
TEXTUREINFO[9] = LoadBitmapFile("Data\\Pics\\Sign.bmp", &BIH[9]);
TEXTUREINFO[10] = LoadBitmapFile("Data\\Pics\\MMario.bmp", &BIH[10]);
TEXTUREINFO[11] = LoadBitmapFile("Data\\Pics\\Mario2.bmp", &BIH[11]);
TEXTUREINFO[12] = LoadBitmapFile("Data\\Pics\\Green Koopa2.bmp", &BIH[12]);

for(int i=0;i<=MAXTEXTURES;i++)
{
glGenTextures(1,&TEXTURE);
glBindTexture(GL_TEXTURE_2D,TEXTURE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BIH.biWidth, BIH.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, TEXTUREINFO);
}
------------------------------------------------


This stuff goes right before this '/* shutdown OpenGL */' but outside of the message loop:
------------------------------------------------
Free();
------------------------------------------------

Share this post


Link to post
Share on other sites
Quote:
Original post by mcgrane66
... Is it because of a lack of time based movement, or bad coding? My progs start out at normal speed (usually) but than the speed half's ... than half's again, and so on till it freezes


The way that you describe it looks like a memory leak...

Share this post


Link to post
Share on other sites
Quote:
Original post by Nathaniel Hammen
Quote:
Original post by mcgrane66
... Is it because of a lack of time based movement, or bad coding? My progs start out at normal speed (usually) but than the speed half's ... than half's again, and so on till it freezes


The way that you describe it looks like a memory leak...
I strongly agree with that hypothesis.

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!