Sign in to follow this  

Whats wrong with my timer?

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

Hey, Im writing a game and using timing in the simplest way: while Pmsg.message <> WM_QUIT do begin if PeekMessage(pMsg, 0, 0, 0, PM_NOREMOVE) then begin if not GetMessage(pMsg, 0, 0, 0) then break; TranslateMessage(pMsg); DispatchMessage(pMsg); end else begin if GetTickCount - FHTimer >= 20 then begin FHTimer:= GetTickCount; Updating etc end; Renering; end; end; well it seemed to be working - by now, because I tried it with a much better computer and it was slowed! Not 20 but 16 sec was the correct number. What can be wrong? I also use FPS-counting and it does better. Do I need to use multimedia timer? Aint works, it drops memory-violation errors randomly. What to do?

Share this post


Link to post
Share on other sites
GetTickCount() is only accurate to something like 16ms, so using it like this isn't very accurate at all. A multimedia timer (timeGetTime() or whatever the equivalent for your language is) would be better.

Share this post


Link to post
Share on other sites
Yes, now I know. But many example shown that.
Now I changed the code. It seems to be perfect although its alway better to ask the others's oppinion :)

.
.
.

timerID:= TimeSetEvent(20,20, New1C, 0, TIME_PERIODIC);

.
.
.

procedure New1C (uTimerID, uMessage: UINT; dwUser, dw1, dw2: DWORD) stdcall;
begin
PostMessage (MainWindow, wm_user, 0,0);
end;

.
.
.

killtimer

.
.
.

and the cycle:


while Msg2.message <> WM_QUIT do
begin
if PeekMessage (Msg2, 0,0,0, PM_REMOVE) then
begin
TranslateMessage (Msg2);
DispatchMessage (Msg2);
if Msg2.message = wm_user then
begin
UPDATES!!!!!!!!!
end;
end
else
begin
RENDERING
end;
end;



So this means the callback routine doesnt run the updates (because it crashes sometimes, dunno why - maybe this is about the synchronization?! lol I neved unserstood the threads) but it just send a message and the main application processes it.

Share this post


Link to post
Share on other sites

This topic is 3667 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this