2D hardware dependency question.

Started by
3 comments, last by Splinter of Chaos 15 years, 8 months ago
I have been working on creating a simple little game (if you could call it that) where it is 2D, has a little square dude, and he can move around and basically test if my collision detection works. Hopefully, it will turn into a 2D game of some sort, but for now I am just trying to get it working. (Don't worry, I am not trying to recreate Super Metroid in my first project...I know a full 2D game is a lot of work) Anywho, I have question: How do you prevent things from becoming hardware dependent? I.E. If you have a jump function, how do you prevent it from looking nice and working correctly on one machine to doing it so fast the user cannot see it on their quad-core processor super computer? I am using C++ and SDL, if that changes how you do it. EDIT: Sorry if it was confusing, I did not mean if my program would run on other hardware, it is at the SPEED of which it would run. By "hardware dependent" I meant "only able to run at the right speed on my machine--on others, it may run too fast". [Edited by - DOS4dinner on July 31, 2008 7:46:03 PM]
Advertisement
c++ is not a hardware specific language, so it's not a concern, at all
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Quote:Original post by DOS4dinner
How do you prevent things from becoming hardware dependent? I.E. If you have a jump function, how do you prevent it from looking nice and working correctly on one machine to doing it so fast the user cannot see it on their quad-core processor super computer? I am using C++ and SDL, if that changes how you do it.
Through correct timing. The simple way is to use the time since the last frame to adjust the movement of objects (i.e. if it is 1/30 sec since last frame, move an object by 1/30 of a tile). A more robust method is to ensure to always perform logic at a fixed rate - say 30 times per second.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by swiftcoder
Quote:Original post by DOS4dinner
How do you prevent things from becoming hardware dependent? I.E. If you have a jump function, how do you prevent it from looking nice and working correctly on one machine to doing it so fast the user cannot see it on their quad-core processor super computer? I am using C++ and SDL, if that changes how you do it.
Through correct timing. The simple way is to use the time since the last frame to adjust the movement of objects (i.e. if it is 1/30 sec since last frame, move an object by 1/30 of a tile). A more robust method is to ensure to always perform logic at a fixed rate - say 30 times per second.


Seems simple. How would you code, for instance, increment a varible by 10 twice a second?
Would it be (rougly) like this?:

get time;
if(time is one second greater)
{
variable += 10;
variable += 10;
}

Quote:Original post by godsenddeath
c++ is not a hardware specific language, so it's not a concern, at all


Might also be important to note that SDL...not so much as doesn't but can't use hardware. But, even if you used DirectX or OpenGL (hardware solutions), it's unlikely that someone without a compatible video card would play your game. (However, one problem is that Vista users might not be able to play your OpenGL game if you use an update version of OpenGL--I don't know if it's all of the newer OpenGLs or just certain features.)

This topic is closed to new replies.

Advertisement