int CTime::Update()
{
if(bSet)
{
DWORD ElapsedTime = 0, CurrentTime = 0;
CurrentTime = GetTickCount();
//this is where it gets crazy
ElapsedTime = (BeginningTime - CurrentTime);
if(ElapsedTime < 1000)
{
FrameRate++;
return 0;
}
else
{
int FrameRateToken = FrameRate;
FrameRate = 0;
bSet = false;
return FrameRateToken;
}
}
else
{
BeginningTime = GetTickCount();
bSet = true;
return 0;
}
}
GetTickCount()
Hello-
I am trying to get a simple time count for my little program. I have created a class which handles this called CTime. Below is the section of code which is giving me troubles.
for some reason, it isn''t giving me the difference of the two vaiables. WHat have i done wrong?
I already see a logic error, but that is easily fixed. i just want to know why my math isn''t working.
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
haha.. Never mind.. i was reading PC Gamer when it hit me... It wrapped around! dang it.. Well, i guess thanks goes out to PC Gamer for helping with one...
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
This is probably the logic error you were talking about, but try changing the line to this:
Alexander "DmGoober" Jhin
alexjh@online.microsoft.com
[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]
ElapsedTime = (CurrentTime - BeginningTime);
Alexander "DmGoober" Jhin
alexjh@online.microsoft.com
[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]
Alexander "DmGoober" Jhinalexjh@online.microsoft.com[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]
quote: ElapsedTime = (BeginningTime - CurrentTime);
...should be...
quote: ElapsedTime = (CurrentTime - BeginningTime);
It takes nearly 50 days for GetTickCount to wrap around.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Doesn''t GetTickCount() return time in milliseconds? so u should multiple the return time by 1000 to get time in seconds. Just my 2 cents.
-----------------------------
"There are ones that say they can and there are those who actually do."
"...u can not learn programming in a class, you have to learn it on your own."
-----------------------------
"There are ones that say they can and there are those who actually do."
"...u can not learn programming in a class, you have to learn it on your own."
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
It actually doesn''t matter if it wraps around when you are taking the difference. With the underflow, the huge negative becomes a relatively small positive, still the difference you want. If you are just looking for the time to be bigger than an old time (don''t really know why you would), then you have to check for wrap, otherwise you''re fine.
Karg
Karg
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement