Jump to content
  • Advertisement

Archived

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

kingpinzs

How do you make a basic timer?

This topic is 5261 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

this is what I found
#define TIMER_ID_1SEC 1
#define TIMER_ID_3SEC 2

SetTimer(hwnd, Timer_ID_1SEC, 1000,NULL);
SetTimer(hwnd, TImer_ID_3SEC, 3000,NULL);

case WM_TIMER:
{
switch(wparam)
{
case TIMER_ID_1Sec:
{
}
case Timer_ID_3Sec:
{
}break;
default:break;
}
return(0);
}break;


case WM_DESTROY:
[
KillTimer(hwnd, TIMER_ID_1SEC);
KillTimer(hwnd, TIMER_ID_3SEC);
PostQuiteMessage(0);
}break;
but this dont look like It will do what I want then there is this one
DWORD GetTickCount(void);

DWORD start_time = GetTickCount();
while ((GetTickCount() - start_time) < 33);
this the onw I ma using but it is hard to change it very easly and it is not that precise. Got any ideas?

Share this post


Link to post
Share on other sites
Advertisement
I also found this one


#include <stdio.h>
#include <time.h>

int main ( void )
{
clock_t start, end;

/* Start the timer */
start = clock();

printf ( "Please wait a few moments and hit return\n" );
getchar();

/* End the timer */
end = clock();

/* Print out the difference */
printf ( "The interval was: %f seconds\n",
(double)( end - start ) / (double)CLOCKS_PER_SEC );

return 0;
}


I am still trying to figure out how to use it for what I need.

sudo code is

images moves down 1 unit waits for timer to hit one second and then moves down another unit. after 10 lines are cleared then
it repeats but moves after timer hits 500 milliseconds
and repeats
ect

Share this post


Link to post
Share on other sites
I dont have my timer code with me but I can try to remember it

class CTimer
{

protected:

INT64 m_Frequency;

INT64 m_StartTime;
INT64 m_EndTime;

float m_Elapsed;

public:

// Call once at init
void Init()
{
QueryPerformanceFrequency(&m_Frequency);
QueryPerformanceCounter(&m_StartTime);
}

// Call once per frame
void Update()
{
QueryPerformanceCounter(&m_EndTime);

m_Elapsed = (m_EndTime - m_StartTime) / m_Frequency;

QueryPerformanceCounter(&m_StartTime);
}

// Time elapsed between frames
float GetElapsed() { return m_Elapsed; }

};

Share this post


Link to post
Share on other sites
Sorry I don’t think I am asking the right question.

Because I just tried a timer and I can get it to print stuff every second but I am missing on how to print out things when it is called only when the time hits a second.
It would be like a wait command to wait for timer to equal 1 second

Does that make sense?

Share this post


Link to post
Share on other sites
I think you will want to learn how to handle WM_TIMER messages

Using Timers (Windows User Interface)
http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Timers/UsingTimers.asp

Share this post


Link to post
Share on other sites
case WM_DESTROY:
[
KillTimer(hwnd, TIMER_ID_1SEC);
KillTimer(hwnd, TIMER_ID_3SEC);
PostQuiteMessage(0);
}break:


should be:

case WM_DESTROY:
{
KillTimer(hwnd, TIMER_ID_1SEC);
KillTimer(hwnd, TIMER_ID_3SEC);
PostQuiteMessage(0);
break:
}



Share this post


Link to post
Share on other sites
this is what I found out through my research
////////////////////////////////////////
WM_TIMER
GetTickCount()
Clock()
Time()
timeGetTime()
SetTimer();
sysdelay();
QueryPerformanceCounter();

This is all of the functions I could find

Is there any others;

And which one would I use for my function?


Share this post


Link to post
Share on other sites
I gave you this link before

http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Timers/UsingTimers.asp

it tells u exactly how to use WM_TIMER
I guess your too lazy to look at it
Im bored so I will try to explain how to use WM_TIMER

// This creates a timer that goes off every five seconds
SetTimer(hwnd, IDT_TIMER1, 5000, (TIMERPROC) NULL);

// Here is how to handle the WM_TIMER message

case WM_TIMER:
{
switch( wParam )
{
case IDT_TIMER1:
{
// Print Something To The Screen Every 5 seconds
// FunctionToPrintToTheScreen("Hello");
return 0;
}
}
return 0;
}


// And finally you can destroy the timer
KillTimer(hwnd, IDT_TIMER1);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!