Jump to content
  • Advertisement
Sign in to follow this  
prux

Whats wrong with my timer?

This topic is 3884 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
Advertisement
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
Sign in to follow this  

  • 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!