Jump to content
  • Advertisement
Sign in to follow this  
farhanx

Need your suggetions...

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi! i have created a small structure like struct GameTimer { DWORD start_clock_count; float incTick,lastTick,thisTick,fps; GameTimer() { incTick=lastTick=fps=thisTick=0.0f; } DWORD Get_Clock(void) { return(GetTickCount()); } DWORD Start_Clock(void) { return(start_clock_count =Get_Clock()); } DWORD Wait_Clock(DWORD count) { while((Get_Clock()-start_clock_count)<count); return(Get_Clock()); }//end Wait_Clock float FPS_Teller(void) { thisTick = GetTickCount(); incTick = thisTick - lastTick; lastTick = thisTick; if(incTick <= 0) incTick = 1; //don't div by zero fps = (fps + (1000 / incTick)) / 2; return fps; } }; and now i am using this utility class in my game loop as below GameTimer mytime; while() { mytime.Start_Clock(); print--- mytime.FPS_Teller(); //Other logics of game mytime.Wait_Clock(25); } 1)Do u think its the best way to keep speed on all kinds of processors ? 2)is it the best way to get the frame per second?and do u think it would be correct? 3)should i add something else? or should i begin my game now? thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Quote:

1)Do u think its the best way to keep speed on all kinds of processors ?


As long as you are using a high-level OS function like GetTickCount() or timeGetTime() for Win32 then it shouldn't matter. One minor problem I noticed in your code is that you're using a "busy-wait" loop in your Wait_Clock() function. If you want to burn time you should use Win32's Sleep() function instead since it will actually pause the current thread and allow other threads to execute (if you don't want your game to constantly peg the CPU at 100% usage).

Quote:

2)is it the best way to get the frame per second?and do u think it would be correct?


Instead of calculating the current FPS every loop I usually just increment a counter every frame and reset it/update the FPS display after each second passes.

Quote:

3)should i add something else? or should i begin my game now?


What additional utility code and classes you need will, of course, depend on the type and scope of your project. However, a couple of things that most games need that you might want to think about are (off the top of my head):

-- A Task/Process manager. You probably don't need to mess around with the additional complexity of system-level threads/processes to do concurrent processing. This will fit in with your timer class.

-- Memory management. The use of smart pointers at least will reduce your code's complexity and prevent many common pointer errors.

-- Managing game settings. Keep your user-defined and debug settings in one place.


Check out the "Enginuity" series of articles on GameDev for solid info on these and other topics.

Jason

Share this post


Link to post
Share on other sites
Ergh looks okay yeah
should GameTimer::Wait_Clock set start_clock_count internally rather than accessing a global or do you want the Wait_clock function to count from the moment it was first turned on?
Thats the method I usually use for displaying framerate in my games (mainly coz it's simpler & looks pretty when it changes fast). It isn't, however, a frame rate. to be technical it is the actually the "frequency" of that frame.
Apart from the naming of the methods, which looks quite ugly, it looks good.
It feels good to make little classes like that. gives a sense of structure in your code. continue. recycle everything you can. (improving now & then ofcourse)

question 3: begin now?
Ofcourse. You will nodoubt begin a few more times during the time you are making it. but that's the best way to learn: Just jump in.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!