Archived

This topic is now archived and is closed to further replies.

kaggz

why is somehting so simple, so slow?

Recommended Posts

I just finished making my first real directx game. its a simple tetris clone which uses directdraw and directinput. Now the game runs fine on my 1gighz machine however, when I tried it on my 300mhz laptop, it runs extremely slow. So slow in fact that its unplayable. Now Im just wondering if something so simple like tetris where all it does is display moving bmps of boxes should require such a powerful machine? Is this normal or is it just a problem with my code? btw, its running in window mode. (i dont want fullscreen)

Share this post


Link to post
Share on other sites
Are you getting slow framerate, or the objects just seem to be moving slow?

IF the objects just seem to be moving slow possibly you need to multiply your movement by a time factor if you are not using double buffering and vsync. Time each iteration of your gameloop and multiply your movement by the amount of time each iteration takes. If you are not waiting for refresh and not using a time factor then something that is moving normal speed on your 1gig will seem a whole lot slower on a 300mhz laptop regardless of how simple it is.

Otherwise the laptop could have a really cheesy video card(can you play any other games on it?), or your game loop doing some things more than it should be doing. Possibly flawed recursion. Check your program with VTune and see if there are any odd functions that take up a large percentage of runtime.

Also make sure that you are not using something silly like DirectX 3 on your laptop and DX8 on your 1gig.

Seeya
Krippy

Share this post


Link to post
Share on other sites
I''d try locking the framerate. At the beginning of your main game function, do something like

clock_time = GetTickCount();


and at the end of the function loop:

while((GetTickCount() - clock_time) < (insert desired framerate);


It would probably be easier to build these into two or three functions, but whatever.

Share this post


Link to post
Share on other sites
Why lock the framerate? Why not just time the game loop and multiply the velocity of each game object by the last frame time in order to work out how far they move this frame?

Actually inserting dead time into a game run loop seems silly, considering the amount of time we spend optimising the things.

Share this post


Link to post
Share on other sites
Use an IF not a WHILE to lock the framerate. That way the game loop still runs even though nothing is drawn to the screen.

Unless it''s 3D and based on time there is no choice but to lock the framerate somehow otherwise you get the above mentioned problem.

You''re code is probably very very sloppy making it run slow. Since you coded it on a 1gig you didn''t catch the problems until now.

You should learn programming on a crap computer because you get lazy otherwise even if you don''t realize it.

Ben
http://therabbithole.redback.inficad.com

Share this post


Link to post
Share on other sites
I agree that there is no point to locking the framerate. If you check the time before rendering each frame and each object has a time based velocity, everything will move correctly (although perhaps choppily) on any computer.

Share this post


Link to post
Share on other sites
Locking frames and locking velocity are the exact same thing in the end.

You can''t interpolate frames in a 2D game so you have to use IFs to keep it moving along or skipping frames if need be to keep up with the intended speed of the animations.

Ben
http://www.icarusindie.com



Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Not really, because if you have a high end computer, you may render the game at 75 fps, while a low end computer would only render it at 25 fps. If you "lock the velocity" (I call it time-based physics) the game will run smoother on faster computers, but everything will move at the same real time speed. If you lock the frame rate, your game will run at say, 30 fps, on all computers, no matter how powerful it may be. Or, if you have a computer old enough, it will run at say, 20 fps, and everything will appear to run in slow motion. Locking the frame rate is a piss poor solution that doesn''t cut it anymore.

As for your comment about not being able to interpolate in 2D, why the hell not?

Besides, if you use time-based-physics, there is no need to interpolate.

Share this post


Link to post
Share on other sites
Umfor a game like tetris, you do not want to use time based physics.

Firstly, in the original (and I assume this game), the blocks move in large jumps anyway, so the actual logistics of using it is screwed up.

Then, the fact that when you are using time based modelling, if you have a small degradation in the frame rate, it seems like a much bigger problem than if you lock the frame rate. A game which runs consistently at 40fps will look better than one which runs at 60fps but then drops to 50fps every few seconds. You should always aim for consistency.

And thirdly... overkill? Tetris just screams fixed frame rate at you

Share this post


Link to post
Share on other sites
Um...why can''t you interpolate frames in 2D?

Possibly because all the animation frames for each sprite are already drawn maybe. I could be wrong...but I don''t think you can calculate addition frames with a bitmap.

I think you''re way over-thinking this whole concept. It''s really quite simple.

If a game is locked at 30 (correctly by not using a WHILE) and a computer can''t go that fast, frames will be dropped. It will not cause slow motion. Once it goes below 15 frames displayed per second the animation will appear obviously jerky. But everything will still move at the same speed.

It works exactly the same as time based movement except additional frames can''t be calculated so 30 displayed frames per second is the max even though the game loop may be getting hit 150 times per second or more.

If you don''t understand how that works...fine but don''t argue. I''m doing it so I know it works.

Ben
http://www.icarusindie.com

Share this post


Link to post
Share on other sites