Archived

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

hillbilly

how to accelerate my game?

Recommended Posts

I wrote a game like Space Invader with GDI(not OpenGL or DX),and one problem is the speed of the game, it''s slow at first,but faster after I''ve destroyed some sprites so, I think there are some reasons for this: 1. I write some classes to the sprite, fighter and bullet, so when a new object is generated, I ''new'' an object of counterpart class, and ''delete'' it when it''s destroyed, do these operations waste time? 2. the data members of classes are almost all ''private'', so I write many functions to access them, just like ''GetPosition(),SetPostion()'',I''m wondering if it will be better if I define those data members as ''pubulic'' or there should be no ''orient object''? so I need not to use any access-funcion even no class? the code isn''t too complicated,but I''m a layman on game programming, help me, please! thanks a lot!

Share this post


Link to post
Share on other sites
quote:
Original post by downgraded
Are you using time-based movement?

eg: desired_movement_per_second * time_since_last_frame = actual movement per frame


oh, I don''t konw the time-based movement''

all the movements are controled by a Windows Message: WM_TIMER, and I wrote code like this: SetTimer(0,150,NULL).and I only defined this one TIMER event.

the collision testing, the moving, the appearance changing are all process in the 150 ms. so I think it is (1000/150)FPS, right?

..............

I have no idea about it...

Share this post


Link to post
Share on other sites
It may have to do with using GDI. I''ve heard that it runs significantly slower than other drawing interfaces. My reccommendation would be the Simple Directmedia Layer (libsdl.org). It provides a quick interface, and isn''t as difficult as DirectX or OpenGL to deal with.

Other than that... I wonder... (just a possibility, since this happened on my machine) Are you running the game fullscreen? And if so, are you using an LCD monitor that doesn''t natively support the resolution you''re using (probably 640x480)? I''m not positive if this is true, it''s just a theory I''m working on... but I think something goes on involving extra processing when a monitor doesn''t natively support the resolution but tries to ''emulate'' (I don''t know what the real term is) it.

Share this post


Link to post
Share on other sites
Oh, so you''re forcing a redraw only once every 150 ms?

That might explain it then. 1000/150 ~ 6.5 frames per second, about 23-24 FPS under the minimum needed to fool the human eye into believing that real motion is occurring. Although, it doesn''t explain why it moves faster when less sprites are on the screen... it should be pretty constant if you timed it to update every 150 ms. Or is that something you were intending to do but didn''t implement?

If you are intending to have it timed like that, try lowering your timing down to like 33 ms. That should get you a full 30 frames per second, provided that the GDI is fast enough to handle it.

If you want to switch your code over to SDL, we''ll all be here to help in the learning process. I think you''ll enjoy SDL, it''s a good SDK.

Share this post


Link to post
Share on other sites
quote:
Original post by VThornheart
It may have to do with using GDI. I''ve heard that it runs significantly slower than other drawing interfaces. My reccommendation would be the Simple Directmedia Layer (libsdl.org). It provides a quick interface, and isn''t as difficult as DirectX or OpenGL to deal with.



thank you,VThornheart!

this game runs in a window, and you are right it will be slow by using GDI, but it''s the one of requirements of the client, although it''s unbelievable

Share this post


Link to post
Share on other sites