Why do my games run so slow?

Started by
24 comments, last by Linolium 19 years, 7 months ago
... 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
Advertisement
if i can make a book suggestion,

Clickies for Dummies, skills like HTML and adding http:// to your links.
:P Sorry about that, wasnt sure why it wasnt working right,
Dont use html much any more :S,
Thanks
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!
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
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.
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 ..
Now get down on your hands and knees and start repeating "Open Source Good, M$ Evil", smacking your head against the pavement after each repetition. Once you have completed your training you may change your first name to GNU/, to show that you are free from the slavery of the closed source world. -Michalson
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();
------------------------------------------------
The Great and All Powerful Linolium
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 am the master of ideas.....If only I could write them down...
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement