why is my game so slow on older computers ??

Started by
5 comments, last by graveyard filla 19 years, 10 months ago
high, im working on a top down 2D RPG w/ c++, OpenGL, and SDL. when i first starting making this game, i was using SDL for the drawing code. it ran very un-acceptibly slow, even through im drawing the bare minimum to the screen (i have it so i only draw the tiles which are visable).. so i learned OpenGL, ported all the drawing code to it. now i get 350 FPS in windowed mode, and 500 FPS in fullscren. but theres a problem: im running on a 3 gig p4 with 512 ram. but people who test it with low end computers, the game runs un-accitbly slow. heres some stats: p3 400 mhz 65 megs, built in on chip memory card. 5 FPS in windowed mode, 60 FPS in fullscreen. p3 500 mhz, 376 RAM, un-known video card, unknown FPS, just incredibly slow running (im guessing under 50 FPS). my log file is telling me both of these PC's have hardward acceleration enabled and hardware blits enabled. i had one guy test the game who a low end computer, no video card. my log file said there was no hardware accel or blits eneabled, and he got 3 FPS in windowed mode and 3 FPS in fullscreen... :( he gets around 50 FPS in sim city, and i think he said around 40 FPS in unreal tournament.. so why in the hell is my game running so slow? i realize this is a broad question, and cant cut and paste my whole source here... but basically, im only drawing enough quads to fill the screen with. thats about 400 quads (tiles), plus the quads for the players and enemies, but there is only 3 enemies on the entire map and one player. how could this be? im making full use of dynamic memory and i dont believe i have any leeks. i using the STL a lot, could this be a problem? its just really depressing my game is this slow, and i do everything un-optimized because on my computer i get 350 FPS and pre-mature optiimaztion is evil. does anyone have advise? im googling for a code profiler, but am not sure how it works, what it does, and which one to use. can you recommend one that works with visual studio .net 2k3 ? im looking but havent found one yet... thanks for any help!!
FTA, my 2D futuristic action MMORPG
Advertisement
Well, I think you draw all the quads even while they aren't on the screen and that can slow down on slow computers a lot since glVertex3f calls aren't the fastest way to draw stuff :)
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
Judging from your examples, it might be a video-memory thing.
Unreal Tournament @ 30fps on a very low-end system? Without
a graphicscard? Is he running in 320x240, or what?

I'm not sure how to solve your issue, I've never used OpenGl
myself. (I'm more of DirectX guy) But if it's indeed a
videomemory issue, perhaps you'll know the solution yourself...

Good luck,
Tristan
i dont understand..

the game is tile based, so the map is made of tiles, which are just textured quads... i only draw the quads that are visable!!! its now i scroll, i figure out where the player is in the world, and i draw the tiles which he can see.. i downloaded GlowCode, and im not sure if im using it right, but apprently the functions which take up the most time are Sprte::Render() (this draws a players/ enemy quad, but right now there is only one player in the game an NO enemies, so this function is only being called once each frame!), Map::Update() (this draws the whole map to the screen), and System::Update() (this is where i take input and check for events and such..)



now here are the 3 functions...i hope im reading this wrong, because it makes no sence.. Sprite::Render() only draws a SINGLE quad, while Map::Update() draws around 400 quads!!!

Sprite::Render()
void Sprite::Render(int current_frame,float x,float y){	//systm->Draw_Quad(texture,parent->X_Pos(),parent->Y_Pos(),parent->Get_W(),parent->Get_H());//	systm->Log("SPRITE::RENDER IS BEING EXECUTED!!!");		  //bind this sprites texture strip to the quad	  glBindTexture(GL_TEXTURE_2D,texture);	  	  //draw this quad white	  glColor3f(1.0f,1.0f,1.0f);	  //the top left corner of this frame in its texture strip	  float tex_x = frames[current_frame].start_x;	  float tex_y = frames[current_frame].start_y;	  //the bottom right corner of this frame in its texture strip	  float tex_ex = frames[current_frame].end_x;	  float tex_ey = frames[current_frame].end_y;	  //find out where to draw this sprite //should be changed so that this function recieves these coords	 // float x = parent->X_Pos() - scroll_x;	  //float y = parent->Y_Pos() - scroll_y;	  ///the w/h of this frame	  float w = (float)frames[current_frame].width;	  float h = (float)frames[current_frame].height;	 	  glBegin(GL_QUADS);                  	     /* Bottom Left */		 glTexCoord2f(tex_x, tex_ey); //was 0.0f,1.0f		 glVertex2f(x, y + h); 	  		 /* Bottom Right */		 glTexCoord2f(tex_ex,tex_ey); //was 1.0, 1.0		 glVertex2f(x + w,y + h); 		 /* Top Right */		 glTexCoord2f(tex_ex,tex_y); //was 1.0,0.0 		 glVertex2f(x + w,y); 		 /* Top Left */		 glTexCoord2f(tex_x,tex_y); //was 0.0 0.0		 glVertex2f(x,y);        glEnd();}


Map::Update()

bool Map::Update(){	int x, y;	//screen pixel x,y coordinate to draw the current tile to	int mx, my;	int sx = 0 - (scroll_x%TILESIZE);	int smx = (sx+scroll_x)/TILESIZE;	for(y = 0 - (scroll_y%TILESIZE), my = (y+scroll_y)/TILESIZE;  y < VIEWHEIGHT;  y+=TILESIZE)	{		//y draw coordinate, the offset is for smooth scrolling		for( x = sx, mx = smx;  x < VIEWWIDTH;  x+=TILESIZE)				{				systm->Draw_Tile((float)x,(float)y,current_map[my][mx]->x_map_loc,current_map[my][mx]->y_map_loc);			mx++;		}		my++;	}	return true;}


now System::Update

bool System::Update(){	//first before we do anything we will clear the bit and depth buffers	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);	/* Clear The Screen And The Depth Buffer */	//glLoadIdentity();    //glColor4f(1.0f,1.0f,1.0f,1.0f);	    while ( SDL_PollEvent(&event) ) //looks for events    {		switch(event.type)		{					case SDL_QUIT: 				done = true;				break;			case SDL_KEYDOWN:				if(event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_q)					done = true;				break;		    case SDL_ACTIVEEVENT:			    //if ( event.active.gain == 0 )			//		isActive = FALSE;			   // else				//	isActive = TRUE;			    break;				case SDL_VIDEORESIZE:			    /* handle resize event */			    screen = SDL_SetVideoMode(event.resize.w,event.resize.h,SCREEN_BPP,Video_Flags);			 				if (!screen)					 Log("COULDNT RE LOAD THE SCREEN WHILE TRYING TO RESIZE!!!",FAILURE);			   				//Load_All_Textures();				//LoadGLTextures();				break;			case SDLK_d:				SDL_WM_ToggleFullScreen(screen);			    break;		}//end of switch event.type	}// end of while polling for events    	keys = SDL_GetKeyState(NULL);	return true;}//end of take input()


can anyone see what im doing wrong? ill post more code if its needed.. thanks for any help!!!
FTA, my 2D futuristic action MMORPG
well, since gavemdev wont let me edit a post for some reason.. im posting this to add my Draw_Tile() function that Map::Update() uses to draw the whole map...

void System::Draw_Tile(float x, float y, float x_loc, float y_loc){	//glEnable(GL_BLEND);	  //bind the texture we sent in to this quad	  glBindTexture(GL_TEXTURE_2D,map_data->tilemap_texture);	  	  //draw this quad white	  glColor3f(1.0f,1.0f,1.0f);	  //float corner_offset = 32.0f/64.0f; //(map.tmap_height*TILESIZE);	  //the width/height of a tile in percent-wise (to calc the edges of a tile.. ie x,y is top left, x + (t_perc)w is right corner	  float t_perc_w = 32.0f/((float)map_data->tmap_width*(float)TILESIZE);	  float t_perc_h = 32.0f/((float)map_data->tmap_height*(float)TILESIZE);	 glBegin(GL_QUADS);                  	     /* Bottom Left */		 glTexCoord2f(x_loc, y_loc + t_perc_h); //was 0.0f,1.0f		 glVertex2f(x, y + 32.0f); 	  		 /* Bottom Right */		 glTexCoord2f(x_loc + t_perc_w , y_loc + t_perc_h); //was 1.0, 1.0		 glVertex2f(x + 32.0f,y + 32.0f); 		 /* Top Right */		 glTexCoord2f(x_loc + t_perc_w , y_loc); //was 1.0,0.0 		 glVertex2f(x + 32.0f,y); 		 /* Top Left */		 glTexCoord2f(x_loc,y_loc); //was 0.0 0.0		 glVertex2f(x,y);        glEnd();}


thanks for any help!!!



FTA, my 2D futuristic action MMORPG
Mmmm,

I think that GlowCode doesn't add the time spent in
System::DrawTile to Map::Update, hence the total visit
time of Map::Update and Sprite::Render() are similar.

So nothing strange so far...

GlowCode hints that System::DrawTile gets
an enormous amount of calls. Perhaps there's a flaw in
your Map::Update, and the DrawTile function gets called
way to much? Try counting the number of calls/frame, and
see if it's what you'd expect.

Cheers,
Tristan

edit: changed small but annoying typo, and another mistake
well, i draw approximetely 400 tiles each frame (around 20x20 grid), so Draw_Tile() will be executed around 400 times each frame...

i still cant comprehend why 400 quads a frame would lag the game so horribly. other games have thousands of polygons, why is my game so slow on these lower end machines? thanks for anymore help...
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement